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
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
72 changes: 67 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
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 }}
cancel-in-progress: false

jobs:
mac:
if: inputs.platforms != 'windows'
runs-on: macos-latest
env:
TAG: ${{ github.event.inputs.tag || github.ref_name }}
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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`.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
```
Expand Down
Binary file added apps/desktop/build/icon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions apps/desktop/e2e/layers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/e2e/plotting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
37 changes: 33 additions & 4 deletions apps/desktop/e2e/projects.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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<string, string>) {
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();
Expand All @@ -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');
Expand All @@ -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());
Expand Down
29 changes: 24 additions & 5 deletions apps/desktop/electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,14 +16,35 @@ 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]
# Everyday builds (`pnpm build:mac`, CI) are unsigned. Releases are signed and notarized by
# `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
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
33 changes: 33 additions & 0 deletions apps/desktop/scripts/make-ico.cjs
Original file line number Diff line number Diff line change
@@ -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)]));
Loading
Loading