Compare commits

...
Author SHA1 Message Date
LukeParkerDev a98927909b perf(desktop): install the context menu after the first window exists
electron-context-menu (with electron-dl, cli-truncate, ext-name and
friends) was imported and configured in configureApplication, before
Chromium was ready. It attaches to every existing and future window, so
loading it right after restoreWindows() gives the same menus without
its dependency tree on the startup path.

Packaged build, warm service, median of 6 launches: first main-process
log line 401 -> 381 ms after spawn.
2026-09-19 00:34:55 +10:00
2 changed files with 9 additions and 2 deletions
+2
View File
@@ -3,6 +3,7 @@ import { app } from "electron"
import { Effect, Layer } from "effect"
import { Ipc } from "./ipc"
import { DesktopInitialization } from "./lifecycle/desktop-initialization"
import { installContextMenu } from "./lifecycle/environment"
import { ApplicationLifecycle } from "./lifecycle"
import { BackgroundService } from "./service/background-service"
import { DesktopCli } from "./service/desktop-cli"
@@ -12,6 +13,7 @@ const runIpc = Effect.fn("Desktop.runIpc")(function* () {
const lifecycle = yield* ApplicationLifecycle.Service
const ipc = yield* Ipc.registerIpcHandlers
if (lifecycle.restoreWindows().length) ipc.installMenu()
yield* installContextMenu
yield* Effect.callback<void>((resume) => {
const quit = () => resume(Effect.void)
app.once("will-quit", quit)
@@ -3,7 +3,6 @@ import http from "node:http"
import { homedir, tmpdir } from "node:os"
import { getCACertificates, setDefaultCACertificates } from "node:tls"
import { app } from "electron"
import contextMenu from "electron-context-menu"
import { Effect, FileSystem, Path } from "effect"
import { CHANNEL } from "../constants"
import { DesktopPaths } from "../paths"
@@ -25,7 +24,6 @@ const jsCallStackFeature = "DocumentPolicyIncludeJSCallStacksInCrashReports"
export const configureApplication = Effect.fn("Application.configure")(function* () {
const path = yield* Path.Path
contextMenu({ showSaveImageAs: true, showLookUpSelection: false, showSearchWithGoogle: false })
try {
process.chdir(homedir())
} catch {}
@@ -48,6 +46,13 @@ export const configureApplication = Effect.fn("Application.configure")(function*
}
})
// electron-context-menu attaches to every existing and future window, so it can load once the first
// window is up instead of holding up startup with its dependency tree.
export const installContextMenu = Effect.gen(function* () {
const { default: contextMenu } = yield* Effect.promise(() => import("electron-context-menu"))
contextMenu({ showSaveImageAs: true, showLookUpSelection: false, showSearchWithGoogle: false })
})
export function acquireApplicationLock() {
if (app.requestSingleInstanceLock()) return true
app.quit()