From 1a2fc518ab49b87bdeb79c3acca244925a35b747 Mon Sep 17 00:00:00 2001 From: hauke Date: Thu, 5 Nov 2026 14:58:36 +0100 Subject: [PATCH] feat #14740: settings, keyring, tray and manual recording Co-Authored-By: Claude Opus 5.5 (1M context) --- Cargo.lock | 1098 ++++++++++++++++++++++++++++++++- crates/core/Cargo.toml | 1 + crates/core/src/capture.rs | 5 +- crates/core/src/lib.rs | 2 + crates/core/src/secrets.rs | 125 ++++ crates/core/src/settings.rs | 151 +++++ crates/core/src/store.rs | 29 +- src-tauri/Cargo.toml | 8 +- src-tauri/build.rs | 2 +- src-tauri/src/commands.rs | 201 ++++++ src-tauri/src/lib.rs | 91 ++- src-tauri/src/main.rs | 2 +- src-tauri/src/state.rs | 279 +++++++++ src-tauri/src/tray.rs | 75 +++ src-tauri/tauri.conf.json | 5 +- ui/index.html | 2 +- ui/src/App.svelte | 37 +- ui/src/app.css | 185 +++++- ui/src/lib/api.ts | 76 +++ ui/src/routes/Recorder.svelte | 153 +++++ ui/src/routes/Settings.svelte | 336 ++++++++++ 21 files changed, 2804 insertions(+), 59 deletions(-) create mode 100644 crates/core/src/secrets.rs create mode 100644 crates/core/src/settings.rs create mode 100644 src-tauri/src/commands.rs create mode 100644 src-tauri/src/state.rs create mode 100644 src-tauri/src/tray.rs create mode 100644 ui/src/lib/api.ts create mode 100644 ui/src/routes/Recorder.svelte create mode 100644 ui/src/routes/Settings.svelte diff --git a/Cargo.lock b/Cargo.lock index 8ef957f..db3e1d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "ahash" version = "0.8.12" @@ -76,6 +87,137 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +[[package]] +name = "async-broadcast" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" +dependencies = [ + "event-listener", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f426a31126c735126297bc5ea7a521263c9faff4f63ca415267ee625651c4f37" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "pin-project-lite", + "slab", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-lock" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75" +dependencies = [ + "async-channel", + "async-io", + "async-lock", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "rustix", +] + +[[package]] +name = "async-recursion" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f8abc12baad266b1c8cec146854c195b5864b4221d4b2ca7296a7ae82d9e451" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "async-signal" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "atk" version = "0.18.2" @@ -105,6 +247,20 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +[[package]] +name = "auto-launch" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17918dba7ecf78b9a14507ec9f984e7977d13fad87dc86d61038980a45d128cf" +dependencies = [ + "dirs 6.0.0", + "os_info", + "smappservice-rs", + "thiserror 2.0.21", + "windows-registry", + "windows-result", +] + [[package]] name = "autocfg" version = "1.5.1" @@ -162,6 +318,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-padding" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +dependencies = [ + "generic-array", +] + [[package]] name = "block2" version = "0.6.2" @@ -171,6 +336,19 @@ dependencies = [ "objc2", ] +[[package]] +name = "blocking" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa" +dependencies = [ + "async-channel", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + [[package]] name = "brotli" version = "9.1.1" @@ -263,12 +441,18 @@ dependencies = [ name = "call-recorder" version = "0.1.0" dependencies = [ + "chrono", "log", + "recorder-audio", + "recorder-core", "serde", "serde_json", "tauri", "tauri-build", + "tauri-plugin-autostart", "tauri-plugin-log", + "tauri-plugin-single-instance", + "tempfile", ] [[package]] @@ -314,6 +498,15 @@ dependencies = [ "toml 1.2.0+spec-1.1.0", ] +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.11.0" @@ -357,6 +550,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + [[package]] name = "chrono" version = "0.4.45" @@ -371,6 +570,16 @@ dependencies = [ "windows-link", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "combine" version = "4.6.9" @@ -381,6 +590,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "cookie" version = "0.18.2" @@ -563,6 +781,24 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "dbus-secret-service" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "708b509edf7889e53d7efb0ffadd994cc6c2345ccb62f55cfd6b0682165e4fa6" +dependencies = [ + "aes", + "block-padding", + "cbc", + "dbus", + "fastrand", + "hkdf", + "num", + "once_cell", + "sha2", + "zeroize", +] + [[package]] name = "defmt" version = "1.2.0" @@ -632,6 +868,16 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", +] + +[[package]] +name = "dirs" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" +dependencies = [ + "dirs-sys", ] [[package]] @@ -772,6 +1018,33 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" +[[package]] +name = "endi" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099" + +[[package]] +name = "enumflags2" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef" +dependencies = [ + "enumflags2_derive", + "serde", +] + +[[package]] +name = "enumflags2_derive" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "env_filter" version = "0.1.4" @@ -809,6 +1082,26 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "event-listener" +version = "5.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" +dependencies = [ + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + [[package]] name = "fallible-iterator" version = "0.3.0" @@ -970,6 +1263,19 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" +[[package]] +name = "futures-lite" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.34" @@ -1118,6 +1424,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -1351,12 +1668,36 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" + [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "hound" version = "3.5.1" @@ -1631,6 +1972,16 @@ dependencies = [ "cfb", ] +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "block-padding", + "generic-array", +] + [[package]] name = "ipnet" version = "2.12.2" @@ -1807,6 +2158,20 @@ dependencies = [ "serde", ] +[[package]] +name = "keyring" +version = "3.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebcc3aff044e5944a8fbaf69eb277d11986064cba30c468730e8b9909fb551c" +dependencies = [ + "byteorder", + "dbus-secret-service", + "log", + "secret-service", + "windows-sys 0.60.2", + "zeroize", +] + [[package]] name = "libappindicator" version = "0.9.0" @@ -2081,6 +2446,55 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags 2.13.2", + "cfg-if", + "cfg_aliases", + "libc", + "memoffset", +] + +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags 2.13.2", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-complex" version = "0.4.6" @@ -2116,6 +2530,27 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -2280,6 +2715,7 @@ checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.13.2", "block2", + "libc", "objc2", "objc2-core-foundation", ] @@ -2307,6 +2743,30 @@ dependencies = [ "objc2-foundation", ] +[[package]] +name = "objc2-security" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe137109bd1e8b5a99390f77a7d8b2961dafc1a1c5db8f2e60329ad6d895a" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-service-management" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b213642d6959cc6023ceb1217aa595eaaf09b8094ce95127c103cab611fe65e8" +dependencies = [ + "block2", + "objc2", + "objc2-core-foundation", + "objc2-foundation", + "objc2-security", +] + [[package]] name = "objc2-ui-kit" version = "0.3.2" @@ -2364,6 +2824,31 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-stream" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50" +dependencies = [ + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "os_info" +version = "3.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf20a545b305cf1da722b236b5155c9bb35f1d5ceb28c048bd96ca842f41b5b" +dependencies = [ + "android_system_properties", + "log", + "nix 0.31.3", + "objc2", + "objc2-foundation", + "objc2-ui-kit", + "windows-sys 0.61.2", +] + [[package]] name = "pango" version = "0.18.3" @@ -2389,6 +2874,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.5" @@ -2477,6 +2968,17 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.34" @@ -2509,6 +3011,20 @@ dependencies = [ "miniz_oxide 0.8.9", ] +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "windows-sys 0.61.2", +] + [[package]] name = "portable-atomic" version = "1.15.0" @@ -2539,6 +3055,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -2646,6 +3171,36 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + [[package]] name = "raw-window-handle" version = "0.6.2" @@ -2679,6 +3234,7 @@ dependencies = [ "chrono", "flacenc", "hound", + "keyring", "rubato", "rusqlite", "serde", @@ -2929,6 +3485,25 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "secret-service" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4d35ad99a181be0a60ffcbe85d680d98f87bdc4d7644ade319b87076b9dbfd4" +dependencies = [ + "aes", + "cbc", + "futures-util", + "generic-array", + "hkdf", + "num", + "once_cell", + "rand", + "serde", + "sha2", + "zbus 4.4.0", +] + [[package]] name = "selectors" version = "0.38.0" @@ -3123,6 +3698,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.9" @@ -3140,6 +3726,16 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + [[package]] name = "simd-adler32" version = "0.3.10" @@ -3164,6 +3760,18 @@ version = "1.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8" +[[package]] +name = "smappservice-rs" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52703b97a53101cf5d4580e0737aaa634ce1fdcfc123c16b2a9658e358013488" +dependencies = [ + "objc2", + "objc2-foundation", + "objc2-service-management", + "thiserror 2.0.21", +] + [[package]] name = "socket2" version = "0.6.5" @@ -3228,6 +3836,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "static_vcruntime" version = "3.0.0" @@ -3270,6 +3884,12 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "swift-rs" version = "1.0.9" @@ -3412,7 +4032,7 @@ dependencies = [ "anyhow", "bytes", "cookie", - "dirs", + "dirs 7.0.0", "dunce", "embed_plist", "getrandom 0.3.4", @@ -3462,7 +4082,7 @@ checksum = "adddb0e648752aaac5da9c3c3c6a68e1e87cab55e3b757b18a9441ef8c3ac614" dependencies = [ "anyhow", "cargo_toml", - "dirs", + "dirs 7.0.0", "glob", "heck 0.5.0", "json-patch", @@ -3534,6 +4154,20 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-autostart" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bce56ceb0a99b8ab5eebc977ba9ffc62391b862648cb9ab76fc8bc7231b8f7e2" +dependencies = [ + "auto-launch", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.21", +] + [[package]] name = "tauri-plugin-log" version = "2.10.1" @@ -3555,6 +4189,22 @@ dependencies = [ "time", ] +[[package]] +name = "tauri-plugin-single-instance" +version = "2.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "726b6da0dd5bd1344f84f4108a622c07d01923baacb5c803a605189672c5352f" +dependencies = [ + "serde", + "serde_json", + "tauri", + "thiserror 2.0.21", + "tokio", + "tracing", + "windows-sys 0.61.2", + "zbus 5.19.0", +] + [[package]] name = "tauri-runtime" version = "2.12.2" @@ -3939,9 +4589,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "tracing-core" version = "0.1.36" @@ -3968,7 +4630,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2b9c52859a94554803ccd4a24b98f74148ebc73b90676d783f3490b1bff9d72" dependencies = [ "crossbeam-channel", - "dirs", + "dirs 7.0.0", "libappindicator", "muda", "objc2", @@ -4001,6 +4663,17 @@ version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" +[[package]] +name = "uds_windows" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e" +dependencies = [ + "memoffset", + "tempfile", + "windows-sys 0.61.2", +] + [[package]] name = "unicode-ident" version = "1.0.27" @@ -4458,6 +5131,17 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + [[package]] name = "windows-result" version = "0.4.1" @@ -4482,7 +5166,34 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", ] [[package]] @@ -4500,13 +5211,46 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", ] [[package]] @@ -4533,42 +5277,138 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + [[package]] name = "winnow" version = "0.5.40" @@ -4619,7 +5459,7 @@ dependencies = [ "block2", "cookie", "crossbeam-channel", - "dirs", + "dirs 7.0.0", "dom_query", "dpi", "dunce", @@ -4673,6 +5513,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "xdg-home" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec1cdab258fb55c0da61328dc52c8764709b249011b2cad0454c72f0bf10a1f6" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "yoke" version = "0.8.4" @@ -4696,6 +5546,132 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zbus" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb97012beadd29e654708a0fdb4c84bc046f537aecfde2c3ee0a9e4b4d48c725" +dependencies = [ + "async-broadcast", + "async-process", + "async-recursion", + "async-trait", + "enumflags2", + "event-listener", + "futures-core", + "futures-sink", + "futures-util", + "hex", + "nix 0.29.0", + "ordered-stream", + "rand", + "serde", + "serde_repr", + "sha1", + "static_assertions", + "tracing", + "uds_windows", + "windows-sys 0.52.0", + "xdg-home", + "zbus_macros 4.4.0", + "zbus_names 3.0.0", + "zvariant 4.2.0", +] + +[[package]] +name = "zbus" +version = "5.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907" +dependencies = [ + "async-broadcast", + "async-executor", + "async-io", + "async-lock", + "async-process", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener", + "futures-core", + "futures-lite", + "hex", + "libc", + "ordered-stream", + "rustix", + "serde", + "serde_repr", + "tracing", + "uds_windows", + "uuid", + "windows-sys 0.61.2", + "winnow 1.0.5", + "zbus_macros 5.19.0", + "zbus_names 4.3.5", + "zvariant 5.15.1", +] + +[[package]] +name = "zbus_macros" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267db9407081e90bbfa46d841d3cbc60f59c0351838c4bc65199ecd79ab1983e" +dependencies = [ + "proc-macro-crate 3.5.0", + "proc-macro2", + "quote", + "syn 2.0.119", + "zvariant_utils 2.1.0", +] + +[[package]] +name = "zbus_macros" +version = "5.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40" +dependencies = [ + "proc-macro-crate 3.5.0", + "proc-macro2", + "quote", + "syn 3.0.9", + "zbus_names 4.3.5", + "zvariant 5.15.1", + "zvariant_utils 4.2.0", +] + +[[package]] +name = "zbus_names" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" +dependencies = [ + "serde", + "static_assertions", + "zvariant 4.2.0", +] + +[[package]] +name = "zbus_names" +version = "4.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812a12be4ead7a59e18ea8f047d08add0066b73bc62fc1467066a2472ae088dd" +dependencies = [ + "serde", + "winnow 1.0.5", + "zvariant 5.15.1", +] + +[[package]] +name = "zcheapstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "939f186d9ecebe044315a5cb6d6f78568bbc21152adc954d5a0c2f58bdbc9920" +dependencies = [ + "serde", +] + [[package]] name = "zerocopy" version = "0.8.63" @@ -4737,6 +5713,26 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "zerotrie" version = "0.2.5" @@ -4781,3 +5777,81 @@ name = "zmij" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zvariant" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe" +dependencies = [ + "endi", + "enumflags2", + "serde", + "static_assertions", + "zvariant_derive 4.2.0", +] + +[[package]] +name = "zvariant" +version = "5.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80bf6d6cd6a4b601acb64cfb8284cdc643fcfa75ef26ae3c46ec8aa4e8a1fbb7" +dependencies = [ + "endi", + "enumflags2", + "serde", + "winnow 1.0.5", + "zcheapstr", + "zvariant_derive 5.15.1", + "zvariant_utils 4.2.0", +] + +[[package]] +name = "zvariant_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73e2ba546bda683a90652bac4a279bc146adad1386f25379cf73200d2002c449" +dependencies = [ + "proc-macro-crate 3.5.0", + "proc-macro2", + "quote", + "syn 2.0.119", + "zvariant_utils 2.1.0", +] + +[[package]] +name = "zvariant_derive" +version = "5.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2672456ba1cb54b5eaec136e63135b3c7495fb938e53b28a62e633496d486d" +dependencies = [ + "proc-macro-crate 3.5.0", + "proc-macro2", + "quote", + "syn 3.0.9", + "zvariant_utils 4.2.0", +] + +[[package]] +name = "zvariant_utils" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zvariant_utils" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn 3.0.9", + "winnow 1.0.5", +] diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 7470b13..40f2ed6 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -16,6 +16,7 @@ thiserror = "1.0" rubato = "0.15" flacenc = "0.5" hound = "3.5" +keyring = { version = "3", features = ["windows-native", "sync-secret-service", "crypto-rust"] } [dev-dependencies] tempfile = "3" diff --git a/crates/core/src/capture.rs b/crates/core/src/capture.rs index 4f56e62..699fb45 100644 --- a/crates/core/src/capture.rs +++ b/crates/core/src/capture.rs @@ -5,6 +5,7 @@ //! PulseAudio on Linux). The [`Recorder`](crate::recorder::Recorder) only sees //! this trait, which keeps it testable with fake sources. +use serde::Serialize; use thiserror::Error; /// Format of the interleaved `f32` samples a [`CaptureSource`] delivers. @@ -28,14 +29,14 @@ pub enum OutputTarget { } /// One audio endpoint as shown in the device picker. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct DeviceInfo { pub id: String, pub name: String, } /// Available capture inputs (microphones) and outputs (render endpoints). -#[derive(Debug, Clone, Default, PartialEq, Eq)] +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)] pub struct Devices { pub inputs: Vec, pub outputs: Vec, diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 89542fc..9b42210 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -9,6 +9,8 @@ pub mod capture; pub mod model; pub mod recorder; pub mod retention; +pub mod secrets; +pub mod settings; pub mod store; #[cfg(test)] diff --git a/crates/core/src/secrets.rs b/crates/core/src/secrets.rs new file mode 100644 index 0000000..4bcade4 --- /dev/null +++ b/crates/core/src/secrets.rs @@ -0,0 +1,125 @@ +//! API keys, stored only in the OS keyring (Windows Credential Manager, +//! Linux Secret Service) under the service `eu.euvino.callrecorder`. + +use std::collections::HashMap; +use std::sync::Mutex; + +use serde::{Deserialize, Serialize}; +use thiserror::Error; + +/// Keyring service name all keys are stored under. +pub const KEYRING_SERVICE: &str = "eu.euvino.callrecorder"; + +/// The external services whose API keys the app keeps. +#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[serde(rename_all = "lowercase")] +pub enum Service { + DeepScript, + Anthropic, +} + +impl Service { + /// Keyring user name of this service's entry. + pub fn user(self) -> &'static str { + match self { + Service::DeepScript => "deepscript", + Service::Anthropic => "anthropic", + } + } +} + +#[derive(Debug, Error)] +pub enum SecretError { + #[error("Schlüsselbund-Fehler: {0}")] + Keyring(String), +} + +pub type Result = std::result::Result; + +pub trait SecretStore: Send + Sync { + /// The stored key, or `None` if there is none (or the keyring cannot be + /// read). + fn get(&self, s: Service) -> Option; + fn set(&self, s: Service, v: &str) -> Result<()>; + /// Removes the key; removing a key that does not exist is not an error. + fn delete(&self, s: Service) -> Result<()>; +} + +/// The OS keyring. +pub struct KeyringSecrets; + +impl KeyringSecrets { + fn entry(s: Service) -> Result { + keyring::Entry::new(KEYRING_SERVICE, s.user()) + .map_err(|e| SecretError::Keyring(e.to_string())) + } +} + +impl SecretStore for KeyringSecrets { + fn get(&self, s: Service) -> Option { + Self::entry(s).ok()?.get_password().ok() + } + + fn set(&self, s: Service, v: &str) -> Result<()> { + Self::entry(s)? + .set_password(v) + .map_err(|e| SecretError::Keyring(e.to_string())) + } + + fn delete(&self, s: Service) -> Result<()> { + match Self::entry(s)?.delete_credential() { + Ok(()) | Err(keyring::Error::NoEntry) => Ok(()), + Err(e) => Err(SecretError::Keyring(e.to_string())), + } + } +} + +/// In-memory secret store for tests. +#[derive(Default)] +pub struct MemorySecrets { + keys: Mutex>, +} + +impl SecretStore for MemorySecrets { + fn get(&self, s: Service) -> Option { + self.keys.lock().unwrap().get(&s).cloned() + } + + fn set(&self, s: Service, v: &str) -> Result<()> { + self.keys.lock().unwrap().insert(s, v.to_string()); + Ok(()) + } + + fn delete(&self, s: Service) -> Result<()> { + self.keys.lock().unwrap().remove(&s); + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn memory_secrets_roundtrip() { + let secrets = MemorySecrets::default(); + assert_eq!(secrets.get(Service::DeepScript), None); + + secrets.set(Service::DeepScript, "ds-key").unwrap(); + assert_eq!(secrets.get(Service::DeepScript).as_deref(), Some("ds-key")); + assert_eq!(secrets.get(Service::Anthropic), None); + + secrets.delete(Service::DeepScript).unwrap(); + assert_eq!(secrets.get(Service::DeepScript), None); + secrets.delete(Service::DeepScript).unwrap(); + } + + #[test] + fn service_serializes_as_keyring_user() { + for s in [Service::DeepScript, Service::Anthropic] { + let json = serde_json::to_string(&s).unwrap(); + assert_eq!(json, format!("\"{}\"", s.user())); + assert_eq!(serde_json::from_str::(&json).unwrap(), s); + } + } +} diff --git a/crates/core/src/settings.rs b/crates/core/src/settings.rs new file mode 100644 index 0000000..ab0f98d --- /dev/null +++ b/crates/core/src/settings.rs @@ -0,0 +1,151 @@ +//! User settings, persisted as JSON in the app config directory. +//! +//! Secrets (API keys) are never part of the settings; they live in the OS +//! keyring (see [`crate::secrets`]). + +use std::fs; +use std::io; +use std::path::Path; + +use serde::{Deserialize, Serialize}; + +/// Executables whose mic use counts as a call (matched case-insensitively). +const DEFAULT_ALLOWLIST: [&str; 6] = [ + "ms-teams.exe", + "teams.exe", + "microsip.exe", + "msedge.exe", + "chrome.exe", + "firefox.exe", +]; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(default)] +pub struct Settings { + pub allowlist: Vec, + pub mic_device: Option, + pub output_device: Option, + pub language: String, + pub deepscript_model: String, + pub retention_days: u32, + pub autostart: bool, + pub start_after_secs: u64, + pub end_after_secs: u64, +} + +impl Default for Settings { + fn default() -> Self { + Self { + allowlist: DEFAULT_ALLOWLIST.iter().map(|s| s.to_string()).collect(), + mic_device: None, + output_device: None, + language: "de".to_string(), + deepscript_model: "premium".to_string(), + retention_days: 7, + autostart: true, + start_after_secs: 3, + end_after_secs: 10, + } + } +} + +impl Settings { + /// Reads the settings file. A missing or unreadable file yields the + /// defaults; fields missing from the file take their default value. + pub fn load(path: &Path) -> Settings { + fs::read_to_string(path) + .ok() + .and_then(|json| serde_json::from_str(&json).ok()) + .unwrap_or_default() + } + + /// Writes the settings file (creating its directory), replacing the old + /// file atomically so a crash never leaves a half-written file behind. + pub fn save(&self, path: &Path) -> io::Result<()> { + if let Some(dir) = path.parent() { + fs::create_dir_all(dir)?; + } + let json = serde_json::to_string_pretty(self).map_err(io::Error::other)?; + let tmp = path.with_extension("json.tmp"); + fs::write(&tmp, json)?; + fs::rename(&tmp, path) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn settings_default_values() { + let s = Settings::default(); + assert_eq!( + s.allowlist, + vec![ + "ms-teams.exe", + "teams.exe", + "microsip.exe", + "msedge.exe", + "chrome.exe", + "firefox.exe" + ] + ); + assert_eq!(s.mic_device, None); + assert_eq!(s.output_device, None); + assert_eq!(s.language, "de"); + assert_eq!(s.deepscript_model, "premium"); + assert_eq!(s.retention_days, 7); + assert!(s.autostart); + assert_eq!(s.start_after_secs, 3); + assert_eq!(s.end_after_secs, 10); + } + + #[test] + fn settings_load_missing_file_returns_default() { + let dir = tempfile::tempdir().unwrap(); + assert_eq!( + Settings::load(&dir.path().join("settings.json")), + Settings::default() + ); + } + + #[test] + fn settings_load_corrupt_file_returns_default() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("settings.json"); + fs::write(&path, "{ not json").unwrap(); + assert_eq!(Settings::load(&path), Settings::default()); + } + + #[test] + fn settings_load_partial_json_fills_defaults() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("settings.json"); + fs::write(&path, r#"{"retention_days": 30, "mic_device": "headset"}"#).unwrap(); + let s = Settings::load(&path); + assert_eq!(s.retention_days, 30); + assert_eq!(s.mic_device.as_deref(), Some("headset")); + assert_eq!( + s, + Settings { + retention_days: 30, + mic_device: Some("headset".into()), + ..Settings::default() + } + ); + } + + #[test] + fn settings_save_then_load_roundtrips() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("nested").join("settings.json"); + let s = Settings { + allowlist: vec!["zoom.exe".into()], + output_device: Some("speakers".into()), + autostart: false, + ..Settings::default() + }; + s.save(&path).unwrap(); + assert_eq!(Settings::load(&path), s); + } +} diff --git a/crates/core/src/store.rs b/crates/core/src/store.rs index 7438446..6fd5ff0 100644 --- a/crates/core/src/store.rs +++ b/crates/core/src/store.rs @@ -162,6 +162,17 @@ impl Store { Ok(()) } + /// Sets the track file paths, for callers that derive them from the + /// call id and so can only know them after [`Store::create_call`]. + pub fn set_paths(&self, id: CallId, mic_path: &Path, out_path: &Path) -> Result<()> { + let conn = self.conn.lock().unwrap(); + conn.execute( + "UPDATE calls SET mic_path = ?1, out_path = ?2 WHERE id = ?3", + params![path_to_str(mic_path)?, path_to_str(out_path)?, id], + )?; + Ok(()) + } + pub fn set_status(&self, id: CallId, status: CallStatus, error: Option<&str>) -> Result<()> { let conn = self.conn.lock().unwrap(); conn.execute( @@ -495,7 +506,7 @@ fn speaker_from_key(key: &str) -> Result { #[cfg(test)] mod tests { use std::collections::BTreeMap; - use std::path::Path; + use std::path::{Path, PathBuf}; use chrono::Local; @@ -744,6 +755,22 @@ mod tests { assert_eq!(recovered.ended_at, Some(original_ended_at)); } + #[test] + fn set_paths_updates_track_paths() { + let store = Store::open_in_memory().unwrap(); + let id = store + .create_call("Manuell", Local::now(), Path::new(""), Path::new("")) + .unwrap(); + + store + .set_paths(id, Path::new("/rec/1-mic.wav"), Path::new("/rec/1-out.wav")) + .unwrap(); + + let call = store.get_call(id).unwrap().unwrap(); + assert_eq!(call.mic_path, PathBuf::from("/rec/1-mic.wav")); + assert_eq!(call.out_path, PathBuf::from("/rec/1-out.wav")); + } + #[test] fn delete_call_cascades() { let store = Store::open_in_memory().unwrap(); diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d2e9cc2..63462cb 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,5 +17,11 @@ tauri-build = { version = "2.7.4", features = [] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } log = "0.4" -tauri = { version = "2.12.5", features = [] } +tauri = { version = "2.12.5", features = ["tray-icon"] } tauri-plugin-log = "2" +tauri-plugin-autostart = "2" +tauri-plugin-single-instance = "2" +chrono = { version = "0.4", features = ["serde"] } +tempfile = "3" +recorder-core = { path = "../crates/core" } +recorder-audio = { path = "../crates/audio" } diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 795b9b7..d860e1e 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,3 +1,3 @@ fn main() { - tauri_build::build() + tauri_build::build() } diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs new file mode 100644 index 0000000..965259c --- /dev/null +++ b/src-tauri/src/commands.rs @@ -0,0 +1,201 @@ +//! Tauri commands and the UI side effects of recording (windows, events). +//! +//! The handlers stay thin: the work happens in [`AppState`]. Anything that +//! blocks (audio devices, stopping a recorder, the keyring) runs on the +//! blocking pool so the UI thread never waits on it. + +use std::thread; +use std::time::Duration; + +use recorder_core::capture::Devices; +use recorder_core::model::CallId; +use recorder_core::secrets::Service; +use recorder_core::settings::Settings; +use tauri::{AppHandle, Emitter, Manager, State}; +use tauri_plugin_autostart::ManagerExt; + +use crate::state::{AppState, DeviceLevels, RecordingState}; + +const LEVELS_INTERVAL: Duration = Duration::from_millis(100); + +type CmdResult = Result; + +#[tauri::command] +pub fn get_settings(state: State<'_, AppState>) -> Settings { + state.settings() +} + +#[tauri::command] +pub fn save_settings( + app: AppHandle, + state: State<'_, AppState>, + settings: Settings, +) -> CmdResult<()> { + let autostart = settings.autostart; + state.save_settings(settings)?; + apply_autostart(&app, autostart); + Ok(()) +} + +/// Stores `key` in the keyring; an empty key deletes the entry. +#[tauri::command] +pub async fn set_api_key(app: AppHandle, service: Service, key: String) -> CmdResult<()> { + blocking(app, move |app| { + let secrets = &app.state::().secrets; + let key = key.trim(); + let result = if key.is_empty() { + secrets.delete(service) + } else { + secrets.set(service, key) + }; + result.map_err(|e| e.to_string()) + }) + .await +} + +/// Whether a key is stored. Never returns the key itself. +#[tauri::command] +pub async fn has_api_key(app: AppHandle, service: Service) -> CmdResult { + blocking(app, move |app| { + let key = app.state::().secrets.get(service); + Ok(key.is_some_and(|key| !key.is_empty())) + }) + .await +} + +#[tauri::command] +pub async fn list_devices() -> CmdResult { + tauri::async_runtime::spawn_blocking(recorder_audio::list_devices) + .await + .map_err(|e| e.to_string()) +} + +#[tauri::command] +pub async fn test_devices(app: AppHandle) -> CmdResult { + blocking(app, |app| app.state::().test_devices()).await +} + +#[tauri::command] +pub fn get_recording_state(state: State<'_, AppState>) -> RecordingState { + state.recording_state() +} + +#[tauri::command] +pub async fn start_manual_recording(app: AppHandle) -> CmdResult { + blocking(app, start_manual).await +} + +#[tauri::command] +pub async fn stop_recording(app: AppHandle) -> CmdResult<()> { + blocking(app, stop).await +} + +#[tauri::command] +pub async fn discard_current_recording(app: AppHandle) -> CmdResult<()> { + blocking(app, discard).await +} + +/// Starts a manual recording, shows the floating window and streams levels. +pub fn start_manual(app: &AppHandle) -> CmdResult { + let state = app.state::().start_manual_recording()?; + let RecordingState::Recording { call_id, .. } = state else { + return Err("Aufnahme wurde nicht gestartet".to_string()); + }; + spawn_level_emitter(app.clone(), call_id); + set_window_visible(app, "recorder", true); + emit_state(app, &state); + Ok(call_id) +} + +/// Stops the current recording and hides the floating window. +pub fn stop(app: &AppHandle) -> CmdResult<()> { + let result = app.state::().stop_recording(); + set_window_visible(app, "recorder", false); + emit_state(app, &RecordingState::Idle); + result.map(|_| ()) +} + +/// Throws the current recording away and hides the floating window. +pub fn discard(app: &AppHandle) -> CmdResult<()> { + let result = app.state::().discard_current_recording(); + set_window_visible(app, "recorder", false); + emit_state(app, &RecordingState::Idle); + result +} + +/// Enables or disables launching at login. Debug builds leave the login +/// items alone so `cargo tauri dev` never registers a dev binary. +pub fn apply_autostart(app: &AppHandle, enabled: bool) { + if cfg!(debug_assertions) { + log::info!("debug build: not changing autostart (wanted {enabled})"); + return; + } + let autolaunch = app.autolaunch(); + let result = if enabled { + autolaunch.enable() + } else { + autolaunch.disable() + }; + if let Err(e) = result { + log::error!("could not apply autostart={enabled}: {e}"); + } +} + +pub fn show_main(app: &AppHandle) { + if let Some(window) = app.get_webview_window("main") { + let _ = window.unminimize(); + let _ = window.show(); + let _ = window.set_focus(); + } +} + +/// Brings back the floating window if the user closed it mid-recording. +pub fn show_recorder_if_recording(app: &AppHandle) { + if matches!( + app.state::().recording_state(), + RecordingState::Recording { .. } + ) { + set_window_visible(app, "recorder", true); + } +} + +/// Emits `levels` every 100 ms until `call_id` stops being the current +/// recording. +fn spawn_level_emitter(app: AppHandle, call_id: CallId) { + thread::spawn(move || loop { + thread::sleep(LEVELS_INTERVAL); + let Some(levels) = app.state::().levels(call_id) else { + break; + }; + let _ = app.emit("levels", levels); + }); +} + +fn emit_state(app: &AppHandle, state: &RecordingState) { + if let Err(e) = app.emit("recording-state", state) { + log::error!("could not emit recording-state: {e}"); + } +} + +fn set_window_visible(app: &AppHandle, label: &str, visible: bool) { + if let Some(window) = app.get_webview_window(label) { + let result = if visible { + window.show() + } else { + window.hide() + }; + if let Err(e) = result { + log::error!("could not change visibility of window {label}: {e}"); + } + } +} + +async fn blocking(app: AppHandle, f: F) -> CmdResult +where + T: Send + 'static, + F: FnOnce(&AppHandle) -> CmdResult + Send + 'static, +{ + tauri::async_runtime::spawn_blocking(move || f(&app)) + .await + .map_err(|e| e.to_string())? +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a650cf5..c67d2dd 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,16 +1,81 @@ +mod commands; +mod state; +mod tray; + +use recorder_core::secrets::KeyringSecrets; +use recorder_core::store::Store; +use tauri::{Manager, WindowEvent}; +use tauri_plugin_autostart::MacosLauncher; + +use crate::state::AppState; + +/// Command-line flag the login item starts the app with; the main window +/// then stays hidden in the tray. +const AUTOSTART_ARG: &str = "--autostart"; + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { - tauri::Builder::default() - .setup(|app| { - if cfg!(debug_assertions) { - app.handle().plugin( - tauri_plugin_log::Builder::default() - .level(log::LevelFilter::Info) - .build(), - )?; - } - Ok(()) - }) - .run(tauri::generate_context!()) - .expect("error while building tauri application"); + tauri::Builder::default() + // Must be registered first: a second launch only focuses the first. + .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { + commands::show_main(app); + })) + .plugin(tauri_plugin_autostart::init( + MacosLauncher::LaunchAgent, + Some(vec![AUTOSTART_ARG]), + )) + .setup(|app| { + if cfg!(debug_assertions) { + app.handle().plugin( + tauri_plugin_log::Builder::default() + .level(log::LevelFilter::Info) + .build(), + )?; + } + + let data_dir = app.path().app_data_dir()?; + let config_dir = app.path().app_config_dir()?; + std::fs::create_dir_all(&data_dir)?; + let store = Store::open(&data_dir.join("calls.sqlite"))?; + let recovery = store.startup_recovery()?; + log::info!("startup recovery: {recovery:?}"); + + let state = AppState::new( + store, + Box::new(KeyringSecrets), + config_dir.join("settings.json"), + data_dir.join("recordings"), + ); + let autostart = state.settings().autostart; + app.manage(state); + commands::apply_autostart(app.handle(), autostart); + + tray::create(app.handle())?; + if !std::env::args().any(|arg| arg == AUTOSTART_ARG) { + commands::show_main(app.handle()); + } + Ok(()) + }) + .on_window_event(|window, event| { + // Closing a window only hides it; the app keeps running in the + // tray (for call detection) until "Beenden". + if let WindowEvent::CloseRequested { api, .. } = event { + api.prevent_close(); + let _ = window.hide(); + } + }) + .invoke_handler(tauri::generate_handler![ + commands::get_settings, + commands::save_settings, + commands::set_api_key, + commands::has_api_key, + commands::list_devices, + commands::test_devices, + commands::get_recording_state, + commands::start_manual_recording, + commands::stop_recording, + commands::discard_current_recording, + ]) + .run(tauri::generate_context!()) + .expect("error while building tauri application"); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0be3484..b6fcfa4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,5 +2,5 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { - call_recorder_lib::run(); + call_recorder_lib::run(); } diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs new file mode 100644 index 0000000..0137c59 --- /dev/null +++ b/src-tauri/src/state.rs @@ -0,0 +1,279 @@ +//! Application state shared by commands, the tray and background threads. +//! +//! Holds the store, the settings, the secret store and the recording that is +//! currently running. Everything here is independent of windows and events; +//! the command layer turns results into UI updates. + +use std::fs; +use std::path::{Path, PathBuf}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Mutex, MutexGuard}; +use std::thread; +use std::time::{Duration, Instant}; + +use chrono::{DateTime, Local}; +use recorder_core::capture::OutputTarget; +use recorder_core::model::{CallId, CallStatus}; +use recorder_core::recorder::Recorder; +use recorder_core::secrets::SecretStore; +use recorder_core::settings::Settings; +use recorder_core::store::Store; +use serde::Serialize; + +/// `app` value of calls started from the tray or UI instead of detection. +const MANUAL_APP: &str = "Manuell"; +/// How long [`AppState::test_devices`] records. +const TEST_DURATION: Duration = Duration::from_secs(5); +const TEST_POLL: Duration = Duration::from_millis(50); + +/// Payload of the `recording-state` event. +#[derive(Serialize, Clone, Debug)] +#[serde(tag = "state", rename_all = "lowercase")] +pub enum RecordingState { + Idle, + Recording { + call_id: CallId, + app: String, + started_at: DateTime, + }, +} + +/// Payload of the `levels` event. +#[derive(Serialize, Clone, Debug)] +pub struct Levels { + pub mic: f32, + pub out: f32, + pub failed_tracks: Vec<&'static str>, +} + +/// Result of [`AppState::test_devices`]: peak rms level per track. +#[derive(Serialize, Clone, Copy, Debug)] +pub struct DeviceLevels { + pub mic: f32, + pub out: f32, +} + +struct CurrentRecording { + call_id: CallId, + app: String, + started_at: DateTime, + recorder: Recorder, +} + +pub struct AppState { + pub store: Store, + pub secrets: Box, + settings: Mutex, + settings_path: PathBuf, + recordings_dir: PathBuf, + current: Mutex>, + /// Set while a recording starts or the devices are tested, so neither + /// runs twice and `current` is never locked for longer than a moment. + devices_busy: AtomicBool, +} + +/// Releases [`AppState::devices_busy`] when dropped. +struct DevicesClaim<'a>(&'a AtomicBool); + +impl Drop for DevicesClaim<'_> { + fn drop(&mut self) { + self.0.store(false, Ordering::SeqCst); + } +} + +impl AppState { + pub fn new( + store: Store, + secrets: Box, + settings_path: PathBuf, + recordings_dir: PathBuf, + ) -> Self { + let settings = Settings::load(&settings_path); + Self { + store, + secrets, + settings: Mutex::new(settings), + settings_path, + recordings_dir, + current: Mutex::new(None), + devices_busy: AtomicBool::new(false), + } + } + + pub fn settings(&self) -> Settings { + lock(&self.settings).clone() + } + + pub fn save_settings(&self, settings: Settings) -> Result<(), String> { + settings + .save(&self.settings_path) + .map_err(|e| format!("Einstellungen konnten nicht gespeichert werden: {e}"))?; + *lock(&self.settings) = settings; + Ok(()) + } + + pub fn recording_state(&self) -> RecordingState { + match lock(&self.current).as_ref() { + Some(cur) => RecordingState::Recording { + call_id: cur.call_id, + app: cur.app.clone(), + started_at: cur.started_at, + }, + None => RecordingState::Idle, + } + } + + /// Levels of the recording `call_id`, or `None` once it is no longer + /// the current recording. + pub fn levels(&self, call_id: CallId) -> Option { + let current = lock(&self.current); + let cur = current.as_ref().filter(|cur| cur.call_id == call_id)?; + let (mic, out) = cur.recorder.levels(); + Some(Levels { + mic, + out, + failed_tracks: cur.recorder.failed_tracks(), + }) + } + + /// Creates a call row and starts recording the configured mic and + /// output device into `recordings/-mic.wav` / `-out.wav`. + pub fn start_manual_recording(&self) -> Result { + let _claim = self.claim_devices("Es läuft bereits eine Aufnahme")?; + let settings = self.settings(); + fs::create_dir_all(&self.recordings_dir) + .map_err(|e| format!("Aufnahmeordner konnte nicht angelegt werden: {e}"))?; + + let started_at = Local::now(); + let call_id = self + .store + .create_call(MANUAL_APP, started_at, Path::new(""), Path::new("")) + .map_err(|e| format!("Gespräch konnte nicht angelegt werden: {e}"))?; + let (mic_path, out_path) = self.track_paths(call_id); + + let started = self + .store + .set_paths(call_id, &mic_path, &out_path) + .map_err(|e| e.to_string()) + .and_then(|()| { + let mic = recorder_audio::mic_source(settings.mic_device.as_deref()); + let out = recorder_audio::output_source(output_target(&settings)); + Recorder::start(mic, out, &mic_path, &out_path).map_err(|e| e.to_string()) + }); + let recorder = match started { + Ok(recorder) => recorder, + Err(err) => { + if let Err(e) = self.store.delete_call(call_id) { + log::error!("could not delete call {call_id} after failed start: {e}"); + } + return Err(format!("Aufnahme konnte nicht gestartet werden: {err}")); + } + }; + + *lock(&self.current) = Some(CurrentRecording { + call_id, + app: MANUAL_APP.to_string(), + started_at, + recorder, + }); + Ok(self.recording_state()) + } + + /// Stops the current recording and finalizes its row. Returns `Ok(false)` + /// if nothing was recording. A recorder error still finishes the row and + /// marks the call as failed. + pub fn stop_recording(&self) -> Result { + let Some(cur) = lock(&self.current).take() else { + return Ok(false); + }; + let result = cur.recorder.stop(); + let id = cur.call_id; + self.store + .finish_recording(id, Local::now(), false) + .map_err(|e| format!("Gespräch konnte nicht gespeichert werden: {e}"))?; + if let Err(err) = result { + let msg = format!("Aufnahme fehlerhaft: {err}"); + if let Err(e) = self.store.set_status(id, CallStatus::Failed, Some(&msg)) { + log::error!("could not mark call {id} as failed: {e}"); + } + return Err(msg); + } + Ok(true) + } + + /// Discards the current recording: deletes both WAVs and the call row. + pub fn discard_current_recording(&self) -> Result<(), String> { + let Some(cur) = lock(&self.current).take() else { + return Ok(()); + }; + cur.recorder.discard(); + self.store + .delete_call(cur.call_id) + .map_err(|e| format!("Gespräch konnte nicht gelöscht werden: {e}")) + } + + /// Records both configured devices into a temporary directory for five + /// seconds and returns the peak level of each track. + pub fn test_devices(&self) -> Result { + let _claim = self.claim_devices("Während einer Aufnahme ist kein Test möglich")?; + let settings = self.settings(); + let dir = tempfile::tempdir() + .map_err(|e| format!("Testordner konnte nicht angelegt werden: {e}"))?; + let mic = recorder_audio::mic_source(settings.mic_device.as_deref()); + let out = recorder_audio::output_source(output_target(&settings)); + let recorder = Recorder::start( + mic, + out, + &dir.path().join("test-mic.wav"), + &dir.path().join("test-out.wav"), + ) + .map_err(|e| format!("Test fehlgeschlagen: {e}"))?; + + let mut peak = DeviceLevels { mic: 0.0, out: 0.0 }; + let until = Instant::now() + TEST_DURATION; + while Instant::now() < until { + thread::sleep(TEST_POLL); + let (mic, out) = recorder.levels(); + peak.mic = peak.mic.max(mic); + peak.out = peak.out.max(out); + } + recorder.discard(); + Ok(peak) + } + + /// Reserves the audio devices for a recording start or a test. Fails + /// with `recording_msg` while a recording runs. + fn claim_devices(&self, recording_msg: &str) -> Result, String> { + if self.devices_busy.swap(true, Ordering::SeqCst) { + return Err("Die Audiogeräte werden gerade getestet oder gestartet".to_string()); + } + let claim = DevicesClaim(&self.devices_busy); + // Checked after claiming: a start that just finished has already + // stored its recording before releasing the claim. + if lock(&self.current).is_some() { + return Err(recording_msg.to_string()); + } + Ok(claim) + } + + fn track_paths(&self, id: CallId) -> (PathBuf, PathBuf) { + ( + self.recordings_dir.join(format!("{id}-mic.wav")), + self.recordings_dir.join(format!("{id}-out.wav")), + ) + } +} + +fn output_target(settings: &Settings) -> OutputTarget { + match &settings.output_device { + Some(id) => OutputTarget::Device(id.clone()), + None => OutputTarget::DefaultRender, + } +} + +/// Locks ignoring poisoning: a panic in one command must not wedge the app. +fn lock(mutex: &Mutex) -> MutexGuard<'_, T> { + mutex + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) +} diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs new file mode 100644 index 0000000..8d84e0d --- /dev/null +++ b/src-tauri/src/tray.rs @@ -0,0 +1,75 @@ +//! Tray icon with "Öffnen", "Aufnahme manuell starten" and "Beenden". + +use std::thread; + +use tauri::menu::{Menu, MenuItem, PredefinedMenuItem}; +use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent}; +use tauri::{AppHandle, Manager}; + +use crate::commands; +use crate::state::AppState; + +const OPEN: &str = "open"; +const RECORD: &str = "record"; +const QUIT: &str = "quit"; + +pub fn create(app: &AppHandle) -> tauri::Result<()> { + let menu = Menu::with_items( + app, + &[ + &MenuItem::with_id(app, OPEN, "Öffnen", true, None::<&str>)?, + &MenuItem::with_id(app, RECORD, "Aufnahme manuell starten", true, None::<&str>)?, + &PredefinedMenuItem::separator(app)?, + &MenuItem::with_id(app, QUIT, "Beenden", true, None::<&str>)?, + ], + )?; + + let mut builder = TrayIconBuilder::with_id("main") + .tooltip("Gesprächsrekorder") + .menu(&menu) + .show_menu_on_left_click(false) + .on_menu_event(|app, event| match event.id().as_ref() { + OPEN => { + commands::show_main(app); + commands::show_recorder_if_recording(app); + } + RECORD => { + // Opening the audio devices can take a moment; keep the + // event loop free. + let app = app.clone(); + thread::spawn(move || { + if let Err(e) = commands::start_manual(&app) { + log::error!("manual recording from tray failed: {e}"); + } + }); + } + QUIT => quit(app), + _ => {} + }) + .on_tray_icon_event(|tray, event| { + if let TrayIconEvent::Click { + button: MouseButton::Left, + button_state: MouseButtonState::Up, + .. + } = event + { + commands::show_main(tray.app_handle()); + } + }); + if let Some(icon) = app.default_window_icon() { + builder = builder.icon(icon.clone()); + } + builder.build(app)?; + Ok(()) +} + +/// Finalizes a running recording, then exits. +fn quit(app: &AppHandle) { + let app = app.clone(); + thread::spawn(move || { + if let Err(e) = app.state::().stop_recording() { + log::error!("stopping the recording on quit failed: {e}"); + } + app.exit(0); + }); +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f93e36a..9b76b0e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -17,10 +17,12 @@ "width": 1000, "height": 680, "resizable": true, - "fullscreen": false + "fullscreen": false, + "visible": false }, { "label": "recorder", + "title": "Gesprächsrekorder", "url": "index.html#/recorder", "width": 300, "height": 200, @@ -30,6 +32,7 @@ }, { "label": "prompt", + "title": "Gespräch beendet", "url": "index.html#/prompt", "width": 340, "height": 180, diff --git a/ui/index.html b/ui/index.html index b265fcc..f9fd0de 100644 --- a/ui/index.html +++ b/ui/index.html @@ -1,5 +1,5 @@ - + diff --git a/ui/src/App.svelte b/ui/src/App.svelte index c9a5342..8def686 100644 --- a/ui/src/App.svelte +++ b/ui/src/App.svelte @@ -1,3 +1,34 @@ -
-

