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
93 changes: 93 additions & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Mac build

# Builds the universal (Intel + Apple Silicon) Mac apps, checks that they start, and adds them to existing releases
# together with their line in SHA256SUMS.txt. A Mac build has to be made on a Mac: the Electron framework inside an
# .app needs symlinks and permissions that a zip made on Windows loses.
on:
workflow_dispatch:
inputs:
studio_tag:
description: Motion Studio release to add the Mac build to (e.g. v1.3.0), empty to skip
required: false
launcher_tag:
description: Motion Launcher release to add the Mac build to (e.g. launcher-v1.2.0), empty to skip
required: false

permissions:
contents: write

jobs:
mac:
runs-on: macos-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci

# .icns icons from the 256 px PNGs.
- name: Icons
run: |
icns() {
set=$(mktemp -d)/icon.iconset; mkdir -p "$set"
for s in 16 32 64 128 256; do sips -z $s $s "$1" --out "$set/icon_${s}x${s}.png" >/dev/null; done
for s in 16 32 64 128; do cp "$set/icon_$((s*2))x$((s*2)).png" "$set/icon_${s}x${s}@2x.png"; done
iconutil -c icns "$set" -o "$2"
}
icns resources/icon.png resources/icon.icns
icns launcher/icons/launcher.png launcher/icons/launcher.icns

# Not notarized: the apps are signed ad hoc (Apple Silicon refuses to run unsigned code), so macOS asks once
# whether to open an app downloaded in a browser.
- name: Motion Studio
if: inputs.studio_tag != ''
run: |
npm run pack:mac
app="dist/Motion Studio-darwin-universal/Motion Studio.app"
codesign --force --deep --sign - "$app"
home=$(mktemp -d)
HOME="$home" node scripts/smoke-project.mjs "$home/project"
HOME="$home" "$app/Contents/MacOS/Motion Studio" --smoke-test studio.png
version=$(node -p "require('./package.json').version")
test "v$version" = "${{ inputs.studio_tag }}" || { echo "package.json is $version, the tag is ${{ inputs.studio_tag }}"; exit 1; }
zip="Motion-Studio-$version-mac-universal.zip"
ditto -c -k --keepParent "$app" "$zip"
echo "STUDIO_ZIP=$zip" >> "$GITHUB_ENV"

- name: Motion Launcher
if: inputs.launcher_tag != ''
run: |
npm run pack:launcher:mac
app="dist/Motion Launcher-darwin-universal/Motion Launcher.app"
codesign --force --deep --sign - "$app"
MOTION_LAUNCHER_HOME=$(mktemp -d) "$app/Contents/MacOS/Motion Launcher" --smoke-test launcher.png
version=$(node -p "require('./launcher/package.json').version")
test "launcher-v$version" = "${{ inputs.launcher_tag }}" || { echo "launcher is $version, the tag is ${{ inputs.launcher_tag }}"; exit 1; }
zip="Motion-Launcher-$version-mac-universal.zip"
ditto -c -k --keepParent "$app" "$zip"
echo "LAUNCHER_ZIP=$zip" >> "$GITHUB_ENV"

- uses: actions/upload-artifact@v4
with:
name: screenshots
path: '*.png'

