BlueGit

ict rusty-teams

feat(calendar): view settings in Settings › Calendar

View section: default view, first day of week (regional or override),
work days as chips and work start/end (both saved to the mailbox),
time scale, and what Work week shows on a day off. Calendar search terms
are localized and covered by the search-term test; one new select is
covered by the layout guard.

Settings search tests now take the locale lock the i18n tests use; they
failed whenever a German locale test ran beside them.

Decision note 0016: work hours go to the mailbox, first day and time
scale stay local because Graph cannot reach the OWA options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Joachim Mild · pushed by metis

Authored 2026-11-15 · 2 weeks ago

Hash
550346085a7ca1ac81fddc9e9b37fff53b3d5da0
Parent
04540699
6 files changed +413 −48
crates/app/src/i18n.rs +8 −6
@@ -1,15 +1,17 @@
1 1 pub use app_base::ui_locale::{tr, tr_args};
2 2
3 /// Serialises tests that set the global UI language (`rust_i18n` keeps one locale per process).
3 4 #[cfg(test)]
4 mod tests {
5 use std::sync::{Mutex, MutexGuard};
5 pub(crate) fn locale_test_lock() -> std::sync::MutexGuard<'static, ()> {
6 static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
7 LOCK.lock().unwrap_or_else(|error| error.into_inner())
8 }
6 9
10 #[cfg(test)]
11 mod tests {
7 12 use app_base::ui_locale::{apply_locale, tr};
8 13
9 fn locale_test_lock() -> MutexGuard<'static, ()> {
10 static LOCK: Mutex<()> = Mutex::new(());
11 LOCK.lock().unwrap_or_else(|error| error.into_inner())
12 }
14 use super::locale_test_lock;
13 15
14 16 #[test]
15 17 fn ui_locale_settings_common_actions() {
@@ -1,15 +1,17 @@
1pub use app_base::ui_locale::{tr, tr_args};
1pub use app_base::ui_locale::{tr, tr_args};
2
2
3/// Serialises tests that set the global UI language (`rust_i18n` keeps one locale per process).
3#[cfg(test)]
4#[cfg(test)]
4mod tests {
5pub(crate) fn locale_test_lock() -> std::sync::MutexGuard<'static, ()> {
5 use std::sync::{Mutex, MutexGuard};
6 static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
7 LOCK.lock().unwrap_or_else(|error| error.into_inner())
8}
6
9
10#[cfg(test)]
11mod tests {
7 use app_base::ui_locale::{apply_locale, tr};
12 use app_base::ui_locale::{apply_locale, tr};
8
13
9 fn locale_test_lock() -> MutexGuard<'static, ()> {
14 use super::locale_test_lock;
10 static LOCK: Mutex<()> = Mutex::new(());
11 LOCK.lock().unwrap_or_else(|error| error.into_inner())
12 }
13
15
14 #[test]
16 #[test]
15 fn ui_locale_settings_common_actions() {
17 fn ui_locale_settings_common_actions() {
crates/app/src/layout_guard.rs +13 −7
@@ -1915,6 +1915,7 @@ mod frames {
1915 1915 const MENU_ITEMS_SCANNED: usize = 40;
1916 1916 const MENU_CHAT: &str = "demo-chat-release";
1917 1917 const THEME_SELECT: &str = "settings-theme";
1918 const CALENDAR_DEFAULT_VIEW_SELECT: &str = "settings-calendar-default-view";
1918 1919
1919 1920 struct MenuRow {
1920 1921 index: usize,
@@ -2136,17 +2137,22 @@ mod frames {
2136 2137
2137 2138 #[gpui_kit::test]
2138 2139 fn settings_select_list_lines_up_with_its_trigger(cx: &mut TestAppContext) {
2140 select_list_lines_up(cx, SettingsSection::Appearance, THEME_SELECT);
2141 }
2142
2143 #[gpui_kit::test]
2144 fn calendar_default_view_list_lines_up_with_its_trigger(cx: &mut TestAppContext) {
2145 select_list_lines_up(cx, SettingsSection::Calendar, CALENDAR_DEFAULT_VIEW_SELECT);
2146 }
2147
2148 fn select_list_lines_up(cx: &mut TestAppContext, section: SettingsSection, id: &str) {
2139 2149 let (handle, state) = mount(cx);
2140 2150 let mut visual = VisualTestContext::from_window(handle, cx);
2141 2151 visual.simulate_resize(size(px(1280.), px(800.)));
2142 visual.update(|_, cx| {
2143 state.update(cx, |state, cx| {
2144 state.open_settings(SettingsSection::Appearance, cx)
2145 })
2146 });
2147 let select: &'static str = Box::leak(select_selector(THEME_SELECT).into_boxed_str());
2152 visual.update(|_, cx| state.update(cx, |state, cx| state.open_settings(section, cx)));
2153 let select: &'static str = Box::leak(select_selector(id).into_boxed_str());
2148 2154 collect(&mut visual, Some(select));
2149 let trigger = visual.debug_bounds(select).expect("theme select rendered");
2155 let trigger = visual.debug_bounds(select).expect("select rendered");
2150 2156 visual.simulate_click(trigger.center(), Default::default());
2151 2157 collect(&mut visual, Some(MENU));
2152 2158 let menu = visual.debug_bounds(MENU).expect("list rendered");
@@ -1915,6 +1915,7 @@ mod frames {
1915 const MENU_ITEMS_SCANNED: usize = 40;
1915 const MENU_ITEMS_SCANNED: usize = 40;
1916 const MENU_CHAT: &str = "demo-chat-release";
1916 const MENU_CHAT: &str = "demo-chat-release";
1917 const THEME_SELECT: &str = "settings-theme";
1917 const THEME_SELECT: &str = "settings-theme";
1918 const CALENDAR_DEFAULT_VIEW_SELECT: &str = "settings-calendar-default-view";
1918
1919
1919 struct MenuRow {
1920 struct MenuRow {
1920 index: usize,
1921 index: usize,
@@ -2136,17 +2137,22 @@ mod frames {
2136
2137
2137 #[gpui_kit::test]
2138 #[gpui_kit::test]
2138 fn settings_select_list_lines_up_with_its_trigger(cx: &mut TestAppContext) {
2139 fn settings_select_list_lines_up_with_its_trigger(cx: &mut TestAppContext) {
2140 select_list_lines_up(cx, SettingsSection::Appearance, THEME_SELECT);
2141 }
2142
2143 #[gpui_kit::test]
2144 fn calendar_default_view_list_lines_up_with_its_trigger(cx: &mut TestAppContext) {
2145 select_list_lines_up(cx, SettingsSection::Calendar, CALENDAR_DEFAULT_VIEW_SELECT);
2146 }
2147
2148 fn select_list_lines_up(cx: &mut TestAppContext, section: SettingsSection, id: &str) {
2139 let (handle, state) = mount(cx);
2149 let (handle, state) = mount(cx);
2140 let mut visual = VisualTestContext::from_window(handle, cx);
2150 let mut visual = VisualTestContext::from_window(handle, cx);
2141 visual.simulate_resize(size(px(1280.), px(800.)));
2151 visual.simulate_resize(size(px(1280.), px(800.)));
2142 visual.update(|_, cx| {
2152 visual.update(|_, cx| state.update(cx, |state, cx| state.open_settings(section, cx)));
2143 state.update(cx, |state, cx| {
2153 let select: &'static str = Box::leak(select_selector(id).into_boxed_str());
2144 state.open_settings(SettingsSection::Appearance, cx)
2145 })
2146 });
2147 let select: &'static str = Box::leak(select_selector(THEME_SELECT).into_boxed_str());
2148 collect(&mut visual, Some(select));
2154 collect(&mut visual, Some(select));
2149 let trigger = visual.debug_bounds(select).expect("theme select rendered");
2155 let trigger = visual.debug_bounds(select).expect("select rendered");
2150 visual.simulate_click(trigger.center(), Default::default());
2156 visual.simulate_click(trigger.center(), Default::default());
2151 collect(&mut visual, Some(MENU));
2157 collect(&mut visual, Some(MENU));
2152 let menu = visual.debug_bounds(MENU).expect("list rendered");
2158 let menu = visual.debug_bounds(MENU).expect("list rendered");
crates/app/src/settings/calendar.rs +339 −24
@@ -1,24 +1,40 @@
1 use gpui_kit::ClipboardItem;
1 2 use gpui_kit::component::v_flex;
2 3 use gpui_kit::*;
3 4 use store::{CalendarProvider, CalendarRef};
4 5
5 use super::rows::{caption, control_row, text_button, toggle_row};
6 use std::collections::HashMap;
7
8 use app_base::format::{WeekdayWidth, clock_format, regional_first_day, weekday_name};
9 use chrono::{NaiveTime, Weekday};
10 use gpui_kit::component::h_flex;
11 use gpui_kit::prelude::FluentBuilder as _;
12
13 use super::rows::{
14 Choice, caption, control_row, select, select_with_width, text_button, toggle_row,
15 };
6 16 use crate::app_state::AppState;
17 use crate::call::calendar_prefs::{CalendarPrefs, DefaultView, TimeScale, WeekendWorkWeek};
18 use crate::i18n::tr;
7 19 use crate::theme;
8 20
9 21 pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 22 let accounts = app.read(cx).calendar_accounts();
23 let pending = app.read(cx).google_connect_pending().is_some();
24 let prefs = app.read(cx).calendar_prefs.clone();
11 25 let mut body = v_flex()
12 26 .w_full()
13 .child(caption("GOOGLE"))
14 .child(connect_row(app, accounts.has_google()));
27 .child(caption(tr("settings.calendar.section_view")))
28 .children(view_rows(app, &prefs))
29 .child(caption(tr("settings.calendar.section_google")))
30 .child(connect_row(app, accounts.has_google(), pending));
15 31 for account in &accounts.google_accounts {
16 32 body = body.child(account_block(app, account, &accounts));
17 33 }
18 34 body = body
19 .child(caption("HOME CALENDAR"))
35 .child(caption(tr("settings.calendar.section_home")))
20 36 .child(home_choices(app, &accounts))
21 .child(caption("ALSO WRITE TO"));
37 .child(caption(tr("settings.calendar.section_write")));
22 38 if accounts.home.provider != CalendarProvider::Outlook {
23 39 let write_app = app.clone();
24 40 let target = CalendarRef::outlook();
@@ -29,8 +45,8 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
29 45 body = body.child(
30 46 toggle_row(
31 47 "settings-write-outlook",
32 "Outlook (Microsoft mailbox)",
33 "Dual-write when home is Google",
48 tr("settings.calendar.outlook_mailbox"),
49 tr("settings.calendar.dual_write_when_google_home"),
34 50 theme::text_muted(),
35 51 selected,
36 52 )
@@ -42,28 +58,70 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
42 58 );
43 59 } else if accounts.google_accounts.is_empty() {
44 60 body = body.child(control_row(
45 "No extra write targets",
46 "Connect Google, then enable dual-write on a calendar above.",
61 tr("settings.calendar.no_extra_targets"),
62 tr("settings.calendar.connect_then_dual_write"),
47 63 div(),
48 64 ));
49 65 }
50 66 body
51 67 }
52 68
53 fn connect_row(app: &Entity<AppState>, connected: bool) -> Div {
69 fn connect_row(app: &Entity<AppState>, connected: bool, pending: bool) -> Div {
54 70 let app = app.clone();
55 71 if connected {
56 72 control_row(
57 "Google Calendar",
58 "Connected accounts appear below. Disconnect removes tokens from this device.",
73 tr("settings.calendar.google_title"),
74 tr("settings.calendar.connected_detail"),
59 75 div(),
60 76 )
77 } else if pending {
78 let reopen = app.clone();
79 let copy = app.clone();
80 let cancel = app.clone();
81 control_row(
82 tr("settings.calendar.google_title"),
83 tr("settings.calendar.finish_in_browser"),
84 div()
85 .flex()
86 .gap_2()
87 .child(
88 text_button(
89 "settings-google-reopen",
90 tr("settings.calendar.open_browser_again"),
91 )
92 .on_click(move |_, _, cx| {
93 reopen.update(cx, |state, cx| state.reopen_google_connect(cx))
94 }),
95 )
96 .child(
97 text_button("settings-google-copy", tr("settings.calendar.copy_link"))
98 .on_click(move |_, _, cx| {
99 if let Some(url) =
100 copy.read(cx).google_connect_pending().map(str::to_owned)
101 {
102 cx.write_to_clipboard(ClipboardItem::new_string(url));
103 }
104 }),
105 )
106 .child(
107 text_button("settings-google-cancel", tr("common.cancel")).on_click(
108 move |_, _, cx| {
109 cancel.update(cx, |state, cx| state.cancel_google_connect(cx))
110 },
111 ),
112 ),
113 )
61 114 } else {
115 let connect = app.clone();
62 116 control_row(
63 "Google Calendar",
64 "Requires TEAMS_GOOGLE_CLIENT_ID. Opens a browser for sign-in.",
65 text_button("settings-google-connect", "Connect Google").on_click(move |_, _, cx| {
66 app.update(cx, |state, cx| state.connect_google_calendar(cx))
117 tr("settings.calendar.google_title"),
118 tr("settings.calendar.connect_hint"),
119 text_button(
120 "settings-google-connect",
121 tr("settings.calendar.connect_button"),
122 )
123 .on_click(move |_, _, cx| {
124 connect.update(cx, |state, cx| state.connect_google_calendar(cx))
67 125 }),
68 126 )
69 127 }
@@ -78,10 +136,10 @@ fn account_block(
78 136 let account_id = account.id.clone();
79 137 let mut block = v_flex().w_full().child(control_row(
80 138 account.email.clone(),
81 "Google account",
139 tr("settings.calendar.google_account"),
82 140 text_button(
83 141 format!("settings-google-disconnect-{}", account.id),
84 "Disconnect",
142 tr("settings.calendar.disconnect"),
85 143 )
86 144 .on_click(move |_, _, cx| {
87 145 disconnect_app.update(cx, |state, cx| {
@@ -104,9 +162,9 @@ fn account_block(
104 162 format!("settings-google-cal-{}", calendar.id),
105 163 calendar.summary.clone(),
106 164 if calendar.primary {
107 "Primary calendar"
165 tr("settings.calendar.primary")
108 166 } else {
109 "Show in calendar grid"
167 tr("settings.calendar.show_in_grid")
110 168 },
111 169 theme::text_muted(),
112 170 calendar.selected,
@@ -123,7 +181,7 @@ fn account_block(
123 181 block = block.child(
124 182 toggle_row(
125 183 format!("settings-google-write-{}", calendar.id),
126 format!("Also write new meetings to {}", calendar.summary),
184 tr_args_write(&calendar.summary),
127 185 "",
128 186 theme::text_muted(),
129 187 is_write,
@@ -139,6 +197,12 @@ fn account_block(
139 197 block
140 198 }
141 199
200 fn tr_args_write(summary: &str) -> String {
201 let mut args = std::collections::HashMap::new();
202 args.insert("name".to_owned(), summary.to_owned());
203 crate::i18n::tr_args("settings.calendar.also_write_to", &args)
204 }
205
142 206 fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> Div {
143 207 let mut choices = v_flex().w_full();
144 208 let outlook_app = app.clone();
@@ -146,8 +210,8 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D
146 210 choices = choices.child(
147 211 toggle_row(
148 212 "settings-home-outlook",
149 "Outlook (Microsoft mailbox)",
150 "Default when no Google home is chosen",
213 tr("settings.calendar.outlook_mailbox"),
214 tr("settings.calendar.outlook_home_detail"),
151 215 theme::text_muted(),
152 216 outlook_home,
153 217 )
@@ -165,7 +229,11 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D
165 229 choices = choices.child(
166 230 toggle_row(
167 231 format!("settings-home-google-{}", calendar.id),
168 format!("Google · {}", calendar.summary),
232 format!(
233 "{} · {}",
234 tr("settings.calendar.google_label"),
235 calendar.summary
236 ),
169 237 account.email.clone(),
170 238 theme::text_muted(),
171 239 selected,
@@ -178,3 +246,250 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D
178 246 }
179 247 choices
180 248 }
249
250 const FIRST_DAY_CHOICES: [Weekday; 3] = [Weekday::Mon, Weekday::Sun, Weekday::Sat];
251 const CHIP_SIZE: f32 = 32.;
252 const TIME_SELECT_WIDTH: f32 = 104.;
253
254 /// Default view, first day, work days and hours, time scale, weekend Work week.
255 fn view_rows(app: &Entity<AppState>, prefs: &CalendarPrefs) -> Vec<Div> {
256 vec![
257 control_row(
258 tr("settings.calendar.default_view"),
259 tr("settings.calendar.default_view_detail"),
260 select(
261 "settings-calendar-default-view",
262 default_view_label(prefs.default_view),
263 false,
264 DefaultView::ALL
265 .into_iter()
266 .map(|view| {
267 prefs_choice(
268 app,
269 default_view_label(view),
270 prefs.default_view == view,
271 move |prefs| prefs.default_view = view,
272 )
273 })
274 .collect(),
275 ),
276 ),
277 control_row(
278 tr("settings.calendar.first_day"),
279 tr("settings.calendar.first_day_detail"),
280 select(
281 "settings-calendar-first-day",
282 first_day_label(prefs.first_day),
283 false,
284 std::iter::once(None)
285 .chain(FIRST_DAY_CHOICES.into_iter().map(Some))
286 .map(|day| {
287 prefs_choice(
288 app,
289 first_day_label(day),
290 prefs.first_day == day,
291 move |prefs| prefs.first_day = day,
292 )
293 })
294 .collect(),
295 ),
296 ),
297 control_row(
298 tr("settings.calendar.work_days"),
299 tr("settings.calendar.mailbox_detail"),
300 work_day_chips(app, prefs),
301 ),
302 control_row(
303 tr("settings.calendar.work_hours"),
304 tr("settings.calendar.mailbox_detail"),
305 h_flex()
306 .gap(px(8.))
307 .child(work_time_select(app, prefs, true))
308 .child(work_time_select(app, prefs, false)),
309 ),
310 control_row(
311 tr("settings.calendar.time_scale"),
312 tr("settings.calendar.time_scale_detail"),
313 select(
314 "settings-calendar-time-scale",
315 time_scale_label(prefs.time_scale),
316 false,
317 TimeScale::ALL
318 .into_iter()
319 .map(|scale| {
320 prefs_choice(
321 app,
322 time_scale_label(scale),
323 prefs.time_scale == scale,
324 move |prefs| prefs.time_scale = scale,
325 )
326 })
327 .collect(),
328 ),
329 ),
330 control_row(
331 tr("settings.calendar.weekend"),
332 tr("settings.calendar.weekend_detail"),
333 select(
334 "settings-calendar-weekend",
335 weekend_label(prefs.weekend_work_week),
336 false,
337 [WeekendWorkWeek::NextWeek, WeekendWorkWeek::ThisWeek]
338 .into_iter()
339 .map(|rule| {
340 prefs_choice(
341 app,
342 weekend_label(rule),
343 prefs.weekend_work_week == rule,
344 move |prefs| prefs.weekend_work_week = rule,
345 )
346 })
347 .collect(),
348 ),
349 ),
350 ]
351 }
352
353 fn prefs_choice(
354 app: &Entity<AppState>,
355 label: String,
356 checked: bool,
357 change: impl Fn(&mut CalendarPrefs) + 'static,
358 ) -> Choice {
359 let app = app.clone();
360 let change = std::rc::Rc::new(change);
361 Choice::new(label, checked, move |cx| {
362 let change = change.clone();
363 app.update(cx, |state, cx| {
364 state.update_calendar_prefs(|prefs| change(prefs), cx)
365 });
366 })
367 }
368
369 fn default_view_label(view: DefaultView) -> String {
370 view.span()
371 .map_or_else(|| tr("settings.calendar.last_used"), |span| span.label())
372 }
373
374 fn first_day_label(day: Option<Weekday>) -> String {
375 match day {
376 Some(day) => weekday_name(day, WeekdayWidth::Full),
377 None => {
378 let mut args = HashMap::new();
379 args.insert(
380 "day".to_owned(),
381 weekday_name(regional_first_day(), WeekdayWidth::Full),
382 );
383 crate::i18n::tr_args("settings.calendar.first_day_regional", &args)
384 }
385 }
386 }
387
388 fn time_scale_label(scale: TimeScale) -> String {
389 let mut args = HashMap::new();
390 args.insert("count".to_owned(), scale.minutes().to_string());
391 crate::i18n::tr_args("settings.calendar.minutes", &args)
392 }
393
394 fn weekend_label(rule: WeekendWorkWeek) -> String {
395 match rule {
396 WeekendWorkWeek::NextWeek => tr("settings.calendar.weekend_next"),
397 WeekendWorkWeek::ThisWeek => tr("settings.calendar.weekend_this"),
398 }
399 }
400
401 /// Seven day chips from the first day of week; the last work day cannot be turned off.
402 fn work_day_chips(app: &Entity<AppState>, prefs: &CalendarPrefs) -> Div {
403 let layout = prefs.layout(regional_first_day());
404 h_flex()
405 .gap(px(4.))
406 .children(layout.weekdays().into_iter().map(|day| {
407 let on = prefs.work_hours.is_work_day(day);
408 let last = on && prefs.work_hours.days.len() == 1;
409 let app = app.clone();
410 let hours = prefs.work_hours.clone();
411 div()
412 .id(SharedString::from(format!(
413 "settings-calendar-work-day-{day}"
414 )))
415 .size(px(CHIP_SIZE))
416 .flex()
417 .items_center()
418 .justify_center()
419 .rounded(px(6.))
420 .border_1()
421 .text_size(px(12.))
422 .font_weight(FontWeight::SEMIBOLD)
423 .map(|chip| {
424 if on {
425 chip.bg(theme::accent())
426 .border_color(theme::accent())
427 .text_color(theme::on_accent())
428 } else {
429 chip.border_color(theme::border_strong())
430 .text_color(theme::text_soft())
431 }
432 })
433 .when(!last, |chip| {
434 chip.cursor_pointer().on_click(move |_, _, cx| {
435 let mut hours = hours.clone();
436 if on {
437 hours.days.retain(|existing| *existing != day);
438 } else {
439 hours.days.push(day);
440 hours.days.sort_by_key(Weekday::num_days_from_monday);
441 }
442 app.update(cx, |state, cx| state.set_work_hours(hours, cx));
443 })
444 })
445 .child(weekday_name(day, WeekdayWidth::Short))
446 }))
447 }
448
449 /// Start or end of work in 30-minute steps; end choices stay after the start.
450 fn work_time_select(
451 app: &Entity<AppState>,
452 prefs: &CalendarPrefs,
453 start: bool,
454 ) -> impl IntoElement {
455 let hours = prefs.work_hours.clone();
456 let current = if start { hours.start } else { hours.end };
457 let choices = (0..48)
458 .filter_map(|step| NaiveTime::from_hms_opt(step / 2, (step % 2) * 30, 0))
459 .filter(|time| {
460 if start {
461 *time < hours.end
462 } else {
463 *time > hours.start
464 }
465 })
466 .map(|time| {
467 let app = app.clone();
468 let mut wanted = hours.clone();
469 if start {
470 wanted.start = time;
471 } else {
472 wanted.end = time;
473 }
474 Choice::new(
475 time.format(clock_format()).to_string(),
476 time == current,
477 move |cx| {
478 let wanted = wanted.clone();
479 app.update(cx, |state, cx| state.set_work_hours(wanted, cx));
480 },
481 )
482 })
483 .collect();
484 select_with_width(
485 if start {
486 "settings-calendar-work-start"
487 } else {
488 "settings-calendar-work-end"
489 },
490 current.format(clock_format()).to_string(),
491 TIME_SELECT_WIDTH,
492 false,
493 choices,
494 )
495 }
@@ -1,24 +1,40 @@
1use gpui_kit::ClipboardItem;
1use gpui_kit::component::v_flex;
2use gpui_kit::component::v_flex;
2use gpui_kit::*;
3use gpui_kit::*;
3use store::{CalendarProvider, CalendarRef};
4use store::{CalendarProvider, CalendarRef};
4
5
5use super::rows::{caption, control_row, text_button, toggle_row};
6use std::collections::HashMap;
7
8use app_base::format::{WeekdayWidth, clock_format, regional_first_day, weekday_name};
9use chrono::{NaiveTime, Weekday};
10use gpui_kit::component::h_flex;
11use gpui_kit::prelude::FluentBuilder as _;
12
13use super::rows::{
14 Choice, caption, control_row, select, select_with_width, text_button, toggle_row,
15};
6use crate::app_state::AppState;
16use crate::app_state::AppState;
17use crate::call::calendar_prefs::{CalendarPrefs, DefaultView, TimeScale, WeekendWorkWeek};
18use crate::i18n::tr;
7use crate::theme;
19use crate::theme;
8
20
9pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
21pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 let accounts = app.read(cx).calendar_accounts();
22 let accounts = app.read(cx).calendar_accounts();
23 let pending = app.read(cx).google_connect_pending().is_some();
24 let prefs = app.read(cx).calendar_prefs.clone();
11 let mut body = v_flex()
25 let mut body = v_flex()
12 .w_full()
26 .w_full()
13 .child(caption("GOOGLE"))
27 .child(caption(tr("settings.calendar.section_view")))
14 .child(connect_row(app, accounts.has_google()));
28 .children(view_rows(app, &prefs))
29 .child(caption(tr("settings.calendar.section_google")))
30 .child(connect_row(app, accounts.has_google(), pending));
15 for account in &accounts.google_accounts {
31 for account in &accounts.google_accounts {
16 body = body.child(account_block(app, account, &accounts));
32 body = body.child(account_block(app, account, &accounts));
17 }
33 }
18 body = body
34 body = body
19 .child(caption("HOME CALENDAR"))
35 .child(caption(tr("settings.calendar.section_home")))
20 .child(home_choices(app, &accounts))
36 .child(home_choices(app, &accounts))
21 .child(caption("ALSO WRITE TO"));
37 .child(caption(tr("settings.calendar.section_write")));
22 if accounts.home.provider != CalendarProvider::Outlook {
38 if accounts.home.provider != CalendarProvider::Outlook {
23 let write_app = app.clone();
39 let write_app = app.clone();
24 let target = CalendarRef::outlook();
40 let target = CalendarRef::outlook();
@@ -29,8 +45,8 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
29 body = body.child(
45 body = body.child(
30 toggle_row(
46 toggle_row(
31 "settings-write-outlook",
47 "settings-write-outlook",
32 "Outlook (Microsoft mailbox)",
48 tr("settings.calendar.outlook_mailbox"),
33 "Dual-write when home is Google",
49 tr("settings.calendar.dual_write_when_google_home"),
34 theme::text_muted(),
50 theme::text_muted(),
35 selected,
51 selected,
36 )
52 )
@@ -42,28 +58,70 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
42 );
58 );
43 } else if accounts.google_accounts.is_empty() {
59 } else if accounts.google_accounts.is_empty() {
44 body = body.child(control_row(
60 body = body.child(control_row(
45 "No extra write targets",
61 tr("settings.calendar.no_extra_targets"),
46 "Connect Google, then enable dual-write on a calendar above.",
62 tr("settings.calendar.connect_then_dual_write"),
47 div(),
63 div(),
48 ));
64 ));
49 }
65 }
50 body
66 body
51}
67}
52
68
53fn connect_row(app: &Entity<AppState>, connected: bool) -> Div {
69fn connect_row(app: &Entity<AppState>, connected: bool, pending: bool) -> Div {
54 let app = app.clone();
70 let app = app.clone();
55 if connected {
71 if connected {
56 control_row(
72 control_row(
57 "Google Calendar",
73 tr("settings.calendar.google_title"),
58 "Connected accounts appear below. Disconnect removes tokens from this device.",
74 tr("settings.calendar.connected_detail"),
59 div(),
75 div(),
60 )
76 )
77 } else if pending {
78 let reopen = app.clone();
79 let copy = app.clone();
80 let cancel = app.clone();
81 control_row(
82 tr("settings.calendar.google_title"),
83 tr("settings.calendar.finish_in_browser"),
84 div()
85 .flex()
86 .gap_2()
87 .child(
88 text_button(
89 "settings-google-reopen",
90 tr("settings.calendar.open_browser_again"),
91 )
92 .on_click(move |_, _, cx| {
93 reopen.update(cx, |state, cx| state.reopen_google_connect(cx))
94 }),
95 )
96 .child(
97 text_button("settings-google-copy", tr("settings.calendar.copy_link"))
98 .on_click(move |_, _, cx| {
99 if let Some(url) =
100 copy.read(cx).google_connect_pending().map(str::to_owned)
101 {
102 cx.write_to_clipboard(ClipboardItem::new_string(url));
103 }
104 }),
105 )
106 .child(
107 text_button("settings-google-cancel", tr("common.cancel")).on_click(
108 move |_, _, cx| {
109 cancel.update(cx, |state, cx| state.cancel_google_connect(cx))
110 },
111 ),
112 ),
113 )
61 } else {
114 } else {
115 let connect = app.clone();
62 control_row(
116 control_row(
63 "Google Calendar",
117 tr("settings.calendar.google_title"),
64 "Requires TEAMS_GOOGLE_CLIENT_ID. Opens a browser for sign-in.",
118 tr("settings.calendar.connect_hint"),
65 text_button("settings-google-connect", "Connect Google").on_click(move |_, _, cx| {
119 text_button(
66 app.update(cx, |state, cx| state.connect_google_calendar(cx))
120 "settings-google-connect",
121 tr("settings.calendar.connect_button"),
122 )
123 .on_click(move |_, _, cx| {
124 connect.update(cx, |state, cx| state.connect_google_calendar(cx))
67 }),
125 }),
68 )
126 )
69 }
127 }
@@ -78,10 +136,10 @@ fn account_block(
78 let account_id = account.id.clone();
136 let account_id = account.id.clone();
79 let mut block = v_flex().w_full().child(control_row(
137 let mut block = v_flex().w_full().child(control_row(
80 account.email.clone(),
138 account.email.clone(),
81 "Google account",
139 tr("settings.calendar.google_account"),
82 text_button(
140 text_button(
83 format!("settings-google-disconnect-{}", account.id),
141 format!("settings-google-disconnect-{}", account.id),
84 "Disconnect",
142 tr("settings.calendar.disconnect"),
85 )
143 )
86 .on_click(move |_, _, cx| {
144 .on_click(move |_, _, cx| {
87 disconnect_app.update(cx, |state, cx| {
145 disconnect_app.update(cx, |state, cx| {
@@ -104,9 +162,9 @@ fn account_block(
104 format!("settings-google-cal-{}", calendar.id),
162 format!("settings-google-cal-{}", calendar.id),
105 calendar.summary.clone(),
163 calendar.summary.clone(),
106 if calendar.primary {
164 if calendar.primary {
107 "Primary calendar"
165 tr("settings.calendar.primary")
108 } else {
166 } else {
109 "Show in calendar grid"
167 tr("settings.calendar.show_in_grid")
110 },
168 },
111 theme::text_muted(),
169 theme::text_muted(),
112 calendar.selected,
170 calendar.selected,
@@ -123,7 +181,7 @@ fn account_block(
123 block = block.child(
181 block = block.child(
124 toggle_row(
182 toggle_row(
125 format!("settings-google-write-{}", calendar.id),
183 format!("settings-google-write-{}", calendar.id),
126 format!("Also write new meetings to {}", calendar.summary),
184 tr_args_write(&calendar.summary),
127 "",
185 "",
128 theme::text_muted(),
186 theme::text_muted(),
129 is_write,
187 is_write,
@@ -139,6 +197,12 @@ fn account_block(
139 block
197 block
140}
198}
141
199
200fn tr_args_write(summary: &str) -> String {
201 let mut args = std::collections::HashMap::new();
202 args.insert("name".to_owned(), summary.to_owned());
203 crate::i18n::tr_args("settings.calendar.also_write_to", &args)
204}
205
142fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> Div {
206fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> Div {
143 let mut choices = v_flex().w_full();
207 let mut choices = v_flex().w_full();
144 let outlook_app = app.clone();
208 let outlook_app = app.clone();
@@ -146,8 +210,8 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D
146 choices = choices.child(
210 choices = choices.child(
147 toggle_row(
211 toggle_row(
148 "settings-home-outlook",
212 "settings-home-outlook",
149 "Outlook (Microsoft mailbox)",
213 tr("settings.calendar.outlook_mailbox"),
150 "Default when no Google home is chosen",
214 tr("settings.calendar.outlook_home_detail"),
151 theme::text_muted(),
215 theme::text_muted(),
152 outlook_home,
216 outlook_home,
153 )
217 )
@@ -165,7 +229,11 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D
165 choices = choices.child(
229 choices = choices.child(
166 toggle_row(
230 toggle_row(
167 format!("settings-home-google-{}", calendar.id),
231 format!("settings-home-google-{}", calendar.id),
168 format!("Google · {}", calendar.summary),
232 format!(
233 "{} · {}",
234 tr("settings.calendar.google_label"),
235 calendar.summary
236 ),
169 account.email.clone(),
237 account.email.clone(),
170 theme::text_muted(),
238 theme::text_muted(),
171 selected,
239 selected,
@@ -178,3 +246,250 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D
178 }
246 }
179 choices
247 choices
180}
248}
249
250const FIRST_DAY_CHOICES: [Weekday; 3] = [Weekday::Mon, Weekday::Sun, Weekday::Sat];
251const CHIP_SIZE: f32 = 32.;
252const TIME_SELECT_WIDTH: f32 = 104.;
253
254/// Default view, first day, work days and hours, time scale, weekend Work week.
255fn view_rows(app: &Entity<AppState>, prefs: &CalendarPrefs) -> Vec<Div> {
256 vec![
257 control_row(
258 tr("settings.calendar.default_view"),
259 tr("settings.calendar.default_view_detail"),
260 select(
261 "settings-calendar-default-view",
262 default_view_label(prefs.default_view),
263 false,
264 DefaultView::ALL
265 .into_iter()
266 .map(|view| {
267 prefs_choice(
268 app,
269 default_view_label(view),
270 prefs.default_view == view,
271 move |prefs| prefs.default_view = view,
272 )
273 })
274 .collect(),
275 ),
276 ),
277 control_row(
278 tr("settings.calendar.first_day"),
279 tr("settings.calendar.first_day_detail"),
280 select(
281 "settings-calendar-first-day",
282 first_day_label(prefs.first_day),
283 false,
284 std::iter::once(None)
285 .chain(FIRST_DAY_CHOICES.into_iter().map(Some))
286 .map(|day| {
287 prefs_choice(
288 app,
289 first_day_label(day),
290 prefs.first_day == day,
291 move |prefs| prefs.first_day = day,
292 )
293 })
294 .collect(),
295 ),
296 ),
297 control_row(
298 tr("settings.calendar.work_days"),
299 tr("settings.calendar.mailbox_detail"),
300 work_day_chips(app, prefs),
301 ),
302 control_row(
303 tr("settings.calendar.work_hours"),
304 tr("settings.calendar.mailbox_detail"),
305 h_flex()
306 .gap(px(8.))
307 .child(work_time_select(app, prefs, true))
308 .child(work_time_select(app, prefs, false)),
309 ),
310 control_row(
311 tr("settings.calendar.time_scale"),
312 tr("settings.calendar.time_scale_detail"),
313 select(
314 "settings-calendar-time-scale",
315 time_scale_label(prefs.time_scale),
316 false,
317 TimeScale::ALL
318 .into_iter()
319 .map(|scale| {
320 prefs_choice(
321 app,
322 time_scale_label(scale),
323 prefs.time_scale == scale,
324 move |prefs| prefs.time_scale = scale,
325 )
326 })
327 .collect(),
328 ),
329 ),
330 control_row(
331 tr("settings.calendar.weekend"),
332 tr("settings.calendar.weekend_detail"),
333 select(
334 "settings-calendar-weekend",
335 weekend_label(prefs.weekend_work_week),
336 false,
337 [WeekendWorkWeek::NextWeek, WeekendWorkWeek::ThisWeek]
338 .into_iter()
339 .map(|rule| {
340 prefs_choice(
341 app,
342 weekend_label(rule),
343 prefs.weekend_work_week == rule,
344 move |prefs| prefs.weekend_work_week = rule,
345 )
346 })
347 .collect(),
348 ),
349 ),
350 ]
351}
352
353fn prefs_choice(
354 app: &Entity<AppState>,
355 label: String,
356 checked: bool,
357 change: impl Fn(&mut CalendarPrefs) + 'static,
358) -> Choice {
359 let app = app.clone();
360 let change = std::rc::Rc::new(change);
361 Choice::new(label, checked, move |cx| {
362 let change = change.clone();
363 app.update(cx, |state, cx| {
364 state.update_calendar_prefs(|prefs| change(prefs), cx)
365 });
366 })
367}
368
369fn default_view_label(view: DefaultView) -> String {
370 view.span()
371 .map_or_else(|| tr("settings.calendar.last_used"), |span| span.label())
372}
373
374fn first_day_label(day: Option<Weekday>) -> String {
375 match day {
376 Some(day) => weekday_name(day, WeekdayWidth::Full),
377 None => {
378 let mut args = HashMap::new();
379 args.insert(
380 "day".to_owned(),
381 weekday_name(regional_first_day(), WeekdayWidth::Full),
382 );
383 crate::i18n::tr_args("settings.calendar.first_day_regional", &args)
384 }
385 }
386}
387
388fn time_scale_label(scale: TimeScale) -> String {
389 let mut args = HashMap::new();
390 args.insert("count".to_owned(), scale.minutes().to_string());
391 crate::i18n::tr_args("settings.calendar.minutes", &args)
392}
393
394fn weekend_label(rule: WeekendWorkWeek) -> String {
395 match rule {
396 WeekendWorkWeek::NextWeek => tr("settings.calendar.weekend_next"),
397 WeekendWorkWeek::ThisWeek => tr("settings.calendar.weekend_this"),
398 }
399}
400
401/// Seven day chips from the first day of week; the last work day cannot be turned off.
402fn work_day_chips(app: &Entity<AppState>, prefs: &CalendarPrefs) -> Div {
403 let layout = prefs.layout(regional_first_day());
404 h_flex()
405 .gap(px(4.))
406 .children(layout.weekdays().into_iter().map(|day| {
407 let on = prefs.work_hours.is_work_day(day);
408 let last = on && prefs.work_hours.days.len() == 1;
409 let app = app.clone();
410 let hours = prefs.work_hours.clone();
411 div()
412 .id(SharedString::from(format!(
413 "settings-calendar-work-day-{day}"
414 )))
415 .size(px(CHIP_SIZE))
416 .flex()
417 .items_center()
418 .justify_center()
419 .rounded(px(6.))
420 .border_1()
421 .text_size(px(12.))
422 .font_weight(FontWeight::SEMIBOLD)
423 .map(|chip| {
424 if on {
425 chip.bg(theme::accent())
426 .border_color(theme::accent())
427 .text_color(theme::on_accent())
428 } else {
429 chip.border_color(theme::border_strong())
430 .text_color(theme::text_soft())
431 }
432 })
433 .when(!last, |chip| {
434 chip.cursor_pointer().on_click(move |_, _, cx| {
435 let mut hours = hours.clone();
436 if on {
437 hours.days.retain(|existing| *existing != day);
438 } else {
439 hours.days.push(day);
440 hours.days.sort_by_key(Weekday::num_days_from_monday);
441 }
442 app.update(cx, |state, cx| state.set_work_hours(hours, cx));
443 })
444 })
445 .child(weekday_name(day, WeekdayWidth::Short))
446 }))
447}
448
449/// Start or end of work in 30-minute steps; end choices stay after the start.
450fn work_time_select(
451 app: &Entity<AppState>,
452 prefs: &CalendarPrefs,
453 start: bool,
454) -> impl IntoElement {
455 let hours = prefs.work_hours.clone();
456 let current = if start { hours.start } else { hours.end };
457 let choices = (0..48)
458 .filter_map(|step| NaiveTime::from_hms_opt(step / 2, (step % 2) * 30, 0))
459 .filter(|time| {
460 if start {
461 *time < hours.end
462 } else {
463 *time > hours.start
464 }
465 })
466 .map(|time| {
467 let app = app.clone();
468 let mut wanted = hours.clone();
469 if start {
470 wanted.start = time;
471 } else {
472 wanted.end = time;
473 }
474 Choice::new(
475 time.format(clock_format()).to_string(),
476 time == current,
477 move |cx| {
478 let wanted = wanted.clone();
479 app.update(cx, |state, cx| state.set_work_hours(wanted, cx));
480 },
481 )
482 })
483 .collect();
484 select_with_width(
485 if start {
486 "settings-calendar-work-start"
487 } else {
488 "settings-calendar-work-end"
489 },
490 current.format(clock_format()).to_string(),
491 TIME_SELECT_WIDTH,
492 false,
493 choices,
494 )
495}
crates/app/src/settings/nav.rs +19 −11
@@ -27,6 +27,20 @@ const ITEM_RADIUS: f32 = 6.;
27 27 const ITEM_ICON: f32 = 16.;
28 28 const NAV_PADDING_X: f32 = 12.;
29 29
30 const CALENDAR_TERMS: [&str; 11] = [
31 "settings.calendar.default_view",
32 "settings.calendar.first_day",
33 "settings.calendar.work_days",
34 "settings.calendar.work_hours",
35 "settings.calendar.time_scale",
36 "settings.calendar.weekend",
37 "settings.calendar.google_title",
38 "settings.calendar.connect_button",
39 "settings.calendar.section_home",
40 "settings.calendar.section_write",
41 "settings.calendar.outlook_mailbox",
42 ];
43
30 44 fn search_terms(section: SettingsSection) -> Vec<String> {
31 45 match section {
32 46 SettingsSection::General => vec![
@@ -34,10 +48,6 @@ fn search_terms(section: SettingsSection) -> Vec<String> {
34 48 tr("settings.general.open_in_background"),
35 49 tr("settings.general.close_to_tray"),
36 50 tr("settings.general.external_browser"),
37 #[cfg(target_os = "linux")]
38 tr("install.menu_title"),
39 #[cfg(target_os = "linux")]
40 tr("install.updates_title"),
41 51 tr("settings.general.up_arrow"),
42 52 tr("settings.general.translate_into"),
43 53 tr("settings.general.behavior_title"),
@@ -70,13 +80,7 @@ fn search_terms(section: SettingsSection) -> Vec<String> {
70 80 tr("settings.chats.markdown"),
71 81 ],
72 82 SettingsSection::Calls => vec![tr("settings.calls.ringtones")],
73 SettingsSection::Calendar => vec![
74 "Google Calendar".to_owned(),
75 "Connect Google".to_owned(),
76 "Home calendar".to_owned(),
77 "Also write to".to_owned(),
78 "Outlook".to_owned(),
79 ],
83 SettingsSection::Calendar => CALENDAR_TERMS.iter().map(|key| tr(key)).collect(),
80 84 SettingsSection::Devices => vec![
81 85 "Speaker".to_owned(),
82 86 "Microphone".to_owned(),
@@ -369,6 +373,7 @@ mod tests {
369 373
370 374 #[test]
371 375 fn search_finds_sections_by_name_and_by_setting() {
376 let _guard = crate::i18n::locale_test_lock();
372 377 apply_locale("en");
373 378 assert!(matches(SettingsSection::Chats, "read receipts"));
374 379 assert!(matches(SettingsSection::Devices, "MICRO"));
@@ -417,12 +422,14 @@ mod tests {
417 422 "settings.chats.enter_to",
418 423 "settings.chats.markdown",
419 424 ],
425 SettingsSection::Calendar => &super::CALENDAR_TERMS,
420 426 _ => &[],
421 427 }
422 428 }
423 429
424 430 #[test]
425 431 fn every_search_term_names_a_setting_on_its_page() {
432 let _guard = crate::i18n::locale_test_lock();
426 433 apply_locale("en");
427 434 let pages = [
428 435 (SettingsSection::General, include_str!("general.rs")),
@@ -432,6 +439,7 @@ mod tests {
432 439 ),
433 440 (SettingsSection::Appearance, include_str!("appearance.rs")),
434 441 (SettingsSection::Devices, include_str!("devices.rs")),
442 (SettingsSection::Calendar, include_str!("calendar.rs")),
435 443 ];
436 444 for (section, source) in pages {
437 445 for key in search_term_keys(section) {
@@ -27,6 +27,20 @@ const ITEM_RADIUS: f32 = 6.;
27const ITEM_ICON: f32 = 16.;
27const ITEM_ICON: f32 = 16.;
28const NAV_PADDING_X: f32 = 12.;
28const NAV_PADDING_X: f32 = 12.;
29
29
30const CALENDAR_TERMS: [&str; 11] = [
31 "settings.calendar.default_view",
32 "settings.calendar.first_day",
33 "settings.calendar.work_days",
34 "settings.calendar.work_hours",
35 "settings.calendar.time_scale",
36 "settings.calendar.weekend",
37 "settings.calendar.google_title",
38 "settings.calendar.connect_button",
39 "settings.calendar.section_home",
40 "settings.calendar.section_write",
41 "settings.calendar.outlook_mailbox",
42];
43
30fn search_terms(section: SettingsSection) -> Vec<String> {
44fn search_terms(section: SettingsSection) -> Vec<String> {
31 match section {
45 match section {
32 SettingsSection::General => vec![
46 SettingsSection::General => vec![
@@ -34,10 +48,6 @@ fn search_terms(section: SettingsSection) -> Vec<String> {
34 tr("settings.general.open_in_background"),
48 tr("settings.general.open_in_background"),
35 tr("settings.general.close_to_tray"),
49 tr("settings.general.close_to_tray"),
36 tr("settings.general.external_browser"),
50 tr("settings.general.external_browser"),
37 #[cfg(target_os = "linux")]
38 tr("install.menu_title"),
39 #[cfg(target_os = "linux")]
40 tr("install.updates_title"),
41 tr("settings.general.up_arrow"),
51 tr("settings.general.up_arrow"),
42 tr("settings.general.translate_into"),
52 tr("settings.general.translate_into"),
43 tr("settings.general.behavior_title"),
53 tr("settings.general.behavior_title"),
@@ -70,13 +80,7 @@ fn search_terms(section: SettingsSection) -> Vec<String> {
70 tr("settings.chats.markdown"),
80 tr("settings.chats.markdown"),
71 ],
81 ],
72 SettingsSection::Calls => vec![tr("settings.calls.ringtones")],
82 SettingsSection::Calls => vec![tr("settings.calls.ringtones")],
73 SettingsSection::Calendar => vec![
83 SettingsSection::Calendar => CALENDAR_TERMS.iter().map(|key| tr(key)).collect(),
74 "Google Calendar".to_owned(),
75 "Connect Google".to_owned(),
76 "Home calendar".to_owned(),
77 "Also write to".to_owned(),
78 "Outlook".to_owned(),
79 ],
80 SettingsSection::Devices => vec![
84 SettingsSection::Devices => vec![
81 "Speaker".to_owned(),
85 "Speaker".to_owned(),
82 "Microphone".to_owned(),
86 "Microphone".to_owned(),
@@ -369,6 +373,7 @@ mod tests {
369
373
370 #[test]
374 #[test]
371 fn search_finds_sections_by_name_and_by_setting() {
375 fn search_finds_sections_by_name_and_by_setting() {
376 let _guard = crate::i18n::locale_test_lock();
372 apply_locale("en");
377 apply_locale("en");
373 assert!(matches(SettingsSection::Chats, "read receipts"));
378 assert!(matches(SettingsSection::Chats, "read receipts"));
374 assert!(matches(SettingsSection::Devices, "MICRO"));
379 assert!(matches(SettingsSection::Devices, "MICRO"));
@@ -417,12 +422,14 @@ mod tests {
417 "settings.chats.enter_to",
422 "settings.chats.enter_to",
418 "settings.chats.markdown",
423 "settings.chats.markdown",
419 ],
424 ],
425 SettingsSection::Calendar => &super::CALENDAR_TERMS,
420 _ => &[],
426 _ => &[],
421 }
427 }
422 }
428 }
423
429
424 #[test]
430 #[test]
425 fn every_search_term_names_a_setting_on_its_page() {
431 fn every_search_term_names_a_setting_on_its_page() {
432 let _guard = crate::i18n::locale_test_lock();
426 apply_locale("en");
433 apply_locale("en");
427 let pages = [
434 let pages = [
428 (SettingsSection::General, include_str!("general.rs")),
435 (SettingsSection::General, include_str!("general.rs")),
@@ -432,6 +439,7 @@ mod tests {
432 ),
439 ),
433 (SettingsSection::Appearance, include_str!("appearance.rs")),
440 (SettingsSection::Appearance, include_str!("appearance.rs")),
434 (SettingsSection::Devices, include_str!("devices.rs")),
441 (SettingsSection::Devices, include_str!("devices.rs")),
442 (SettingsSection::Calendar, include_str!("calendar.rs")),
435 ];
443 ];
436 for (section, source) in pages {
444 for (section, source) in pages {
437 for key in search_term_keys(section) {
445 for key in search_term_keys(section) {
docs/decisions/0016-calendar-week-start-and-time-scale-stay-local.md added +33 −0
@@ -0,0 +1,33 @@
1 ---
2 status: proposed
3 date: 2026-11-15
4 ---
5
6 # ADR 0016: Calendar work hours go to the mailbox, week start and time scale stay local
7
8 ## Context
9
10 `GUARDRAILS.md` says settings Teams knows are saved where Teams saves them. The calendar view settings come from two places in Teams:
11
12 - Work days and work hours are the Outlook mailbox working hours. Graph exposes them as `/me/mailboxSettings`. The Teams client token is granted `MailboxSettings.ReadWrite` but not `MailboxSettings.Read`. A live read returned HTTP 200 on 2026-11-15.
13 - First day of week and the time scale are Outlook web (OWA) user options. Graph has no endpoint for them. The new Teams calendar reads them through the OWA options service.
14
15 The options were:
16
17 - write everything locally;
18 - reach the OWA options service from the fork;
19 - split by what Graph can reach.
20
21 ## Decision
22
23 - Work days and hours are read from and written to the mailbox working hours through Graph. A local copy is only a cache for the grid.
24 - First day of week defaults to the regional format, which is where Teams takes it from when no OWA option is set. A local override can change it.
25 - The time scale is a local setting. Its default, 30 minutes, matches Teams.
26 - Default view and the last used span are fork settings and stay local.
27
28 ## Consequences
29
30 - Changing work hours in the app changes them in Outlook and Teams too, and the other way round after the next read.
31 - A first-day or time-scale change in Outlook web does not reach the app, and an app change does not reach Outlook. This deviation is named in the change's commit.
32 - If the fork adopts the OWA options service later, first day and time scale move there, and this record is superseded.
33 - OpenSpec `calendar-view-settings` owns the observable behaviour.
@@ -0,0 +1,33 @@
1---
2status: proposed
3date: 2026-11-15
4---
5
6# ADR 0016: Calendar work hours go to the mailbox, week start and time scale stay local
7
8## Context
9
10`GUARDRAILS.md` says settings Teams knows are saved where Teams saves them. The calendar view settings come from two places in Teams:
11
12- Work days and work hours are the Outlook mailbox working hours. Graph exposes them as `/me/mailboxSettings`. The Teams client token is granted `MailboxSettings.ReadWrite` but not `MailboxSettings.Read`. A live read returned HTTP 200 on 2026-11-15.
13- First day of week and the time scale are Outlook web (OWA) user options. Graph has no endpoint for them. The new Teams calendar reads them through the OWA options service.
14
15The options were:
16
17- write everything locally;
18- reach the OWA options service from the fork;
19- split by what Graph can reach.
20
21## Decision
22
23- Work days and hours are read from and written to the mailbox working hours through Graph. A local copy is only a cache for the grid.
24- First day of week defaults to the regional format, which is where Teams takes it from when no OWA option is set. A local override can change it.
25- The time scale is a local setting. Its default, 30 minutes, matches Teams.
26- Default view and the last used span are fork settings and stay local.
27
28## Consequences
29
30- Changing work hours in the app changes them in Outlook and Teams too, and the other way round after the next read.
31- A first-day or time-scale change in Outlook web does not reach the app, and an app change does not reach Outlook. This deviation is named in the change's commit.
32- If the fork adopts the OWA options service later, first day and time scale move there, and this record is superseded.
33- OpenSpec `calendar-view-settings` owns the observable behaviour.
docs/decisions/README.md +1 −0
@@ -30,5 +30,6 @@ Statuses: `proposed`, `accepted`, `superseded`.
30 30 | [0012](0012-linux-close-to-tray-closes-the-window.md) | On Linux, close to tray closes the main window |
31 31 | [0013](0013-local-diagnostic-data-and-upstream-issues.md) | Local diagnostic data layout and upstream issues |
32 32 | [0014](0014-linux-installs-and-updates-itself.md) | The Linux binary installs and updates itself |
33 | [0016](0016-calendar-week-start-and-time-scale-stay-local.md) | Calendar work hours go to the mailbox, week start and time scale stay local |
33 34
34 35 Records `0001` to `0014` are the decisions already shipped. `0001` follows Daniel's call-window note in `GUARDRAILS.md`.
@@ -30,5 +30,6 @@ Statuses: `proposed`, `accepted`, `superseded`.
30| [0012](0012-linux-close-to-tray-closes-the-window.md) | On Linux, close to tray closes the main window |
30| [0012](0012-linux-close-to-tray-closes-the-window.md) | On Linux, close to tray closes the main window |
31| [0013](0013-local-diagnostic-data-and-upstream-issues.md) | Local diagnostic data layout and upstream issues |
31| [0013](0013-local-diagnostic-data-and-upstream-issues.md) | Local diagnostic data layout and upstream issues |
32| [0014](0014-linux-installs-and-updates-itself.md) | The Linux binary installs and updates itself |
32| [0014](0014-linux-installs-and-updates-itself.md) | The Linux binary installs and updates itself |
33| [0016](0016-calendar-week-start-and-time-scale-stay-local.md) | Calendar work hours go to the mailbox, week start and time scale stay local |
33
34
34Records `0001` to `0014` are the decisions already shipped. `0001` follows Daniel's call-window note in `GUARDRAILS.md`.
35Records `0001` to `0014` are the decisions already shipped. `0001` follows Daniel's call-window note in `GUARDRAILS.md`.