Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub struct LauncherApp {
pub static_location_enabled: bool,
pub static_pos: Option<(i32, i32)>,
pub static_size: Option<(i32, i32)>,
pub hide_after_run: bool,
}

impl LauncherApp {
Expand All @@ -117,6 +118,7 @@ impl LauncherApp {
static_enabled: Option<bool>,
static_pos: Option<(i32, i32)>,
static_size: Option<(i32, i32)>,
hide_after_run: Option<bool>,
) {
self.plugin_dirs = plugin_dirs;
self.index_paths = index_paths;
Expand Down Expand Up @@ -146,6 +148,9 @@ impl LauncherApp {
if static_size.is_some() {
self.static_size = static_size;
}
if let Some(v) = hide_after_run {
self.hide_after_run = v;
}
}

pub fn new(
Expand Down Expand Up @@ -263,6 +268,7 @@ impl LauncherApp {
static_location_enabled: static_enabled,
static_pos,
static_size,
hide_after_run: settings.hide_after_run,
};

tracing::debug!("initial viewport visible: {}", initial_visible);
Expand Down Expand Up @@ -605,6 +611,15 @@ impl eframe::App for LauncherApp {
refresh = true;
set_focus = true;
}
if self.hide_after_run
&& !a.action.starts_with("bookmark:add:")
&& !a.action.starts_with("bookmark:remove:")
&& !a.action.starts_with("folder:add:")
&& !a.action.starts_with("folder:remove:")
&& !a.action.starts_with("calc:")
{
self.visible_flag.store(false, Ordering::SeqCst);
}
}
if refresh {
self.search();
Expand Down Expand Up @@ -774,6 +789,15 @@ impl eframe::App for LauncherApp {
refresh = true;
set_focus = true;
}
if self.hide_after_run
&& !a.action.starts_with("bookmark:add:")
&& !a.action.starts_with("bookmark:remove:")
&& !a.action.starts_with("folder:add:")
&& !a.action.starts_with("folder:remove:")
&& !a.action.starts_with("calc:")
{
self.visible_flag.store(false, Ordering::SeqCst);
}
}
self.selected = Some(idx);
}
Expand Down
1 change: 1 addition & 0 deletions src/plugin_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl PluginEditor {
Some(s.static_location_enabled),
s.static_pos,
s.static_size,
Some(s.hide_after_run),
);

app.plugins.reload_from_dirs(&self.plugin_dirs);
Expand Down
4 changes: 4 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub struct Settings {
/// Size of the window when `static_location_enabled` is true.
#[serde(default)]
pub static_size: Option<(i32, i32)>,
/// Hide the main window automatically after successfully launching an action.
#[serde(default)]
pub hide_after_run: bool,
}

fn default_toasts() -> bool { true }
Expand Down Expand Up @@ -96,6 +99,7 @@ impl Default for Settings {
static_location_enabled: false,
static_pos: None,
static_size: None,
hide_after_run: false,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/settings_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct SettingsEditor {
static_y: i32,
static_w: i32,
static_h: i32,
hide_after_run: bool,
}

impl SettingsEditor {
Expand Down Expand Up @@ -105,6 +106,7 @@ impl SettingsEditor {
static_y: settings.static_pos.unwrap_or((0, 0)).1,
static_w: settings.static_size.unwrap_or((400, 220)).0,
static_h: settings.static_size.unwrap_or((400, 220)).1,
hide_after_run: settings.hide_after_run,
}
}

Expand Down Expand Up @@ -146,6 +148,7 @@ impl SettingsEditor {
static_location_enabled: self.static_enabled,
static_pos: Some((self.static_x, self.static_y)),
static_size: Some((self.static_w, self.static_h)),
hide_after_run: self.hide_after_run,
}
}

Expand Down Expand Up @@ -233,6 +236,7 @@ impl SettingsEditor {
});

ui.checkbox(&mut self.show_toasts, "Enable toast notifications");
ui.checkbox(&mut self.hide_after_run, "Hide window after running action");

ui.horizontal(|ui| {
ui.label("Query scale");
Expand Down Expand Up @@ -373,6 +377,7 @@ impl SettingsEditor {
Some(new_settings.static_location_enabled),
new_settings.static_pos,
new_settings.static_size,
Some(new_settings.hide_after_run),
);
app.hotkey_str = new_settings.hotkey.clone();
app.quit_hotkey_str = new_settings.quit_hotkey.clone();
Expand Down
82 changes: 82 additions & 0 deletions tests/hide_after_run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use multi_launcher::gui::LauncherApp;
use multi_launcher::plugin::PluginManager;
use multi_launcher::actions::Action;
use multi_launcher::settings::Settings;
use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
use eframe::egui;

fn new_app_with_settings(ctx: &egui::Context, actions: Vec<Action>, settings: Settings) -> (LauncherApp, Arc<AtomicBool>) {
let custom_len = actions.len();
let visible = Arc::new(AtomicBool::new(true));
(
LauncherApp::new(
ctx,
actions,
custom_len,
PluginManager::new(),
"actions.json".into(),
"settings.json".into(),
settings,
None,
None,
None,
None,
visible.clone(),
Arc::new(AtomicBool::new(false)),
Arc::new(AtomicBool::new(false)),
),
visible)
}

fn run_action(action: &str) -> bool {
let ctx = egui::Context::default();
let actions = vec![Action { label: "test".into(), desc: "".into(), action: action.into(), args: None }];
let (mut app, flag) = new_app_with_settings(&ctx, actions, Settings::default());
app.update_paths(
None, None, None, None, None, None, None, None, None, None, None, None, Some(true),
);
flag.store(true, Ordering::SeqCst);
let a = app.results[0].clone();
if multi_launcher::launcher::launch_action(&a).is_ok() {
if app.hide_after_run
&& !a.action.starts_with("bookmark:add:")
&& !a.action.starts_with("bookmark:remove:")
&& !a.action.starts_with("folder:add:")
&& !a.action.starts_with("folder:remove:")
&& !a.action.starts_with("calc:")
{
flag.store(false, Ordering::SeqCst);
}
}
!flag.load(Ordering::SeqCst)
}

#[test]
fn hide_after_run_updates_visibility() {
assert!(run_action("history:clear"));
}

#[test]
fn hide_after_run_not_for_bookmark_add() {
assert!(!run_action("bookmark:add:https://example.com"));
}

#[test]
fn hide_after_run_not_for_bookmark_remove() {
assert!(!run_action("bookmark:remove:https://example.com"));
}

#[test]
fn hide_after_run_not_for_folder_add() {
assert!(!run_action("folder:add:/tmp"));
}

#[test]
fn hide_after_run_not_for_folder_remove() {
assert!(!run_action("folder:remove:/tmp"));
}

#[test]
fn hide_after_run_not_for_calc_copy() {
assert!(!run_action("calc:1+2"));
}