mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 17:01:37 +03:00
fix(desktop): finish the macOS Cmd+Q quit after shutdown (#59144)
Co-authored-by: Brendonovich <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: anmol0b <91365474+anmol0b@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
f669c46c96
commit
ec09e45314
@@ -8,7 +8,7 @@ import { emitIpcEvent } from "../ipc-events"
|
||||
import { DesktopLogging, scoped } from "../native/logging"
|
||||
import { DesktopStorage } from "../storage"
|
||||
import { safeWebContentsURL } from "../windows/state"
|
||||
import { getLastFocusedWindow, getWindowByID, makeMainWindows, setAppQuitting, setRelaunchHandler } from "../windows"
|
||||
import { getLastFocusedWindow, getWindowByID, mainWindows, setAppQuitting, setRelaunchHandler } from "../windows"
|
||||
import { marks } from "./marks"
|
||||
import { initializeFirstLaunchOnboarding } from "./onboarding"
|
||||
import { Shutdown } from "./shutdown"
|
||||
@@ -29,12 +29,21 @@ const runtime = Layer.effect(
|
||||
Effect.gen(function* () {
|
||||
const shutdown = yield* Shutdown.Service
|
||||
const runFork = Effect.runForkWith(yield* Effect.context())
|
||||
const windows = yield* makeMainWindows()
|
||||
const windows = yield* mainWindows()
|
||||
const createWindow = windows.create
|
||||
const restoreWindows = windows.restore
|
||||
const pendingDeepLinks: string[] = []
|
||||
let shutdownReady = false
|
||||
const prepareToRestart = shutdown.run.pipe(Effect.ensuring(Effect.sync(() => (shutdownReady = true))))
|
||||
let quitRequested = false
|
||||
|
||||
// A hung shutdown step would otherwise leave every quit waiting on it forever.
|
||||
const prepareToRestart = shutdown.run.pipe(
|
||||
Effect.timeoutOrElse({
|
||||
duration: "10 seconds",
|
||||
orElse: () => Effect.logError("shutdown timed out, quitting anyway"),
|
||||
}),
|
||||
Effect.ensuring(Effect.sync(() => (shutdownReady = true))),
|
||||
)
|
||||
|
||||
const focusWindow = (win: BrowserWindow | null) => {
|
||||
if (!win) return
|
||||
@@ -94,11 +103,15 @@ const runtime = Layer.effect(
|
||||
}
|
||||
|
||||
const beforeQuit = (event: Event) => {
|
||||
quitRequested = true
|
||||
setAppQuitting()
|
||||
|
||||
if (shutdownReady) return
|
||||
event.preventDefault()
|
||||
runFork(prepareToRestart.pipe(Effect.ensuring(Effect.sync(() => app.quit()))))
|
||||
// Electron records the cancelled quit only after this event returns. A shutdown with nothing to
|
||||
// stop finishes in a microtask, so re-quitting from it would be overwritten and the app would
|
||||
// stay alive with no windows. Re-quit on the next tick instead.
|
||||
runFork(prepareToRestart.pipe(Effect.ensuring(Effect.sync(() => setImmediate(() => app.quit())))))
|
||||
}
|
||||
|
||||
const willQuit = () => {
|
||||
@@ -125,11 +138,14 @@ const runtime = Layer.effect(
|
||||
runFork(prepareToRestart.pipe(Effect.ensuring(Effect.sync(() => app.quit()))))
|
||||
}
|
||||
|
||||
// Electron emits this instead of will-quit when it lost track of a quit, so finish the one we asked for.
|
||||
const windowAllClosed = () => {
|
||||
if (process.platform !== "darwin") app.quit()
|
||||
if (quitRequested || process.platform !== "darwin") app.quit()
|
||||
}
|
||||
|
||||
const activate = () => {
|
||||
if (quitRequested) return
|
||||
|
||||
if (BrowserWindow.getAllWindows().length === 0) restoreWindows()
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
import { registerRendererProtocol, setProtocolReporter } from "./protocol"
|
||||
import { loadWindow } from "./scheme"
|
||||
import { createWindowRegistry } from "./registry"
|
||||
import { makeWindowRecovery } from "./recovery"
|
||||
import { windowRecovery } from "./recovery"
|
||||
import { takeEarlyWindow, type EarlyWindow } from "./early"
|
||||
import { manageWindowState, readWindowState, resolveWindowState, windowStateFile } from "./window-state"
|
||||
import { allowRendererPermissions, wireNavigationPolicy, wireRendererHeaders } from "./security"
|
||||
@@ -114,13 +114,13 @@ export function setWindowThemeReady(win: BrowserWindow) {
|
||||
themeReady.get(win)?.()
|
||||
}
|
||||
|
||||
export const makeMainWindows = Effect.fn("Window.make")(function* () {
|
||||
export const mainWindows = Effect.fn("Window.make")(function* () {
|
||||
const fs = yield* FileSystem.FileSystem
|
||||
const path = yield* Path.Path
|
||||
const paths = yield* DesktopPaths.resolve
|
||||
const storage = yield* DesktopStorage.Service
|
||||
const runFork = Effect.runForkWith(yield* Effect.context())
|
||||
const wireWindowRecovery = yield* makeWindowRecovery
|
||||
const wireWindowRecovery = yield* windowRecovery
|
||||
|
||||
const restore = () => {
|
||||
// The entry module created and showed the first restored window on ready; it is adopted here,
|
||||
|
||||
@@ -4,14 +4,14 @@ import { Effect } from "effect"
|
||||
import { DesktopLogging, scoped } from "../native/logging"
|
||||
import { nativeT } from "../native/translations"
|
||||
import { safeWindowURL } from "./state"
|
||||
import { makeUnresponsiveSampler } from "./unresponsive"
|
||||
import { unresponsiveSampler } from "./unresponsive"
|
||||
|
||||
export const makeWindowRecovery = Effect.gen(function* () {
|
||||
export const windowRecovery = Effect.gen(function* () {
|
||||
const context = yield* Effect.context()
|
||||
const runFork = Effect.runForkWith(context)
|
||||
const runPromise = Effect.runPromiseWith(context)
|
||||
const logging = yield* DesktopLogging.Service
|
||||
const createUnresponsiveSampler = yield* makeUnresponsiveSampler
|
||||
const createUnresponsiveSampler = yield* unresponsiveSampler
|
||||
|
||||
function wireWindowRecovery(win: BrowserWindow, name: string, relaunch: () => void) {
|
||||
let showing = false
|
||||
|
||||
@@ -7,7 +7,7 @@ const sampleInterval = 1000
|
||||
|
||||
const samplePeriod = 15000
|
||||
|
||||
export const makeUnresponsiveSampler = Effect.gen(function* () {
|
||||
export const unresponsiveSampler = Effect.gen(function* () {
|
||||
const runFork = Effect.runForkWith(yield* Effect.context())
|
||||
|
||||
function createUnresponsiveSampler(win: BrowserWindow, name: string) {
|
||||
|
||||
Reference in New Issue
Block a user