Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tauri-plugin-process = "2"
libc = "0.2"

[target.'cfg(windows)'.dependencies]
tauri = { version = "2", features = ["tray-icon"] }
portable-pty = { version = "0.9", path = "../vendor/portable-pty" }
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Security", "Win32_System_JobObjects", "Win32_System_Threading", "Win32_System_LibraryLoader", "Win32_System_Diagnostics_ToolHelp"] }

Expand Down
9 changes: 8 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ mod reminders;
mod search;
mod session_store;
mod skills;
#[cfg(target_os = "windows")]
mod tray;
mod window;
mod window_transfer;
#[cfg(windows)]
Expand Down Expand Up @@ -199,6 +201,8 @@ pub fn run() {
reminders::init(app.handle());
checkpoint::init(app.handle())?;
menu::install(app.handle())?;
#[cfg(target_os = "windows")]
tray::install(app.handle())?;
#[cfg(target_os = "macos")]
{
macos::install_dock_menu(app.handle());
Expand Down Expand Up @@ -360,7 +364,9 @@ pub fn run() {
open_new_window,
window::hide_window,
window::destroy_window,
window::confirm_quit,
window::quit_poll_reply,
window::quit_decision,
window::quit_ready,
window::set_window_glass_enabled,
window_transfer::stage_window_transfer,
window_transfer::take_window_transfer,
Expand Down Expand Up @@ -398,6 +404,7 @@ pub fn run() {
event: tauri::WindowEvent::Destroyed,
..
} => {
window::forget_quit_window(handle, &label);
let other_window = handle.webview_windows().keys().any(|name| name != &label);
if !other_window {
reap_harness_children(handle);
Expand Down
48 changes: 48 additions & 0 deletions src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! Tray icon: the way back to a window that closing hid.
//!
//! Windows only. Closing a window hides it so the harness children keep
//! running, and a hidden window drops off the taskbar, so without this the
//! windows would be unreachable.

use tauri::menu::{MenuBuilder, MenuItemBuilder};
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
use tauri::AppHandle;

const SHOW: &str = "tray_show";
const QUIT: &str = "tray_quit";

pub fn install(app: &AppHandle) -> tauri::Result<()> {
let show = MenuItemBuilder::with_id(SHOW, "Show MonoCode").build(app)?;
let quit = MenuItemBuilder::with_id(QUIT, "Quit MonoCode").build(app)?;
let menu = MenuBuilder::new(app).items(&[&show, &quit]).build()?;

let mut tray = TrayIconBuilder::with_id("main")
.tooltip("MonoCode")
.menu(&menu)
// Left click reopens; the menu stays on the right button.
.show_menu_on_left_click(false)
.on_menu_event(|app, event| match event.id().as_ref() {
SHOW => {
let _ = crate::window::show_hidden_or_open_new(app);
}
QUIT => crate::window::request_quit(app),
_ => {}
})
.on_tray_icon_event(|tray, event| {
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
let _ = crate::window::show_hidden_or_open_new(tray.app_handle());
}
});

if let Some(icon) = app.default_window_icon().cloned() {
tray = tray.icon(icon);
}

tray.build(app)?;
Ok(())
}
Loading
Loading