Skip to content

Commit b154ee9

Browse files
committed
fix: terminal deletion after share stop
1 parent f30c80a commit b154ee9

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

app/components/TerminalPanel.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,18 @@ const panelHeight = ref(props.initialTerminalHeight ?? 261);
116116
117117
// --- Share mode: sync sessions from server's sharedTerminals ---
118118
watch(isSharing, (sharing) => {
119+
knownShareIds.clear();
120+
sessions.value = [];
121+
splitId.value = null;
122+
savedPairsMap.clear();
123+
nextId = 1;
124+
epoch = Date.now();
119125
if (sharing) {
120-
knownShareIds.clear();
121-
sessions.value = [];
122-
splitId.value = null;
123-
savedPairsMap.clear();
124-
// Re-ensure a session in case the panel is already visible.
125-
// sharedTerminals watcher (immediate) will populate sessions if there are existing
126-
// terminals; ensureSession only creates a new local one if nothing else does.
126+
// Sharing started: sharedTerminals watcher (immediate) populates sessions if terminals
127+
// already exist; ensureSession creates a pending local one if needed.
127128
nextTick(() => ensureSession());
128129
}
130+
// Sharing stopped: sessions cleared above. index.vue calls ensureSession() when terminal is open.
129131
});
130132
131133
watch(() => sharedTerminals.value, (list) => {

app/pages/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ function onShareStopped() {
633633
// Host stopped sharing: close all relay terminals
634634
for (const handle of relayTerminals.values()) handle.close();
635635
relayTerminals.clear();
636+
// Re-create terminal sessions now that we're back in normal mode
637+
if (terminalOpen.value) {
638+
nextTick(() => terminalPanelRef.value?.ensureSession());
639+
}
636640
}
637641
638642
async function autoJoinShare(sid: string) {

electron/main.cjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,21 @@ function createWindow(rootPath) {
158158
});
159159

160160
win.on("closed", () => {
161-
windows.delete(win);
162-
if (!isQuitting) saveSessions();
161+
if (!isQuitting) {
162+
const root = windows.get(win);
163+
windows.delete(win);
164+
if (windows.size === 0 && root !== undefined) {
165+
// Last window on Windows/Linux: before-quit fires AFTER this, map already empty.
166+
// Save the last root now so it's restored on next launch.
167+
try { fs.writeFileSync(sessionsFile, JSON.stringify([root || ""]), "utf-8"); } catch (e) {
168+
log(`[session] save error: ${e.message}`);
169+
}
170+
} else {
171+
saveSessions();
172+
}
173+
} else {
174+
windows.delete(win);
175+
}
163176
});
164177

165178
return win;

0 commit comments

Comments
 (0)