-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
/
Copy pathsafari.rs
140 lines (114 loc) · 4.12 KB
/
safari.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use crate::config::ManagerConfig;
use reqwest::Client;
use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;
use std::string::ToString;
use crate::files::BrowserPath;
use crate::config::OS::MACOS;
use crate::{create_http_client, Logger, SeleniumManager, STABLE};
pub const SAFARI_NAME: &str = "safari";
pub const SAFARIDRIVER_NAME: &str = "safaridriver";
const SAFARI_PATH: &str = r#"/Applications/Safari.app"#;
const SAFARI_FULL_PATH: &str = r#"/Applications/Safari.app/Contents/MacOS/Safari"#;
pub struct SafariManager {
pub browser_name: &'static str,
pub driver_name: &'static str,
pub config: ManagerConfig,
pub http_client: Client,
pub log: Logger,
}
impl SafariManager {
pub fn new() -> Result<Box<Self>, Box<dyn Error>> {
let browser_name = SAFARI_NAME;
let driver_name = SAFARIDRIVER_NAME;
let config = ManagerConfig::default(browser_name, driver_name);
let default_timeout = config.timeout.to_owned();
let default_proxy = &config.proxy;
Ok(Box::new(SafariManager {
browser_name,
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::new(),
}))
}
}
impl SeleniumManager for SafariManager {
fn get_browser_name(&self) -> &str {
self.browser_name
}
fn get_browser_names_in_path(&self) -> Vec<&str> {
vec![self.get_browser_name()]
}
fn get_http_client(&self) -> &Client {
&self.http_client
}
fn set_http_client(&mut self, http_client: Client) {
self.http_client = http_client;
}
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
HashMap::from([(BrowserPath::new(MACOS, STABLE), SAFARI_PATH)])
}
fn discover_browser_version(&mut self) -> Result<Option<String>, Box<dyn Error>> {
self.discover_safari_version(SAFARI_FULL_PATH.to_string())
}
fn get_driver_name(&self) -> &str {
self.driver_name
}
fn request_driver_version(&mut self) -> Result<String, Box<dyn Error>> {
Ok("(local)".to_string())
}
fn request_browser_version(&mut self) -> Result<Option<String>, Box<dyn Error>> {
Ok(None)
}
fn get_driver_url(&mut self) -> Result<String, Box<dyn Error>> {
Err(format!("{} not available for download", self.get_driver_name()).into())
}
fn get_driver_path_in_cache(&self) -> Result<PathBuf, Box<dyn Error>> {
Ok(PathBuf::from("/usr/bin/safaridriver"))
}
fn get_config(&self) -> &ManagerConfig {
&self.config
}
fn get_config_mut(&mut self) -> &mut ManagerConfig {
&mut self.config
}
fn set_config(&mut self, config: ManagerConfig) {
self.config = config;
}
fn get_logger(&self) -> &Logger {
&self.log
}
fn set_logger(&mut self, log: Logger) {
self.log = log;
}
fn download_browser(&mut self) -> Result<Option<PathBuf>, Box<dyn Error>> {
Ok(None)
}
fn get_platform_label(&self) -> &str {
""
}
fn request_latest_browser_version_from_online(&mut self) -> Result<String, Box<dyn Error>> {
self.unavailable_download()
}
fn request_fixed_browser_version_from_online(&mut self) -> Result<String, Box<dyn Error>> {
self.unavailable_download()
}
}