From 4d90e2cf298b0719ad8e5e54787fa4ac676d33e0 Mon Sep 17 00:00:00 2001 From: Huakun Date: Fri, 21 Feb 2025 05:59:25 -0500 Subject: [PATCH] Feature: watch manifest and reload for dev extension (#181) * feat(desktop): add file system watch support for extensions - Enable file system watching for package.json and test files - Update Cargo.toml to include file system watch feature - Add console logging for file system events * feat(desktop): add extension auto reload mechanism for dev extensions - Implement `reloadExtension` method in extensions store - Add Tauri event for reloading a single extension - Update UI worker to watch package.json and trigger extension reload - Add Linux dependencies for building from source in CONTRIBUTING.md --- CONTRIBUTING.md | 11 + Cargo.lock | 293 ++++++++++++++---- apps/desktop/src-tauri/Cargo.toml | 14 +- apps/desktop/src/lib/stores/extensions.ts | 18 ++ apps/desktop/src/lib/types/fs.ts | 12 + apps/desktop/src/lib/utils/init.ts | 7 +- apps/desktop/src/lib/utils/tauri-events.ts | 10 + .../app/extension/ui-worker/+page.svelte | 30 +- 8 files changed, 321 insertions(+), 74 deletions(-) create mode 100644 apps/desktop/src/lib/types/fs.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ec27d75..25a1ecd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,8 @@ If you are interested in contributing to the project, please read the following - [cmake](https://cmake.org/) - MacOS: `brew install cmake` - Linux: `sudo apt install -y cmake` +- Other Linux Dependencies + - `sudo apt-get install -y protobuf-compiler libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libxdo-dev` ### Setup @@ -44,6 +46,15 @@ cd apps/desktop pnpm tauri dev ``` +### Build from Source + +If you have problem running the app, consider building from source to see if it works. + +```bash +cd apps/desktop +pnpm tauri build +``` + ## i188n If you are willing to help with the translation, please use translations in json files in `apps/desktop/messages`. diff --git a/Cargo.lock b/Cargo.lock index a7a5475..b39534d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -837,7 +837,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4918709cc4dd777ad2b6303ed03cb37f3ca0ccede8c1b0d28ac6db8f4710e0" dependencies = [ "once_cell", - "proc-macro-crate 2.0.2", + "proc-macro-crate 2.0.0", "proc-macro2", "quote", "syn 2.0.87", @@ -1013,26 +1013,26 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.18.1" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +checksum = "8769706aad5d996120af43197bf46ef6ad0fda35216b4505f926a365a232d924" dependencies = [ "camino", "cargo-platform", "semver", "serde", "serde_json", - "thiserror 1.0.66", + "thiserror 2.0.3", ] [[package]] name = "cargo_toml" -version = "0.17.2" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a969e13a7589e9e3e4207e153bae624ade2b5622fb4684a4923b23ec3d57719" +checksum = "5fbd1fe9db3ebf71b89060adaf7b0504c2d6a425cf061313099547e382c2e472" dependencies = [ "serde", - "toml 0.8.2", + "toml 0.8.20", ] [[package]] @@ -1882,6 +1882,15 @@ dependencies = [ "dirs-sys 0.4.1", ] +[[package]] +name = "dirs" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" +dependencies = [ + "dirs-sys 0.5.0", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -1899,7 +1908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", - "redox_users", + "redox_users 0.4.6", "winapi", ] @@ -1911,10 +1920,22 @@ checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" dependencies = [ "libc", "option-ext", - "redox_users", + "redox_users 0.4.6", "windows-sys 0.48.0", ] +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users 0.5.0", + "windows-sys 0.59.0", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1922,7 +1943,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", - "redox_users", + "redox_users 0.4.6", "winapi", ] @@ -2098,7 +2119,7 @@ dependencies = [ "cc", "memchr", "rustc_version", - "toml 0.8.2", + "toml 0.8.20", "vswhom", "winreg 0.52.0", ] @@ -2336,6 +2357,15 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "file-id" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bc904b9bbefcadbd8e3a9fb0d464a9b979de6324c03b3c663e8994f46a5be36" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "filetime" version = "0.2.25" @@ -2439,6 +2469,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + [[package]] name = "funty" version = "2.0.0" @@ -2720,6 +2759,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.13.3+wasi-0.2.2", + "windows-targets 0.52.6", +] + [[package]] name = "ghash" version = "0.5.1" @@ -2808,7 +2859,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" dependencies = [ "heck 0.4.1", - "proc-macro-crate 2.0.2", + "proc-macro-crate 2.0.0", "proc-macro-error", "proc-macro2", "quote", @@ -3769,6 +3820,26 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + [[package]] name = "kuchikiki" version = "0.8.2" @@ -4263,6 +4334,7 @@ checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ "hermit-abi 0.3.9", "libc", + "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.52.0", ] @@ -4448,6 +4520,38 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" +[[package]] +name = "notify" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c533b4c39709f9ba5005d8002048266593c1cfaf3c5f0739d5b8ab0c6c504009" +dependencies = [ + "bitflags 2.6.0", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio 1.0.2", + "notify-types", + "walkdir", + "windows-sys 0.52.0", +] + +[[package]] +name = "notify-debouncer-full" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dcf855483228259b2353f89e99df35fc639b2b2510d1166e4858e3f67ec1afb" +dependencies = [ + "file-id", + "log", + "notify", + "notify-types", + "walkdir", +] + [[package]] name = "notify-rust" version = "4.11.3" @@ -4461,6 +4565,16 @@ dependencies = [ "zbus", ] +[[package]] +name = "notify-types" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585d3cb5e12e01aed9e8a1f70d5c6b5e86fe2a6e48fc8cd0b3e0b8df6f6eb174" +dependencies = [ + "instant", + "serde", +] + [[package]] name = "ntapi" version = "0.4.1" @@ -4596,7 +4710,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 2.0.2", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.87", @@ -5419,11 +5533,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", "toml_edit 0.20.2", ] @@ -5892,6 +6005,17 @@ dependencies = [ "thiserror 1.0.66", ] +[[package]] +name = "redox_users" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" +dependencies = [ + "getrandom 0.2.15", + "libredox", + "thiserror 2.0.3", +] + [[package]] name = "regex" version = "1.11.1" @@ -7161,15 +7285,15 @@ dependencies = [ "cfg-expr", "heck 0.5.0", "pkg-config", - "toml 0.8.2", + "toml 0.8.20", "version-compare", ] [[package]] name = "tao" -version = "0.30.8" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6682a07cf5bab0b8a2bd20d0a542917ab928b5edb75ebd4eda6b05cbaab872da" +checksum = "3731d04d4ac210cd5f344087733943b9bfb1a32654387dad4d1c70de21aee2c9" dependencies = [ "bitflags 2.6.0", "cocoa 0.26.0", @@ -7182,7 +7306,6 @@ dependencies = [ "gdkwayland-sys", "gdkx11-sys", "gtk", - "instant", "jni", "lazy_static", "libc", @@ -7240,13 +7363,13 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tauri" -version = "2.1.1" +version = "2.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e545de0a2dfe296fa67db208266cd397c5a55ae782da77973ef4c4fac90e9f2c" +checksum = "58a998b6be84104ca05c7e9a21f2180ddec020c8b84ea59a8fc8530a2a19588d" dependencies = [ "anyhow", "bytes", - "dirs 5.0.1", + "dirs 6.0.0", "dunce", "embed_plist", "futures-util", @@ -7291,9 +7414,9 @@ dependencies = [ [[package]] name = "tauri-build" -version = "2.0.3" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd2a4bcfaf5fb9f4be72520eefcb61ae565038f8ccba2a497d8c28f463b8c01" +checksum = "8e950124f6779c6cf98e3260c7a6c8488a74aa6350dd54c6950fdaa349bca2df" dependencies = [ "anyhow", "cargo_toml", @@ -7307,15 +7430,15 @@ dependencies = [ "serde_json", "tauri-utils", "tauri-winres", - "toml 0.8.2", + "toml 0.8.20", "walkdir", ] [[package]] name = "tauri-codegen" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf79faeecf301d3e969b1fae977039edb77a4c1f25cc0a961be298b54bff97cf" +checksum = "f77894f9ddb5cb6c04fcfe8c8869ebe0aded4dabf19917118d48be4a95599ab5" dependencies = [ "base64 0.22.1", "brotli", @@ -7350,9 +7473,9 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52027c8c5afb83166dacddc092ee8fff50772f9646d461d8c33ee887e447a03" +checksum = "3240a5caed760a532e8f687be6f05b2c7d11a1d791fb53ccc08cfeb3e5308736" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -7375,7 +7498,7 @@ dependencies = [ "serde", "serde_json", "tauri-utils", - "toml 0.8.2", + "toml 0.8.20", "walkdir", ] @@ -7470,6 +7593,8 @@ dependencies = [ "anyhow", "dunce", "glob", + "notify", + "notify-debouncer-full", "percent-encoding", "schemars", "serde", @@ -7479,7 +7604,7 @@ dependencies = [ "tauri-plugin", "tauri-utils", "thiserror 2.0.3", - "toml 0.8.2", + "toml 0.8.20", "url", "uuid", ] @@ -7501,9 +7626,9 @@ dependencies = [ [[package]] name = "tauri-plugin-http" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e62a9bde54d6a0218b63f5a248f02056ad4316ba6ad81dfb9e4f73715df5deb1" +checksum = "3a8137a106e0741fdd357366178fc6e0597abe7d20796f53f44171a1bcec1683" dependencies = [ "data-url", "http 1.1.0", @@ -7594,16 +7719,16 @@ dependencies = [ [[package]] name = "tauri-plugin-log" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eddd784c138c08a43954bc3e735402e6b2b2ee8d8c254a7391f4e77c01273dd5" +checksum = "367a28a5e0ca39eac98005699466e8906edc4a2a8f8e13a5f1a71dc0bea6c677" dependencies = [ "android_logger", "byte-unit", - "cocoa 0.26.0", "fern", "log", - "objc", + "objc2", + "objc2-foundation", "serde", "serde_json", "serde_repr", @@ -7634,9 +7759,9 @@ dependencies = [ [[package]] name = "tauri-plugin-notification" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46ab803095f14ac6521fdb6477210a49e86fed6623c3c97d8e4b2b35e045e922" +checksum = "0f8d3ee5207d3359ca2b714545664f24f70374d795bf91f7c1935a494003a57d" dependencies = [ "log", "notify-rust", @@ -7851,9 +7976,9 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce18d43f80d4aba3aa8a0c953bbe835f3d0f2370aca75e8dbb14bd4bab27958" +checksum = "2274ef891ccc0a8d318deffa9d70053f947664d12d58b9c0d1ae5e89237e01f7" dependencies = [ "dpi", "gtk", @@ -7870,9 +7995,9 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f442a38863e10129ffe2cec7bd09c2dcf8a098a3a27801a476a304d5bb991d2" +checksum = "3707b40711d3b9f6519150869e358ffbde7c57567fb9b5a8b51150606939b2a0" dependencies = [ "gtk", "http 1.1.0", @@ -7896,9 +8021,9 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9271a88f99b4adea0dc71d0baca4505475a0bbd139fb135f62958721aaa8fe54" +checksum = "96fb10e7cc97456b2d5b9c03e335b5de5da982039a303a20d10006885e4523a0" dependencies = [ "brotli", "cargo_metadata", @@ -7924,7 +8049,7 @@ dependencies = [ "serde_with", "swift-rs", "thiserror 2.0.3", - "toml 0.8.2", + "toml 0.8.20", "url", "urlpattern", "uuid", @@ -8209,21 +8334,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.2" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.20.2", + "toml_edit 0.22.24", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] @@ -8238,7 +8363,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.5.40", ] [[package]] @@ -8246,12 +8371,23 @@ name = "toml_edit" version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.6.0", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ "indexmap 2.6.0", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.7.3", ] [[package]] @@ -8628,11 +8764,11 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.11.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" +checksum = "93d59ca99a559661b96bf898d8fce28ed87935fd2bea9f05983c1464dd6c71b1" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.3.1", "serde", ] @@ -8742,6 +8878,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.13.3+wasi-0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasm-bindgen" version = "0.2.95" @@ -8947,9 +9092,9 @@ dependencies = [ [[package]] name = "webview2-com" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61ff3d9d0ee4efcb461b14eb3acfda2702d10dc329f339303fc3e57215ae2c" +checksum = "823e7ebcfaea51e78f72c87fc3b65a1e602c321f407a0b36dbb327d7bb7cd921" dependencies = [ "webview2-com-macros", "webview2-com-sys", @@ -8972,9 +9117,9 @@ dependencies = [ [[package]] name = "webview2-com-sys" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3a3e2eeb58f82361c93f9777014668eb3d07e7d174ee4c819575a9208011886" +checksum = "7a82bce72db6e5ee83c68b5de1e2cd6ea195b9fbff91cb37df5884cbe3222df4" dependencies = [ "thiserror 1.0.66", "windows 0.58.0", @@ -9507,6 +9652,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7f4ea97f6f78012141bcdb6a216b2609f0979ada50b20ca5b52dde2eac2bb1" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.10.1" @@ -9537,10 +9691,19 @@ dependencies = [ ] [[package]] -name = "wry" -version = "0.47.0" +name = "wit-bindgen-rt" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "553ca1ce149982123962fac2506aa75b8b76288779a77e72b12fa2fc34938647" +checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" +dependencies = [ + "bitflags 2.6.0", +] + +[[package]] +name = "wry" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2e33c08b174442ff80d5c791020696f9f8b4e4a87b8cfc7494aad6167ec44e1" dependencies = [ "base64 0.22.1", "block2", @@ -9568,7 +9731,7 @@ dependencies = [ "sha2", "soup3", "tao-macros", - "thiserror 1.0.66", + "thiserror 2.0.3", "url", "webkit2gtk", "webkit2gtk-sys", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 7b6b186..431c82d 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -14,10 +14,10 @@ name = "kunkun_lib" crate-type = ["staticlib", "cdylib", "rlib"] [build-dependencies] -tauri-build = { version = "2.0.3", features = [] } +tauri-build = { version = "2.0.5", features = [] } [dependencies] -tauri = { version = "2.1.1", features = [ +tauri = { version = "2.2.5", features = [ "macos-private-api", "image-png", "image-ico", @@ -35,11 +35,11 @@ log = { workspace = true } urlencoding = "2.1.3" tauri-plugin-process = "2.2.0" tauri-plugin-shellx = "2.0.12" -tauri-plugin-fs = "2.2.0" +tauri-plugin-fs = { version = "2.2.0", features = ["watch"] } tauri-plugin-dialog = "2.2.0" -tauri-plugin-notification = "2.2.0" +tauri-plugin-notification = "2.2.1" tauri-plugin-os = "2.2.0" -tauri-plugin-http = "2.2.0" +tauri-plugin-http = "2.3.0" tauri-plugin-upload = { workspace = true } # tauri-plugin-upload = "2.2.1" tauri-plugin-jarvis = { workspace = true } @@ -50,10 +50,10 @@ tauri-plugin-user-input = { workspace = true } tauri-plugin-clipboard = { workspace = true } tauri-plugin-store = "2.2.0" tauri-plugin-deep-link = "2.2.0" -tauri-plugin-log = { version = "2.2.0", features = ["colored"] } +tauri-plugin-log = { version = "2.2.1", features = ["colored"] } crypto = { workspace = true } zip = "2.2.2" -uuid = "1.11.0" +uuid = "1.14.0" # tauri-plugin-devtools = "2.0.0" obfstr = { workspace = true } base64 = { workspace = true } diff --git a/apps/desktop/src/lib/stores/extensions.ts b/apps/desktop/src/lib/stores/extensions.ts index e3bd0c7..d1da587 100644 --- a/apps/desktop/src/lib/stores/extensions.ts +++ b/apps/desktop/src/lib/stores/extensions.ts @@ -29,6 +29,7 @@ function createExtensionsStore(): Writable & { tarballUrl: string, extras?: { overwritePackageJson?: string } ) => Promise + reloadExtension: (extPath: string) => Promise } { const store = writable([]) @@ -42,6 +43,22 @@ function createExtensionsStore(): Writable & { }) } + // if dev extension's package.json is changed, use this function to reload commands + async function reloadExtension(extPath: string) { + const ext = get(extensions).find((ext) => ext.extPath === extPath) + if (ext) { + const pkgJsonPath = await path.join(extPath, "package.json") + const ext = await extAPI.loadExtensionManifestFromDisk(pkgJsonPath) + // replace the old extension with the new one + store.update((exts) => { + // filter out the old extension + return [...exts.filter((e) => e.extPath !== extPath), ext] + }) + } else { + console.warn(`reloadExtension: Extension ${extPath} not found`) + } + } + /** * Get all extensions installed from the store (non-dev extensions) */ @@ -195,6 +212,7 @@ function createExtensionsStore(): Writable & { return { ...store, init, + reloadExtension, getExtensionsFromStore, findStoreExtensionByIdentifier, registerNewExtensionByPath, diff --git a/apps/desktop/src/lib/types/fs.ts b/apps/desktop/src/lib/types/fs.ts new file mode 100644 index 0000000..1204098 --- /dev/null +++ b/apps/desktop/src/lib/types/fs.ts @@ -0,0 +1,12 @@ +import * as v from "valibot" + +export const WatchEvent = v.object({ + type: v.object({ + modify: v.object({ + kind: v.union([v.literal("data"), v.literal("metadata")]), + mode: v.union([v.literal("any"), v.literal("content")]) + }) + }), + paths: v.array(v.string()) +}) +export type WatchEvent = v.InferOutput diff --git a/apps/desktop/src/lib/utils/init.ts b/apps/desktop/src/lib/utils/init.ts index 85480d0..bd8751c 100644 --- a/apps/desktop/src/lib/utils/init.ts +++ b/apps/desktop/src/lib/utils/init.ts @@ -1,8 +1,9 @@ -import { appConfig } from "@/stores" +import { appConfig, extensions } from "@/stores" import { getCurrentWindow } from "@tauri-apps/api/window" import { info } from "@tauri-apps/plugin-log" import { dev } from "$app/environment" import { mapKeyToTauriKey, registerAppHotkey } from "./hotkey" +import { listenToReloadOneExtension } from "./tauri-events" /** * Initialize the app @@ -11,6 +12,10 @@ export function init() { const window = getCurrentWindow() if (window.label === "main") { initMainWindow() + listenToReloadOneExtension(({ payload: { extPath } }) => { + info(`listenToReloadOneExtension in main window: ${extPath}`) + extensions.reloadExtension(extPath) + }) } if (!dev) { diff --git a/apps/desktop/src/lib/utils/tauri-events.ts b/apps/desktop/src/lib/utils/tauri-events.ts index 1102342..8350ef4 100644 --- a/apps/desktop/src/lib/utils/tauri-events.ts +++ b/apps/desktop/src/lib/utils/tauri-events.ts @@ -16,6 +16,8 @@ export const FileDragOver = "tauri://drag-over" export const NewClipboardItemAddedEvent = "new_clipboard_item_added" export const RefreshConfigEvent = "kunkun://refresh-config" export const RefreshExtEvent = "kunkun://refresh-extensions" +export const ReloadOneExtensionEvent = "kunkun://reload-one-extension" + export function listenToFileDrop(cb: EventCallback<{ paths: string[] }>) { return listen<{ paths: string[] }>(FileDragDrop, cb) } @@ -55,3 +57,11 @@ export function emitRefreshDevExt() { export function listenToRefreshDevExt(cb: EventCallback) { return listen(DEEP_LINK_PATH_REFRESH_DEV_EXTENSION, cb) } + +export function emitReloadOneExtension(extPath: string) { + return emitTo("main", ReloadOneExtensionEvent, { extPath }) +} + +export function listenToReloadOneExtension(cb: EventCallback<{ extPath: string }>) { + return listen(ReloadOneExtensionEvent, cb) +} diff --git a/apps/desktop/src/routes/app/extension/ui-worker/+page.svelte b/apps/desktop/src/routes/app/extension/ui-worker/+page.svelte index cb6810f..d5bbbaf 100644 --- a/apps/desktop/src/routes/app/extension/ui-worker/+page.svelte +++ b/apps/desktop/src/routes/app/extension/ui-worker/+page.svelte @@ -3,8 +3,13 @@ import { appState } from "@/stores/appState.js" import { keys } from "@/stores/keys" import { winExtMap } from "@/stores/winExtMap.js" + import { WatchEvent } from "@/types/fs.js" import { helperAPI } from "@/utils/helper.js" - import { listenToFileDrop, listenToRefreshDevExt } from "@/utils/tauri-events.js" + import { + emitReloadOneExtension, + listenToFileDrop, + listenToRefreshDevExt + } from "@/utils/tauri-events.js" import { isInMainWindow } from "@/utils/window.js" import { db } from "@kksh/api/commands" import { @@ -28,6 +33,7 @@ import type { IKunkunFullServerAPI } from "@kunkunapi/src/api/server" import type { UnlistenFn } from "@tauri-apps/api/event" import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow" + import * as fs from "@tauri-apps/plugin-fs" import { readTextFile } from "@tauri-apps/plugin-fs" import { debug } from "@tauri-apps/plugin-log" import { platform } from "@tauri-apps/plugin-os" @@ -57,6 +63,7 @@ let loaded = $state(false) let listview: Templates.ListView | undefined = $state(undefined) const _platform = platform() + let unlistenPkgJsonWatch: UnlistenFn | undefined async function goBack() { if (isInMainWindow()) { @@ -242,6 +249,22 @@ worker?.terminate() } }) + + function onPkgJsonChange(evt: fs.WatchEvent) { + const parsed = v.safeParse(WatchEvent, evt) + if (parsed.success) { + if ( + parsed.output.type.modify.kind === "data" && + parsed.output.type.modify.mode === "content" && + parsed.output.paths.includes(data.pkgJsonPath) + ) { + console.log("pkgJson changed", parsed.output.paths) + // emit event to reload extension commands + emitReloadOneExtension(loadedExt.extPath) + } + } + } + onMount(async () => { setTimeout(() => { appState.setLoadingBar(true) @@ -261,11 +284,16 @@ appState.setLoadingBar(false) loaded = true }, 500) + console.log("watching", data.pkgJsonPath) + fs.watch(data.pkgJsonPath, onPkgJsonChange).then((unlisten) => { + unlistenPkgJsonWatch = unlisten + }) }) onDestroy(() => { unlistenRefreshWorkerExt?.() unlistenFileDrop?.() + unlistenPkgJsonWatch?.() winExtMap.unregisterExtensionFromWindow(appWin.label) extensionLoadingBar = false appState.setActionPanel(undefined)