# Adds the zip and its checksum line (replacing an older line for the same file) to the release.
- name: Publish
run: |
publish() {
tag=$1; zip=$2; [ -n "$tag" ] && [ -n "$zip" ] || return 0
rm -f SHA256SUMS.txt
gh release download "$tag" -p SHA256SUMS.txt || touch SHA256SUMS.txt
grep -v " \*\?$zip\$" SHA256SUMS.txt > sums.tmp || true
shasum -a 256 -b "$zip" >> sums.tmp
mv sums.tmp SHA256SUMS.txt
cat SHA256SUMS.txt
gh release upload "$tag" "$zip" SHA256SUMS.txt --clobber
}
publish "${{ inputs.studio_tag }}" "$STUDIO_ZIP"
publish "${{ inputs.launcher_tag }}" "$LAUNCHER_ZIP"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
*.pfx
*.p12
*.cer
*.icns
3 changes: 2 additions & 1 deletion launcher/apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"repo": "tinygusie2/motion-studio",
"asset": "^Motion-Studio-.*-win-x64\\.zip$",
"checksums": "SHA256SUMS.txt",
"exe": "Motion Studio.exe"
"exe": "Motion Studio.exe",
"mac": { "asset": "^Motion-Studio-.*-mac-universal\\.zip$", "exe": "Motion Studio.app" }
},
{
"id": "visual",
Expand Down
7 changes: 5 additions & 2 deletions launcher/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// starts them. Extra editors can be added without a new launcher build in %APPDATA%\Motion Launcher\apps.json.
import { app, BrowserWindow, Menu, dialog, ipcMain, shell } from 'electron';
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Store, cleanup, compareVersions, findExisting, install, installedExe, latestRelease, launch } from './updater.mjs';
import { Store, cleanup, compareVersions, findExisting, forPlatform, install, installedExe, latestRelease, launch } from './updater.mjs';

const here = fileURLToPath(new URL('.', import.meta.url));
const smoke = process.argv.includes('--smoke-test');
Expand All @@ -27,7 +28,7 @@ function loadApps() {
if (at < 0) at = list.findIndex(a => a.placeholder && !a.comingSoon);
if (at >= 0) list[at] = extra; else list.push(extra);
}
return list.map(a => ({ ...a, name: loc(a.name), description: loc(a.description) }));
return list.map(a => forPlatform(a)).filter(Boolean).map(a => ({ ...a, name: loc(a.name), description: loc(a.description) }));
}
// Start menu shortcuts, so Windows Search finds the launcher and every app it installed. An app's shortcut points at its
// installed version, so it is written again after each update.
Expand All @@ -42,7 +43,9 @@ function appShortcut(a) {
if (info) shortcut(a.name, installedExe(root, a, info), a.description);
}
// The exes behind the Start menu and desktop shortcuts, for finding editors that were installed without the launcher.
// On a Mac: the .app bundles in /Applications and ~/Applications.
function shortcutTargets() {
if (process.platform === 'darwin') return apps.flatMap(a => [join('/Applications', a.exe), join(homedir(), 'Applications', a.exe)]);
if (process.platform !== 'win32') return [];
const dirs = [startMenu(), join(process.env.ProgramData || 'C:\\ProgramData', 'Microsoft', 'Windows', 'Start Menu', 'Programs'), app.getPath('desktop')];
const out = [];
Expand Down
2 changes: 1 addition & 1 deletion launcher/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "motion-launcher",
"productName": "Motion Launcher",
"version": "1.1.1",
"version": "1.2.0",
"description": "Installs, updates and starts Motion Studio (and other editors) from their GitHub releases.",
"license": "MIT",
"private": true,
Expand Down
20 changes: 16 additions & 4 deletions launcher/updater.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ export function parseChecksums(text) {
return sums;
}

// Windows' own tar.exe (bsdtar) unpacks zips; Git Bash's GNU tar that may come first on PATH does not.
// An app as this platform sees it: on a Mac its `mac` block ({ asset, exe: 'Name.app' }) replaces the Windows asset and
// exe. An app without one has no Mac build and is left out there (null).
export function forPlatform(app, platform = process.platform) {
if (platform !== 'darwin') return app;
return app.mac ? { ...app, ...app.mac } : null;
}

// Windows' own tar.exe (bsdtar) unpacks zips; Git Bash's GNU tar that may come first on PATH does not. On a Mac, ditto
// keeps the symlinks and permissions an .app bundle needs.
function extract(zip, dir) {
const [cmd, args] = process.platform === 'win32'
? [join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'tar.exe'), ['-xf', zip, '-C', dir]]
: ['unzip', ['-q', zip, '-d', dir]];
: process.platform === 'darwin' ? ['ditto', ['-x', '-k', zip, dir]] : ['unzip', ['-q', zip, '-d', dir]];
return new Promise((resolve, reject) => execFile(cmd, args, { windowsHide: true }, err => err ? reject(err) : resolve()));
}

