diff --git a/packages/desktop/CHANGELOG.md b/packages/desktop/CHANGELOG.md index 73a073e780..9916a41b8d 100644 --- a/packages/desktop/CHANGELOG.md +++ b/packages/desktop/CHANGELOG.md @@ -1,6 +1,14 @@ # CHANGELOG +## v0.30.6 (2026-11-19) + +### Bug Fixes + +- **desktop**: show the window again on a second launch + + + ## v0.30.5 (2026-11-19) ### Bug Fixes diff --git a/packages/desktop/openadapt_desktop/__init__.py b/packages/desktop/openadapt_desktop/__init__.py index c54484ed72..c5dd5310f4 100644 --- a/packages/desktop/openadapt_desktop/__init__.py +++ b/packages/desktop/openadapt_desktop/__init__.py @@ -21,4 +21,4 @@ +-- backends/ Storage backend plugins """ -__version__ = "0.30.5" +__version__ = "0.30.6" diff --git a/packages/desktop/package-lock.json b/packages/desktop/package-lock.json index 973325039e..e12c17a1bb 100644 --- a/packages/desktop/package-lock.json +++ b/packages/desktop/package-lock.json @@ -1,12 +1,12 @@ { "name": "openadapt-desktop", - "version": "0.30.5", + "version": "0.30.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "openadapt-desktop", - "version": "0.30.5", + "version": "0.30.6", "dependencies": { "@tauri-apps/api": "^2", "@tauri-apps/plugin-notification": "^2", diff --git a/packages/desktop/package.json b/packages/desktop/package.json index e745cf456a..db398cfed3 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -1,6 +1,6 @@ { "name": "openadapt-desktop", - "version": "0.30.5", + "version": "0.30.6", "description": "Installed companion for OpenAdapt authoring, teaching, and local pairing", "private": true, "type": "module", diff --git a/packages/desktop/pyproject.toml b/packages/desktop/pyproject.toml index 1e3c998e14..1b00301d34 100644 --- a/packages/desktop/pyproject.toml +++ b/packages/desktop/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "openadapt-desktop" -version = "0.30.5" +version = "0.30.6" description = "The OpenAdapt desktop app and local engine: record a data-entry task, run it on a list, and check each saved record" readme = "README.md" requires-python = ">=3.11" diff --git a/packages/desktop/src-tauri/Cargo.lock b/packages/desktop/src-tauri/Cargo.lock index 8b6e23533a..63f909cb56 100644 --- a/packages/desktop/src-tauri/Cargo.lock +++ b/packages/desktop/src-tauri/Cargo.lock @@ -2504,7 +2504,7 @@ dependencies = [ [[package]] name = "openadapt-desktop" -version = "0.30.5" +version = "0.30.6" dependencies = [ "hex", "reqwest", diff --git a/packages/desktop/src-tauri/Cargo.toml b/packages/desktop/src-tauri/Cargo.toml index ea3c689b65..80279fdaab 100644 --- a/packages/desktop/src-tauri/Cargo.toml +++ b/packages/desktop/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openadapt-desktop" -version = "0.30.5" +version = "0.30.6" description = "Installed companion for OpenAdapt authoring, teaching, and local pairing" authors = ["OpenAdapt AI"] license = "MIT" diff --git a/packages/desktop/src-tauri/src/main.rs b/packages/desktop/src-tauri/src/main.rs index eb18707cbb..2431b0f045 100644 --- a/packages/desktop/src-tauri/src/main.rs +++ b/packages/desktop/src-tauri/src/main.rs @@ -14,6 +14,7 @@ mod ffmpeg; mod pairing; mod sidecar; mod tray; +mod window; use std::sync::Arc; @@ -49,9 +50,8 @@ fn main() { // Must be first: on Windows/Linux it forwards a second process's // statically configured deep link into the deep-link plugin event. .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { - if let Some(window) = app.get_webview_window("main") { - let _ = window.show(); - } + // A second launch brings the running app's window to the front. + window::show_main(app); })) .plugin(tauri_plugin_deep_link::init()) .plugin(tauri_plugin_shell::init()) @@ -60,6 +60,8 @@ fn main() { builder = builder.plugin(tauri_plugin_updater::Builder::new().build()); } builder + // Closing the main window hides it; see window.rs. + .on_window_event(window::on_window_event) .manage(SidecarHandle(engine.clone())) .manage(commands::UpdaterAvailable(updater_configured)) .setup(move |app| { @@ -124,9 +126,13 @@ fn main() { ]) .build(context) .expect("error while building openadapt-desktop") - .run(move |_app, event| { - if let tauri::RunEvent::Exit = event { - sidecar::shutdown(&engine_for_exit); + .run(move |app, event| match event { + tauri::RunEvent::Exit => sidecar::shutdown(&engine_for_exit), + // A click on the Dock icon while the app is running. + #[cfg(target_os = "macos")] + tauri::RunEvent::Reopen { .. } => window::show_main(app), + _ => { + let _ = app; } }); } diff --git a/packages/desktop/src-tauri/src/tray.rs b/packages/desktop/src-tauri/src/tray.rs index 291cc37b66..a7ad526eff 100644 --- a/packages/desktop/src-tauri/src/tray.rs +++ b/packages/desktop/src-tauri/src/tray.rs @@ -125,10 +125,7 @@ pub fn setup_tray(app: &App) -> Result<(), Box> { } fn show_main(app: &AppHandle) { - if let Some(window) = app.get_webview_window("main") { - let _ = window.show(); - let _ = window.set_focus(); - } + crate::window::show_main(app); } /// Reflect shadow mode's on/off state in the tray. Called by the window diff --git a/packages/desktop/src-tauri/src/window.rs b/packages/desktop/src-tauri/src/window.rs new file mode 100644 index 0000000000..efda3beb0d --- /dev/null +++ b/packages/desktop/src-tauri/src/window.rs @@ -0,0 +1,67 @@ +// The main window: closing it hides it, and every way back shows it again. +// +// The app keeps running after the main window is closed, because the tray icon +// and the hidden control overlay stay alive. Before 0.30.5 closing destroyed the +// window, so nothing could bring it back: a second launch from the Start menu, +// "Open OpenAdapt" in the tray menu and a click on the macOS Dock icon all +// looked for a window that no longer existed and did nothing. +// +// Closing now hides the window instead. `show_main` is the one way back, used +// by the single-instance handler (a second launch), the tray menu and the Dock. + +use tauri::{AppHandle, Manager, Window, WindowEvent}; + +pub const MAIN_WINDOW: &str = "main"; + +/// What a close request does to a window. +#[derive(Debug, PartialEq, Eq)] +pub enum CloseAction { + /// Keep the window and hide it, so it can be shown again. + Hide, + /// Let the window close. + Close, +} + +/// Only the main window is kept; any other window closes as usual. +pub fn close_action(label: &str) -> CloseAction { + if label == MAIN_WINDOW { + CloseAction::Hide + } else { + CloseAction::Close + } +} + +/// Hide the main window when the person closes it. +pub fn on_window_event(window: &Window, event: &WindowEvent) { + if let WindowEvent::CloseRequested { api, .. } = event { + if close_action(window.label()) == CloseAction::Hide { + api.prevent_close(); + let _ = window.hide(); + } + } +} + +/// Bring the main window back to the front. +pub fn show_main(app: &AppHandle) { + if let Some(window) = app.get_webview_window(MAIN_WINDOW) { + let _ = window.unminimize(); + let _ = window.show(); + let _ = window.set_focus(); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn closing_the_main_window_hides_it() { + assert_eq!(close_action("main"), CloseAction::Hide); + } + + #[test] + fn other_windows_close_as_usual() { + assert_eq!(close_action("control-overlay"), CloseAction::Close); + assert_eq!(close_action(""), CloseAction::Close); + } +} diff --git a/packages/desktop/src-tauri/tauri.conf.json b/packages/desktop/src-tauri/tauri.conf.json index 2a0c316a00..ede2e28594 100644 --- a/packages/desktop/src-tauri/tauri.conf.json +++ b/packages/desktop/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/nicoverbruggen/tauri-v2-schema/main/schema.json", "productName": "OpenAdapt Desktop", - "version": "0.30.5", + "version": "0.30.6", "identifier": "ai.openadapt.desktop", "build": { "frontendDist": "../dist", diff --git a/packages/desktop/tests/test_main_window_reopens.py b/packages/desktop/tests/test_main_window_reopens.py new file mode 100644 index 0000000000..cb8cbf21fa --- /dev/null +++ b/packages/desktop/tests/test_main_window_reopens.py @@ -0,0 +1,50 @@ +"""Every way back to the app shows the main window. + +The app keeps running after its window is closed. Before Desktop 0.30.5 closing +destroyed the window, so a second launch from the Start menu, "Open OpenAdapt" +in the tray menu and a click on the macOS Dock icon all did nothing. + +``src-tauri/src/window.rs`` now hides the window on close and owns the one +function that shows it again. These checks hold the wiring in place; the +behaviour itself was verified on Windows 11 and macOS with a branch build. +""" + +from __future__ import annotations + +import re +from pathlib import Path + +SHELL = Path(__file__).resolve().parents[1] / "src-tauri" / "src" + + +def _source(name: str) -> str: + return (SHELL / name).read_text(encoding="utf-8") + + +def test_closing_the_main_window_hides_it_instead_of_destroying_it() -> None: + window = _source("window.rs") + handler = window[window.index("pub fn on_window_event") : window.index("pub fn show_main")] + assert "WindowEvent::CloseRequested" in handler + assert "api.prevent_close()" in handler + assert "window.hide()" in handler + assert ".on_window_event(window::on_window_event)" in _source("main.rs") + + +def test_a_second_launch_shows_the_running_apps_window() -> None: + main = _source("main.rs") + start = main.index("tauri_plugin_single_instance::init(") + handler = main[start : main.index("}))", start)] + assert "window::show_main(app)" in handler + + +def test_the_tray_menu_and_the_dock_show_the_window_too() -> None: + assert "crate::window::show_main(app)" in _source("tray.rs") + main = _source("main.rs") + assert re.search(r"RunEvent::Reopen\s*\{\s*\.\.\s*\}\s*=>\s*window::show_main\(app\)", main) + + +def test_show_main_restores_shows_and_focuses() -> None: + window = _source("window.rs") + body = window[window.index("pub fn show_main") : window.index("#[cfg(test)]")] + for call in ("window.unminimize()", "window.show()", "window.set_focus()"): + assert call in body diff --git a/packages/desktop/uv.lock b/packages/desktop/uv.lock index b93d155de5..c1a1c306ad 100644 --- a/packages/desktop/uv.lock +++ b/packages/desktop/uv.lock @@ -1172,7 +1172,7 @@ wheels = [ [[package]] name = "openadapt-desktop" -version = "0.30.5" +version = "0.30.6" source = { editable = "." } dependencies = [ { name = "cryptography" },