Close a window automatically when the last tab is closed (#131)

This commit is contained in:
Evan Simkowitz 2024-07-22 16:39:45 -07:00 committed by GitHub
parent 1c99e1ed4c
commit b2ee164b85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -217,6 +217,15 @@ async function handleWSEvent(evtMsg: WSEventType) {
const newWin = createBrowserWindow(clientData.oid, windowData);
await newWin.readyPromise;
newWin.show();
} else if (evtMsg.eventtype == "electron:closewindow") {
if (evtMsg.data === undefined) return;
const windows = electron.BrowserWindow.getAllWindows();
for (const window of windows) {
if ((window as any).waveWindowId === evtMsg.data) {
// Bypass the "Are you sure?" dialog, since this event is called when there's no more tabs for the window.
window.destroy();
}
}
} else {
console.log("unhandled electron ws eventtype", evtMsg.eventtype);
}

View File

@ -22,6 +22,7 @@ const (
WSEvent_BlockControllerStatus = "blockcontroller:status"
WSEvent_LayoutAction = "layoutaction"
WSEvent_ElectronNewWindow = "electron:newwindow"
WSEvent_ElectronCloseWindow = "electron:closewindow"
WSEvent_Rpc = "rpc"
)

View File

@ -67,10 +67,13 @@ func (svc *WindowService) CloseTab(ctx context.Context, uiContext wstore.UIConte
var newActiveTabId string
if len(ws.TabIds) > 0 {
newActiveTabId = ws.TabIds[0]
} else {
newActiveTabId = ""
}
wstore.SetActiveTab(ctx, uiContext.WindowId, newActiveTabId)
} else {
eventbus.SendEventToElectron(eventbus.WSEventType{
EventType: eventbus.WSEvent_ElectronCloseWindow,
Data: uiContext.WindowId,
})
}
}
return wstore.ContextGetUpdatesRtn(ctx), nil
}