Files
DeepTutor/apps/desktop/scripts/package.mjs
Bingxi Zhao (Frank) a4fa63b6e2 feat(desktop): add Open DeepTutor for macOS under apps/desktop
Move the Electron macOS app into the main repository and ship it with every
DeepTutor release.

- apps/desktop: Electron shell that installs a signed bundled runtime and
  hosts the web UI; versioned with the bundled core.
- White app icon with the black DeepTutor mark, generated by
  scripts/make-icon.swift; redesigned start screen and title bar.
- Shell copy in en/zh/de/fr/pl/uk, starting in English and following the
  interface language and theme from DeepTutor Settings, including live changes.
- Web UI labels itself "Open DeepTutor MacOS v<version>" inside the app
  (user-agent marker) and "Open DeepTutor Web v<version>" in a browser.
- Sealing refuses a missing or mismatched signing key instead of silently
  generating a new one.
- desktop-release.yml builds, smoke-tests and attaches the DMG to each
  GitHub Release; Developer ID signing and notarization run when secrets exist.
- tests.yml runs the shell checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 19:20:15 +08:00

43 lines
2.3 KiB
JavaScript

import { packager } from '@electron/packager';
import { cp, mkdir, rm, readFile, writeFile } from 'node:fs/promises';
import { execFileSync } from 'node:child_process';
import path from 'node:path';
// The app is versioned with the DeepTutor core it ships: Open DeepTutor MacOS v<core>.
const seed = JSON.parse(await readFile('.local/seed/runtime.json', 'utf8'));
const version = seed.coreVersion;
const stage = path.resolve('.local/app');
await rm(stage, { recursive: true, force: true });
await mkdir(stage, { recursive: true });
for (const name of ['src', 'assets', 'README.md']) {
await cp(name, path.join(stage, name), { recursive: true });
}
const pkg = JSON.parse(await readFile('package.json', 'utf8'));
await writeFile(path.join(stage, 'package.json'), JSON.stringify({ ...pkg, version }, null, 2));
await cp('../../LICENSE', path.join(stage, 'LICENSE'));
// With APPLE_SIGNING_IDENTITY ("Developer ID Application: …") the app gets a
// hardened-runtime Developer ID signature; otherwise it is signed ad hoc.
const identity = process.env.APPLE_SIGNING_IDENTITY;
const entitlements = path.resolve('assets/entitlements.mac.plist');
const outputs = await packager({
dir: stage, name: 'Open DeepTutor', appBundleId: 'org.deeptutor.open-desktop',
appVersion: version, buildVersion: version, electronVersion: pkg.devDependencies.electron,
platform: 'darwin', arch: process.arch, out: 'out', overwrite: true,
asar: false, prune: false, icon: path.resolve('assets/icon.icns'),
extraResource: [path.resolve('.local/seed')],
appCategoryType: 'public.app-category.education',
extendInfo: {
NSMicrophoneUsageDescription: 'Open DeepTutor uses the microphone when you speak to your tutor.',
NSCameraUsageDescription: 'Open DeepTutor uses the camera when you capture learning material.',
NSLocalNetworkUsageDescription: 'Open DeepTutor runs its learning services on this Mac.',
},
...(identity ? { osxSign: { identity, optionsForFile: () => ({ hardenedRuntime: true, entitlements }) } } : {}),
});
for (const output of outputs) {
const bundle = path.join(output, 'Open DeepTutor.app');
if (!identity) execFileSync('/usr/bin/codesign', ['--force', '--deep', '--sign', '-', bundle], { stdio: 'inherit' });
execFileSync('/usr/bin/codesign', ['--verify', '--deep', '--strict', bundle], { stdio: 'inherit' });
console.log(bundle);
}