From 59402e01dd5255b4ba0a1159a81d5481125741d3 Mon Sep 17 00:00:00 2001 From: Volkov Maksim Date: Sat, 20 Jan 2024 16:03:51 +0300 Subject: [PATCH] Add option to start minimized --- resources/ui/SettingsWindow.ui | 14 ++++++++++++++ src/Config.vala | 2 ++ src/CryptorApp.vala | 2 +- src/ui/CryptorWindow.vala | 8 ++++++++ src/ui/SettingsWindow.vala | 12 +++++++++++- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/resources/ui/SettingsWindow.ui b/resources/ui/SettingsWindow.ui index 52c6788..0da14f6 100644 --- a/resources/ui/SettingsWindow.ui +++ b/resources/ui/SettingsWindow.ui @@ -112,6 +112,20 @@ 4 + + + Start minimized to tray + True + True + False + True + + + False + True + 5 + + diff --git a/src/Config.vala b/src/Config.vala index d4ab642..64e69d9 100644 --- a/src/Config.vala +++ b/src/Config.vala @@ -8,6 +8,7 @@ namespace Cryptor { public bool autosave_on_quit { get; set; } public bool show_tray_icon { get; set; } public bool send_to_tray { get; set; } + public bool start_minimized { get; set; } public Gee.ArrayList vaults { get; set; } @@ -17,6 +18,7 @@ namespace Cryptor { autosave_on_quit = true; show_tray_icon = false; send_to_tray = false; + start_minimized = false; vaults = new Gee.ArrayList (); } diff --git a/src/CryptorApp.vala b/src/CryptorApp.vala index 6db3577..249ca5f 100644 --- a/src/CryptorApp.vala +++ b/src/CryptorApp.vala @@ -14,7 +14,7 @@ namespace Cryptor { protected override void activate () { var win = new UI.CryptorWindow (this); - win.show_all (); + win.show_or_not_show (); } public static int main (string[] args) { diff --git a/src/ui/CryptorWindow.vala b/src/ui/CryptorWindow.vala index cc611f6..2b1f5ad 100644 --- a/src/ui/CryptorWindow.vala +++ b/src/ui/CryptorWindow.vala @@ -59,6 +59,14 @@ namespace Cryptor.UI { show_tray_icon (); } + public void show_or_not_show () { + if (config.start_minimized && tray != null) { + this.hide (); + } else { + this.show_all (); + } + } + [GtkCallback] private void on_mi_quit_activate (Gtk.MenuItem mi) { save_before_quit (null, null); diff --git a/src/ui/SettingsWindow.vala b/src/ui/SettingsWindow.vala index a31b0fe..2f430f7 100644 --- a/src/ui/SettingsWindow.vala +++ b/src/ui/SettingsWindow.vala @@ -6,6 +6,7 @@ namespace Cryptor.UI { public class SettingsWindow : Dialog { private Config config; bool prev_send_to_tray; + bool prev_start_minimized; [GtkChild] private unowned CheckButton check_unmount; @@ -19,6 +20,8 @@ namespace Cryptor.UI { [GtkChild] private unowned CheckButton check_send_to_tray; + [GtkChild] + private unowned CheckButton check_start_minimized; public SettingsWindow (Window parent, Config config) { Object ( @@ -29,7 +32,9 @@ namespace Cryptor.UI { check_autosave.active = config.autosave_on_quit; check_show_tray.active = config.show_tray_icon; check_send_to_tray.active = config.send_to_tray; + check_start_minimized.active = config.start_minimized; prev_send_to_tray = config.send_to_tray; + prev_start_minimized = config.start_minimized; } [GtkCallback] @@ -38,6 +43,7 @@ namespace Cryptor.UI { config.autosave_on_quit = check_autosave.active; config.show_tray_icon = check_show_tray.active; config.send_to_tray = check_send_to_tray.active; + config.start_minimized = check_start_minimized.active; config.changes_made = true; this.close (); } @@ -52,10 +58,14 @@ namespace Cryptor.UI { if (cb.active) { check_send_to_tray.sensitive = true; check_send_to_tray.active = prev_send_to_tray; + check_start_minimized.sensitive = true; + check_start_minimized.active = prev_start_minimized; } else { check_send_to_tray.active = false; check_send_to_tray.sensitive = false; + check_start_minimized.active = false; + check_start_minimized.sensitive = false; } } } -} \ No newline at end of file +}