improvement(desktop): make each terminal its own resource tab (#7749) · simstudioai/sim@23cc971 · GitHub
Skip to content

Commit 23cc971

Browse files
authored
improvement(desktop): make each terminal its own resource tab (#7749)
* improvement(desktop): make each terminal its own resource tab * fix(desktop): close hidden terminal tabs from the strip and keep the activity icon on terminal tabs * fix(desktop): keep terminal close ownership with the window showing the panel
1 parent 5e39483 commit 23cc971

50 files changed

Lines changed: 1519 additions & 1236 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/main/ipc.test.ts‎

Lines changed: 5 additions & 5 deletions

‎apps/desktop/src/main/ipc.ts‎

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,39 +1516,20 @@ export function registerIpcHandlers(deps: IpcDeps): void {
15161516
return fillCoordinator()?.fillCredential(id, scope) ?? false
15171517
},
15181518
},
1519-
'terminal:start': {
1519+
'terminal:restore-scope': {
15201520
kind: 'invoke',
15211521
gate: 'app-origin',
15221522
requires: 'terminal',
15231523
passSender: true,
1524-
denied: { ok: false, code: 'ACCESS_DENIED', error: 'Not allowed from this page.' },
1525-
handler: (sender, raw, rawScope) => {
1526-
const contents = sender as WebContents
1527-
const scope = rendererScope(terminalScopeBySender, contents, rawScope)
1528-
if (!scope) {
1529-
return { ok: false, code: 'STALE_SCOPE', error: 'This terminal chat is not active.' }
1530-
}
1531-
const options = isRecordLike(raw) ? raw : {}
1532-
const cols = Number(options.cols)
1533-
const rows = Number(options.rows)
1524+
denied: { tabs: [], activeTerminalId: null },
1525+
handler: (sender, rawScope) => {
1526+
const scope = rendererScope(terminalScopeBySender, sender as WebContents, rawScope)
1527+
if (!scope) return { tabs: [], activeTerminalId: null }
15341528
try {
1535-
return {
1536-
ok: true,
1537-
tabs: {
1538-
...deps.terminal.start(scope, {
1539-
cols: toCellCount(cols, 80),
1540-
rows: toCellCount(rows, 24),
1541-
}),
1542-
scopeId: scope,
1543-
},
1544-
}
1529+
return { ...deps.terminal.restoreScope(scope), scopeId: scope }
15451530
} catch (error) {
1546-
const failure = error as { code?: string; message?: string }
1547-
return {
1548-
ok: false,
1549-
code: failure.code ?? 'SPAWN_FAILED',
1550-
error: failure.message ?? 'Could not open a terminal.',
1551-
}
1531+
logger.warn('Could not restore saved terminals', { error: getErrorMessage(error) })
1532+
return { ...deps.terminal.getTabs(scope), scopeId: scope }
15521533
}
15531534
},
15541535
},
@@ -1778,12 +1759,13 @@ export function registerIpcHandlers(deps: IpcDeps): void {
17781759
requires: 'terminal',
17791760
passSender: true,
17801761
denied: { tabs: [], activeTerminalId: null },
1781-
handler: (sender, terminalId, rawScope) => {
1762+
handler: (sender, terminalId, rawScope, rawOptions) => {
17821763
const scope = rendererScope(terminalScopeBySender, sender as WebContents, rawScope)
17831764
if (!scope) return { tabs: [], activeTerminalId: null }
1765+
const claim = !(isRecordLike(rawOptions) && rawOptions.claim === false)
17841766
const tabs =
17851767
typeof terminalId === 'string'
1786-
? deps.terminal.switchTerminal(scope, terminalId)
1768+
? deps.terminal.switchTerminal(scope, terminalId, { claim })
17871769
: deps.terminal.getTabs(scope)
17881770
return { ...tabs, scopeId: scope }
17891771
},
@@ -1850,7 +1832,6 @@ export function registerIpcHandlers(deps: IpcDeps): void {
18501832
handler: (sender, terminalId, cols, rows, rawScope) => {
18511833
// `typeof NaN === 'number'`, and the downstream `cols <= 0` guard is
18521834
// false for NaN, so an unfinite value reached pty.resize() intact.
1853-
// Matches the clamping terminal:start already applies to these fields.
18541835
if (typeof terminalId !== 'string') return
18551836
if (!isPositiveFinite(cols) || !isPositiveFinite(rows)) return
18561837
const scope = rendererScope(terminalScopeBySender, sender as WebContents, rawScope)

‎apps/desktop/src/main/terminal/index.ts‎

Lines changed: 30 additions & 30 deletions

0 commit comments

Comments
 (0)