diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0fe0c64 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +# Keep LF line endings on Windows checkouts too, so Prettier's check passes there. +* text=auto eol=lf +*.icns binary +*.ico binary +*.png binary +*.jpg binary +*.woff2 binary diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index aba00c5..a34982a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -34,7 +34,7 @@ body: id: os attributes: label: OS version - placeholder: macOS 15.1 (Apple Silicon) + placeholder: macOS 15.1 (Apple Silicon), Windows 11 24H2 validations: required: true - type: input diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3d19bf..300409a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,3 +26,21 @@ jobs: # on first launch and one of them fails. - run: pnpm --filter @plotka/desktop exec node node_modules/electron/install.js - run: pnpm test:e2e + + # The same tests on Windows. Formatting and lint don't depend on the platform, so they only + # run above. + windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - run: corepack enable pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm typecheck + - run: pnpm test + - run: pnpm --filter @plotka/desktop exec node node_modules/electron/install.js + - run: pnpm test:e2e + # Check the installer still builds. + - run: pnpm build:win diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9862d00..cce7bc5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,18 +1,23 @@ name: Release -# Builds an UNSIGNED macOS app and attaches it to a DRAFT GitHub release. Releases are normally -# built, signed and notarized on a Mac with `pnpm release:publish`; this is the fallback, so it -# only runs by hand (a tag push must not replace a signed .dmg with an unsigned one). -# See docs/releasing.md. +# Builds UNSIGNED apps and attaches them to a DRAFT GitHub release. Releases are normally built on +# a Mac with `pnpm release:publish` (the .dmg signed and notarized, plus the Windows installer); +# this is the fallback, so it only runs by hand (a tag push must not replace a signed .dmg with an +# unsigned one). See docs/releasing.md. on: workflow_dispatch: inputs: tag: description: 'Existing tag to build, e.g. v0.2.0' required: true + platforms: + description: 'Which apps to build. "mac" replaces a signed .dmg with an unsigned one.' + type: choice + options: [windows, mac, both] + default: windows permissions: - contents: write # create the draft release and upload the .dmg + contents: write # create the draft release and upload the apps concurrency: group: release-${{ github.event.inputs.tag || github.ref_name }} @@ -20,6 +25,7 @@ concurrency: jobs: mac: + if: inputs.platforms != 'windows' runs-on: macos-latest env: TAG: ${{ github.event.inputs.tag || github.ref_name }} @@ -68,3 +74,59 @@ jobs: else gh release create "$TAG" "${files[@]}" --draft --title "Plotka $TAG" --generate-notes fi + + windows: + # After the Mac job (if it runs), so the two don't both try to create the draft release. + needs: mac + if: ${{ !cancelled() && inputs.platforms != 'mac' && needs.mac.result != 'failure' }} + runs-on: windows-latest + defaults: + run: + shell: bash + env: + TAG: ${{ github.event.inputs.tag || github.ref_name }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - run: corepack enable pnpm + - run: pnpm install --frozen-lockfile + + - name: Check the tag matches the app version + run: | + version=$(node -p "require('./apps/desktop/package.json').version") + if [ "$TAG" != "v$version" ]; then + echo "::error::Tag $TAG doesn't match the app version $version (apps/desktop/package.json). Bump the version, then tag v$version." + exit 1 + fi + + - name: Checks + run: | + pnpm lint + pnpm typecheck + pnpm test + + - name: Build the installer (unsigned) + run: pnpm build:win + env: + CSC_IDENTITY_AUTO_DISCOVERY: 'false' + + - name: Create or update the draft release + env: + GH_TOKEN: ${{ github.token }} + run: | + shopt -s nullglob + files=(apps/desktop/release/*-setup.exe apps/desktop/release/*-setup.exe.blockmap) + if [ ${#files[@]} -eq 0 ]; then + echo "::error::No installer was built." + exit 1 + fi + if gh release view "$TAG" >/dev/null 2>&1; then + gh release upload "$TAG" "${files[@]}" --clobber + else + gh release create "$TAG" "${files[@]}" --draft --title "Plotka $TAG" --generate-notes + fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21cfbd9..b779619 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,8 +66,8 @@ a seed. Full guide: `docs/adding-a-transform.md` (coming with the transforms epi ## Reporting bugs -Use the bug report template and include your machine model, firmware version and macOS -version. +Use the bug report template and include your machine model, firmware version and operating +system version. ## Keeping the user guide up to date @@ -80,4 +80,5 @@ and every "?" button points to a page and section that exist. ## App icon The icon's source is `apps/desktop/build/icon.svg`. After editing it, run -`apps/desktop/scripts/make-icon.sh` (macOS) to regenerate `build/icon.icns`. +`apps/desktop/scripts/make-icon.sh` (macOS) to regenerate `build/icon.icns` and +`build/icon.ico`. diff --git a/README.md b/README.md index b08b370..bb7db01 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ extension needed. ![Plotka welcome screen: an example plot and Open…, Doodle… and + Text](docs/screenshots/welcome.png) -**Status:** early releases for macOS, tested on an AxiDraw V3/A3. Download the app from +**Status:** early releases for macOS and Windows, tested on an AxiDraw V3/A3 on macOS. Download the app from [GitHub releases](../../releases/latest). ## Features @@ -94,13 +94,18 @@ Any EiBotBoard (EBB) based plotter should work with a machine profile. See ## Install -Download the `.dmg` from the [latest release](../../releases/latest). It runs on macOS, on -Apple Silicon and Intel. Windows and Linux aren't planned for now, but pull requests that add -them are welcome. +Download it from the [latest release](../../releases/latest). -From v0.5.0 the app is signed and notarized: open the `.dmg`, drag Plotka to Applications and -open it like any other app. (v0.4.0 and older aren't signed. Right-click the app and choose -**Open** the first time.) +**macOS** (Apple Silicon and Intel): download the `.dmg`. From v0.5.0 the app is signed and +notarized: open the `.dmg`, drag Plotka to Applications and open it like any other app. (v0.4.0 +and older aren't signed. Right-click the app and choose **Open** the first time.) + +**Windows** (10 and 11, 64-bit): download `Plotka-…-x64-setup.exe` and +run it. It installs for your user only, without asking for admin rights. The installer isn't +signed yet, so Windows SmartScreen says it "protected your PC" the first time: click **More +info**, then **Run anyway**. The plotter needs no driver; it shows up as a COM port. + +Linux isn't planned for now, but pull requests that add it are welcome. ## How it works @@ -147,6 +152,7 @@ pnpm test # unit tests (Vitest) pnpm lint # ESLint pnpm typecheck # TypeScript pnpm build:mac # universal (Apple Silicon + Intel) .dmg in apps/desktop/release +pnpm build:win # Windows x64 installer in apps/desktop/release (builds on macOS too) pnpm release 0.5.0 # bump, commit and tag a release; see docs/releasing.md pnpm release:publish # build, sign, notarize and upload it as a draft release ``` diff --git a/apps/desktop/build/icon.ico b/apps/desktop/build/icon.ico new file mode 100644 index 0000000..f188118 Binary files /dev/null and b/apps/desktop/build/icon.ico differ diff --git a/apps/desktop/e2e/layers.spec.ts b/apps/desktop/e2e/layers.spec.ts index 690572b..613b983 100644 --- a/apps/desktop/e2e/layers.spec.ts +++ b/apps/desktop/e2e/layers.spec.ts @@ -58,11 +58,11 @@ test('arrange: move and resize layers and the whole artwork by dragging', async }; const drag = async (from: { x: number; y: number }, dx: number, dy: number, noSnap = false) => { await page.mouse.move(from.x, from.y); - if (noSnap) await page.keyboard.down('Meta'); + if (noSnap) await page.keyboard.down('ControlOrMeta'); await page.mouse.down(); await page.mouse.move(from.x + dx, from.y + dy, { steps: 8 }); await page.mouse.up(); - if (noSnap) await page.keyboard.up('Meta'); + if (noSnap) await page.keyboard.up('ControlOrMeta'); await expect(page.getByText('Updating…')).toHaveCount(0); }; const fillTabValue = async (name: string, nth = 0) => { diff --git a/apps/desktop/e2e/plotting.spec.ts b/apps/desktop/e2e/plotting.spec.ts index e142b8d..2e8da75 100644 --- a/apps/desktop/e2e/plotting.spec.ts +++ b/apps/desktop/e2e/plotting.spec.ts @@ -45,7 +45,10 @@ test('connect the simulated plotter, jog, plot, pause, resume, finish', async () }); expect(opened[0]).toMatch(/plotka\.log$/); expect(opened[1]).toMatch( - /^https:\/\/github\.com\/blnkhz\/plotka\/issues\/new\?template=bug_report\.yml&app=[\d.]+&os=macOS/, + new RegExp( + String.raw`^https://github\.com/blnkhz/plotka/issues/new\?template=bug_report\.yml&app=[\d.]+&os=` + + (process.platform === 'win32' ? 'Windows' : 'macOS'), + ), ); await app.close(); diff --git a/apps/desktop/e2e/projects.spec.ts b/apps/desktop/e2e/projects.spec.ts index a9f8680..4961652 100644 --- a/apps/desktop/e2e/projects.spec.ts +++ b/apps/desktop/e2e/projects.spec.ts @@ -1,7 +1,8 @@ +import { execFileSync } from 'node:child_process'; import { mkdtempSync, readFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { expect, test } from '@playwright/test'; +import { expect, test, type ElectronApplication } from '@playwright/test'; import { shots, launch, dropFile } from './helpers'; test('save a project and open it again with all its settings (PROJ-1)', async () => { @@ -113,10 +114,38 @@ test('undo and redo settings from the Edit menu and the toolbar (PROJ-2)', async await app.close(); }); +/** + * Kills the app with no clean shutdown, and waits until it's gone. On Windows, Electron's helper + * processes outlive a killed main process for a moment and keep the single-instance lock, so a + * copy started then quits at once: kill the whole process tree there. + */ +async function crash(app: ElectronApplication) { + const proc = app.process(); + const exited = new Promise((resolve) => proc.once('exit', resolve)); + if (process.platform === 'win32') { + execFileSync('taskkill', ['/pid', String(proc.pid), '/T', '/F'], { stdio: 'ignore' }); + } else { + proc.kill('SIGKILL'); + } + await exited; +} + +/** Launches the app, trying again for a few seconds while a crashed copy still holds the lock. */ +async function relaunch(env: Record) { + for (let attempt = 1; ; attempt++) { + try { + return await launch(env); + } catch (e) { + if (attempt === 5) throw e; + await new Promise((r) => setTimeout(r, 1000)); + } + } +} + test('autosave: unsaved work comes back after a crash (PROJ-4)', async () => { const data = mkdtempSync(join(tmpdir(), 'plotka-e2e-')); const open = async () => { - const app = await launch({ PLOTKA_USER_DATA: data }); + const app = await relaunch({ PLOTKA_USER_DATA: data }); const page = await app.firstWindow(); await page.setViewportSize({ width: 1400, height: 900 }); await page.locator('#root > div').waitFor(); @@ -127,7 +156,7 @@ test('autosave: unsaved work comes back after a crash (PROJ-4)', async () => { await dropFile(page, 'motif.svg'); await page.getByRole('button', { name: 'Landscape' }).click(); await page.waitForTimeout(4000); // autosave writes 3 s after the last change - app.process().kill('SIGKILL'); // no clean shutdown + await crash(app); // no clean shutdown ({ app, page } = await open()); const banner = page.getByRole('alert'); @@ -140,7 +169,7 @@ test('autosave: unsaved work comes back after a crash (PROJ-4)', async () => { .poll(() => app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0]!.getTitle())) .toContain('(edited)'); await page.waitForTimeout(4000); - app.process().kill('SIGKILL'); + await crash(app); // Discard removes it for good. ({ app, page } = await open()); diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.yml index c201b61..228549c 100644 --- a/apps/desktop/electron-builder.yml +++ b/apps/desktop/electron-builder.yml @@ -6,8 +6,6 @@ directories: files: - out/** - package.json - # Only the macOS serialport binary is needed in a Mac build. - - '!**/node_modules/@serialport/bindings-cpp/prebuilds/{android,linux,win32}-*/**' # The licence and third-party notices (fonts included) ship inside the app, in Resources. extraResources: - from: ../../LICENSE @@ -18,6 +16,9 @@ asarUnpack: - '**/node_modules/@serialport/bindings-cpp/**' mac: category: public.app-category.graphics-design + # Only the macOS serialport binary is needed in a Mac build. + files: + - '!**/node_modules/@serialport/bindings-cpp/prebuilds/{android,linux,win32}-*/**' target: - target: dmg arch: [universal] @@ -25,7 +26,25 @@ mac: # `pnpm release:publish`, which sets the identity on the command line and notarizes with a # notarytool keychain profile (APPLE_KEYCHAIN_PROFILE). See docs/releasing.md. identity: null -# serialport ships a universal (x64 + arm64) N-API prebuild, which Electron loads as is, so -# nothing needs compiling. Everything else is bundled into out/ by electron-vite; only -# `dependencies` (just serialport) are packaged. +win: + icon: build/icon.ico + target: + - target: nsis + arch: [x64] + # Only the 64-bit Windows serialport binary is needed. Windows 11 on Arm runs the x64 build. + files: + - '!**/node_modules/@serialport/bindings-cpp/prebuilds/{android,darwin,linux}-*/**' + - '!**/node_modules/@serialport/bindings-cpp/prebuilds/win32-{arm64,ia32}/**' + # Builds are unsigned for now, so Windows SmartScreen warns the first time. See + # docs/releasing.md. +nsis: + # A per-user install with no admin prompt; it opens Plotka when it finishes. + oneClick: true + perMachine: false + artifactName: ${productName}-${version}-x64-setup.${ext} + # Settings, pen heights and the plot log stay if Plotka is uninstalled. + deleteAppDataOnUninstall: false +# serialport ships N-API prebuilds for every platform (a universal one for macOS), which +# Electron loads as they are, so nothing needs compiling. Everything else is bundled into out/ +# by electron-vite; only `dependencies` (just serialport) are packaged. npmRebuild: false diff --git a/apps/desktop/package.json b/apps/desktop/package.json index fc5bd08..57b7d13 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -11,6 +11,7 @@ "build": "electron-vite build", "preview": "electron-vite preview", "build:mac": "electron-vite build && electron-builder --mac --universal --publish never", + "build:win": "electron-vite build && electron-builder --win --x64 --publish never", "typecheck": "tsc -p tsconfig.node.json && tsc -p tsconfig.web.json && tsc -p tsconfig.e2e.json", "test:e2e": "electron-vite build && playwright test" }, diff --git a/apps/desktop/scripts/make-ico.cjs b/apps/desktop/scripts/make-ico.cjs new file mode 100644 index 0000000..961944d --- /dev/null +++ b/apps/desktop/scripts/make-ico.cjs @@ -0,0 +1,33 @@ +// Packs square PNGs into a Windows .ico (used by make-icon.sh). Windows Vista and later read +// PNG images inside an .ico directly, so the PNGs go in as they are. +// Usage: node make-ico.cjs out.ico 16.png 32.png … 256.png +const fs = require('fs'); + +const [out, ...inputs] = process.argv.slice(2); +const images = inputs.map((file) => { + const png = fs.readFileSync(file); + if (png.readUInt32BE(12) !== 0x49484452) throw new Error(`${file} isn't a PNG`); + return { png, width: png.readUInt32BE(16), height: png.readUInt32BE(20) }; +}); + +const header = Buffer.alloc(6); +header.writeUInt16LE(0, 0); // reserved +header.writeUInt16LE(1, 2); // 1 = icon +header.writeUInt16LE(images.length, 4); + +let offset = 6 + 16 * images.length; +const entries = images.map(({ png, width, height }) => { + const e = Buffer.alloc(16); + e.writeUInt8(width >= 256 ? 0 : width, 0); // 0 means 256 + e.writeUInt8(height >= 256 ? 0 : height, 1); + e.writeUInt8(0, 2); // no palette + e.writeUInt8(0, 3); // reserved + e.writeUInt16LE(1, 4); // colour planes + e.writeUInt16LE(32, 6); // bits per pixel + e.writeUInt32LE(png.length, 8); + e.writeUInt32LE(offset, 12); + offset += png.length; + return e; +}); + +fs.writeFileSync(out, Buffer.concat([header, ...entries, ...images.map((i) => i.png)])); diff --git a/apps/desktop/scripts/make-icon.sh b/apps/desktop/scripts/make-icon.sh index 15c014f..cebc852 100755 --- a/apps/desktop/scripts/make-icon.sh +++ b/apps/desktop/scripts/make-icon.sh @@ -1,14 +1,25 @@ #!/bin/sh -# Rebuilds build/icon.icns from build/icon.svg. macOS only (sips, iconutil). +# Rebuilds build/icon.icns (macOS) and build/icon.ico (Windows) from build/icon.svg. +# Runs on macOS only (sips, iconutil). set -e cd "$(dirname "$0")/.." tmp=$(mktemp -d) ./node_modules/.bin/electron scripts/render-icon.cjs build/icon.svg "$tmp/icon.png" + mkdir "$tmp/icon.iconset" for s in 16 32 128 256 512; do sips -z $s $s "$tmp/icon.png" --out "$tmp/icon.iconset/icon_${s}x${s}.png" >/dev/null sips -z $((s * 2)) $((s * 2)) "$tmp/icon.png" --out "$tmp/icon.iconset/icon_${s}x${s}@2x.png" >/dev/null done iconutil -c icns "$tmp/icon.iconset" -o build/icon.icns -rm -rf "$tmp" echo "Wrote build/icon.icns" + +mkdir "$tmp/ico" +for s in 16 24 32 48 64 128 256; do + sips -z $s $s "$tmp/icon.png" --out "$tmp/ico/$s.png" >/dev/null +done +node scripts/make-ico.cjs build/icon.ico "$tmp"/ico/16.png "$tmp"/ico/24.png "$tmp"/ico/32.png \ + "$tmp"/ico/48.png "$tmp"/ico/64.png "$tmp"/ico/128.png "$tmp"/ico/256.png +echo "Wrote build/icon.ico" + +rm -rf "$tmp" diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts index 3fa1ada..abcacaf 100644 --- a/apps/desktop/src/main/index.ts +++ b/apps/desktop/src/main/index.ts @@ -1,3 +1,4 @@ +import { existsSync } from 'node:fs'; import { join } from 'node:path'; import { app, BrowserWindow, dialog, shell } from 'electron'; import { registerIpcHandlers } from './ipc'; @@ -56,7 +57,7 @@ function createWindow(): BrowserWindow { defaultId: 0, cancelId: 0, message: `“${project.name}” has unsaved changes.`, - detail: 'Save with ⌘S to keep them.', + detail: `Save with ${process.platform === 'darwin' ? '⌘S' : 'Ctrl+S'} to keep them.`, }); if (choice === 0) e.preventDefault(); // Closing without saving was a deliberate choice: don't offer the work back next time. @@ -101,13 +102,41 @@ function createWindow(): BrowserWindow { // Files opened from Finder or the Dock (also before the window exists). const pendingOpens: string[] = []; -app.on('open-file', (e, path) => { - e.preventDefault(); +function requestOpen(path: string) { if (!isOpenable(path)) return; if (app.isReady() && BrowserWindow.getAllWindows().length) void openPath(path); else pendingOpens.push(path); +} +app.on('open-file', (e, path) => { + e.preventDefault(); + requestOpen(path); }); +/** Files on the command line: how Windows and Linux open a file with the app. */ +function filesInArgs(argv: readonly string[]): string[] { + // A packaged app's arguments follow the executable; in development, `electron .` comes first. + return argv + .slice(app.isPackaged ? 1 : 2) + .filter((a) => !a.startsWith('-') && isOpenable(a) && existsSync(a)); +} + +// On Windows and Linux, opening a file while Plotka is running starts a second copy: hand the +// file to the running one and quit. (macOS sends open-file to the running app instead.) +if (process.platform !== 'darwin') { + if (!app.requestSingleInstanceLock()) app.exit(0); + else { + app.on('second-instance', (_e, argv) => { + const win = BrowserWindow.getAllWindows()[0]; + if (win) { + if (win.isMinimized()) win.restore(); + win.focus(); + } + filesInArgs(argv).forEach(requestOpen); + }); + filesInArgs(process.argv).forEach(requestOpen); + } +} + /** Opens files that arrived before the window was listening. */ export function flushPendingOpens() { for (const p of pendingOpens.splice(0)) void openPath(p); diff --git a/apps/desktop/src/main/log.ts b/apps/desktop/src/main/log.ts index 53e8597..80a5f87 100644 --- a/apps/desktop/src/main/log.ts +++ b/apps/desktop/src/main/log.ts @@ -2,10 +2,11 @@ import { homedir, release } from 'node:os'; import { join } from 'node:path'; import { app, shell, type WebContents } from 'electron'; import { createLogger, type Logger } from './logger'; -import { bugReportUrl, describeMac } from './report'; +import { bugReportUrl, describeSystem } from './report'; /** - * The app's log, at ~/Library/Logs/Plotka/plotka.log (Help › Show Log File). It records what's + * The app's log, at ~/Library/Logs/Plotka/plotka.log on macOS and + * %APPDATA%\Plotka\logs\plotka.log on Windows (Help › Show Log File). It records what's * useful in a bug report: the app and OS versions, connections, plots and how they ended, and * errors from the main process and the window. No artwork and no full paths outside ~. */ @@ -33,7 +34,7 @@ export function startLogging() { log.info('Plotka started', { version: app.getVersion(), packaged: app.isPackaged, - macOS: process.platform === 'darwin' ? process.getSystemVersion() : undefined, + os: describeSystem(process.platform, process.getSystemVersion(), process.arch), platform: process.platform, kernel: release(), arch: process.arch, @@ -67,11 +68,11 @@ export function revealLog() { /** * Help › Report a Problem: opens the GitHub bug report form with the versions filled in, and - * shows the log in Finder so it can be dragged into the form. + * shows the log in Finder or File Explorer so it can be dragged into the form. */ export function reportProblem() { log.info('Report a problem'); shell.showItemInFolder(log.file); - const os = describeMac(process.getSystemVersion(), process.arch); + const os = describeSystem(process.platform, process.getSystemVersion(), process.arch); void shell.openExternal(bugReportUrl(app.getVersion(), os)); } diff --git a/apps/desktop/src/main/menu.ts b/apps/desktop/src/main/menu.ts index ca4df4b..017f75d 100644 --- a/apps/desktop/src/main/menu.ts +++ b/apps/desktop/src/main/menu.ts @@ -14,8 +14,8 @@ function send(action: Action, win?: BrowserWindow | null) { } /** - * The app menu. Its shortcuts are the only handlers for ⌘O, ⌘S, ⇧⌘S, ⌘Z and ⇧⌘Z; the page - * decides what each means (e.g. Undo in a text field undoes typing). + * The app menu. Its shortcuts are the only handlers for ⌘O, ⌘S, ⇧⌘S, ⌘Z and ⇧⌘Z (Ctrl+Y on + * Windows and Linux, where the page handles Ctrl+Shift+Z); the page decides what each means (e.g. Undo in a text field undoes typing). */ export function installMenu() { build(); @@ -64,7 +64,8 @@ function build() { label: 'Edit', submenu: [ item('undo', 'Undo', 'CmdOrCtrl+Z'), - item('redo', 'Redo', 'Shift+CmdOrCtrl+Z'), + // Windows' usual Redo is Ctrl+Y; the page also takes Ctrl+Shift+Z there (App.tsx). + item('redo', 'Redo', isMac ? 'Shift+Cmd+Z' : 'Ctrl+Y'), { type: 'separator' }, { role: 'cut' }, { role: 'copy' }, @@ -103,6 +104,8 @@ function build() { // For bug reports: the log has the versions, connections, plots and errors. { label: 'Show Log File', click: () => revealLog() }, { label: 'Report a Problem…', click: () => reportProblem() }, + // On macOS, About is in the app menu. + ...(isMac ? [] : [{ type: 'separator' as const }, { role: 'about' as const }]), ], }, ]; diff --git a/apps/desktop/src/main/report.ts b/apps/desktop/src/main/report.ts index 027d2ef..81472cd 100644 --- a/apps/desktop/src/main/report.ts +++ b/apps/desktop/src/main/report.ts @@ -10,7 +10,18 @@ export function bugReportUrl(appVersion: string, os: string): string { return `${NEW_ISSUE}?${q}`; } -/** "macOS 15.1 (Apple Silicon)", as the form's placeholder shows it. */ -export function describeMac(version: string, arch: string): string { - return `macOS ${version} (${arch === 'arm64' ? 'Apple Silicon' : 'Intel'})`; +/** + * The OS the way the form's placeholder shows it: "macOS 15.1 (Apple Silicon)", + * "Windows 11 (build 26100)". `version` is process.getSystemVersion(). + */ +export function describeSystem(platform: string, version: string, arch: string): string { + if (platform === 'darwin') + return `macOS ${version} (${arch === 'arm64' ? 'Apple Silicon' : 'Intel'})`; + if (platform === 'win32') { + // Windows 11 still reports 10.0; its builds start at 22000. + const build = Number(version.split('.')[2]); + const name = build >= 22000 ? 'Windows 11' : 'Windows 10'; + return `${name} (build ${Number.isFinite(build) ? build : version}${arch === 'arm64' ? ', Arm' : ''})`; + } + return `${platform === 'linux' ? 'Linux' : platform} ${version} (${arch})`; } diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsx index 2ab2018..f4490bf 100644 --- a/apps/desktop/src/renderer/src/App.tsx +++ b/apps/desktop/src/renderer/src/App.tsx @@ -19,6 +19,7 @@ import { startAutosave } from './lib/autosave'; import { RecoveryBanner } from './components/RecoveryBanner'; import { openFromOutside } from './lib/openFile'; import { fmtDistance } from './lib/format'; +import { isMac, keyText } from './lib/keys'; import { useProcessed, useProcessing } from './lib/useProcessed'; import { fmtDuration } from './lib/format'; import { useStore, selectedDoodle } from './store'; @@ -154,23 +155,33 @@ function Toolbar() { return (
- - - - {loading ? 'Loading…' : (source?.name ?? 'No file')} @@ -251,6 +262,10 @@ function useShortcuts() { if (e.key === 'F1') { e.preventDefault(); useStore.getState().openHelp(); + } else if (!isMac && e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'z') { + // Off macOS the menu's Redo is Ctrl+Y; Ctrl+Shift+Z redoes too. + e.preventDefault(); + void menuAction('redo'); } else if (useStore.getState().help.open) { // Typing in the help window shouldn't move the plotter. } else if (!mod && !typing && e.key.toLowerCase() === 'f') { diff --git a/apps/desktop/src/renderer/src/components/DoodlePad.tsx b/apps/desktop/src/renderer/src/components/DoodlePad.tsx index 06054e8..3fd8b46 100644 --- a/apps/desktop/src/renderer/src/components/DoodlePad.tsx +++ b/apps/desktop/src/renderer/src/components/DoodlePad.tsx @@ -15,6 +15,7 @@ import { type Primitive, type Vec2, } from '@plotka/core'; +import { fileName, keyText } from '../lib/keys'; import { doodleSvg, useStore } from '../store'; import { NumberField, Row, Section, Segmented } from './controls'; import styles from './DoodlePad.module.css'; @@ -420,7 +421,7 @@ export function DoodlePad() { doodleSvg(useStore.getState().doodle), ['.svg'], ); - if (path) setSaved(path.split('/').pop() ?? path); + if (path) setSaved(fileName(path)); }} > Save SVG… @@ -559,10 +560,10 @@ export function DoodlePad() { }} />
- -
diff --git a/apps/desktop/src/renderer/src/components/RightPanel.tsx b/apps/desktop/src/renderer/src/components/RightPanel.tsx index b178683..2b1c48c 100644 --- a/apps/desktop/src/renderer/src/components/RightPanel.tsx +++ b/apps/desktop/src/renderer/src/components/RightPanel.tsx @@ -10,6 +10,7 @@ import { exportPlot } from '../lib/exportPlot'; import { OptimizeSection } from './OptimizeSection'; import { PageTab } from './PageTab'; import { StatsTable } from './StatsTable'; +import { keyText } from '../lib/keys'; import styles from './RightPanel.module.css'; const TABS: { id: Tab; label: string }[] = [ @@ -130,13 +131,13 @@ function PlotTab() {
diff --git a/apps/desktop/src/renderer/src/lib/helpDocs.ts b/apps/desktop/src/renderer/src/lib/helpDocs.ts index 6d60936..444d20a 100644 --- a/apps/desktop/src/renderer/src/lib/helpDocs.ts +++ b/apps/desktop/src/renderer/src/lib/helpDocs.ts @@ -1,4 +1,5 @@ import { buildTopics, type HelpTopic } from './help'; +import { keyText } from './keys'; // The guide is bundled into the app at build time from docs/guide. const files = import.meta.glob('../../../../../../docs/guide/*.md', { @@ -7,6 +8,9 @@ const files = import.meta.glob('../../../../../../docs/guide/*.md', { eager: true, }) as Record; -export const HELP_TOPICS: HelpTopic[] = buildTopics(files); +// The guide is written with macOS key symbols; elsewhere they read Ctrl+S and so on. +export const HELP_TOPICS: HelpTopic[] = buildTopics( + Object.fromEntries(Object.entries(files).map(([f, md]) => [f, keyText(md)])), +); export const findTopic = (id: string) => HELP_TOPICS.find((t) => t.id === id); diff --git a/apps/desktop/src/renderer/src/lib/keys.ts b/apps/desktop/src/renderer/src/lib/keys.ts new file mode 100644 index 0000000..c50b300 --- /dev/null +++ b/apps/desktop/src/renderer/src/lib/keys.ts @@ -0,0 +1,31 @@ +/** + * Keyboard shortcuts as people see them. The app's text is written with macOS symbols + * (⌘S, ⇧⌘Z, ⌥); on Windows and Linux they read Ctrl+S, Ctrl+Shift+Z, Alt. + */ + +export const isMac = typeof navigator !== 'undefined' && /Mac/.test(navigator.userAgent); + +const NAMES: Record = { '⌃': 'Ctrl', '⌘': 'Ctrl', '⌥': 'Alt', '⇧': 'Shift' }; +const ORDER = ['Ctrl', 'Alt', 'Shift']; + +/** + * Rewrites the macOS key symbols in a piece of text for this platform. A run of modifiers joins + * the key after it with "+" ("⇧⌘S" → "Ctrl+Shift+S"); a modifier on its own just gets its name + * ("hold ⇧", "⇧-click"). + */ +export function keyText(text: string, mac = isMac): string { + if (mac) return text; + return text.replace(/([⌃⌘⌥⇧]+)([A-Z0-9?]?)/g, (_m, mods: string, key: string) => { + const names = [...new Set([...mods].map((m) => NAMES[m] ?? m))].sort( + (a, b) => ORDER.indexOf(a) - ORDER.indexOf(b), + ); + return [...names, ...(key ? [key] : [])].join('+'); + }); +} + +/** Whether the platform's command key (⌘ on macOS, Ctrl elsewhere) is held. */ +export const commandKey = (e: { metaKey: boolean; ctrlKey: boolean }, mac = isMac) => + mac ? e.metaKey : e.ctrlKey; + +/** The last part of a file path, with either kind of slash. */ +export const fileName = (path: string) => path.split(/[\\/]/).pop() || path; diff --git a/apps/desktop/test/keys.test.ts b/apps/desktop/test/keys.test.ts new file mode 100644 index 0000000..9631284 --- /dev/null +++ b/apps/desktop/test/keys.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from 'vitest'; +import { commandKey, fileName, keyText } from '../src/renderer/src/lib/keys'; + +describe('keyText', () => { + it('leaves the text alone on macOS', () => { + expect(keyText('Save (⇧⌘S)', true)).toBe('Save (⇧⌘S)'); + }); + + it('spells out shortcuts elsewhere', () => { + expect(keyText('Open (⌘O)', false)).toBe('Open (Ctrl+O)'); + expect(keyText('⌘Z / ⇧⌘Z', false)).toBe('Ctrl+Z / Ctrl+Shift+Z'); + expect(keyText('Help (⌘?)', false)).toBe('Help (Ctrl+?)'); + }); + + it('names a modifier on its own', () => { + expect(keyText('⇧ free, ⌥ from center · ⌘ no snapping', false)).toBe( + 'Shift free, Alt from center · Ctrl no snapping', + ); + expect(keyText('hold **⇧** to stretch, ⇧-click another', false)).toBe( + 'hold **Shift** to stretch, Shift-click another', + ); + }); +}); + +describe('commandKey', () => { + it('is ⌘ on macOS and Ctrl elsewhere', () => { + expect(commandKey({ metaKey: true, ctrlKey: false }, true)).toBe(true); + expect(commandKey({ metaKey: false, ctrlKey: true }, true)).toBe(false); + expect(commandKey({ metaKey: false, ctrlKey: true }, false)).toBe(true); + expect(commandKey({ metaKey: true, ctrlKey: false }, false)).toBe(false); + }); +}); + +describe('fileName', () => { + it('handles both kinds of slash', () => { + expect(fileName('/Users/me/art.svg')).toBe('art.svg'); + expect(fileName('C:\\Users\\me\\art.svg')).toBe('art.svg'); + expect(fileName('art.svg')).toBe('art.svg'); + }); +}); diff --git a/apps/desktop/test/report.test.ts b/apps/desktop/test/report.test.ts index e0a54c0..a95aeda 100644 --- a/apps/desktop/test/report.test.ts +++ b/apps/desktop/test/report.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { bugReportUrl, describeMac } from '../src/main/report'; +import { bugReportUrl, describeSystem } from '../src/main/report'; describe('bug report link', () => { it('opens the bug report form with the versions filled in', () => { @@ -11,7 +11,17 @@ describe('bug report link', () => { }); it('names the Mac the way the form asks for it', () => { - expect(describeMac('15.1', 'arm64')).toBe('macOS 15.1 (Apple Silicon)'); - expect(describeMac('14.6.1', 'x64')).toBe('macOS 14.6.1 (Intel)'); + expect(describeSystem('darwin', '15.1', 'arm64')).toBe('macOS 15.1 (Apple Silicon)'); + expect(describeSystem('darwin', '14.6.1', 'x64')).toBe('macOS 14.6.1 (Intel)'); + }); + + it('tells Windows 11 from Windows 10, which both report 10.0', () => { + expect(describeSystem('win32', '10.0.26100', 'x64')).toBe('Windows 11 (build 26100)'); + expect(describeSystem('win32', '10.0.22631', 'arm64')).toBe('Windows 11 (build 22631, Arm)'); + expect(describeSystem('win32', '10.0.19045', 'x64')).toBe('Windows 10 (build 19045)'); + }); + + it('describes Linux plainly', () => { + expect(describeSystem('linux', '6.8.0', 'x64')).toBe('Linux 6.8.0 (x64)'); }); }); diff --git a/docs/guide/01-getting-started.md b/docs/guide/01-getting-started.md index 3af160f..21f8603 100644 --- a/docs/guide/01-getting-started.md +++ b/docs/guide/01-getting-started.md @@ -23,10 +23,10 @@ one of your recent files. Press Esc or click outside it to go straight to the ap ## Light, dark and colour themes -The app follows the light or dark setting of macOS. Under **View > Appearance** you can pick +The app follows the system's light or dark setting. Under **View > Appearance** you can pick **Light** or **Dark** for the app only, or one of six colour themes: **Matcha Mauve**, **Cyber Lime**, **Butter Cobalt**, **Bubblegum Tomato**, **Ube Mint** and **Ice Tangerine**. **Use -System Setting** follows macOS again. The choice is kept for next time. The paper in the preview +System Setting** follows the system again. The choice is kept for next time. The paper in the preview stays white (or nearly) in every theme, so the preview still looks like the plot. ## Your first plot diff --git a/docs/guide/12-projects.md b/docs/guide/12-projects.md index 855406e..0d89e33 100644 --- a/docs/guide/12-projects.md +++ b/docs/guide/12-projects.md @@ -22,9 +22,10 @@ so you can try the same pattern on other artwork. ## Recent files -**File → Open Recent** lists the last 10 projects and SVGs you opened or saved (also in the Dock -icon's menu). **Clear Menu** empties it. A file that has been moved or deleted is taken off the -list when you pick it. You can also open SVGs and projects from Finder with **Open With**. +**File → Open Recent** lists the last 10 projects and SVGs you opened or saved (on macOS, also +in the Dock icon's menu). **Clear Menu** empties it. A file that has been moved or deleted is +taken off the list when you pick it. You can also open SVGs and projects from Finder or File +Explorer with **Open With**. ## Autosave and recovery diff --git a/docs/guide/13-shortcuts.md b/docs/guide/13-shortcuts.md index 346b94b..1dbc0ce 100644 --- a/docs/guide/13-shortcuts.md +++ b/docs/guide/13-shortcuts.md @@ -8,7 +8,7 @@ | ⌘E | Export what will be plotted as SVG | | ⇧⌘E | Export the toolpath as JSON | | ⌘Z | Undo | -| ⇧⌘Z | Redo | +| ⇧⌘Z | Redo (on Windows, Ctrl+Y too) | | F | Fit the page in the preview | | Space + drag | Move the view in the preview | | Space | Pause or resume a plot | diff --git a/docs/guide/14-troubleshooting.md b/docs/guide/14-troubleshooting.md index 2e01d62..7dfd4a6 100644 --- a/docs/guide/14-troubleshooting.md +++ b/docs/guide/14-troubleshooting.md @@ -33,10 +33,12 @@ ## Reporting a problem -Plotka keeps a log of what it did: the app and macOS versions, connecting to the plotter, each -plot and how it ended, and any errors. Choose **Help › Show Log File** to find it in Finder -(it's `~/Library/Logs/Plotka/plotka.log`). The log has no artwork in it. +Plotka keeps a log of what it did: the app and system versions, connecting to the plotter, +each plot and how it ended, and any errors. Choose **Help › Show Log File** to find it in +Finder or File Explorer. On macOS it's `~/Library/Logs/Plotka/plotka.log`; on Windows, +`%APPDATA%\Plotka\logs\plotka.log`. The log has no artwork in it. To report a bug, choose **Help › Report a Problem…**. It opens the bug report form on -[GitHub](https://github.com/blnkhz/plotka/issues) with the app and macOS versions filled in, and -shows the log in Finder. Drag the log into the form, and the SVG or project file if you can. +[GitHub](https://github.com/blnkhz/plotka/issues) with the app and system versions filled in, +and shows the log in Finder or File Explorer. Drag the log into the form, and the SVG or project +file if you can. diff --git a/docs/releasing.md b/docs/releasing.md index 0fb8bd9..ad9310d 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -1,8 +1,9 @@ # Releasing Releases are built on your Mac: `pnpm release:publish` checks the code, builds the universal -`.dmg`, signs and notarizes it with the Apple Developer account, and attaches it to a **draft** -GitHub release. Nothing is public until you publish the draft. +`.dmg`, signs and notarizes it with the Apple Developer account, builds the Windows installer +(unsigned), and attaches both to a **draft** GitHub release. Nothing is public until you publish +the draft. ## Steps @@ -26,10 +27,12 @@ GitHub release. Nothing is public until you publish the draft. it yet. 4. Open the draft it links to. Download the `.dmg` from it and open it: macOS should open - Plotka without any warning. Connect and plot something small. + Plotka without any warning. Connect and plot something small. If you can, do the same with + the Windows installer on a Windows PC. 5. Edit the notes if needed and click **Publish release**. -Running `pnpm release:publish` again for the same version replaces the `.dmg` on the draft. +Running `pnpm release:publish` again for the same version replaces the `.dmg` and the +installer on the draft. ## One-time setup for signing @@ -75,9 +78,27 @@ from the ones used for iOS apps or the App Store, and a notarytool profile in yo - The name macOS shows as the developer is the certificate's team name. - `pnpm release:publish --unsigned` makes an unsigned release without any Apple setup. People then see macOS's "unidentified developer" warning the first time they open the app. -- `pnpm build:mac` builds an unsigned `.dmg` into `apps/desktop/release/` for your own use. +- `pnpm build:mac` builds an unsigned `.dmg` into `apps/desktop/release/` for your own use, + and `pnpm build:win` the Windows installer. The Windows build works on a Mac without Wine. - The **Release** workflow on GitHub (**Actions › Release › Run workflow**, with a tag) builds - an unsigned `.dmg` on a GitHub-hosted Mac. It's a fallback for when you're away from your - Mac. It only runs by hand, so pushing a tag never replaces a signed `.dmg`. GitHub's macOS - runners are sometimes busy and the job can time out waiting for one; run it again later. + unsigned apps on GitHub-hosted runners: pick **windows**, **mac** or **both**. It's a + fallback for when you're away from your Mac. It only runs by hand, so pushing a tag never + replaces a signed `.dmg`; picking **mac** or **both** does, so only do that when there isn't + a signed one. GitHub's macOS runners are sometimes busy and the job can time out waiting for + one; run it again later. + +## Windows signing + +The Windows installer isn't signed, so Windows SmartScreen shows "Windows protected your PC" +the first time someone runs it (they click **More info › Run anyway**). The warning goes away +with a code signing certificate. Two ways, both supported by electron-builder: + +- **Azure Trusted Signing**: a monthly subscription, signs in the cloud, no hardware token. + It needs identity verification for the publisher name, which can take a few days. +- **An OV or EV certificate** from a certificate authority: paid yearly, and the key has to + live on a hardware token or a cloud HSM. + +Either way, signing happens when the installer is built, with the settings under `win:` in +`apps/desktop/electron-builder.yml`. + - While the repository is private, only people with access to it can download releases. diff --git a/eslint.config.js b/eslint.config.js index f16183e..e1c06c3 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -6,7 +6,16 @@ import prettier from 'eslint-config-prettier'; import globals from 'globals'; export default tseslint.config( - { ignores: ['**/node_modules/**', '**/out/**', '**/dist/**', '**/release/**', '**/coverage/**'] }, + { + ignores: [ + '**/node_modules/**', + '**/out/**', + '**/dist/**', + '**/release/**', + '**/coverage/**', + 'marketing/**', + ], + }, js.configs.recommended, ...tseslint.configs.recommended, { diff --git a/package.json b/package.json index d0e0cb9..83a5a54 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "dev": "pnpm --filter @plotka/desktop dev", "build": "pnpm --filter @plotka/desktop build", "build:mac": "pnpm --filter @plotka/desktop build:mac", + "build:win": "pnpm --filter @plotka/desktop build:win", "test": "vitest run", "test:watch": "vitest", "typecheck": "pnpm -r typecheck", diff --git a/scripts/publish.sh b/scripts/publish.sh index 1a39916..a5d049c 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,6 +1,7 @@ #!/bin/sh -# Builds the release for the version tag at HEAD on this Mac, signs and notarizes it, and -# attaches it to a DRAFT GitHub release. Nothing is public until you publish the draft. +# Builds the release for the version tag at HEAD on this Mac: the macOS app, signed and +# notarized, and the Windows installer (unsigned). Attaches both to a DRAFT GitHub release. +# Nothing is public until you publish the draft. # # Usage: pnpm release:publish (signed and notarized; needs .env.release, see below) # pnpm release:publish --unsigned (no Apple Developer account needed) @@ -64,8 +65,13 @@ else pnpm exec electron-builder --mac --universal --publish never \ "-c.mac.identity=$PLOTKA_SIGN_IDENTITY" fi + +step "Building the Windows installer" +pnpm exec electron-builder --win --x64 --publish never cd "$root" +exe="apps/desktop/release/Plotka-$version-x64-setup.exe" +[ -f "$exe" ] || fail "No $exe was built." dmg="apps/desktop/release/Plotka-$version-universal.dmg" app="apps/desktop/release/mac-universal/Plotka.app" [ -f "$dmg" ] || fail "No $dmg was built." @@ -88,12 +94,13 @@ step "Uploading to the draft release" git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1 || git push origin "$tag" if gh release view "$tag" >/dev/null 2>&1; then - gh release upload "$tag" "$dmg" --clobber + gh release upload "$tag" "$dmg" "$exe" --clobber else - gh release create "$tag" "$dmg" --draft --verify-tag --title "Plotka $tag" --generate-notes + gh release create "$tag" "$dmg" "$exe" --draft --verify-tag --title "Plotka $tag" --generate-notes fi step "Done" $unsigned && echo "This build is NOT signed: macOS will warn people the first time they open it." -echo "Review the draft, try the .dmg, then publish it:" +echo "The Windows installer isn't signed: Windows SmartScreen warns people the first time." +echo "Review the draft, try the .dmg and the installer, then publish it:" gh release view "$tag" --json url -q .url