Gesprächsrekorder

-
+ + +{#if route === '/recorder'} + +{:else if route === '/settings'} + +{:else if route === '/prompt'} +
+

Gespräch beendet.

+
+{:else} +
+ +
+{/if} diff --git a/ui/src/app.css b/ui/src/app.css index 7530ed5..7dc873e 100644 --- a/ui/src/app.css +++ b/ui/src/app.css @@ -1,40 +1,179 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; + --text: #1d2330; + --muted: #6b7280; + --bg: #f5f6f9; + --surface: #fff; + --border: #e2e4ea; + --control-border: #cfd3dc; + --primary: #3b5bdb; + --primary-soft: #eef2ff; + --rec: #c62828; + --rec-soft: #fde8e8; + --ok: #1e7b34; + --ok-soft: #e6f4ea; + --meter-bg: #e8eaf0; - font: 18px/145% system-ui, 'Segoe UI', Roboto, sans-serif; - color-scheme: light dark; + font: 14px/1.45 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif; color: var(--text); background: var(--bg); - font-synthesis: none; - text-rendering: optimizeLegibility; + color-scheme: light; -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; } -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - } +* { + box-sizing: border-box; } body { margin: 0; + background: var(--bg); } h1 { - font-family: inherit; - font-weight: 500; - color: var(--text-h); + font-size: 20px; + font-weight: 600; + margin: 0; } -main { - display: flex; - min-height: 100svh; - place-content: center; - place-items: center; - text-align: center; +h2 { + font-size: 12px; + font-weight: 600; + color: var(--muted); + text-transform: uppercase; + letter-spacing: 0.04em; + margin: 0 0 10px; +} + +a { + color: var(--primary); +} + +.page { + max-width: 760px; + margin: 0 auto; + padding: 20px 24px 32px; +} + +.page-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + margin-bottom: 16px; +} + +.card { + background: var(--surface); + border: 1px solid var(--border); + border-radius: 10px; + padding: 16px; + margin-bottom: 14px; +} + +.muted { + color: var(--muted); + font-size: 12px; +} + +.error { + color: var(--rec); + font-size: 12px; +} + +.btn { + display: inline-flex; + align-items: center; + gap: 4px; + padding: 6px 14px; + border-radius: 6px; + border: 1px solid var(--control-border); + background: var(--surface); + color: var(--text); + font: inherit; + font-size: 13px; + font-weight: 600; + text-decoration: none; + cursor: pointer; +} + +.btn:hover:not(:disabled) { + border-color: var(--primary); +} + +.btn:disabled { + opacity: 0.5; + cursor: default; +} + +.btn.primary { + background: var(--primary); + border-color: var(--primary); + color: #fff; +} + +.btn.danger { + color: var(--rec); + border-color: #f0b4b4; +} + +.btn.small { + padding: 3px 10px; + font-size: 12px; +} + +.pill { + display: inline-block; + padding: 2px 8px; + border-radius: 999px; + font-size: 11px; + font-weight: 600; +} + +.pill.rec { + background: var(--rec-soft); + color: var(--rec); +} + +.pill.ok { + background: var(--ok-soft); + color: var(--ok); +} + +.pill.missing { + background: #eee; + color: #666; +} + +.meter { + height: 6px; + border-radius: 3px; + background: var(--meter-bg); + overflow: hidden; +} + +.meter > div { + height: 100%; + background: linear-gradient(90deg, #37b24d, #f59f00); + transition: width 90ms linear; +} + +input, +select { + font: inherit; + font-size: 13px; + color: var(--text); + padding: 5px 8px; + border: 1px solid var(--control-border); + border-radius: 6px; + background: var(--surface); +} + +input:focus, +select:focus { + outline: 2px solid var(--primary-soft); + border-color: var(--primary); +} + +label { + font-size: 13px; } diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts new file mode 100644 index 0000000..edaf058 --- /dev/null +++ b/ui/src/lib/api.ts @@ -0,0 +1,76 @@ +// Typed wrappers around the Tauri commands and events of the app shell. + +import { invoke } from '@tauri-apps/api/core' +import { listen, type UnlistenFn } from '@tauri-apps/api/event' + +export type CallId = number + +export interface Settings { + allowlist: string[] + mic_device: string | null + output_device: string | null + language: string + deepscript_model: string + retention_days: number + autostart: boolean + start_after_secs: number + end_after_secs: number +} + +export type Service = 'deepscript' | 'anthropic' + +export interface DeviceInfo { + id: string + name: string +} + +export interface Devices { + inputs: DeviceInfo[] + outputs: DeviceInfo[] +} + +export interface DeviceLevels { + mic: number + out: number +} + +export type Track = 'mic' | 'out' + +export type RecordingState = + | { state: 'idle' } + | { state: 'recording'; call_id: CallId; app: string; started_at: string } + +export interface Levels { + mic: number + out: number + failed_tracks: Track[] +} + +export const getSettings = () => invoke('get_settings') +export const saveSettings = (settings: Settings) => invoke('save_settings', { settings }) +export const setApiKey = (service: Service, key: string) => + invoke('set_api_key', { service, key }) +export const hasApiKey = (service: Service) => invoke('has_api_key', { service }) +export const listDevices = () => invoke('list_devices') +export const testDevices = () => invoke('test_devices') +export const getRecordingState = () => invoke('get_recording_state') +export const startManualRecording = () => invoke('start_manual_recording') +export const stopRecording = () => invoke('stop_recording') +export const discardCurrentRecording = () => invoke('discard_current_recording') + +export const onRecordingState = (handler: (state: RecordingState) => void): Promise => + listen('recording-state', (event) => handler(event.payload)) +export const onLevels = (handler: (levels: Levels) => void): Promise => + listen('levels', (event) => handler(event.payload)) + +/** Maps an rms level (0..1) to a meter fill (0..1) on a -60..0 dB scale. */ +export function meterFill(level: number): number { + if (level <= 0) return 0 + const db = 20 * Math.log10(level) + return Math.min(1, Math.max(0, (db + 60) / 60)) +} + +/** Error text of a rejected command. */ +export function errorText(err: unknown): string { + return typeof err === 'string' ? err : err instanceof Error ? err.message : String(err) +} diff --git a/ui/src/routes/Recorder.svelte b/ui/src/routes/Recorder.svelte new file mode 100644 index 0000000..2e2eb09 --- /dev/null +++ b/ui/src/routes/Recorder.svelte @@ -0,0 +1,153 @@ + + +
+
+ ● Aufnahme läuft + + {recording.state === 'recording' ? recording.app : ''} · {elapsed} + +
+ + {#each tracks as { track, label, failed } (track)} +
+
{label}
+
+ {#if levels.failed_tracks.includes(track)} +
{failed}
+ {/if} +
+ {/each} + +
+ + +
+ {#if error} +
{error}
+ {/if} +
+ + diff --git a/ui/src/routes/Settings.svelte b/ui/src/routes/Settings.svelte new file mode 100644 index 0000000..da9dd83 --- /dev/null +++ b/ui/src/routes/Settings.svelte @@ -0,0 +1,336 @@ + + +
+ + + {#if settings} +
+

API-Schlüssel

+ {#each services as { id, name } (id)} +
+ {name} + {#if keySaved[id]} + gespeichert ✓ + {:else} + fehlt + {/if} + + + {#if keySaved[id]} + + {/if} +
+ {/each} +
+ +
+

Audio

+
+ + + + +
+

+ Bitte mit Headset telefonieren – sonst landet die Gegenseite auch auf der Mikrofonspur. +

+
+ + + {testing + ? 'Bitte 5 Sekunden sprechen und etwas abspielen.' + : 'Nimmt 5 Sekunden auf und zeigt den Pegel beider Spuren.'} + +
+ {#if testResult} +
+ Mikrofon +
+ Lautsprecher +
+
+ {/if} +
+ +
+

Gesprächserkennung

+

Programme, deren Mikrofonnutzung als Gespräch zählt:

+
    + {#each settings.allowlist as name (name)} +
  • + {name} + +
  • + {/each} +
+
{ + e.preventDefault() + addApp() + }} + > + + +
+
+ +
+

Allgemein

+
+ + + + Tage + + +
+
+ + + {:else if error} +

{error}

+ {/if} +
+ +