From b351c38e88e61dc68312829f385afc93df2648fc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 7 Jan 2023 19:34:36 +0000 Subject: [PATCH 1/3] fix(deps): update rust crate notify to v5 --- Cargo.lock | 244 +++++++++++------------------------- plugins/fs-watch/Cargo.toml | 2 +- 2 files changed, 71 insertions(+), 175 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85718b5a..fd37b042 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cipher", "cpufeatures", "opaque-debug", @@ -158,7 +158,7 @@ dependencies = [ "log", "rand 0.7.3", "runloop", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -393,12 +393,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -411,7 +405,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cipher", "cpufeatures", "zeroize", @@ -442,7 +436,7 @@ dependencies = [ "num-traits", "time 0.1.45", "wasm-bindgen", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -606,7 +600,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -615,7 +609,7 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-utils", ] @@ -625,7 +619,7 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-utils", ] @@ -635,7 +629,7 @@ version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -871,7 +865,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "dirs-sys-next", ] @@ -883,7 +877,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -894,7 +888,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -962,7 +956,7 @@ version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1005,7 +999,7 @@ version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall", "windows-sys 0.42.0", @@ -1063,41 +1057,15 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fsevent" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" -dependencies = [ - "bitflags", - "fsevent-sys", -] - [[package]] name = "fsevent-sys" -version = "2.0.1" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" dependencies = [ "libc", ] -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futf" version = "0.1.5" @@ -1318,7 +1286,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -1329,7 +1297,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", @@ -1373,7 +1341,7 @@ dependencies = [ "gobject-sys", "libc", "system-deps 6.0.3", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1696,7 +1664,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1787,9 +1755,9 @@ dependencies = [ [[package]] name = "inotify" -version = "0.7.1" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" dependencies = [ "bitflags", "inotify-sys", @@ -1811,7 +1779,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1958,13 +1926,23 @@ dependencies = [ ] [[package]] -name = "kernel32-sys" -version = "0.2.2" +name = "kqueue" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +checksum = "2c8fc60ba15bf51257aa9807a48a61013db043fcf3a78cb0d916e8e396dcad98" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587" +dependencies = [ + "bitflags", + "libc", ] [[package]] @@ -1988,12 +1966,6 @@ dependencies = [ "spin 0.5.2", ] -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libappindicator" version = "0.7.1" @@ -2030,8 +2002,8 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ - "cfg-if 1.0.0", - "winapi 0.3.9", + "cfg-if", + "winapi", ] [[package]] @@ -2117,7 +2089,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "value-bag", ] @@ -2127,7 +2099,7 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "generator", "scoped-tls", "serde", @@ -2225,25 +2197,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.8.5" @@ -2256,30 +2209,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "mio-extras" -version = "2.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" -dependencies = [ - "lazycell", - "log", - "mio 0.6.23", - "slab", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - [[package]] name = "native-tls" version = "0.2.11" @@ -2326,17 +2255,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "net2" -version = "0.2.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d0df99cfcd2530b2e694f6e17e7f37b8e26bb23983ac530c0c97408837c631" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "new_debug_unreachable" version = "1.0.4" @@ -2350,7 +2268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "libc", "memoffset", ] @@ -2373,20 +2291,20 @@ dependencies = [ [[package]] name = "notify" -version = "4.0.17" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" +checksum = "ed2c66da08abae1c024c01d635253e402341b4060a12e99b31c7594063bf490a" dependencies = [ "bitflags", + "crossbeam-channel", "filetime", - "fsevent", "fsevent-sys", "inotify", + "kqueue", "libc", - "mio 0.6.23", - "mio-extras", + "mio", "walkdir", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2396,7 +2314,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" dependencies = [ "overload", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2547,7 +2465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "foreign-types", "libc", "once_cell", @@ -2643,12 +2561,12 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "instant", "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2657,7 +2575,7 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall", "smallvec", @@ -2905,7 +2823,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "opaque-debug", "universal-hash", @@ -3141,7 +3059,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3194,7 +3112,7 @@ dependencies = [ "spin 0.5.2", "untrusted", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3535,7 +3453,7 @@ version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.10.6", ] @@ -3547,7 +3465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer 0.9.0", - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.9.0", "opaque-debug", @@ -3559,7 +3477,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.10.6", ] @@ -3601,7 +3519,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -4346,12 +4264,12 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "fastrand", "libc", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -4417,7 +4335,7 @@ checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -4484,7 +4402,7 @@ dependencies = [ "bytes 1.3.0", "libc", "memchr", - "mio 0.8.5", + "mio", "num_cpus", "pin-project-lite", "socket2", @@ -4572,7 +4490,7 @@ version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -4848,7 +4766,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -4886,7 +4804,7 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -4911,7 +4829,7 @@ version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -5071,12 +4989,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -5087,12 +4999,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -5105,7 +5011,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5309,7 +5215,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5350,16 +5256,6 @@ dependencies = [ "windows-implement", ] -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "x11" version = "2.20.1" diff --git a/plugins/fs-watch/Cargo.toml b/plugins/fs-watch/Cargo.toml index 89501ac8..b3dbd942 100644 --- a/plugins/fs-watch/Cargo.toml +++ b/plugins/fs-watch/Cargo.toml @@ -15,4 +15,4 @@ serde_json.workspace = true tauri.workspace = true log.workspace = true thiserror.workspace = true -notify = "4.0" \ No newline at end of file +notify = "5.0" \ No newline at end of file From 24b09c385e63260692d4eaf11ac74afcd4610ff2 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Sat, 7 Jan 2023 22:25:44 +0100 Subject: [PATCH 2/3] adapt plugin to notify v5 --- Cargo.lock | 13 +++ plugins/fs-watch/Cargo.toml | 3 +- plugins/fs-watch/guest-js/index.ts | 173 ++++++++++++++--------------- plugins/fs-watch/src/lib.rs | 99 ++++++----------- 4 files changed, 132 insertions(+), 156 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd37b042..1ff0a30b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2303,10 +2303,22 @@ dependencies = [ "kqueue", "libc", "mio", + "serde", "walkdir", "winapi", ] +[[package]] +name = "notify-debouncer-mini" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e23e9fa24f094b143c1eb61f90ac6457de87be6987bc70746e0179f7dbc9007b" +dependencies = [ + "crossbeam-channel", + "notify", + "serde", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -4048,6 +4060,7 @@ version = "0.1.0" dependencies = [ "log", "notify", + "notify-debouncer-mini", "serde", "serde_json", "tauri", diff --git a/plugins/fs-watch/Cargo.toml b/plugins/fs-watch/Cargo.toml index b3dbd942..b8f648a9 100644 --- a/plugins/fs-watch/Cargo.toml +++ b/plugins/fs-watch/Cargo.toml @@ -15,4 +15,5 @@ serde_json.workspace = true tauri.workspace = true log.workspace = true thiserror.workspace = true -notify = "5.0" \ No newline at end of file +notify = { version = "5.0" , features = ["serde"] } +notify-debouncer-mini = { version = "0.2.1" , features = ["serde"] } diff --git a/plugins/fs-watch/guest-js/index.ts b/plugins/fs-watch/guest-js/index.ts index bb16c2c9..0fb7eb24 100644 --- a/plugins/fs-watch/guest-js/index.ts +++ b/plugins/fs-watch/guest-js/index.ts @@ -1,110 +1,103 @@ -import { invoke } from "@tauri-apps/api/tauri"; -import { UnlistenFn } from "@tauri-apps/api/event"; -import { appWindow, WebviewWindow } from "@tauri-apps/api/window"; +import { invoke } from '@tauri-apps/api/tauri'; +import { UnlistenFn } from '@tauri-apps/api/event'; +import { appWindow, WebviewWindow } from '@tauri-apps/api/window'; const w: WebviewWindow = appWindow; export interface WatchOptions { - recursive?: boolean; + recursive?: boolean; } export interface DebouncedWatchOptions extends WatchOptions { - delayMs?: number; + delayMs?: number; } -export interface RawEvent { - path: string | null; - operation: number; - cookie: number | null; -} - -export type DebouncedEvent = - | { type: "NoticeWrite"; payload: string } - | { type: "NoticeRemove"; payload: string } - | { type: "Create"; payload: string } - | { type: "Write"; payload: string } - | { type: "Chmod"; payload: string } - | { type: "Remove"; payload: string } - | { type: "Rename"; payload: string } - | { type: "Rescan"; payload: null } - | { type: "Error"; payload: { error: string; path: string | null } }; +export type RawEvent = { + type: RawEventKind; + paths: string[]; + attrs: unknown; +}; + +type RawEventKind = + | 'any ' + | { + access?: unknown; + } + | { + create?: unknown; + } + | { + modify?: unknown; + } + | { + remove?: unknown; + } + | 'other'; + +export type DebouncedEvent = { kind: 'any'; path: string } | { kind: 'AnyContinous'; path: string }; async function unwatch(id: number): Promise { - await invoke("plugin:fs-watch|unwatch", { id }); + await invoke('plugin:fs-watch|unwatch', { id }); } -export async function watch( - paths: string | string[], - options: DebouncedWatchOptions, - cb: (event: DebouncedEvent) => void -): Promise { - const opts = { - recursive: false, - delayMs: 2000, - ...options, - }; - let watchPaths; - if (typeof paths === "string") { - watchPaths = [paths]; - } else { - watchPaths = paths; - } - - const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; - - await invoke("plugin:fs-watch|watch", { - id, - paths: watchPaths, - options: opts, - }); - - const unlisten = await w.listen( - `watcher://debounced-event/${id}`, - (event) => { - cb(event.payload); +export async function watch(paths: string | string[], options: DebouncedWatchOptions, cb: (event: DebouncedEvent) => void): Promise { + const opts = { + recursive: false, + delayMs: 2000, + ...options, + }; + let watchPaths; + if (typeof paths === 'string') { + watchPaths = [paths]; + } else { + watchPaths = paths; } - ); - return () => { - void unwatch(id); - unlisten(); - }; + const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; + + await invoke('plugin:fs-watch|watch', { + id, + paths: watchPaths, + options: opts, + }); + + const unlisten = await w.listen(`watcher://debounced-event/${id}`, (event) => { + cb(event.payload); + }); + + return () => { + void unwatch(id); + unlisten(); + }; } -export async function watchImmediate( - paths: string | string[], - options: WatchOptions, - cb: (event: RawEvent) => void -): Promise { - const opts = { - recursive: false, - ...options, - delayMs: null, - }; - let watchPaths; - if (typeof paths === "string") { - watchPaths = [paths]; - } else { - watchPaths = paths; - } - - const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; - - await invoke("plugin:fs-watch|watch", { - id, - paths: watchPaths, - options: opts, - }); - - const unlisten = await w.listen( - `watcher://raw-event/${id}`, - (event) => { - cb(event.payload); +export async function watchImmediate(paths: string | string[], options: WatchOptions, cb: (event: RawEvent) => void): Promise { + const opts = { + recursive: false, + ...options, + delayMs: null, + }; + let watchPaths; + if (typeof paths === 'string') { + watchPaths = [paths]; + } else { + watchPaths = paths; } - ); - return () => { - void unwatch(id); - unlisten(); - }; + const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; + + await invoke('plugin:fs-watch|watch', { + id, + paths: watchPaths, + options: opts, + }); + + const unlisten = await w.listen(`watcher://raw-event/${id}`, (event) => { + cb(event.payload); + }); + + return () => { + void unwatch(id); + unlisten(); + }; } diff --git a/plugins/fs-watch/src/lib.rs b/plugins/fs-watch/src/lib.rs index 790507b7..c022b253 100644 --- a/plugins/fs-watch/src/lib.rs +++ b/plugins/fs-watch/src/lib.rs @@ -1,7 +1,5 @@ -use notify::{ - raw_watcher, watcher, DebouncedEvent, Op, RawEvent, RecommendedWatcher, RecursiveMode, - Watcher as _, -}; +use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher}; +use notify_debouncer_mini::{new_debouncer, DebounceEventResult, Debouncer}; use serde::{ser::Serializer, Deserialize, Serialize}; use tauri::{ command, @@ -39,72 +37,33 @@ impl Serialize for Error { } #[derive(Default)] -struct WatcherCollection(Mutex)>>); +struct WatcherCollection(Mutex)>>); -#[derive(Clone, Serialize)] -struct RawEventWrapper { - path: Option, - operation: u32, - cookie: Option, +enum WatcherKind { + Debouncer(Debouncer), + Watcher(RecommendedWatcher), } -#[derive(Clone, Serialize)] -#[serde(tag = "type", content = "payload")] -enum DebouncedEventWrapper { - NoticeWrite(PathBuf), - NoticeRemove(PathBuf), - Create(PathBuf), - Write(PathBuf), - Chmod(PathBuf), - Remove(PathBuf), - Rename(PathBuf, PathBuf), - Rescan, - Error { - error: String, - path: Option, - }, -} - -impl From for DebouncedEventWrapper { - fn from(event: DebouncedEvent) -> Self { - match event { - DebouncedEvent::NoticeWrite(path) => Self::NoticeWrite(path), - DebouncedEvent::NoticeRemove(path) => Self::NoticeRemove(path), - DebouncedEvent::Create(path) => Self::Create(path), - DebouncedEvent::Write(path) => Self::Write(path), - DebouncedEvent::Chmod(path) => Self::Chmod(path), - DebouncedEvent::Remove(path) => Self::Remove(path), - DebouncedEvent::Rename(from, to) => Self::Rename(from, to), - DebouncedEvent::Rescan => Self::Rescan, - DebouncedEvent::Error(error, path) => Self::Error { - error: error.to_string(), - path, - }, - } - } -} - -fn watch_raw(window: Window, rx: Receiver, id: Id) { +fn watch_raw(window: Window, rx: Receiver>, id: Id) { spawn(move || { let event_name = format!("watcher://raw-event/{}", id); while let Ok(event) = rx.recv() { - let _ = window.emit( - &event_name, - RawEventWrapper { - path: event.path, - operation: event.op.unwrap_or_else(|_| Op::empty()).bits(), - cookie: event.cookie, - }, - ); + if let Ok(event) = event { + // TODO: Should errors be emitted too? + let _ = window.emit(&event_name, event); + } } }); } -fn watch_debounced(window: Window, rx: Receiver, id: Id) { +fn watch_debounced(window: Window, rx: Receiver, id: Id) { spawn(move || { let event_name = format!("watcher://debounced-event/{}", id); while let Ok(event) = rx.recv() { - let _ = window.emit(&event_name, DebouncedEventWrapper::from(event)); + if let Ok(event) = event { + // TODO: Should errors be emitted too? + let _ = window.emit(&event_name, event); + } } }); } @@ -132,20 +91,21 @@ async fn watch( let watcher = if let Some(delay) = options.delay_ms { let (tx, rx) = channel(); - let mut watcher = watcher(tx, Duration::from_millis(delay))?; + let mut debouncer = new_debouncer(Duration::from_millis(delay), None, tx)?; + let watcher = debouncer.watcher(); for path in &paths { watcher.watch(path, mode)?; } watch_debounced(window, rx, id); - watcher + WatcherKind::Debouncer(debouncer) } else { let (tx, rx) = channel(); - let mut watcher = raw_watcher(tx)?; + let mut watcher = RecommendedWatcher::new(tx, Config::default())?; for path in &paths { watcher.watch(path, mode)?; } watch_raw(window, rx, id); - watcher + WatcherKind::Watcher(watcher) }; watchers.0.lock().unwrap().insert(id, (watcher, paths)); @@ -155,10 +115,19 @@ async fn watch( #[command] async fn unwatch(watchers: State<'_, WatcherCollection>, id: Id) -> Result<()> { - if let Some((mut watcher, paths)) = watchers.0.lock().unwrap().remove(&id) { - for path in paths { - watcher.unwatch(path)?; - } + if let Some((watcher, paths)) = watchers.0.lock().unwrap().remove(&id) { + match watcher { + WatcherKind::Debouncer(mut debouncer) => { + for path in paths { + debouncer.watcher().unwatch(&path)? + } + } + WatcherKind::Watcher(mut watcher) => { + for path in paths { + watcher.unwatch(&path)? + } + } + }; } Ok(()) } From ea5fb0013c0507ff082a94352645efcc51d321f7 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Sat, 7 Jan 2023 22:28:10 +0100 Subject: [PATCH 3/3] fmt --- plugins/fs-watch/guest-js/index.ts | 174 ++++++++++++++++------------- 1 file changed, 95 insertions(+), 79 deletions(-) diff --git a/plugins/fs-watch/guest-js/index.ts b/plugins/fs-watch/guest-js/index.ts index 0fb7eb24..31d333b2 100644 --- a/plugins/fs-watch/guest-js/index.ts +++ b/plugins/fs-watch/guest-js/index.ts @@ -1,103 +1,119 @@ -import { invoke } from '@tauri-apps/api/tauri'; -import { UnlistenFn } from '@tauri-apps/api/event'; -import { appWindow, WebviewWindow } from '@tauri-apps/api/window'; +import { invoke } from "@tauri-apps/api/tauri"; +import { UnlistenFn } from "@tauri-apps/api/event"; +import { appWindow, WebviewWindow } from "@tauri-apps/api/window"; const w: WebviewWindow = appWindow; export interface WatchOptions { - recursive?: boolean; + recursive?: boolean; } export interface DebouncedWatchOptions extends WatchOptions { - delayMs?: number; + delayMs?: number; } export type RawEvent = { - type: RawEventKind; - paths: string[]; - attrs: unknown; + type: RawEventKind; + paths: string[]; + attrs: unknown; }; type RawEventKind = - | 'any ' - | { - access?: unknown; - } - | { - create?: unknown; - } - | { - modify?: unknown; - } - | { - remove?: unknown; - } - | 'other'; - -export type DebouncedEvent = { kind: 'any'; path: string } | { kind: 'AnyContinous'; path: string }; + | "any " + | { + access?: unknown; + } + | { + create?: unknown; + } + | { + modify?: unknown; + } + | { + remove?: unknown; + } + | "other"; + +export type DebouncedEvent = + | { kind: "any"; path: string } + | { kind: "AnyContinous"; path: string }; async function unwatch(id: number): Promise { - await invoke('plugin:fs-watch|unwatch', { id }); + await invoke("plugin:fs-watch|unwatch", { id }); } -export async function watch(paths: string | string[], options: DebouncedWatchOptions, cb: (event: DebouncedEvent) => void): Promise { - const opts = { - recursive: false, - delayMs: 2000, - ...options, - }; - let watchPaths; - if (typeof paths === 'string') { - watchPaths = [paths]; - } else { - watchPaths = paths; +export async function watch( + paths: string | string[], + options: DebouncedWatchOptions, + cb: (event: DebouncedEvent) => void +): Promise { + const opts = { + recursive: false, + delayMs: 2000, + ...options, + }; + let watchPaths; + if (typeof paths === "string") { + watchPaths = [paths]; + } else { + watchPaths = paths; + } + + const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; + + await invoke("plugin:fs-watch|watch", { + id, + paths: watchPaths, + options: opts, + }); + + const unlisten = await w.listen( + `watcher://debounced-event/${id}`, + (event) => { + cb(event.payload); } + ); - const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; - - await invoke('plugin:fs-watch|watch', { - id, - paths: watchPaths, - options: opts, - }); - - const unlisten = await w.listen(`watcher://debounced-event/${id}`, (event) => { - cb(event.payload); - }); - - return () => { - void unwatch(id); - unlisten(); - }; + return () => { + void unwatch(id); + unlisten(); + }; } -export async function watchImmediate(paths: string | string[], options: WatchOptions, cb: (event: RawEvent) => void): Promise { - const opts = { - recursive: false, - ...options, - delayMs: null, - }; - let watchPaths; - if (typeof paths === 'string') { - watchPaths = [paths]; - } else { - watchPaths = paths; +export async function watchImmediate( + paths: string | string[], + options: WatchOptions, + cb: (event: RawEvent) => void +): Promise { + const opts = { + recursive: false, + ...options, + delayMs: null, + }; + let watchPaths; + if (typeof paths === "string") { + watchPaths = [paths]; + } else { + watchPaths = paths; + } + + const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; + + await invoke("plugin:fs-watch|watch", { + id, + paths: watchPaths, + options: opts, + }); + + const unlisten = await w.listen( + `watcher://raw-event/${id}`, + (event) => { + cb(event.payload); } + ); - const id = window.crypto.getRandomValues(new Uint32Array(1))[0]; - - await invoke('plugin:fs-watch|watch', { - id, - paths: watchPaths, - options: opts, - }); - - const unlisten = await w.listen(`watcher://raw-event/${id}`, (event) => { - cb(event.payload); - }); - - return () => { - void unwatch(id); - unlisten(); - }; + return () => { + void unwatch(id); + unlisten(); + }; }