From 5e4d6e098f32560fa51092e4900edbea968657dd Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 10 Oct 2021 14:39:40 +0200 Subject: [PATCH] Improve connection handling Signed-off-by: trivernis --- mediarepo-ui/src-tauri/Cargo.lock | 788 +++++++++++++++++++- mediarepo-ui/src-tauri/Cargo.toml | 9 +- mediarepo-ui/src-tauri/src/commands/mod.rs | 16 + mediarepo-ui/src-tauri/src/commands/repo.rs | 27 +- mediarepo-ui/src-tauri/src/context.rs | 4 +- mediarepo-ui/src-tauri/src/error.rs | 12 + mediarepo-ui/src-tauri/src/ipc/files.rs | 1 + mediarepo-ui/src-tauri/src/ipc/mod.rs | 45 ++ mediarepo-ui/src-tauri/src/main.rs | 6 +- mediarepo-ui/src/app/models/Info.ts | 0 10 files changed, 876 insertions(+), 32 deletions(-) create mode 100644 mediarepo-ui/src-tauri/src/ipc/files.rs create mode 100644 mediarepo-ui/src-tauri/src/ipc/mod.rs create mode 100644 mediarepo-ui/src/app/models/Info.ts diff --git a/mediarepo-ui/src-tauri/Cargo.lock b/mediarepo-ui/src-tauri/Cargo.lock index eb49e57..51955d4 100644 --- a/mediarepo-ui/src-tauri/Cargo.lock +++ b/mediarepo-ui/src-tauri/Cargo.lock @@ -14,6 +14,17 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" +[[package]] +name = "ahash" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +dependencies = [ + "getrandom 0.2.3", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.18" @@ -43,6 +54,7 @@ name = "app" version = "0.1.0" dependencies = [ "directories", + "mediarepo", "rmp-ipc", "serde", "serde_json", @@ -51,6 +63,7 @@ dependencies = [ "thiserror", "tokio", "toml", + "typemap_rev", ] [[package]] @@ -90,6 +103,38 @@ dependencies = [ "winapi", ] +[[package]] +name = "async-stream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-trait" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atk" version = "0.14.0" @@ -114,6 +159,15 @@ dependencies = [ "system-deps 3.2.0", ] +[[package]] +name = "atoi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" +dependencies = [ + "num-traits", +] + [[package]] name = "attohttpc" version = "0.17.0" @@ -132,12 +186,42 @@ dependencies = [ "wildmatch", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "bae" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec107f431ee3d8a8e45e6dd117adab769556ef463959e77bf6a4888d5fd500cf" +dependencies = [ + "heck", + "proc-macro-error 0.4.12", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "base-x" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" + [[package]] name = "base64" version = "0.13.0" @@ -170,6 +254,17 @@ dependencies = [ "constant_time_eq", ] +[[package]] +name = "blake2s_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e461a7034e85b211a4acb57ee2e6730b32912b06c08cc242243c39fc21ae6a2" +dependencies = [ + "arrayref", + "arrayvec 0.5.2", + "constant_time_eq", +] + [[package]] name = "blake3" version = "1.0.0" @@ -191,6 +286,22 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "block-padding", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + [[package]] name = "bstr" version = "0.2.17" @@ -324,6 +435,7 @@ dependencies = [ "libc", "num-integer", "num-traits", + "serde", "time", "winapi", ] @@ -499,6 +611,30 @@ dependencies = [ "objc", ] +[[package]] +name = "cpufeatures" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10c2722795460108a7872e1cd933a85d6ec38abc4baecad51028f702da28889f" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" + [[package]] name = "crc32fast" version = "1.2.1" @@ -542,6 +678,16 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.5" @@ -614,6 +760,32 @@ dependencies = [ "syn", ] +[[package]] +name = "data-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" + +[[package]] +name = "data-encoding-macro" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" +dependencies = [ + "data-encoding", + "syn", +] + [[package]] name = "deflate" version = "0.7.20" @@ -725,6 +897,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dtoa" version = "0.4.8" @@ -773,6 +951,19 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "fastrand" version = "1.5.0" @@ -899,6 +1090,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-intrusive" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62007592ac46aa7c2b6416f7deb9a8a8f63a01e0f1d6e1787d5630170db2b63e" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + [[package]] name = "futures-io" version = "0.3.17" @@ -977,9 +1179,9 @@ dependencies = [ [[package]] name = "gdk" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a453eae5ec10345b3a96ca1b547328bfc94edd40aa95b08f14bb4c35863db140" +checksum = "b9d749dcfc00d8de0d7c3a289e04a04293eb5ba3d8a4e64d64911d481fa9933b" dependencies = [ "bitflags", "cairo-rs", @@ -1075,14 +1277,14 @@ checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.10.0+wasi-snapshot-preview1", ] [[package]] name = "gio" -version = "0.14.6" +version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a29d8062af72045518271a2cd98b4e1617ce43f5b4223ad0fb9a0eff8f718c" +checksum = "711c3632b3ebd095578a9c091418d10fed492da9443f58ebc8f45efbeb215cb0" dependencies = [ "bitflags", "futures-channel", @@ -1123,9 +1325,9 @@ dependencies = [ [[package]] name = "glib" -version = "0.14.5" +version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4a930b7208e6e0ab839eea5f65ac2b82109f729621430d47fe905e2e09d33f4" +checksum = "7c515f1e62bf151ef6635f528d05b02c11506de986e43b34a5c920ef0b3796a4" dependencies = [ "bitflags", "futures-channel", @@ -1149,7 +1351,7 @@ dependencies = [ "anyhow", "heck", "proc-macro-crate 1.1.0", - "proc-macro-error", + "proc-macro-error 1.0.4", "proc-macro2", "quote", "syn", @@ -1212,9 +1414,9 @@ dependencies = [ [[package]] name = "gtk" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6603bb79ded6ac6f3bac203794383afa8b1d6a8656d34a93a88f0b22826cd46c" +checksum = "2eb51122dd3317e9327ec1e4faa151d1fa0d95664cd8fb8dcfacf4d4d29ac70c" dependencies = [ "atk", "bitflags", @@ -1260,12 +1462,30 @@ dependencies = [ "anyhow", "heck", "proc-macro-crate 1.1.0", - "proc-macro-error", + "proc-macro-error 1.0.4", "proc-macro2", "quote", "syn", ] +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +dependencies = [ + "hashbrown", +] + [[package]] name = "heck" version = "0.3.3" @@ -1284,6 +1504,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "html5ever" version = "0.25.1" @@ -1315,6 +1541,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eee9694f83d9b7c09682fdb32213682939507884e5bcf227be9aff5d644b90dc" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "ico" version = "0.1.0" @@ -1360,6 +1592,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "infer" version = "0.4.0" @@ -1445,6 +1687,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "keccak" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" + [[package]] name = "kuchiki" version = "0.8.1" @@ -1469,6 +1717,17 @@ version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +[[package]] +name = "libsqlite3-sys" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "lock_api" version = "0.4.5" @@ -1558,6 +1817,74 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "mediarepo" +version = "0.1.0" +source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=edc5877582cde744fe23c22f31075da792821e77#edc5877582cde744fe23c22f31075da792821e77" +dependencies = [ + "env_logger", + "log", + "mediarepo-core", + "mediarepo-socket", + "tokio", +] + +[[package]] +name = "mediarepo-core" +version = "0.1.0" +source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=edc5877582cde744fe23c22f31075da792821e77#edc5877582cde744fe23c22f31075da792821e77" +dependencies = [ + "base64", + "multibase", + "multihash", + "rmp-ipc", + "sea-orm", + "serde", + "sqlx", + "thiserror", + "tokio", + "toml", + "typemap_rev", +] + +[[package]] +name = "mediarepo-database" +version = "0.1.0" +source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=edc5877582cde744fe23c22f31075da792821e77#edc5877582cde744fe23c22f31075da792821e77" +dependencies = [ + "chrono", + "mediarepo-core", + "sea-orm", + "sqlx", +] + +[[package]] +name = "mediarepo-model" +version = "0.1.0" +source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=edc5877582cde744fe23c22f31075da792821e77#edc5877582cde744fe23c22f31075da792821e77" +dependencies = [ + "chrono", + "mediarepo-core", + "mediarepo-database", + "sea-orm", + "serde", + "tokio", + "typemap_rev", +] + +[[package]] +name = "mediarepo-socket" +version = "0.1.0" +source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=edc5877582cde744fe23c22f31075da792821e77#edc5877582cde744fe23c22f31075da792821e77" +dependencies = [ + "chrono", + "mediarepo-core", + "mediarepo-model", + "rmp-ipc", + "serde", + "tokio", +] + [[package]] name = "memchr" version = "2.4.1" @@ -1573,6 +1900,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c64630dcdd71f1a64c435f54885086a0de5d6a12d104d69b165fb7d5286d677" + [[package]] name = "minisign-verify" version = "0.1.8" @@ -1620,6 +1953,48 @@ dependencies = [ "winapi", ] +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + +[[package]] +name = "multihash" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e540106213dc639fe2b632a7d9e3525169ef081378a7c2da4457b84fec44c0" +dependencies = [ + "blake2b_simd", + "blake2s_simd", + "blake3", + "digest", + "generic-array", + "multihash-derive", + "sha2", + "sha3", + "unsigned-varint", +] + +[[package]] +name = "multihash-derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "424f6e86263cd5294cbd7f1e95746b95aca0e0d66bff31e5a40d6baa87b4aa99" +dependencies = [ + "proc-macro-crate 1.1.0", + "proc-macro-error 1.0.4", + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "native-tls" version = "0.2.8" @@ -1719,6 +2094,17 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nom" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" +dependencies = [ + "memchr", + "minimal-lexical", + "version_check", +] + [[package]] name = "notify-rust" version = "4.5.4" @@ -1742,6 +2128,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -1839,6 +2236,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "open" version = "2.0.1" @@ -1905,9 +2308,9 @@ dependencies = [ [[package]] name = "pango" -version = "0.14.3" +version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fc88307d9797976ea62722ff2ec5de3fae279c6e20100ed3f49ca1a4bf3f96" +checksum = "546fd59801e5ca735af82839007edd226fe7d3bb06433ec48072be4439c28581" dependencies = [ "bitflags", "glib", @@ -2164,16 +2567,42 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-error" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7" +dependencies = [ + "proc-macro-error-attr 0.4.12", + "proc-macro2", + "quote", + "syn", + "version_check", +] + [[package]] name = "proc-macro-error" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "proc-macro-error-attr", + "proc-macro-error-attr 1.0.4", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de" +dependencies = [ "proc-macro2", "quote", "syn", + "syn-mid", "version_check", ] @@ -2449,9 +2878,9 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af495ca346adde10163eb920b52b5a3992fb209b31df58ece4ed0f855661978c" +checksum = "d2ada2c7329ea55e1e80f2a1ae9ddb123f93ae4b349d493273138118feadfecb" dependencies = [ "lazy_static", "log", @@ -2485,6 +2914,17 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rust_decimal" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0f1028de22e436bb35fce070310ee57d57b5e59ae77b4e3f24ce4773312b813" +dependencies = [ + "arrayvec 0.5.2", + "num-traits", + "serde", +] + [[package]] name = "rustc_version" version = "0.3.3" @@ -2537,6 +2977,88 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sea-orm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c5c7f0848ed7ddb2b3956abc84d5167dd33bb34c43e3b69172f565ca657a11" +dependencies = [ + "async-stream", + "async-trait", + "chrono", + "futures", + "futures-util", + "rust_decimal", + "sea-orm-macros", + "sea-query", + "sea-strum", + "serde", + "serde_json", + "sqlx", + "uuid", +] + +[[package]] +name = "sea-orm-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9466819cb0878e7fb6f6a1d7e46471a93b7121fef39db82f5799127884e39534" +dependencies = [ + "bae", + "convert_case", + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sea-query" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db6d690760e4f48663f0ecd9d91b03c1e6a5b17991d1c53043c5f07ba7db29" +dependencies = [ + "chrono", + "rust_decimal", + "sea-query-derive", + "serde_json", + "uuid", +] + +[[package]] +name = "sea-query-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cdc022b4f606353fe5dc85b09713a04e433323b70163e81513b141c6ae6eb5" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", + "thiserror", +] + +[[package]] +name = "sea-strum" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c77c6c6c8b3950fccb65edd5d04985b5377f4c8f669cb9a215553f0369ec001" +dependencies = [ + "sea-strum_macros", +] + +[[package]] +name = "sea-strum_macros" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51c247af6c2c4ffd372fe97e9afa579b4438e4c306c9aa3f11cbf72f1e845180" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "security-framework" version = "2.4.2" @@ -2630,6 +3152,7 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" dependencies = [ + "indexmap", "itoa", "ryu", "serde", @@ -2668,6 +3191,31 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "sha2" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" +dependencies = [ + "block-buffer", + "cfg-if 1.0.0", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer", + "digest", + "keccak", + "opaque-debug", +] + [[package]] name = "sharded-slab" version = "0.1.3" @@ -2730,6 +3278,107 @@ dependencies = [ "system-deps 1.3.2", ] +[[package]] +name = "sqlformat" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7911b0031a0247af40095838002999c7a52fba29d9739e93326e71a5a1bc9d43" +dependencies = [ + "sqlx-core", + "sqlx-macros", +] + +[[package]] +name = "sqlx-core" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aec89bfaca8f7737439bad16d52b07f1ccd0730520d3bf6ae9d069fe4b641fb1" +dependencies = [ + "ahash", + "atoi", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "crossbeam-channel", + "crossbeam-queue", + "crossbeam-utils", + "either", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-util", + "hashlink", + "hex", + "indexmap", + "itoa", + "libc", + "libsqlite3-sys", + "log", + "memchr", + "num-bigint", + "once_cell", + "parking_lot", + "percent-encoding", + "rust_decimal", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "sqlx-rt", + "stringprep", + "thiserror", + "tokio-stream", + "url", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-macros" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "584866c833511b1a152e87a7ee20dee2739746f60c858b3c5209150bc4b466f5" +dependencies = [ + "dotenv", + "either", + "heck", + "once_cell", + "proc-macro2", + "quote", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-rt", + "syn", + "url", +] + +[[package]] +name = "sqlx-rt" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d1bd069de53442e7a320f525a6d4deb8bb0621ac7a55f7eccbc2b58b57f43d0" +dependencies = [ + "native-tls", + "once_cell", + "tokio", + "tokio-native-tls", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -2776,6 +3425,16 @@ dependencies = [ "quote", ] +[[package]] +name = "stringprep" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "strsim" version = "0.9.3" @@ -2832,6 +3491,29 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syn-mid" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa8e7560a164edb1621a55d18a0c59abf49d360f47aa7b821061dd7eea7fac9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + [[package]] name = "system-deps" version = "1.3.2" @@ -3087,6 +3769,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "thin-slice" version = "0.1.1" @@ -3124,11 +3815,12 @@ dependencies = [ [[package]] name = "time" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", + "wasi 0.10.0+wasi-snapshot-preview1", "winapi", ] @@ -3160,9 +3852,42 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", + "tokio-macros", "winapi", ] +[[package]] +name = "tokio-macros" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.5.8" @@ -3292,6 +4017,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + +[[package]] +name = "unsigned-varint" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f8d425fafb8cd76bc3f22aace4af471d3156301d7508f2107e98fbeae10bc7f" + [[package]] name = "url" version = "2.2.2" @@ -3318,6 +4055,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ "getrandom 0.2.3", + "serde", ] [[package]] @@ -3375,9 +4113,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" @@ -3533,6 +4271,16 @@ dependencies = [ "cc", ] +[[package]] +name = "whoami" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "483a59fee1a93fec90eb08bc2eb4315ef10f4ebc478b3a5fadc969819cb66117" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + [[package]] name = "widestring" version = "0.4.3" diff --git a/mediarepo-ui/src-tauri/Cargo.toml b/mediarepo-ui/src-tauri/Cargo.toml index 9749899..96eab19 100644 --- a/mediarepo-ui/src-tauri/Cargo.toml +++ b/mediarepo-ui/src-tauri/Cargo.toml @@ -18,15 +18,22 @@ tauri-build = { version = "1.0.0-beta.4" } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tauri = { version = "1.0.0-beta.8", features = ["api-all"] } -rmp-ipc = "0.4.0" +rmp-ipc = "0.4.3" thiserror = "1.0.30" directories = "4.0.1" toml = "0.5.8" +typemap_rev = "0.1.5" [dependencies.tokio] version = "1.12.0" features = ["fs", "io-std", "io-util"] +[dependencies.mediarepo] +git = "https://github.com/Trivernis/mediarepo-daemon" +rev = "edc5877582cde744fe23c22f31075da792821e77" +features = ["library"] +default-features=false + [features] default = [ "custom-protocol" ] custom-protocol = [ "tauri/custom-protocol" ] diff --git a/mediarepo-ui/src-tauri/src/commands/mod.rs b/mediarepo-ui/src-tauri/src/commands/mod.rs index c426b23..59563d4 100644 --- a/mediarepo-ui/src-tauri/src/commands/mod.rs +++ b/mediarepo-ui/src-tauri/src/commands/mod.rs @@ -1 +1,17 @@ +use crate::context::Context; +use crate::error::AppResult; + pub mod repo; + +#[tauri::command] +pub async fn emit_info(context: tauri::State<'_, Context>) -> AppResult<()> { + let ipc = context.ipc.read().await; + if let Some(ipc) = &*ipc { + ipc.emitter.emit("info", ()).await?; + println!("Emitted info event."); + } else { + println!("No IPC Context"); + } + + Ok(()) +} diff --git a/mediarepo-ui/src-tauri/src/commands/repo.rs b/mediarepo-ui/src-tauri/src/commands/repo.rs index a76c39b..a0bf1fc 100644 --- a/mediarepo-ui/src-tauri/src/commands/repo.rs +++ b/mediarepo-ui/src-tauri/src/commands/repo.rs @@ -6,6 +6,9 @@ use crate::error::{AppError, AppResult}; use tokio::fs; use crate::settings::save_settings; use rmp_ipc::context::Context as IPCContext; +use tauri::Window; +use crate::ipc::build_ipc_context; +use std::mem; static REPO_CONFIG_FILE: &str = "repo.toml"; @@ -30,6 +33,12 @@ pub async fn get_repositories(context: tauri::State<'_, Context>) -> AppResult) -> AppResult> { + let repo = context.active_repository.read().await; + Ok(repo.clone()) +} + #[tauri::command] pub async fn add_repository(name: String, path: String, context: tauri::State<'_, Context>) -> AppResult> { let repo_path = path.clone(); @@ -54,12 +63,18 @@ pub async fn add_repository(name: String, path: String, context: tauri::State<'_ } #[tauri::command] -pub async fn select_repository(name: String, context: tauri::State<'_, Context>) -> AppResult<()> { +pub async fn select_repository(window: Window, name: String, context: tauri::State<'_, Context>) -> AppResult<()> { let settings = context.settings.read().await; let repo = settings.repositories.get(&name).ok_or(AppError::new(format!("Repository '{}' not found", name)))?; - let ipc = connect(&repo.address).await?; + let ipc = connect(window, &repo.address).await?; let mut ipc_ctx = context.ipc.write().await; - *ipc_ctx = Some(ipc); + let old_ipc = mem::replace(&mut *ipc_ctx, Some(ipc)); + + if let Some(old_ctx) = old_ipc { + old_ctx.stop().await?; + } + let mut active_repo = context.active_repository.write().await; + *active_repo = Some(repo.clone()); Ok(()) } @@ -72,8 +87,6 @@ async fn read_repo_config(path: PathBuf) -> AppResult { } /// Connects to the IPC Server -async fn connect(address: &str) -> AppResult { - let ctx = IPCBuilder::new().address(address).build_client().await?; - - Ok(ctx) +async fn connect(window: Window, address: &str) -> AppResult { + build_ipc_context(window, address).await } diff --git a/mediarepo-ui/src-tauri/src/context.rs b/mediarepo-ui/src-tauri/src/context.rs index 701dad4..0753627 100644 --- a/mediarepo-ui/src-tauri/src/context.rs +++ b/mediarepo-ui/src-tauri/src/context.rs @@ -6,7 +6,7 @@ use crate::settings::Settings; #[derive(Clone)] pub struct Context { - pub active_repository: Option, + pub active_repository: Arc>>, pub ipc: Arc>>, pub settings: Arc> } @@ -15,7 +15,7 @@ impl Context { pub fn new(settings: Settings) -> Self { Self { ipc: Arc::new(RwLock::new(None)), - active_repository: None, + active_repository: Arc::new(RwLock::new(None)), settings: Arc::new(RwLock::new(settings)) } } diff --git a/mediarepo-ui/src-tauri/src/error.rs b/mediarepo-ui/src-tauri/src/error.rs index ef7eab1..cf00f76 100644 --- a/mediarepo-ui/src-tauri/src/error.rs +++ b/mediarepo-ui/src-tauri/src/error.rs @@ -48,3 +48,15 @@ impl From for AppError { Self::new(format!("Daemon Error: {:?}", e)) } } + +impl From for AppError { + fn from(e: tauri::Error) -> Self { + Self::new(format!("Tauri error: {:?}", e)) + } +} + +impl From for rmp_ipc::error::Error { + fn from(e: AppError) -> Self { + rmp_ipc::error::Error::Message(e.message) + } +} diff --git a/mediarepo-ui/src-tauri/src/ipc/files.rs b/mediarepo-ui/src-tauri/src/ipc/files.rs new file mode 100644 index 0000000..48afb4b --- /dev/null +++ b/mediarepo-ui/src-tauri/src/ipc/files.rs @@ -0,0 +1 @@ +use mediarepo::requests::AddFileRequest; diff --git a/mediarepo-ui/src-tauri/src/ipc/mod.rs b/mediarepo-ui/src-tauri/src/ipc/mod.rs new file mode 100644 index 0000000..2affd4e --- /dev/null +++ b/mediarepo-ui/src-tauri/src/ipc/mod.rs @@ -0,0 +1,45 @@ +mod files; + +use mediarepo::responses::InfoResponse; +use rmp_ipc::context::{Context as IPCContext, Context}; +use rmp_ipc::{Event, IPCBuilder}; +use rmp_ipc::error::Result; +use rmp_ipc::error_event::{ERROR_EVENT_NAME, ErrorEventData}; +use tauri::Window; +use typemap_rev::TypeMapKey; +use crate::error::AppResult; + +pub struct WindowKey; + +impl TypeMapKey for WindowKey { + type Value = Window; +} + +pub async fn build_ipc_context(window: Window, address: &str) -> AppResult { + let ctx = IPCBuilder::new() + .address(address) + .insert::(window) + .on(ERROR_EVENT_NAME, |c, e|Box::pin(handle_error(c, e))) + .on("info", |c, e| Box::pin(handle_info(c, e))) + .build_client().await?; + + Ok(ctx) +} + +async fn handle_error(ctx: &Context, event: Event) -> Result<()> { + let error_data = event.data::()?; + let data = ctx.data.read().await; + let window = data.get::().unwrap(); + window.emit("error", error_data).expect("Failed to emit error event"); + + Ok(()) +} + +async fn handle_info(ctx: &Context, event: Event) -> Result<()> { + let info_data = event.data::()?; + let data = ctx.data.read().await; + let window = data.get::().unwrap(); + window.emit("info", info_data).expect("Failed to emit info event"); + + Ok(()) +} diff --git a/mediarepo-ui/src-tauri/src/main.rs b/mediarepo-ui/src-tauri/src/main.rs index b596766..03cb7b9 100644 --- a/mediarepo-ui/src-tauri/src/main.rs +++ b/mediarepo-ui/src-tauri/src/main.rs @@ -3,7 +3,8 @@ windows_subsystem = "windows" )] -use crate::commands::repo::{get_repositories, add_repository, select_repository}; +use crate::commands::repo::{get_repositories, add_repository, select_repository, get_active_repository}; +use crate::commands::emit_info; use crate::context::Context; use crate::settings::load_settings; @@ -11,6 +12,7 @@ mod commands; pub mod context; pub mod error; mod settings; +mod ipc; fn main() { let settings = load_settings().expect("Failed to load settings"); @@ -18,7 +20,7 @@ fn main() { tauri::Builder::default() .manage(context) - .invoke_handler(tauri::generate_handler![get_repositories, add_repository, select_repository]) + .invoke_handler(tauri::generate_handler![get_repositories, add_repository, select_repository, get_active_repository, emit_info]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/mediarepo-ui/src/app/models/Info.ts b/mediarepo-ui/src/app/models/Info.ts new file mode 100644 index 0000000..e69de29