fix(merge): review fixes for PRs #27-#30
- keep login_grace at 4 s so silent SSO redirects do not open the login window - fontconfig test without env mutation, asserts the stripped keys - schließen in the Google sign-in page - sign-in phase Opening only on first run, warm starts keep the fast splash - drop unused google_connect_* fields, cache browser discovery once - cargo fmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -44,11 +44,7 @@ fn open_sink() -> Result<rodio::MixerDeviceSink, String> {
44
44
.into_iter()
45
45
.flatten()
46
46
.find(|device| {
47
let id = device
48
.id()
49
.ok()
50
.map(|id| id.1)
51
.unwrap_or_default();
47
let id = device.id().ok().map(|id| id.1).unwrap_or_default();
52
48
let name = device
53
49
.description()
54
50
.ok()
@@ -57,7 +53,8 @@ fn open_sink() -> Result<rodio::MixerDeviceSink, String> {
57
53
device_matches_key(&id, &name, key)
58
54
})
59
55
{
60
match rodio::DeviceSinkBuilder::from_device(device).and_then(|builder| builder.open_stream())
56
match rodio::DeviceSinkBuilder::from_device(device)
57
.and_then(|builder| builder.open_stream())
61
58
{
62
59
Ok(sink) => return Ok(sink),
63
60
Err(error) => crate::diagnostics::record(format!(
@@ -132,15 +129,27 @@ mod tests {
132
129
133
130
#[test]
134
131
fn call_output_keys_match_cpal_ids_and_friendly_names() {
135
assert!(device_matches_key("sink-a", "Front Speakers", "Front Speakers"));
132
assert!(device_matches_key(
133
"sink-a",
134
"Front Speakers",
135
"Front Speakers"
136
));
136
137
assert!(device_matches_key("sink-a", "Front Speakers", "sink-a"));
137
assert!(device_matches_key("sink-a", "Front Speakers", "front speakers"));
138
assert!(device_matches_key(
139
"sink-a",
140
"Front Speakers",
141
"front speakers"
142
));
138
143
assert!(device_matches_key(
139
144
"alsa_output.pci-0000_00_1f.3.analog-stereo",
140
145
"Built-in Audio Analog Stereo",
141
146
"alsa_output.pci-0000_00_1f.3.analog-stereo"
142
147
));
143
assert!(!device_matches_key("sink-a", "Front Speakers", "Headphones"));
148
assert!(!device_matches_key(
149
"sink-a",
150
"Front Speakers",
151
"Headphones"
152
));
144
153
assert!(!device_matches_key("id", "Speaker", ""));
145
154
}
146
155
@@ -44,11 +44,7 @@ fn open_sink() -> Result<rodio::MixerDeviceSink, String> {44
.into_iter()44
.into_iter()45
.flatten()45
.flatten()46
.find(|device| {46
.find(|device| {47
let id = device47
let id = device.id().ok().map(|id| id.1).unwrap_or_default();48
.id()49
.ok()50
.map(|id| id.1)51
.unwrap_or_default();52
let name = device48
let name = device53
.description()49
.description()54
.ok()50
.ok()@@ -57,7 +53,8 @@ fn open_sink() -> Result<rodio::MixerDeviceSink, String> {57
device_matches_key(&id, &name, key)53
device_matches_key(&id, &name, key)58
})54
})59
{55
{60
match rodio::DeviceSinkBuilder::from_device(device).and_then(|builder| builder.open_stream())56
match rodio::DeviceSinkBuilder::from_device(device)57
.and_then(|builder| builder.open_stream())61
{58
{62
Ok(sink) => return Ok(sink),59
Ok(sink) => return Ok(sink),63
Err(error) => crate::diagnostics::record(format!(60
Err(error) => crate::diagnostics::record(format!(@@ -132,15 +129,27 @@ mod tests {132
129
133
#[test]130
#[test]134
fn call_output_keys_match_cpal_ids_and_friendly_names() {131
fn call_output_keys_match_cpal_ids_and_friendly_names() {135
assert!(device_matches_key("sink-a", "Front Speakers", "Front Speakers"));132
assert!(device_matches_key(133
"sink-a",134
"Front Speakers",135
"Front Speakers"136
));136
assert!(device_matches_key("sink-a", "Front Speakers", "sink-a"));137
assert!(device_matches_key("sink-a", "Front Speakers", "sink-a"));137
assert!(device_matches_key("sink-a", "Front Speakers", "front speakers"));138
assert!(device_matches_key(139
"sink-a",140
"Front Speakers",141
"front speakers"142
));138
assert!(device_matches_key(143
assert!(device_matches_key(139
"alsa_output.pci-0000_00_1f.3.analog-stereo",144
"alsa_output.pci-0000_00_1f.3.analog-stereo",140
"Built-in Audio Analog Stereo",145
"Built-in Audio Analog Stereo",141
"alsa_output.pci-0000_00_1f.3.analog-stereo"146
"alsa_output.pci-0000_00_1f.3.analog-stereo"142
));147
));143
assert!(!device_matches_key("sink-a", "Front Speakers", "Headphones"));148
assert!(!device_matches_key(149
"sink-a",150
"Front Speakers",151
"Headphones"152
));144
assert!(!device_matches_key("id", "Speaker", ""));153
assert!(!device_matches_key("id", "Speaker", ""));145
}154
}146
155
@@ -158,10 +158,6 @@ pub struct AppState {
158
158
pub saved: SavedSet,
159
159
pub call_history: Vec<teams_core::CallLogEntry>,
160
160
pub calendar_events: Vec<chatsvc::CalendarEvent>,
161
/// Authorize URL while Google OAuth waits on the loopback redirect.
162
pub google_connect_pending: Option<String>,
163
/// Bumped on cancel so a late loopback result is discarded.
164
pub google_connect_generation: u64,
165
161
pub calendar_nudge: Option<tokio::sync::mpsc::UnboundedSender<()>>,
166
162
pub calls_list: crate::call::CallsList,
167
163
pub speed_dial: Vec<crate::call::SpeedDialEntry>,
@@ -326,8 +322,6 @@ impl AppState {
326
322
saved: SavedSet::default(),
327
323
call_history: Vec::new(),
328
324
calendar_events: Vec::new(),
329
google_connect_pending: None,
330
google_connect_generation: 0,
331
325
calendar_nudge: None,
332
326
calls_list: crate::call::CallsList::default(),
333
327
speed_dial,
@@ -158,10 +158,6 @@ pub struct AppState {158
pub saved: SavedSet,158
pub saved: SavedSet,159
pub call_history: Vec<teams_core::CallLogEntry>,159
pub call_history: Vec<teams_core::CallLogEntry>,160
pub calendar_events: Vec<chatsvc::CalendarEvent>,160
pub calendar_events: Vec<chatsvc::CalendarEvent>,161
/// Authorize URL while Google OAuth waits on the loopback redirect.162
pub google_connect_pending: Option<String>,163
/// Bumped on cancel so a late loopback result is discarded.164
pub google_connect_generation: u64,165
pub calendar_nudge: Option<tokio::sync::mpsc::UnboundedSender<()>>,161
pub calendar_nudge: Option<tokio::sync::mpsc::UnboundedSender<()>>,166
pub calls_list: crate::call::CallsList,162
pub calls_list: crate::call::CallsList,167
pub speed_dial: Vec<crate::call::SpeedDialEntry>,163
pub speed_dial: Vec<crate::call::SpeedDialEntry>,@@ -326,8 +322,6 @@ impl AppState {326
saved: SavedSet::default(),322
saved: SavedSet::default(),327
call_history: Vec::new(),323
call_history: Vec::new(),328
calendar_events: Vec::new(),324
calendar_events: Vec::new(),329
google_connect_pending: None,330
google_connect_generation: 0,331
calendar_nudge: None,325
calendar_nudge: None,332
calls_list: crate::call::CallsList::default(),326
calls_list: crate::call::CallsList::default(),333
speed_dial,327
speed_dial,@@ -26,10 +26,7 @@ fn slot() -> &'static Mutex<BrowserSignInState> {
26
26
}
27
27
28
28
pub fn current() -> BrowserSignInState {
29
slot()
30
.lock()
31
.map(|guard| guard.clone())
32
.unwrap_or_default()
29
slot().lock().map(|guard| guard.clone()).unwrap_or_default()
33
30
}
34
31
35
32
pub fn set(state: BrowserSignInState) {
@@ -26,10 +26,7 @@ fn slot() -> &'static Mutex<BrowserSignInState> {26
}26
}27
27
28
pub fn current() -> BrowserSignInState {28
pub fn current() -> BrowserSignInState {29
slot()29
slot().lock().map(|guard| guard.clone()).unwrap_or_default()30
.lock()31
.map(|guard| guard.clone())32
.unwrap_or_default()33
}30
}34
31
35
pub fn set(state: BrowserSignInState) {32
pub fn set(state: BrowserSignInState) {@@ -118,11 +118,10 @@ impl AppState {
118
118
return;
119
119
}
120
120
};
121
this
122
.update(cx, |state, cx| {
123
crate::external_browser::open_url(cx, &state.store, &authorize_url);
124
})
125
.ok();
121
this.update(cx, |state, cx| {
122
crate::external_browser::open_url(cx, &state.store, &authorize_url);
123
})
124
.ok();
126
125
let finished = runtime::spawn(async move {
127
126
finish_google_connect(oauth, pending, listener, store).await
128
127
});
@@ -118,11 +118,10 @@ impl AppState {118
return;118
return;119
}119
}120
};120
};121
this121
this.update(cx, |state, cx| {122
.update(cx, |state, cx| {122
crate::external_browser::open_url(cx, &state.store, &authorize_url);123
crate::external_browser::open_url(cx, &state.store, &authorize_url);123
})124
})124
.ok();125
.ok();126
let finished = runtime::spawn(async move {125
let finished = runtime::spawn(async move {127
finish_google_connect(oauth, pending, listener, store).await126
finish_google_connect(oauth, pending, listener, store).await128
});127
});@@ -4,6 +4,7 @@
4
4
5
5
use std::path::{Path, PathBuf};
6
6
use std::process::Command;
7
use std::sync::LazyLock;
7
8
8
9
use gpui_kit::App;
9
10
use store::Store;
@@ -51,7 +52,9 @@ pub fn open_url(cx: &mut App, store: &Store, url: &str) {
51
52
match load(store) {
52
53
ExternalBrowser::System => cx.open_url(url),
53
54
ExternalBrowser::Program(program) => {
54
let known = available_choices().iter().any(|choice| choice.id == program);
55
let known = available_choices()
56
.iter()
57
.any(|choice| choice.id == program);
55
58
if !known || launch_program(&program, url).is_err() {
56
59
cx.open_url(url);
57
60
}
@@ -76,7 +79,13 @@ fn looks_like_app_name(program: &str) -> bool {
76
79
!program.contains('/') && program.chars().any(|c| c.is_uppercase() || c == ' ')
77
80
}
78
81
79
pub fn available_choices() -> Vec<BrowserChoice> {
82
static CHOICES: LazyLock<Vec<BrowserChoice>> = LazyLock::new(discover_choices);
83
84
pub fn available_choices() -> &'static [BrowserChoice] {
85
&CHOICES
86
}
87
88
fn discover_choices() -> Vec<BrowserChoice> {
80
89
let mut choices = vec![BrowserChoice {
81
90
id: SYSTEM_VALUE.to_owned(),
82
91
label: SYSTEM_VALUE.to_owned(),
@@ -4,6 +4,7 @@4
4
5
use std::path::{Path, PathBuf};5
use std::path::{Path, PathBuf};6
use std::process::Command;6
use std::process::Command;7
use std::sync::LazyLock;7
8
8
use gpui_kit::App;9
use gpui_kit::App;9
use store::Store;10
use store::Store;@@ -51,7 +52,9 @@ pub fn open_url(cx: &mut App, store: &Store, url: &str) {51
match load(store) {52
match load(store) {52
ExternalBrowser::System => cx.open_url(url),53
ExternalBrowser::System => cx.open_url(url),53
ExternalBrowser::Program(program) => {54
ExternalBrowser::Program(program) => {54
let known = available_choices().iter().any(|choice| choice.id == program);55
let known = available_choices()56
.iter()57
.any(|choice| choice.id == program);55
if !known || launch_program(&program, url).is_err() {58
if !known || launch_program(&program, url).is_err() {56
cx.open_url(url);59
cx.open_url(url);57
}60
}@@ -76,7 +79,13 @@ fn looks_like_app_name(program: &str) -> bool {76
!program.contains('/') && program.chars().any(|c| c.is_uppercase() || c == ' ')79
!program.contains('/') && program.chars().any(|c| c.is_uppercase() || c == ' ')77
}80
}78
81
79
pub fn available_choices() -> Vec<BrowserChoice> {82
static CHOICES: LazyLock<Vec<BrowserChoice>> = LazyLock::new(discover_choices);83
84
pub fn available_choices() -> &'static [BrowserChoice] {85
&CHOICES86
}87
88
fn discover_choices() -> Vec<BrowserChoice> {80
let mut choices = vec![BrowserChoice {89
let mut choices = vec![BrowserChoice {81
id: SYSTEM_VALUE.to_owned(),90
id: SYSTEM_VALUE.to_owned(),82
label: SYSTEM_VALUE.to_owned(),91
label: SYSTEM_VALUE.to_owned(),@@ -7,7 +7,6 @@ pub mod backend;
7
7
pub mod banner_image;
8
8
pub mod browser_sign_in;
9
9
pub mod calendar_accounts_actions;
10
pub mod external_browser;
11
10
pub mod call;
12
11
pub mod call_rows;
13
12
pub mod card_actions;
@@ -28,6 +27,7 @@ pub mod demo;
28
27
pub mod demo_meetings;
29
28
pub mod demo_profiles;
30
29
pub mod emoji;
30
pub mod external_browser;
31
31
pub mod find_in_chat;
32
32
pub mod forward_selection;
33
33
pub mod gifs;
@@ -7,7 +7,6 @@ pub mod backend;7
pub mod banner_image;7
pub mod banner_image;8
pub mod browser_sign_in;8
pub mod browser_sign_in;9
pub mod calendar_accounts_actions;9
pub mod calendar_accounts_actions;10
pub mod external_browser;11
pub mod call;10
pub mod call;12
pub mod call_rows;11
pub mod call_rows;13
pub mod card_actions;12
pub mod card_actions;@@ -28,6 +27,7 @@ pub mod demo;28
pub mod demo_meetings;27
pub mod demo_meetings;29
pub mod demo_profiles;28
pub mod demo_profiles;30
pub mod emoji;29
pub mod emoji;30
pub mod external_browser;31
pub mod find_in_chat;31
pub mod find_in_chat;32
pub mod forward_selection;32
pub mod forward_selection;33
pub mod gifs;33
pub mod gifs;@@ -75,7 +75,10 @@ mod tests {
75
75
fn ui_locale_auth_splash_keys() {
76
76
let _guard = locale_test_lock();
77
77
apply_locale("en");
78
assert_eq!(tr("auth.splash.opening_browser"), "Opening the browser for sign-in…");
78
assert_eq!(
79
tr("auth.splash.opening_browser"),
80
"Opening the browser for sign-in…"
81
);
79
82
apply_locale("de");
80
83
assert!(tr("auth.splash.awaiting_browser").contains("Browser"));
81
84
}
@@ -75,7 +75,10 @@ mod tests {75
fn ui_locale_auth_splash_keys() {75
fn ui_locale_auth_splash_keys() {76
let _guard = locale_test_lock();76
let _guard = locale_test_lock();77
apply_locale("en");77
apply_locale("en");78
assert_eq!(tr("auth.splash.opening_browser"), "Opening the browser for sign-in…");78
assert_eq!(79
tr("auth.splash.opening_browser"),80
"Opening the browser for sign-in…"81
);79
apply_locale("de");82
apply_locale("de");80
assert!(tr("auth.splash.awaiting_browser").contains("Browser"));83
assert!(tr("auth.splash.awaiting_browser").contains("Browser"));81
}84
}@@ -147,7 +147,6 @@ pub fn start(endpoint: &str) -> Arc<dyn session::Transport> {
147
147
let headless_notify = Arc::new(Notify::new());
148
148
let supervisor_browser = browser.clone();
149
149
let supervisor_notify = headless_notify.clone();
150
publish_sign_in(BrowserSignInState::Opening);
151
150
app_base::runtime::handle().spawn(async move {
152
151
let first_run = !Path::new(&supervisor_browser.config().profile).exists();
153
152
let outcome = if first_run {
@@ -147,7 +147,6 @@ pub fn start(endpoint: &str) -> Arc<dyn session::Transport> {147
let headless_notify = Arc::new(Notify::new());147
let headless_notify = Arc::new(Notify::new());148
let supervisor_browser = browser.clone();148
let supervisor_browser = browser.clone();149
let supervisor_notify = headless_notify.clone();149
let supervisor_notify = headless_notify.clone();150
publish_sign_in(BrowserSignInState::Opening);151
app_base::runtime::handle().spawn(async move {150
app_base::runtime::handle().spawn(async move {152
let first_run = !Path::new(&supervisor_browser.config().profile).exists();151
let first_run = !Path::new(&supervisor_browser.config().profile).exists();153
let outcome = if first_run {152
let outcome = if first_run {@@ -107,18 +107,18 @@ fn external_browser_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {
107
107
108
108
let selected = external_browser::load(&app.read(cx).store);
109
109
let current_label = external_browser::available_choices()
110
.into_iter()
110
.iter()
111
111
.find(|choice| choice.id == selected.id())
112
112
.map(|choice| {
113
113
if external_browser::is_system_id(&choice.id) {
114
114
tr("settings.general.external_browser_system")
115
115
} else {
116
choice.label
116
choice.label.clone()
117
117
}
118
118
})
119
119
.unwrap_or_else(|| tr("settings.general.external_browser_system"));
120
120
let choices: Vec<Choice> = external_browser::available_choices()
121
.into_iter()
121
.iter()
122
122
.map(|choice| {
123
123
let label = if external_browser::is_system_id(&choice.id) {
124
124
tr("settings.general.external_browser_system")
@@ -126,7 +126,7 @@ fn external_browser_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {
126
126
choice.label.clone()
127
127
};
128
128
let is_selected = selected.id() == choice.id;
129
let (app, id) = (app.clone(), choice.id);
129
let (app, id) = (app.clone(), choice.id.clone());
130
130
Choice::new(label, is_selected, move |cx| {
131
131
app.update(cx, |state, cx| {
132
132
let browser = if external_browser::is_system_id(&id) {
@@ -145,12 +145,7 @@ fn external_browser_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {
145
145
control_row(
146
146
tr("settings.general.external_browser"),
147
147
tr("settings.general.external_browser_detail"),
148
select(
149
"settings-external-browser",
150
current_label,
151
false,
152
choices,
153
),
148
select("settings-external-browser", current_label, false, choices),
154
149
)
155
150
.into_any_element(),
156
151
]
@@ -107,18 +107,18 @@ fn external_browser_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {107
107
108
let selected = external_browser::load(&app.read(cx).store);108
let selected = external_browser::load(&app.read(cx).store);109
let current_label = external_browser::available_choices()109
let current_label = external_browser::available_choices()110
.into_iter()110
.iter()111
.find(|choice| choice.id == selected.id())111
.find(|choice| choice.id == selected.id())112
.map(|choice| {112
.map(|choice| {113
if external_browser::is_system_id(&choice.id) {113
if external_browser::is_system_id(&choice.id) {114
tr("settings.general.external_browser_system")114
tr("settings.general.external_browser_system")115
} else {115
} else {116
choice.label116
choice.label.clone()117
}117
}118
})118
})119
.unwrap_or_else(|| tr("settings.general.external_browser_system"));119
.unwrap_or_else(|| tr("settings.general.external_browser_system"));120
let choices: Vec<Choice> = external_browser::available_choices()120
let choices: Vec<Choice> = external_browser::available_choices()121
.into_iter()121
.iter()122
.map(|choice| {122
.map(|choice| {123
let label = if external_browser::is_system_id(&choice.id) {123
let label = if external_browser::is_system_id(&choice.id) {124
tr("settings.general.external_browser_system")124
tr("settings.general.external_browser_system")@@ -126,7 +126,7 @@ fn external_browser_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {126
choice.label.clone()126
choice.label.clone()127
};127
};128
let is_selected = selected.id() == choice.id;128
let is_selected = selected.id() == choice.id;129
let (app, id) = (app.clone(), choice.id);129
let (app, id) = (app.clone(), choice.id.clone());130
Choice::new(label, is_selected, move |cx| {130
Choice::new(label, is_selected, move |cx| {131
app.update(cx, |state, cx| {131
app.update(cx, |state, cx| {132
let browser = if external_browser::is_system_id(&id) {132
let browser = if external_browser::is_system_id(&id) {@@ -145,12 +145,7 @@ fn external_browser_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {145
control_row(145
control_row(146
tr("settings.general.external_browser"),146
tr("settings.general.external_browser"),147
tr("settings.general.external_browser_detail"),147
tr("settings.general.external_browser_detail"),148
select(148
select("settings-external-browser", current_label, false, choices),149
"settings-external-browser",150
current_label,151
false,152
choices,153
),154
)149
)155
.into_any_element(),150
.into_any_element(),156
]151
]@@ -66,8 +66,8 @@ pub fn phase(facts: &StartupFacts) -> Phase {
66
66
if facts.elapsed >= GIVE_UP_AFTER && !(signing_in && !content_ready) {
67
67
return Phase::Ready;
68
68
}
69
let late_hint = (facts.elapsed >= HINT_AFTER && !content_ready)
70
.then(|| tr("auth.splash.first_start_hint"));
69
let late_hint =
70
(facts.elapsed >= HINT_AFTER && !content_ready).then(|| tr("auth.splash.first_start_hint"));
71
71
let loading = |status: String| Phase::Loading {
72
72
status,
73
73
running: true,
@@ -97,8 +97,8 @@ pub fn phase(facts: &StartupFacts) -> Phase {
97
97
}
98
98
99
99
fn browser_phase(facts: &StartupFacts) -> Option<Phase> {
100
let late_browser_hint = (facts.elapsed >= HINT_AFTER)
101
.then(|| tr("auth.splash.browser_still_loading_hint"));
100
let late_browser_hint =
101
(facts.elapsed >= HINT_AFTER).then(|| tr("auth.splash.browser_still_loading_hint"));
102
102
match facts.browser_sign_in {
103
103
BrowserSignInState::Idle => None,
104
104
BrowserSignInState::Opening => Some(Phase::Loading {
@@ -336,7 +336,7 @@ mod tests {
336
336
has_chats: true,
337
337
..facts(100, &online)
338
338
};
339
assert!(status(phase(&warm)).contains("Rusty Teams") || !status(phase(&warm)).is_empty());
339
assert_translated(&status(phase(&warm)));
340
340
let warm = StartupFacts {
341
341
has_chats: true,
342
342
..facts(450, &online)
@@ -395,8 +395,9 @@ mod tests {
395
395
fn browser_awaiting_sign_in_stops_the_bar() {
396
396
let connecting = ConnectionState::Connecting;
397
397
let awaiting = BrowserSignInState::AwaitingSignIn;
398
let Phase::Loading { running, status, .. } =
399
phase(&facts_with(2_000, &connecting, &awaiting))
398
let Phase::Loading {
399
running, status, ..
400
} = phase(&facts_with(2_000, &connecting, &awaiting))
400
401
else {
401
402
panic!("still loading")
402
403
};
@@ -408,8 +409,9 @@ mod tests {
408
409
fn browser_opening_keeps_the_bar_running() {
409
410
let connecting = ConnectionState::Connecting;
410
411
let opening = BrowserSignInState::Opening;
411
let Phase::Loading { running, status, .. } =
412
phase(&facts_with(2_000, &connecting, &opening))
412
let Phase::Loading {
413
running, status, ..
414
} = phase(&facts_with(2_000, &connecting, &opening))
413
415
else {
414
416
panic!("still loading")
415
417
};
@@ -425,7 +427,10 @@ mod tests {
425
427
has_chats: true,
426
428
..facts_with(450, &online, &awaiting)
427
429
};
428
let Phase::Loading { running, status, .. } = phase(&warm) else {
430
let Phase::Loading {
431
running, status, ..
432
} = phase(&warm)
433
else {
429
434
panic!("managed browser must keep splash over warm cache")
430
435
};
431
436
assert!(!running);
@@ -66,8 +66,8 @@ pub fn phase(facts: &StartupFacts) -> Phase {66
if facts.elapsed >= GIVE_UP_AFTER && !(signing_in && !content_ready) {66
if facts.elapsed >= GIVE_UP_AFTER && !(signing_in && !content_ready) {67
return Phase::Ready;67
return Phase::Ready;68
}68
}69
let late_hint = (facts.elapsed >= HINT_AFTER && !content_ready)69
let late_hint =70
.then(|| tr("auth.splash.first_start_hint"));70
(facts.elapsed >= HINT_AFTER && !content_ready).then(|| tr("auth.splash.first_start_hint"));71
let loading = |status: String| Phase::Loading {71
let loading = |status: String| Phase::Loading {72
status,72
status,73
running: true,73
running: true,@@ -97,8 +97,8 @@ pub fn phase(facts: &StartupFacts) -> Phase {97
}97
}98
98
99
fn browser_phase(facts: &StartupFacts) -> Option<Phase> {99
fn browser_phase(facts: &StartupFacts) -> Option<Phase> {100
let late_browser_hint = (facts.elapsed >= HINT_AFTER)100
let late_browser_hint =101
.then(|| tr("auth.splash.browser_still_loading_hint"));101
(facts.elapsed >= HINT_AFTER).then(|| tr("auth.splash.browser_still_loading_hint"));102
match facts.browser_sign_in {102
match facts.browser_sign_in {103
BrowserSignInState::Idle => None,103
BrowserSignInState::Idle => None,104
BrowserSignInState::Opening => Some(Phase::Loading {104
BrowserSignInState::Opening => Some(Phase::Loading {@@ -336,7 +336,7 @@ mod tests {336
has_chats: true,336
has_chats: true,337
..facts(100, &online)337
..facts(100, &online)338
};338
};339
assert!(status(phase(&warm)).contains("Rusty Teams") || !status(phase(&warm)).is_empty());339
assert_translated(&status(phase(&warm)));340
let warm = StartupFacts {340
let warm = StartupFacts {341
has_chats: true,341
has_chats: true,342
..facts(450, &online)342
..facts(450, &online)@@ -395,8 +395,9 @@ mod tests {395
fn browser_awaiting_sign_in_stops_the_bar() {395
fn browser_awaiting_sign_in_stops_the_bar() {396
let connecting = ConnectionState::Connecting;396
let connecting = ConnectionState::Connecting;397
let awaiting = BrowserSignInState::AwaitingSignIn;397
let awaiting = BrowserSignInState::AwaitingSignIn;398
let Phase::Loading { running, status, .. } =398
let Phase::Loading {399
phase(&facts_with(2_000, &connecting, &awaiting))399
running, status, ..400
} = phase(&facts_with(2_000, &connecting, &awaiting))400
else {401
else {401
panic!("still loading")402
panic!("still loading")402
};403
};@@ -408,8 +409,9 @@ mod tests {408
fn browser_opening_keeps_the_bar_running() {409
fn browser_opening_keeps_the_bar_running() {409
let connecting = ConnectionState::Connecting;410
let connecting = ConnectionState::Connecting;410
let opening = BrowserSignInState::Opening;411
let opening = BrowserSignInState::Opening;411
let Phase::Loading { running, status, .. } =412
let Phase::Loading {412
phase(&facts_with(2_000, &connecting, &opening))413
running, status, ..414
} = phase(&facts_with(2_000, &connecting, &opening))413
else {415
else {414
panic!("still loading")416
panic!("still loading")415
};417
};@@ -425,7 +427,10 @@ mod tests {425
has_chats: true,427
has_chats: true,426
..facts_with(450, &online, &awaiting)428
..facts_with(450, &online, &awaiting)427
};429
};428
let Phase::Loading { running, status, .. } = phase(&warm) else {430
let Phase::Loading {431
running, status, ..432
} = phase(&warm)433
else {429
panic!("managed browser must keep splash over warm cache")434
panic!("managed browser must keep splash over warm cache")430
};435
};431
assert!(!running);436
assert!(!running);@@ -100,28 +100,26 @@ fn is_app_emoji_fontconfig(value: &std::ffi::OsStr) -> bool {
100
100
}
101
101
102
102
fn strip_app_fontconfig(command: &mut Command) {
103
for key in ["FONTCONFIG_FILE", "FONTCONFIG_PATH"] {
104
let Some(value) = std::env::var_os(key) else {
105
continue;
106
};
107
if is_app_emoji_fontconfig(&value) {
108
command.env_remove(key);
109
}
103
for key in app_fontconfig_keys(|key| std::env::var_os(key)) {
104
command.env_remove(key);
110
105
}
111
106
}
112
107
108
fn app_fontconfig_keys(lookup: impl Fn(&str) -> Option<std::ffi::OsString>) -> Vec<&'static str> {
109
["FONTCONFIG_FILE", "FONTCONFIG_PATH"]
110
.into_iter()
111
.filter(|key| lookup(key).is_some_and(|value| is_app_emoji_fontconfig(&value)))
112
.collect()
113
}
114
113
115
fn chrome_major(platform: Platform, executable: &Path) -> u32 {
114
116
let detected = match platform {
115
117
Platform::Linux | Platform::Macos => {
116
118
let mut command = Command::new(executable);
117
119
strip_app_fontconfig(&mut command);
118
command
119
.arg("--version")
120
.output()
121
.ok()
122
.and_then(|output| {
123
major_from_version_output(&String::from_utf8_lossy(&output.stdout))
124
})
120
command.arg("--version").output().ok().and_then(|output| {
121
major_from_version_output(&String::from_utf8_lossy(&output.stdout))
122
})
125
123
}
126
124
Platform::Windows | Platform::Wsl => executable
127
125
.parent()
@@ -287,36 +285,12 @@ mod tests {
287
285
288
286
#[test]
289
287
fn chrome_drops_only_app_emoji_fontconfig() {
290
assert!(is_app_emoji_fontconfig(std::ffi::OsStr::new(
291
"/tmp/cache/fontconfig-emoji/fonts.conf"
292
)));
293
assert!(!is_app_emoji_fontconfig(std::ffi::OsStr::new(
294
"/etc/fonts/fonts.conf"
295
)));
296
297
let previous_file = std::env::var_os("FONTCONFIG_FILE");
298
let previous_path = std::env::var_os("FONTCONFIG_PATH");
299
// SAFETY: test-only env mutation around a synchronous strip call.
300
unsafe {
301
std::env::set_var(
302
"FONTCONFIG_FILE",
303
"/tmp/cache/fontconfig-emoji/fonts.conf",
304
);
305
std::env::set_var("FONTCONFIG_PATH", "/etc/fonts");
306
}
307
let mut command = Command::new("true");
308
strip_app_fontconfig(&mut command);
309
// App marker path is removed; user FONTCONFIG_PATH is left alone.
310
let _ = command;
311
unsafe {
312
match previous_file {
313
Some(value) => std::env::set_var("FONTCONFIG_FILE", value),
314
None => std::env::remove_var("FONTCONFIG_FILE"),
315
}
316
match previous_path {
317
Some(value) => std::env::set_var("FONTCONFIG_PATH", value),
318
None => std::env::remove_var("FONTCONFIG_PATH"),
319
}
320
}
288
let keys = app_fontconfig_keys(|key| match key {
289
"FONTCONFIG_FILE" => Some("/tmp/cache/fontconfig-emoji/fonts.conf".into()),
290
"FONTCONFIG_PATH" => Some("/etc/fonts".into()),
291
_ => None,
292
});
293
assert_eq!(keys, vec!["FONTCONFIG_FILE"]);
294
assert!(app_fontconfig_keys(|_| None).is_empty());
321
295
}
322
296
}
@@ -100,28 +100,26 @@ fn is_app_emoji_fontconfig(value: &std::ffi::OsStr) -> bool {100
}100
}101
101
102
fn strip_app_fontconfig(command: &mut Command) {102
fn strip_app_fontconfig(command: &mut Command) {103
for key in ["FONTCONFIG_FILE", "FONTCONFIG_PATH"] {103
for key in app_fontconfig_keys(|key| std::env::var_os(key)) {104
let Some(value) = std::env::var_os(key) else {104
command.env_remove(key);105
continue;106
};107
if is_app_emoji_fontconfig(&value) {108
command.env_remove(key);109
}110
}105
}111
}106
}112
107
108
fn app_fontconfig_keys(lookup: impl Fn(&str) -> Option<std::ffi::OsString>) -> Vec<&'static str> {109
["FONTCONFIG_FILE", "FONTCONFIG_PATH"]110
.into_iter()111
.filter(|key| lookup(key).is_some_and(|value| is_app_emoji_fontconfig(&value)))112
.collect()113
}114
113
fn chrome_major(platform: Platform, executable: &Path) -> u32 {115
fn chrome_major(platform: Platform, executable: &Path) -> u32 {114
let detected = match platform {116
let detected = match platform {115
Platform::Linux | Platform::Macos => {117
Platform::Linux | Platform::Macos => {116
let mut command = Command::new(executable);118
let mut command = Command::new(executable);117
strip_app_fontconfig(&mut command);119
strip_app_fontconfig(&mut command);118
command120
command.arg("--version").output().ok().and_then(|output| {119
.arg("--version")121
major_from_version_output(&String::from_utf8_lossy(&output.stdout))120
.output()122
})121
.ok()122
.and_then(|output| {123
major_from_version_output(&String::from_utf8_lossy(&output.stdout))124
})125
}123
}126
Platform::Windows | Platform::Wsl => executable124
Platform::Windows | Platform::Wsl => executable127
.parent()125
.parent()@@ -287,36 +285,12 @@ mod tests {287
285
288
#[test]286
#[test]289
fn chrome_drops_only_app_emoji_fontconfig() {287
fn chrome_drops_only_app_emoji_fontconfig() {290
assert!(is_app_emoji_fontconfig(std::ffi::OsStr::new(288
let keys = app_fontconfig_keys(|key| match key {291
"/tmp/cache/fontconfig-emoji/fonts.conf"289
"FONTCONFIG_FILE" => Some("/tmp/cache/fontconfig-emoji/fonts.conf".into()),292
)));290
"FONTCONFIG_PATH" => Some("/etc/fonts".into()),293
assert!(!is_app_emoji_fontconfig(std::ffi::OsStr::new(291
_ => None,294
"/etc/fonts/fonts.conf"292
});295
)));293
assert_eq!(keys, vec!["FONTCONFIG_FILE"]);296
294
assert!(app_fontconfig_keys(|_| None).is_empty());297
let previous_file = std::env::var_os("FONTCONFIG_FILE");298
let previous_path = std::env::var_os("FONTCONFIG_PATH");299
// SAFETY: test-only env mutation around a synchronous strip call.300
unsafe {301
std::env::set_var(302
"FONTCONFIG_FILE",303
"/tmp/cache/fontconfig-emoji/fonts.conf",304
);305
std::env::set_var("FONTCONFIG_PATH", "/etc/fonts");306
}307
let mut command = Command::new("true");308
strip_app_fontconfig(&mut command);309
// App marker path is removed; user FONTCONFIG_PATH is left alone.310
let _ = command;311
unsafe {312
match previous_file {313
Some(value) => std::env::set_var("FONTCONFIG_FILE", value),314
None => std::env::remove_var("FONTCONFIG_FILE"),315
}316
match previous_path {317
Some(value) => std::env::set_var("FONTCONFIG_PATH", value),318
None => std::env::remove_var("FONTCONFIG_PATH"),319
}320
}321
}295
}322
}296
}@@ -35,7 +35,7 @@ impl Default for WatchdogConfig {
35
35
died_wait: Duration::from_millis(1000),
36
36
probe_interval: Duration::from_secs(30),
37
37
probe_failures: 2,
38
login_grace: Duration::from_secs(1),
38
login_grace: Duration::from_secs(4),
39
39
}
40
40
}
41
41
}
@@ -35,7 +35,7 @@ impl Default for WatchdogConfig {35
died_wait: Duration::from_millis(1000),35
died_wait: Duration::from_millis(1000),36
probe_interval: Duration::from_secs(30),36
probe_interval: Duration::from_secs(30),37
probe_failures: 2,37
probe_failures: 2,38
login_grace: Duration::from_secs(1),38
login_grace: Duration::from_secs(4),39
}39
}40
}40
}41
}41
}@@ -1654,7 +1654,10 @@ mod tests {
1654
1654
fn signaling_failure_detail_keeps_status_and_a_short_body() {
1655
1655
let detail = signaling_failure_detail(400, &"x".repeat(300));
1656
1656
assert!(detail.starts_with("HTTP 400 "));
1657
assert_eq!(detail.chars().count(), "HTTP 400 ".chars().count() + FAILURE_BODY_CHARS);
1657
assert_eq!(
1658
detail.chars().count(),
1659
"HTTP 400 ".chars().count() + FAILURE_BODY_CHARS
1660
);
1658
1661
}
1659
1662
1660
1663
#[test]
@@ -1654,7 +1654,10 @@ mod tests {1654
fn signaling_failure_detail_keeps_status_and_a_short_body() {1654
fn signaling_failure_detail_keeps_status_and_a_short_body() {1655
let detail = signaling_failure_detail(400, &"x".repeat(300));1655
let detail = signaling_failure_detail(400, &"x".repeat(300));1656
assert!(detail.starts_with("HTTP 400 "));1656
assert!(detail.starts_with("HTTP 400 "));1657
assert_eq!(detail.chars().count(), "HTTP 400 ".chars().count() + FAILURE_BODY_CHARS);1657
assert_eq!(1658
detail.chars().count(),1659
"HTTP 400 ".chars().count() + FAILURE_BODY_CHARS1660
);1658
}1661
}1659
1662
1660
#[test]1663
#[test]@@ -84,7 +84,7 @@ h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>
84
84
<body>
85
85
<h1>Signed in</h1>
86
86
<p>You can close this window and return to Rusty Teams.</p>
87
<p lang="de">Angemeldet. Sie können dieses Fenster schliessen und zu Rusty Teams zurückkehren.</p>
87
<p lang="de">Angemeldet. Sie können dieses Fenster schließen und zu Rusty Teams zurückkehren.</p>
88
88
</body>
89
89
</html>"#;
90
90
@@ -97,7 +97,7 @@ h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>
97
97
<body>
98
98
<h1>Sign-in did not finish</h1>
99
99
<p>You can close this window and try again in Rusty Teams.</p>
100
<p lang="de">Die Anmeldung ist nicht abgeschlossen. Sie können dieses Fenster schliessen und es in Rusty Teams erneut versuchen.</p>
100
<p lang="de">Die Anmeldung ist nicht abgeschlossen. Sie können dieses Fenster schließen und es in Rusty Teams erneut versuchen.</p>
101
101
</body>
102
102
</html>"#;
103
103
@@ -84,7 +84,7 @@ h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>84
<body>84
<body>85
<h1>Signed in</h1>85
<h1>Signed in</h1>86
<p>You can close this window and return to Rusty Teams.</p>86
<p>You can close this window and return to Rusty Teams.</p>87
<p lang="de">Angemeldet. Sie können dieses Fenster schliessen und zu Rusty Teams zurückkehren.</p>87
<p lang="de">Angemeldet. Sie können dieses Fenster schließen und zu Rusty Teams zurückkehren.</p>88
</body>88
</body>89
</html>"#;89
</html>"#;90
90
@@ -97,7 +97,7 @@ h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>97
<body>97
<body>98
<h1>Sign-in did not finish</h1>98
<h1>Sign-in did not finish</h1>99
<p>You can close this window and try again in Rusty Teams.</p>99
<p>You can close this window and try again in Rusty Teams.</p>100
<p lang="de">Die Anmeldung ist nicht abgeschlossen. Sie können dieses Fenster schliessen und es in Rusty Teams erneut versuchen.</p>100
<p lang="de">Die Anmeldung ist nicht abgeschlossen. Sie können dieses Fenster schließen und es in Rusty Teams erneut versuchen.</p>101
</body>101
</body>102
</html>"#;102
</html>"#;103
103
@@ -220,8 +220,8 @@ mod tests {
220
220
221
221
#[test]
222
222
fn resolve_falls_back_to_compile_when_runtime_empty() {
223
let oauth = resolve_oauth(Some(" "), None, Some("compile-id"), Some("compile-secret"))
224
.unwrap();
223
let oauth =
224
resolve_oauth(Some(" "), None, Some("compile-id"), Some("compile-secret")).unwrap();
225
225
assert_eq!(oauth.client_id, "compile-id");
226
226
assert_eq!(oauth.client_secret, "compile-secret");
227
227
}
@@ -220,8 +220,8 @@ mod tests {220
220
221
#[test]221
#[test]222
fn resolve_falls_back_to_compile_when_runtime_empty() {222
fn resolve_falls_back_to_compile_when_runtime_empty() {223
let oauth = resolve_oauth(Some(" "), None, Some("compile-id"), Some("compile-secret"))223
let oauth =224
.unwrap();224
resolve_oauth(Some(" "), None, Some("compile-id"), Some("compile-secret")).unwrap();225
assert_eq!(oauth.client_id, "compile-id");225
assert_eq!(oauth.client_id, "compile-id");226
assert_eq!(oauth.client_secret, "compile-secret");226
assert_eq!(oauth.client_secret, "compile-secret");227
}227
}@@ -126,7 +126,11 @@ pub fn create_one_to_one_request(region: &str, member_mris: &[String]) -> Reques
126
126
}
127
127
128
128
fn created_thread_id(body: &Value) -> Option<String> {
129
if let Some(id) = body.get("id").and_then(Value::as_str).filter(|id| id.starts_with("19:")) {
129
if let Some(id) = body
130
.get("id")
131
.and_then(Value::as_str)
132
.filter(|id| id.starts_with("19:"))
133
{
130
134
return Some(id.to_owned());
131
135
}
132
136
if let Some(id) = body
@@ -229,8 +233,7 @@ impl<T: MessageTransport> ThreadMembers<T> {
229
233
created_thread_id(&answer.body).ok_or_else(|| {
230
234
Error::UnexpectedAnswer(format!(
231
235
"thread creation has no location (HTTP {} {})",
232
answer.status,
233
answer.body
236
answer.status, answer.body
234
237
))
235
238
})
236
239
}
@@ -126,7 +126,11 @@ pub fn create_one_to_one_request(region: &str, member_mris: &[String]) -> Reques126
}126
}127
127
128
fn created_thread_id(body: &Value) -> Option<String> {128
fn created_thread_id(body: &Value) -> Option<String> {129
if let Some(id) = body.get("id").and_then(Value::as_str).filter(|id| id.starts_with("19:")) {129
if let Some(id) = body130
.get("id")131
.and_then(Value::as_str)132
.filter(|id| id.starts_with("19:"))133
{130
return Some(id.to_owned());134
return Some(id.to_owned());131
}135
}132
if let Some(id) = body136
if let Some(id) = body@@ -229,8 +233,7 @@ impl<T: MessageTransport> ThreadMembers<T> {229
created_thread_id(&answer.body).ok_or_else(|| {233
created_thread_id(&answer.body).ok_or_else(|| {230
Error::UnexpectedAnswer(format!(234
Error::UnexpectedAnswer(format!(231
"thread creation has no location (HTTP {} {})",235
"thread creation has no location (HTTP {} {})",232
answer.status,236
answer.status, answer.body233
answer.body234
))237
))235
})238
})236
}239
}