BlueGit

ict rusty-teams

fix(settings): Edge, Brave, Helium, and Vivaldi can be the sign-in browser (#138)

metis Joe Mild · pushed by metis

Authored 2026-11-27 · 4 days ago

Hash
52f6b8705914ff491f0e522d6b04d882dad98bcc
Parent
7059d5ef
3 files changed +95 −11
crates/browser/src/config.rs +14 −1
@@ -9,12 +9,25 @@ pub const FIREFOX_PROFILE_NAME: &str = "rusty-teams-firefox";
9 9 pub const DEFAULT_PORT: u16 = 9222;
10 10 const CHROME_RELATIVE: &str = r"Google\Chrome\Application\chrome.exe";
11 11 const WINDOWS_VARIABLES: [&str; 4] = ["LOCALAPPDATA", "PROGRAMFILES", "PROGRAMFILES(X86)", "TEMP"];
12 pub(crate) const LINUX_CHROME_NAMES: [&str; 5] = [
12 pub(crate) const LINUX_CHROME_NAMES: &[&str] = &[
13 13 "google-chrome",
14 14 "google-chrome-stable",
15 15 "chromium",
16 16 "chromium-browser",
17 17 "chrome",
18 "microsoft-edge",
19 "microsoft-edge-stable",
20 "microsoft-edge-beta",
21 "microsoft-edge-dev",
22 "brave",
23 "brave-browser",
24 "brave-browser-stable",
25 "brave-browser-beta",
26 "brave-browser-nightly",
27 "helium",
28 "vivaldi",
29 "vivaldi-stable",
30 "vivaldi-snapshot",
18 31 ];
19 32 const MACOS_CHROME_NAMES: [&str; 3] = ["google-chrome", "chromium", "chrome"];
20 33 /// Chromium-based browsers in order of preference; each one gets its own profile, so the user's
@@ -9,12 +9,25 @@ pub const FIREFOX_PROFILE_NAME: &str = "rusty-teams-firefox";
9pub const DEFAULT_PORT: u16 = 9222;
9pub const DEFAULT_PORT: u16 = 9222;
10const CHROME_RELATIVE: &str = r"Google\Chrome\Application\chrome.exe";
10const CHROME_RELATIVE: &str = r"Google\Chrome\Application\chrome.exe";
11const WINDOWS_VARIABLES: [&str; 4] = ["LOCALAPPDATA", "PROGRAMFILES", "PROGRAMFILES(X86)", "TEMP"];
11const WINDOWS_VARIABLES: [&str; 4] = ["LOCALAPPDATA", "PROGRAMFILES", "PROGRAMFILES(X86)", "TEMP"];
12pub(crate) const LINUX_CHROME_NAMES: [&str; 5] = [
12pub(crate) const LINUX_CHROME_NAMES: &[&str] = &[
13 "google-chrome",
13 "google-chrome",
14 "google-chrome-stable",
14 "google-chrome-stable",
15 "chromium",
15 "chromium",
16 "chromium-browser",
16 "chromium-browser",
17 "chrome",
17 "chrome",
18 "microsoft-edge",
19 "microsoft-edge-stable",
20 "microsoft-edge-beta",
21 "microsoft-edge-dev",
22 "brave",
23 "brave-browser",
24 "brave-browser-stable",
25 "brave-browser-beta",
26 "brave-browser-nightly",
27 "helium",
28 "vivaldi",
29 "vivaldi-stable",
30 "vivaldi-snapshot",
18];
31];
19const MACOS_CHROME_NAMES: [&str; 3] = ["google-chrome", "chromium", "chrome"];
32const MACOS_CHROME_NAMES: [&str; 3] = ["google-chrome", "chromium", "chrome"];
20/// Chromium-based browsers in order of preference; each one gets its own profile, so the user's
33/// Chromium-based browsers in order of preference; each one gets its own profile, so the user's
crates/browser/src/process.rs +3 −0
@@ -67,6 +67,7 @@ pub(crate) fn is_chrome_image(image_name: &str) -> bool {
67 67 || lowered.starts_with("google chrome")
68 68 || lowered.starts_with("chromium")
69 69 || lowered.starts_with("microsoft edge")
70 || lowered.starts_with("microsoft-edge")
70 71 || lowered.starts_with("msedge")
71 72 || lowered.starts_with("brave")
72 73 || lowered.starts_with("helium")
@@ -186,6 +187,8 @@ mod tests {
186 187 assert!(is_chrome_image(
187 188 "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
188 189 ));
190 assert!(is_chrome_image("microsoft-edge"));
191 assert!(is_chrome_image("microsoft-edge-stable"));
189 192 assert!(is_chrome_image(
190 193 "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
191 194 ));
@@ -67,6 +67,7 @@ pub(crate) fn is_chrome_image(image_name: &str) -> bool {
67 || lowered.starts_with("google chrome")
67 || lowered.starts_with("google chrome")
68 || lowered.starts_with("chromium")
68 || lowered.starts_with("chromium")
69 || lowered.starts_with("microsoft edge")
69 || lowered.starts_with("microsoft edge")
70 || lowered.starts_with("microsoft-edge")
70 || lowered.starts_with("msedge")
71 || lowered.starts_with("msedge")
71 || lowered.starts_with("brave")
72 || lowered.starts_with("brave")
72 || lowered.starts_with("helium")
73 || lowered.starts_with("helium")
@@ -186,6 +187,8 @@ mod tests {
186 assert!(is_chrome_image(
187 assert!(is_chrome_image(
187 "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
188 "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
188 ));
189 ));
190 assert!(is_chrome_image("microsoft-edge"));
191 assert!(is_chrome_image("microsoft-edge-stable"));
189 assert!(is_chrome_image(
192 assert!(is_chrome_image(
190 "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
193 "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
191 ));
194 ));
crates/browser/src/sign_in_choice.rs +78 −10
@@ -120,16 +120,25 @@ pub(crate) fn installed_in(
120 120 Some((name.to_owned(), path))
121 121 })
122 122 .collect(),
123 Platform::Linux => LINUX_CHROME_NAMES
124 .iter()
125 .chain(&LINUX_FIREFOX_NAMES)
126 .filter_map(|name| {
127 let path = std::env::split_paths(path_variable)
123 Platform::Linux => {
124 let mut found = Vec::new();
125 let mut seen = Vec::new();
126 for name in LINUX_CHROME_NAMES.iter().chain(LINUX_FIREFOX_NAMES.iter()) {
127 let Some(path) = std::env::split_paths(path_variable)
128 128 .map(|directory| directory.join(name))
129 .find(|path| exists(path))?;
130 Some(((*name).to_owned(), path))
131 })
132 .collect(),
129 .find(|path| exists(path))
130 else {
131 continue;
132 };
133 let key = std::fs::canonicalize(&path).unwrap_or_else(|_| path.clone());
134 if seen.contains(&key) {
135 continue;
136 }
137 seen.push(key);
138 found.push(((*name).to_owned(), path));
139 }
140 found
141 }
133 142 Platform::Windows | Platform::Wsl => Vec::new(),
134 143 };
135 144 found
@@ -198,12 +207,22 @@ fn bundle_id(executable: &Path) -> Option<String> {
198 207 }
199 208
200 209 /// The installed browser named like the desktop entry `xdg-settings` reports, as in `firefox.desktop`.
210 /// Edge Stable's desktop file is `microsoft-edge.desktop` while the executable is
211 /// `microsoft-edge-stable`. Brave's desktop file is `brave-browser.desktop` while the
212 /// executable on some distributions is `brave`.
201 213 fn desktop_entry_match<'a>(
202 214 entry: &str,
203 215 installed: &'a [InstalledBrowser],
204 216 ) -> Option<&'a InstalledBrowser> {
205 217 let stem = entry.trim().trim_end_matches(".desktop");
206 installed.iter().find(|browser| browser.name == stem)
218 let names: &[&str] = match stem {
219 "microsoft-edge" => &["microsoft-edge", "microsoft-edge-stable"],
220 "brave-browser" => &["brave", "brave-browser", "brave-browser-stable"],
221 other => return installed.iter().find(|browser| browser.name == other),
222 };
223 names
224 .iter()
225 .find_map(|name| installed.iter().find(|browser| browser.name == *name))
207 226 }
208 227
209 228 #[cfg(test)]
@@ -265,6 +284,55 @@ mod tests {
265 284 assert!(desktop_entry_match("org.gnome.Epiphany.desktop", &installed).is_none());
266 285 }
267 286
287 #[test]
288 fn lists_edge_and_brave_and_matches_their_desktop_files() {
289 let root = Path::new("/usr/bin");
290 let installed = installed_in(
291 Platform::Linux,
292 None,
293 &std::env::join_paths([root]).unwrap(),
294 &|path| {
295 path == root.join("microsoft-edge-stable")
296 || path == root.join("brave")
297 || path == root.join("firefox")
298 },
299 );
300 let names: Vec<&str> = installed
301 .iter()
302 .map(|browser| browser.name.as_str())
303 .collect();
304 assert_eq!(names, ["microsoft-edge-stable", "brave", "firefox"]);
305 assert_eq!(
306 desktop_entry_match("microsoft-edge.desktop\n", &installed)
307 .map(|browser| browser.name.as_str()),
308 Some("microsoft-edge-stable")
309 );
310 assert_eq!(
311 desktop_entry_match("brave-browser.desktop", &installed)
312 .map(|browser| browser.name.as_str()),
313 Some("brave")
314 );
315 assert_eq!(installed[0].engine, Engine::Chromium);
316 assert_eq!(installed[1].engine, Engine::Chromium);
317
318 let channels = installed_in(
319 Platform::Linux,
320 None,
321 &std::env::join_paths([root]).unwrap(),
322 &|path| {
323 path == root.join("microsoft-edge-beta")
324 || path == root.join("brave-browser-nightly")
325 },
326 );
327 assert!(desktop_entry_match("microsoft-edge.desktop", &channels).is_none());
328 assert!(desktop_entry_match("brave-browser.desktop", &channels).is_none());
329 assert_eq!(
330 desktop_entry_match("microsoft-edge-beta.desktop", &channels)
331 .map(|browser| browser.name.as_str()),
332 Some("microsoft-edge-beta")
333 );
334 }
335
268 336 #[test]
269 337 fn parses_the_saved_choice() {
270 338 assert_eq!(SignInBrowser::parse(" \n"), SignInBrowser::Automatic);
@@ -120,16 +120,25 @@ pub(crate) fn installed_in(
120 Some((name.to_owned(), path))
120 Some((name.to_owned(), path))
121 })
121 })
122 .collect(),
122 .collect(),
123 Platform::Linux => LINUX_CHROME_NAMES
123 Platform::Linux => {
124 .iter()
124 let mut found = Vec::new();
125 .chain(&LINUX_FIREFOX_NAMES)
125 let mut seen = Vec::new();
126 .filter_map(|name| {
126 for name in LINUX_CHROME_NAMES.iter().chain(LINUX_FIREFOX_NAMES.iter()) {
127 let path = std::env::split_paths(path_variable)
127 let Some(path) = std::env::split_paths(path_variable)
128 .map(|directory| directory.join(name))
128 .map(|directory| directory.join(name))
129 .find(|path| exists(path))?;
129 .find(|path| exists(path))
130 Some(((*name).to_owned(), path))
130 else {
131 })
131 continue;
132 .collect(),
132 };
133 let key = std::fs::canonicalize(&path).unwrap_or_else(|_| path.clone());
134 if seen.contains(&key) {
135 continue;
136 }
137 seen.push(key);
138 found.push(((*name).to_owned(), path));
139 }
140 found
141 }
133 Platform::Windows | Platform::Wsl => Vec::new(),
142 Platform::Windows | Platform::Wsl => Vec::new(),
134 };
143 };
135 found
144 found
@@ -198,12 +207,22 @@ fn bundle_id(executable: &Path) -> Option<String> {
198}
207}
199
208
200/// The installed browser named like the desktop entry `xdg-settings` reports, as in `firefox.desktop`.
209/// The installed browser named like the desktop entry `xdg-settings` reports, as in `firefox.desktop`.
210/// Edge Stable's desktop file is `microsoft-edge.desktop` while the executable is
211/// `microsoft-edge-stable`. Brave's desktop file is `brave-browser.desktop` while the
212/// executable on some distributions is `brave`.
201fn desktop_entry_match<'a>(
213fn desktop_entry_match<'a>(
202 entry: &str,
214 entry: &str,
203 installed: &'a [InstalledBrowser],
215 installed: &'a [InstalledBrowser],
204) -> Option<&'a InstalledBrowser> {
216) -> Option<&'a InstalledBrowser> {
205 let stem = entry.trim().trim_end_matches(".desktop");
217 let stem = entry.trim().trim_end_matches(".desktop");
206 installed.iter().find(|browser| browser.name == stem)
218 let names: &[&str] = match stem {
219 "microsoft-edge" => &["microsoft-edge", "microsoft-edge-stable"],
220 "brave-browser" => &["brave", "brave-browser", "brave-browser-stable"],
221 other => return installed.iter().find(|browser| browser.name == other),
222 };
223 names
224 .iter()
225 .find_map(|name| installed.iter().find(|browser| browser.name == *name))
207}
226}
208
227
209#[cfg(test)]
228#[cfg(test)]
@@ -265,6 +284,55 @@ mod tests {
265 assert!(desktop_entry_match("org.gnome.Epiphany.desktop", &installed).is_none());
284 assert!(desktop_entry_match("org.gnome.Epiphany.desktop", &installed).is_none());
266 }
285 }
267
286
287 #[test]
288 fn lists_edge_and_brave_and_matches_their_desktop_files() {
289 let root = Path::new("/usr/bin");
290 let installed = installed_in(
291 Platform::Linux,
292 None,
293 &std::env::join_paths([root]).unwrap(),
294 &|path| {
295 path == root.join("microsoft-edge-stable")
296 || path == root.join("brave")
297 || path == root.join("firefox")
298 },
299 );
300 let names: Vec<&str> = installed
301 .iter()
302 .map(|browser| browser.name.as_str())
303 .collect();
304 assert_eq!(names, ["microsoft-edge-stable", "brave", "firefox"]);
305 assert_eq!(
306 desktop_entry_match("microsoft-edge.desktop\n", &installed)
307 .map(|browser| browser.name.as_str()),
308 Some("microsoft-edge-stable")
309 );
310 assert_eq!(
311 desktop_entry_match("brave-browser.desktop", &installed)
312 .map(|browser| browser.name.as_str()),
313 Some("brave")
314 );
315 assert_eq!(installed[0].engine, Engine::Chromium);
316 assert_eq!(installed[1].engine, Engine::Chromium);
317
318 let channels = installed_in(
319 Platform::Linux,
320 None,
321 &std::env::join_paths([root]).unwrap(),
322 &|path| {
323 path == root.join("microsoft-edge-beta")
324 || path == root.join("brave-browser-nightly")
325 },
326 );
327 assert!(desktop_entry_match("microsoft-edge.desktop", &channels).is_none());
328 assert!(desktop_entry_match("brave-browser.desktop", &channels).is_none());
329 assert_eq!(
330 desktop_entry_match("microsoft-edge-beta.desktop", &channels)
331 .map(|browser| browser.name.as_str()),
332 Some("microsoft-edge-beta")
333 );
334 }
335
268 #[test]
336 #[test]
269 fn parses_the_saved_choice() {
337 fn parses_the_saved_choice() {
270 assert_eq!(SignInBrowser::parse(" \n"), SignInBrowser::Automatic);
338 assert_eq!(SignInBrowser::parse(" \n"), SignInBrowser::Automatic);