fix(desktop): closing the window quits when keep-awake watches nothing here

From the review of #800: the window hid the app whenever a keep-awake mode
was chosen, also with no server open (the connect page) or with a Codeman
on another machine, where keep-awake holds nothing. Closing the window then
left a hidden app in the Dock for nothing, and it never quit on close again
until Cmd+Q.

close_hides_app() now decides from the open server as well: it hides only
while keep-awake watches a Codeman on this Mac, the same server and the same
is_this_mac() rule the worker uses. It still hides while keep-awake is only
paused (on battery with Only When Plugged In, no agent at work, no answer),
since it carries on by itself once that changes.

The test now covers loopback, this Mac's own address, another machine's
address and no server, and fails with the old rule. The frame is recorded
and the config saved once, before the hide or quit choice, and the Reopen
comment says how a hidden app comes back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-10 17:57:06 +01:00
1 parent 430bf6217b
commit 3a3e2ee1a4
3 files changed
+58 -30

No files matched your search

+15 -12
View File
@@ -757,7 +757,9 @@ impl App {
Event::UserEvent(event) => self.on_user_event(event, target),
// A click on the Dock icon while no window is visible, which is
// the main window minimized: tao only reports it, so bring the
// window back here.
// window back here. An app hidden by closing its window
// (`hide_app`) needs nothing here: AppKit unhides it, with every
// window as it was, before it reports the click.
Event::Reopen {
has_visible_windows: false,
..
@@ -833,24 +835,25 @@ impl App {
control_flow: &mut ControlFlow,
) {
match event {
WindowEvent::CloseRequested if id != self.main_id => self.remove_window(id),
WindowEvent::CloseRequested => {
if id != self.main_id {
self.remove_window(id);
} else if self.config.keep_awake.mode.close_hides_app() {
self.record_main_frame();
self.save_config();
let server = self.phase.borrow().loaded().cloned();
let mode = self.config.keep_awake.mode;
if keep_awake::available()
&& keep_awake::close_hides_app(mode, server.as_ref(), keep_awake::local_addresses)
{
// Keep This Mac Awake ends with the app, so closing the
// window while it is on hides Codeman instead, as Cmd+H
// does (full screen and pop-outs included): the Mac stays
// awake, a click on the Dock icon brings it back, and
// Cmd+Q still quits.
self.record_main_frame();
self.save_config();
// window while it watches a Codeman on this Mac hides
// Codeman instead, as Cmd+H does (full screen and pop-outs
// included): the Mac stays awake, a click on the Dock icon
// brings it back, and Cmd+Q still quits.
hide_app(target);
} else {
// Closing the main window quits; the server and its
// sessions keep running, so nothing is lost.
self.keep_awake.shutdown();
self.record_main_frame();
self.save_config();
*control_flow = ControlFlow::Exit;
}
}