fix(windows): explain an unfinished install instead of crash-looping the window (#34447)

Missing, empty, or locked ffmpeg.dll beside Orca.exe (as an interrupted
update leaves it) makes every renderer die at child init with 0x80000003
and the window crash-loops. Gate the packaged Windows desktop launch on
it after the single-instance preflight and show the standard startup
failure dialog instead.

Rebased onto main keeping the WSL holder and agent-hooks uninstall
preflights ahead of the gate. Message no longer claims the installer
relaunches Orca, and tests cover the gate's skip paths.

Co-authored-by: m4air <m4air@Mac.localdomain>
This commit is contained in:
OrcaWin
2026-11-02 22:03:20 -08:00
committed by GitHub
co-authored by m4air
parent 5933df0147
commit bebf5a2621
3 changed files with 151 additions and 1 deletions
+3 -1
View File
@@ -13,6 +13,7 @@ import { runMainProcessPreflight } from './startup/main-process-preflight'
import { runWslHolderUninstallPreflight } from './startup/wsl-holder-uninstall-preflight'
import { runAgentHooksUninstallPreflight } from './startup/agent-hooks-uninstall-preflight'
import { enableLinearRegexpFallback } from './startup/linear-regexp-fallback'
import { ensureWindowsRendererRuntimeFiles } from './startup/windows-renderer-runtime-files'
import { registerMainProcessIpcHandlers } from './startup/main-process-ipc-bootstrap'
import { initializeMainProcessReady } from './startup/main-process-ready'
import { installMainProcessQuitHandlers } from './startup/main-process-quit'
@@ -125,7 +126,8 @@ const preflightReady =
runMainProcessPreflight({
focusExistingWindow,
requestDesktopActivation
})
}) &&
ensureWindowsRendererRuntimeFiles(state.isServeMode)
// Skip userData writes after losing the single-instance lock.
if (preflightReady) {
@@ -0,0 +1,101 @@
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import os from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const { electronApp, handleFailure } = vi.hoisted(() => ({
electronApp: { isPackaged: true },
handleFailure: vi.fn()
}))
vi.mock('electron', () => ({ app: electronApp }))
vi.mock('./main-process-preflight-failure', () => ({
handleMainProcessPreflightFailure: handleFailure
}))
import {
ensureWindowsRendererRuntimeFiles,
findUnusableRendererRuntimeFile
} from './windows-renderer-runtime-files'
let installDir: string
let execPath: string
beforeEach(() => {
installDir = mkdtempSync(join(os.tmpdir(), 'orca-renderer-runtime-files-'))
execPath = join(installDir, 'Orca.exe')
})
afterEach(() => {
rmSync(installDir, { recursive: true, force: true })
})
describe('findUnusableRendererRuntimeFile', () => {
it('accepts a complete install', () => {
writeFileSync(join(installDir, 'ffmpeg.dll'), 'MZ')
expect(findUnusableRendererRuntimeFile(execPath)).toBeNull()
})
it('reports a DLL an unfinished update has not written yet', () => {
expect(findUnusableRendererRuntimeFile(execPath)).toBe('ffmpeg.dll')
})
it('reports a DLL that is still empty', () => {
writeFileSync(join(installDir, 'ffmpeg.dll'), '')
expect(findUnusableRendererRuntimeFile(execPath)).toBe('ffmpeg.dll')
})
})
describe('ensureWindowsRendererRuntimeFiles', () => {
const originalPlatform = process.platform
const originalExecPath = process.execPath
const setPlatform = (value: NodeJS.Platform): void => {
Object.defineProperty(process, 'platform', { value, configurable: true })
}
beforeEach(() => {
handleFailure.mockReset()
electronApp.isPackaged = true
setPlatform('win32')
Object.defineProperty(process, 'execPath', { value: execPath, configurable: true })
vi.spyOn(console, 'error').mockImplementation(() => {})
})
afterEach(() => {
setPlatform(originalPlatform)
Object.defineProperty(process, 'execPath', { value: originalExecPath, configurable: true })
vi.restoreAllMocks()
})
it('fails the preflight with an explanation when ffmpeg.dll is missing', () => {
expect(ensureWindowsRendererRuntimeFiles(false)).toBe(false)
expect(handleFailure).toHaveBeenCalledTimes(1)
expect(String(handleFailure.mock.calls[0][0])).toContain(
'ffmpeg.dll is missing, empty, or in use'
)
})
it('passes a complete packaged install', () => {
writeFileSync(join(installDir, 'ffmpeg.dll'), 'MZ')
expect(ensureWindowsRendererRuntimeFiles(false)).toBe(true)
expect(handleFailure).not.toHaveBeenCalled()
})
it('skips non-Windows hosts', () => {
setPlatform('darwin')
expect(ensureWindowsRendererRuntimeFiles(false)).toBe(true)
expect(handleFailure).not.toHaveBeenCalled()
})
it('skips unpackaged dev runs', () => {
electronApp.isPackaged = false
expect(ensureWindowsRendererRuntimeFiles(false)).toBe(true)
expect(handleFailure).not.toHaveBeenCalled()
})
it('skips serve mode, which never opens a renderer window', () => {
expect(ensureWindowsRendererRuntimeFiles(true)).toBe(true)
expect(handleFailure).not.toHaveBeenCalled()
})
})
@@ -0,0 +1,47 @@
import { app } from 'electron'
import { closeSync, fstatSync, openSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { handleMainProcessPreflightFailure } from './main-process-preflight-failure'
/** Every renderer delay-loads this at child init; without it each one dies with 0x80000003 before any page loads. */
const RENDERER_RUNTIME_FILES = ['ffmpeg.dll'] as const
function isReadableNonEmptyFile(path: string): boolean {
let fd: number
try {
fd = openSync(path, 'r')
} catch {
return false
}
try {
return fstatSync(fd).size > 0
} catch {
return false
} finally {
closeSync(fd)
}
}
/** First renderer runtime file beside the exe that is missing, empty, or locked, as an unfinished update leaves it. */
export function findUnusableRendererRuntimeFile(execPath: string): string | null {
const exeDir = dirname(execPath)
return RENDERER_RUNTIME_FILES.find((name) => !isReadableNonEmptyFile(join(exeDir, name))) ?? null
}
/** False once it has told the user to let an unfinished update complete; exiting also releases the installer's files. */
export function ensureWindowsRendererRuntimeFiles(isServeMode: boolean): boolean {
if (process.platform !== 'win32' || !app.isPackaged || isServeMode) {
return true
}
const fileName = findUnusableRendererRuntimeFile(process.execPath)
if (!fileName) {
return true
}
const message =
`Orca's installation is incomplete: ${fileName} is missing, empty, or in use. ` +
'If Orca is updating, wait for the installer to finish, then open Orca again. ' +
'Otherwise, reinstall Orca.'
console.error(`[startup] ${message}`)
handleMainProcessPreflightFailure(new Error(message))
return false
}