Skip to content

Commit d603910

Browse files
committed
Add quit on lost focus to settings UI (only for mac)
1 parent 09bd8db commit d603910

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

src/gui/settings_window/general_view.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub(crate) fn general_content() -> impl Widget<UIState> {
1414
.then(UISettings::visual_settings)
1515
.then(UIVisualSettings::show_hotkeys),
1616
),
17-
rules_view::SaveRulesOnDataChange {
18-
save_rules_command: save_command.clone(),
17+
rules_view::SubmitCommandOnDataChange {
18+
command: save_command.clone(),
1919
},
2020
);
2121

@@ -33,9 +33,33 @@ pub(crate) fn general_content() -> impl Widget<UIState> {
3333
ctx.show_context_menu(submenu_hidden_apps, point);
3434
});
3535

36-
return Flex::column()
36+
let mut col = Flex::column()
3737
.cross_axis_alignment(CrossAxisAlignment::Start)
3838
.with_child(hotkeys_row)
39-
.with_default_spacer()
40-
.with_child(restore_app_button);
39+
.with_default_spacer();
40+
41+
// Showing this option only for macOS right now,
42+
// because linux calls this even when just opening a context menu
43+
// mac is handled by application event instead now, which is fired when all windows of app loose focus
44+
let is_mac = cfg!(target_os = "macos");
45+
if is_mac {
46+
let quit_on_lost_focus_switch = ControllerHost::new(
47+
Switch::new().lens(
48+
UIState::ui_settings
49+
.then(UISettings::visual_settings)
50+
.then(UIVisualSettings::quit_on_lost_focus),
51+
),
52+
rules_view::SubmitCommandOnDataChange {
53+
command: save_command.clone(),
54+
},
55+
);
56+
57+
let quit_on_lost_focus_row = Flex::row()
58+
.with_child(Label::new("Quit when Focus is Lost"))
59+
.with_child(quit_on_lost_focus_switch);
60+
61+
col = col.with_child(quit_on_lost_focus_row).with_default_spacer()
62+
}
63+
64+
return col.with_child(restore_app_button);
4165
}

src/gui/settings_window/rules_view.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ fn create_incognito_checkbox(
148148
{
149149
let incognito_checkbox = ControllerHost::new(
150150
Checkbox::from_label(Label::new("In Incognito").with_font(FONT)),
151-
SaveRulesOnDataChange {
152-
save_rules_command: command1.clone(),
151+
SubmitCommandOnDataChange {
152+
command: command1.clone(),
153153
},
154154
)
155155
.lens(UIProfileAndIncognito::incognito)
@@ -247,8 +247,8 @@ fn create_rule(browsers: &Arc<Vec<UIBrowser>>) -> impl Widget<UISettingsRule> {
247247
//let value_text_box = ValueTextBox::new(text_box, formatter).update_data_while_editing(true);
248248
let value_text_box = ControllerHost::new(
249249
text_box,
250-
SaveRulesOnDataChange {
251-
save_rules_command: SAVE_RULES.with(()),
250+
SubmitCommandOnDataChange {
251+
command: SAVE_RULES.with(()),
252252
},
253253
);
254254

@@ -311,15 +311,15 @@ fn find_browser(browsers: &Arc<Vec<UIBrowser>>, unique_id: String) -> Option<&UI
311311
return option;
312312
}
313313

314-
pub(crate) struct SaveRulesOnDataChange {
315-
pub(crate) save_rules_command: Command,
314+
pub(crate) struct SubmitCommandOnDataChange {
315+
pub(crate) command: Command,
316316
}
317317

318-
impl<T: Data, W: Widget<T>> Controller<T, W> for SaveRulesOnDataChange {
318+
impl<T: Data, W: Widget<T>> Controller<T, W> for SubmitCommandOnDataChange {
319319
fn update(&mut self, child: &mut W, ctx: &mut UpdateCtx, old_data: &T, data: &T, env: &Env) {
320320
child.update(ctx, old_data, data, env);
321321
if !old_data.same(data) {
322-
ctx.submit_command(self.save_rules_command.clone());
322+
ctx.submit_command(self.command.clone());
323323
}
324324
}
325325
}

0 commit comments

Comments
 (0)