Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions packages/desktop-electron/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { randomUUID } from "node:crypto"
import { EventEmitter } from "node:events"
import { existsSync } from "node:fs"
import { createServer } from "node:net"
import { homedir } from "node:os"
import { join } from "node:path"
Expand Down Expand Up @@ -128,8 +127,6 @@ function setInitStep(step: InitStep) {
}

async function initialize() {
const needsMigration = !sqliteFileExists()
const sqliteDone = needsMigration ? defer<void>() : undefined
let overlay: BrowserWindow | null = null

const port = await getSidecarPort()
Expand All @@ -153,13 +150,8 @@ async function initialize() {
setInitStep({ phase: "sqlite_waiting" })
if (overlay) sendSqliteMigrationProgress(overlay, progress)
if (mainWindow) sendSqliteMigrationProgress(mainWindow, progress)
if (progress.type === "Done") sqliteDone?.resolve()
})

if (needsMigration) {
await sqliteDone?.promise
}

await Promise.race([
health.wait,
delay(30_000).then(() => {
Expand All @@ -177,12 +169,10 @@ async function initialize() {
deepLinks: pendingDeepLinks,
}

if (needsMigration) {
const show = await Promise.race([loadingTask.then(() => false), delay(1_000).then(() => true)])
if (show) {
overlay = createLoadingWindow(globals)
await delay(1_000)
}
const show = await Promise.race([loadingTask.then(() => false), delay(1_000).then(() => true)])
if (show) {
overlay = createLoadingWindow(globals)
await delay(1_000)
}

await loadingTask
Expand Down Expand Up @@ -295,12 +285,6 @@ async function getSidecarPort() {
})
}

function sqliteFileExists() {
const xdg = process.env.XDG_DATA_HOME
const base = xdg && xdg.length > 0 ? xdg : join(homedir(), ".local", "share")
return existsSync(join(base, "opencode", "opencode.db"))
}

function setupAutoUpdater() {
if (!UPDATER_ENABLED) return
autoUpdater.logger = logger
Expand Down
10 changes: 8 additions & 2 deletions packages/desktop-electron/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ const api: ElectronAPI = {
killSidecar: () => ipcRenderer.invoke("kill-sidecar"),
installCli: () => ipcRenderer.invoke("install-cli"),
awaitInitialization: (onStep) => {
const handler = (_: unknown, step: InitStep) => onStep(step)
const handler = (_: unknown, step: InitStep) => {
onStep(step)
if (step.phase === "done") {
ipcRenderer.removeListener("init-step", handler)
}
}
ipcRenderer.on("init-step", handler)
return ipcRenderer.invoke("await-initialization").finally(() => {
return ipcRenderer.invoke("await-initialization").catch((error) => {
ipcRenderer.removeListener("init-step", handler)
throw error
})
},
getDefaultServerUrl: () => ipcRenderer.invoke("get-default-server-url"),
Expand Down
Loading