A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.
TypeScript
feat(desktop): turn computer control on for Windows
Marcelito13d98ba01872
diff --git a/apps/desktop/src-tauri/src/computer/app.rs b/apps/desktop/src-tauri/src/computer/app.rsindex 79d0da8..8d605ed 100644--- a/apps/desktop/src-tauri/src/computer/app.rs+++ b/apps/desktop/src-tauri/src/computer/app.rs@@ -1,6 +1,6 @@//! The app side of computer control (L60): the `computer_*` commands, the `computer://state`-//! event, the panic shortcut, the timeout watcher, and the native dialogs. Off macOS the-//! commands answer "unavailable" and nothing starts. Yolo mode (S24.9) is switched only from+//! event, the panic shortcut, the timeout watcher, and the native dialogs. Off macOS and Windows+//! the commands answer "unavailable" and nothing starts. Yolo mode (S24.9) is switched only from//! here (`computer_set_yolo` and the tray item), never from the MCP helper or the daemon.//!//! The glow (S28): a click-through overlay window (`glow`) is ordered in while a session is@@ -16,7 +16,7 @@ use super::control::Control;use super::server::Endpoint;use super::session::{Reason, StateEvent};use super::working::Windows;-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]use super::working::{MainThread, Rings, Task, Working, WorkingEvent, READY_TIMEOUT, WORKING_EVENT};use super::{Clock, PermissionKind, Permissions, SystemClock};use crate::alert::Choice;@@ -30,12 +30,19 @@ pub const GLOW_WINDOW: &str = "glow";pub const GLOW_TITLE: &str = "Gentle Dot Glow";/// ⌥⇧Esc ends the session from anywhere (S24.3).pub const PANIC_SHORTCUT: &str = "Alt+Shift+Escape";+#[cfg(not(windows))]pub const GRANT_TEXT: &str = "Allow Gentle Dot to see and control this Mac for 30 minutes?";+#[cfg(windows)]+pub const GRANT_TEXT: &str = "Allow Gentle Dot to see and control this PC for 30 minutes?";/// Every computer-control dialog defaults to its refusing button (L75 A2).pub const GRANT_CHOICE: Choice = Choice { allow: "Allow", refuse: "Deny" };pub const CONFIRM_CHOICE: Choice = Choice { allow: "Allow", refuse: "Cancel" };+#[cfg(not(windows))]pub const YOLO_TEXT: &str = "Turn on yolo mode? Gentle Dot will send, pay, delete, and submit without asking you first, \for up to 1 hour. Stop and ⌥⇧Esc still work.";+#[cfg(windows)]+pub const YOLO_TEXT: &str = "Turn on yolo mode? Gentle Dot will send, pay, delete, and submit without asking you first, \+for up to 1 hour. Stop and Alt+Shift+Esc still work.";pub const YOLO_CHOICE: Choice = Choice { allow: "Turn On", refuse: "Cancel" };/// The tray's "Yolo mode" item, kept in step with the state.@@ -44,15 +51,15 @@ pub struct YoloMenuItem(pub tauri::menu::CheckMenuItem<tauri::Wry>);pub struct Computer {control: Arc<Control>,endpoint: Option<Endpoint>,- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]desktop: Arc<dyn super::Desktop>,- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]working: Arc<Working>,}/// What the overlay thread hears: the session started or ended, the agent acted, or a call/// starts (answered once the rings were told to draw, or why not) or ends its working rings.-#[cfg_attr(not(target_os = "macos"), allow(dead_code))]+#[cfg_attr(not(any(target_os = "macos", windows)), allow(dead_code))]enum Overlay {Session(bool),Mark(super::glow::Mark),@@ -65,10 +72,10 @@ enum Overlay {const OVERLAY_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(1);/// The overlay's working rings, through the overlay thread.-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]struct OverlayRings(std::sync::mpsc::Sender<Overlay>);-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]impl Rings for OverlayRings {fn show(&self, operation: u64) -> Result<(), String> {let (reply, answer) = std::sync::mpsc::channel();@@ -81,10 +88,10 @@ impl Rings for OverlayRings {}}-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]struct AppMainThread(AppHandle);-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]impl MainThread for AppMainThread {fn run(&self, task: Task) -> Result<(), String> {self.0.run_on_main_thread(task).map_err(|error| error.to_string())@@ -101,32 +108,59 @@ pub fn show_without_focus(window: &tauri::WebviewWindow) -> Result<(), String> {Ok(())}+#[cfg(windows)]+pub fn show_without_focus(window: &tauri::WebviewWindow) -> Result<(), String> {+ super::win::show_without_activating(window.hwnd().map_err(|e| e.to_string())?.0);+ Ok(())+}++// Both sides bypass tao so its visibility flag continues to represent the user's choice.+#[cfg(windows)]+pub fn hide_for_call(window: &tauri::WebviewWindow) -> Result<(), String> {+ super::win::hide_window(window.hwnd().map_err(|e| e.to_string())?.0);+ Ok(())+}++/// A window of Gentle Dot is shown or hidden through tao (the panel, the Dot) while the returned+/// change lives: a computer-control capture overlapping it is not returned.+#[cfg(windows)]+pub(crate) fn window_change() -> super::win::WindowChange {+ super::win::WindowChange::begin()+}++#[cfg(windows)]+pub fn set_shown(window: &tauri::WebviewWindow, shown: bool) -> Result<(), String> {+ let hwnd = window.hwnd().map_err(|e| e.to_string())?.0;+ if shown { super::win::show_window(hwnd); } else { super::win::hide_window(hwnd); }+ Ok(())+}+impl Computer {/// The helper's address and key for this launch, registered with the daemon over the app's- /// channel (S24.7, L61); `None` off macOS or when the helper did not start.+ /// channel (S24.7, L61); `None` off macOS and Windows or when the helper did not start.pub fn endpoint(&self) -> Option<Endpoint> {self.endpoint.clone()}}-/// Creates the session and, on macOS, starts the MCP helper, the timeout watcher, and the+/// Creates the session and, on macOS and Windows, starts the MCP helper, the timeout watcher, and the/// glow overlay. `windows` are the Dot and the panel, hidden during each call (S1). Runs in the/// app's setup, on the main thread.pub fn start(app: &AppHandle, windows: Arc<dyn Windows>) -> Computer {let (overlay, marks) = std::sync::mpsc::channel::<Overlay>();- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]let working = Arc::new(Working::new(windows,Arc::new(OverlayRings(overlay.clone())),Arc::new(AppMainThread(app.clone())),READY_TIMEOUT,));- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]let session_ended = {let working = working.clone();move || working.session_ended()};- #[cfg(not(target_os = "macos"))]+ #[cfg(not(any(target_os = "macos", windows)))]let session_ended = {drop(windows);|| {}@@ -165,20 +199,33 @@ pub fn start(app: &AppHandle, windows: Arc<dyn Windows>) -> Computer {}Computer { control, endpoint, desktop, working }}- #[cfg(not(target_os = "macos"))]+ #[cfg(windows)]+ {+ let desktop: Arc<dyn super::Desktop> = Arc::new(super::win::WinDesktop);+ let glow = move |mark| { let _ = overlay.send(Overlay::Mark(mark)); };+ let endpoint = start_helper(app, control.clone(), desktop.clone(), glow, working.clone())+ .map_err(|error| eprintln!("gentle-dot: computer control is unavailable: {error}")).ok();+ watch_timeout(control.clone());+ match build_glow(app) {+ Ok(window) => run_glow(app.clone(), window, control.clone(), working.clone(), marks),+ Err(error) => eprintln!("gentle-dot: the computer-control glow is unavailable: {error}"),+ }+ Computer { control, endpoint, desktop, working }+ }+ #[cfg(not(any(target_os = "macos", windows)))]{drop((overlay, marks));Computer { control, endpoint: None }}}-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]fn start_helper(app: &AppHandle,control: Arc<Control>,desktop: Arc<dyn super::Desktop>,glow: impl Fn(super::glow::Mark) + Send + Sync + 'static,- working: Arc<Working>,+ working: Arc<dyn super::working::Preparation>,) -> std::io::Result<Endpoint> {let token = super::server::new_token();let helper = super::mcp::Helper::new(@@ -266,7 +313,7 @@ fn cover(window: &tauri::WebviewWindow, covering: &mut Option<super::glow::Frame}}-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]fn emit_working(app: &AppHandle, operation: u64, active: bool) -> Result<(), String> {let event = WorkingEvent { active, operation_id: operation };app.emit_to(GLOW_WINDOW, WORKING_EVENT, event).map_err(|error| error.to_string())@@ -292,7 +339,7 @@ fn run_overlay(let _ = order_overlay(&app, ns_window, &number, active);shown = active;}- if let Some(operation) = drawing.take().filter(|_| !active) {+ if let Some(operation) = super::working::session_clears(&mut drawing, active) {let _ = emit_working(&app, operation, false);}}@@ -354,8 +401,78 @@ fn run_overlay(}}+/// A click-through, non-activating overlay excluded from capture.+#[cfg(windows)]+fn build_glow(app: &AppHandle) -> Result<tauri::WebviewWindow, String> {+ let window = tauri::WebviewWindowBuilder::new(app, GLOW_WINDOW, tauri::WebviewUrl::App("index.html?surface=glow".into()))+ .title(GLOW_TITLE).inner_size(1.0, 1.0).position(0.0, 0.0).transparent(true)+ .decorations(false).always_on_top(true).resizable(false).skip_taskbar(true)+ .shadow(false).focused(false).focusable(false).visible(false).build().map_err(|error| error.to_string())?;+ window.set_ignore_cursor_events(true).map_err(|error| error.to_string())?;+ if let Err(error) = super::win::prepare_overlay(window.hwnd().map_err(|error| error.to_string())?.0) {+ let _ = window.close();+ return Err(error);+ }+ Ok(window)+}++#[cfg(windows)]+fn run_glow(app: AppHandle, window: tauri::WebviewWindow, control: Arc<Control>, working: Arc<Working>, marks: std::sync::mpsc::Receiver<Overlay>) {+ let Ok(hwnd) = window.hwnd() else {+ eprintln!("gentle-dot: the computer-control glow is unavailable: no window handle");+ return;+ };+ let hwnd = hwnd.0 as usize;+ let spawned = std::thread::Builder::new().name("computer-glow".into()).spawn(move || {+ let window = hwnd as *mut std::ffi::c_void;+ let (mut shown, mut covering, mut drawing) = (false, None, None);+ for message in marks {+ match message {+ Overlay::Session(active) => {+ if active != shown { super::win::show_overlay(window, active); shown = active; }+ if let Some(operation) = super::working::session_clears(&mut drawing, active) {+ let _ = emit_working(&app, operation, false);+ }+ }+ Overlay::Working { operation, reply } => {+ let outcome = if !control.is_active(SystemClock.now_ms()) || !working.is_current(operation) {+ Err("the call already ended".to_string())+ } else {+ match super::win::pointer_location().and_then(super::win::display_frame_at) {+ None => Err("no display under the pointer".to_string()),+ Some(display) => {+ if covering != Some(display) { super::win::cover(window, display); covering = Some(display); }+ super::win::show_overlay(window, true);+ shown = true;+ drawing = Some(operation);+ emit_working(&app, operation, true)+ }+ }+ };+ let _ = reply.send(outcome);+ }+ Overlay::WorkingEnd(operation) => {+ if drawing == Some(operation) { drawing = None; let _ = emit_working(&app, operation, false); }+ }+ Overlay::Mark(mark) => {+ if !control.is_active(SystemClock.now_ms()) { continue; }+ let placed = super::glow::place(mark, super::win::display_frame_at, super::win::focused_frame);+ let Some((display, event)) = placed else { continue };+ if covering != Some(display) { super::win::cover(window, display); covering = Some(display); }+ if !shown { super::win::show_overlay(window, true); shown = true; }+ let event = super::glow::in_css_pixels(event, super::win::display_scale(display));+ if let Err(error) = app.emit_to(GLOW_WINDOW, GLOW_EVENT, event) {+ eprintln!("gentle-dot: cannot draw the glow: {error}");+ }+ }+ }+ }+ });+ if let Err(error) = spawned { eprintln!("gentle-dot: the computer-control glow is unavailable: {error}"); }+}+/// Reports the timeout when it happens, not only at the next tool call.-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]fn watch_timeout(control: Arc<Control>) {std::thread::spawn(move || loop {std::thread::sleep(std::time::Duration::from_secs(1));@@ -377,9 +494,9 @@ pub fn computer_endpoint(computer: State<'_, Computer>) -> Option<Endpoint> {#[tauri::command]pub fn computer_permissions(computer: State<'_, Computer>) -> Permissions {- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]return computer.desktop.permissions();- #[cfg(not(target_os = "macos"))]+ #[cfg(not(any(target_os = "macos", windows)))]{let _ = computer;Permissions { accessibility: false, screen_recording: false, screenshots_supported: false }@@ -390,7 +507,9 @@ pub fn computer_permissions(computer: State<'_, Computer>) -> Permissions {pub fn computer_request_permission(kind: PermissionKind) -> Result<(), String> {#[cfg(target_os = "macos")]return super::request_permission(kind);- #[cfg(not(target_os = "macos"))]+ #[cfg(windows)]+ { let _ = kind; Ok(()) }+ #[cfg(not(any(target_os = "macos", windows)))]{let _ = kind;Err("Computer control is only available on macOS.".into())@@ -410,9 +529,9 @@ pub fn computer_working_ready(computer: State<'_, Computer>,operation_id: u64,) -> Result<bool, String> {- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]return computer.working.acknowledge(window.label(), operation_id);- #[cfg(not(target_os = "macos"))]+ #[cfg(not(any(target_os = "macos", windows)))]{let _ = (window, computer, operation_id);Err("Computer control is only available on macOS.".into())@@ -423,9 +542,9 @@ pub fn computer_working_ready(/// off the main thread; the tray item calls it from a thread of its own.pub fn set_yolo(app: &AppHandle, enabled: bool) -> Result<StateEvent, String> {let computer = app.try_state::<Computer>().ok_or("Computer control is not ready.")?;- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]return Ok(computer.control.set_yolo(enabled, SystemClock.now_ms(), &NativeDialogs { app: app.clone() }));- #[cfg(not(target_os = "macos"))]+ #[cfg(not(any(target_os = "macos", windows)))]{let _ = (computer, enabled);Err("Computer control is only available on macOS.".into())@@ -454,19 +573,19 @@ pub fn computer_status(computer: State<'_, Computer>) -> StateEvent {}/// Dialogs shown by the app itself (an `NSAlert`, see `alert`), never the webview.-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]struct NativeDialogs {app: AppHandle,}-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]impl NativeDialogs {fn ask(&self, message: &str, choice: Choice) -> bool {crate::alert::ask(&self.app, "Gentle Dot", message, choice)}}-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]impl super::Dialogs for NativeDialogs {fn ask_grant(&self) -> bool {self.ask(GRANT_TEXT, GRANT_CHOICE)@@ -486,12 +605,14 @@ mod tests {use super::*;#[test]+ #[cfg(not(windows))]fn the_grant_dialog_asks_exactly_what_the_spec_says() {assert_eq!(GRANT_TEXT, "Allow Gentle Dot to see and control this Mac for 30 minutes?");assert_eq!(GRANT_CHOICE, Choice { allow: "Allow", refuse: "Deny" });}#[test]+ #[cfg(not(windows))]fn the_yolo_dialog_says_what_it_skips_and_for_how_long() {assert_eq!(YOLO_TEXT,@@ -501,12 +622,25 @@ for up to 1 hour. Stop and ⌥⇧Esc still work."assert_eq!(YOLO_CHOICE, Choice { allow: "Turn On", refuse: "Cancel" });}+ #[test]+ #[cfg(windows)]+ fn windows_dialogs_name_the_pc_and_panic_shortcut() {+ assert_eq!(GRANT_TEXT, "Allow Gentle Dot to see and control this PC for 30 minutes?");+ assert_eq!(GRANT_CHOICE, Choice { allow: "Allow", refuse: "Deny" });+ assert_eq!(YOLO_TEXT, "Turn on yolo mode? Gentle Dot will send, pay, delete, and submit without asking you first, \+for up to 1 hour. Stop and Alt+Shift+Esc still work.");+ assert_eq!(YOLO_CHOICE, Choice { allow: "Turn On", refuse: "Cancel" });+ }+#[test]fn every_computer_dialog_defaults_to_its_refusing_button() {for choice in [GRANT_CHOICE, CONFIRM_CHOICE, YOLO_CHOICE] {assert_eq!(choice.alert_buttons(), [choice.refuse, choice.allow]);assert!(!choice.allows_response(Some(crate::alert::REFUSE_RESPONSE)));assert!(!choice.allows_response(None));+ assert!(!choice.allows_task_button(Some(crate::alert::TASK_REFUSE_ID)));+ assert!(!choice.allows_task_button(None));+ assert!(choice.allows_task_button(Some(crate::alert::TASK_ALLOW_ID)));}}diff --git a/apps/desktop/src-tauri/src/computer/glow.rs b/apps/desktop/src-tauri/src/computer/glow.rsindex 60884d0..d63aa67 100644--- a/apps/desktop/src-tauri/src/computer/glow.rs+++ b/apps/desktop/src-tauri/src/computer/glow.rs@@ -105,9 +105,26 @@ pub fn place(Some((display, GlowEvent { x, y, to_x: to.map(|t| t.0), to_y: to.map(|t| t.1), ..event }))}+/// Convert physical-pixel marks to the overlay page's CSS pixels.+#[cfg(any(windows, test))]+pub fn in_css_pixels(event: GlowEvent, scale: f64) -> GlowEvent {+ if !scale.is_finite() || scale <= 0.0 || scale == 1.0 { return event; }+ let css = |value: f64| value / scale;+ GlowEvent { x: css(event.x), y: css(event.y), to_x: event.to_x.map(css), to_y: event.to_y.map(css), width: event.width.map(css), height: event.height.map(css), ..event }+}+#[cfg(test)]mod tests {use super::*;++ #[test]+ fn windows_marks_are_turned_into_the_pages_css_pixels() {+ let drag = GlowEvent { kind: GlowKind::Drag, x: 300.0, y: 150.0, to_x: Some(600.0), to_y: Some(90.0), width: None, height: None };+ assert_eq!(in_css_pixels(drag, 1.5), GlowEvent { kind: GlowKind::Drag, x: 200.0, y: 100.0, to_x: Some(400.0), to_y: Some(60.0), width: None, height: None });+ let key = GlowEvent { kind: GlowKind::Key, x: 20.0, y: 40.0, to_x: None, to_y: None, width: Some(200.0), height: Some(50.0) };+ assert_eq!(in_css_pixels(key, 2.0), GlowEvent { kind: GlowKind::Key, x: 10.0, y: 20.0, to_x: None, to_y: None, width: Some(100.0), height: Some(25.0) });+ for scale in [1.0, 0.0, -1.0, f64::NAN] { assert_eq!(in_css_pixels(key, scale), key, "{scale}"); }+ }use serde_json::json;/// Two displays side by side: the main one at the origin, a second one to its right.diff --git a/apps/desktop/src-tauri/src/computer/mod.rs b/apps/desktop/src-tauri/src/computer/mod.rsindex f9cc9bd..7f45a12 100644--- a/apps/desktop/src-tauri/src/computer/mod.rs+++ b/apps/desktop/src-tauri/src/computer/mod.rs@@ -22,12 +22,7 @@ pub mod risk;pub mod server;pub mod session;pub mod windows;-// The Windows desktop backend: input, capture, apps, keys bound to the approved recipient, UI-// Automation, its `Desktop` implementation, and the overlay the app drives. The app starts using-// it when computer control is turned on for Windows, which removes this allow. Crate-visible for-// the dialogs, which hold captures off while one shows that is not kept out of them.#[cfg(windows)]-#[allow(dead_code)]pub(crate) mod win;// The Windows desktop's pure parts, tested everywhere: UI Automation element mapping, which// processes are apps, and what Windows posts for each input event. The Windows desktop backenddiff --git a/apps/desktop/src-tauri/src/computer/working.rs b/apps/desktop/src-tauri/src/computer/working.rsindex fd1e21f..f19dc8b 100644--- a/apps/desktop/src-tauri/src/computer/working.rs+++ b/apps/desktop/src-tauri/src/computer/working.rs@@ -311,8 +311,23 @@ impl Preparation for Working {}}+/// End the current drawing only when the session ends.+pub fn session_clears(drawing: &mut Option<u64>, active: bool) -> Option<u64> {+ if active { None } else { drawing.take() }+}+#[cfg(test)]mod tests {+ #[test]+ fn only_the_end_of_the_session_clears_the_rings_being_drawn() {+ let mut drawing = Some(7);+ assert_eq!(super::session_clears(&mut drawing, true), None);+ assert_eq!(drawing, Some(7));+ assert_eq!(super::session_clears(&mut drawing, false), Some(7));+ assert_eq!(drawing, None);+ assert_eq!(super::session_clears(&mut drawing, false), None);+ }+use super::*;use std::sync::atomic::{AtomicBool, Ordering};use std::sync::Weak;diff --git a/apps/desktop/src-tauri/src/shell.rs b/apps/desktop/src-tauri/src/shell.rsindex 704e5da..46f09f2 100644--- a/apps/desktop/src-tauri/src/shell.rs+++ b/apps/desktop/src-tauri/src/shell.rs@@ -32,11 +32,13 @@ use tauri::{WebviewWindowBuilder, WindowEvent,};use tauri_plugin_autostart::{MacosLauncher, ManagerExt as _};-use tauri_plugin_dialog::{DialogExt, MessageDialogKind};+#[cfg(not(windows))]+use tauri_plugin_dialog::DialogExt;+use tauri_plugin_dialog::MessageDialogKind;use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutEvent, ShortcutState};use tauri_plugin_opener::OpenerExt;-const DOT: &str = "dot";+pub(crate) const DOT: &str = "dot";pub(crate) const PANEL: &str = "panel";const TRAY: &str = "main";/// The Dot window, in points: a 66 pt black disc with the rose, plus a 3 pt@@ -89,14 +91,18 @@ impl working::Windows for ShellWindows {}fn hide(&self, part: Part) -> Result<(), String> {- self.get(part).ok_or_else(|| format!("window {part:?} is missing"))?.hide().map_err(err)+ let window = self.get(part).ok_or_else(|| format!("window {part:?} is missing"))?;+ #[cfg(windows)]+ return computer::hide_for_call(&window);+ #[cfg(not(windows))]+ window.hide().map_err(err)}fn show(&self, part: Part) {let Some(window) = self.get(part) else { return };- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]let shown = computer::show_without_focus(&window);- #[cfg(not(target_os = "macos"))]+ #[cfg(not(any(target_os = "macos", windows)))]let shown = window.show().map_err(err);if let Err(error) = shown {eprintln!("gentle-dot: cannot show the {part:?} again: {error}");@@ -230,7 +236,12 @@ async fn connection_info(app: AppHandle) -> CommandResult<ConnectionInfo> {#[tauri::command]fn toggle_panel(app: AppHandle) -> CommandResult {- if window(&app, PANEL)?.is_visible().map_err(err)? {+ let panel = window(&app, PANEL)?;+ #[cfg(windows)]+ let shown = panel.is_visible().map_err(err)? && !panel.is_minimized().map_err(err)?;+ #[cfg(not(windows))]+ let shown = panel.is_visible().map_err(err)?;+ if shown {hide_panel(app)} else {show_panel(&app)@@ -246,7 +257,12 @@ fn hide_panel(app: AppHandle) -> CommandResult {*shell.panel_spot.lock().unwrap() = Some((rect.x, rect.y));}}- panel.hide().map_err(err)+ #[cfg(windows)]+ let _change = computer::window_change();+ panel.hide().map_err(err)?;+ #[cfg(windows)]+ computer::set_shown(&panel, false)?;+ Ok(())}#[tauri::command]@@ -261,11 +277,15 @@ fn set_rose_hidden(app: AppHandle, hidden: bool) -> CommandResult<bool> {position::save_rose_hidden(&desktop_file(&shell.config), hidden).map_err(err)?;shell.rose_hidden.store(hidden, Ordering::SeqCst);let dot = window(&app, DOT)?;+ #[cfg(windows)]+ let _change = computer::window_change();if hidden {dot.hide().map_err(err)?;} else {dot.show().map_err(err)?;}+ #[cfg(windows)]+ computer::set_shown(&dot, !hidden)?;if let Some(item) = app.try_state::<RoseMenuItem>() {item.0.set_text(rose_menu_label(hidden)).map_err(err)?;}@@ -369,6 +389,12 @@ impl shortcut::Host for ShortcutHost<'_> {}/// The accelerator is only a label; one the menu cannot show is left off.+fn unlabel_tray_open(app: &AppHandle) {+ if let Some(item) = app.try_state::<OpenMenuItem>() {+ let _ = item.0.set_accelerator(None::<&str>);+ }+}+fn label_tray_open(app: &AppHandle, shortcut: &str) {if let Some(item) = app.try_state::<OpenMenuItem>() {if item.0.set_accelerator(Some(shortcut)).is_err() {@@ -469,13 +495,31 @@ fn place_panel_next_to_dot(app: &AppHandle) -> CommandResult {}fn show_panel(app: &AppHandle) -> CommandResult {+ // Restoring a minimized panel shows it too.+ #[cfg(windows)]+ let _change = computer::window_change();+ #[cfg(windows)]+ restore_panel(&window(app, PANEL)?)?;place_panel(app)?;let panel = window(app, PANEL)?;panel.show().map_err(err)?;+ #[cfg(windows)]+ computer::set_shown(&panel, true)?;panel.set_focus().map_err(err)?;app.emit("dot://panel-shown", ()).map_err(err)}+/// A minimized panel must be restored before it is moved or shown.+#[cfg(windows)]+fn restore_panel(panel: &WebviewWindow) -> CommandResult {+ if panel.is_minimized().map_err(err)? { panel.unminimize().map_err(err)?; }+ let current = rect_of(panel)?;+ if (current.width, current.height) != (PANEL_SIZE.0 as i32, PANEL_SIZE.1 as i32) {+ panel.set_size(LogicalSize::new(PANEL_SIZE.0, PANEL_SIZE.1)).map_err(err)?;+ }+ Ok(())+}+/// Snaps the Dot to the nearest edge and persists the position.fn snap_dot(app: &AppHandle) -> CommandResult {let dot = window(app, DOT)?;@@ -537,6 +581,8 @@ fn build_windows(// the Dot stays resizable and equal minimum and maximum sizes pin it at DOT_SIZE.#[cfg(target_os = "linux")]let dot = dot.resizable(true).min_inner_size(DOT_SIZE.0, DOT_SIZE.1).max_inner_size(DOT_SIZE.0, DOT_SIZE.1);+ #[cfg(windows)]+ let dot = dot.minimizable(false);let dot = dot.build()?;// Linux has no window effects; the panel URL tells the UI to paint an opaque background.let panel = WebviewWindowBuilder::new(app, PANEL, WebviewUrl::App(platform::panel_url(Os::CURRENT).into()))@@ -550,6 +596,8 @@ fn build_windows(// Lets the chat receive HTML5 drops of attachments (S31); Tauri's own handler would take them..disable_drag_drop_handler().visible(false);+ #[cfg(windows)]+ let panel = panel.minimizable(false);#[cfg(target_os = "macos")]let panel = panel.effects(EffectsBuilder::new().effect(Effect::HudWindow).state(EffectState::Active).radius(20.0).build());@@ -613,7 +661,7 @@ fn build_tray(app: &AppHandle, config: &DesktopConfig, rose_hidden: bool) -> tauapp.manage(OpenMenuItem(open.clone()));let menu = Menu::new(app)?;let conversations = conversations_on(std::env::var("GENTLE_DOT_CONVERSATIONS").ok().as_deref());- for id in tray_menu_ids(conversations, cfg!(target_os = "macos")) {+ for id in tray_menu_ids(conversations, cfg!(any(target_os = "macos", windows))) {match id {"open" => menu.append(&open)?,"new" => menu.append(&MenuItem::with_id(app, "new", "New conversation", true, None::<&str>)?)?,@@ -694,6 +742,15 @@ fn rose_hidden_state(app: &AppHandle) -> bool {}fn show_message(app: &AppHandle, kind: MessageDialogKind, text: &str) {+ // Gentle Dot's own task dialog on Windows: its life is known exactly, so computer-control+ // captures are held off while it shows (the plugin's box closes on another thread, and its+ // close can be reported late or not at all).+ #[cfg(windows)]+ {+ let _ = app;+ crate::alert::tell("Gentle Dot", text, matches!(kind, MessageDialogKind::Error));+ }+ #[cfg(not(windows))]app.dialog().message(text).title("Gentle Dot").kind(kind).show(|_| {});}@@ -729,7 +786,7 @@ fn restart_daemon(app: AppHandle) {}/// ⌥⇧Esc ends computer control from anywhere, even while another app is in front.-#[cfg(target_os = "macos")]+#[cfg(any(target_os = "macos", windows))]fn register_panic_shortcut(app: &AppHandle) {let handler = |app: &AppHandle, _: &_, event: tauri_plugin_global_shortcut::ShortcutEvent| {if event.state() == ShortcutState::Pressed {@@ -864,15 +921,16 @@ pub fn run() {let (voice_input, voice_model) = voice::start(&handle);app.manage(voice_input);app.manage(voice_model);- #[cfg(target_os = "macos")]+ #[cfg(any(target_os = "macos", windows))]register_panic_shortcut(&handle);build_windows(&handle, &config, places_windows, rose_hidden)?;build_tray(&handle, &config, rose_hidden)?;if places_windows {let bound = register_shortcut(&handle, &config.shortcut);- if let Some(bound) = &bound {- label_tray_open(&handle, bound);+ match &bound {+ Some(bound) => label_tray_open(&handle, bound),+ None => unlabel_tray_open(&handle),}*app.state::<Shell>().shortcut.lock().unwrap() = bound;let snap = app.state::<Shell>().snap.clone();