From fc476dfe50fa62ad6db9bbfc492b52f46c7abc70 Mon Sep 17 00:00:00 2001 From: Exidex <16986685+Exidex@users.noreply.github.com> Date: Sun, 25 Aug 2024 18:25:13 +0200 Subject: [PATCH] Add system tray on macos and windows --- Cargo.lock | 550 +++++++++++++++++++++++--- rust/client/Cargo.toml | 3 + rust/client/src/lib.rs | 21 + rust/client/src/ui/mod.rs | 6 + rust/client/src/ui/sys_tray.rs | 64 +++ rust/common/src/rpc/backend_api.rs | 10 +- rust/common/src/rpc/backend_server.rs | 12 +- rust/server/src/plugins/mod.rs | 3 +- rust/server/src/rpc.rs | 6 + schema/backend.proto | 6 + 10 files changed, 629 insertions(+), 52 deletions(-) create mode 100644 rust/client/src/ui/sys_tray.rs diff --git a/Cargo.lock b/Cargo.lock index 1583bfc..ecbcb53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -423,6 +423,29 @@ dependencies = [ "syn 2.0.59", ] +[[package]] +name = "atk" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4af014b17dd80e8af9fa689b2d4a211ddba6eb583c1622f35d0cb543f6b17e4" +dependencies = [ + "atk-sys", + "glib", + "libc", +] + +[[package]] +name = "atk-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "251e0b7d90e33e0ba930891a505a9a35ece37b2dd37a14f3ffc306c13b980009" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "atoi" version = "2.0.0" @@ -818,7 +841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5952f0958672e4aa8fc706d01905c56af57759e078c53a6fddf4a13361943e7a" dependencies = [ "block", - "core-foundation", + "core-foundation 0.9.4", "core-graphics 0.22.3", "dispatch", "lazy_static", @@ -835,6 +858,31 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bf2a5fb3207c12b5d208ebc145f967fea5cac41a021c37417ccc31ba40f39ee" +[[package]] +name = "cairo-rs" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca26ef0159422fb77631dc9d17b102f253b876fe1586b03b803e63a309b4ee2" +dependencies = [ + "bitflags 2.5.0", + "cairo-sys-rs", + "glib", + "libc", + "once_cell", + "thiserror", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685c9fa8e590b8b3d678873528d83411db17242a73fccaed827770ea0fedda51" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + [[package]] name = "calloop" version = "0.12.4" @@ -1023,6 +1071,7 @@ dependencies = [ "tonic", "tracing", "tracing-subscriber", + "tray-icon", "utils", ] @@ -1082,14 +1131,30 @@ checksum = "f6140449f97a6e97f9511815c5632d84c8aacf8ac271ad77c559218161a1373c" dependencies = [ "bitflags 1.3.2", "block", - "cocoa-foundation", - "core-foundation", + "cocoa-foundation 0.1.2", + "core-foundation 0.9.4", "core-graphics 0.23.2", "foreign-types 0.5.0", "libc", "objc", ] +[[package]] +name = "cocoa" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f79398230a6e2c08f5c9760610eb6924b52aa9e7950a619602baba59dcbbdbb2" +dependencies = [ + "bitflags 2.5.0", + "block", + "cocoa-foundation 0.2.0", + "core-foundation 0.10.0", + "core-graphics 0.24.0", + "foreign-types 0.5.0", + "libc", + "objc", +] + [[package]] name = "cocoa-foundation" version = "0.1.2" @@ -1098,8 +1163,22 @@ checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7" dependencies = [ "bitflags 1.3.2", "block", - "core-foundation", - "core-graphics-types", + "core-foundation 0.9.4", + "core-graphics-types 0.1.3", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14045fb83be07b5acf1c0884b2180461635b433455fa35d1cd6f17f1450679d" +dependencies = [ + "bitflags 2.5.0", + "block", + "core-foundation 0.10.0", + "core-graphics-types 0.2.0", "libc", "objc", ] @@ -1276,10 +1355,20 @@ dependencies = [ ] [[package]] -name = "core-foundation-sys" -version = "0.8.6" +name = "core-foundation" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core-graphics" @@ -1288,8 +1377,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", + "core-foundation 0.9.4", + "core-graphics-types 0.1.3", "foreign-types 0.3.2", "libc", ] @@ -1301,8 +1390,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", + "core-foundation 0.9.4", + "core-graphics-types 0.1.3", + "foreign-types 0.5.0", + "libc", +] + +[[package]] +name = "core-graphics" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" +dependencies = [ + "bitflags 2.5.0", + "core-foundation 0.10.0", + "core-graphics-types 0.2.0", "foreign-types 0.5.0", "libc", ] @@ -1314,7 +1416,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" +dependencies = [ + "bitflags 2.5.0", + "core-foundation 0.10.0", "libc", ] @@ -2380,6 +2493,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" +[[package]] +name = "dpi" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" + [[package]] name = "dprint-swc-ext" version = "0.11.1" @@ -2799,6 +2918,16 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +[[package]] +name = "field-offset" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +dependencies = [ + "memoffset 0.9.1", + "rustc_version 0.4.0", +] + [[package]] name = "filetime" version = "0.2.23" @@ -3147,6 +3276,64 @@ dependencies = [ "cli", ] +[[package]] +name = "gdk" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5ba081bdef3b75ebcdbfc953699ed2d7417d6bd853347a42a37d76406a33646" +dependencies = [ + "cairo-rs", + "gdk-pixbuf", + "gdk-sys", + "gio", + "glib", + "libc", + "pango", +] + +[[package]] +name = "gdk-pixbuf" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e1f5f1b0bfb830d6ccc8066d18db35c487b1b2b1e8589b5dfe9f07e8defaec" +dependencies = [ + "gdk-pixbuf-sys", + "gio", + "glib", + "libc", + "once_cell", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gdk-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31ff856cb3386dae1703a920f803abafcc580e9b5f711ca62ed1620c25b51ff2" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps", +] + [[package]] name = "generator" version = "0.7.5" @@ -3238,6 +3425,38 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "gio" +version = "0.18.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fc8f532f87b79cbc51a79748f16a6828fb784be93145a322fa14d06d354c73" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys", + "glib", + "libc", + "once_cell", + "pin-project-lite", + "smallvec", + "thiserror", +] + +[[package]] +name = "gio-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + [[package]] name = "git2" version = "0.18.3" @@ -3324,6 +3543,53 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3" +[[package]] +name = "glib" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233daaf6e83ae6a12a52055f568f9d7cf4671dabb78ff9560ab6da230ce00ee5" +dependencies = [ + "bitflags 2.5.0", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys", + "glib-macros", + "glib-sys", + "gobject-sys", + "libc", + "memchr", + "once_cell", + "smallvec", + "thiserror", +] + +[[package]] +name = "glib-macros" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" +dependencies = [ + "heck 0.4.1", + "proc-macro-crate 2.0.0", + "proc-macro-error", + "proc-macro2 1.0.80", + "quote 1.0.36", + "syn 2.0.59", +] + +[[package]] +name = "glib-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" +dependencies = [ + "libc", + "system-deps", +] + [[package]] name = "global-hotkey" version = "0.4.2" @@ -3371,6 +3637,17 @@ dependencies = [ "wgpu", ] +[[package]] +name = "gobject-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + [[package]] name = "gpu-alloc" version = "0.6.0" @@ -3445,6 +3722,58 @@ dependencies = [ "subtle", ] +[[package]] +name = "gtk" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93c4f5e0e20b60e10631a5f06da7fe3dda744b05ad0ea71fee2f47adf865890c" +dependencies = [ + "atk", + "cairo-rs", + "field-offset", + "futures-channel", + "gdk", + "gdk-pixbuf", + "gio", + "glib", + "gtk-sys", + "gtk3-macros", + "libc", + "pango", + "pkg-config", +] + +[[package]] +name = "gtk-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771437bf1de2c1c0b496c11505bdf748e26066bbe942dfc8f614c9460f6d7722" +dependencies = [ + "atk-sys", + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "system-deps", +] + +[[package]] +name = "gtk3-macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6063efb63db582968fb7df72e1ae68aa6360dcfb0a75143f34fc7d616bad75e" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro-error", + "proc-macro2 1.0.80", + "quote 1.0.36", + "syn 2.0.59", +] + [[package]] name = "guillotiere" version = "0.6.2" @@ -4453,6 +4782,30 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2cdeb66e45e9f36bfad5bbdb4d2384e70936afbee843c6f6543f0c551ebb25" +[[package]] +name = "libappindicator" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03589b9607c868cc7ae54c0b2a22c8dc03dd41692d48f2d7df73615c6a95dc0a" +dependencies = [ + "glib", + "gtk", + "gtk-sys", + "libappindicator-sys", + "log", +] + +[[package]] +name = "libappindicator-sys" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e9ec52138abedcc58dc17a7c6c0c00a2bdb4f3427c7f63fa97fd0d859155caf" +dependencies = [ + "gtk-sys", + "libloading 0.7.4", + "once_cell", +] + [[package]] name = "libc" version = "0.2.153" @@ -4520,7 +4873,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.5", + "windows-targets 0.48.5", ] [[package]] @@ -4853,6 +5206,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "metal" version = "0.27.0" @@ -4861,7 +5223,7 @@ checksum = "c43f73953f8cbe511f021b58f18c3ce1c3d1ae13fe953293e13345bf83217f25" dependencies = [ "bitflags 2.5.0", "block", - "core-graphics-types", + "core-graphics-types 0.1.3", "foreign-types 0.5.0", "log", "objc", @@ -4917,6 +5279,24 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4519a88847ba2d5ead3dc53f1060ec6a571de93f325d9c5c4968147382b1cbc3" +[[package]] +name = "muda" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba8ac4080fb1e097c2c22acae467e46e4da72d941f02e82b67a87a2a89fa38b1" +dependencies = [ + "cocoa 0.26.0", + "crossbeam-channel", + "dpi", + "gtk", + "keyboard-types", + "objc", + "once_cell", + "png 0.17.13", + "thiserror", + "windows-sys 0.59.0", +] + [[package]] name = "multimap" version = "0.8.3" @@ -5654,6 +6034,31 @@ dependencies = [ "syn 2.0.59", ] +[[package]] +name = "pango" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ca27ec1eb0457ab26f3036ea52229edbdb74dee1edd29063f5b9b010e7ebee4" +dependencies = [ + "gio", + "glib", + "libc", + "once_cell", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "parking_lot" version = "0.11.2" @@ -6103,6 +6508,15 @@ dependencies = [ "toml_edit 0.19.15", ] +[[package]] +name = "proc-macro-crate" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" +dependencies = [ + "toml_edit 0.20.7", +] + [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -7138,7 +7552,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "core-foundation-sys", "libc", "security-framework-sys", @@ -7603,7 +8017,7 @@ dependencies = [ "as-raw-xcb-connection", "bytemuck", "cfg_aliases 0.2.0", - "cocoa", + "cocoa 0.25.0", "core-graphics 0.23.2", "drm", "fastrand", @@ -8468,7 +8882,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys", ] @@ -8958,6 +9372,17 @@ dependencies = [ "winnow 0.5.40", ] +[[package]] +name = "toml_edit" +version = "0.20.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +dependencies = [ + "indexmap 2.2.6", + "toml_datetime", + "winnow 0.5.40", +] + [[package]] name = "toml_edit" version = "0.21.1" @@ -9116,6 +9541,26 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "tray-icon" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92252d649d771105448969f2b2dda4342ba48b77731b60d37c93665e26615b" +dependencies = [ + "core-graphics 0.24.0", + "crossbeam-channel", + "dirs 5.0.1", + "libappindicator", + "muda", + "objc2 0.5.2", + "objc2-app-kit", + "objc2-foundation", + "once_cell", + "png 0.17.13", + "thiserror", + "windows-sys 0.59.0", +] + [[package]] name = "triomphe" version = "0.1.11" @@ -9950,7 +10395,7 @@ dependencies = [ "bitflags 2.5.0", "block", "cfg_aliases 0.1.1", - "core-graphics-types", + "core-graphics-types 0.1.3", "d3d12", "glow", "glutin_wgl_sys", @@ -10083,7 +10528,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ "windows-core", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10092,7 +10537,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10119,7 +10564,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -10154,18 +10608,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -10182,9 +10636,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -10200,9 +10654,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -10218,15 +10672,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -10242,9 +10696,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -10260,9 +10714,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -10278,9 +10732,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -10296,9 +10750,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winit" @@ -10313,7 +10767,7 @@ dependencies = [ "bytemuck", "calloop", "cfg_aliases 0.1.1", - "core-foundation", + "core-foundation 0.9.4", "core-graphics 0.23.2", "cursor-icon", "icrate", diff --git a/rust/client/Cargo.toml b/rust/client/Cargo.toml index 210467c..c41ccc9 100644 --- a/rust/client/Cargo.toml +++ b/rust/client/Cargo.toml @@ -22,6 +22,9 @@ serde_json = "1.0" once_cell = "1.19" bytes = "1.6.0" +[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] +tray-icon = { version = "0.15.1", default-features = false } + [target.'cfg(target_os = "linux")'.dependencies] iced.workspace = true iced.features = ["wayland"] diff --git a/rust/client/src/lib.rs b/rust/client/src/lib.rs index c5f812c..209b5ff 100644 --- a/rust/client/src/lib.rs +++ b/rust/client/src/lib.rs @@ -38,6 +38,27 @@ pub fn open_window() { }) } +pub fn open_settings_window() { + tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("unable to start server tokio runtime") + .block_on(async { + let result = BackendApi::new().await; + + match result { + Ok(mut backend_api) => { + backend_api.show_settings_window() + .await + .expect("Unknown error") + } + Err(_) => { + tracing::error!("Unable to connect to server. Please check if you have Gauntlet running on your PC") + } + } + }) +} + pub fn generate_theme_sample() -> anyhow::Result<()> { let dirs = Dirs::new(); diff --git a/rust/client/src/ui/mod.rs b/rust/client/src/ui/mod.rs index aed1b54..1129836 100644 --- a/rust/client/src/ui/mod.rs +++ b/rust/client/src/ui/mod.rs @@ -47,6 +47,8 @@ mod theme; mod client_context; mod widget_container; mod inline_view_container; +#[cfg(any(target_os = "macos", target_os = "windows"))] +mod sys_tray; pub use theme::GauntletTheme; @@ -59,6 +61,8 @@ pub struct AppModel { focused: bool, theme: GauntletTheme, wayland: bool, + #[cfg(any(target_os = "macos", target_os = "windows"))] + tray_icon: tray_icon::TrayIcon, // ephemeral state prompt: String, @@ -370,6 +374,8 @@ impl Application for AppModel { focused: false, theme: GauntletTheme::new(), wayland, + #[cfg(any(target_os = "macos", target_os = "windows"))] + tray_icon: sys_tray::create_tray(), // ephemeral state prompt: "".to_string(), diff --git a/rust/client/src/ui/sys_tray.rs b/rust/client/src/ui/sys_tray.rs new file mode 100644 index 0000000..c4bcd54 --- /dev/null +++ b/rust/client/src/ui/sys_tray.rs @@ -0,0 +1,64 @@ +use image::ImageFormat; + +pub fn create_tray() -> tray_icon::TrayIcon { + use tray_icon::TrayIconBuilder; + use tray_icon::menu::{MenuEvent, Menu, MenuItem, PredefinedMenuItem, AboutMetadataBuilder}; + + MenuEvent::set_event_handler(Some(|event: MenuEvent| { + match event.id().as_ref() { + "GAUNTLET_OPEN_MAIN_WINDOW" => { + crate::open_window() + } + "GAUNTLET_OPEN_SETTING_WINDOW" => { + crate::open_settings_window() + } + _ => {} + } + })); + + let (tray_icon, muda_icon) = { + let bytes = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../assets/linux/icon_256.png")); + + let image = image::load_from_memory_with_format(bytes, ImageFormat::Png) + .expect("Failed to open icon path") + .into_rgba8(); + + let (width, height) = image.dimensions(); + let rgba = image.into_raw(); + + let tray_icon = tray_icon::Icon::from_rgba(rgba.clone(), width, height) + .expect("Failed to open icon"); + + let muda_icon = tray_icon::menu::Icon::from_rgba(rgba, width, height) + .expect("Failed to open icon"); + + (tray_icon, muda_icon) + }; + + let about_metadata = AboutMetadataBuilder::new() + .name(Some("Gauntlet")) + .version(Some(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../VERSION")))) + .authors(Some(vec!["Exidex".to_string()])) + .credits(Some("Exidex".to_string())) + .license(Some("MPL-2.0")) + .website(Some("https://github.com/project-gauntlet/gauntlet")) + .icon(Some(muda_icon)) + .build(); + + let menu = Menu::with_items( + &[ + &MenuItem::new("Gauntlet", false, None), + &MenuItem::with_id("GAUNTLET_OPEN_MAIN_WINDOW", "Open", true, None), + &MenuItem::with_id("GAUNTLET_OPEN_SETTING_WINDOW", "Open Settings", true, None), + &PredefinedMenuItem::separator(), + &PredefinedMenuItem::about(Some("About..."), Some(about_metadata)), + &PredefinedMenuItem::quit(Some("Quit Gauntlet")), + ] + ).expect("unable to create tray menu"); + + TrayIconBuilder::new() + .with_menu(Box::new(menu)) + .with_icon(tray_icon) + .build() + .expect("unable to create tray") +} \ No newline at end of file diff --git a/rust/common/src/rpc/backend_api.rs b/rust/common/src/rpc/backend_api.rs index 952b941..c448d82 100644 --- a/rust/common/src/rpc/backend_api.rs +++ b/rust/common/src/rpc/backend_api.rs @@ -7,7 +7,7 @@ use tonic::transport::Channel; use utils::channel::{RequestError, RequestSender}; use crate::model::{BackendRequestData, BackendResponseData, DownloadStatus, EntrypointId, LocalSaveData, PhysicalKey, PhysicalShortcut, PluginId, PluginPreferenceUserData, SearchResult, SettingsEntrypoint, SettingsEntrypointType, SettingsPlugin, UiPropertyValue, UiWidgetId}; -use crate::rpc::grpc::{RpcDownloadPluginRequest, RpcDownloadStatus, RpcDownloadStatusRequest, RpcEntrypointTypeSettings, RpcGetGlobalShortcutRequest, RpcPingRequest, RpcPluginsRequest, RpcRemovePluginRequest, RpcSaveLocalPluginRequest, RpcSetEntrypointStateRequest, RpcSetGlobalShortcutRequest, RpcSetPluginStateRequest, RpcSetPreferenceValueRequest, RpcShowWindowRequest}; +use crate::rpc::grpc::{RpcDownloadPluginRequest, RpcDownloadStatus, RpcDownloadStatusRequest, RpcEntrypointTypeSettings, RpcGetGlobalShortcutRequest, RpcPingRequest, RpcPluginsRequest, RpcRemovePluginRequest, RpcSaveLocalPluginRequest, RpcSetEntrypointStateRequest, RpcSetGlobalShortcutRequest, RpcSetPluginStateRequest, RpcSetPreferenceValueRequest, RpcShowSettingsWindowRequest, RpcShowWindowRequest}; use crate::rpc::grpc::rpc_backend_client::RpcBackendClient; use crate::rpc::grpc_convert::{plugin_preference_from_rpc, plugin_preference_user_data_from_rpc, plugin_preference_user_data_to_rpc}; @@ -242,6 +242,14 @@ impl BackendApi { Ok(()) } + + pub async fn show_settings_window(&mut self) -> Result<(), BackendApiError> { + let _ = self.client.show_settings_window(Request::new(RpcShowSettingsWindowRequest::default())) + .await?; + + Ok(()) + } + pub async fn plugins(&mut self) -> Result, BackendApiError> { let plugins = self.client.plugins(Request::new(RpcPluginsRequest::default())) .await? diff --git a/rust/common/src/rpc/backend_server.rs b/rust/common/src/rpc/backend_server.rs index d1600db..747bae5 100644 --- a/rust/common/src/rpc/backend_server.rs +++ b/rust/common/src/rpc/backend_server.rs @@ -7,7 +7,7 @@ use tonic::{Request, Response, Status}; use tonic::transport::Server; use crate::model::{DownloadStatus, EntrypointId, LocalSaveData, PhysicalKey, PhysicalShortcut, PluginId, PluginPreferenceUserData, SettingsEntrypointType, SettingsPlugin}; -use crate::rpc::grpc::{RpcDownloadPluginRequest, RpcDownloadPluginResponse, RpcDownloadStatus, RpcDownloadStatusRequest, RpcDownloadStatusResponse, RpcDownloadStatusValue, RpcEntrypoint, RpcEntrypointTypeSettings, RpcGetGlobalShortcutRequest, RpcGetGlobalShortcutResponse, RpcPingRequest, RpcPingResponse, RpcPlugin, RpcPluginsRequest, RpcPluginsResponse, RpcRemovePluginRequest, RpcRemovePluginResponse, RpcSaveLocalPluginRequest, RpcSaveLocalPluginResponse, RpcSetEntrypointStateRequest, RpcSetEntrypointStateResponse, RpcSetGlobalShortcutRequest, RpcSetGlobalShortcutResponse, RpcSetPluginStateRequest, RpcSetPluginStateResponse, RpcSetPreferenceValueRequest, RpcSetPreferenceValueResponse, RpcShowWindowRequest, RpcShowWindowResponse}; +use crate::rpc::grpc::{RpcDownloadPluginRequest, RpcDownloadPluginResponse, RpcDownloadStatus, RpcDownloadStatusRequest, RpcDownloadStatusResponse, RpcDownloadStatusValue, RpcEntrypoint, RpcEntrypointTypeSettings, RpcGetGlobalShortcutRequest, RpcGetGlobalShortcutResponse, RpcPingRequest, RpcPingResponse, RpcPlugin, RpcPluginsRequest, RpcPluginsResponse, RpcRemovePluginRequest, RpcRemovePluginResponse, RpcSaveLocalPluginRequest, RpcSaveLocalPluginResponse, RpcSetEntrypointStateRequest, RpcSetEntrypointStateResponse, RpcSetGlobalShortcutRequest, RpcSetGlobalShortcutResponse, RpcSetPluginStateRequest, RpcSetPluginStateResponse, RpcSetPreferenceValueRequest, RpcSetPreferenceValueResponse, RpcShowSettingsWindowRequest, RpcShowSettingsWindowResponse, RpcShowWindowRequest, RpcShowWindowResponse}; use crate::rpc::grpc::rpc_backend_server::{RpcBackend, RpcBackendServer}; use crate::rpc::grpc_convert::{plugin_preference_to_rpc, plugin_preference_user_data_from_rpc, plugin_preference_user_data_to_rpc}; @@ -49,6 +49,8 @@ impl RpcBackendServerImpl { pub trait BackendServer { async fn show_window(&self) -> anyhow::Result<()>; + async fn show_settings_window(&self) -> anyhow::Result<()>; + async fn plugins(&self) -> anyhow::Result>; async fn set_plugin_state( @@ -105,6 +107,14 @@ impl RpcBackend for RpcBackendServerImpl { Ok(Response::new(RpcShowWindowResponse::default())) } + async fn show_settings_window(&self, _request: Request) -> Result, Status> { + self.server.show_settings_window() + .await + .map_err(|err| Status::internal(format!("{:#}", err)))?; + + Ok(Response::new(RpcShowSettingsWindowResponse::default())) + } + async fn plugins(&self, _: Request) -> Result, Status> { let plugins = self.server.plugins() .await diff --git a/rust/server/src/plugins/mod.rs b/rust/server/src/plugins/mod.rs index cc81832..be09932 100644 --- a/rust/server/src/plugins/mod.rs +++ b/rust/server/src/plugins/mod.rs @@ -422,7 +422,7 @@ impl ApplicationManager { } } - pub fn handle_open_settings_window(&self){ + pub fn handle_open_settings_window(&self) { let current_exe = std::env::current_exe() .expect("unable to get current_exe"); @@ -430,7 +430,6 @@ impl ApplicationManager { .args(["settings"]) .spawn() .expect("failed to execute settings process"); - } pub fn handle_open_settings_window_preferences(&self, plugin_id: PluginId, entrypoint_id: Option) { diff --git a/rust/server/src/rpc.rs b/rust/server/src/rpc.rs index 15f4dcf..060b51c 100644 --- a/rust/server/src/rpc.rs +++ b/rust/server/src/rpc.rs @@ -28,6 +28,12 @@ impl BackendServer for BackendServerImpl { self.application_manager.show_window().await } + async fn show_settings_window(&self) -> anyhow::Result<()> { + self.application_manager.handle_open_settings_window(); + + Ok(()) + } + async fn plugins(&self) -> anyhow::Result> { let result = self.application_manager.plugins() .await; diff --git a/schema/backend.proto b/schema/backend.proto index 60de86d..7418b77 100644 --- a/schema/backend.proto +++ b/schema/backend.proto @@ -8,6 +8,7 @@ service RpcBackend { // cli rpc ShowWindow (RpcShowWindowRequest) returns (RpcShowWindowResponse); + rpc ShowSettingsWindow (RpcShowSettingsWindowRequest) returns (RpcShowSettingsWindowResponse); // settings rpc Plugins (RpcPluginsRequest) returns (RpcPluginsResponse); @@ -36,6 +37,11 @@ message RpcShowWindowRequest { message RpcShowWindowResponse { } +message RpcShowSettingsWindowRequest { +} +message RpcShowSettingsWindowResponse { +} + message RpcPingRequest { } message RpcPingResponse {