Merge pull request #20: feat(macos): managed Chrome sign-in like WebView2 / Linux
@@ -48,3 +48,6 @@ webview.workspace = true
48
48
49
49
[target.'cfg(target_os = "linux")'.dependencies]
50
50
browser.workspace = true
51
52
[target.'cfg(target_os = "macos")'.dependencies]
53
browser.workspace = true
@@ -48,3 +48,6 @@ webview.workspace = true48
48
49
[target.'cfg(target_os = "linux")'.dependencies]49
[target.'cfg(target_os = "linux")'.dependencies]50
browser.workspace = true50
browser.workspace = true51
52
[target.'cfg(target_os = "macos")'.dependencies]53
browser.workspace = true@@ -4,13 +4,15 @@
4
4
)]
5
5
6
6
mod active_appearance;
7
mod active_locale;
7
8
mod agent_direct;
8
9
pub mod agents;
9
10
pub mod call;
11
mod i18n;
10
12
mod inline_video;
11
13
#[cfg(test)]
12
14
mod layout_guard;
13
#[cfg(target_os = "linux")]
15
#[cfg(any(target_os = "linux", target_os = "macos"))]
14
16
mod linux_browser;
15
17
pub mod notify;
16
18
mod settings;
@@ -124,6 +126,7 @@ fn data_path(name: &str) -> PathBuf {
124
126
fn transport(
125
127
endpoint: Option<&str>,
126
128
database: Option<&std::path::Path>,
129
#[cfg(windows)] sign_in_title: String,
127
130
) -> Arc<dyn session::Transport> {
128
131
#[cfg(windows)]
129
132
if endpoint.is_none() {
@@ -134,7 +137,7 @@ fn transport(
134
137
inline_video::configure(user_data_folder.clone());
135
138
let transport = webview::start(webview::HostConfig {
136
139
user_data_folder,
137
window_title: format!("{APP_NAME} - Sign in"),
140
window_title: sign_in_title,
138
141
log: |line| app_base::diagnostics::record(line),
139
142
});
140
143
task_dialog::install_host(transport.clone());
@@ -142,7 +145,7 @@ fn transport(
142
145
}
143
146
#[cfg(not(windows))]
144
147
let _ = database;
145
#[cfg(target_os = "linux")]
148
#[cfg(any(target_os = "linux", target_os = "macos"))]
146
149
if endpoint.is_none() {
147
150
return linux_browser::start(session::DEFAULT_ENDPOINT);
148
151
}
@@ -219,8 +222,24 @@ fn main() {
219
222
open_store(&path)
220
223
};
221
224
let store = Arc::new(store);
225
app_base::ui_locale::apply_locale(app_base::ui_locale::effective_locale(
226
app_base::ui_locale::load(&store),
227
));
228
#[cfg(windows)]
229
let sign_in_title = format!(
230
"{} - {}",
231
app_base::APP_NAME,
232
app_base::ui_locale::tr("auth.sign_in")
233
);
222
234
let user_input = user_activity::UserInput::new();
223
235
let receiver = (!arguments.demo).then(|| {
236
#[cfg(windows)]
237
let transport = transport(
238
arguments.endpoint.as_deref(),
239
arguments.database.as_deref(),
240
sign_in_title.clone(),
241
);
242
#[cfg(not(windows))]
224
243
let transport = transport(arguments.endpoint.as_deref(), arguments.database.as_deref());
225
244
let activity = user_activity::track(user_input.clone());
226
245
backend::start(store.clone(), transport, !arguments.read_only, activity)
@@ -244,6 +263,7 @@ fn main() {
244
263
.detach();
245
264
theme::load_fonts(cx);
246
265
active_appearance::install(&store, cx);
266
active_locale::install(&store, cx);
247
267
theme::apply(cx);
248
268
bind_keys(cx);
249
269
let state = cx.new(|_| {
@@ -264,7 +284,7 @@ fn main() {
264
284
while let Some(event) = receiver.recv().await {
265
285
let kind = event.kind();
266
286
let started = std::time::Instant::now();
267
#[cfg(target_os = "linux")]
287
#[cfg(any(target_os = "linux", target_os = "macos"))]
268
288
linux_browser::note_backend_event(&event);
269
289
state.update(cx, |state, cx| state.apply(event, cx));
270
290
app_base::diagnostics::record_if_slow(&kind, started.elapsed());
@@ -311,7 +331,7 @@ fn main() {
311
331
.detach();
312
332
});
313
333
presence_link::unregister_on_exit(ENDPOINT_UNREGISTER_TIMEOUT);
314
#[cfg(target_os = "linux")]
334
#[cfg(any(target_os = "linux", target_os = "macos"))]
315
335
linux_browser::stop();
316
336
#[cfg(windows)]
317
337
updater::exit_now();
@@ -4,13 +4,15 @@4
)]4
)]5
5
6
mod active_appearance;6
mod active_appearance;7
mod active_locale;7
mod agent_direct;8
mod agent_direct;8
pub mod agents;9
pub mod agents;9
pub mod call;10
pub mod call;11
mod i18n;10
mod inline_video;12
mod inline_video;11
#[cfg(test)]13
#[cfg(test)]12
mod layout_guard;14
mod layout_guard;13
#[cfg(target_os = "linux")]15
#[cfg(any(target_os = "linux", target_os = "macos"))]14
mod linux_browser;16
mod linux_browser;15
pub mod notify;17
pub mod notify;16
mod settings;18
mod settings;@@ -124,6 +126,7 @@ fn data_path(name: &str) -> PathBuf {124
fn transport(126
fn transport(125
endpoint: Option<&str>,127
endpoint: Option<&str>,126
database: Option<&std::path::Path>,128
database: Option<&std::path::Path>,129
#[cfg(windows)] sign_in_title: String,127
) -> Arc<dyn session::Transport> {130
) -> Arc<dyn session::Transport> {128
#[cfg(windows)]131
#[cfg(windows)]129
if endpoint.is_none() {132
if endpoint.is_none() {@@ -134,7 +137,7 @@ fn transport(134
inline_video::configure(user_data_folder.clone());137
inline_video::configure(user_data_folder.clone());135
let transport = webview::start(webview::HostConfig {138
let transport = webview::start(webview::HostConfig {136
user_data_folder,139
user_data_folder,137
window_title: format!("{APP_NAME} - Sign in"),140
window_title: sign_in_title,138
log: |line| app_base::diagnostics::record(line),141
log: |line| app_base::diagnostics::record(line),139
});142
});140
task_dialog::install_host(transport.clone());143
task_dialog::install_host(transport.clone());@@ -142,7 +145,7 @@ fn transport(142
}145
}143
#[cfg(not(windows))]146
#[cfg(not(windows))]144
let _ = database;147
let _ = database;145
#[cfg(target_os = "linux")]148
#[cfg(any(target_os = "linux", target_os = "macos"))]146
if endpoint.is_none() {149
if endpoint.is_none() {147
return linux_browser::start(session::DEFAULT_ENDPOINT);150
return linux_browser::start(session::DEFAULT_ENDPOINT);148
}151
}@@ -219,8 +222,24 @@ fn main() {219
open_store(&path)222
open_store(&path)220
};223
};221
let store = Arc::new(store);224
let store = Arc::new(store);225
app_base::ui_locale::apply_locale(app_base::ui_locale::effective_locale(226
app_base::ui_locale::load(&store),227
));228
#[cfg(windows)]229
let sign_in_title = format!(230
"{} - {}",231
app_base::APP_NAME,232
app_base::ui_locale::tr("auth.sign_in")233
);222
let user_input = user_activity::UserInput::new();234
let user_input = user_activity::UserInput::new();223
let receiver = (!arguments.demo).then(|| {235
let receiver = (!arguments.demo).then(|| {236
#[cfg(windows)]237
let transport = transport(238
arguments.endpoint.as_deref(),239
arguments.database.as_deref(),240
sign_in_title.clone(),241
);242
#[cfg(not(windows))]224
let transport = transport(arguments.endpoint.as_deref(), arguments.database.as_deref());243
let transport = transport(arguments.endpoint.as_deref(), arguments.database.as_deref());225
let activity = user_activity::track(user_input.clone());244
let activity = user_activity::track(user_input.clone());226
backend::start(store.clone(), transport, !arguments.read_only, activity)245
backend::start(store.clone(), transport, !arguments.read_only, activity)@@ -244,6 +263,7 @@ fn main() {244
.detach();263
.detach();245
theme::load_fonts(cx);264
theme::load_fonts(cx);246
active_appearance::install(&store, cx);265
active_appearance::install(&store, cx);266
active_locale::install(&store, cx);247
theme::apply(cx);267
theme::apply(cx);248
bind_keys(cx);268
bind_keys(cx);249
let state = cx.new(|_| {269
let state = cx.new(|_| {@@ -264,7 +284,7 @@ fn main() {264
while let Some(event) = receiver.recv().await {284
while let Some(event) = receiver.recv().await {265
let kind = event.kind();285
let kind = event.kind();266
let started = std::time::Instant::now();286
let started = std::time::Instant::now();267
#[cfg(target_os = "linux")]287
#[cfg(any(target_os = "linux", target_os = "macos"))]268
linux_browser::note_backend_event(&event);288
linux_browser::note_backend_event(&event);269
state.update(cx, |state, cx| state.apply(event, cx));289
state.update(cx, |state, cx| state.apply(event, cx));270
app_base::diagnostics::record_if_slow(&kind, started.elapsed());290
app_base::diagnostics::record_if_slow(&kind, started.elapsed());@@ -311,7 +331,7 @@ fn main() {311
.detach();331
.detach();312
});332
});313
presence_link::unregister_on_exit(ENDPOINT_UNREGISTER_TIMEOUT);333
presence_link::unregister_on_exit(ENDPOINT_UNREGISTER_TIMEOUT);314
#[cfg(target_os = "linux")]334
#[cfg(any(target_os = "linux", target_os = "macos"))]315
linux_browser::stop();335
linux_browser::stop();316
#[cfg(windows)]336
#[cfg(windows)]317
updater::exit_now();337
updater::exit_now();@@ -15,12 +15,18 @@ const LINUX_CHROME_NAMES: [&str; 5] = [
15
15
"chromium-browser",
16
16
"chrome",
17
17
];
18
const MACOS_CHROME_NAMES: [&str; 3] = ["google-chrome", "chromium", "chrome"];
19
const MACOS_CHROME_APP_PATHS: [&str; 2] = [
20
"Google Chrome.app/Contents/MacOS/Google Chrome",
21
"Chromium.app/Contents/MacOS/Chromium",
22
];
18
23
19
24
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20
25
pub enum Platform {
21
26
Wsl,
22
27
Windows,
23
28
Linux,
29
Macos,
24
30
}
25
31
26
32
impl Platform {
@@ -28,6 +34,9 @@ impl Platform {
28
34
if cfg!(windows) {
29
35
return Platform::Windows;
30
36
}
37
if cfg!(target_os = "macos") {
38
return Platform::Macos;
39
}
31
40
let proc_version = std::fs::read_to_string("/proc/version").ok();
32
41
Platform::from_proc_version(proc_version.as_deref())
33
42
}
@@ -38,12 +47,21 @@ impl Platform {
38
47
_ => Platform::Linux,
39
48
}
40
49
}
50
51
pub fn uses_unix_paths(self) -> bool {
52
matches!(self, Platform::Linux | Platform::Macos)
53
}
41
54
}
42
55
43
56
#[derive(Debug, Clone)]
44
57
pub(crate) enum ChromeSearch {
45
58
Files(Vec<PathBuf>),
46
59
Named(Vec<String>),
60
/// Absolute install paths first, then PATH names (macOS Application bundles + CLI).
61
FilesThenNamed {
62
files: Vec<PathBuf>,
63
names: Vec<String>,
64
},
47
65
}
48
66
49
67
#[derive(Debug, Clone)]
@@ -60,6 +78,7 @@ pub struct Config {
60
78
pub struct ConfigInputs<'a> {
61
79
pub windows_variables: HashMap<String, String>,
62
80
pub linux_data_dir: Option<PathBuf>,
81
pub home_dir: Option<PathBuf>,
63
82
pub to_local: &'a dyn Fn(&str) -> String,
64
83
}
65
84
@@ -67,7 +86,7 @@ impl Config {
67
86
pub fn detect() -> Result<Config, BrowserError> {
68
87
let platform = Platform::detect();
69
88
let windows_variables = match platform {
70
Platform::Linux => HashMap::new(),
89
Platform::Linux | Platform::Macos => HashMap::new(),
71
90
Platform::Windows => WINDOWS_VARIABLES
72
91
.iter()
73
92
.filter_map(|name| {
@@ -78,7 +97,9 @@ impl Config {
78
97
.collect(),
79
98
Platform::Wsl => wsl_windows_variables()?,
80
99
};
81
let linux_data_dir = directories::BaseDirs::new().map(|dirs| dirs.data_dir().to_path_buf());
100
let base = directories::BaseDirs::new();
101
let linux_data_dir = base.as_ref().map(|dirs| dirs.data_dir().to_path_buf());
102
let home_dir = base.as_ref().map(|dirs| dirs.home_dir().to_path_buf());
82
103
let to_local = |windows_path: &str| match platform {
83
104
Platform::Wsl => {
84
105
wslpath(windows_path).unwrap_or_else(|| windows_path_to_wsl(windows_path))
@@ -91,6 +112,7 @@ impl Config {
91
112
&ConfigInputs {
92
113
windows_variables,
93
114
linux_data_dir,
115
home_dir,
94
116
to_local: &to_local,
95
117
},
96
118
)
@@ -126,6 +148,35 @@ impl Config {
126
148
),
127
149
}
128
150
}
151
Platform::Macos => {
152
let data_dir = inputs.linux_data_dir.clone().ok_or_else(|| {
153
BrowserError::Environment("no Application Support directory".into())
154
})?;
155
let mut files = Vec::new();
156
for root in [PathBuf::from("/Applications")]
157
.into_iter()
158
.chain(inputs.home_dir.iter().map(|home| home.join("Applications")))
159
{
160
for relative in MACOS_CHROME_APP_PATHS {
161
files.push(root.join(relative));
162
}
163
}
164
Config {
165
platform,
166
port,
167
profile: format!("{}/{}", path_text(&data_dir), PROFILE_NAME),
168
mode_file: data_dir.join(format!("{PROFILE_NAME}.mode")),
169
profile_parent: path_text(&data_dir),
170
mode_parent: data_dir,
171
chrome_search: ChromeSearch::FilesThenNamed {
172
files,
173
names: MACOS_CHROME_NAMES
174
.iter()
175
.map(|name| (*name).to_owned())
176
.collect(),
177
},
178
}
179
}
129
180
Platform::Windows | Platform::Wsl => {
130
181
let local = inputs
131
182
.windows_variables
@@ -156,7 +207,7 @@ impl Config {
156
207
}
157
208
158
209
pub fn with_profile_name(mut self, name: &str) -> Config {
159
let separator = if self.platform == Platform::Linux {
210
let separator = if self.platform.uses_unix_paths() {
160
211
"/"
161
212
} else {
162
213
"\\"
@@ -176,6 +227,16 @@ fn path_text(path: &Path) -> String {
176
227
path.to_string_lossy().into_owned()
177
228
}
178
229
230
fn find_named_chrome(
231
names: &[String],
232
path_variable: &std::ffi::OsStr,
233
exists: &dyn Fn(&Path) -> bool,
234
) -> Option<PathBuf> {
235
std::env::split_paths(path_variable)
236
.flat_map(|directory| names.iter().map(move |name| directory.join(name)))
237
.find(|candidate| exists(candidate))
238
}
239
179
240
pub(crate) fn find_chrome(
180
241
search: &ChromeSearch,
181
242
path_variable: &std::ffi::OsStr,
@@ -189,11 +250,20 @@ pub(crate) fn find_chrome(
189
250
.ok_or_else(|| {
190
251
BrowserError::ChromeNotFound("not under Program Files or LocalAppData".into())
191
252
}),
192
ChromeSearch::Named(names) => std::env::split_paths(path_variable)
193
.flat_map(|directory| names.iter().map(move |name| directory.join(name)))
253
ChromeSearch::Named(names) => {
254
find_named_chrome(names, path_variable, exists).ok_or_else(|| {
255
BrowserError::ChromeNotFound(format!("none of {} on PATH", names.join(", ")))
256
})
257
}
258
ChromeSearch::FilesThenNamed { files, names } => files
259
.iter()
194
260
.find(|candidate| exists(candidate))
261
.cloned()
262
.or_else(|| find_named_chrome(names, path_variable, exists))
195
263
.ok_or_else(|| {
196
BrowserError::ChromeNotFound(format!("none of {} on PATH", names.join(", ")))
264
BrowserError::ChromeNotFound(
265
"not under /Applications, ~/Applications, or PATH".into(),
266
)
197
267
}),
198
268
}
199
269
}
@@ -275,6 +345,7 @@ mod tests {
275
345
.map(|(k, v)| ((*k).into(), (*v).into()))
276
346
.collect(),
277
347
linux_data_dir: None,
348
home_dir: None,
278
349
to_local,
279
350
}
280
351
}
@@ -362,6 +433,7 @@ mod tests {
362
433
let inputs = ConfigInputs {
363
434
windows_variables: [("LOCALAPPDATA".to_owned(), r"D:\L".to_owned())].into(),
364
435
linux_data_dir: None,
436
home_dir: None,
365
437
to_local: &to_local,
366
438
};
367
439
let config = Config::resolve(Platform::Windows, 9222, &inputs).unwrap();
@@ -389,6 +461,7 @@ mod tests {
389
461
let inputs = ConfigInputs {
390
462
windows_variables: HashMap::new(),
391
463
linux_data_dir: Some(PathBuf::from("/home/u/.local/share")),
464
home_dir: None,
392
465
to_local: &to_local,
393
466
};
394
467
let config = Config::resolve(Platform::Linux, 9222, &inputs).unwrap();
@@ -399,17 +472,74 @@ mod tests {
399
472
);
400
473
}
401
474
475
#[test]
476
fn resolves_macos_config_under_application_support() {
477
let to_local = |path: &str| path.to_owned();
478
let inputs = ConfigInputs {
479
windows_variables: HashMap::new(),
480
linux_data_dir: Some(PathBuf::from("/Users/joe/Library/Application Support")),
481
home_dir: Some(PathBuf::from("/Users/joe")),
482
to_local: &to_local,
483
};
484
let config = Config::resolve(Platform::Macos, 9222, &inputs).unwrap();
485
assert_eq!(
486
config.profile,
487
"/Users/joe/Library/Application Support/rusty-teams-chrome"
488
);
489
assert_eq!(
490
config.mode_file,
491
PathBuf::from("/Users/joe/Library/Application Support/rusty-teams-chrome.mode")
492
);
493
let ChromeSearch::FilesThenNamed { files, names } = &config.chrome_search else {
494
panic!("expected files then named")
495
};
496
assert_eq!(
497
files[0],
498
PathBuf::from("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
499
);
500
assert_eq!(
501
files[2],
502
PathBuf::from("/Users/joe/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
503
);
504
assert!(names.iter().any(|name| name == "google-chrome"));
505
assert_eq!(
506
config.with_profile_name("x").profile,
507
"/Users/joe/Library/Application Support/x"
508
);
509
}
510
402
511
#[test]
403
512
fn missing_localappdata_is_an_error() {
404
513
let to_local = |path: &str| path.to_owned();
405
514
let inputs = ConfigInputs {
406
515
windows_variables: HashMap::new(),
407
516
linux_data_dir: None,
517
home_dir: None,
408
518
to_local: &to_local,
409
519
};
410
520
assert!(Config::resolve(Platform::Windows, 9222, &inputs).is_err());
411
521
}
412
522
523
#[test]
524
fn finds_macos_chrome_under_applications_before_path() {
525
let search = ChromeSearch::FilesThenNamed {
526
files: vec![
527
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome".into(),
528
"/Users/joe/Applications/Chromium.app/Contents/MacOS/Chromium".into(),
529
],
530
names: vec!["google-chrome".into()],
531
};
532
let path = std::env::join_paths(["/usr/local/bin"]).unwrap();
533
let found = find_chrome(&search, &path, &|candidate| {
534
candidate.ends_with("Google Chrome") || candidate.ends_with("google-chrome")
535
})
536
.unwrap();
537
assert_eq!(
538
found,
539
PathBuf::from("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
540
);
541
}
542
413
543
#[test]
414
544
fn overrides_port_and_profile_name() {
415
545
let to_local = |path: &str| windows_path_to_wsl(path);
@@ -15,12 +15,18 @@ const LINUX_CHROME_NAMES: [&str; 5] = [15
"chromium-browser",15
"chromium-browser",16
"chrome",16
"chrome",17
];17
];18
const MACOS_CHROME_NAMES: [&str; 3] = ["google-chrome", "chromium", "chrome"];19
const MACOS_CHROME_APP_PATHS: [&str; 2] = [20
"Google Chrome.app/Contents/MacOS/Google Chrome",21
"Chromium.app/Contents/MacOS/Chromium",22
];18
23
19
#[derive(Debug, Clone, Copy, PartialEq, Eq)]24
#[derive(Debug, Clone, Copy, PartialEq, Eq)]20
pub enum Platform {25
pub enum Platform {21
Wsl,26
Wsl,22
Windows,27
Windows,23
Linux,28
Linux,29
Macos,24
}30
}25
31
26
impl Platform {32
impl Platform {@@ -28,6 +34,9 @@ impl Platform {28
if cfg!(windows) {34
if cfg!(windows) {29
return Platform::Windows;35
return Platform::Windows;30
}36
}37
if cfg!(target_os = "macos") {38
return Platform::Macos;39
}31
let proc_version = std::fs::read_to_string("/proc/version").ok();40
let proc_version = std::fs::read_to_string("/proc/version").ok();32
Platform::from_proc_version(proc_version.as_deref())41
Platform::from_proc_version(proc_version.as_deref())33
}42
}@@ -38,12 +47,21 @@ impl Platform {38
_ => Platform::Linux,47
_ => Platform::Linux,39
}48
}40
}49
}50
51
pub fn uses_unix_paths(self) -> bool {52
matches!(self, Platform::Linux | Platform::Macos)53
}41
}54
}42
55
43
#[derive(Debug, Clone)]56
#[derive(Debug, Clone)]44
pub(crate) enum ChromeSearch {57
pub(crate) enum ChromeSearch {45
Files(Vec<PathBuf>),58
Files(Vec<PathBuf>),46
Named(Vec<String>),59
Named(Vec<String>),60
/// Absolute install paths first, then PATH names (macOS Application bundles + CLI).61
FilesThenNamed {62
files: Vec<PathBuf>,63
names: Vec<String>,64
},47
}65
}48
66
49
#[derive(Debug, Clone)]67
#[derive(Debug, Clone)]@@ -60,6 +78,7 @@ pub struct Config {60
pub struct ConfigInputs<'a> {78
pub struct ConfigInputs<'a> {61
pub windows_variables: HashMap<String, String>,79
pub windows_variables: HashMap<String, String>,62
pub linux_data_dir: Option<PathBuf>,80
pub linux_data_dir: Option<PathBuf>,81
pub home_dir: Option<PathBuf>,63
pub to_local: &'a dyn Fn(&str) -> String,82
pub to_local: &'a dyn Fn(&str) -> String,64
}83
}65
84
@@ -67,7 +86,7 @@ impl Config {67
pub fn detect() -> Result<Config, BrowserError> {86
pub fn detect() -> Result<Config, BrowserError> {68
let platform = Platform::detect();87
let platform = Platform::detect();69
let windows_variables = match platform {88
let windows_variables = match platform {70
Platform::Linux => HashMap::new(),89
Platform::Linux | Platform::Macos => HashMap::new(),71
Platform::Windows => WINDOWS_VARIABLES90
Platform::Windows => WINDOWS_VARIABLES72
.iter()91
.iter()73
.filter_map(|name| {92
.filter_map(|name| {@@ -78,7 +97,9 @@ impl Config {78
.collect(),97
.collect(),79
Platform::Wsl => wsl_windows_variables()?,98
Platform::Wsl => wsl_windows_variables()?,80
};99
};81
let linux_data_dir = directories::BaseDirs::new().map(|dirs| dirs.data_dir().to_path_buf());100
let base = directories::BaseDirs::new();101
let linux_data_dir = base.as_ref().map(|dirs| dirs.data_dir().to_path_buf());102
let home_dir = base.as_ref().map(|dirs| dirs.home_dir().to_path_buf());82
let to_local = |windows_path: &str| match platform {103
let to_local = |windows_path: &str| match platform {83
Platform::Wsl => {104
Platform::Wsl => {84
wslpath(windows_path).unwrap_or_else(|| windows_path_to_wsl(windows_path))105
wslpath(windows_path).unwrap_or_else(|| windows_path_to_wsl(windows_path))@@ -91,6 +112,7 @@ impl Config {91
&ConfigInputs {112
&ConfigInputs {92
windows_variables,113
windows_variables,93
linux_data_dir,114
linux_data_dir,115
home_dir,94
to_local: &to_local,116
to_local: &to_local,95
},117
},96
)118
)@@ -126,6 +148,35 @@ impl Config {126
),148
),127
}149
}128
}150
}151
Platform::Macos => {152
let data_dir = inputs.linux_data_dir.clone().ok_or_else(|| {153
BrowserError::Environment("no Application Support directory".into())154
})?;155
let mut files = Vec::new();156
for root in [PathBuf::from("/Applications")]157
.into_iter()158
.chain(inputs.home_dir.iter().map(|home| home.join("Applications")))159
{160
for relative in MACOS_CHROME_APP_PATHS {161
files.push(root.join(relative));162
}163
}164
Config {165
platform,166
port,167
profile: format!("{}/{}", path_text(&data_dir), PROFILE_NAME),168
mode_file: data_dir.join(format!("{PROFILE_NAME}.mode")),169
profile_parent: path_text(&data_dir),170
mode_parent: data_dir,171
chrome_search: ChromeSearch::FilesThenNamed {172
files,173
names: MACOS_CHROME_NAMES174
.iter()175
.map(|name| (*name).to_owned())176
.collect(),177
},178
}179
}129
Platform::Windows | Platform::Wsl => {180
Platform::Windows | Platform::Wsl => {130
let local = inputs181
let local = inputs131
.windows_variables182
.windows_variables@@ -156,7 +207,7 @@ impl Config {156
}207
}157
208
158
pub fn with_profile_name(mut self, name: &str) -> Config {209
pub fn with_profile_name(mut self, name: &str) -> Config {159
let separator = if self.platform == Platform::Linux {210
let separator = if self.platform.uses_unix_paths() {160
"/"211
"/"161
} else {212
} else {162
"\\"213
"\\"@@ -176,6 +227,16 @@ fn path_text(path: &Path) -> String {176
path.to_string_lossy().into_owned()227
path.to_string_lossy().into_owned()177
}228
}178
229
230
fn find_named_chrome(231
names: &[String],232
path_variable: &std::ffi::OsStr,233
exists: &dyn Fn(&Path) -> bool,234
) -> Option<PathBuf> {235
std::env::split_paths(path_variable)236
.flat_map(|directory| names.iter().map(move |name| directory.join(name)))237
.find(|candidate| exists(candidate))238
}239
179
pub(crate) fn find_chrome(240
pub(crate) fn find_chrome(180
search: &ChromeSearch,241
search: &ChromeSearch,181
path_variable: &std::ffi::OsStr,242
path_variable: &std::ffi::OsStr,@@ -189,11 +250,20 @@ pub(crate) fn find_chrome(189
.ok_or_else(|| {250
.ok_or_else(|| {190
BrowserError::ChromeNotFound("not under Program Files or LocalAppData".into())251
BrowserError::ChromeNotFound("not under Program Files or LocalAppData".into())191
}),252
}),192
ChromeSearch::Named(names) => std::env::split_paths(path_variable)253
ChromeSearch::Named(names) => {193
.flat_map(|directory| names.iter().map(move |name| directory.join(name)))254
find_named_chrome(names, path_variable, exists).ok_or_else(|| {255
BrowserError::ChromeNotFound(format!("none of {} on PATH", names.join(", ")))256
})257
}258
ChromeSearch::FilesThenNamed { files, names } => files259
.iter()194
.find(|candidate| exists(candidate))260
.find(|candidate| exists(candidate))261
.cloned()262
.or_else(|| find_named_chrome(names, path_variable, exists))195
.ok_or_else(|| {263
.ok_or_else(|| {196
BrowserError::ChromeNotFound(format!("none of {} on PATH", names.join(", ")))264
BrowserError::ChromeNotFound(265
"not under /Applications, ~/Applications, or PATH".into(),266
)197
}),267
}),198
}268
}199
}269
}@@ -275,6 +345,7 @@ mod tests {275
.map(|(k, v)| ((*k).into(), (*v).into()))345
.map(|(k, v)| ((*k).into(), (*v).into()))276
.collect(),346
.collect(),277
linux_data_dir: None,347
linux_data_dir: None,348
home_dir: None,278
to_local,349
to_local,279
}350
}280
}351
}@@ -362,6 +433,7 @@ mod tests {362
let inputs = ConfigInputs {433
let inputs = ConfigInputs {363
windows_variables: [("LOCALAPPDATA".to_owned(), r"D:\L".to_owned())].into(),434
windows_variables: [("LOCALAPPDATA".to_owned(), r"D:\L".to_owned())].into(),364
linux_data_dir: None,435
linux_data_dir: None,436
home_dir: None,365
to_local: &to_local,437
to_local: &to_local,366
};438
};367
let config = Config::resolve(Platform::Windows, 9222, &inputs).unwrap();439
let config = Config::resolve(Platform::Windows, 9222, &inputs).unwrap();@@ -389,6 +461,7 @@ mod tests {389
let inputs = ConfigInputs {461
let inputs = ConfigInputs {390
windows_variables: HashMap::new(),462
windows_variables: HashMap::new(),391
linux_data_dir: Some(PathBuf::from("/home/u/.local/share")),463
linux_data_dir: Some(PathBuf::from("/home/u/.local/share")),464
home_dir: None,392
to_local: &to_local,465
to_local: &to_local,393
};466
};394
let config = Config::resolve(Platform::Linux, 9222, &inputs).unwrap();467
let config = Config::resolve(Platform::Linux, 9222, &inputs).unwrap();@@ -399,17 +472,74 @@ mod tests {399
);472
);400
}473
}401
474
475
#[test]476
fn resolves_macos_config_under_application_support() {477
let to_local = |path: &str| path.to_owned();478
let inputs = ConfigInputs {479
windows_variables: HashMap::new(),480
linux_data_dir: Some(PathBuf::from("/Users/joe/Library/Application Support")),481
home_dir: Some(PathBuf::from("/Users/joe")),482
to_local: &to_local,483
};484
let config = Config::resolve(Platform::Macos, 9222, &inputs).unwrap();485
assert_eq!(486
config.profile,487
"/Users/joe/Library/Application Support/rusty-teams-chrome"488
);489
assert_eq!(490
config.mode_file,491
PathBuf::from("/Users/joe/Library/Application Support/rusty-teams-chrome.mode")492
);493
let ChromeSearch::FilesThenNamed { files, names } = &config.chrome_search else {494
panic!("expected files then named")495
};496
assert_eq!(497
files[0],498
PathBuf::from("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")499
);500
assert_eq!(501
files[2],502
PathBuf::from("/Users/joe/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")503
);504
assert!(names.iter().any(|name| name == "google-chrome"));505
assert_eq!(506
config.with_profile_name("x").profile,507
"/Users/joe/Library/Application Support/x"508
);509
}510
402
#[test]511
#[test]403
fn missing_localappdata_is_an_error() {512
fn missing_localappdata_is_an_error() {404
let to_local = |path: &str| path.to_owned();513
let to_local = |path: &str| path.to_owned();405
let inputs = ConfigInputs {514
let inputs = ConfigInputs {406
windows_variables: HashMap::new(),515
windows_variables: HashMap::new(),407
linux_data_dir: None,516
linux_data_dir: None,517
home_dir: None,408
to_local: &to_local,518
to_local: &to_local,409
};519
};410
assert!(Config::resolve(Platform::Windows, 9222, &inputs).is_err());520
assert!(Config::resolve(Platform::Windows, 9222, &inputs).is_err());411
}521
}412
522
523
#[test]524
fn finds_macos_chrome_under_applications_before_path() {525
let search = ChromeSearch::FilesThenNamed {526
files: vec![527
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome".into(),528
"/Users/joe/Applications/Chromium.app/Contents/MacOS/Chromium".into(),529
],530
names: vec!["google-chrome".into()],531
};532
let path = std::env::join_paths(["/usr/local/bin"]).unwrap();533
let found = find_chrome(&search, &path, &|candidate| {534
candidate.ends_with("Google Chrome") || candidate.ends_with("google-chrome")535
})536
.unwrap();537
assert_eq!(538
found,539
PathBuf::from("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")540
);541
}542
413
#[test]543
#[test]414
fn overrides_port_and_profile_name() {544
fn overrides_port_and_profile_name() {415
let to_local = |path: &str| windows_path_to_wsl(path);545
let to_local = |path: &str| windows_path_to_wsl(path);@@ -56,10 +56,10 @@ pub fn chrome_arguments(spec: &ArgumentSpec) -> Vec<String> {
56
56
}
57
57
58
58
pub fn user_agent(platform: Platform, major: u32) -> String {
59
let system = if platform == Platform::Linux {
60
"X11; Linux x86_64"
61
} else {
62
"Windows NT 10.0; Win64; x64"
59
let system = match platform {
60
Platform::Linux => "X11; Linux x86_64",
61
Platform::Macos => "Macintosh; Intel Mac OS X 10_15_7",
62
Platform::Windows | Platform::Wsl => "Windows NT 10.0; Win64; x64",
63
63
};
64
64
format!(
65
65
"Mozilla/5.0 ({system}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{major}.0.0.0 Safari/537.36"
@@ -90,12 +90,12 @@ const FALLBACK_MAJOR: u32 = 150;
90
90
91
91
fn chrome_major(platform: Platform, executable: &Path) -> u32 {
92
92
let detected = match platform {
93
Platform::Linux => Command::new(executable)
93
Platform::Linux | Platform::Macos => Command::new(executable)
94
94
.arg("--version")
95
95
.output()
96
96
.ok()
97
97
.and_then(|output| major_from_version_output(&String::from_utf8_lossy(&output.stdout))),
98
_ => executable
98
Platform::Windows | Platform::Wsl => executable
99
99
.parent()
100
100
.and_then(|parent| std::fs::read_dir(parent).ok())
101
101
.and_then(|entries| {
@@ -225,6 +225,9 @@ mod tests {
225
225
assert!(user_agent(Platform::Wsl, 154).contains("Windows NT 10.0; Win64; x64"));
226
226
assert!(user_agent(Platform::Windows, 154).contains("Chrome/154.0.0.0"));
227
227
assert!(user_agent(Platform::Linux, 140).contains("X11; Linux x86_64"));
228
assert!(user_agent(Platform::Macos, 154).contains("Macintosh; Intel Mac OS X 10_15_7"));
229
assert!(user_agent(Platform::Macos, 154).contains("Chrome/154.0.0.0"));
230
assert!(!user_agent(Platform::Macos, 154).contains("Windows NT"));
228
231
}
229
232
230
233
#[test]
@@ -56,10 +56,10 @@ pub fn chrome_arguments(spec: &ArgumentSpec) -> Vec<String> {56
}56
}57
57
58
pub fn user_agent(platform: Platform, major: u32) -> String {58
pub fn user_agent(platform: Platform, major: u32) -> String {59
let system = if platform == Platform::Linux {59
let system = match platform {60
"X11; Linux x86_64"60
Platform::Linux => "X11; Linux x86_64",61
} else {61
Platform::Macos => "Macintosh; Intel Mac OS X 10_15_7",62
"Windows NT 10.0; Win64; x64"62
Platform::Windows | Platform::Wsl => "Windows NT 10.0; Win64; x64",63
};63
};64
format!(64
format!(65
"Mozilla/5.0 ({system}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{major}.0.0.0 Safari/537.36"65
"Mozilla/5.0 ({system}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{major}.0.0.0 Safari/537.36"@@ -90,12 +90,12 @@ const FALLBACK_MAJOR: u32 = 150;90
90
91
fn chrome_major(platform: Platform, executable: &Path) -> u32 {91
fn chrome_major(platform: Platform, executable: &Path) -> u32 {92
let detected = match platform {92
let detected = match platform {93
Platform::Linux => Command::new(executable)93
Platform::Linux | Platform::Macos => Command::new(executable)94
.arg("--version")94
.arg("--version")95
.output()95
.output()96
.ok()96
.ok()97
.and_then(|output| major_from_version_output(&String::from_utf8_lossy(&output.stdout))),97
.and_then(|output| major_from_version_output(&String::from_utf8_lossy(&output.stdout))),98
_ => executable98
Platform::Windows | Platform::Wsl => executable99
.parent()99
.parent()100
.and_then(|parent| std::fs::read_dir(parent).ok())100
.and_then(|parent| std::fs::read_dir(parent).ok())101
.and_then(|entries| {101
.and_then(|entries| {@@ -225,6 +225,9 @@ mod tests {225
assert!(user_agent(Platform::Wsl, 154).contains("Windows NT 10.0; Win64; x64"));225
assert!(user_agent(Platform::Wsl, 154).contains("Windows NT 10.0; Win64; x64"));226
assert!(user_agent(Platform::Windows, 154).contains("Chrome/154.0.0.0"));226
assert!(user_agent(Platform::Windows, 154).contains("Chrome/154.0.0.0"));227
assert!(user_agent(Platform::Linux, 140).contains("X11; Linux x86_64"));227
assert!(user_agent(Platform::Linux, 140).contains("X11; Linux x86_64"));228
assert!(user_agent(Platform::Macos, 154).contains("Macintosh; Intel Mac OS X 10_15_7"));229
assert!(user_agent(Platform::Macos, 154).contains("Chrome/154.0.0.0"));230
assert!(!user_agent(Platform::Macos, 154).contains("Windows NT"));228
}231
}229
232
230
#[test]233
#[test]@@ -28,6 +28,14 @@ pub(crate) fn parse_netstat_pid(output: &str, port: u16) -> Option<u32> {
28
28
})
29
29
}
30
30
31
/// First LISTEN row's PID column from `lsof -nP -iTCP:<port> -sTCP:LISTEN`.
32
pub(crate) fn parse_lsof_pid(output: &str) -> Option<u32> {
33
output.lines().skip(1).find_map(|line| {
34
let columns: Vec<&str> = line.split_whitespace().collect();
35
columns.get(1)?.parse().ok()
36
})
37
}
38
31
39
fn run(program: &str, arguments: &[&str]) -> Result<String, BrowserError> {
32
40
let output = Command::new(program).args(arguments).output()?;
33
41
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
@@ -36,6 +44,10 @@ fn run(program: &str, arguments: &[&str]) -> Result<String, BrowserError> {
36
44
fn listener_pid(platform: Platform, port: u16) -> Result<u32, BrowserError> {
37
45
let pid = match platform {
38
46
Platform::Linux => parse_ss_pid(&run("ss", &["-ltnpH", &format!("sport = :{port}")])?),
47
Platform::Macos => parse_lsof_pid(&run(
48
"lsof",
49
&["-nP", &format!("-iTCP:{port}"), "-sTCP:LISTEN"],
50
)?),
39
51
Platform::Windows => parse_netstat_pid(&run("netstat", &["-ano", "-p", "TCP"])?, port),
40
52
Platform::Wsl => parse_netstat_pid(&run("netstat.exe", &["-ano", "-p", "TCP"])?, port),
41
53
};
@@ -45,6 +57,8 @@ fn listener_pid(platform: Platform, port: u16) -> Result<u32, BrowserError> {
45
57
pub(crate) fn is_chrome_image(image_name: &str) -> bool {
46
58
let lowered = image_name.trim().trim_matches('"').to_ascii_lowercase();
47
59
lowered.starts_with("chrome")
60
|| lowered.starts_with("google chrome")
61
|| lowered.starts_with("chromium")
48
62
}
49
63
50
64
fn process_image_name(platform: Platform, pid: &str) -> Result<String, BrowserError> {
@@ -52,6 +66,7 @@ fn process_image_name(platform: Platform, pid: &str) -> Result<String, BrowserEr
52
66
let csv_arguments = ["/FI", filter.as_str(), "/FO", "CSV", "/NH"];
53
67
let output = match platform {
54
68
Platform::Linux => std::fs::read_to_string(format!("/proc/{pid}/comm"))?,
69
Platform::Macos => run("ps", &["-p", pid, "-o", "comm="])?,
55
70
Platform::Windows => run("tasklist", &csv_arguments)?,
56
71
Platform::Wsl => run("tasklist.exe", &csv_arguments)?,
57
72
};
@@ -67,7 +82,7 @@ pub(crate) fn kill_listener(platform: Platform, port: u16) -> Result<(), Browser
67
82
)));
68
83
}
69
84
let (program, arguments): (&str, Vec<&str>) = match platform {
70
Platform::Linux => ("kill", vec!["-KILL", &pid]),
85
Platform::Linux | Platform::Macos => ("kill", vec!["-KILL", &pid]),
71
86
Platform::Windows => ("taskkill", vec!["/PID", &pid, "/T", "/F"]),
72
87
Platform::Wsl => ("taskkill.exe", vec!["/PID", &pid, "/T", "/F"]),
73
88
};
@@ -94,6 +109,8 @@ mod tests {
94
109
fn only_chrome_images_are_killable() {
95
110
assert!(is_chrome_image("\"chrome.exe\""));
96
111
assert!(is_chrome_image("chrome\n"));
112
assert!(is_chrome_image("Google Chrome"));
113
assert!(is_chrome_image("Chromium"));
97
114
assert!(!is_chrome_image("\"wslrelay.exe\""));
98
115
assert!(!is_chrome_image(""));
99
116
}
@@ -104,4 +121,11 @@ mod tests {
104
121
assert_eq!(parse_netstat_pid(table, 9222), Some(5150));
105
122
assert_eq!(parse_netstat_pid(table, 9333), None);
106
123
}
124
125
#[test]
126
fn reads_pid_from_lsof() {
127
let table = "COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME\nGoogle\\x20Ch 4242 joe 45u IPv4 0xabc 0t0 TCP 127.0.0.1:9222 (LISTEN)\n";
128
assert_eq!(parse_lsof_pid(table), Some(4242));
129
assert_eq!(parse_lsof_pid("COMMAND PID\n"), None);
130
}
107
131
}
@@ -28,6 +28,14 @@ pub(crate) fn parse_netstat_pid(output: &str, port: u16) -> Option<u32> {28
})28
})29
}29
}30
30
31
/// First LISTEN row's PID column from `lsof -nP -iTCP:<port> -sTCP:LISTEN`.32
pub(crate) fn parse_lsof_pid(output: &str) -> Option<u32> {33
output.lines().skip(1).find_map(|line| {34
let columns: Vec<&str> = line.split_whitespace().collect();35
columns.get(1)?.parse().ok()36
})37
}38
31
fn run(program: &str, arguments: &[&str]) -> Result<String, BrowserError> {39
fn run(program: &str, arguments: &[&str]) -> Result<String, BrowserError> {32
let output = Command::new(program).args(arguments).output()?;40
let output = Command::new(program).args(arguments).output()?;33
Ok(String::from_utf8_lossy(&output.stdout).into_owned())41
Ok(String::from_utf8_lossy(&output.stdout).into_owned())@@ -36,6 +44,10 @@ fn run(program: &str, arguments: &[&str]) -> Result<String, BrowserError> {36
fn listener_pid(platform: Platform, port: u16) -> Result<u32, BrowserError> {44
fn listener_pid(platform: Platform, port: u16) -> Result<u32, BrowserError> {37
let pid = match platform {45
let pid = match platform {38
Platform::Linux => parse_ss_pid(&run("ss", &["-ltnpH", &format!("sport = :{port}")])?),46
Platform::Linux => parse_ss_pid(&run("ss", &["-ltnpH", &format!("sport = :{port}")])?),47
Platform::Macos => parse_lsof_pid(&run(48
"lsof",49
&["-nP", &format!("-iTCP:{port}"), "-sTCP:LISTEN"],50
)?),39
Platform::Windows => parse_netstat_pid(&run("netstat", &["-ano", "-p", "TCP"])?, port),51
Platform::Windows => parse_netstat_pid(&run("netstat", &["-ano", "-p", "TCP"])?, port),40
Platform::Wsl => parse_netstat_pid(&run("netstat.exe", &["-ano", "-p", "TCP"])?, port),52
Platform::Wsl => parse_netstat_pid(&run("netstat.exe", &["-ano", "-p", "TCP"])?, port),41
};53
};@@ -45,6 +57,8 @@ fn listener_pid(platform: Platform, port: u16) -> Result<u32, BrowserError> {45
pub(crate) fn is_chrome_image(image_name: &str) -> bool {57
pub(crate) fn is_chrome_image(image_name: &str) -> bool {46
let lowered = image_name.trim().trim_matches('"').to_ascii_lowercase();58
let lowered = image_name.trim().trim_matches('"').to_ascii_lowercase();47
lowered.starts_with("chrome")59
lowered.starts_with("chrome")60
|| lowered.starts_with("google chrome")61
|| lowered.starts_with("chromium")48
}62
}49
63
50
fn process_image_name(platform: Platform, pid: &str) -> Result<String, BrowserError> {64
fn process_image_name(platform: Platform, pid: &str) -> Result<String, BrowserError> {@@ -52,6 +66,7 @@ fn process_image_name(platform: Platform, pid: &str) -> Result<String, BrowserEr52
let csv_arguments = ["/FI", filter.as_str(), "/FO", "CSV", "/NH"];66
let csv_arguments = ["/FI", filter.as_str(), "/FO", "CSV", "/NH"];53
let output = match platform {67
let output = match platform {54
Platform::Linux => std::fs::read_to_string(format!("/proc/{pid}/comm"))?,68
Platform::Linux => std::fs::read_to_string(format!("/proc/{pid}/comm"))?,69
Platform::Macos => run("ps", &["-p", pid, "-o", "comm="])?,55
Platform::Windows => run("tasklist", &csv_arguments)?,70
Platform::Windows => run("tasklist", &csv_arguments)?,56
Platform::Wsl => run("tasklist.exe", &csv_arguments)?,71
Platform::Wsl => run("tasklist.exe", &csv_arguments)?,57
};72
};@@ -67,7 +82,7 @@ pub(crate) fn kill_listener(platform: Platform, port: u16) -> Result<(), Browser67
)));82
)));68
}83
}69
let (program, arguments): (&str, Vec<&str>) = match platform {84
let (program, arguments): (&str, Vec<&str>) = match platform {70
Platform::Linux => ("kill", vec!["-KILL", &pid]),85
Platform::Linux | Platform::Macos => ("kill", vec!["-KILL", &pid]),71
Platform::Windows => ("taskkill", vec!["/PID", &pid, "/T", "/F"]),86
Platform::Windows => ("taskkill", vec!["/PID", &pid, "/T", "/F"]),72
Platform::Wsl => ("taskkill.exe", vec!["/PID", &pid, "/T", "/F"]),87
Platform::Wsl => ("taskkill.exe", vec!["/PID", &pid, "/T", "/F"]),73
};88
};@@ -94,6 +109,8 @@ mod tests {94
fn only_chrome_images_are_killable() {109
fn only_chrome_images_are_killable() {95
assert!(is_chrome_image("\"chrome.exe\""));110
assert!(is_chrome_image("\"chrome.exe\""));96
assert!(is_chrome_image("chrome\n"));111
assert!(is_chrome_image("chrome\n"));112
assert!(is_chrome_image("Google Chrome"));113
assert!(is_chrome_image("Chromium"));97
assert!(!is_chrome_image("\"wslrelay.exe\""));114
assert!(!is_chrome_image("\"wslrelay.exe\""));98
assert!(!is_chrome_image(""));115
assert!(!is_chrome_image(""));99
}116
}@@ -104,4 +121,11 @@ mod tests {104
assert_eq!(parse_netstat_pid(table, 9222), Some(5150));121
assert_eq!(parse_netstat_pid(table, 9222), Some(5150));105
assert_eq!(parse_netstat_pid(table, 9333), None);122
assert_eq!(parse_netstat_pid(table, 9333), None);106
}123
}124
125
#[test]126
fn reads_pid_from_lsof() {127
let table = "COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME\nGoogle\\x20Ch 4242 joe 45u IPv4 0xabc 0t0 TCP 127.0.0.1:9222 (LISTEN)\n";128
assert_eq!(parse_lsof_pid(table), Some(4242));129
assert_eq!(parse_lsof_pid("COMMAND PID\n"), None);130
}107
}131
}@@ -323,6 +323,7 @@ pub async fn harness() -> Harness {
323
323
let inputs = ConfigInputs {
324
324
windows_variables: Default::default(),
325
325
linux_data_dir: Some(directory.path().to_path_buf()),
326
home_dir: None,
326
327
to_local: &to_local,
327
328
};
328
329
let config = Config::resolve(Platform::Linux, mock.port, &inputs).unwrap();
@@ -323,6 +323,7 @@ pub async fn harness() -> Harness {323
let inputs = ConfigInputs {323
let inputs = ConfigInputs {324
windows_variables: Default::default(),324
windows_variables: Default::default(),325
linux_data_dir: Some(directory.path().to_path_buf()),325
linux_data_dir: Some(directory.path().to_path_buf()),326
home_dir: None,326
to_local: &to_local,327
to_local: &to_local,327
};328
};328
let config = Config::resolve(Platform::Linux, mock.port, &inputs).unwrap();329
let config = Config::resolve(Platform::Linux, mock.port, &inputs).unwrap();@@ -93,8 +93,9 @@ impl MicSettings {
93
93
self.uses_device_track_on(cfg!(windows))
94
94
}
95
95
96
/// On Linux, Auto and Low keep the Pulse ADM device track (same path Web Teams uses).
97
/// Music mode and Off still run the software chain; Windows always does.
96
/// On Linux and macOS, Auto and Low keep the platform ADM device track
97
/// (Pulse / CoreAudio — same path Web Teams uses). Music mode and Off still
98
/// run the software chain; Windows always does.
98
99
pub fn uses_device_track_on(self, windows: bool) -> bool {
99
100
!windows
100
101
&& !self.music_mode
@@ -114,8 +115,9 @@ mod tests {
114
115
use super::*;
115
116
116
117
#[test]
117
fn auto_uses_the_device_track_on_linux_and_keeps_ml_for_the_windows_chain() {
118
fn auto_uses_the_device_track_on_linux_and_macos_and_keeps_ml_for_the_windows_chain() {
118
119
let settings = MicSettings::default();
120
// Non-Windows (Pulse on Linux, CoreAudio on macOS) keeps the ADM track.
119
121
assert!(settings.uses_device_track_on(false));
120
122
assert!(!settings.uses_device_track_on(true));
121
123
assert!(settings.ml_noise_suppression());
@@ -131,7 +133,7 @@ mod tests {
131
133
}
132
134
133
135
#[test]
134
fn low_keeps_the_device_track_with_the_apm_noise_suppression() {
136
fn low_keeps_the_coreaudio_or_pulse_device_track_with_the_apm_noise_suppression() {
135
137
let settings = MicSettings {
136
138
noise_suppression: NoiseSuppression::Low,
137
139
music_mode: false,
@@ -177,12 +179,12 @@ mod tests {
177
179
music_mode,
178
180
};
179
181
assert!(!settings.uses_device_track_on(true));
180
let linux_device = !music_mode
182
let non_windows_device = !music_mode
181
183
&& matches!(
182
184
noise_suppression,
183
185
NoiseSuppression::Auto | NoiseSuppression::Low
184
186
);
185
assert_eq!(settings.uses_device_track_on(false), linux_device);
187
assert_eq!(settings.uses_device_track_on(false), non_windows_device);
186
188
}
187
189
}
188
190
}
@@ -93,8 +93,9 @@ impl MicSettings {93
self.uses_device_track_on(cfg!(windows))93
self.uses_device_track_on(cfg!(windows))94
}94
}95
95
96
/// On Linux, Auto and Low keep the Pulse ADM device track (same path Web Teams uses).96
/// On Linux and macOS, Auto and Low keep the platform ADM device track97
/// Music mode and Off still run the software chain; Windows always does.97
/// (Pulse / CoreAudio — same path Web Teams uses). Music mode and Off still98
/// run the software chain; Windows always does.98
pub fn uses_device_track_on(self, windows: bool) -> bool {99
pub fn uses_device_track_on(self, windows: bool) -> bool {99
!windows100
!windows100
&& !self.music_mode101
&& !self.music_mode@@ -114,8 +115,9 @@ mod tests {114
use super::*;115
use super::*;115
116
116
#[test]117
#[test]117
fn auto_uses_the_device_track_on_linux_and_keeps_ml_for_the_windows_chain() {118
fn auto_uses_the_device_track_on_linux_and_macos_and_keeps_ml_for_the_windows_chain() {118
let settings = MicSettings::default();119
let settings = MicSettings::default();120
// Non-Windows (Pulse on Linux, CoreAudio on macOS) keeps the ADM track.119
assert!(settings.uses_device_track_on(false));121
assert!(settings.uses_device_track_on(false));120
assert!(!settings.uses_device_track_on(true));122
assert!(!settings.uses_device_track_on(true));121
assert!(settings.ml_noise_suppression());123
assert!(settings.ml_noise_suppression());@@ -131,7 +133,7 @@ mod tests {131
}133
}132
134
133
#[test]135
#[test]134
fn low_keeps_the_device_track_with_the_apm_noise_suppression() {136
fn low_keeps_the_coreaudio_or_pulse_device_track_with_the_apm_noise_suppression() {135
let settings = MicSettings {137
let settings = MicSettings {136
noise_suppression: NoiseSuppression::Low,138
noise_suppression: NoiseSuppression::Low,137
music_mode: false,139
music_mode: false,@@ -177,12 +179,12 @@ mod tests {177
music_mode,179
music_mode,178
};180
};179
assert!(!settings.uses_device_track_on(true));181
assert!(!settings.uses_device_track_on(true));180
let linux_device = !music_mode182
let non_windows_device = !music_mode181
&& matches!(183
&& matches!(182
noise_suppression,184
noise_suppression,183
NoiseSuppression::Auto | NoiseSuppression::Low185
NoiseSuppression::Auto | NoiseSuppression::Low184
);186
);185
assert_eq!(settings.uses_device_track_on(false), linux_device);187
assert_eq!(settings.uses_device_track_on(false), non_windows_device);186
}188
}187
}189
}188
}190
}