feat(desktop): scope tabs to windows (#34669)

This commit is contained in:
Brendan Allan
2026-07-01 07:02:10 +00:00
committed by GitHub
parent 55552c521f
commit af72cec799
14 changed files with 185 additions and 42 deletions
+15 -10
View File
@@ -6,7 +6,7 @@ import { homedir, tmpdir } from "node:os"
import { join } from "node:path"
import { getCACertificates, setDefaultCACertificates } from "node:tls"
import type { Event } from "electron"
import { app, BrowserWindow } from "electron"
import { app } from "electron"
import { Deferred, Effect, Fiber } from "effect"
import contextMenu from "electron-context-menu"
@@ -28,11 +28,13 @@ import {
} from "./server"
import { setupAutoUpdater, showUpdaterDialog } from "./updater"
import {
createMainWindow,
getLastFocusedWindow,
registerRendererProtocol,
setRelaunchHandler,
setAppQuitting,
setBackgroundColor,
setDockIcon,
restoreMainWindows,
} from "./windows"
import { createWslServersController } from "./wsl/servers"
import { registerWslIpcHandlers } from "./wsl/ipc"
@@ -53,7 +55,6 @@ const TEST_ONBOARDING = process.env.OPENCODE_TEST_ONBOARDING === "1"
const jsCallStackFeature = "DocumentPolicyIncludeJSCallStacksInCrashReports"
let logger: ReturnType<typeof initLogging>
let mainWindow: BrowserWindow | null = null
let server: SidecarListener | null = null
const pendingDeepLinks: string[] = []
@@ -70,7 +71,8 @@ function useEnvProxy() {
function emitDeepLinks(urls: string[]) {
if (urls.length === 0) return
pendingDeepLinks.push(...urls)
if (mainWindow) sendDeepLinks(mainWindow, urls)
const win = getLastFocusedWindow()
if (win) sendDeepLinks(win, urls)
}
async function killSidecar() {
@@ -194,9 +196,10 @@ const main = Effect.gen(function* () {
logger.log("deep link received via second-instance", { urls })
emitDeepLinks(urls)
}
if (mainWindow) {
mainWindow.show()
mainWindow.focus()
const win = getLastFocusedWindow()
if (win) {
win.show()
win.focus()
}
})
@@ -207,10 +210,12 @@ const main = Effect.gen(function* () {
})
app.on("before-quit", () => {
setAppQuitting()
void stopSidecars()
})
app.on("will-quit", () => {
setAppQuitting()
void stopSidecars()
})
@@ -347,11 +352,11 @@ const main = Effect.gen(function* () {
yield* Fiber.await(loadingTask)
mainWindow = createMainWindow()
if (mainWindow) {
const windows = restoreMainWindows()
if (windows.length) {
createMenu({
trigger: (id) => {
const win = BrowserWindow.getFocusedWindow() ?? mainWindow
const win = getLastFocusedWindow()
if (win) sendMenuCommand(win, id)
},
checkForUpdates: () => {