mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
Close a window automatically when the last tab is closed (#131)
This commit is contained in:
parent
1c99e1ed4c
commit
b2ee164b85
@ -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);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ const (
|
||||
WSEvent_BlockControllerStatus = "blockcontroller:status"
|
||||
WSEvent_LayoutAction = "layoutaction"
|
||||
WSEvent_ElectronNewWindow = "electron:newwindow"
|
||||
WSEvent_ElectronCloseWindow = "electron:closewindow"
|
||||
WSEvent_Rpc = "rpc"
|
||||
)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user