Skip to content
Merged
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
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <channel>` (`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 `<version>-canary.<run>.<attempt>.g<sha>`. It also packages the desktop app (`apps/desktop`, `vp run package <channel>`) 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 `<version>-canary.<run>.<attempt>.g<sha>`. It also packages the desktop app (`apps/desktop`, `vp run package <channel>`) 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 `<version>-dev.<YYYYMMDDHHMMSS>` (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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: {
Expand All @@ -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,
Expand Down
Binary file added apps/desktop/resources/icon.ico
Binary file not shown.
5 changes: 3 additions & 2 deletions apps/desktop/scripts/package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -36,7 +37,7 @@ run(
"exec",
"electron-builder",
"--config",
"electron-builder.config.ts",
"electron.config.ts",
`-c.extraMetadata.version=${version}`,
"--publish",
"never",
Expand Down
42 changes: 37 additions & 5 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<string, string> = {
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 5 additions & 2 deletions apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>,
reveal: (path: string) => ipcRenderer.invoke(REVEAL_CHANNEL, path) as Promise<void>,
// 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<string | null>,
reveal: (path: string) => ipcRenderer.invoke(REVEAL_CHANNEL, path) as Promise<void>,
}),
});
2 changes: 1 addition & 1 deletion apps/desktop/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
3 changes: 2 additions & 1 deletion apps/server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions apps/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
);
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>;
/** Shows `path` in the file manager, selected. */
reveal: (path: string) => Promise<void>;
/** Opens the native folder dialog at `from`; the chosen folder, or null when cancelled. Not on Windows. */
pickFolder?: (from: string) => Promise<string | null>;
/** Shows `path` in the file manager, selected. Not on Windows. */
reveal?: (path: string) => Promise<void>;
};
}
}
Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/shell/sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/github.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Loading