diff --git a/Cargo.lock b/Cargo.lock index 93699ee..e6507e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,9 +233,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d67d43201f4d20c78bcda740c142ca52482d81da80681533d33bf3f0596c8e2" +checksum = "d0f9ee0f6e02ffd7ad5816e9464499fba7b3effd01123b515c41d1697c43dad1" dependencies = [ "compression-codecs", "compression-core", @@ -564,9 +564,9 @@ dependencies = [ [[package]] name = "blade-graphics" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4deb8f595ce7f00dee3543ebf6fd9a20ea86fc421ab79600dac30876250bdae" +checksum = "e71cfb73b98eb9f58ee84048aa1bdf4e7497fd20c141b57523499fa066b48fed" dependencies = [ "ash", "ash-window", @@ -834,9 +834,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.43" +version = "0.4.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" dependencies = [ "iana-time-zone", "js-sys", @@ -1276,9 +1276,9 @@ checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376" [[package]] name = "deflate64" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26bf8fc351c5ed29b5c2f0cbbac1b209b74f60ecd62e675a998df72c49af5204" +checksum = "807800ff3288b621186fe0a8f3392c4652068257302709c24efd918c3dffcdc2" [[package]] name = "derive_more" @@ -1402,9 +1402,9 @@ checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" [[package]] name = "dispatch2" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" +checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" dependencies = [ "bitflags 2.11.0", "objc2", @@ -1423,9 +1423,9 @@ dependencies = [ [[package]] name = "dlib" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +checksum = "ab8ecd87370524b461f8557c119c405552c396ed91fc0a8eec68679eab26f94a" dependencies = [ "libloading", ] @@ -1579,9 +1579,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "erased-serde" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e8918065695684b2b0702da20382d5ae6065cf3327bc2d6436bd49a71ce9f3" +checksum = "d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec" dependencies = [ "serde", "serde_core", @@ -2062,20 +2062,20 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "r-efi", + "r-efi 5.3.0", "wasip2", "wasm-bindgen", ] [[package]] name = "getrandom" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" dependencies = [ "cfg-if", "libc", - "r-efi", + "r-efi 6.0.0", "rand_core 0.10.0", "wasip2", "wasip3", @@ -2573,15 +2573,15 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" [[package]] name = "hidapi" -version = "2.6.4" +version = "2.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565dd4c730b8f8b2c0fb36df6be12e5470ae10895ddcc4e9dcfbfb495de202b0" +checksum = "d1b71e1f4791fb9e93b9d7ee03d70b501ab48f6151432fbcadeabc30fe15396e" dependencies = [ "cc", "cfg-if", "libc", "pkg-config", - "windows-sys 0.48.0", + "windows-sys 0.61.2", ] [[package]] @@ -3019,9 +3019,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.11.0" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" [[package]] name = "is-docker" @@ -3087,9 +3087,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.88" +version = "0.3.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e709f3e3d22866f9c25b3aff01af289b18422cc8b4262fb19103ee80fe513d" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" dependencies = [ "once_cell", "wasm-bindgen", @@ -3215,13 +3215,14 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "libredox" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a" dependencies = [ "bitflags 2.11.0", "libc", - "redox_syscall 0.7.1", + "plain", + "redox_syscall 0.7.3", ] [[package]] @@ -3821,9 +3822,9 @@ dependencies = [ [[package]] name = "objc2" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05" +checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f" dependencies = [ "objc2-encode", ] @@ -4191,18 +4192,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.10" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.10" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" dependencies = [ "proc-macro2", "quote", @@ -4211,9 +4212,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pin-utils" @@ -4223,9 +4224,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "piper" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" dependencies = [ "atomic-waker", "fastrand 2.3.0", @@ -4238,6 +4239,12 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "png" version = "0.17.16" @@ -4337,11 +4344,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" dependencies = [ - "toml_edit 0.23.10+spec-1.0.0", + "toml_edit 0.25.3+spec-1.1.0", ] [[package]] @@ -4406,12 +4413,9 @@ dependencies = [ [[package]] name = "pxfm" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7186d3822593aa4393561d186d1393b3923e9d6163d3fbfd6e825e3e6cf3e6a8" -dependencies = [ - "num-traits", -] +checksum = "b5a041e753da8b807c9255f28de81879c78c876392ff2469cde94799b2896b9d" [[package]] name = "qoi" @@ -4503,9 +4507,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.44" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -4516,6 +4520,12 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "rand" version = "0.8.5" @@ -4544,7 +4554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" dependencies = [ "chacha20", - "getrandom 0.4.1", + "getrandom 0.4.2", "rand_core 0.10.0", ] @@ -4716,9 +4726,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.7.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35985aa610addc02e24fc232012c86fd11f14111180f902b67e2d5331f8ebf2b" +checksum = "6ce70a74e890531977d37e532c34d45e9055d2409ed08ddba14529471ed0be16" dependencies = [ "bitflags 2.11.0", ] @@ -4790,9 +4800,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" [[package]] name = "resvg" @@ -4810,9 +4820,9 @@ dependencies = [ [[package]] name = "rgb" -version = "0.8.52" +version = "0.8.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" +checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4" dependencies = [ "bytemuck", ] @@ -4984,9 +4994,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.36" +version = "0.23.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" dependencies = [ "once_cell", "ring", @@ -5876,12 +5886,12 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.25.0" +version = "3.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0136791f7c95b1f6dd99f9cc786b91bb81c3800b639b3478e561ddb7be95e5f1" +checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0" dependencies = [ "fastrand 2.3.0", - "getrandom 0.4.1", + "getrandom 0.4.2", "once_cell", "rustix 1.1.4", "windows-sys 0.61.2", @@ -6033,9 +6043,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.49.0" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" dependencies = [ "bytes", "libc", @@ -6125,6 +6135,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "toml_datetime" +version = "1.0.0+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e" +dependencies = [ + "serde_core", +] + [[package]] name = "toml_edit" version = "0.22.27" @@ -6141,12 +6160,12 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.23.10+spec-1.0.0" +version = "0.25.3+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269" +checksum = "a0a07913e63758bc95142d9863a5a45173b71515e68b690cad70cf99c3255ce1" dependencies = [ "indexmap", - "toml_datetime 0.7.5+spec-1.1.0", + "toml_datetime 1.0.0+spec-1.1.0", "toml_parser", "winnow", ] @@ -6321,13 +6340,13 @@ checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" [[package]] name = "uds_windows" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89daebc3e6fd160ac4aa9fc8b3bf71e1f74fbf92367ae71fb83a037e8bf164b9" +checksum = "51b70b87d15e91f553711b40df3048faf27a7a04e01e0ddc0cf9309f0af7c2ca" dependencies = [ "memoffset", "tempfile", - "winapi", + "windows-sys 0.61.2", ] [[package]] @@ -6499,7 +6518,7 @@ version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b672338555252d43fd2240c714dc444b8c6fb0a5c5335e65a07bba7742735ddb" dependencies = [ - "getrandom 0.4.1", + "getrandom 0.4.2", "js-sys", "serde_core", "sha1_smol", @@ -6630,9 +6649,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.111" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1adf1535672f5b7824f817792b1afd731d7e843d2d04ec8f27e8cb51edd8ac" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" dependencies = [ "cfg-if", "once_cell", @@ -6643,9 +6662,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.61" +version = "0.4.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe88540d1c934c4ec8e6db0afa536876c5441289d7f9f9123d4f065ac1250a6b" +checksum = "e9c5522b3a28661442748e09d40924dfb9ca614b21c00d3fd135720e48b67db8" dependencies = [ "cfg-if", "futures-util", @@ -6657,9 +6676,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.111" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e638317c08b21663aed4d2b9a2091450548954695ff4efa75bff5fa546b3b1" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -6667,9 +6686,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.111" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c64760850114d03d5f65457e96fc988f11f01d38fbaa51b254e4ab5809102af" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" dependencies = [ "bumpalo", "proc-macro2", @@ -6680,9 +6699,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.111" +version = "0.2.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60eecd4fe26177cfa3339eb00b4a36445889ba3ad37080c2429879718e20ca41" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" dependencies = [ "unicode-ident", ] @@ -6833,9 +6852,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.88" +version = "0.3.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6bb20ed2d9572df8584f6dc81d68a41a625cadc6f15999d649a70ce7e3597a" +checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9" dependencies = [ "js-sys", "wasm-bindgen", @@ -7882,18 +7901,18 @@ checksum = "6df3dc4292935e51816d896edcd52aa30bc297907c26167fec31e2b0c6a32524" [[package]] name = "zerocopy" -version = "0.8.39" +version = "0.8.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" +checksum = "a789c6e490b576db9f7e6b6d661bcc9799f7c0ac8352f56ea20193b2681532e5" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.39" +version = "0.8.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" +checksum = "f65c489a7071a749c849713807783f70672b28094011623e200cb86dcb835953" dependencies = [ "proc-macro2", "quote", diff --git a/build.rs b/build.rs index 1aae248..2e1290d 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ #[cfg(windows)] +#[allow(clippy::single_component_path_imports)] use tauri_winres; // Configures windows application resource.( fix for app icon and launching app as admin) diff --git a/src/logging.rs b/src/logging.rs index dd85049..9602637 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -1,9 +1,7 @@ use directories::ProjectDirs; use log::LevelFilter; -use log::Record; use log4rs::{ append::{ - Append, console::{ConsoleAppender, Target}, rolling_file::{ RollingFileAppender, @@ -13,57 +11,9 @@ use log4rs::{ }, }, config::{Appender, Logger, Root}, - encode::{Encode, Write, pattern::PatternEncoder}, + encode::pattern::PatternEncoder, }; use std::fs; -use std::sync::{Arc, Mutex, OnceLock}; - -pub static LOG_BUFFER: OnceLock>>> = OnceLock::new(); - -struct SimpleWriter(Vec); - -impl std::io::Write for SimpleWriter { - fn write(&mut self, buf: &[u8]) -> std::io::Result { - self.0.extend_from_slice(buf); - Ok(buf.len()) - } - - fn flush(&mut self) -> std::io::Result<()> { - Ok(()) - } -} - -impl Write for SimpleWriter {} - -#[derive(Debug)] -struct BufferAppender { - encoder: Box, -} - -impl BufferAppender { - pub fn new(encoder: Box) -> Self { - Self { encoder } - } -} - -impl Append for BufferAppender { - fn append(&self, record: &Record) -> anyhow::Result<()> { - let mut writer = SimpleWriter(Vec::new()); - self.encoder.encode(&mut writer, record)?; - let log = String::from_utf8(writer.0)?; - - let buffer = LOG_BUFFER.get_or_init(|| Arc::new(Mutex::new(Vec::new()))); - if let Ok(mut logs) = buffer.lock() { - if logs.len() >= 1000 { - logs.remove(0); - } - logs.push(log); - } - Ok(()) - } - - fn flush(&self) {} -} /// Initializes log4rs with custom configuration for stdout and file logging. pub fn logger_init() { @@ -71,8 +21,7 @@ pub fn logger_init() { let org = "suyogtandel"; let app = "picoforge"; - LOG_BUFFER.get_or_init(|| Arc::new(Mutex::new(Vec::new()))); - + // Determine the log file path using ProjectDirs for cross-platform compatibility let log_file_path = { let log_dir = if let Some(proj_dirs) = ProjectDirs::from(qual, org, app) { proj_dirs.data_local_dir().join("logs") @@ -109,34 +58,20 @@ pub fn logger_init() { ))) .build(); - // Buffer Appender - let buffer_appender = BufferAppender::new(Box::new(PatternEncoder::new( - "[{d(%Y-%m-%d %H:%M:%S %Z)} {l} {t}] {m}{n}", - ))); - - let app_level = if cfg!(debug_assertions) { - LevelFilter::Trace + let (app_level, root_level) = if cfg!(debug_assertions) { + (LevelFilter::Trace, LevelFilter::Debug) } else { - LevelFilter::Info + (LevelFilter::Info, LevelFilter::Error) }; let config = log4rs::Config::builder() .appender(Appender::builder().build("stdout", Box::new(stdout))) .appender(Appender::builder().build("logfile", Box::new(logfile))) - .appender(Appender::builder().build("buffer", Box::new(buffer_appender) as Box)) - .logger( - Logger::builder() - .appenders(["stdout", "logfile", "buffer"]) - .additive(false) - .build("picoforge", app_level), - ) - .logger(Logger::builder().build("gpui", LevelFilter::Error)) - .logger(Logger::builder().build("gpui_component", LevelFilter::Error)) - .logger(Logger::builder().build("blade_graphics", LevelFilter::Error)) + .logger(Logger::builder().build("picoforge", app_level)) .build( Root::builder() - .appenders(vec!["logfile", "stdout", "buffer"]) - .build(LevelFilter::Error), + .appenders(vec!["logfile", "stdout"]) + .build(root_level), ) .unwrap(); diff --git a/src/main.rs b/src/main.rs index 1ff7647..6ffa6d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,6 @@ fn main() { titlebar: Some(TitlebarOptions { title: Some("PicoForge".into()), appears_transparent: true, - // TODO: This option needs to be tested and adjusted on macos traffic_light_position: Some(gpui::point(px(9.0), px(9.0))), }), diff --git a/src/ui/components/button.rs b/src/ui/components/button.rs index 7a5e4ae..6672629 100644 --- a/src/ui/components/button.rs +++ b/src/ui/components/button.rs @@ -10,12 +10,14 @@ use gpui_component::{ h_flex, }; +type ClickHandler = Option>; + /// A stateless text button wrapper #[derive(IntoElement)] pub struct PFButton { id: SharedString, text: SharedString, - on_click: Option>, + on_click: ClickHandler, bg_color_start: Rgba, bg_color_hover: Rgba, bg_color_active: Rgba, @@ -159,7 +161,7 @@ impl RenderOnce for PFButton { pub struct PFIconButton { icon: Icon, text: SharedString, - on_click: Option>, + on_click: ClickHandler, bg_color_start: Rgba, bg_color_hover: Rgba, bg_color_active: Rgba, diff --git a/src/ui/components/dialog.rs b/src/ui/components/dialog.rs index 424fd5d..ec0aaa3 100644 --- a/src/ui/components/dialog.rs +++ b/src/ui/components/dialog.rs @@ -7,6 +7,12 @@ use gpui_component::{ v_flex, }; +type PinPromptCallback = std::rc::Rc, &mut App)>; +type ConfirmCallback = std::rc::Rc, &mut App)>; +type ChangePinCallback = + std::rc::Rc, &mut App)>; +type SetPinCallback = std::rc::Rc, &mut App)>; + #[derive(Clone)] enum DialogPhase { Input, @@ -15,40 +21,13 @@ enum DialogPhase { Error(String), } -fn render_error_message(msg: String) -> impl IntoElement { - let troubleshooting_phrase = "troubleshooting guide"; - let url = "https://github.com/librekeys/picoforge/wiki/Troubleshooting#1-my-key-is-not-detected-by-picoforge-or-picoforge-displays-a-device-status-of-online---fido-and-there-are-some-settings-that-i-cannot-configure"; - - if msg.contains(troubleshooting_phrase) { - v_flex() - .child("The device firmware does not support being configured in fido only communication mode.") - .child( - h_flex() - .gap_1() - .child("Have a look at the") - .child( - div() - .text_color(rgb(0x3b82f6)) - .cursor_pointer() - .on_mouse_down(MouseButton::Left, move |_, _, cx| { - cx.open_url(url); - }) - .child(troubleshooting_phrase.to_string()), - ) - .child("to fix this"), - ) - } else { - div().child(msg) - } -} - pub struct PinPromptContent { phase: DialogPhase, title: SharedString, description: SharedString, confirm_label: SharedString, pin_input: Entity, - on_confirm: std::rc::Rc, &mut App)>, + on_confirm: PinPromptCallback, _subscription: Subscription, } @@ -271,7 +250,7 @@ pub struct ConfirmContent { message: String, ok_label: SharedString, ok_variant: ButtonVariant, - on_ok: std::rc::Rc, &mut App)>, + on_ok: ConfirmCallback, } impl ConfirmContent { @@ -453,7 +432,7 @@ pub struct ChangePinContent { current_pin: Entity, new_pin: Entity, confirm_pin: Entity, - on_confirm: std::rc::Rc, &mut App)>, + on_confirm: ChangePinCallback, _subscriptions: Vec, } @@ -769,7 +748,7 @@ pub struct SetPinContent { phase: DialogPhase, new_pin: Entity, confirm_pin: Entity, - on_confirm: std::rc::Rc, &mut App)>, + on_confirm: SetPinCallback, _subscriptions: Vec, } @@ -1175,3 +1154,30 @@ pub fn open_status_dialog( handle } + +fn render_error_message(msg: String) -> impl IntoElement { + let troubleshooting_phrase = "troubleshooting guide"; + let url = "https://github.com/librekeys/picoforge/wiki/Troubleshooting#1-my-key-is-not-detected-by-picoforge-or-picoforge-displays-a-device-status-of-online---fido-and-there-are-some-settings-that-i-cannot-configure"; + + if msg.contains(troubleshooting_phrase) { + v_flex() + .child("The device firmware does not support being configured in fido only communication mode.") + .child( + h_flex() + .gap_1() + .child("Have a look at the") + .child( + div() + .text_color(rgb(0x3b82f6)) + .cursor_pointer() + .on_mouse_down(MouseButton::Left, move |_, _, cx| { + cx.open_url(url); + }) + .child(troubleshooting_phrase.to_string()), + ) + .child("to fix this"), + ) + } else { + div().child(msg) + } +} diff --git a/src/ui/components/sidebar.rs b/src/ui/components/sidebar.rs index aa41cd7..35caaca 100644 --- a/src/ui/components/sidebar.rs +++ b/src/ui/components/sidebar.rs @@ -11,13 +11,16 @@ use gpui_component::{ }; use std::rc::Rc; +type SelectHandler = Option)>>; +type RefreshHandler = Option)>>; + pub struct AppSidebar { active_view: ActiveView, width: Pixels, collapsed: bool, state: GlobalDeviceState, - on_select: Option)>>, - on_refresh: Option)>>, + on_select: SelectHandler, + on_refresh: RefreshHandler, } impl AppSidebar { @@ -151,12 +154,6 @@ impl AppSidebar { "icons/shield-check.svg", ActiveView::Security, )) - .child(self.menu_item( - cx, - "Logs", - "icons/scroll-text.svg", - ActiveView::Logs, - )) .child(self.menu_item_icon_name( cx, "About", diff --git a/src/ui/rootview.rs b/src/ui/rootview.rs index f208353..498ad1a 100644 --- a/src/ui/rootview.rs +++ b/src/ui/rootview.rs @@ -2,7 +2,7 @@ use crate::device::io; use crate::ui::components::sidebar::AppSidebar; use crate::ui::types::{ActiveView, GlobalDeviceState}; use crate::ui::views::{ - about::AboutView, config::ConfigView, home::HomeView, logs::LogsView, passkeys::PasskeysEvent, + about::AboutView, config::ConfigView, home::HomeView, passkeys::PasskeysEvent, passkeys::PasskeysView, security::SecurityView, }; @@ -25,7 +25,6 @@ pub struct ApplicationRoot { sidebar_width: Pixels, config_view: Option>, passkeys_view: Option>, - logs_view: Option>, focus_handle: FocusHandle, } @@ -40,7 +39,6 @@ impl ApplicationRoot { sidebar_width: px(255.), config_view: None, passkeys_view: None, - logs_view: None, focus_handle: cx.focus_handle(), }; this.refresh_device_status(None, cx); @@ -75,12 +73,12 @@ impl ApplicationRoot { } } - if let Some(config_view) = &self.config_view { - if let Some(window) = window { - config_view.update(cx, |view, cx| { - view.update_device_status(Some(status.clone()), window, cx); - }); - } + if let Some(config_view) = &self.config_view + && let Some(window) = window + { + config_view.update(cx, |view, cx| { + view.update_device_status(Some(status.clone()), window, cx); + }); } if let Some(passkeys_view) = &self.passkeys_view { @@ -125,8 +123,8 @@ impl Render for ApplicationRoot { self.sidebar_width = target_width; } - let dialog_layer = Root::render_dialog_layer(window, &mut **cx); - let sheet_layer = Root::render_sheet_layer(window, &mut **cx); + let dialog_layer = Root::render_dialog_layer(window, cx); + let sheet_layer = Root::render_sheet_layer(window, cx); let title_bar = TitleBar::new().bg(cx.theme().title_bar).child( h_flex() @@ -184,12 +182,6 @@ impl Render for ApplicationRoot { view.clone().into_any_element() } ActiveView::Security => SecurityView::build(cx).into_any_element(), - ActiveView::Logs => { - let view = self - .logs_view - .get_or_insert_with(|| cx.new(|cx| LogsView::new(window, cx))); - view.clone().into_any_element() - } ActiveView::About => AboutView::build(cx.theme()).into_any_element(), }); diff --git a/src/ui/types.rs b/src/ui/types.rs index 91f5a2d..f69df55 100644 --- a/src/ui/types.rs +++ b/src/ui/types.rs @@ -8,7 +8,6 @@ pub enum ActiveView { Passkeys, Configuration, Security, - Logs, About, } diff --git a/src/ui/views/config.rs b/src/ui/views/config.rs index 055697e..18b617c 100644 --- a/src/ui/views/config.rs +++ b/src/ui/views/config.rs @@ -386,19 +386,19 @@ impl ConfigView { } let led_gpio_str = self.led_gpio_input.read(cx).text().to_string(); - if let Ok(val) = led_gpio_str.parse::() { - if val != current_config.led_gpio { - changes.led_gpio = Some(val); - } + if let Ok(val) = led_gpio_str.parse::() + && val != current_config.led_gpio + { + changes.led_gpio = Some(val); } let driver_idx = self.led_driver_select.read(cx).selected_index(cx); - if let Some(idx) = driver_idx { - if let Some(driver) = LedDriverType::all().get(idx.row) { - let val = driver.value(); - if Some(val) != current_config.led_driver { - changes.led_driver = Some(val); - } + if let Some(idx) = driver_idx + && let Some(driver) = LedDriverType::all().get(idx.row) + { + let val = driver.value(); + if Some(val) != current_config.led_driver { + changes.led_driver = Some(val); } } @@ -408,10 +408,10 @@ impl ConfigView { } let touch_timeout_str = self.touch_timeout_input.read(cx).text().to_string(); - if let Ok(val) = touch_timeout_str.parse::() { - if val != current_config.touch_timeout { - changes.touch_timeout = Some(val); - } + if let Ok(val) = touch_timeout_str.parse::() + && val != current_config.touch_timeout + { + changes.touch_timeout = Some(val); } if (self.led_dimmable != current_config.led_dimmable) @@ -789,7 +789,7 @@ impl Render for ConfigView { })), ), ), - &theme, + theme, ) .into_any_element() } diff --git a/src/ui/views/logs.rs b/src/ui/views/logs.rs deleted file mode 100644 index c7fb368..0000000 --- a/src/ui/views/logs.rs +++ /dev/null @@ -1,160 +0,0 @@ -use crate::logging::LOG_BUFFER; -use crate::ui::components::page_view::PageView; -use gpui::*; -use gpui_component::{ - ActiveTheme, Icon, button::Button, h_flex, scroll::ScrollableElement, v_flex, -}; - -pub struct LogsView { - logs: Vec, -} - -impl LogsView { - pub fn new(_window: &mut Window, cx: &mut Context) -> Self { - let view_weak = cx.entity().downgrade(); - let mut cx_async = cx.to_async(); - - cx.spawn(async move |_, _| { - loop { - cx_async - .background_executor() - .timer(std::time::Duration::from_millis(250)) - .await; - - if let Some(view) = view_weak.upgrade() { - view.update(&mut cx_async, |view, cx| { - view.sync_logs(); - cx.notify(); - }) - .ok(); - } else { - break; - } - } - }) - .detach(); - - Self { logs: Vec::new() } - } - - fn sync_logs(&mut self) { - if let Some(buffer) = LOG_BUFFER.get() { - if let Ok(logs) = buffer.lock() { - self.logs = logs.clone(); - } - } - } - - fn clear(&mut self, cx: &mut Context) { - if let Some(buffer) = LOG_BUFFER.get() { - if let Ok(mut logs) = buffer.lock() { - logs.clear(); - } - } - self.logs.clear(); - cx.notify(); - } -} - -impl Render for LogsView { - fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { - let clear_logs_listener = cx.listener(|this, _, _, cx| { - this.clear(cx); - }); - - let copy_logs_listener = cx.listener(|this, _, _, cx| { - let all_logs = this.logs.join("\n"); - log::debug!("Copying {} bytes of logs", all_logs.len()); - cx.write_to_clipboard(ClipboardItem::new_string(all_logs)); - }); - - let theme = cx.theme(); - - PageView::build( - "System Logs", - "Real-time device communication and application events.", - v_flex() - .gap_4() - .h_full() - .w_full() - .child( - div() - .flex_1() - .flex() - .flex_col() - .min_h(px(500.0)) - .bg(gpui::black()) - .border_1() - .border_color(theme.border) - .rounded(theme.radius) - .child(if self.logs.is_empty() { - div() - .flex_1() - .flex() - .flex_col() - .items_center() - .justify_center() - .text_color(theme.muted_foreground) - .child( - Icon::default() - .path("icons/terminal.svg") - .size_12() - .text_color(theme.muted_foreground) - .opacity(0.5), - ) - .child(div().mt_4().child("No events recorded yet.")) - .into_any_element() - } else { - div() - .overflow_y_scrollbar() - .flex_1() - .h(px(500.0)) - .child( - div() - .overflow_y_scrollbar() - .max_h(px(500.0)) - .p_4() - .font_family("Mono") - .text_sm() - .child(v_flex().gap_neg_4().children( - self.logs.iter().map(|log| { - // TODO: Convert these values to constants in colors.rs - let color = if log.contains("ERROR") { - rgb(0xef4444) - } else if log.contains("WARN") { - rgb(0xfde047) - } else if log.contains("INFO") { - rgb(0x4ade80) - } else if log.contains("TRACE") { - rgb(0x3b82f6) - } else { - theme.foreground.to_rgb() - }; - - div().text_color(color).child(log.clone()) - }), - )), - ) - .into_any_element() - }), - ) - .child( - h_flex() - .justify_end() - .gap_2() - .child( - // NOTE: This does not work on linux as of now(tested on NIXOS-26_GNOME-49_WAYLAND) - Button::new("copy_logs") - .label("Copy Logs") - .on_click(copy_logs_listener), - ) - .child( - Button::new("clear_logs") - .label("Clear Logs") - .on_click(clear_logs_listener), - ), - ), - theme, - ) - } -} diff --git a/src/ui/views/mod.rs b/src/ui/views/mod.rs index c325063..0326cc7 100644 --- a/src/ui/views/mod.rs +++ b/src/ui/views/mod.rs @@ -1,6 +1,5 @@ pub mod about; pub mod config; pub mod home; -pub mod logs; pub mod passkeys; pub mod security;