Skip to content

Commit

Permalink
Add quit on lost focus to settings UI (only for mac)
Browse files Browse the repository at this point in the history
  • Loading branch information
liias committed Jan 27, 2024
1 parent 09bd8db commit d603910
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
34 changes: 29 additions & 5 deletions src/gui/settings_window/general_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub(crate) fn general_content() -> impl Widget<UIState> {
.then(UISettings::visual_settings)
.then(UIVisualSettings::show_hotkeys),
),
rules_view::SaveRulesOnDataChange {
save_rules_command: save_command.clone(),
rules_view::SubmitCommandOnDataChange {
command: save_command.clone(),
},
);

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

return Flex::column()
let mut col = Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(hotkeys_row)
.with_default_spacer()
.with_child(restore_app_button);
.with_default_spacer();

// Showing this option only for macOS right now,
// because linux calls this even when just opening a context menu
// mac is handled by application event instead now, which is fired when all windows of app loose focus
let is_mac = cfg!(target_os = "macos");
if is_mac {
let quit_on_lost_focus_switch = ControllerHost::new(
Switch::new().lens(
UIState::ui_settings
.then(UISettings::visual_settings)
.then(UIVisualSettings::quit_on_lost_focus),
),
rules_view::SubmitCommandOnDataChange {
command: save_command.clone(),
},
);

let quit_on_lost_focus_row = Flex::row()
.with_child(Label::new("Quit when Focus is Lost"))
.with_child(quit_on_lost_focus_switch);

col = col.with_child(quit_on_lost_focus_row).with_default_spacer()
}

return col.with_child(restore_app_button);
}
16 changes: 8 additions & 8 deletions src/gui/settings_window/rules_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ fn create_incognito_checkbox(
{
let incognito_checkbox = ControllerHost::new(
Checkbox::from_label(Label::new("In Incognito").with_font(FONT)),
SaveRulesOnDataChange {
save_rules_command: command1.clone(),
SubmitCommandOnDataChange {
command: command1.clone(),
},
)
.lens(UIProfileAndIncognito::incognito)
Expand Down Expand Up @@ -247,8 +247,8 @@ fn create_rule(browsers: &Arc<Vec<UIBrowser>>) -> impl Widget<UISettingsRule> {
//let value_text_box = ValueTextBox::new(text_box, formatter).update_data_while_editing(true);
let value_text_box = ControllerHost::new(
text_box,
SaveRulesOnDataChange {
save_rules_command: SAVE_RULES.with(()),
SubmitCommandOnDataChange {
command: SAVE_RULES.with(()),
},
);

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

pub(crate) struct SaveRulesOnDataChange {
pub(crate) save_rules_command: Command,
pub(crate) struct SubmitCommandOnDataChange {
pub(crate) command: Command,
}

impl<T: Data, W: Widget<T>> Controller<T, W> for SaveRulesOnDataChange {
impl<T: Data, W: Widget<T>> Controller<T, W> for SubmitCommandOnDataChange {
fn update(&mut self, child: &mut W, ctx: &mut UpdateCtx, old_data: &T, data: &T, env: &Env) {
child.update(ctx, old_data, data, env);
if !old_data.same(data) {
ctx.submit_command(self.save_rules_command.clone());
ctx.submit_command(self.command.clone());
}
}
}
Expand Down

0 comments on commit d603910

Please sign in to comment.