Expand All @@ -109,7 +117,9 @@ export function findExisting(app, exes) {
for (const exe of exes) {
if (!exe || basename(exe).toLowerCase() !== app.exe.toLowerCase() || !existsSync(exe)) continue;
let version = '0.0.0';
try { version = JSON.parse(readFileSync(join(dirname(exe), 'resources', 'app', 'package.json'), 'utf8')).version || version; } catch {}
// An .app bundle keeps the app in Contents/Resources, a Windows build next to the exe in resources.
const pkg = exe.toLowerCase().endsWith('.app') ? join(exe, 'Contents', 'Resources', 'app', 'package.json') : join(dirname(exe), 'resources', 'app', 'package.json');
try { version = JSON.parse(readFileSync(pkg, 'utf8')).version || version; } catch {}
return { version, path: dirname(exe), found: true, installedAt: statSync(exe).mtime.toISOString(), verified: false, previous: null };
}
return null;
Expand Down Expand Up @@ -205,7 +215,9 @@ export function launch(app, { root, store }) {
if (!info) throw new Error(`${app.name} is not installed`);
const exe = installedExe(root, app, info);
if (!existsSync(exe)) throw new Error(`${exe} is missing; install ${app.name} again`);
const child = spawn(exe, app.args || [], { cwd: dirname(exe), detached: true, stdio: 'ignore' });
// An .app bundle is a folder: macOS starts it through open (-n: a new copy, also when one runs from elsewhere).
const [cmd, args] = exe.toLowerCase().endsWith('.app') ? ['open', ['-n', exe, ...(app.args?.length ? ['--args', ...app.args] : [])]] : [exe, app.args || []];
const child = spawn(cmd, args, { cwd: dirname(exe), detached: true, stdio: 'ignore' });
child.unref();
return child.pid;
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
"serve": "node src/server.mjs",
"build": "node src/cli.mjs build",
"pack": "node scripts/pack.mjs",
"pack:mac": "node scripts/pack.mjs --mac",
"sign": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/sign.ps1",
"sign:cert": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/make-selfsigned-cert.ps1",
"dist": "npm run pack && npm run sign",
"launcher": "electron launcher",
"icon:launcher": "electron scripts/make-icon.cjs --launcher",
"pack:launcher": "node scripts/pack-launcher.mjs",
"pack:launcher:mac": "node scripts/pack-launcher.mjs --mac",
"sign:launcher": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/sign.ps1 -Exe \"dist/Motion Launcher-win32-x64/Motion Launcher.exe\" -Description \"Motion Launcher\"",
"dist:launcher": "npm run pack:launcher && npm run sign:launcher",
"test": "node --test \"test/*.test.mjs\"",
Expand Down
9 changes: 6 additions & 3 deletions scripts/pack-launcher.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// Packages the launcher into dist/Motion Launcher-win32-x64 (npm run pack:launcher). It is its own small app in
// launcher/, built with the same Electron as Motion Studio.
import { packager } from '@electron/packager';

// --mac: a universal (Intel + Apple Silicon) .app; it has to be built on a Mac (see .github/workflows/mac.yml).
const mac = process.argv.includes('--mac');
import { readFileSync } from 'node:fs';

const electronVersion = JSON.parse(readFileSync('node_modules/electron/package.json', 'utf8')).version;
const [out] = await packager({
dir: 'launcher',
name: 'Motion Launcher',
platform: 'win32',
arch: 'x64',
platform: mac ? 'darwin' : 'win32',
arch: mac ? 'universal' : 'x64',
out: 'dist',
overwrite: true,
electronVersion,
icon: 'launcher/icons/launcher.ico',
icon: mac ? 'launcher/icons/launcher.icns' : 'launcher/icons/launcher.ico',
asar: false,
prune: false
});
Expand Down
9 changes: 6 additions & 3 deletions scripts/pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
// `^` of `--ignore=^/dist`, and an unanchored /dist also threw away node_modules/gsap/dist.
import { packager } from '@electron/packager';

// --mac: a universal (Intel + Apple Silicon) .app; it has to be built on a Mac (see .github/workflows/mac.yml).
const mac = process.argv.includes('--mac');

const [out] = await packager({
dir: '.',
name: 'Motion Studio',
platform: 'win32',
arch: 'x64',
platform: mac ? 'darwin' : 'win32',
arch: mac ? 'universal' : 'x64',
out: 'dist',
overwrite: true,
icon: 'resources/icon.ico',
icon: mac ? 'resources/icon.icns' : 'resources/icon.ico',
asar: false,
// Paths are relative to the project, starting with /.
ignore: [/^\/dist(\/|$)/, /^\/launcher(\/|$)/, /^\/scripts(\/|$)/, /^\/docs(\/|$)/, /^\/test(\/|$)/, /^\/\.git/, /^\/\.claude(\/|$)/]
Expand Down
14 changes: 14 additions & 0 deletions scripts/smoke-project.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// A project with one video, for the packaged app's --smoke-test on a fresh machine (CI): node scripts/smoke-project.mjs <dir>
// Run it with HOME pointing at a scratch folder: the app's settings (~/.motion-studio) then open this project.
import { createWorkspace, Workspace, loadSettings, saveSettings } from '../src/workspace.mjs';

const dir = process.argv[2];
if (!dir) throw new Error('usage: node scripts/smoke-project.mjs <dir>');
createWorkspace(dir, 'Smoke test');
new Workspace(dir).writeSpec('smoke', {
brand: 'brand', layout: 'text', dur: 4, end: 3,
heads: [{ t: 0.3, text: 'Smoke *test*' }],
clips: [], chips: [], zooms: [], taps: [], subs: [], vo: { lines: [] }
});
saveSettings({ ...loadSettings(), workspace: dir, recents: [dir] });
console.log(`Smoke project in ${dir}`);
23 changes: 22 additions & 1 deletion test/launcher.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { after, before, test } from 'node:test';
import { crc32 } from 'node:zlib';
import { Store, cleanup, compareVersions, findExisting, install, installedExe, latestRelease, parseChecksums } from '../launcher/updater.mjs';
import { Store, cleanup, compareVersions, findExisting, forPlatform, install, installedExe, latestRelease, parseChecksums } from '../launcher/updater.mjs';

// A zip with stored (uncompressed) entries: { 'path/in/zip': 'content' }.
function zip(files) {
Expand Down Expand Up @@ -142,6 +142,27 @@ test('cleanup never removes a folder with projects in it', () => {
assert.deepEqual(new Set(readdirSync(demo)), new Set(['1.0.0', '2.0.0', '3.0.0']));
});

test('forPlatform: a Mac gets the mac asset and .app, an app without a Mac build is left out there', () => {
const ms = { id: 'ms', asset: '-win-x64', exe: 'MS.exe', mac: { asset: '-mac-universal', exe: 'MS.app' } };
assert.equal(forPlatform(ms, 'win32'), ms);
assert.deepEqual([forPlatform(ms, 'darwin').asset, forPlatform(ms, 'darwin').exe], ['-mac-universal', 'MS.app']);
assert.equal(forPlatform({ id: 'v', exe: 'V.exe' }, 'darwin'), null);
const real = JSON.parse(readFileSync(new URL('../launcher/apps.json', import.meta.url), 'utf8'));
assert.ok(new RegExp(forPlatform(real[0], 'darwin').asset).test('Motion-Studio-1.3.0-mac-universal.zip'));
});

test('findExisting reads the version of an .app bundle', () => {
const dir = mkdtempSync(join(tmpdir(), 'ml-mac-'));
try {
const bundle = join(dir, 'MS.app');
mkdirSync(join(bundle, 'Contents', 'Resources', 'app'), { recursive: true });
writeFileSync(join(bundle, 'Contents', 'Resources', 'app', 'package.json'), JSON.stringify({ version: '1.3.0' }));
const found = findExisting({ id: 'ms', exe: 'MS.app' }, [bundle]);
assert.equal(found.version, '1.3.0');
assert.equal(found.path, dir);
} finally { rmSync(dir, { recursive: true, force: true }); }
});

test('findExisting adopts a copy installed without the launcher, with its version', () => {
const dir = mkdtempSync(join(tmpdir(), 'ml-found-'));
try {
Expand Down
Loading