Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Isolate Windows-specific code behind a platform module

Salomão Davy4175ebca7109
diff --git a/windows/Cargo.lock b/windows/Cargo.lock
index ac0c6001..4648fe32 100644
--- a/windows/Cargo.lock
+++ b/windows/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 0.2.17",
+]
+
[[package]]
name = "aho-corasick"
version = "1.1.5"
@@ -281,6 +292,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"
@@ -428,6 +448,15 @@ dependencies = [
"toml 1.1.6+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.5.1"
@@ -485,7 +514,7 @@ checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
dependencies = [
"cfg-if",
"cpufeatures 0.3.1",
- "rand_core",
+ "rand_core 0.10.1",
]
[[package]]
@@ -500,6 +529,16 @@ dependencies = [
"windows-link 0.2.1",
]
+[[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.8"
@@ -574,6 +613,7 @@ name = "coucou"
version = "0.1.1"
dependencies = [
"keyring",
+ "libc",
"reqwest 0.12.28",
"serde",
"serde_json",
@@ -719,6 +759,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.1.1"
@@ -788,6 +846,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
+ "subtle",
]
[[package]]
@@ -1340,7 +1399,7 @@ dependencies = [
"js-sys",
"libc",
"r-efi 6.0.0",
- "rand_core",
+ "rand_core 0.10.1",
"wasm-bindgen",
]
@@ -1528,6 +1587,24 @@ 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 = "html5ever"
version = "0.39.0"
@@ -1813,6 +1890,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"
@@ -1996,7 +2083,9 @@ 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",
]
@@ -2212,12 +2301,88 @@ 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 = "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"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
+dependencies = [
+ "num-traits",
+]
+
[[package]]
name = "num-conv"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
+[[package]]
+name = "num-integer"
+version = "0.1.47"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b"
+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"
@@ -2686,6 +2851,15 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
+[[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"
@@ -2792,7 +2966,7 @@ dependencies = [
"bytes",
"getrandom 0.4.3",
"lru-slab",
- "rand",
+ "rand 0.10.3",
"rand_pcg",
"ring",
"rustc-hash",
@@ -2840,6 +3014,17 @@ 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 0.6.4",
+]
+
[[package]]
name = "rand"
version = "0.10.3"
@@ -2848,7 +3033,26 @@ checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
dependencies = [
"chacha20",
"getrandom 0.4.3",
- "rand_core",
+ "rand_core 0.10.1",
+]
+
+[[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 0.6.4",
+]
+
+[[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]]
@@ -2863,7 +3067,7 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
dependencies = [
- "rand_core",
+ "rand_core 0.10.1",
]
[[package]]
@@ -3178,6 +3382,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 0.8.8",
+ "serde",
+ "sha2",
+ "zbus 4.4.0",
+]
+
[[package]]
name = "selectors"
version = "0.38.0"
@@ -3379,6 +3602,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 0.2.17",
+ "digest",
+]
+
[[package]]
name = "sha2"
version = "0.10.9"
@@ -3494,6 +3728,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 = "string_cache"
version = "0.9.0"
@@ -3819,7 +4059,7 @@ dependencies = [
"tokio",
"tracing",
"windows-sys 0.60.2",
- "zbus",
+ "zbus 5.19.0",
]
[[package]]
@@ -5205,6 +5445,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.3"
@@ -5228,6 +5478,38 @@ 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",
+ "ordered-stream",
+ "rand 0.8.8",
+ "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"
@@ -5258,9 +5540,22 @@ dependencies = [
"uuid",
"windows-sys 0.61.2",
"winnow 1.0.4",
- "zbus_macros",
- "zbus_names",
- "zvariant",
+ "zbus_macros 5.19.0",
+ "zbus_names 4.3.4",
+ "zvariant 5.15.0",
+]
+
+[[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]]
@@ -5273,9 +5568,20 @@ dependencies = [
"proc-macro2",
"quote",
"syn 3.0.6",
- "zbus_names",
- "zvariant",
- "zvariant_utils",
+ "zbus_names 4.3.4",
+ "zvariant 5.15.0",
+ "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]]
@@ -5286,7 +5592,7 @@ checksum = "d8bf88b4a3ff53e883001e0e0115b297a9d53c31b9c1edd2bfdd853e3428624e"
dependencies = [
"serde",
"winnow 1.0.4",
- "zvariant",
+ "zvariant 5.15.0",
]
[[package]]
@@ -5298,6 +5604,26 @@ dependencies = [
"serde",
]
+[[package]]
+name = "zerocopy"
+version = "0.8.59"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6df92bf3d9227be3d53173901ddbffac2babc27ae50f397776ffd6dc33f800cb"
+dependencies = [
+ "zerocopy-derive",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.8.59"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac4f328cf2f05d084e496c3e9c3f33ed0a183656a16e1fcec4d464d8373aec82"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "zerofrom"
version = "0.1.8"
@@ -5324,6 +5650,20 @@ name = "zeroize"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
+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"
@@ -5370,6 +5710,19 @@ 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.0"
@@ -5381,8 +5734,21 @@ dependencies = [
"serde",
"winnow 1.0.4",
"zcheapstr",
- "zvariant_derive",
- "zvariant_utils",
+ "zvariant_derive 5.15.0",
+ "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]]
@@ -5395,7 +5761,18 @@ dependencies = [
"proc-macro2",
"quote",
"syn 3.0.6",
- "zvariant_utils",
+ "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]]
diff --git a/windows/src-tauri/Cargo.toml b/windows/src-tauri/Cargo.toml
index 0274d9f5..3add7e90 100644
--- a/windows/src-tauri/Cargo.toml
+++ b/windows/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "coucou"
-description = "Coucou for Windows — Mochi lives at the top of your screen"
+description = "Coucou for Windows and Linux — Mochi lives at the top of your screen"
authors = ["Louis Raille"]
version.workspace = true
edition.workspace = true
@@ -21,6 +21,8 @@ serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
tokio = { version = "1", features = ["net", "io-util", "sync", "time", "rt"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
+
+[target.'cfg(windows)'.dependencies]
keyring = { version = "3", features = ["windows-native"] }
windows = { version = "0.61", features = [
"Win32_Foundation",
@@ -32,3 +34,8 @@ windows = { version = "0.61", features = [
"Win32_UI_Input_KeyboardAndMouse",
"Win32_UI_WindowsAndMessaging",
] }
+
+[target.'cfg(target_os = "linux")'.dependencies]
+# Secret Service (GNOME Keyring, KWallet) over D-Bus, encrypted in transit.
+keyring = { version = "3", features = ["sync-secret-service", "crypto-rust"] }
+libc = "0.2"
diff --git a/windows/src-tauri/src/hooks.rs b/windows/src-tauri/src/hooks.rs
index 0e3e32d1..85843306 100644
--- a/windows/src-tauri/src/hooks.rs
+++ b/windows/src-tauri/src/hooks.rs
@@ -14,9 +14,7 @@ use std::path::{Path, PathBuf};
use serde::Serialize;
use serde_json::{json, Map, Value};
use tauri::{AppHandle, Manager};
-use windows::Win32::System::SystemInformation::GetLocalTime;
-
-use crate::settings;
+use crate::{platform, settings};
/// Every event the island reacts to, with the hook timeout written to settings.json.
/// PermissionRequest waits for a human, so it gets the decision timeout + 10 s.
@@ -58,14 +56,8 @@ pub struct HookPreview {
pub fingerprint: String,
}
-fn home() -> PathBuf {
- std::env::var_os("USERPROFILE")
- .map(PathBuf::from)
- .unwrap_or_else(|| PathBuf::from("."))
-}
-
pub fn settings_path() -> PathBuf {
- home().join(".claude").join("settings.json")
+ platform::home_dir().join(".claude").join("settings.json")
}
/// Reads `~/.claude/settings.json`.
@@ -197,10 +189,10 @@ fn pretty(v: &Value) -> String {
/// Down to the second: installing then uninstalling in the same minute must not
/// quietly overwrite the first backup.
fn stamp() -> String {
- let t = unsafe { GetLocalTime() };
+ let t = platform::local_time();
format!(
"{:04}{:02}{:02}-{:02}{:02}{:02}",
- t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond
+ t.year, t.month, t.day, t.hour, t.minute, t.second
)
}
@@ -303,9 +295,9 @@ pub fn write(install: bool, fingerprint: &str) -> Result<String, String> {
Ok(backup.to_string_lossy().to_string())
}
-/// Copies coucou-hook.exe into %LOCALAPPDATA%\Coucou\bin on launch.
-/// In a bundled install it comes from the app resources; in `tauri dev` it sits
-/// next to coucou.exe in the workspace target directory.
+/// Copies the relay (coucou-hook.exe / coucou-hook) into the local data dir's
+/// bin/ on launch. In a bundled install it comes from the app resources; in
+/// `tauri dev` it sits next to the app binary in the workspace target directory.
///
/// Every candidate is tried rather than just the first, because getting this
/// wrong is silent and fatal: `resources` used to be a glob, which made NSIS
@@ -320,24 +312,25 @@ pub fn ensure_hook_exe(app: &AppHandle) {
}
let mut candidates: Vec<PathBuf> = Vec::new();
- if let Ok(p) = app.path().resolve("coucou-hook.exe", tauri::path::BaseDirectory::Resource) {
+ if let Ok(p) = app.path().resolve(platform::HOOK_EXE, tauri::path::BaseDirectory::Resource) {
candidates.push(p);
}
if let Ok(exe) = std::env::current_exe() {
if let Some(parent) = exe.parent() {
// Installed build, then `tauri dev` (target/debug) next to the
// release hook the pre-build step produces.
- candidates.push(parent.join("coucou-hook.exe"));
- candidates.push(parent.join("../release/coucou-hook.exe"));
+ candidates.push(parent.join(platform::HOOK_EXE));
+ candidates.push(parent.join("../release").join(platform::HOOK_EXE));
// Belt and braces: where the old glob form used to land it.
- candidates.push(parent.join("_up_/target/release/coucou-hook.exe"));
+ candidates.push(parent.join("_up_/target/release").join(platform::HOOK_EXE));
}
}
let tried: Vec<String> = candidates.iter().map(|p| p.display().to_string()).collect();
let Some(src) = candidates.into_iter().find(|p| p.exists()) else {
crate::log::line(format!(
- "coucou-hook.exe not found — Claude Code hooks cannot work. Looked in: {}",
+ "{} not found — Claude Code hooks cannot work. Looked in: {}",
+ platform::HOOK_EXE,
tried.join(", ")
));
return;
@@ -354,7 +347,7 @@ pub fn ensure_hook_exe(app: &AppHandle) {
// copy is fine, it is the same relay.
if let Err(err) = std::fs::copy(&src, &dest) {
if !dest.exists() {
- crate::log::line(format!("could not install coucou-hook.exe: {err}"));
+ crate::log::line(format!("could not install {}: {err}", platform::HOOK_EXE));
}
}
}
@@ -512,13 +505,13 @@ mod tests {
}
/// Everything filesystem-shaped lives in one test on purpose: it points
- /// USERPROFILE at a temp directory, and that is process-wide.
+ /// the home directory at a temp directory, and that is process-wide.
#[test]
fn writing_backs_up_preserves_and_refuses_a_changed_file() {
let tmp = std::env::temp_dir().join(format!("coucou-hooks-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&tmp);
std::fs::create_dir_all(tmp.join(".claude")).unwrap();
- std::env::set_var("USERPROFILE", &tmp);
+ std::env::set_var(platform::HOME_VAR, &tmp);
let path = settings_path();
assert!(path.starts_with(&tmp), "the test must not touch the real home");
diff --git a/windows/src-tauri/src/island.rs b/windows/src-tauri/src/island.rs
index 0a4fc878..3d6acbad 100644
--- a/windows/src-tauri/src/island.rs
+++ b/windows/src-tauri/src/island.rs
@@ -12,16 +12,7 @@ use std::time::Duration;
use serde::Serialize;
use tauri::{AppHandle, Emitter, Manager, Monitor, PhysicalPosition, PhysicalSize, WebviewWindow};
-use windows::Win32::Foundation::{HWND, POINT};
-use windows::core::BOOL;
-use windows::Win32::Foundation::LPARAM;
-use windows::Win32::System::Ole::RevokeDragDrop;
-use windows::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VK_LBUTTON};
-use windows::Win32::UI::WindowsAndMessaging::{EnumChildWindows, GetClassNameW};
-use windows::Win32::UI::WindowsAndMessaging::{
- GetCursorPos, GetWindowLongPtrW, SetWindowLongPtrW, GWL_EXSTYLE, WS_EX_NOACTIVATE,
- WS_EX_TOOLWINDOW,
-};
+use crate::platform::{self, cursor_physical, left_button_down};
/// Logical size of the full window — the largest island view, like the macOS panel.
pub const PANEL_W: f64 = 720.0;
@@ -68,7 +59,7 @@ pub struct PollGate {
cv: Condvar,
pub collapsed: AtomicBool,
pub rect: Mutex<IslandRect>,
- /// Mirrors the window flag so we only call into Win32 when it changes.
+ /// Mirrors the window flag so we only call into the OS when it changes.
ignoring: AtomicBool,
}
@@ -114,51 +105,6 @@ pub fn window(app: &AppHandle) -> Option<WebviewWindow> {
app.get_webview_window(WINDOW_LABEL)
}
-fn cursor_physical() -> Option<(f64, f64)> {
- let mut p = POINT::default();
- unsafe { GetCursorPos(&mut p).ok()? };
- Some((p.x as f64, p.y as f64))
-}
-
-/// Lets dropped files reach the app again.
-///
-/// wry installs its drop target by walking the webview's child windows **once**,
-/// when the webview is created. WebView2 creates `Chrome_RenderWidgetHostHWND`
-/// later and registers its own target on it; being the innermost window, that one
-/// wins, and since the page has no HTML5 drop handler it refuses everything — the
-/// "no drop" cursor, with nothing reaching Tauri. Revoking it makes OLE fall
-/// through to the target wry registered on the parent widget, which is the one
-/// that feeds Tauri's drag events.
-///
-/// Cheap and idempotent, so it is simply re-run whenever a drag might be starting.
-pub fn unblock_webview_drops(app: &AppHandle) {
- for label in [WINDOW_LABEL, "settings"] {
- let Some(win) = app.get_webview_window(label) else { continue };
- let Some(hwnd) = hwnd_of(&win) else { continue };
- unsafe {
- let _ = EnumChildWindows(Some(hwnd), Some(revoke_render_widget), LPARAM(0));
- }
- }
-}
-
-unsafe extern "system" fn revoke_render_widget(hwnd: HWND, _: LPARAM) -> BOOL {
- let mut name = [0u16; 64];
- let len = unsafe { GetClassNameW(hwnd, &mut name) };
- if len > 0 {
- let class = String::from_utf16_lossy(&name[..len as usize]);
- if class == "Chrome_RenderWidgetHostHWND" {
- let _ = unsafe { RevokeDragDrop(hwnd) };
- }
- }
- true.into()
-}
-
-/// True while the left mouse button is held — the only signal we get that a
-/// drag might be in flight before it reaches the window.
-fn left_button_down() -> bool {
- unsafe { (GetAsyncKeyState(VK_LBUTTON.0 as i32) as u16 & 0x8000) != 0 }
-}
-
fn monitor_contains(m: &Monitor, x: f64, y: f64) -> bool {
let p = m.position();
let s = m.size();
@@ -224,39 +170,6 @@ pub fn apply_geometry(app: &AppHandle, pref: &str, collapsed: bool) {
let _ = win.set_always_on_top(true);
}
-fn hwnd_of(win: &WebviewWindow) -> Option<HWND> {
- let raw = win.hwnd().ok()?.0 as isize;
- if raw == 0 {
- return None;
- }
- Some(HWND(raw as *mut _))
-}
-
-/// WS_EX_NOACTIVATE keeps clicks from stealing focus; WS_EX_TOOLWINDOW keeps the
-/// island out of Alt-Tab.
-pub fn make_non_activating(win: &WebviewWindow) {
- let Some(hwnd) = hwnd_of(win) else { return };
- unsafe {
- let ex = GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
- let want = ex | WS_EX_NOACTIVATE.0 as isize | WS_EX_TOOLWINDOW.0 as isize;
- SetWindowLongPtrW(hwnd, GWL_EXSTYLE, want);
- }
-}
-
-/// Temporarily allow activation so a text field inside the island can be typed in.
-pub fn set_activating(win: &WebviewWindow, activating: bool) {
- let Some(hwnd) = hwnd_of(win) else { return };
- unsafe {
- let ex = GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
- let want = if activating {
- ex & !(WS_EX_NOACTIVATE.0 as isize)
- } else {
- ex | WS_EX_NOACTIVATE.0 as isize
- };
- SetWindowLongPtrW(hwnd, GWL_EXSTYLE, want);
- }
-}
-
/// Position, size and scale of the monitor the island lives on. Any change here
/// means the island has to be placed again.
fn current_screen_key(app: &AppHandle) -> Option<(i32, i32, u32, u32, u64)> {
@@ -339,7 +252,7 @@ pub fn spawn_cursor_poll(app: AppHandle, gate: Arc<PollGate>) {
let down = left_button_down();
if down && !was_down {
let handle = app.clone();
- let _ = app.run_on_main_thread(move || unblock_webview_drops(&handle));
+ let _ = app.run_on_main_thread(move || platform::unblock_webview_drops(&handle));
}
was_down = down;
diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rs
index 5d19db6c..7292852a 100644
--- a/windows/src-tauri/src/lib.rs
+++ b/windows/src-tauri/src/lib.rs
@@ -7,12 +7,11 @@ mod integrations;
mod island;
mod log;
mod pipe;
+mod platform;
mod secrets;
mod settings;
mod tray;
-mod win_user;
-use std::os::windows::process::CommandExt;
use std::process::Command;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex};
@@ -28,9 +27,6 @@ use island::{PollGate, ScreenInfo};
use pipe::Pending;
use settings::Settings;
-/// Keeps spawned helpers from flashing a console window.
-const CREATE_NO_WINDOW: u32 = 0x0800_0000;
-
pub struct Shared {
pub settings: Mutex<Settings>,
pub gate: Arc<PollGate>,
@@ -108,7 +104,7 @@ fn set_island_rect(shared: State<Shared>, x: f64, y: f64, width: f64, height: f6
#[tauri::command]
fn focus_window(app: AppHandle, focused: bool) {
let Some(win) = island::window(&app) else { return };
- island::set_activating(&win, focused);
+ platform::set_activating(&win, focused);
if focused {
let _ = win.set_focus();
}
@@ -126,52 +122,32 @@ fn open_url(url: String) {
if !(url.starts_with("http://") || url.starts_with("https://")) {
return;
}
- let _ = Command::new("rundll32.exe")
- .args(["url.dll,FileProtocolHandler", &url])
- .creation_flags(CREATE_NO_WINDOW)
- .spawn();
+ platform::open_url(&url);
}
/// "Open terminal" opens the working folder in VS Code when `code` is on PATH,
-/// and falls back to Explorer otherwise.
+/// and falls back to the file manager otherwise.
#[tauri::command]
fn open_in_vscode(path: Option<String>) -> bool {
- // No `cmd /C` anywhere near this. The path is a project folder chosen by
- // whoever is using Claude Code, and cmd would happily read `&`, `^` and `%`
- // in a folder name as syntax. Finding the launcher ourselves and handing the
- // path over as a separate argument keeps it a path.
- if let Some(code) = find_on_path("code") {
+ // No shell anywhere near this. The path is a project folder chosen by
+ // whoever is using Claude Code, and a shell would happily read `&`, `^`, `%`
+ // or `$` in a folder name as syntax. Finding the launcher ourselves and
+ // handing the path over as a separate argument keeps it a path.
+ if let Some(code) = platform::find_on_path("code") {
let mut cmd = Command::new(code);
if let Some(p) = path.as_deref().filter(|p| !p.is_empty()) {
cmd.arg(p);
}
- if cmd.creation_flags(CREATE_NO_WINDOW).spawn().is_ok() {
+ if platform::no_console(&mut cmd).spawn().is_ok() {
return true;
}
}
if let Some(p) = path.as_deref().filter(|p| !p.is_empty()) {
- let _ = Command::new("explorer").arg(p).spawn();
+ platform::reveal_folder(p);
}
false
}
-/// Our own `where`: walks %PATH% against %PATHEXT%, no shell involved.
-/// Rust quotes arguments correctly for `.cmd`/`.bat` targets since 1.77, so
-/// spawning `code.cmd` directly is safe.
-fn find_on_path(stem: &str) -> Option<std::path::PathBuf> {
- let exts = std::env::var("PATHEXT").unwrap_or_else(|_| ".COM;.EXE;.BAT;.CMD".into());
- let dirs = std::env::var_os("PATH")?;
- for dir in std::env::split_paths(&dirs) {
- for ext in exts.split(';').filter(|e| !e.is_empty()) {
- let candidate = dir.join(format!("{stem}{}", ext.to_lowercase()));
- if candidate.is_file() {
- return Some(candidate);
- }
- }
- }
- None
-}
-
#[tauri::command]
fn quit_app(app: AppHandle) {
app.exit(0);
@@ -415,7 +391,7 @@ pub fn run() {
create_settings_window(&handle);
if let Some(win) = island::window(&handle) {
- island::make_non_activating(&win);
+ platform::make_non_activating(&win);
island::apply_geometry(&handle, &loaded.screen, false);
let _ = win.show();
}
diff --git a/windows/src-tauri/src/log.rs b/windows/src-tauri/src/log.rs
index 13425a56..d618165e 100644
--- a/windows/src-tauri/src/log.rs
+++ b/windows/src-tauri/src/log.rs
@@ -1,17 +1,16 @@
-// Small append-only log at %LOCALAPPDATA%\Coucou\coucou.log — the Windows
-// equivalent of nbLog() in HookServer.swift. Nothing leaves the machine.
+// Small append-only log at %LOCALAPPDATA%\Coucou\coucou.log (Windows) or
+// ~/.local/share/coucou/coucou.log (Linux) — the equivalent of nbLog() in
+// HookServer.swift. Nothing leaves the machine.
use std::io::Write;
-use windows::Win32::System::SystemInformation::GetLocalTime;
-
-use crate::settings;
+use crate::{platform, settings};
pub fn line(message: impl AsRef<str>) {
- let t = unsafe { GetLocalTime() };
+ let t = platform::local_time();
let stamp = format!(
"{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
- t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond
+ t.year, t.month, t.day, t.hour, t.minute, t.second
);
let dir = settings::local_dir();
if std::fs::create_dir_all(&dir).is_err() {
diff --git a/windows/src-tauri/src/pipe.rs b/windows/src-tauri/src/pipe.rs
index f8cd71c4..5554dc75 100644
--- a/windows/src-tauri/src/pipe.rs
+++ b/windows/src-tauri/src/pipe.rs
@@ -17,6 +17,10 @@
// documented hookSpecificOutput JSON is coucou-hook's job, so the wire format
// Claude Code expects lives in exactly one place.
+// Until the Linux transport lands, the shared request/decision half of this
+// file has no caller there.
+#![cfg_attr(not(windows), allow(dead_code, unused_imports))]
+
use std::collections::HashMap;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Mutex;
@@ -24,7 +28,9 @@ use std::time::Duration;
use serde_json::{json, Value};
use tauri::{AppHandle, Emitter, Manager};
+#[cfg(windows)]
use tokio::io::{AsyncReadExt, AsyncWriteExt};
+#[cfg(windows)]
use tokio::net::windows::named_pipe::{NamedPipeServer, ServerOptions};
use tokio::sync::mpsc;
@@ -57,12 +63,14 @@ pub struct Pending(pub Mutex<HashMap<String, mpsc::Sender<Reply>>>);
static COUNTER: AtomicU64 = AtomicU64::new(1);
/// `\\.\pipe\coucou-<sid>` — must match coucou-hook's `pipe_path()` exactly.
+#[cfg(windows)]
pub fn pipe_name() -> String {
- let key = crate::win_user::current_user_sid()
+ let key = crate::platform::current_user_sid()
.unwrap_or_else(|| std::env::var("USERNAME").unwrap_or_else(|_| "user".into()));
format!(r"\\.\pipe\coucou-{key}")
}
+#[cfg(windows)]
pub fn start(app: AppHandle) {
tauri::async_runtime::spawn(async move {
let name = pipe_name();
@@ -95,6 +103,14 @@ pub fn start(app: AppHandle) {
});
}
+/// The relay transport on Linux is not written yet; until it is, hook events
+/// never reach the island and Claude Code carries on as if Coucou were closed.
+#[cfg(target_os = "linux")]
+pub fn start(_app: AppHandle) {
+ log::line("relay transport not available on this platform yet — hooks are inactive");
+}
+
+#[cfg(windows)]
async fn handle(app: AppHandle, mut pipe: NamedPipeServer) {
let mut buf = Vec::new();
let mut chunk = [0u8; 4096];
diff --git a/windows/src-tauri/src/platform/linux.rs b/windows/src-tauri/src/platform/linux.rs
new file mode 100644
index 00000000..d0a296f8
--- /dev/null
+++ b/windows/src-tauri/src/platform/linux.rs
@@ -0,0 +1,105 @@
+// Linux: XDG directories for files, xdg-open for links and folders.
+//
+// The island-window functions are placeholders for now: they do nothing, so the
+// window keeps its Tauri defaults. The real version depends on the session
+// (layer-shell on Wayland compositors that have it, X11 elsewhere).
+
+use std::os::unix::fs::PermissionsExt;
+use std::path::PathBuf;
+use std::process::Command;
+
+use tauri::{AppHandle, WebviewWindow};
+
+use super::{home_dir, LocalTime};
+
+/// File name of the Claude Code relay.
+pub const HOOK_EXE: &str = "coucou-hook";
+
+/// Environment variable holding the home directory.
+pub const HOME_VAR: &str = "HOME";
+
+// ── Files ─────────────────────────────────────────────────────────────────────
+
+/// `$XDG_CONFIG_HOME`, or `~/.config` when it is unset or not absolute.
+fn xdg(var: &str, fallback: &str) -> PathBuf {
+ std::env::var_os(var)
+ .map(PathBuf::from)
+ .filter(|p| p.is_absolute())
+ .unwrap_or_else(|| home_dir().join(fallback))
+}
+
+/// ~/.config/coucou — preferences.
+pub fn config_dir() -> PathBuf {
+ xdg("XDG_CONFIG_HOME", ".config").join("coucou")
+}
+
+/// ~/.local/share/coucou — where coucou-hook, the inbox and the log live. The
+/// relay has to sit at a stable path: an AppImage is mounted somewhere new on
+/// every launch.
+pub fn local_dir() -> PathBuf {
+ xdg("XDG_DATA_HOME", ".local/share").join("coucou")
+}
+
+pub fn local_time() -> LocalTime {
+ let mut tm: libc::tm = unsafe { std::mem::zeroed() };
+ unsafe {
+ let now = libc::time(std::ptr::null_mut());
+ libc::localtime_r(&now, &mut tm);
+ }
+ LocalTime {
+ year: (tm.tm_year + 1900) as u32,
+ month: (tm.tm_mon + 1) as u32,
+ day: tm.tm_mday as u32,
+ hour: tm.tm_hour as u32,
+ minute: tm.tm_min as u32,
+ second: tm.tm_sec as u32,
+ }
+}
+
+// ── Processes ─────────────────────────────────────────────────────────────────
+
+/// Nothing to hide: a spawned process only gets a terminal if it asks for one.
+pub fn no_console(cmd: &mut Command) -> &mut Command {
+ cmd
+}
+
+pub fn open_url(url: &str) {
+ let _ = Command::new("xdg-open").arg(url).spawn();
+}
+
+pub fn reveal_folder(path: &str) {
+ let _ = Command::new("xdg-open").arg(path).spawn();
+}
+
+/// Our own `which`: the first executable file named `stem` on $PATH.
+pub fn find_on_path(stem: &str) -> Option<PathBuf> {
+ let dirs = std::env::var_os("PATH")?;
+ std::env::split_paths(&dirs)
+ .map(|dir| dir.join(stem))
+ .find(|p| {
+ std::fs::metadata(p)
+ .map(|m| m.is_file() && m.permissions().mode() & 0o111 != 0)
+ .unwrap_or(false)
+ })
+}
+
+// ── Cursor ────────────────────────────────────────────────────────────────────
+
+/// Not available yet. With no position the poll loop emits nothing and never
+/// turns click-through on, so the island takes every click over its window.
+pub fn cursor_physical() -> Option<(f64, f64)> {
+ None
+}
+
+pub fn left_button_down() -> bool {
+ false
+}
+
+// ── Island window ─────────────────────────────────────────────────────────────
+
+/// WebKitGTK has no competing drop target to remove.
+pub fn unblock_webview_drops(_app: &AppHandle) {}
+
+pub fn make_non_activating(_win: &WebviewWindow) {}
+
+pub fn set_activating(_win: &WebviewWindow, _activating: bool) {}
diff --git a/windows/src-tauri/src/platform/mod.rs b/windows/src-tauri/src/platform/mod.rs
new file mode 100644
index 00000000..5eb032dc
--- /dev/null
+++ b/windows/src-tauri/src/platform/mod.rs
@@ -0,0 +1,33 @@
+// Everything that differs between operating systems, behind one set of names.
+//
+// The rest of the app calls `platform::…` and never touches Win32 or a Linux
+// API directly. Each OS file exposes the same functions; the compiler picks one.
+
+use std::path::PathBuf;
+
+#[cfg(windows)]
+mod windows;
+#[cfg(windows)]
+pub use self::windows::*;
+
+#[cfg(target_os = "linux")]
+mod linux;
+#[cfg(target_os = "linux")]
+pub use self::linux::*;
+
+/// Wall-clock time in the user's time zone, for log lines and backup names.
+pub struct LocalTime {
+ pub year: u32,
+ pub month: u32,
+ pub day: u32,
+ pub hour: u32,
+ pub minute: u32,
+ pub second: u32,
+}
+
+/// The user's home directory, where `.claude/settings.json` lives.
+pub fn home_dir() -> PathBuf {
+ std::env::var_os(HOME_VAR)
+ .map(PathBuf::from)
+ .unwrap_or_else(|| PathBuf::from("."))
+}
diff --git a/windows/src-tauri/src/platform/windows.rs b/windows/src-tauri/src/platform/windows.rs
new file mode 100644
index 00000000..4273ba18
--- /dev/null
+++ b/windows/src-tauri/src/platform/windows.rs
@@ -0,0 +1,221 @@
+// Windows: Win32 for the island window and the cursor, %APPDATA% for files.
+
+use std::os::windows::process::CommandExt;
+use std::path::PathBuf;
+use std::process::Command;
+
+use tauri::{AppHandle, Manager, WebviewWindow};
+
+use ::windows::core::{BOOL, PWSTR};
+use ::windows::Win32::Foundation::{CloseHandle, HANDLE, HLOCAL, HWND, LPARAM, LocalFree, POINT};
+use ::windows::Win32::Security::Authorization::ConvertSidToStringSidW;
+use ::windows::Win32::Security::{GetTokenInformation, TokenUser, TOKEN_QUERY, TOKEN_USER};
+use ::windows::Win32::System::Ole::RevokeDragDrop;
+use ::windows::Win32::System::SystemInformation::GetLocalTime;
+use ::windows::Win32::System::Threading::{GetCurrentProcess, OpenProcessToken};
+use ::windows::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VK_LBUTTON};
+use ::windows::Win32::UI::WindowsAndMessaging::{
+ EnumChildWindows, GetClassNameW, GetCursorPos, GetWindowLongPtrW, SetWindowLongPtrW,
+ GWL_EXSTYLE, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW,
+};
+
+use super::LocalTime;
+use crate::island::WINDOW_LABEL;
+
+/// File name of the Claude Code relay.
+pub const HOOK_EXE: &str = "coucou-hook.exe";
+
+/// Environment variable holding the home directory.
+pub const HOME_VAR: &str = "USERPROFILE";
+
+/// Keeps spawned helpers from flashing a console window.
+const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+
+// ── Files ─────────────────────────────────────────────────────────────────────
+
+/// %APPDATA%\Coucou — preferences.
+pub fn config_dir() -> PathBuf {
+ let base = std::env::var_os("APPDATA")
+ .map(PathBuf::from)
+ .unwrap_or_else(|| PathBuf::from("."));
+ base.join("Coucou")
+}
+
+/// %LOCALAPPDATA%\Coucou — where coucou-hook.exe, the inbox and the log live.
+pub fn local_dir() -> PathBuf {
+ let base = std::env::var_os("LOCALAPPDATA")
+ .map(PathBuf::from)
+ .unwrap_or_else(|| PathBuf::from("."));
+ base.join("Coucou")
+}
+
+pub fn local_time() -> LocalTime {
+ let t = unsafe { GetLocalTime() };
+ LocalTime {
+ year: t.wYear.into(),
+ month: t.wMonth.into(),
+ day: t.wDay.into(),
+ hour: t.wHour.into(),
+ minute: t.wMinute.into(),
+ second: t.wSecond.into(),
+ }
+}
+
+// ── Processes ─────────────────────────────────────────────────────────────────
+
+/// Spawned helpers must never flash a console window.
+pub fn no_console(cmd: &mut Command) -> &mut Command {
+ cmd.creation_flags(CREATE_NO_WINDOW)
+}
+
+pub fn open_url(url: &str) {
+ let _ = no_console(Command::new("rundll32.exe").args(["url.dll,FileProtocolHandler", url]))
+ .spawn();
+}
+
+pub fn reveal_folder(path: &str) {
+ let _ = Command::new("explorer").arg(path).spawn();
+}
+
+/// Our own `where`: walks %PATH% against %PATHEXT%, no shell involved.
+/// Rust quotes arguments correctly for `.cmd`/`.bat` targets since 1.77, so
+/// spawning `code.cmd` directly is safe.
+pub fn find_on_path(stem: &str) -> Option<PathBuf> {
+ let exts = std::env::var("PATHEXT").unwrap_or_else(|_| ".COM;.EXE;.BAT;.CMD".into());
+ let dirs = std::env::var_os("PATH")?;
+ for dir in std::env::split_paths(&dirs) {
+ for ext in exts.split(';').filter(|e| !e.is_empty()) {
+ let candidate = dir.join(format!("{stem}{}", ext.to_lowercase()));
+ if candidate.is_file() {
+ return Some(candidate);
+ }
+ }
+ }
+ None
+}
+
+// ── Who we are ────────────────────────────────────────────────────────────────
+//
+// Named pipes share one machine-wide namespace, so the SID in the name is what
+// keeps two accounts on the same machine from ever meeting on `coucou-*`.
+// coucou-hook computes the same string (hook/src/win.rs) and additionally checks
+// that the process serving the pipe really is us.
+
+/// The SID of the account this process runs as, as `S-1-5-21-…`.
+pub fn current_user_sid() -> Option<String> {
+ unsafe {
+ let mut token = HANDLE::default();
+ OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).ok()?;
+
+ // First call sizes the buffer, second fills it.
+ let mut needed = 0u32;
+ let _ = GetTokenInformation(token, TokenUser, None, 0, &mut needed);
+ if needed == 0 {
+ let _ = CloseHandle(token);
+ return None;
+ }
+ let mut buf = vec![0u8; needed as usize];
+ let ok = GetTokenInformation(
+ token,
+ TokenUser,
+ Some(buf.as_mut_ptr().cast()),
+ needed,
+ &mut needed,
+ )
+ .is_ok();
+ let _ = CloseHandle(token);
+ if !ok {
+ return None;
+ }
+
+ let user = &*(buf.as_ptr() as *const TOKEN_USER);
+ let mut text = PWSTR::null();
+ ConvertSidToStringSidW(user.User.Sid, &mut text).ok()?;
+ let sid = text.to_string().ok();
+ let _ = LocalFree(Some(HLOCAL(text.0 as *mut _)));
+ sid
+ }
+}
+
+// ── Cursor ────────────────────────────────────────────────────────────────────
+
+/// Cursor position in physical screen pixels.
+pub fn cursor_physical() -> Option<(f64, f64)> {
+ let mut p = POINT::default();
+ unsafe { GetCursorPos(&mut p).ok()? };
+ Some((p.x as f64, p.y as f64))
+}
+
+/// True while the left mouse button is held — the only signal we get that a
+/// drag might be in flight before it reaches the window.
+pub fn left_button_down() -> bool {
+ unsafe { (GetAsyncKeyState(VK_LBUTTON.0 as i32) as u16 & 0x8000) != 0 }
+}
+
+// ── Island window ─────────────────────────────────────────────────────────────
+
+fn hwnd_of(win: &WebviewWindow) -> Option<HWND> {
+ let raw = win.hwnd().ok()?.0 as isize;
+ if raw == 0 {
+ return None;
+ }
+ Some(HWND(raw as *mut _))
+}
+
+/// Lets dropped files reach the app again.
+///
+/// wry installs its drop target by walking the webview's child windows **once**,
+/// when the webview is created. WebView2 creates `Chrome_RenderWidgetHostHWND`
+/// later and registers its own target on it; being the innermost window, that one
+/// wins, and since the page has no HTML5 drop handler it refuses everything — the
+/// "no drop" cursor, with nothing reaching Tauri. Revoking it makes OLE fall
+/// through to the target wry registered on the parent widget, which is the one
+/// that feeds Tauri's drag events.
+///
+/// Cheap and idempotent, so it is simply re-run whenever a drag might be starting.
+pub fn unblock_webview_drops(app: &AppHandle) {
+ for label in [WINDOW_LABEL, "settings"] {
+ let Some(win) = app.get_webview_window(label) else { continue };
+ let Some(hwnd) = hwnd_of(&win) else { continue };
+ unsafe {
+ let _ = EnumChildWindows(Some(hwnd), Some(revoke_render_widget), LPARAM(0));
+ }
+ }
+}
+
+unsafe extern "system" fn revoke_render_widget(hwnd: HWND, _: LPARAM) -> BOOL {
+ let mut name = [0u16; 64];
+ let len = unsafe { GetClassNameW(hwnd, &mut name) };
+ if len > 0 {
+ let class = String::from_utf16_lossy(&name[..len as usize]);
+ if class == "Chrome_RenderWidgetHostHWND" {
+ let _ = unsafe { RevokeDragDrop(hwnd) };
+ }
+ }
+ true.into()
+}
+
+/// WS_EX_NOACTIVATE keeps clicks from stealing focus; WS_EX_TOOLWINDOW keeps the
+/// island out of Alt-Tab.
+pub fn make_non_activating(win: &WebviewWindow) {
+ let Some(hwnd) = hwnd_of(win) else { return };
+ unsafe {
+ let ex = GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
+ let want = ex | WS_EX_NOACTIVATE.0 as isize | WS_EX_TOOLWINDOW.0 as isize;
+ SetWindowLongPtrW(hwnd, GWL_EXSTYLE, want);
+ }
+}
+
+/// Temporarily allow activation so a text field inside the island can be typed in.
+pub fn set_activating(win: &WebviewWindow, activating: bool) {
+ let Some(hwnd) = hwnd_of(win) else { return };
+ unsafe {
+ let ex = GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
+ let want = if activating {
+ ex & !(WS_EX_NOACTIVATE.0 as isize)
+ } else {
+ ex | WS_EX_NOACTIVATE.0 as isize
+ };
+ SetWindowLongPtrW(hwnd, GWL_EXSTYLE, want);
+ }
+}
diff --git a/windows/src-tauri/src/secrets.rs b/windows/src-tauri/src/secrets.rs
index 06296d1f..5c37b652 100644
--- a/windows/src-tauri/src/secrets.rs
+++ b/windows/src-tauri/src/secrets.rs
@@ -1,5 +1,5 @@
-// API keys live in the Windows Credential Manager, never on disk and never in
-// the front end — the island can only ask whether a key is present.
+// API keys live in the Windows Credential Manager or, on Linux, the Secret
+// Service (GNOME Keyring, KWallet) — never on disk and never in the front end — the island can only ask whether a key is present.
use keyring::Entry;
diff --git a/windows/src-tauri/src/settings.rs b/windows/src-tauri/src/settings.rs
index 27071798..effac511 100644
--- a/windows/src-tauri/src/settings.rs
+++ b/windows/src-tauri/src/settings.rs
@@ -1,5 +1,5 @@
-// Preferences, stored as plain JSON in %APPDATA%\Coucou\settings.json.
-// No secret ever lands here — API keys live in the Windows Credential Manager.
+// Preferences, stored as plain JSON in settings.json under platform::config_dir().
+// No secret ever lands here — API keys live in the OS keychain (see secrets.rs).
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
@@ -47,24 +47,10 @@ impl Default for Settings {
}
}
-/// %APPDATA%\Coucou
-pub fn config_dir() -> PathBuf {
- let base = std::env::var_os("APPDATA")
- .map(PathBuf::from)
- .unwrap_or_else(|| PathBuf::from("."));
- base.join("Coucou")
-}
-
-/// %LOCALAPPDATA%\Coucou — where coucou-hook.exe and the log live.
-pub fn local_dir() -> PathBuf {
- let base = std::env::var_os("LOCALAPPDATA")
- .map(PathBuf::from)
- .unwrap_or_else(|| PathBuf::from("."));
- base.join("Coucou")
-}
+pub use crate::platform::{config_dir, local_dir};
pub fn hook_exe_path() -> PathBuf {
- local_dir().join("bin").join("coucou-hook.exe")
+ local_dir().join("bin").join(crate::platform::HOOK_EXE)
}
fn settings_path() -> PathBuf {
diff --git a/windows/src-tauri/src/win_user.rs b/windows/src-tauri/src/win_user.rs
deleted file mode 100644
index 001b759d..00000000
--- a/windows/src-tauri/src/win_user.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-// Who we are, for the relay pipe name.
-//
-// Named pipes share one machine-wide namespace, so the SID in the name is what
-// keeps two accounts on the same machine from ever meeting on `coucou-*`.
-// coucou-hook computes the same string (hook/src/win.rs) and additionally checks
-// that the process serving the pipe really is us.
-
-use windows::core::PWSTR;
-use windows::Win32::Foundation::{CloseHandle, HANDLE, HLOCAL, LocalFree};
-use windows::Win32::Security::Authorization::ConvertSidToStringSidW;
-use windows::Win32::Security::{GetTokenInformation, TokenUser, TOKEN_QUERY, TOKEN_USER};
-use windows::Win32::System::Threading::{GetCurrentProcess, OpenProcessToken};
-
-/// The SID of the account this process runs as, as `S-1-5-21-…`.
-pub fn current_user_sid() -> Option<String> {
- unsafe {
- let mut token = HANDLE::default();
- OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).ok()?;
-
- // First call sizes the buffer, second fills it.
- let mut needed = 0u32;
- let _ = GetTokenInformation(token, TokenUser, None, 0, &mut needed);
- if needed == 0 {
- let _ = CloseHandle(token);
- return None;
- }
- let mut buf = vec![0u8; needed as usize];
- let ok = GetTokenInformation(
- token,
- TokenUser,
- Some(buf.as_mut_ptr().cast()),
- needed,
- &mut needed,
- )
- .is_ok();
- let _ = CloseHandle(token);
- if !ok {
- return None;
- }
-
- let user = &*(buf.as_ptr() as *const TOKEN_USER);
- let mut text = PWSTR::null();
- ConvertSidToStringSidW(user.User.Sid, &mut text).ok()?;
- let sid = text.to_string().ok();
- let _ = LocalFree(Some(HLOCAL(text.0 as *mut _)));
- sid
- }
-}
diff --git a/windows/src-tauri/tauri.linux.conf.json b/windows/src-tauri/tauri.linux.conf.json
new file mode 100644
index 00000000..9d3dada0
--- /dev/null
+++ b/windows/src-tauri/tauri.linux.conf.json
@@ -0,0 +1,6 @@
+{
+ "$schema": "https://schema.tauri.app/config/2",
+ "bundle": {
+ "resources": []
+ }
+}