From c7a4ddad63f5742abb329ccbe8db42e3bd6ed8dd Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:31:16 +0100 Subject: [PATCH 01/13] update libcosmic + do not serialize settings at first launch --- Cargo.lock | 467 ++++++++++++++++++++++++++++++---------- data/src/dir_manager.rs | 6 +- data/src/settings.rs | 3 +- 3 files changed, 353 insertions(+), 123 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cfa0798..9372773 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,9 +197,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.17" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23a1e53f0f5d86382dafe1cf314783b2044280f406e7e1506368220ad11b1338" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -212,9 +212,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" @@ -425,7 +425,7 @@ dependencies = [ "futures-lite 2.4.0", "parking", "polling 3.7.3", - "rustix 0.38.38", + "rustix 0.38.39", "slab", "tracing", "windows-sys 0.59.0", @@ -475,7 +475,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.38", + "rustix 0.38.39", "windows-sys 0.48.0", ] @@ -494,7 +494,7 @@ dependencies = [ "cfg-if", "event-listener 5.3.1", "futures-lite 2.4.0", - "rustix 0.38.38", + "rustix 0.38.39", "tracing", ] @@ -506,7 +506,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -521,7 +521,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.38", + "rustix 0.38.39", "signal-hook-registry", "slab", "windows-sys 0.59.0", @@ -541,7 +541,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -555,7 +555,7 @@ name = "atomicwrites" version = "0.4.2" source = "git+https://github.com/jackpot51/rust-atomicwrites#043ab4859d53ffd3d55334685303d8df39c9f768" dependencies = [ - "rustix 0.38.38", + "rustix 0.38.39", "tempfile", "windows-sys 0.48.0", ] @@ -667,7 +667,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -772,7 +772,7 @@ checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -811,7 +811,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -829,7 +829,7 @@ dependencies = [ "bitflags 2.6.0", "log", "polling 3.7.3", - "rustix 0.38.38", + "rustix 0.38.39", "slab", "thiserror", ] @@ -841,7 +841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" dependencies = [ "calloop", - "rustix 0.38.38", + "rustix 0.38.39", "wayland-backend", "wayland-client", ] @@ -869,9 +869,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.31" +version = "1.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +checksum = "baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d70" dependencies = [ "jobserver", "libc", @@ -967,7 +967,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1214,7 +1214,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1233,7 +1233,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "quote", "syn 1.0.109", @@ -1265,7 +1265,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "almost", "cosmic-config", @@ -1341,7 +1341,7 @@ dependencies = [ "crossterm_winapi", "mio 1.0.2", "parking_lot 0.12.3", - "rustix 0.38.38", + "rustix 0.38.39", "signal-hook", "signal-hook-mio", "winapi", @@ -1395,7 +1395,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" dependencies = [ "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1442,7 +1442,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1453,7 +1453,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1528,7 +1528,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "unicode-xid", ] @@ -1541,7 +1541,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1598,7 +1598,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1661,7 +1661,7 @@ dependencies = [ "bytemuck", "drm-ffi", "drm-fourcc", - "rustix 0.38.38", + "rustix 0.38.39", ] [[package]] @@ -1671,7 +1671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41334f8405792483e32ad05fbb9c5680ff4e84491883d2947a4757dc54cb2ac6" dependencies = [ "drm-sys", - "rustix 0.38.38", + "rustix 0.38.39", ] [[package]] @@ -1726,7 +1726,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1986,9 +1986,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "font-types" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda6e36206148f69fc6ecb1bb6c0dedd7ee469f3db1d0dc2045beea28430ca43" +checksum = "b3971f9a5ca983419cdc386941ba3b9e1feba01a0ab888adf78739feb2798492" dependencies = [ "bytemuck", ] @@ -2048,7 +2048,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2183,7 +2183,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2413,9 +2413,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" [[package]] name = "hassle-rs" @@ -2527,7 +2527,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.85", + "syn 2.0.87", "unic-langid", ] @@ -2541,7 +2541,7 @@ dependencies = [ "i18n-config", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2570,7 +2570,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_accessibility", @@ -2588,7 +2588,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "accesskit", "accesskit_winit", @@ -2597,7 +2597,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bitflags 2.6.0", "bytes", @@ -2620,7 +2620,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "futures", "iced_core", @@ -2646,7 +2646,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -2668,7 +2668,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2680,7 +2680,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bytes", "dnd", @@ -2694,7 +2694,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bytemuck", "cosmic-text", @@ -2710,7 +2710,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "as-raw-xcb-connection", "bitflags 2.6.0", @@ -2726,7 +2726,7 @@ dependencies = [ "raw-window-handle", "resvg", "rustc-hash 2.0.0", - "rustix 0.38.38", + "rustix 0.38.39", "smithay-client-toolkit", "thiserror", "tiny-xlib", @@ -2741,7 +2741,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_renderer", @@ -2758,7 +2758,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_futures", @@ -2775,6 +2775,124 @@ dependencies = [ "winit", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -2783,12 +2901,23 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -2831,7 +2960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.1", ] [[package]] @@ -3077,7 +3206,7 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#4b562867eccb65895953023a19393fa293aafb4b" +source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "apply", "ashpd 0.9.2", @@ -3147,7 +3276,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcb64f856d7b5144b0c102ec029f4d8a474c91c86336a2f5e96494e3d2f72db3" dependencies = [ "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3168,6 +3297,12 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a385b1be4e5c3e362ad2ffa73c392e53f031eaa5b7d648e64cd87f27f6063d7" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "litrs" version = "0.4.1" @@ -3610,7 +3745,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3917,7 +4052,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3951,7 +4086,7 @@ dependencies = [ "by_address", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4050,7 +4185,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4085,7 +4220,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4156,7 +4291,7 @@ dependencies = [ "concurrent-queue", "hermit-abi 0.4.0", "pin-project-lite", - "rustix 0.38.38", + "rustix 0.38.39", "tracing", "windows-sys 0.59.0", ] @@ -4189,7 +4324,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4230,7 +4365,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4250,7 +4385,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "version_check", "yansi", ] @@ -4525,7 +4660,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.85", + "syn 2.0.87", "walkdir", ] @@ -4583,9 +4718,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.38" +version = "0.38.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa260229e6538e52293eeb577aabd09945a09d6d9cc0fc550ed7529056c2e32a" +checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" dependencies = [ "bitflags 2.6.0", "errno", @@ -4710,7 +4845,7 @@ checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4734,7 +4869,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4768,7 +4903,7 @@ checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -4905,7 +5040,7 @@ dependencies = [ "log", "memmap2 0.9.5", "pkg-config", - "rustix 0.38.38", + "rustix 0.38.39", "thiserror", "wayland-backend", "wayland-client", @@ -4977,7 +5112,7 @@ dependencies = [ "objc", "raw-window-handle", "redox_syscall 0.4.1", - "rustix 0.38.38", + "rustix 0.38.39", "tiny-xlib", "wasm-bindgen", "wayland-backend", @@ -4997,6 +5132,12 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -5020,9 +5161,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "svg_fmt" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20e16a0f46cf5fd675563ef54f26e83e20f2366bcf027bcb3cc3ed2b98aaf2ca" +checksum = "ce5d813d71d82c4cbc1742135004e4a79fd870214c155443451c139c9470a0aa" [[package]] name = "svgtypes" @@ -5058,20 +5199,31 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.85" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "sys-locale" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e801cf239ecd6ccd71f03d270d67dd53d13e90aab208bf4b8fe4ad957ea949b0" +checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4" dependencies = [ "libc", ] @@ -5096,7 +5248,7 @@ dependencies = [ "cfg-if", "fastrand 2.1.1", "once_cell", - "rustix 0.38.38", + "rustix 0.38.39", "windows-sys 0.59.0", ] @@ -5111,22 +5263,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.65" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -5195,6 +5347,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" dependencies = [ "displaydoc", + "zerovec", ] [[package]] @@ -5238,7 +5391,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -5325,7 +5478,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -5446,15 +5599,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" -[[package]] -name = "unicode-normalization" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-properties" version = "0.1.3" @@ -5493,9 +5637,9 @@ checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "url" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", "idna", @@ -5549,6 +5693,18 @@ dependencies = [ "xmlwriter", ] +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -5615,7 +5771,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -5649,7 +5805,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5683,7 +5839,7 @@ checksum = "056535ced7a150d45159d3a8dc30f91a2e2d588ca0b23f70e56033622b8016f6" dependencies = [ "cc", "downcast-rs", - "rustix 0.38.38", + "rustix 0.38.39", "scoped-tls", "smallvec", "wayland-sys", @@ -5696,7 +5852,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b66249d3fc69f76fd74c82cc319300faa554e9d865dab1f7cd66cc20db10b280" dependencies = [ "bitflags 2.6.0", - "rustix 0.38.38", + "rustix 0.38.39", "wayland-backend", "wayland-scanner", ] @@ -5718,7 +5874,7 @@ version = "0.31.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b08bc3aafdb0035e7fe0fdf17ba0c09c268732707dca4ae098f60cb28c9e4c" dependencies = [ - "rustix 0.38.38", + "rustix 0.38.39", "wayland-client", "xcursor", ] @@ -6017,7 +6173,7 @@ checksum = "942ac266be9249c84ca862f0a164a39533dc2f6f33dc98ec89c8da99b82ea0bd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -6028,7 +6184,7 @@ checksum = "da33557140a288fae4e1d5f8873aaf9eb6613a9cf82c3e070223ff177f598b60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -6285,7 +6441,7 @@ dependencies = [ "pin-project", "raw-window-handle", "redox_syscall 0.4.1", - "rustix 0.38.38", + "rustix 0.38.39", "sctk-adwaita", "smithay-client-toolkit", "smol_str", @@ -6332,6 +6488,18 @@ dependencies = [ "toml 0.5.11", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "x11-dl" version = "2.21.0" @@ -6354,7 +6522,7 @@ dependencies = [ "libc", "libloading", "once_cell", - "rustix 0.38.38", + "rustix 0.38.39", "x11rb-protocol", ] @@ -6421,9 +6589,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.22" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4e2e2f7cba5a093896c1e150fbfe177d1883e7448200efb81d40b9d339ef26" +checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f" [[package]] name = "xmlwriter" @@ -6443,6 +6611,30 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c94451ac9513335b5e23d7a8a2b61a7102398b8cca5160829d313e84c9d98be1" +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", +] + [[package]] name = "zbus" version = "3.15.2" @@ -6541,7 +6733,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "zvariant_utils 2.1.0", ] @@ -6591,7 +6783,50 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", +] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] @@ -6653,7 +6888,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "zvariant_utils 2.1.0", ] @@ -6676,5 +6911,5 @@ checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] diff --git a/data/src/dir_manager.rs b/data/src/dir_manager.rs index c71c956..44956a7 100644 --- a/data/src/dir_manager.rs +++ b/data/src/dir_manager.rs @@ -238,11 +238,7 @@ fn init_settings(config_dir_path: &Path) -> Settings { let settings_file_path = config_dir_path.join(SETTINGS_FILENAME); if !settings_file_path.exists() { - let default_settings = Settings::default(); - if let Err(e) = serialize(&settings_file_path, &default_settings) { - error!("can't init settings: {}", e); - } - default_settings + Settings::default() } else { match deserialize(&settings_file_path) { Ok(t) => t, diff --git a/data/src/settings.rs b/data/src/settings.rs index c3775fd..7364356 100644 --- a/data/src/settings.rs +++ b/data/src/settings.rs @@ -3,14 +3,13 @@ use serde::{Deserialize, Serialize}; use std::fmt::Display; #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(default)] pub struct Settings { - #[serde(default)] pub theme: AppTheme, #[serde(default = "default_update_delay")] pub update_delay: u64, - #[serde(default)] pub current_config: Option, } From 3072e3fc054f9e59d7239bf704f396509f8be8eb Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:54:17 +0100 Subject: [PATCH 02/13] add state --- data/src/dir_manager.rs | 105 ++++++++++++++++++++++++++++------------ data/src/settings.rs | 13 ++--- 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/data/src/dir_manager.rs b/data/src/dir_manager.rs index 44956a7..e806edc 100644 --- a/data/src/dir_manager.rs +++ b/data/src/dir_manager.rs @@ -9,7 +9,11 @@ use hardware::Hardware; use thiserror::Error; use utils::{APP, ORG, QUALIFIER}; -use crate::{config::Config, settings::Settings, utils::RemoveElem}; +use crate::{ + config::Config, + settings::{Settings, SettingsState}, + utils::RemoveElem, +}; use self::helper::{deserialize, serialize}; @@ -21,8 +25,10 @@ pub struct ConfigNames { #[derive(Debug)] pub struct DirManager { pub config_dir_path: PathBuf, + pub state_dir_path: PathBuf, pub config_names: ConfigNames, settings: Settings, + state: SettingsState, } #[derive(Error, Debug)] @@ -40,18 +46,17 @@ pub enum ConfigError { type Result = std::result::Result; static SETTINGS_FILENAME: &str = "settings.toml"; +static STATE_FILENAME: &str = "state.toml"; static HARDWARE_FILENAME: &str = "hardware.toml"; impl DirManager { - pub fn new(config_dir_path: &Option, config_name: &Option) -> DirManager { - fn default_config_dir_path() -> PathBuf { - ProjectDirs::from(QUALIFIER, ORG, APP) - .unwrap() - .config_dir() - .to_path_buf() - } + pub fn new( + custom_config_dir_path: &Option, + custom_config_name: &Option, + ) -> DirManager { + let project_dirs = ProjectDirs::from(QUALIFIER, ORG, APP).unwrap(); - let config_dir_path = match config_dir_path { + let config_dir_path = match custom_config_dir_path { Some(config_dir_path) => { if config_dir_path.exists() { if config_dir_path.is_dir() { @@ -61,7 +66,7 @@ impl DirManager { "The path {} is not a directory. Fall back to default directory.", config_dir_path.display() ); - default_config_dir_path() + project_dirs.config_dir().to_path_buf() } } else { warn!( @@ -71,7 +76,7 @@ impl DirManager { config_dir_path.clone() } } - None => default_config_dir_path(), + None => project_dirs.config_dir().to_path_buf(), }; if !config_dir_path.exists() { @@ -80,11 +85,25 @@ impl DirManager { } } - let mut settings = init_settings(&config_dir_path); + let mut settings = { + let settings_file_path = config_dir_path.join(SETTINGS_FILENAME); + + if !settings_file_path.exists() { + Settings::default() + } else { + match deserialize(&settings_file_path) { + Ok(t) => t, + Err(e) => { + error!("can't deserialize settings at init: {}", e); + Settings::default() + } + } + } + }; let config_names = ConfigNames::new(&config_dir_path); - if let Some(config_name) = config_name { + if let Some(config_name) = custom_config_name { let config_name = helper::remove_toml_extension(config_name).to_owned(); settings.current_config = if config_names.contains(&config_name) { Some(config_name) @@ -94,10 +113,36 @@ impl DirManager { } }; + let state_dir_path = project_dirs.data_local_dir().to_path_buf(); + + if !state_dir_path.exists() { + if let Err(e) = fs::create_dir_all(&state_dir_path) { + error!("Can't create config directories: {e}.") + } + } + + let state = { + let state_file_path = state_dir_path.join(STATE_FILENAME); + + if !state_file_path.exists() { + SettingsState::default() + } else { + match deserialize(&state_file_path) { + Ok(t) => t, + Err(e) => { + error!("can't deserialize settings at init: {}", e); + SettingsState::default() + } + } + } + }; + DirManager { config_names, config_dir_path, settings, + state, + state_dir_path, } } @@ -109,6 +154,10 @@ impl DirManager { self.config_dir_path.join(HARDWARE_FILENAME) } + fn state_file_path(&self) -> PathBuf { + self.state_dir_path.join(STATE_FILENAME) + } + fn config_file_path(&self, name: &str) -> PathBuf { self.config_dir_path .join(helper::add_toml_extension(name).into_owned()) @@ -121,7 +170,19 @@ impl DirManager { pub fn update_settings(&mut self, mut f: impl FnMut(&mut Settings)) { f(&mut self.settings); - if let Err(e) = serialize(&self.settings_file_path(), &self.settings()) { + if let Err(e) = serialize(&self.settings_file_path(), &self.settings) { + error!("{e}"); + } + } + + pub fn state(&self) -> &SettingsState { + &self.state + } + + pub fn update_state(&mut self, mut f: impl FnMut(&mut SettingsState)) { + f(&mut self.state); + + if let Err(e) = serialize(&self.state_file_path(), &self.state) { error!("{e}"); } } @@ -234,22 +295,6 @@ impl DirManager { } } -fn init_settings(config_dir_path: &Path) -> Settings { - let settings_file_path = config_dir_path.join(SETTINGS_FILENAME); - - if !settings_file_path.exists() { - Settings::default() - } else { - match deserialize(&settings_file_path) { - Ok(t) => t, - Err(e) => { - error!("can't deserialize settings at init: {}", e); - Settings::default() - } - } - } -} - impl ConfigNames { fn new(config_dir_path: &Path) -> Self { let mut config_names = ConfigNames { data: Vec::new() }; diff --git a/data/src/settings.rs b/data/src/settings.rs index 7364356..6ed8a19 100644 --- a/data/src/settings.rs +++ b/data/src/settings.rs @@ -2,12 +2,17 @@ use light_enum::Values; use serde::{Deserialize, Serialize}; use std::fmt::Display; +#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[serde(default)] +pub struct SettingsState { + show_flatpak_dialog: bool, +} + #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(default)] pub struct Settings { pub theme: AppTheme, - #[serde(default = "default_update_delay")] pub update_delay: u64, pub current_config: Option, @@ -29,16 +34,12 @@ impl Default for Settings { fn default() -> Self { Self { theme: Default::default(), - update_delay: default_update_delay(), + update_delay: 1500, current_config: Default::default(), } } } -fn default_update_delay() -> u64 { - 1500 -} - impl Settings { pub fn current_config_text(&self) -> &str { match &self.current_config { From 6a1635c8f060e98fab64af2d6887f71586f31df7 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:06:38 +0100 Subject: [PATCH 03/13] add stucture --- .cargo/config.toml | 1 + .vscode/settings.json | 3 +++ Cargo.toml | 32 +++++++++++++++++++------------- data/src/settings.rs | 12 ++++++++++-- ui/Cargo.toml | 3 +++ ui/build.rs | 9 +++++++++ ui/src/dialogs.rs | 28 ++++++++++++++++++++++++++++ ui/src/lib.rs | 16 ++++++++++++++++ utils/Cargo.toml | 4 ++-- 9 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 ui/build.rs create mode 100644 ui/src/dialogs.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 2dd62ff..fcc51b1 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -4,6 +4,7 @@ LMSENSORS_INCLUDE_DIR = { value = "build/libsensors/include", relative = true } LMSENSORS_LIB_DIR = { value = "build/libsensors/lib", relative = true } RUST_LOG = "warn,fan_control=info,ui=info,data=info,hardware=info" RUST_BACKTRACE = "full" +FAN_CONTROL_FORMAT = "flatpak" [build] # Because compilation fails on Fedora 39 if not enabled diff --git a/.vscode/settings.json b/.vscode/settings.json index e85d955..db27614 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,6 @@ { "rust-analyzer.cargo.features": "all", + "cSpell.words": [ + "Flatpak" + ], } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 3c4243c..3ac4c31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,19 +40,10 @@ ui = ["dep:ui"] fake_hardware = ["hardware/fake_hardware"] -[dependencies] -data.workspace = true -ui = { workspace = true, optional = true } -thiserror.workspace = true -clap.workspace = true -log.workspace = true -env_logger.workspace = true -hardware.workspace = true -crossterm = "0.28" - -[build-dependencies] -winres = "0.1" - +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(FAN_CONTROL_FORMAT, values("flatpak"))', +] } [workspace.dependencies] hardware = { path = "hardware" } @@ -82,5 +73,20 @@ derive_more = { version = "1", default-features = false, features = [ # libcosmic = { path = "../libcosmic" } # libcosmic = { git = "https://github.com/wiiznokes/libcosmic", rev = "2dff73b8b2871afca6c65c861954c196818f960f" } + +[dependencies] +data.workspace = true +ui = { workspace = true, optional = true } +thiserror.workspace = true +clap.workspace = true +log.workspace = true +env_logger.workspace = true +hardware.workspace = true +crossterm = "0.28" + +[build-dependencies] +winres = "0.1" + + [profile.release] lto = "fat" diff --git a/data/src/settings.rs b/data/src/settings.rs index 6ed8a19..f9c5f18 100644 --- a/data/src/settings.rs +++ b/data/src/settings.rs @@ -2,10 +2,18 @@ use light_enum::Values; use serde::{Deserialize, Serialize}; use std::fmt::Display; -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(default)] pub struct SettingsState { - show_flatpak_dialog: bool, + pub show_flatpak_dialog: bool, +} + +impl Default for SettingsState { + fn default() -> Self { + Self { + show_flatpak_dialog: true, + } + } } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/ui/Cargo.toml b/ui/Cargo.toml index 1839000..6a352b0 100644 --- a/ui/Cargo.toml +++ b/ui/Cargo.toml @@ -10,6 +10,9 @@ repository.workspace = true keywords.workspace = true +[lints] +workspace = true + [dependencies] data.workspace = true hardware.workspace = true diff --git a/ui/build.rs b/ui/build.rs new file mode 100644 index 0000000..f9583ae --- /dev/null +++ b/ui/build.rs @@ -0,0 +1,9 @@ +use std::env; + +fn main() { + println!("cargo:rerun-if-env-changed=FAN_CONTROL_FORMAT"); + + if let Ok(var) = env::var("FAN_CONTROL_FORMAT") { + println!("cargo:rustc-cfg=FAN_CONTROL_FORMAT=\"{}\"", var); + } +} diff --git a/ui/src/dialogs.rs b/ui/src/dialogs.rs new file mode 100644 index 0000000..b75fd16 --- /dev/null +++ b/ui/src/dialogs.rs @@ -0,0 +1,28 @@ +use cosmic::{ + widget::{button, dialog, text}, + Element, +}; + +use crate::message::AppMsg; + +pub enum Dialog { + Flatpak, +} + +impl Dialog { + pub fn view(&self) -> Element { + match self { + Dialog::Flatpak => view_flatpak_dialog(), + } + } +} + +fn view_flatpak_dialog() -> Element<'static, AppMsg> { + dialog("Udev rules") + .body("body") + .control(text("control")) + .primary_action(button::text("Got it")) + .secondary_action(button::text("Got it2")) + .tertiary_action(button::text("Got it3")) + .into() +} diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 80f0f88..4101668 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -7,6 +7,7 @@ use data::{ utils::RemoveElem, AppState, }; +use dialogs::Dialog; use graph::GraphWindow; use hardware::{HardwareBridge, Mode}; use item::items_view; @@ -40,6 +41,7 @@ extern crate log; pub mod localize; mod add_node; +mod dialogs; mod graph; mod headers; mod icon; @@ -83,6 +85,7 @@ struct Ui { is_updating: bool, graph_window: Option, toasts: Toasts, + dialog: Option, } impl cosmic::Application for Ui { @@ -109,6 +112,14 @@ impl cosmic::Application for Ui { .current_config_text() .to_owned(); + let dialog = if cfg!(FAN_CONTROL_FORMAT = "flatpak") + && app_state.dir_manager.state().show_flatpak_dialog + { + Some(Dialog::Flatpak) + } else { + None + }; + let ui_state = Ui { nodes_c: NodesC::new(app_state.app_graph.nodes.values()), app_state, @@ -119,6 +130,7 @@ impl cosmic::Application for Ui { is_updating: false, graph_window: None, toasts: Toasts::new(AppMsg::RemoveToast), + dialog, }; let commands = Task::batch([cosmic::app::command::message(cosmic::app::message::app( @@ -602,6 +614,10 @@ impl cosmic::Application for Ui { panic!("no view for window {id:?}"); } + + fn dialog(&self) -> Option> { + self.dialog.as_ref().map(|dialog| dialog.view()) + } } // todo: re enable when is "work" on flatpak diff --git a/utils/Cargo.toml b/utils/Cargo.toml index 9ca1b1b..37d9a3c 100644 --- a/utils/Cargo.toml +++ b/utils/Cargo.toml @@ -10,6 +10,8 @@ homepage.workspace = true repository.workspace = true keywords.workspace = true +[lints] +workspace = true [dependencies] cached = "0.53" @@ -19,5 +21,3 @@ cargo-packager-resource-resolver = { version = "0.1", features = [ ] } log.workspace = true -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(FAN_CONTROL_FORMAT, values("flatpak"))'] } \ No newline at end of file From 817952229e9e98fa36f48fabdb0ec27caf0f61db Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:28:31 +0100 Subject: [PATCH 04/13] ff --- ui/src/dialogs.rs | 58 ++++++++++++++++++++++++++++++++++++++++------- ui/src/lib.rs | 3 +++ ui/src/message.rs | 3 ++- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/ui/src/dialogs.rs b/ui/src/dialogs.rs index b75fd16..13c056e 100644 --- a/ui/src/dialogs.rs +++ b/ui/src/dialogs.rs @@ -1,28 +1,70 @@ use cosmic::{ + iced::clipboard, widget::{button, dialog, text}, - Element, + Element, Task, }; +use hardware::HardwareBridge; -use crate::message::AppMsg; +use crate::{message::AppMsg, Ui}; +#[derive(Clone, Debug)] pub enum Dialog { Flatpak, } +#[derive(Clone, Debug)] +pub enum DialogMsg { + Flatpak(FlatpakDialogMsg), +} + impl Dialog { pub fn view(&self) -> Element { match self { Dialog::Flatpak => view_flatpak_dialog(), } + .map(AppMsg::Dialog) } + + pub fn update(app: &mut Ui, message: DialogMsg) -> Task { + match message { + DialogMsg::Flatpak(flatpak_dialog_msg) => match flatpak_dialog_msg { + FlatpakDialogMsg::Close => { + app.dialog = None; + } + FlatpakDialogMsg::CopyToClipboard(data) => return clipboard::write(data), + FlatpakDialogMsg::CloseAndDontShowAgain => { + app.dialog = None; + app.app_state.dir_manager.update_state(|state| { + state.show_flatpak_dialog = false; + }); + } + }, + } + + Task::none() + } +} + +#[derive(Clone, Debug)] +pub enum FlatpakDialogMsg { + Close, + CopyToClipboard(String), + CloseAndDontShowAgain, } -fn view_flatpak_dialog() -> Element<'static, AppMsg> { - dialog("Udev rules") +fn view_flatpak_dialog() -> Element<'static, DialogMsg> { + let dialog: Element<_> = dialog("Udev rules") .body("body") .control(text("control")) - .primary_action(button::text("Got it")) - .secondary_action(button::text("Got it2")) - .tertiary_action(button::text("Got it3")) - .into() + .primary_action(button::text("Remind me latter").on_press(FlatpakDialogMsg::Close)) + .secondary_action( + button::text("Copy command to clipboard") + .on_press(FlatpakDialogMsg::CopyToClipboard("todo".into())), + ) + .tertiary_action( + button::text("Already done it").on_press(FlatpakDialogMsg::CloseAndDontShowAgain), + ) + .into(); + + dialog.map(DialogMsg::Flatpak) } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 4101668..e830769 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -537,6 +537,9 @@ impl cosmic::Application for Ui { AppMsg::RemoveToast(pos) => { self.toasts.remove(pos); } + AppMsg::Dialog(dialog_msg) => { + return Dialog::update(self, dialog_msg).map(|m| cosmic::app::Message::App(m)); + } } Task::none() diff --git a/ui/src/message.rs b/ui/src/message.rs index 9b5d53c..794c8e2 100644 --- a/ui/src/message.rs +++ b/ui/src/message.rs @@ -6,7 +6,7 @@ use data::{ settings::AppTheme, }; -use crate::graph::GraphWindowMsg; +use crate::{dialogs::DialogMsg, graph::GraphWindowMsg}; #[derive(Debug, Clone)] pub enum AppMsg { @@ -26,6 +26,7 @@ pub enum AppMsg { GraphWindow(GraphWindowMsg), RemoveToast(ToastId), + Dialog(DialogMsg), } #[derive(Debug, Clone)] From b5549dbe66d53a0fc493fe101ae5180a6309f07e Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 01:20:43 +0100 Subject: [PATCH 05/13] markdown --- Cargo.lock | 51 +++++++++++++++++++++++++++++++++-------------- Cargo.toml | 4 ++-- ui/Cargo.toml | 1 + ui/src/dialogs.rs | 23 ++++++++++++++++++--- 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9372773..2ff8b82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1214,7 +1214,6 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1233,7 +1232,6 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "quote", "syn 1.0.109", @@ -1265,7 +1263,6 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "almost", "cosmic-config", @@ -2236,6 +2233,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -2570,7 +2576,6 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_accessibility", @@ -2588,7 +2593,6 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "accesskit", "accesskit_winit", @@ -2597,7 +2601,6 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bitflags 2.6.0", "bytes", @@ -2620,7 +2623,6 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "futures", "iced_core", @@ -2646,7 +2648,6 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -2668,7 +2669,6 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2680,7 +2680,6 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bytes", "dnd", @@ -2694,7 +2693,6 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "bytemuck", "cosmic-text", @@ -2710,7 +2708,6 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "as-raw-xcb-connection", "bitflags 2.6.0", @@ -2741,7 +2738,6 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_renderer", @@ -2749,16 +2745,17 @@ dependencies = [ "num-traits", "once_cell", "ouroboros", + "pulldown-cmark", "rustc-hash 2.0.0", "thiserror", "unicode-segmentation", + "url", "window_clipboard", ] [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "dnd", "iced_futures", @@ -3206,7 +3203,6 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#3c5a2d9340ca80836ce947cad8cc4c0fb1157355" dependencies = [ "apply", "ashpd 0.9.2", @@ -4396,6 +4392,25 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d" +[[package]] +name = "pulldown-cmark" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625" +dependencies = [ + "bitflags 2.6.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" + [[package]] name = "qoi" version = "0.4.1" @@ -5569,6 +5584,12 @@ dependencies = [ "tinystr", ] +[[package]] +name = "unicase" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" + [[package]] name = "unicode-bidi" version = "0.3.17" diff --git a/Cargo.toml b/Cargo.toml index 3ac4c31..4c48a22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,8 +69,8 @@ derive_more = { version = "1", default-features = false, features = [ ] } # strum = { version = "0.25", features = ["derive"] } -# [patch."https://github.com/pop-os/libcosmic"] -# libcosmic = { path = "../libcosmic" } +[patch."https://github.com/pop-os/libcosmic"] +libcosmic = { path = "../libcosmic" } # libcosmic = { git = "https://github.com/wiiznokes/libcosmic", rev = "2dff73b8b2871afca6c65c861954c196818f960f" } diff --git a/ui/Cargo.toml b/ui/Cargo.toml index 6a352b0..64b7247 100644 --- a/ui/Cargo.toml +++ b/ui/Cargo.toml @@ -34,6 +34,7 @@ features = [ "tokio", "multi-window", "single-instance", + "markdown", # todo: re enable when it works on Flatpak # "dbus-config", #"a11y", diff --git a/ui/src/dialogs.rs b/ui/src/dialogs.rs index 13c056e..d679d81 100644 --- a/ui/src/dialogs.rs +++ b/ui/src/dialogs.rs @@ -1,6 +1,10 @@ use cosmic::{ - iced::clipboard, - widget::{button, dialog, text}, + iced::{clipboard, theme::Palette}, + widget::{ + button, dialog, + markdown::{self, Url}, + text, + }, Element, Task, }; use hardware::HardwareBridge; @@ -38,6 +42,9 @@ impl Dialog { state.show_flatpak_dialog = false; }); } + FlatpakDialogMsg::OpenUrl(url) => { + // todo + }, }, } @@ -50,12 +57,22 @@ pub enum FlatpakDialogMsg { Close, CopyToClipboard(String), CloseAndDontShowAgain, + OpenUrl(Url), } fn view_flatpak_dialog() -> Element<'static, DialogMsg> { + let items = markdown::parse(include_str!("../../res/linux/udev_rules.md")).collect::>(); + let dialog: Element<_> = dialog("Udev rules") .body("body") - .control(text("control")) + .control( + markdown::view( + items.iter(), + markdown::Settings::default(), + markdown::Style::from_palette(Palette::CATPPUCCIN_FRAPPE), + ) + .map(|url| FlatpakDialogMsg::OpenUrl(url)), + ) .primary_action(button::text("Remind me latter").on_press(FlatpakDialogMsg::Close)) .secondary_action( button::text("Copy command to clipboard") From 80dc5ad07d9285c9b555349c5dff0040e8abb6fa Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:46:52 +0100 Subject: [PATCH 06/13] fixes --- Cargo.lock | 70 +++++++++++++++++++++++++++++++++++------ Cargo.toml | 4 +-- data/src/dir_manager.rs | 6 +++- i18n/en/ui.ftl | 5 ++- ui/Cargo.toml | 1 + ui/src/dialogs.rs | 6 ++-- 6 files changed, 77 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ff8b82..fe5b7b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,7 +424,7 @@ dependencies = [ "futures-io", "futures-lite 2.4.0", "parking", - "polling 3.7.3", + "polling 3.7.4", "rustix 0.38.39", "slab", "tracing", @@ -828,7 +828,7 @@ checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" dependencies = [ "bitflags 2.6.0", "log", - "polling 3.7.3", + "polling 3.7.4", "rustix 0.38.39", "slab", "thiserror", @@ -1214,6 +1214,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1232,6 +1233,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "quote", "syn 1.0.109", @@ -1240,7 +1242,7 @@ dependencies = [ [[package]] name = "cosmic-text" version = "0.12.1" -source = "git+https://github.com/pop-os/cosmic-text.git#4fe90bb6126c22f589b46768d7754d65ae300c5e" +source = "git+https://github.com/pop-os/cosmic-text.git#1f4065c1c3399efad58841082212f7c039b58480" dependencies = [ "bitflags 2.6.0", "fontdb 0.16.2", @@ -1263,6 +1265,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "almost", "cosmic-config", @@ -2576,6 +2579,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_accessibility", @@ -2593,6 +2597,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "accesskit", "accesskit_winit", @@ -2601,6 +2606,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bitflags 2.6.0", "bytes", @@ -2623,6 +2629,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "futures", "iced_core", @@ -2648,6 +2655,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -2669,6 +2677,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2680,6 +2689,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bytes", "dnd", @@ -2693,6 +2703,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bytemuck", "cosmic-text", @@ -2708,6 +2719,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "as-raw-xcb-connection", "bitflags 2.6.0", @@ -2738,6 +2750,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_renderer", @@ -2756,6 +2769,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_futures", @@ -3019,6 +3033,25 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -3196,13 +3229,14 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.161" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libcosmic" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "apply", "ashpd 0.9.2", @@ -3991,6 +4025,17 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "open" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a877bf6abd716642a53ef1b89fb498923a4afca5c754f9050b4d081c05c4b3" +dependencies = [ + "is-wsl", + "libc", + "pathdiff", +] + [[package]] name = "option-ext" version = "0.2.0" @@ -4145,6 +4190,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pathdiff" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c5ce1153ab5b689d0c074c4e7fc613e942dfb7dd9eea5ab202d2ad91fe361" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -4279,9 +4330,9 @@ dependencies = [ [[package]] name = "polling" -version = "3.7.3" +version = "3.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" +checksum = "a604568c3202727d1507653cb121dbd627a58684eb09a820fd746bee38b4442f" dependencies = [ "cfg-if", "concurrent-queue", @@ -5382,9 +5433,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.41.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", @@ -5560,6 +5611,7 @@ dependencies = [ "i18n-embed-fl", "libcosmic", "log", + "open", "rust-embed", "tokio", "utils", diff --git a/Cargo.toml b/Cargo.toml index 4c48a22..3ac4c31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,8 +69,8 @@ derive_more = { version = "1", default-features = false, features = [ ] } # strum = { version = "0.25", features = ["derive"] } -[patch."https://github.com/pop-os/libcosmic"] -libcosmic = { path = "../libcosmic" } +# [patch."https://github.com/pop-os/libcosmic"] +# libcosmic = { path = "../libcosmic" } # libcosmic = { git = "https://github.com/wiiznokes/libcosmic", rev = "2dff73b8b2871afca6c65c861954c196818f960f" } diff --git a/data/src/dir_manager.rs b/data/src/dir_manager.rs index e806edc..91e72e6 100644 --- a/data/src/dir_manager.rs +++ b/data/src/dir_manager.rs @@ -113,7 +113,11 @@ impl DirManager { } }; - let state_dir_path = project_dirs.data_local_dir().to_path_buf(); + let state_dir_path = if cfg!(target_os = "linux") { + project_dirs.state_dir().unwrap().to_path_buf() + } else { + project_dirs.data_local_dir().to_path_buf() + }; if !state_dir_path.exists() { if let Err(e) = fs::create_dir_all(&state_dir_path) { diff --git a/i18n/en/ui.ftl b/i18n/en/ui.ftl index 956aaeb..e543b24 100644 --- a/i18n/en/ui.ftl +++ b/i18n/en/ui.ftl @@ -48,4 +48,7 @@ create_config = Create configuration # Error already_used_error = This name is already being use -invalid_value_error = this value is invalid \ No newline at end of file +invalid_value_error = this value is invalid + +# Dialogs +udev_rules_dialog_title = Install Udev Rules \ No newline at end of file diff --git a/ui/Cargo.toml b/ui/Cargo.toml index 64b7247..b2c31b1 100644 --- a/ui/Cargo.toml +++ b/ui/Cargo.toml @@ -23,6 +23,7 @@ rust-embed.workspace = true utils.workspace = true derive_more.workspace = true tokio = { version = "1", features = ["time"] } +open = "5" [dependencies.libcosmic] git = "https://github.com/pop-os/libcosmic" branch = "master" diff --git a/ui/src/dialogs.rs b/ui/src/dialogs.rs index d679d81..18cc05e 100644 --- a/ui/src/dialogs.rs +++ b/ui/src/dialogs.rs @@ -43,8 +43,10 @@ impl Dialog { }); } FlatpakDialogMsg::OpenUrl(url) => { - // todo - }, + if let Err(e) = open::that(url.as_str()) { + error!("{e}"); + } + } }, } From 12f6999d601e0876ad4a5ba9862b876b535a9271 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:11:19 +0100 Subject: [PATCH 07/13] impl dialog --- Cargo.lock | 15 --------------- Cargo.toml | 4 ++-- i18n/en/ui.ftl | 4 +++- ui/src/dialogs.rs | 23 +++++++++++++++-------- ui/src/lib.rs | 2 +- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe5b7b6..1b8af80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1214,7 +1214,6 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1233,7 +1232,6 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "quote", "syn 1.0.109", @@ -1265,7 +1263,6 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "almost", "cosmic-config", @@ -2579,7 +2576,6 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_accessibility", @@ -2597,7 +2593,6 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "accesskit", "accesskit_winit", @@ -2606,7 +2601,6 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bitflags 2.6.0", "bytes", @@ -2629,7 +2623,6 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "futures", "iced_core", @@ -2655,7 +2648,6 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -2677,7 +2669,6 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2689,7 +2680,6 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bytes", "dnd", @@ -2703,7 +2693,6 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bytemuck", "cosmic-text", @@ -2719,7 +2708,6 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "as-raw-xcb-connection", "bitflags 2.6.0", @@ -2750,7 +2738,6 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_renderer", @@ -2769,7 +2756,6 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_futures", @@ -3236,7 +3222,6 @@ checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "apply", "ashpd 0.9.2", diff --git a/Cargo.toml b/Cargo.toml index 3ac4c31..4c48a22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,8 +69,8 @@ derive_more = { version = "1", default-features = false, features = [ ] } # strum = { version = "0.25", features = ["derive"] } -# [patch."https://github.com/pop-os/libcosmic"] -# libcosmic = { path = "../libcosmic" } +[patch."https://github.com/pop-os/libcosmic"] +libcosmic = { path = "../libcosmic" } # libcosmic = { git = "https://github.com/wiiznokes/libcosmic", rev = "2dff73b8b2871afca6c65c861954c196818f960f" } diff --git a/i18n/en/ui.ftl b/i18n/en/ui.ftl index e543b24..2cce7e3 100644 --- a/i18n/en/ui.ftl +++ b/i18n/en/ui.ftl @@ -51,4 +51,6 @@ already_used_error = This name is already being use invalid_value_error = this value is invalid # Dialogs -udev_rules_dialog_title = Install Udev Rules \ No newline at end of file +udev_rules_dialog_ok = Already done it +udev_rules_dialog_remind_later = Remind me Later +udev_rules_dialog_copy_to_clipboard = Copy Commands to Clipboard \ No newline at end of file diff --git a/ui/src/dialogs.rs b/ui/src/dialogs.rs index 18cc05e..830280d 100644 --- a/ui/src/dialogs.rs +++ b/ui/src/dialogs.rs @@ -3,7 +3,6 @@ use cosmic::{ widget::{ button, dialog, markdown::{self, Url}, - text, }, Element, Task, }; @@ -65,23 +64,31 @@ pub enum FlatpakDialogMsg { fn view_flatpak_dialog() -> Element<'static, DialogMsg> { let items = markdown::parse(include_str!("../../res/linux/udev_rules.md")).collect::>(); - let dialog: Element<_> = dialog("Udev rules") - .body("body") + let commands = r#" + wget https://raw.githubusercontent.com/wiiznokes/fan-control/master/res/linux/60-fan-control.rules + sudo mv 60-fan-control.rules /etc/udev/rules.d/ + sudo udevadm control --reload-rules && sudo udevadm trigger + "#; + + let dialog: Element<_> = dialog() .control( markdown::view( items.iter(), markdown::Settings::default(), markdown::Style::from_palette(Palette::CATPPUCCIN_FRAPPE), ) - .map(|url| FlatpakDialogMsg::OpenUrl(url)), + .map(FlatpakDialogMsg::OpenUrl), + ) + .primary_action( + button::text(fl!("udev_rules_dialog_ok")) + .on_press(FlatpakDialogMsg::CloseAndDontShowAgain), ) - .primary_action(button::text("Remind me latter").on_press(FlatpakDialogMsg::Close)) .secondary_action( - button::text("Copy command to clipboard") - .on_press(FlatpakDialogMsg::CopyToClipboard("todo".into())), + button::text(fl!("udev_rules_dialog_copy_to_clipboard")) + .on_press(FlatpakDialogMsg::CopyToClipboard(commands.into())), ) .tertiary_action( - button::text("Already done it").on_press(FlatpakDialogMsg::CloseAndDontShowAgain), + button::text(fl!("udev_rules_dialog_remind_later")).on_press(FlatpakDialogMsg::Close), ) .into(); diff --git a/ui/src/lib.rs b/ui/src/lib.rs index e830769..0c08cfb 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -538,7 +538,7 @@ impl cosmic::Application for Ui { self.toasts.remove(pos); } AppMsg::Dialog(dialog_msg) => { - return Dialog::update(self, dialog_msg).map(|m| cosmic::app::Message::App(m)); + return Dialog::update(self, dialog_msg).map(cosmic::app::Message::App); } } From 8a5214d8d6827cd6120430be0c9e34b578da7847 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 19:49:41 +0100 Subject: [PATCH 08/13] update deps --- Cargo.lock | 109 ++++++++++++++++++++++++++++++---------------- Cargo.toml | 6 +-- ui/src/dialogs.rs | 2 +- utils/Cargo.toml | 2 +- 4 files changed, 77 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b8af80..c8ba206 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,7 +32,7 @@ dependencies = [ "accesskit_consumer", "atspi-common", "serde", - "thiserror", + "thiserror 1.0.68", "zvariant 3.15.2", ] @@ -171,7 +171,7 @@ dependencies = [ "ndk-context", "ndk-sys 0.6.0+11769913", "num_enum", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -789,16 +789,16 @@ checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cached" -version = "0.53.1" +version = "0.54.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4d73155ae6b28cf5de4cfc29aeb02b8a1c6dab883cb015d15cd514e42766846" +checksum = "9718806c4a2fe9e8a56fd736f97b340dd10ed1be8ed733ed50449f351dc33cae" dependencies = [ "ahash", "cached_proc_macro", "cached_proc_macro_types", "hashbrown 0.14.5", "once_cell", - "thiserror", + "thiserror 1.0.68", "web-time", ] @@ -831,7 +831,7 @@ dependencies = [ "polling 3.7.4", "rustix 0.38.39", "slab", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -855,7 +855,7 @@ dependencies = [ "cargo-packager-utils", "heck 0.5.0", "log", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -1010,7 +1010,7 @@ name = "clipboard_x11" version = "0.4.2" source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-0.13#a83bf83784276aaa882ef13555295a2ad9edd265" dependencies = [ - "thiserror", + "thiserror 1.0.68", "x11rb", ] @@ -1214,6 +1214,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1232,6 +1233,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "quote", "syn 1.0.109", @@ -1263,6 +1265,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "almost", "cosmic-config", @@ -1273,7 +1276,7 @@ dependencies = [ "ron", "serde", "serde_json", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -1485,7 +1488,7 @@ dependencies = [ "serde", "serde_json", "serial_test", - "thiserror", + "thiserror 2.0.0", "toml 0.8.19", "utils", ] @@ -1853,7 +1856,7 @@ dependencies = [ "env_logger", "hardware", "log", - "thiserror", + "thiserror 2.0.0", "ui", "winres", ] @@ -1972,7 +1975,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a530c4694a6a8d528794ee9bbd8ba0122e779629ac908d15ad5a7ae7763a33d" dependencies = [ - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -2082,7 +2085,7 @@ dependencies = [ "dirs", "once_cell", "rust-ini", - "thiserror", + "thiserror 1.0.68", "xdg", ] @@ -2340,7 +2343,7 @@ checksum = "fdd4240fc91d3433d5e5b0fc5b67672d771850dc19bbee03c1381e19322803d7" dependencies = [ "log", "presser", - "thiserror", + "thiserror 1.0.68", "winapi", "windows 0.52.0", ] @@ -2403,7 +2406,7 @@ dependencies = [ "rand", "serde", "serde_json", - "thiserror", + "thiserror 2.0.0", "utils", ] @@ -2433,7 +2436,7 @@ dependencies = [ "com", "libc", "libloading", - "thiserror", + "thiserror 1.0.68", "widestring", "winapi", ] @@ -2490,7 +2493,7 @@ dependencies = [ "log", "serde", "serde_derive", - "thiserror", + "thiserror 1.0.68", "unic-langid", ] @@ -2511,7 +2514,7 @@ dependencies = [ "log", "parking_lot 0.12.3", "rust-embed", - "thiserror", + "thiserror 1.0.68", "unic-langid", "walkdir", ] @@ -2576,6 +2579,7 @@ dependencies = [ [[package]] name = "iced" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_accessibility", @@ -2586,13 +2590,14 @@ dependencies = [ "iced_winit", "image", "mime", - "thiserror", + "thiserror 1.0.68", "window_clipboard", ] [[package]] name = "iced_accessibility" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "accesskit", "accesskit_winit", @@ -2601,6 +2606,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bitflags 2.6.0", "bytes", @@ -2615,7 +2621,7 @@ dependencies = [ "rustc-hash 2.0.0", "serde", "smol_str", - "thiserror", + "thiserror 1.0.68", "web-time", "window_clipboard", ] @@ -2623,6 +2629,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "futures", "iced_core", @@ -2648,6 +2655,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -2662,37 +2670,40 @@ dependencies = [ "once_cell", "raw-window-handle", "rustc-hash 2.0.0", - "thiserror", + "thiserror 1.0.68", "unicode-segmentation", ] [[package]] name = "iced_renderer" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "iced_graphics", "iced_tiny_skia", "iced_wgpu", "log", - "thiserror", + "thiserror 1.0.68", ] [[package]] name = "iced_runtime" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bytes", "dnd", "iced_core", "iced_futures", "raw-window-handle", - "thiserror", + "thiserror 1.0.68", "window_clipboard", ] [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "bytemuck", "cosmic-text", @@ -2708,6 +2719,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "as-raw-xcb-connection", "bitflags 2.6.0", @@ -2725,7 +2737,7 @@ dependencies = [ "rustc-hash 2.0.0", "rustix 0.38.39", "smithay-client-toolkit", - "thiserror", + "thiserror 1.0.68", "tiny-xlib", "wayland-backend", "wayland-client", @@ -2738,6 +2750,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_renderer", @@ -2747,7 +2760,7 @@ dependencies = [ "ouroboros", "pulldown-cmark", "rustc-hash 2.0.0", - "thiserror", + "thiserror 1.0.68", "unicode-segmentation", "url", "window_clipboard", @@ -2756,6 +2769,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "dnd", "iced_futures", @@ -2763,7 +2777,7 @@ dependencies = [ "iced_runtime", "log", "rustc-hash 2.0.0", - "thiserror", + "thiserror 1.0.68", "tracing", "wasm-bindgen-futures", "web-sys", @@ -3079,7 +3093,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.68", "walkdir", "windows-sys 0.45.0", ] @@ -3222,6 +3236,7 @@ checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libcosmic" version = "0.1.0" +source = "git+https://github.com/pop-os/libcosmic?branch=master#568ff097d67b93eef646d2f86937935438dba4dd" dependencies = [ "apply", "ashpd 0.9.2", @@ -3248,7 +3263,7 @@ dependencies = [ "serde", "slotmap", "taffy", - "thiserror", + "thiserror 1.0.68", "tokio", "tracing", "unicode-segmentation", @@ -3333,7 +3348,7 @@ dependencies = [ "libc", "num_enum", "sensors-sys", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -3561,7 +3576,7 @@ dependencies = [ "rustc-hash 1.1.0", "spirv", "termcolor", - "thiserror", + "thiserror 1.0.68", "unicode-xid", ] @@ -3577,7 +3592,7 @@ dependencies = [ "ndk-sys 0.6.0+11769913", "num_enum", "raw-window-handle", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -4587,7 +4602,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -5092,7 +5107,7 @@ dependencies = [ "memmap2 0.9.5", "pkg-config", "rustix 0.38.39", - "thiserror", + "thiserror 1.0.68", "wayland-backend", "wayland-client", "wayland-csd-frame", @@ -5318,7 +5333,16 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.68", +] + +[[package]] +name = "thiserror" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15291287e9bff1bc6f9ff3409ed9af665bec7a5fc8ac079ea96be07bca0e2668" +dependencies = [ + "thiserror-impl 2.0.0", ] [[package]] @@ -5332,6 +5356,17 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "thiserror-impl" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22efd00f33f93fa62848a7cab956c3d38c8d43095efda1decfc2b3a5dc0b8972" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "tiff" version = "0.9.1" @@ -6069,7 +6104,7 @@ dependencies = [ "raw-window-handle", "rustc-hash 1.1.0", "smallvec", - "thiserror", + "thiserror 1.0.68", "wgpu-hal", "wgpu-types", ] @@ -6112,7 +6147,7 @@ dependencies = [ "renderdoc-sys", "rustc-hash 1.1.0", "smallvec", - "thiserror", + "thiserror 1.0.68", "wasm-bindgen", "web-sys", "wgpu-types", @@ -6179,7 +6214,7 @@ dependencies = [ "dnd", "mime", "raw-window-handle", - "thiserror", + "thiserror 1.0.68", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4c48a22..8b873a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,15 +62,15 @@ i18n-embed = { version = "0.15", features = [ ] } rust-embed = "8" i18n-embed-fl = "0.9" -thiserror = "1" +thiserror = "2" derive_more = { version = "1", default-features = false, features = [ "unwrap", "display", ] } # strum = { version = "0.25", features = ["derive"] } -[patch."https://github.com/pop-os/libcosmic"] -libcosmic = { path = "../libcosmic" } +# [patch."https://github.com/pop-os/libcosmic"] +# libcosmic = { path = "../libcosmic" } # libcosmic = { git = "https://github.com/wiiznokes/libcosmic", rev = "2dff73b8b2871afca6c65c861954c196818f960f" } diff --git a/ui/src/dialogs.rs b/ui/src/dialogs.rs index 830280d..5c87ab6 100644 --- a/ui/src/dialogs.rs +++ b/ui/src/dialogs.rs @@ -70,7 +70,7 @@ fn view_flatpak_dialog() -> Element<'static, DialogMsg> { sudo udevadm control --reload-rules && sudo udevadm trigger "#; - let dialog: Element<_> = dialog() + let dialog: Element<_> = dialog("") .control( markdown::view( items.iter(), diff --git a/utils/Cargo.toml b/utils/Cargo.toml index 37d9a3c..7a186e8 100644 --- a/utils/Cargo.toml +++ b/utils/Cargo.toml @@ -14,7 +14,7 @@ keywords.workspace = true workspace = true [dependencies] -cached = "0.53" +cached = "0.54" constcat = "0.5" cargo-packager-resource-resolver = { version = "0.1", features = [ "auto-detect-format", From 80d09b9a59e118c41f388250fc7726e7d9fb49f0 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:08:13 +0100 Subject: [PATCH 09/13] fix tooltips --- i18n/en/ui.ftl | 2 +- ui/src/add_node.rs | 27 +++++++++++------ ui/src/headers.rs | 75 ++++++++++++++++++++++++++++------------------ 3 files changed, 65 insertions(+), 39 deletions(-) diff --git a/i18n/en/ui.ftl b/i18n/en/ui.ftl index 2cce7e3..dde1fed 100644 --- a/i18n/en/ui.ftl +++ b/i18n/en/ui.ftl @@ -51,6 +51,6 @@ already_used_error = This name is already being use invalid_value_error = this value is invalid # Dialogs -udev_rules_dialog_ok = Already done it +udev_rules_dialog_ok = I understand udev_rules_dialog_remind_later = Remind me Later udev_rules_dialog_copy_to_clipboard = Copy Commands to Clipboard \ No newline at end of file diff --git a/ui/src/add_node.rs b/ui/src/add_node.rs index 0586693..72e4064 100644 --- a/ui/src/add_node.rs +++ b/ui/src/add_node.rs @@ -1,4 +1,8 @@ -use cosmic::{iced_widget::Column, widget::IconButton, Element}; +use cosmic::{ + iced_widget::{text, Column}, + widget::tooltip, + Element, +}; use data::node::NodeTypeLight; use crate::{icon::icon_button_from_handle, icon_button, node_icon_handle, AppMsg, ToogleMsg}; @@ -17,15 +21,20 @@ pub fn add_node_button_view(expanded: bool) -> Element<'static, AppMsg> { .push(icon_button!("close/40").on_press(AppMsg::Toggle(ToogleMsg::CreateButton(false)))) .into(), - false => icon_button!("add/40") - .on_press(AppMsg::Toggle(ToogleMsg::CreateButton(true))) - .tooltip(fl!("add_item")) - .into(), + false => tooltip( + icon_button!("add/40").on_press(AppMsg::Toggle(ToogleMsg::CreateButton(true))), + text(fl!("add_item")), + tooltip::Position::Top, + ) + .into(), } } -fn add_item<'a>(kind: NodeTypeLight, desc: String) -> IconButton<'a, AppMsg> { - icon_button_from_handle(node_icon_handle!(kind)) - .on_press(AppMsg::NewNode(kind.clone())) - .tooltip(desc) +fn add_item<'a>(kind: NodeTypeLight, desc: String) -> Element<'a, AppMsg> { + tooltip( + icon_button_from_handle(node_icon_handle!(kind)).on_press(AppMsg::NewNode(kind.clone())), + text(desc), + tooltip::Position::Left, + ) + .into() } diff --git a/ui/src/headers.rs b/ui/src/headers.rs index 068b090..1beac47 100644 --- a/ui/src/headers.rs +++ b/ui/src/headers.rs @@ -1,8 +1,8 @@ use cosmic::{ iced_core::{Alignment, Length}, - iced_widget::{Button, Column}, + iced_widget::{text, Button, Column}, theme, - widget::{Container, Row, Text, TextInput}, + widget::{tooltip, Container, Row, Text, TextInput}, Element, }; use data::dir_manager::DirManager; @@ -33,22 +33,27 @@ pub fn header_center<'a>( expanded: bool, ) -> Vec> { let settings = dir_manager.settings(); + let mut elems = Vec::new(); + // save button if settings.current_config.is_some() { - let mut save_button = icon_button!("save/40") - .tooltip(fl!("save_config")) - .height(ICON_LENGHT) - .width(ICON_LENGHT); - - if dir_manager - .config_names - .is_valid_name(&settings.current_config, current_config) - { - save_button = save_button.on_press(ConfigMsg::Save.into()); - } - - elems.push(save_button.into()); + elems.push( + tooltip( + icon_button!("save/40") + .height(ICON_LENGHT) + .width(ICON_LENGHT) + .on_press_maybe( + dir_manager + .config_names + .is_valid_name(&settings.current_config, current_config) + .then_some(ConfigMsg::Save.into()), + ), + text(fl!("save_config")), + tooltip::Position::Bottom, + ) + .into(), + ); } let mut name = TextInput::new(fl!("config_name"), current_config) @@ -101,16 +106,23 @@ pub fn header_center<'a>( elems.push(choose_config); - let mut create_button = icon_button!("add/40") - .height(ICON_LENGHT) - .width(ICON_LENGHT) - .tooltip(fl!("create_config")); - - if dir_manager.config_names.is_valid_create(current_config) { - create_button = create_button.on_press(ConfigMsg::Create(current_config.to_owned()).into()); - } - - elems.push(create_button.into()); + // create button + elems.push( + tooltip( + icon_button!("add/40") + .height(ICON_LENGHT) + .width(ICON_LENGHT) + .on_press_maybe( + dir_manager + .config_names + .is_valid_create(current_config) + .then_some(ConfigMsg::Create(current_config.to_owned()).into()), + ), + text(fl!("create_config")), + tooltip::Position::Bottom, + ) + .into(), + ); elems } @@ -125,10 +137,15 @@ fn config_choice_line<'a>(optional_name: Option) -> Element<'a, AppMsg> if optional_name.is_some() { elements.push( - icon_button!("delete_forever/24") - .on_press(ConfigMsg::Delete(name).into()) - .tooltip(fl!("delete_config")) - .into(), + tooltip( + icon_button!("delete_forever/40") + .height(ICON_LENGHT) + .width(ICON_LENGHT) + .on_press(ConfigMsg::Delete(name).into()), + text(fl!("delete_config")), + tooltip::Position::Right, + ) + .into(), ); } Row::with_children(elements) From 6cc1e1b613ccb22d54be8b3d6c7b257f2193b7c3 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:29:15 +0100 Subject: [PATCH 10/13] impl warning when not saved + fix tooltips --- data/src/config/control.rs | 11 +++++- data/src/config/custom_temp.rs | 2 +- data/src/config/fan.rs | 8 +++- data/src/config/flat.rs | 2 +- data/src/config/graph.rs | 67 +++++++++++++++++++--------------- data/src/config/linear.rs | 2 +- data/src/config/mod.rs | 2 +- data/src/config/serde_test.rs | 4 +- data/src/config/target.rs | 13 ++++++- data/src/config/temp.rs | 8 +++- i18n/en/ui.ftl | 3 ++ res/icons/warning/20px.svg | 1 + res/icons/warning/24px.svg | 1 + res/icons/warning/40px.svg | 1 + res/icons/warning/48px.svg | 1 + ui/src/headers.rs | 44 +++++++++++++++++----- ui/src/lib.rs | 2 +- 17 files changed, 123 insertions(+), 49 deletions(-) create mode 100644 res/icons/warning/20px.svg create mode 100644 res/icons/warning/24px.svg create mode 100644 res/icons/warning/40px.svg create mode 100644 res/icons/warning/48px.svg diff --git a/data/src/config/control.rs b/data/src/config/control.rs index 2bd5816..6e96dd4 100644 --- a/data/src/config/control.rs +++ b/data/src/config/control.rs @@ -9,7 +9,7 @@ use crate::{ update::UpdateError, }; -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Eq)] pub struct Control { // unique pub name: String, @@ -27,6 +27,15 @@ pub struct Control { pub mode_set: Option, } +impl PartialEq for Control { + fn eq(&self, other: &Self) -> bool { + self.name == other.name + && self.hardware_id == other.hardware_id + && self.input == other.input + && self.active == other.active + } +} + impl Control { pub fn new( name: String, diff --git a/data/src/config/custom_temp.rs b/data/src/config/custom_temp.rs index 9c4ee29..46c9da5 100644 --- a/data/src/config/custom_temp.rs +++ b/data/src/config/custom_temp.rs @@ -9,7 +9,7 @@ use crate::{ update::UpdateError, }; -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq)] pub struct CustomTemp { pub name: String, pub kind: CustomTempKind, diff --git a/data/src/config/fan.rs b/data/src/config/fan.rs index f57cec7..f15f689 100644 --- a/data/src/config/fan.rs +++ b/data/src/config/fan.rs @@ -8,7 +8,7 @@ use crate::{ use hardware::{HSensor, Hardware, HardwareBridge, Value}; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Eq)] pub struct Fan { // unique pub name: String, @@ -21,6 +21,12 @@ pub struct Fan { pub fan_h: Option>, } +impl PartialEq for Fan { + fn eq(&self, other: &Self) -> bool { + self.name == other.name && self.hardware_id == other.hardware_id + } +} + impl Fan { pub fn get_value(&self, bridge: &mut H) -> Result { match &self.fan_h { diff --git a/data/src/config/flat.rs b/data/src/config/flat.rs index ce051e5..9a77458 100644 --- a/data/src/config/flat.rs +++ b/data/src/config/flat.rs @@ -6,7 +6,7 @@ use crate::{ app_graph::AppGraph, node::{IsValid, Node, NodeType, ToNode}, }; -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct Flat { pub name: String, pub value: u16, diff --git a/data/src/config/graph.rs b/data/src/config/graph.rs index 0bf99e6..6b48f08 100644 --- a/data/src/config/graph.rs +++ b/data/src/config/graph.rs @@ -7,7 +7,6 @@ use crate::{ app_graph::AppGraph, node::{IsValid, Node, NodeType, ToNode}, update::UpdateError, - utils::{has_duplicate, is_sorted, InsertSorted, RemoveElem}, }; use super::utils::affine::Affine; @@ -48,7 +47,7 @@ impl Coord { } } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Eq)] pub struct Graph { // unique pub name: String, @@ -56,10 +55,23 @@ pub struct Graph { // temp unique // 0 <= percent <= 100 #[serde(rename = "coord")] - pub coords: Vec, + pub coords: BTreeSet, pub input: Option, // Temp or CustomTemp } +impl PartialEq for Graph { + fn eq(&self, other: &Self) -> bool { + self.name == other.name + && self.input == other.input + && self.coords.len() == other.coords.len() + && self + .coords + .iter() + .zip(&other.coords) + .all(|(a, b)| a.exact_same(b)) + } +} + impl Default for Graph { fn default() -> Self { Self { @@ -73,7 +85,9 @@ impl Default for Graph { temp: 70, percent: 100, }, - ], + ] + .into_iter() + .collect(), input: Default::default(), } } @@ -95,17 +109,12 @@ impl ToNode for Graph { self.coords = deduplicator.into_iter().collect(); - debug_assert!(!has_duplicate(&self.coords)); - debug_assert!(is_sorted(&self.coords)); - Node::new(NodeType::Graph(self), app_graph) } } impl IsValid for Graph { fn is_valid(&self) -> bool { - debug_assert!(!has_duplicate(&self.coords)); - debug_assert!(is_sorted(&self.coords)); self.input.is_some() && !self.coords.is_empty() } } @@ -126,9 +135,9 @@ impl Graph { let coord = Coord { temp, percent }; - if self.coords.binary_search(&coord).is_ok() { + if self.coords.contains(&coord) { return Err(format!( - "Can't add create this new coord {}, this temp is already present", + "Can't create this new coord {}, this temp is already present", temp ) .into()); @@ -138,32 +147,28 @@ impl Graph { } pub fn get_value(&self, value: Value) -> Result { - debug_assert!(!has_duplicate(&self.coords)); - debug_assert!(is_sorted(&self.coords)); - let dummy_coord = Coord { temp: value as u8, percent: 0, }; - let res = match self.coords.binary_search(&dummy_coord) { - Ok(index) => self.coords[index].percent as Value, - Err(index) => { - if index == 0 { - self.coords[index].percent as Value - } else if index == self.coords.len() { - self.coords[index - 1].percent as Value - } else { - let coord1 = &self.coords[index - 1]; - let coord2 = &self.coords[index]; - - Affine { + let res = match self.coords.get(&dummy_coord) { + Some(c) => c.percent as Value, + None => { + let lower_bound = self.coords.range(..=dummy_coord).next_back(); + let upper_bound = self.coords.range(dummy_coord..).next(); + + match (lower_bound, upper_bound) { + (Some(coord), None) | (None, Some(coord)) => coord.percent as Value, + (Some(coord1), Some(coord2)) => Affine { xa: coord1.temp.into(), ya: coord1.percent.into(), xb: coord2.temp.into(), yb: coord2.percent.into(), } - .calcule(value) as Value + .calcule(value) as Value, + + _ => panic!("internal error: no value for graph"), } } }; @@ -172,10 +177,10 @@ impl Graph { } pub fn add_coord(&mut self, new: Coord) { - self.coords.insert_sorted(|c| c.cmp(&new), new); + self.coords.insert(new); } pub fn remove_coord(&mut self, coord: &Coord) { - self.coords.remove_elem(|c| c.exact_same(coord)); + self.coords.remove(coord); } pub fn replace_coord(&mut self, prev: &Coord, new: Coord) { self.remove_coord(prev); @@ -214,7 +219,9 @@ mod test { temp: 40, percent: 5, }, - ], + ] + .into_iter() + .collect(), input: None, }; diff --git a/data/src/config/linear.rs b/data/src/config/linear.rs index 754331b..21c94bf 100644 --- a/data/src/config/linear.rs +++ b/data/src/config/linear.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use super::utils::affine::Affine; -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct Linear { pub name: String, #[serde(rename = "minTemp", alias = "min_temp")] diff --git a/data/src/config/mod.rs b/data/src/config/mod.rs index 784f44c..0424cfa 100644 --- a/data/src/config/mod.rs +++ b/data/src/config/mod.rs @@ -23,7 +23,7 @@ use crate::{ use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq)] pub struct Config { #[serde(default, rename = "Control")] pub controls: Vec, diff --git a/data/src/config/serde_test.rs b/data/src/config/serde_test.rs index 7257af1..f5a1edf 100644 --- a/data/src/config/serde_test.rs +++ b/data/src/config/serde_test.rs @@ -163,7 +163,9 @@ fn config1() -> Config { temp: 50, percent: 30, }, - ], + ] + .into_iter() + .collect(), input: Some("max".into()), }], flats: vec![Flat { diff --git a/data/src/config/target.rs b/data/src/config/target.rs index 089208c..b0c9015 100644 --- a/data/src/config/target.rs +++ b/data/src/config/target.rs @@ -6,7 +6,7 @@ use crate::{ use hardware::{Hardware, Value}; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Eq)] pub struct Target { pub name: String, #[serde(rename = "idleTemp", alias = "idle_temp")] @@ -23,6 +23,17 @@ pub struct Target { pub idle_has_been_reatch: bool, } +impl PartialEq for Target { + fn eq(&self, other: &Self) -> bool { + self.name == other.name + && self.idle_temp == other.idle_temp + && self.idle_speed == other.idle_speed + && self.load_temp == other.load_temp + && self.load_speed == other.load_speed + && self.input == other.input + } +} + impl Target { pub fn get_value(&mut self, value: Value) -> Result { if self.idle_has_been_reatch { diff --git a/data/src/config/temp.rs b/data/src/config/temp.rs index e8dbf0a..bf0b7e5 100644 --- a/data/src/config/temp.rs +++ b/data/src/config/temp.rs @@ -9,7 +9,7 @@ use crate::{ update::UpdateError, }; -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Eq)] pub struct Temp { pub name: String, #[serde(rename = "id")] @@ -19,6 +19,12 @@ pub struct Temp { pub temp_h: Option>, } +impl PartialEq for Temp { + fn eq(&self, other: &Self) -> bool { + self.name == other.name && self.hardware_id == other.hardware_id + } +} + impl Temp { pub fn get_value(&self, bridge: &mut H) -> Result { match &self.temp_h { diff --git a/i18n/en/ui.ftl b/i18n/en/ui.ftl index dde1fed..2ad7eb3 100644 --- a/i18n/en/ui.ftl +++ b/i18n/en/ui.ftl @@ -50,6 +50,9 @@ create_config = Create configuration already_used_error = This name is already being use invalid_value_error = this value is invalid +# Warning +config_not_saved = Configuration not saved + # Dialogs udev_rules_dialog_ok = I understand udev_rules_dialog_remind_later = Remind me Later diff --git a/res/icons/warning/20px.svg b/res/icons/warning/20px.svg new file mode 100644 index 0000000..d67ad68 --- /dev/null +++ b/res/icons/warning/20px.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/res/icons/warning/24px.svg b/res/icons/warning/24px.svg new file mode 100644 index 0000000..238299e --- /dev/null +++ b/res/icons/warning/24px.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/res/icons/warning/40px.svg b/res/icons/warning/40px.svg new file mode 100644 index 0000000..cdf3a0e --- /dev/null +++ b/res/icons/warning/40px.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/res/icons/warning/48px.svg b/res/icons/warning/48px.svg new file mode 100644 index 0000000..2278ceb --- /dev/null +++ b/res/icons/warning/48px.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ui/src/headers.rs b/ui/src/headers.rs index 1beac47..30b1384 100644 --- a/ui/src/headers.rs +++ b/ui/src/headers.rs @@ -5,7 +5,8 @@ use cosmic::{ widget::{tooltip, Container, Row, Text, TextInput}, Element, }; -use data::dir_manager::DirManager; +use data::{config::Config, AppState}; +use hardware::HardwareBridge; use crate::{ icon, icon::expand_icon, icon_button, message::ConfigMsg, my_widgets::drop_down, AppMsg, @@ -27,15 +28,40 @@ pub fn header_start<'a>() -> Vec> { elems } -pub fn header_center<'a>( - dir_manager: &'a DirManager, - current_config: &'a String, +pub fn header_center<'a, H: HardwareBridge>( + app_state: &'a AppState, + current_config_cached: &'a String, expanded: bool, ) -> Vec> { + let dir_manager = &app_state.dir_manager; let settings = dir_manager.settings(); let mut elems = Vec::new(); + // configuration not saved + if match &settings.current_config { + Some(current_config) => { + if current_config != current_config_cached { + true + } else { + match dir_manager.get_config() { + Some(config) => config != Config::from_app_graph(&app_state.app_graph), + None => true, + } + } + } + None => true, + } { + elems.push( + tooltip( + icon!("warning/40").height(ICON_LENGHT).width(ICON_LENGHT), + text(fl!("config_not_saved")), + tooltip::Position::Bottom, + ) + .into(), + ); + } + // save button if settings.current_config.is_some() { elems.push( @@ -46,7 +72,7 @@ pub fn header_center<'a>( .on_press_maybe( dir_manager .config_names - .is_valid_name(&settings.current_config, current_config) + .is_valid_name(&settings.current_config, current_config_cached) .then_some(ConfigMsg::Save.into()), ), text(fl!("save_config")), @@ -56,13 +82,13 @@ pub fn header_center<'a>( ); } - let mut name = TextInput::new(fl!("config_name"), current_config) + let mut name = TextInput::new(fl!("config_name"), current_config_cached) .on_input(|name| ConfigMsg::Rename(name).into()) .width(Length::Fixed(180.0)); if !dir_manager .config_names - .is_valid_name(&settings.current_config, current_config) + .is_valid_name(&settings.current_config, current_config_cached) { //let error_text = fl!("already_used_error"); name = name.error("This name is already being use"); @@ -115,8 +141,8 @@ pub fn header_center<'a>( .on_press_maybe( dir_manager .config_names - .is_valid_create(current_config) - .then_some(ConfigMsg::Create(current_config.to_owned()).into()), + .is_valid_create(current_config_cached) + .then_some(ConfigMsg::Create(current_config_cached.to_owned()).into()), ), text(fl!("create_config")), tooltip::Position::Bottom, diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 0c08cfb..dca3d35 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -566,7 +566,7 @@ impl cosmic::Application for Ui { fn header_center(&self) -> Vec> { headers::header_center( - &self.app_state.dir_manager, + &self.app_state, &self.current_config_cached, self.choose_config_expanded, ) From f0f6dc67f611599508b1eea0c8ab2b71d60fa254 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:04:14 +0100 Subject: [PATCH 11/13] save a cached config when closing without saving --- data/src/dir_manager.rs | 28 ++++++++++++++++++++++------ src/main.rs | 5 ++++- ui/src/lib.rs | 23 +++++++++++++++++++---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/data/src/dir_manager.rs b/data/src/dir_manager.rs index 91e72e6..cfa8e03 100644 --- a/data/src/dir_manager.rs +++ b/data/src/dir_manager.rs @@ -26,6 +26,7 @@ pub struct ConfigNames { pub struct DirManager { pub config_dir_path: PathBuf, pub state_dir_path: PathBuf, + pub cache_dir_path: PathBuf, pub config_names: ConfigNames, settings: Settings, state: SettingsState, @@ -48,6 +49,7 @@ type Result = std::result::Result; static SETTINGS_FILENAME: &str = "settings.toml"; static STATE_FILENAME: &str = "state.toml"; static HARDWARE_FILENAME: &str = "hardware.toml"; +static CACHED_CONFIG_FILENAME: &str = "cached_config.toml"; impl DirManager { pub fn new( @@ -119,12 +121,6 @@ impl DirManager { project_dirs.data_local_dir().to_path_buf() }; - if !state_dir_path.exists() { - if let Err(e) = fs::create_dir_all(&state_dir_path) { - error!("Can't create config directories: {e}.") - } - } - let state = { let state_file_path = state_dir_path.join(STATE_FILENAME); @@ -147,6 +143,7 @@ impl DirManager { settings, state, state_dir_path, + cache_dir_path: project_dirs.cache_dir().to_path_buf(), } } @@ -204,6 +201,20 @@ impl DirManager { } } + pub fn get_config_cached(&self) -> Option { + deserialize::(&self.cache_dir_path.join(CACHED_CONFIG_FILENAME)).ok() + } + + pub fn save_config_cached(&self, config: &Config) -> Result<()> { + serialize(&self.cache_dir_path.join(CACHED_CONFIG_FILENAME), config)?; + + Ok(()) + } + + pub fn remove_config_cached(&self) { + let _ = fs::remove_file(self.cache_dir_path.join(CACHED_CONFIG_FILENAME)); + } + pub fn serialize_hardware(&self, hardware: &Hardware) { let hardware_file_path = self.hardware_file_path(); @@ -446,6 +457,11 @@ mod helper { } pub fn serialize(path: &Path, rust_struct: &T) -> super::Result<()> { + let parent = path.parent().unwrap(); + if !parent.exists() { + fs::create_dir_all(parent)? + } + let str = toml::to_string_pretty(rust_struct)?; fs::write(path, str)?; Ok(()) diff --git a/src/main.rs b/src/main.rs index 8ec604b..cce5adf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,7 +102,10 @@ fn try_run() -> Result<()> { return Ok(()); } - let app_graph = match dir_manager.get_config() { + let app_graph = match dir_manager + .get_config_cached() + .or_else(|| dir_manager.get_config()) + { Some(config) => AppGraph::from_config(config, hardware), None => AppGraph::default(hardware), }; diff --git a/ui/src/lib.rs b/ui/src/lib.rs index dca3d35..7d8c60e 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -593,11 +593,26 @@ impl cosmic::Application for Ui { if let Err(e) = self.app_state.bridge.shutdown() { error!("shutdown hardware: {}", e); } - None - } - fn on_close_requested(&self, _id: iced::window::Id) -> Option { - // todo: pop up. Need to use settings to not close auto + let runtime_config = Config::from_app_graph(&self.app_state.app_graph); + + if match self.app_state.dir_manager.get_config() { + Some(saved_config) => saved_config != runtime_config, + None => true, + } { + if let Err(err) = self + .app_state + .dir_manager + .save_config_cached(&runtime_config) + { + error!("{err}") + } else { + info!("cached config saved successfully"); + } + } else { + self.app_state.dir_manager.remove_config_cached(); + } + None } From db7fa3363e875014955658341e383812557a47d8 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:09:58 +0100 Subject: [PATCH 12/13] add logs --- data/src/dir_manager.rs | 18 ++++++++++++++---- ui/src/lib.rs | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/data/src/dir_manager.rs b/data/src/dir_manager.rs index cfa8e03..0045c32 100644 --- a/data/src/dir_manager.rs +++ b/data/src/dir_manager.rs @@ -151,6 +151,10 @@ impl DirManager { self.config_dir_path.join(SETTINGS_FILENAME) } + fn cached_config_file_path(&self) -> PathBuf { + self.cache_dir_path.join(CACHED_CONFIG_FILENAME) + } + fn hardware_file_path(&self) -> PathBuf { self.config_dir_path.join(HARDWARE_FILENAME) } @@ -202,17 +206,23 @@ impl DirManager { } pub fn get_config_cached(&self) -> Option { - deserialize::(&self.cache_dir_path.join(CACHED_CONFIG_FILENAME)).ok() + deserialize::(&self.cached_config_file_path()) + .ok() + .inspect(|_| info!("load cached config")) } pub fn save_config_cached(&self, config: &Config) -> Result<()> { - serialize(&self.cache_dir_path.join(CACHED_CONFIG_FILENAME), config)?; + serialize(&self.cached_config_file_path(), config)?; Ok(()) } - pub fn remove_config_cached(&self) { - let _ = fs::remove_file(self.cache_dir_path.join(CACHED_CONFIG_FILENAME)); + pub fn remove_config_cached(&self) -> Result<()> { + if fs::exists(self.cached_config_file_path())? { + fs::remove_file(self.cached_config_file_path())?; + info!("cached config removed successfully"); + } + Ok(()) } pub fn serialize_hardware(&self, hardware: &Hardware) { diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 7d8c60e..0174a35 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -610,7 +610,9 @@ impl cosmic::Application for Ui { info!("cached config saved successfully"); } } else { - self.app_state.dir_manager.remove_config_cached(); + if let Err(err) = self.app_state.dir_manager.remove_config_cached() { + error!("{err}") + } } None From 771ec7bbf83a7bcb2e76b67cbbd4a6d64a75455b Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:12:07 +0100 Subject: [PATCH 13/13] Update lib.rs --- ui/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 0174a35..c8885f3 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -609,10 +609,8 @@ impl cosmic::Application for Ui { } else { info!("cached config saved successfully"); } - } else { - if let Err(err) = self.app_state.dir_manager.remove_config_cached() { - error!("{err}") - } + } else if let Err(err) = self.app_state.dir_manager.remove_config_cached() { + error!("{err}") } None