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.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Windows: take file drops from every Explorer view, and make Cancel work
KauaDc5f7dfacae085
diff --git a/windows/Cargo.lock b/windows/Cargo.lockindex 6278c752..489bfbf8 100644--- a/windows/Cargo.lock+++ b/windows/Cargo.lock@@ -623,7 +623,9 @@ dependencies = ["tauri-plugin-autostart","tauri-plugin-single-instance","tokio",+ "webview2-com","windows 0.61.3",+ "windows-core 0.62.2",][[package]]diff --git a/windows/src-tauri/Cargo.toml b/windows/src-tauri/Cargo.tomlindex f581867d..3b9bcc91 100644--- a/windows/src-tauri/Cargo.toml+++ b/windows/src-tauri/Cargo.toml@@ -24,6 +24,10 @@ reqwest = { version = "0.12", default-features = false, features = ["json", "rus[target.'cfg(windows)'.dependencies]keyring = { version = "3", features = ["windows-native"] }+# The island's file drop reads paths straight from WebView2 (webview_drop.rs).+# Same versions as wry, so nothing new is compiled.+webview2-com = "0.39"+wv2_core = { package = "windows-core", version = "0.62" }windows = { version = "0.61", features = ["Win32_Foundation","Win32_Security",diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rsindex 714103e5..b7583383 100644--- a/windows/src-tauri/src/lib.rs+++ b/windows/src-tauri/src/lib.rs@@ -11,6 +11,8 @@ mod platform;mod secrets;mod settings;mod tray;+#[cfg(windows)]+mod webview_drop;use std::process::Command;use std::sync::atomic::Ordering;@@ -410,6 +412,8 @@ pub fn run() {if let Some(win) = island::window(&handle) {platform::make_non_activating(&win);+ #[cfg(windows)]+ webview_drop::install(&handle);island::apply_geometry(&handle, &loaded.screen, false);let _ = win.show();}diff --git a/windows/src-tauri/src/platform/windows.rs b/windows/src-tauri/src/platform/windows.rsindex 6e1200a8..fca91ed1 100644--- a/windows/src-tauri/src/platform/windows.rs+++ b/windows/src-tauri/src/platform/windows.rs@@ -20,7 +20,6 @@ use ::windows::Win32::UI::WindowsAndMessaging::{};use super::LocalTime;-use crate::island::WINDOW_LABEL;/// File name of the Claude Code relay.pub const HOOK_EXE: &str = "coucou-hook.exe";@@ -173,24 +172,22 @@ fn hwnd_of(win: &WebviewWindow) -> Option<HWND> {Some(HWND(raw as *mut _))}-/// Lets dropped files reach the app again.+/// Keeps the settings window from showing the "no drop" cursor.////// 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.+/// wins, and since the page has no HTML5 drop handler it refuses everything.+/// Revoking it makes OLE fall through to wry's target. The island is the other+/// way round: it takes drops through WebView2's own target (see webview_drop.rs),+/// so its windows are left alone.////// 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));- }+ let Some(win) = app.get_webview_window("settings") else { return };+ let Some(hwnd) = hwnd_of(&win) else { return };+ unsafe {+ let _ = EnumChildWindows(Some(hwnd), Some(revoke_render_widget), LPARAM(0));}}diff --git a/windows/src-tauri/src/webview_drop.rs b/windows/src-tauri/src/webview_drop.rsnew file mode 100644index 00000000..4a729c8b--- /dev/null+++ b/windows/src-tauri/src/webview_drop.rs@@ -0,0 +1,69 @@+// Files dropped on the island, taken by WebView2 itself.+//+// Tauri's drag-drop goes through drop targets wry registers on the webview's+// child windows. The innermost windows, though, belong to msedgewebview2.exe,+// and drags from the classic Explorer folder view (Downloads, Documents…) never+// walked up to wry's target: "no drop" cursor, nothing reached the app. Only the+// newer WinUI views (Home, Recent) got through.+//+// So `dragDropEnabled` is off for the island and WebView2 takes drops the way+// Edge does. The page accepts the HTML5 drag (src/core/bridge.ts) and hands the+// dropped File objects back with `chrome.webview.postMessageWithAdditionalObjects`;+// here they turn back into real paths and reach the island as a `file-drag` drop.++use tauri::{AppHandle, Emitter};+use webview2_com::Microsoft::Web::WebView2::Win32::{+ ICoreWebView2File, ICoreWebView2WebMessageReceivedEventArgs2,+};+use webview2_com::{take_pwstr, WebMessageReceivedEventHandler};+use wv2_core::{Interface, PWSTR};++use crate::island::{self, WINDOW_LABEL};++#[derive(serde::Serialize, Clone)]+struct FileDrop {+ #[serde(rename = "type")]+ kind: &'static str,+ paths: Vec<String>,+}++pub fn install(app: &AppHandle) {+ let Some(win) = island::window(app) else { return };+ let handle = app.clone();+ let result = win.with_webview(move |webview| unsafe {+ let core = match webview.controller().CoreWebView2() {+ Ok(core) => core,+ Err(err) => {+ crate::log::line(format!("file drop: no webview: {err}"));+ return;+ }+ };+ let handler = WebMessageReceivedEventHandler::create(Box::new(move |_, args| {+ let Some(args) = args else { return Ok(()) };+ // Tauri's own IPC messages come through here too; they carry no objects.+ let Ok(args) = args.cast::<ICoreWebView2WebMessageReceivedEventArgs2>() else { return Ok(()) };+ let Ok(objects) = args.AdditionalObjects() else { return Ok(()) };+ let mut count = 0u32;+ objects.Count(&mut count)?;+ if count == 0 {+ return Ok(());+ }+ let mut paths = Vec::new();+ for i in 0..count {+ let Ok(file) = objects.GetValueAtIndex(i)?.cast::<ICoreWebView2File>() else { continue };+ let mut path = PWSTR::null();+ file.Path(&mut path)?;+ paths.push(take_pwstr(path));+ }+ let _ = handle.emit_to(WINDOW_LABEL, "file-drag", FileDrop { kind: "drop", paths });+ Ok(())+ }));+ let mut token = 0i64;+ if let Err(err) = core.add_WebMessageReceived(&handler, &mut token) {+ crate::log::line(format!("file drop: cannot listen: {err}"));+ }+ });+ if let Err(err) = result {+ crate::log::line(format!("file drop: {err}"));+ }+}diff --git a/windows/src-tauri/tauri.conf.json b/windows/src-tauri/tauri.conf.jsonindex 2196b815..5d2f0282 100644--- a/windows/src-tauri/tauri.conf.json+++ b/windows/src-tauri/tauri.conf.json@@ -34,7 +34,7 @@"maximizable": false,"minimizable": false,"closable": false,- "dragDropEnabled": true,+ "dragDropEnabled": false,"additionalBrowserArgs": "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --autoplay-policy=no-user-gesture-required"}]diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.tsindex 24aaf55f..774ab1b5 100644--- a/windows/src/core/bridge.ts+++ b/windows/src/core/bridge.ts@@ -150,12 +150,70 @@ export interface DragDropPayload {paths?: string[];}-/** Files dragged onto the island. Only reaches us when the window takes the mouse. */+interface WebView2Bridge {+ postMessageWithAdditionalObjects(message: unknown, objects: ArrayLike<unknown>): void;+}++/**+ * Files dragged onto the island. Only reaches us when the window takes the mouse.+ *+ * On Windows WebView2 takes the drop itself, as in Edge — Tauri's drop handling+ * never sees drags from the classic Explorer folder view (see+ * src-tauri/src/webview_drop.rs). Enter/over/leave come straight from the page;+ * the drop hands the File objects to Rust, which answers with their real paths+ * as a `file-drag` event. Elsewhere (Linux) Tauri's own drag events still do it.+ */export async function onDragDrop(handler: (e: DragDropPayload) => void) {if (!IS_TAURI) return () => {};- return getCurrentWebview().onDragDropEvent((event) => {- handler(event.payload as DragDropPayload);- });+ const webview = (window as unknown as { chrome?: { webview?: WebView2Bridge } }).chrome?.webview;+ if (!webview) {+ return getCurrentWebview().onDragDropEvent((event) => {+ handler(event.payload as DragDropPayload);+ });+ }+ const hasFiles = (e: DragEvent) => e.dataTransfer?.types.includes("Files") ?? false;+ // dragenter/dragleave fire for every element crossed; only the outermost pair counts.+ let depth = 0;++ const onEnter = (e: DragEvent) => {+ if (!hasFiles(e)) return;+ e.preventDefault();+ if (depth++ === 0) handler({ type: "enter" });+ };+ const onOver = (e: DragEvent) => {+ if (!hasFiles(e)) return;+ // Without this WebView2 refuses the drop — or navigates to the file.+ e.preventDefault();+ if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";+ handler({ type: "over" });+ };+ const onLeave = (e: DragEvent) => {+ if (!hasFiles(e) || depth === 0) return;+ if (--depth === 0) handler({ type: "leave" });+ };+ const onDrop = (e: DragEvent) => {+ e.preventDefault();+ depth = 0;+ const files = e.dataTransfer?.files;+ if (!files || files.length === 0) {+ handler({ type: "drop", paths: [] });+ return;+ }+ webview.postMessageWithAdditionalObjects("coucou-file-drop", files);+ };++ window.addEventListener("dragenter", onEnter);+ window.addEventListener("dragover", onOver);+ window.addEventListener("dragleave", onLeave);+ window.addEventListener("drop", onDrop);+ const unlisten = await listen<DragDropPayload>("file-drag", (e) => handler(e.payload));+ return () => {+ window.removeEventListener("dragenter", onEnter);+ window.removeEventListener("dragover", onOver);+ window.removeEventListener("dragleave", onLeave);+ window.removeEventListener("drop", onDrop);+ unlisten();+ };}export async function onEvent<T>(name: string, handler: (payload: T) => void) {diff --git a/windows/src/island/island.ts b/windows/src/island/island.tsindex 7fdb6180..a942435f 100644--- a/windows/src/island/island.ts+++ b/windows/src/island/island.ts@@ -106,6 +106,7 @@ export class Island {private build() {const actions: ViewActions = {setView: (v) => this.setView(v),+ cancelDrop: () => this.discardDrop(),collapse: () => this.collapse(),setFocus: (id) => {State.setFocus(id);@@ -191,7 +192,7 @@ export class Island {: null;this.setView("prompt");},- cancel: () => this.setView(State.defaultView()),+ cancel: () => this.discardDrop(),});this.clipEl = h(@@ -406,11 +407,14 @@ export class Island {void Bridge.ingestFile(path).then((file) => {+ // Cancelled (or replaced by another drop) while the copy was running.+ if (State.droppedFile?.path !== path) return;State.droppedFile = { name: file.name, path: file.path };State.promptContext = { kind: "file", name: file.name, path: file.path };State.notify();}).catch((err) => {+ if (State.droppedFile?.path !== path) return;UploadSeq.deactivate();State.noteMessage = String(err).replace(/^Error:\s*/, "");this.engine.animateMorph(0);@@ -420,6 +424,13 @@ export class Island {});}+ /** "Cancel" on the dropped file: forget it, so the chat does not pick it up. */+ private discardDrop() {+ State.droppedFile = null;+ State.promptContext = null;+ this.setView(State.defaultView());+ }+/*** Sounds and view changes hung off the canvas timeline: a `tick` every 10 %,* the ✓ chime when the bar completes, then `choose` once Mochi has grown back.@@ -836,8 +847,12 @@ export class Island {const expanded = State.mode === "expanded";const greetingActive = expanded && State.view === "greeting";- this.contentEl.style.opacity = expanded && !greetingActive ? "1" : "0";- this.contentEl.style.pointerEvents = expanded && !greetingActive ? "auto" : "none";+ const live = expanded && !greetingActive;+ this.contentEl.style.opacity = live ? "1" : "0";+ // While the drop sequence owns the body its buttons are painted on the canvas+ // underneath, so only the header may keep taking clicks up here.+ this.contentEl.style.pointerEvents = live && !this.uploadActive ? "auto" : "none";+ this.header.el.style.pointerEvents = live ? "auto" : "none";this.greetingCanvas.style.display = greetingActive ? "block" : "none";this.header.sync();diff --git a/windows/src/style.css b/windows/src/style.cssindex b2cf6756..a4168add 100644--- a/windows/src/style.css+++ b/windows/src/style.css@@ -126,13 +126,19 @@ body {cursor: pointer;}-/* The ordinary views step aside while the sequence owns the body. */+/* The ordinary views step aside while the sequence owns the body. The active+ view sets pointer-events back to auto, which beats the parent's none: it has+ to be switched off too, or its invisible card swallows the canvas buttons. */#views.hidden-by-upload {opacity: 0;pointer-events: none;transition: opacity 0.22s ease-in-out;}+#views.hidden-by-upload .view.on {+ pointer-events: none;+}+#bot-glow {position: absolute;pointer-events: none;diff --git a/windows/src/views/upload.ts b/windows/src/views/upload.tsindex 714060ff..bb8e1fac 100644--- a/windows/src/views/upload.ts+++ b/windows/src/views/upload.ts@@ -97,7 +97,7 @@ export function buildChoose(actions: ViewActions): ViewHost {h("button", {class: "btn secondary",text: "Cancel",- onclick: () => actions.setView(State.defaultView()),+ onclick: () => actions.cancelDrop(),}),);const el = h(diff --git a/windows/src/views/views.ts b/windows/src/views/views.tsindex ac0ac7b6..e4a17581 100644--- a/windows/src/views/views.ts+++ b/windows/src/views/views.ts@@ -14,6 +14,8 @@ import { renderIntegrationCard, type IntegrationCardHooks } from "./integrationsexport interface ViewActions {setView(v: IslandViewName): void;+ /** "Cancel" on a dropped file: forgets it and goes back home. */+ cancelDrop(): void;collapse(): void;setFocus(id: string): void;openTerminal(): void;