diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 63513fac..0fd0cf29 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -158,8 +158,18 @@ jobs: - target: linux-x64 runner: ubuntu-24.04 args: --linux --x64 + - target: win-arm64 + runner: windows-11-arm + args: --win --arm64 + - target: win-x64 + runner: windows-2025 + args: --win --x64 env: CODEWORK_RELEASE_ID: ${{ needs.guard.outputs.id }} + # Windows runners default to PowerShell, which reads "$CHANNEL" as its own variable. + defaults: + run: + shell: bash steps: - uses: actions/checkout@v6 # The pacman target packs with bsdtar. @@ -184,6 +194,7 @@ jobs: apps/desktop/dist/codework-desktop-*.AppImage apps/desktop/dist/codework-desktop-*.deb apps/desktop/dist/codework-desktop-*.pacman + apps/desktop/dist/codework-desktop-*.exe if-no-files-found: error retention-days: 1 diff --git a/CLAUDE.md b/CLAUDE.md index 1d65bbe2..65be0da2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -81,7 +81,7 @@ Conventional Commit style with optional package scopes, e.g `feat(aikit): ...`, Every package is published by CI from `.github/workflows/publish.yml`, which runs `vp run release ` (`scripts/release.mjs`). It publishes the packages in dependency order, derived from their `package.json` workspace dependencies (`scripts/workspace.mjs`), pinning each package to the exact versions uploaded in the same run. `scripts/publish.mjs` builds a single package, rewrites its manifest and publishes it from a temp dir. -- **canary**: every push to `canary`, without `vp check` or typecheck, for quick testing. Versions are `-canary...g`. It also packages the desktop app (`apps/desktop`, `vp run package `) as "CodeWork Canary" for macOS arm64 and Linux x64/arm64, and replaces the `nightly` prerelease with it. +- **canary**: every push to `canary`, without `vp check` or typecheck, for quick testing. Versions are `-canary...g`. It also packages the desktop app (`apps/desktop`, `vp run package `) as "CodeWork Canary" for macOS arm64, Linux x64/arm64 and Windows x64/arm64, and replaces the `nightly` prerelease with it. - **dev**: every push to `dev`. Versions are `-dev.` (UTC). - **latest**: run the workflow by hand on `main`. It publishes each package whose manifest version is not on npm yet and skips the rest. diff --git a/apps/desktop/electron-builder.config.ts b/apps/desktop/electron.config.ts similarity index 71% rename from apps/desktop/electron-builder.config.ts rename to apps/desktop/electron.config.ts index 6ce6b617..84604f00 100644 --- a/apps/desktop/electron-builder.config.ts +++ b/apps/desktop/electron.config.ts @@ -25,9 +25,12 @@ export default { artifactName: "codework-desktop-${os}-${arch}.${ext}", // Nothing native to rebuild: the app server uses node:sqlite. npmRebuild: false, + // The app is in English, so Chromium's other locales are left out of every installer. + electronLanguages: ["en-US"], copyright: "Copyright © CodeWork", directories: { output: "dist", buildResources: "resources" }, - extraMetadata: { name: packageName, productName, homepage: "https://www.codework.sh" }, + // appId too: on Windows the app takes it as its AppUserModelID, the one the installer gives its shortcuts. + extraMetadata: { name: packageName, productName, appId, homepage: "https://www.codework.sh" }, // The app is its two bundles and its icon; Electron is the only dependency, and it is the runtime. files: ["out/*.cjs", "resources/icon.png", "package.json"], // The app server runs as its own process from Resources, so it sits outside the asar archive. @@ -48,6 +51,8 @@ export default { // flag removed until builds are signed and notarized. identity: "-", hardenedRuntime: false, + // macOS 26 offers Messages and Mail codes in every text field unless the app opts out. + extendInfo: { NSAutoFillRequiresTextContentTypeForOneTimeCodeOnMac: true }, }, dmg: { icon: "resources/icon.icns" }, linux: { @@ -60,8 +65,30 @@ export default { maintainer: "CodeWork", executableName: packageName, }, - deb: { packageName }, + deb: { + packageName, + // electron-builder's list misses ALSA and GBM, which Electron loads; Debian 13 and Ubuntu 24.04 + // renamed some to 64-bit-time names, so the old names stay as fallbacks. + depends: [ + "libasound2t64 | libasound2", + "libatspi2.0-0t64 | libatspi2.0-0", + "libgbm1", + "libgtk-3-0t64 | libgtk-3-0", + "libnotify4", + "libnss3", + "libsecret-1-0", + "libuuid1", + "libxss1", + "libxtst6", + "xdg-utils", + ], + }, pacman: { packageName }, + win: { + // One installer per run, for the arch scripts/package.mjs builds for. + target: "nsis", + icon: "resources/icon.ico", + }, // The static AppImage runtime, so it runs without libfuse2. toolsets: { appimage: "1.0.3" }, publish: null, diff --git a/apps/desktop/resources/icon.ico b/apps/desktop/resources/icon.ico new file mode 100644 index 00000000..df1b3edf Binary files /dev/null and b/apps/desktop/resources/icon.ico differ diff --git a/apps/desktop/scripts/package.mjs b/apps/desktop/scripts/package.mjs index 0c1a8a3b..6e05bfcc 100644 --- a/apps/desktop/scripts/package.mjs +++ b/apps/desktop/scripts/package.mjs @@ -16,8 +16,9 @@ if (!["canary", "dev", "latest"].includes(channel)) { process.exit(1); } +// On Windows pnpm is a .cmd shim, which Node runs only through a shell. const run = (command, args, cwd, env = process.env) => { - const result = spawnSync(command, args, { cwd, env, stdio: "inherit" }); + const result = spawnSync(command, args, { cwd, env, stdio: "inherit", shell: process.platform === "win32" }); if (result.status !== 0) process.exit(result.status ?? 1); }; @@ -36,7 +37,7 @@ run( "exec", "electron-builder", "--config", - "electron-builder.config.ts", + "electron.config.ts", `-c.extraMetadata.version=${version}`, "--publish", "never", diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index fcd177e8..5ecea8e7 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -1,4 +1,5 @@ import { app, BrowserWindow, dialog, ipcMain, net, protocol, shell } from "electron"; +import { readFileSync } from "node:fs"; import { readFile, stat } from "node:fs/promises"; import path from "node:path"; import { HOME_CHANNEL, PICK_FOLDER_CHANNEL, REVEAL_CHANNEL } from "./ipc.ts"; @@ -15,8 +16,8 @@ const DEV_SERVER_URL = process.env.CODEWORK_WEB_URL; const CLIENT_ASSETS_DIR = process.env.CODEWORK_WEB_DIR ?? (app.isPackaged ? path.join(process.resourcesPath, "web") : path.resolve(app.getAppPath(), "../web/dist")); -// The 3D brand mark on Apple's icon grid. A packaged build will carry it as an .icns; until then -// it is set at runtime, or the Dock shows Electron's own icon. +// The 3D brand mark on Apple's icon grid. A packaged build carries it as an .icns; an unpackaged run +// sets it at runtime, or the Dock shows Electron's own icon. const ICON = path.join(app.getAppPath(), "resources/icon.png"); const MIME_TYPES: Record = { @@ -124,22 +125,53 @@ function createMainWindow(): BrowserWindow { }), // Windows and Linux take the window's icon; macOS ignores it for the Dock's. icon: ICON, + // The default File/Edit menu bar shows until Alt; its shortcuts work either way. + autoHideMenuBar: true, // Hidden until the page's first paint, the splash in the saved theme, so it never opens blank. show: false, webPreferences: { preload: path.join(app.getAppPath(), "out/preload.cjs"), sandbox: true, + // A hidden window's renderer is throttled, which holds up the first paint that shows it. + backgroundThrottling: false, }, }); - window.once("ready-to-show", () => window.show()); + const reveal = () => { + window.show(); + window.webContents.setBackgroundThrottling(true); + }; + window.once("ready-to-show", reveal); // Linux can miss ready-to-show; the load finishing reveals the window there. - if (process.platform === "linux") window.webContents.once("did-finish-load", () => window.show()); + if (process.platform === "linux") window.webContents.once("did-finish-load", reveal); + // Links that open a new window, as a reply's links do, open in the browser instead. + window.webContents.setWindowOpenHandler(({ url }) => { + if (url.startsWith("https:") || url.startsWith("http:")) void shell.openExternal(url); + return { action: "deny" }; + }); void window.loadURL(APP_URL); return window; } +// A second launch (the Start menu, a .desktop file) would start a second app server on the same +// database, so it focuses the running app's window instead. +if (!app.requestSingleInstanceLock()) app.exit(); +app.on("second-instance", () => { + const window = BrowserWindow.getAllWindows()[0]; + if (window === undefined) return; + if (window.isMinimized()) window.restore(); + window.focus(); +}); + +// The installer's shortcuts carry the app id, and Windows groups the taskbar button with the +// shortcut whose id the running app takes. +if (process.platform === "win32" && app.isPackaged) { + const { appId } = JSON.parse(readFileSync(path.join(app.getAppPath(), "package.json"), "utf8")) as { appId: string }; + app.setAppUserModelId(appId); +} + void app.whenReady().then(async () => { - app.dock?.setIcon(ICON); + // A packaged app's Info.plist names its icon; setting it again would replace one the user chose. + if (!app.isPackaged) app.dock?.setIcon(ICON); protocol.handle(SCHEME, handleRequest); ipcMain.on(HOME_CHANNEL, (event) => { event.returnValue = app.getPath("home"); diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts index 8fec9cb6..ce8ec81f 100644 --- a/apps/desktop/src/preload.ts +++ b/apps/desktop/src/preload.ts @@ -6,6 +6,9 @@ contextBridge.exposeInMainWorld("desktopBridge", { // Main creates the window only after the server is ready, so this is set. server: ipcRenderer.sendSync(SERVER_CHANNEL) as string, home: ipcRenderer.sendSync(HOME_CHANNEL) as string, - pickFolder: (from: string) => ipcRenderer.invoke(PICK_FOLDER_CHANNEL, from) as Promise, - reveal: (path: string) => ipcRenderer.invoke(REVEAL_CHANNEL, path) as Promise, + // On Windows the CodeWork server runs in WSL, which has no use for the Windows paths these deal in. + ...(process.platform !== "win32" && { + pickFolder: (from: string) => ipcRenderer.invoke(PICK_FOLDER_CHANNEL, from) as Promise, + reveal: (path: string) => ipcRenderer.invoke(REVEAL_CHANNEL, path) as Promise, + }), }); diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json index fe14fcdd..c3038f7f 100644 --- a/apps/desktop/tsconfig.json +++ b/apps/desktop/tsconfig.json @@ -5,5 +5,5 @@ "lib": ["ES2023", "DOM"], "tsBuildInfoFile": "../../.cache/typescript/desktop.tsbuildinfo" }, - "include": ["src", "vite.config.ts", "electron-builder.config.ts", "bump.config.ts"] + "include": ["src", "vite.config.ts", "electron.config.ts", "bump.config.ts"] } diff --git a/apps/server/src/cli.ts b/apps/server/src/cli.ts index 7234aa68..e234a9b5 100644 --- a/apps/server/src/cli.ts +++ b/apps/server/src/cli.ts @@ -112,7 +112,8 @@ const executableOf = (row: Servers.Row, foundOnce: typeof found) => { ); }; -const alive = (pid: number) => +/** Whether a process runs under `pid`. */ +export const alive = (pid: number) => Effect.sync(() => { try { process.kill(pid, 0); diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts index b13f6d45..acbff9f4 100644 --- a/apps/server/src/server.ts +++ b/apps/server/src/server.ts @@ -5,6 +5,7 @@ import { RpcSerialization, RpcServer } from "effect/rpc"; /* @effect-diagnostics nodeBuiltinImport:off -- the RPC listener needs a raw node server. */ import { createServer } from "node:http"; import type { Socket } from "node:net"; +import { Cli } from "./cli.ts"; import { Codework } from "./codework.ts"; import { Contract } from "@codeworksh/contract"; import { Db } from "./db.ts"; @@ -51,9 +52,13 @@ const announceReady = Layer.effectDiscard( const exitWithParent = Layer.effectDiscard( Effect.gen(function* () { const parent = process.ppid; - yield* Effect.sync(() => process.ppid).pipe( - // Adopted by launchd (pid 1) is orphaned too, even when the parent was gone before this started. - Effect.repeat({ while: (ppid) => ppid === parent && ppid !== 1, schedule: Schedule.spaced("1 second") }), + // Adopted by launchd (pid 1) is orphaned too, even when the parent was gone before this started. + // Windows never adopts an orphan, so the parent itself is asked whether it still runs. + const attached = Effect.suspend(() => + process.ppid === parent && process.ppid !== 1 ? Cli.alive(parent) : Effect.succeed(false), + ); + yield* attached.pipe( + Effect.repeat({ while: (running) => running, schedule: Schedule.spaced("1 second") }), Effect.andThen(Effect.sync(() => process.kill(process.pid, "SIGTERM"))), Effect.forkScoped, ); diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts index df895260..1ccc7651 100644 --- a/apps/web/src/env.ts +++ b/apps/web/src/env.ts @@ -6,10 +6,10 @@ declare global { server: string; /** The user's home directory. */ home: string; - /** Opens the native folder dialog at `from`; the chosen folder, or null when cancelled. */ - pickFolder: (from: string) => Promise; - /** Shows `path` in the file manager, selected. */ - reveal: (path: string) => Promise; + /** Opens the native folder dialog at `from`; the chosen folder, or null when cancelled. Not on Windows. */ + pickFolder?: (from: string) => Promise; + /** Shows `path` in the file manager, selected. Not on Windows. */ + reveal?: (path: string) => Promise; }; } } diff --git a/apps/web/src/shell/sources.tsx b/apps/web/src/shell/sources.tsx index 62fc3541..886cd8a5 100644 --- a/apps/web/src/shell/sources.tsx +++ b/apps/web/src/shell/sources.tsx @@ -109,12 +109,13 @@ function useFinish(close: () => void) { }; } -/** The native folder dialog, opening at `from`; finishes on a pick. Absent outside the desktop app. */ +/** The native folder dialog, opening at `from`; finishes on a pick. Absent outside the desktop app and on Windows. */ function usePick(close: () => void) { const finish = useFinish(close); - if (bridge === undefined) return undefined; + const pickFolder = bridge?.pickFolder; + if (pickFolder === undefined) return undefined; return (from: string) => - void bridge.pickFolder(from).then((picked) => { + void pickFolder(from).then((picked) => { if (picked !== null) finish(picked); }); } diff --git a/scripts/github.mjs b/scripts/github.mjs index b234d6cb..68d84317 100644 --- a/scripts/github.mjs +++ b/scripts/github.mjs @@ -76,6 +76,8 @@ if (channel === "canary") { "", "macOS builds are not signed or notarized yet. After installing, run:", '`xattr -dr com.apple.quarantine "/Applications/CodeWork Canary.app"`', + "", + "Windows builds are not signed yet, so SmartScreen warns on install: choose More info, then Run anyway.", ].join("\n"), ); } else if (channel === "dev") {