From 260ecdc531d1eded2679ee7dc76c401e5071f566 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Thu, 27 Jun 2024 13:21:23 +0200 Subject: [PATCH] Implemented reading/writing of json settings --- Linux/Cargo.lock | 1119 +--------------------------- Linux/Cargo.toml | 10 +- Linux/locales/mainwindow.yml | 7 +- Linux/src/config.rs | 57 -- Linux/src/config/json.rs | 55 ++ Linux/src/config/mod.rs | 75 ++ Linux/src/mainwindow.rs | 93 ++- Linux/src/orchestrator/mod.rs | 53 +- Linux/src/orchestrator/settings.rs | 19 + Linux/src/registry/mod.rs | 4 +- Linux/src/util/mod.rs | 4 +- Linux/src/util/option_result.rs | 33 + Linux/src/util/unique_id.rs | 42 +- Linux/src/util/validated_string.rs | 55 ++ 14 files changed, 383 insertions(+), 1243 deletions(-) delete mode 100644 Linux/src/config.rs create mode 100644 Linux/src/config/json.rs create mode 100644 Linux/src/config/mod.rs create mode 100644 Linux/src/orchestrator/settings.rs create mode 100644 Linux/src/util/option_result.rs create mode 100644 Linux/src/util/validated_string.rs diff --git a/Linux/Cargo.lock b/Linux/Cargo.lock index 949937d..3649d22 100644 --- a/Linux/Cargo.lock +++ b/Linux/Cargo.lock @@ -6,6 +6,7 @@ version = 3 name = "MassiveKnob" version = "0.1.0" dependencies = [ + "anyhow", "env_logger", "log", "min-rs", @@ -15,8 +16,7 @@ dependencies = [ "relm4-icons", "rust-i18n", "serde", - "slint-build", - "walkdir", + "serde_json", ] [[package]] @@ -34,18 +34,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -55,12 +43,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "anstream" version = "0.6.14" @@ -110,24 +92,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + [[package]] name = "arc-swap" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" -[[package]] -name = "arrayref" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" - -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - [[package]] name = "autocfg" version = "1.3.0" @@ -149,18 +125,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "bit_field" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" - [[package]] name = "bitflags" version = "1.3.2" @@ -189,18 +153,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "by_address" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64fa3c856b712db6612c019f14756e64e4bcea13337a6b33b696333a9eaa2d06" - -[[package]] -name = "bytemuck" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" - [[package]] name = "byteorder" version = "1.5.0" @@ -253,46 +205,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "codemap" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e769b5c8c8283982a987c6e948e540254f1058d5a74b8794914d4ef5fc2a24" - -[[package]] -name = "codemap-diagnostic" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc20770be05b566a963bf91505e60412c4a2d016d1ef95c5512823bb085a8122" -dependencies = [ - "codemap", - "termcolor", -] - -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - [[package]] name = "colorchoice" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "countme" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636" - [[package]] name = "crc32fast" version = "1.4.2" @@ -327,40 +245,6 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "css-color-parser2" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8ed1639f4b56ec6f31d007ff66ce4a13099dce5a9995d48368a30d62bf04bd" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "data-url" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" - -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version", - "syn 1.0.109", -] - [[package]] name = "dirs-next" version = "1.0.2" @@ -382,23 +266,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "displaydoc" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - -[[package]] -name = "either" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" - [[package]] name = "env_filter" version = "0.1.0" @@ -428,40 +295,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "euclid" -version = "0.22.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f0eb73b934648cd7a4a61f1b15391cd95dab0b4da6e2e66c2a072c144b4a20" -dependencies = [ - "num-traits", -] - -[[package]] -name = "exr" -version = "1.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "887d93f60543e9a9362ef8a21beedd0a833c5d9610e18c67abe15a5963dcb1a4" -dependencies = [ - "bit_field", - "flume", - "half", - "lebe", - "miniz_oxide", - "rayon-core", - "smallvec", - "zune-inflate", -] - -[[package]] -name = "fdeflate" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f9bfee30e4dedf0ab8b422f03af778d9612b63f502710fc500a334ebe2de645" -dependencies = [ - "simd-adler32", -] - [[package]] name = "field-offset" version = "0.3.6" @@ -482,12 +315,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "float-cmp" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" - [[package]] name = "flume" version = "0.11.0" @@ -500,48 +327,6 @@ dependencies = [ "spin", ] -[[package]] -name = "fontconfig-parser" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a595cb550439a117696039dfc69830492058211b771a2a165379f2a1a53d84d" -dependencies = [ - "roxmltree", -] - -[[package]] -name = "fontdb" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0299020c3ef3f60f526a4f64ab4a3d4ce116b1acbf24cdd22da0068e5d81dc3" -dependencies = [ - "fontconfig-parser", - "log", - "memmap2", - "slotmap", - "tinyvec", - "ttf-parser", -] - -[[package]] -name = "fontdue" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9099a2f86b8e674b75d03ff154b3fe4c5208ed249ced8d69cc313a9fa40bb488" -dependencies = [ - "hashbrown 0.14.5", - "ttf-parser", -] - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - [[package]] name = "fragile" version = "2.0.0" @@ -707,16 +492,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "gif" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" -dependencies = [ - "color_quant", - "weezl", -] - [[package]] name = "gimli" version = "0.29.0" @@ -962,16 +737,6 @@ dependencies = [ "zvariant", ] -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -983,10 +748,6 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] [[package]] name = "heck" @@ -1006,178 +767,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "i-slint-common" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98770ce4f006a76efa0c728857a29fdca2dcad5dc0442f0aa786a28bbf9dcab1" -dependencies = [ - "cfg-if", - "derive_more", - "fontdb", - "libloading", -] - -[[package]] -name = "i-slint-compiler" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2f6ebf56a7c2845868e01e111558b0e2e8164a3514a7fd54ab3edc2b6c3a83" -dependencies = [ - "by_address", - "codemap", - "codemap-diagnostic", - "css-color-parser2", - "derive_more", - "fontdue", - "i-slint-common", - "image", - "itertools", - "linked_hash_set", - "lyon_extra", - "lyon_path", - "num_enum", - "once_cell", - "proc-macro2", - "quote", - "resvg", - "rowan", - "smol_str", - "strum", - "thiserror", - "url", -] - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f8ac670d7422d7f76b32e17a5db556510825b29ec9154f235977c9caba61036" -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.66", -] - -[[package]] -name = "idna" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4716a3a0933a1d01c2f72450e89596eb51dd34ef3c211ccd875acdf1f8fe47ed" -dependencies = [ - "icu_normalizer", - "icu_properties", - "smallvec", - "utf8_iter", -] - [[package]] name = "ignore" version = "0.4.22" @@ -1194,30 +783,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "image" -version = "0.24.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "exr", - "gif", - "jpeg-decoder", - "num-traits", - "png", - "qoi", - "tiff", -] - -[[package]] -name = "imagesize" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284" - [[package]] name = "indexmap" version = "1.9.3" @@ -1244,30 +809,12 @@ version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "jpeg-decoder" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" -dependencies = [ - "rayon", -] - [[package]] name = "js-sys" version = "0.3.69" @@ -1277,50 +824,18 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kurbo" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e5aa9f0f96a938266bdb12928a67169e8d22c6a786fda8ed984b85e6ba93c3c" -dependencies = [ - "arrayvec", - "smallvec", -] - [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lebe" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" - [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "libloading" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" -dependencies = [ - "cfg-if", - "windows-targets", -] - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - [[package]] name = "libredox" version = "0.1.3" @@ -1337,21 +852,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "linked_hash_set" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47186c6da4d81ca383c7c47c1bfc80f4b95f4720514d860a5407aaf4233f9588" -dependencies = [ - "linked-hash-map", -] - -[[package]] -name = "litemap" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" - [[package]] name = "lock_api" version = "0.4.12" @@ -1368,52 +868,12 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -[[package]] -name = "lyon_extra" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c4a243ce61e7e5f3ae6c72a88d8fb081b6c69f13500c15e99cfd1159a833b20" -dependencies = [ - "lyon_path", - "thiserror", -] - -[[package]] -name = "lyon_geom" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edecfb8d234a2b0be031ab02ebcdd9f3b9ee418fb35e265f7a540a48d197bff9" -dependencies = [ - "arrayvec", - "euclid", - "num-traits", -] - -[[package]] -name = "lyon_path" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c08a606c7a59638d6c6aa18ac91a06aa9fb5f765a7efb27e6a4da58700740d7" -dependencies = [ - "lyon_geom", - "num-traits", -] - [[package]] name = "memchr" version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" -[[package]] -name = "memmap2" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" -dependencies = [ - "libc", -] - [[package]] name = "memoffset" version = "0.9.1" @@ -1438,7 +898,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", - "simd-adler32", ] [[package]] @@ -1459,16 +918,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", - "libm", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -1479,27 +928,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num_enum" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" -dependencies = [ - "proc-macro-crate 3.1.0", - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "object" version = "0.36.0" @@ -1539,18 +967,6 @@ dependencies = [ "system-deps", ] -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pico-args" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -1578,19 +994,6 @@ dependencies = [ "dirs-next", ] -[[package]] -name = "png" -version = "0.17.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" -dependencies = [ - "bitflags 1.3.2", - "crc32fast", - "fdeflate", - "flate2", - "miniz_oxide", -] - [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -1619,15 +1022,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "qoi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" -dependencies = [ - "bytemuck", -] - [[package]] name = "quick-xml" version = "0.31.0" @@ -1647,26 +1041,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rayon" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_users" version = "0.4.5" @@ -1746,48 +1120,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "resvg" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2327ced609dadeed3e9702fec3e6b2ddd208758a9268d13e06566c6101ba533" -dependencies = [ - "log", - "pico-args", - "rgb", - "svgtypes", - "tiny-skia", - "usvg", -] - -[[package]] -name = "rgb" -version = "0.8.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" -dependencies = [ - "bytemuck", -] - -[[package]] -name = "rowan" -version = "0.15.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a58fa8a7ccff2aec4f39cc45bf5f985cec7125ab271cf681c279fd00192b49" -dependencies = [ - "countme", - "hashbrown 0.14.5", - "memoffset", - "rustc-hash", - "text-size", -] - -[[package]] -name = "roxmltree" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f" - [[package]] name = "rust-i18n" version = "3.0.1" @@ -1845,12 +1177,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc_version" version = "0.4.0" @@ -1860,28 +1186,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustversion" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" - -[[package]] -name = "rustybuzz" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88117946aa1bfb53c2ae0643ceac6506337f44887f8c9fbfb43587b1cc52ba49" -dependencies = [ - "bitflags 2.5.0", - "bytemuck", - "smallvec", - "ttf-parser", - "unicode-bidi-mirroring", - "unicode-ccc", - "unicode-properties", - "unicode-script", -] - [[package]] name = "ryu" version = "1.0.18" @@ -1967,27 +1271,6 @@ dependencies = [ "yaml-rust", ] -[[package]] -name = "simd-adler32" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" - -[[package]] -name = "simplecss" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a11be7c62927d9427e9f40f3444d5499d868648e2edbc4e2116de69e7ec0e89d" -dependencies = [ - "log", -] - -[[package]] -name = "siphasher" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" - [[package]] name = "slab" version = "0.4.9" @@ -1997,42 +1280,12 @@ dependencies = [ "autocfg", ] -[[package]] -name = "slint-build" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41a2c87c4f1fb80f6a0af909e702ed3d782a1e388de04738be041c8f1dc5dfd5" -dependencies = [ - "i-slint-compiler", - "spin_on", - "thiserror", - "toml_edit 0.22.14", -] - -[[package]] -name = "slotmap" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a" -dependencies = [ - "version_check", -] - [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "smol_str" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd538fb6910ac1099850255cf94a94df6551fbdd602454387d0adb2d1ca6dead" -dependencies = [ - "serde", -] - [[package]] name = "spin" version = "0.9.8" @@ -2042,15 +1295,6 @@ dependencies = [ "lock_api", ] -[[package]] -name = "spin_on" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076e103ed41b9864aa838287efe5f4e3a7a0362dd00671ae62a212e5e4612da2" -dependencies = [ - "pin-utils", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -2063,47 +1307,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strict-num" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" -dependencies = [ - "float-cmp", -] - -[[package]] -name = "strum" -version = "0.26.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn 2.0.66", -] - -[[package]] -name = "svgtypes" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fae3064df9b89391c9a76a0425a69d124aee9c5c28455204709e72c39868a43c" -dependencies = [ - "kurbo", - "siphasher", -] - [[package]] name = "syn" version = "1.0.109" @@ -2126,17 +1329,6 @@ dependencies = [ "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.66", -] - [[package]] name = "system-deps" version = "6.2.2" @@ -2156,21 +1348,6 @@ version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "text-size" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233" - [[package]] name = "thiserror" version = "1.0.61" @@ -2191,68 +1368,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "tiff" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" -dependencies = [ - "flate2", - "jpeg-decoder", - "weezl", -] - -[[package]] -name = "tiny-skia" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab" -dependencies = [ - "arrayref", - "arrayvec", - "bytemuck", - "cfg-if", - "log", - "png", - "tiny-skia-path", -] - -[[package]] -name = "tiny-skia-path" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93" -dependencies = [ - "arrayref", - "bytemuck", - "strict-num", -] - -[[package]] -name = "tinystr" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" -dependencies = [ - "displaydoc", - "zerovec", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "tokio" version = "1.38.0" @@ -2376,104 +1491,12 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "ttf-parser" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-bidi-mirroring" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23cb788ffebc92c5948d0e997106233eeb1d8b9512f93f41651f52b6c5f5af86" - -[[package]] -name = "unicode-ccc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df77b101bcc4ea3d78dafc5ad7e4f58ceffe0b2b16bf446aeb50b6cb4157656" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-properties" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4259d9d4425d9f0661581b804cb85fe66a4c631cadd8f490d1c13a35d5d9291" - -[[package]] -name = "unicode-script" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8d71f5726e5f285a935e9fe8edfd53f0491eb6e9a5774097fdabee7cd8c9cd" - -[[package]] -name = "unicode-vo" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" - -[[package]] -name = "url" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c25da092f0a868cdf09e8674cd3b7ef3a7d92a24253e663a2fb85e2496de56" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "usvg" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c704361d822337cfc00387672c7b59eaa72a1f0744f62b2a68aa228a0c6927d" -dependencies = [ - "base64", - "data-url", - "flate2", - "fontdb", - "imagesize", - "kurbo", - "log", - "pico-args", - "roxmltree", - "rustybuzz", - "simplecss", - "siphasher", - "strict-num", - "svgtypes", - "tiny-skia-path", - "unicode-bidi", - "unicode-script", - "unicode-vo", - "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" @@ -2486,12 +1509,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "walkdir" version = "2.5.0" @@ -2562,12 +1579,6 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" -[[package]] -name = "weezl" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" - [[package]] name = "winapi" version = "0.3.9" @@ -2690,24 +1701,6 @@ dependencies = [ "memchr", ] -[[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 = "xmlwriter" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" - [[package]] name = "yaml-rust" version = "0.4.5" @@ -2717,102 +1710,6 @@ dependencies = [ "linked-hash-map", ] -[[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.66", - "synstructure", -] - -[[package]] -name = "zerocopy" -version = "0.7.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - -[[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.66", - "synstructure", -] - -[[package]] -name = "zerovec" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2cc8827d6c0994478a15c53f374f46fbd41bea663d809b14744bc42e6b109c" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97cf56601ee5052b4417d90c8755c6683473c926039908196cf35d99f893ebe7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - -[[package]] -name = "zune-inflate" -version = "0.2.54" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" -dependencies = [ - "simd-adler32", -] - [[package]] name = "zvariant" version = "3.15.2" diff --git a/Linux/Cargo.toml b/Linux/Cargo.toml index 7c11c1e..ae63d8c 100644 --- a/Linux/Cargo.toml +++ b/Linux/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" build = "build.rs" [dependencies] +anyhow = "1.0.86" env_logger = "0.11.3" log = "0.4.21" platform-dirs = "0.3.0" @@ -12,11 +13,8 @@ regex = "1.10.5" relm4 = "0.8.1" relm4-icons = "0.8.3" rust-i18n = "3.0.1" -serde = "1.0.203" +serde = { version = "1.0.203", features = ["derive"] } +serde_json = "1.0.117" [dependencies.min-rs] -git = "https://github.com/MvRens/min-rs.git" - -[build-dependencies] -slint-build = "1.6" -walkdir = "2.5.0" +git = "https://github.com/MvRens/min-rs.git" \ No newline at end of file diff --git a/Linux/locales/mainwindow.yml b/Linux/locales/mainwindow.yml index 4ee5659..81faab7 100644 --- a/Linux/locales/mainwindow.yml +++ b/Linux/locales/mainwindow.yml @@ -3,6 +3,7 @@ _version: 2 mainwindow: title: en: MassiveKnob + tab: device: en: Device @@ -13,4 +14,8 @@ mainwindow: analogoutputs: en: Analog outputs digitaloutputs: - en: Digital outputs \ No newline at end of file + en: Digital outputs + + deviceType: + label: + en: Type \ No newline at end of file diff --git a/Linux/src/config.rs b/Linux/src/config.rs deleted file mode 100644 index 9fc3edc..0000000 --- a/Linux/src/config.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::path::{Path, PathBuf}; -use std::io::{Error, Read, Write}; -use platform_dirs::AppDirs; - -#[derive(Debug)] -pub struct Config -{ - root: PathBuf, - pub device_id: Option -} - - -impl Config -{ - pub fn new() -> Self - { - let appdirs = AppDirs::new(Some("massiveknob"), false).unwrap(); - - Self - { - root: appdirs.data_dir, - device_id: None - } - } - - - pub fn get_reader(&self, name: &str) -> Option - { - let path = Path::join(&self.root, name); - if !path.exists() - { - return None; - } - - match std::fs::File::open(path) - { - Ok(v) => Some(v), - Err(_) => None - } - } - - - pub fn get_writer(&self, name: &str) -> Result - { - let path = Path::join(&self.root, name); - if !path.exists() - { - match std::fs::create_dir_all(path.clone()) - { - Ok(_v) => (), - Err(e) => return Err(e) - } - } - - std::fs::File::create(path) - } -} diff --git a/Linux/src/config/json.rs b/Linux/src/config/json.rs new file mode 100644 index 0000000..8215341 --- /dev/null +++ b/Linux/src/config/json.rs @@ -0,0 +1,55 @@ +use anyhow::Error; + +use crate::util::option_result::OptionResult; +use super::{ConfigManager, ConfigName}; + +pub trait JsonConfigManager +{ + fn read_json(&self, name: &ConfigName) -> OptionResult where T : serde::de::DeserializeOwned; + fn write_json(&self, name: &ConfigName, value: &T) -> Result<(), Error> where T : serde::ser::Serialize; +} + + +impl JsonConfigManager for ConfigManager +{ + fn read_json(&self, name: &ConfigName) -> OptionResult where T : serde::de::DeserializeOwned + { + match self.get_reader(&json_config_name(name)) + { + OptionResult::None => OptionResult::None, + + OptionResult::Some(reader) => + { + match serde_json::from_reader(reader) + { + Ok(v) => OptionResult::Some(v), + Err(e) => OptionResult::Err(e.into()) + } + }, + + OptionResult::Err(e) => OptionResult::Err(e) + } + } + + + fn write_json(&self, name: &ConfigName, value: &T) -> Result<(), Error> where T : serde::ser::Serialize + { + match self.get_writer(&json_config_name(name)) + { + Ok(writer) => match serde_json::to_writer(writer, value) + { + Ok(_) => Ok(()), + Err(e) => Err(e.into()) + }, + + Err(e) => Err(e.into()) + } + } +} + + +#[inline] +fn json_config_name(name: &ConfigName) -> ConfigName +{ + ConfigName::new(format!("{}.json", name.as_str()).as_str()) +} \ No newline at end of file diff --git a/Linux/src/config/mod.rs b/Linux/src/config/mod.rs new file mode 100644 index 0000000..f9b433b --- /dev/null +++ b/Linux/src/config/mod.rs @@ -0,0 +1,75 @@ +use std::path::{Path, PathBuf}; +use std::io::{Error, Read, Write}; +use platform_dirs::AppDirs; + +use crate::util::option_result::OptionResult; +use crate::util::validated_string::{ValidatedString, ValidatedStringPattern}; + + +pub mod json; + + + +#[derive(Debug)] +pub struct ConfigManager +{ + root: PathBuf, +} + + +impl ConfigManager +{ + pub fn new() -> Self + { + let appdirs = AppDirs::new(Some("massiveknob"), false).unwrap(); + + Self + { + root: appdirs.data_dir + } + } + + + pub fn get_reader(&self, name: &ConfigName) -> OptionResult + { + let path = Path::join(&self.root, name.as_str()); + if !path.exists() + { + return OptionResult::None; + } + + match std::fs::File::open(path) + { + Ok(v) => OptionResult::Some(v), + Err(e) => OptionResult::Err(e.into()) + } + } + + + pub fn get_writer(&self, name: &ConfigName) -> Result + { + let path = Path::join(&self.root, name.as_str()); + if !path.exists() + { + match std::fs::create_dir_all(path.clone()) + { + Ok(_v) => (), + Err(e) => return Err(e) + } + } + + std::fs::File::create(path) + } +} + + + +pub type ConfigName = ValidatedString; + + +pub struct ConfigNamePattern; + +impl ValidatedStringPattern for ConfigNamePattern +{ + fn pattern() -> &'static str { r"^[a-zA-Z0-9\.\-_]+$" } +} \ No newline at end of file diff --git a/Linux/src/mainwindow.rs b/Linux/src/mainwindow.rs index 2d776d0..e2f6130 100644 --- a/Linux/src/mainwindow.rs +++ b/Linux/src/mainwindow.rs @@ -34,6 +34,13 @@ pub enum MainWindowMsg pub struct MainWindowWidgets { + device: MainWindowDeviceWidgets +} + + +pub struct MainWindowDeviceWidgets +{ + devices_combobox: gtk::ComboBoxText } @@ -60,18 +67,8 @@ impl SimpleComponent for MainWindow fn init(_data: Self::Init, window: Self::Root, _sender: ComponentSender, ) -> ComponentParts { let model = MainWindow {}; + let widgets = Self::init_ui(&window); - let tabs = gtk::Notebook::builder().build(); - window.set_child(Some(&tabs)); - - add_box_tab(&tabs, "mainwindow.tab.device"); - add_box_tab(&tabs, "mainwindow.tab.analoginputs"); - add_box_tab(&tabs, "mainwindow.tab.digitalinputs"); - //add_box_tab(&tabs, "mainwindow.tab.analogoutputs"); - //add_box_tab(&tabs, "mainwindow.tab.digitaloutputs"); - - - let widgets = MainWindowWidgets {}; ComponentParts { model, widgets } } @@ -85,17 +82,73 @@ impl SimpleComponent for MainWindow } -fn add_box_tab(notebook: >k::Notebook, title_key: &str) -> gtk::Box + +impl MainWindow { - let tab = gtk::Box::builder() - .orientation(gtk::Orientation::Vertical) - .build(); + fn init_ui(window: >k::Window) -> MainWindowWidgets + { + let tabs = gtk::Notebook::builder().build(); + window.set_child(Some(&tabs)); - let tab_label = gtk::Label::builder() - .label(t!(title_key)) - .build(); + MainWindowWidgets + { + device: Self::init_device_tab(&tabs) + //Self::new_box_tab(&tabs, "mainwindow.tab.analoginputs"); + //Self::new_box_tab(&tabs, "mainwindow.tab.digitalinputs"); + //Self::add_box_tab(&tabs, "mainwindow.tab.analogoutputs"); + //Self::add_box_tab(&tabs, "mainwindow.tab.digitaloutputs"); + } + } - notebook.append_page(&tab, Some(&tab_label)); - tab + fn init_device_tab(tabs: >k::Notebook) -> MainWindowDeviceWidgets + { + let tab = Self::new_box_tab(&tabs, "mainwindow.tab.device"); + + let label = gtk::Label::builder() + .label(t!("mainwindow.deviceType.label")) + .halign(gtk::Align::Start) + .build(); + + tab.append(&label); + + + + let devices_combobox = gtk::ComboBoxText::builder() + .build(); + + tab.append(&devices_combobox); + + + // TEMP + devices_combobox.append_text("Test"); + devices_combobox.append_text("Test 2"); + + + MainWindowDeviceWidgets + { + devices_combobox + } + } + + + fn new_box_tab(notebook: >k::Notebook, title_key: &str) -> gtk::Box + { + let tab = gtk::Box::builder() + .orientation(gtk::Orientation::Vertical) + .spacing(8) + .margin_start(8) + .margin_end(8) + .margin_top(8) + .margin_bottom(8) + .build(); + + let tab_label = gtk::Label::builder() + .label(t!(title_key)) + .build(); + + notebook.append_page(&tab, Some(&tab_label)); + + tab + } } \ No newline at end of file diff --git a/Linux/src/orchestrator/mod.rs b/Linux/src/orchestrator/mod.rs index e5deacc..9e40503 100644 --- a/Linux/src/orchestrator/mod.rs +++ b/Linux/src/orchestrator/mod.rs @@ -1,18 +1,25 @@ use crate::actions; use crate::actions::MkAction; -use crate::config::Config; +use crate::config::json::JsonConfigManager; +use crate::config::{ConfigManager, ConfigName}; use crate::devices; use crate::devices::MkDevice; use crate::registry::MkRegistry; use crate::util::unique_id::UniqueId; +mod settings; + + pub struct Orchestrator { - config: Config, + config_manager: ConfigManager, device_registry: MkRegistry, - action_registry: MkRegistry + action_registry: MkRegistry, + + settings_name: ConfigName, + settings: settings::Settings } @@ -20,8 +27,14 @@ impl Orchestrator { pub fn new() -> Self { - let config = Config::new(); - //config.get_reader(name) + let config_manager = ConfigManager::new(); + + let settings_name = ConfigName::new("settings"); + let settings = match config_manager.read_json(&settings_name).expect("Error reading settings") + { + None => settings::Settings::new(), + Some(v) => v + }; let mut device_registry = MkRegistry::new(); let mut action_registry = MkRegistry::new(); @@ -31,23 +44,41 @@ impl Orchestrator Self { - config, + config_manager, + device_registry, - action_registry + action_registry, + + settings_name, + settings } } pub fn current_device(&self) -> Option<&MkDevice> { - let Some(device_id) = &self.config.device_id else { return None }; + let Some(device_id) = &self.settings.device_id else { return None }; self.device_registry.by_id(UniqueId::new(device_id.as_str())) } - pub fn set_current_device_id(&self, id: &str) + pub fn set_current_device_id(&mut self, id: &str) { - // TODO if changed, unload old device, activate new - todo!("Store in config"); + let new_id = Some(String::from(id)); + if new_id == self.settings.device_id { return; } + + self.settings.device_id = new_id; + self.store_settings(); + + // TODO unload old device, activate new + } + + + fn store_settings(&self) + { + if let Err(e) = self.config_manager.write_json(&self.settings_name, &self.settings) + { + log::error!("Error writing settings: {e}"); + } } } \ No newline at end of file diff --git a/Linux/src/orchestrator/settings.rs b/Linux/src/orchestrator/settings.rs new file mode 100644 index 0000000..1cc6c46 --- /dev/null +++ b/Linux/src/orchestrator/settings.rs @@ -0,0 +1,19 @@ +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize)] +pub struct Settings +{ + pub device_id: Option +} + + +impl Settings +{ + pub fn new() -> Self + { + Self + { + device_id: None + } + } +} \ No newline at end of file diff --git a/Linux/src/registry/mod.rs b/Linux/src/registry/mod.rs index ad465ec..abed845 100644 --- a/Linux/src/registry/mod.rs +++ b/Linux/src/registry/mod.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use log::info; +use log; use crate::util::unique_id::UniqueId; @@ -38,7 +38,7 @@ impl<'a, T> MkRegistry where T: RegistryItem { let device_id = device.unique_id(); - info!("Registered device: [{}] {}", device_id.as_str(), device.name()); + log::debug!("Registered device: [{}] {}", device_id.as_str(), device.name()); self.items.insert(String::from(device_id.as_str()), device); } diff --git a/Linux/src/util/mod.rs b/Linux/src/util/mod.rs index 358541a..67149b4 100644 --- a/Linux/src/util/mod.rs +++ b/Linux/src/util/mod.rs @@ -1 +1,3 @@ -pub mod unique_id; \ No newline at end of file +pub mod unique_id; +pub mod option_result; +pub mod validated_string; diff --git a/Linux/src/util/option_result.rs b/Linux/src/util/option_result.rs new file mode 100644 index 0000000..3eef969 --- /dev/null +++ b/Linux/src/util/option_result.rs @@ -0,0 +1,33 @@ +use std::fmt::Display; + + +pub enum OptionResult +{ + None, + Some(T), + Err(E), +} + + +impl OptionResult +{ + pub fn unwrap(self) -> Option + { + match self + { + OptionResult::None => None, + OptionResult::Some(v) => Some(v), + OptionResult::Err(e) => panic!("called `OptionResult::unwrap()` on an `Err` value: {e}"), + } + } + + pub fn expect(self, msg: &str) -> Option + { + match self + { + OptionResult::None => None, + OptionResult::Some(v) => Some(v), + OptionResult::Err(e) => panic!("{msg}: {e}"), + } + } +} \ No newline at end of file diff --git a/Linux/src/util/unique_id.rs b/Linux/src/util/unique_id.rs index 4df9136..dfea5ae 100644 --- a/Linux/src/util/unique_id.rs +++ b/Linux/src/util/unique_id.rs @@ -1,38 +1,12 @@ -use regex::Regex; +use super::validated_string::{ValidatedString, ValidatedStringPattern}; -pub struct UniqueId +pub type UniqueId = ValidatedString; + + +pub struct UniqueIdPattern; + +impl ValidatedStringPattern for UniqueIdPattern { - inner: String, -} - - -impl UniqueId -{ - pub fn new(id: &str) -> Self - { - assert!(is_valid_unique_id(id), "Id '{id}' has invalid characters"); - UniqueId { inner: id.to_string() } - } - - pub fn as_str(&self) -> &str - { - self.inner.as_str() - } -} - - -fn is_valid_unique_id(id: &str) -> bool -{ - let re = Regex::new(r"^[a-zA-Z0-9\.\-_]+$").unwrap(); - re.is_match(id) -} - - -impl Clone for UniqueId -{ - fn clone(&self) -> Self - { - Self { inner: self.inner.clone() } - } + fn pattern() -> &'static str { r"^[a-zA-Z0-9\.\-_]+$" } } \ No newline at end of file diff --git a/Linux/src/util/validated_string.rs b/Linux/src/util/validated_string.rs new file mode 100644 index 0000000..708e4c6 --- /dev/null +++ b/Linux/src/util/validated_string.rs @@ -0,0 +1,55 @@ +use std::marker::PhantomData; +use regex::Regex; + + +/// A string which must conform to the specified regex pattern, +/// otherwise it will panic by design. Intended for code validation, +/// not for runtime input validation. +pub struct ValidatedString +{ + inner: String, + + // Satisfy the compiler's demand to use T + _phantom: std::marker::PhantomData +} + + +impl ValidatedString +{ + pub fn new(value: &str) -> Self + { + let pattern = Regex::new(T::pattern()).unwrap(); + assert!(pattern.is_match(value), "Value '{value}' has invalid characters"); + + Self + { + inner: value.to_string(), + _phantom: PhantomData + } + } + + + pub fn as_str(&self) -> &str + { + self.inner.as_str() + } +} + + +impl Clone for ValidatedString +{ + fn clone(&self) -> Self + { + Self + { + inner: self.inner.clone(), + _phantom: PhantomData + } + } +} + + +pub trait ValidatedStringPattern +{ + fn pattern() -> &'static str; +} \ No newline at end of file