mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 20:59:44 +08:00
* fix(desktop): restore Windows bounds on the display with the most overlap * fix(desktop): retry transient macOS DMG creation failures Retry hdiutil Resource busy failures with bounded backoff and remove partial images before retrying. Preserve immediate failure for permanent errors and cover retries, cleanup, and child-process diagnostics with regression tests. * fix(desktop): harden Windows window state persistence and recovery Flush pending window state on minimized or fullscreen exit, retain deferred display clamping across native transitions, and validate maximized state strictly. Preserve maximization when a saved display is unavailable and add real Electron lifecycle and cold-start regression tests with documented hardware verification limits. * test(desktop): initialize Electron before Windows tests --------- Co-authored-by: Codex <codex@openai.com>
64 lines
3.4 KiB
JavaScript
64 lines
3.4 KiB
JavaScript
import { packager } from '@electron/packager';
|
|
import { cp, mkdir, rm, symlink } from 'node:fs/promises';
|
|
import { execFileSync } from 'node:child_process';
|
|
import path from 'node:path';
|
|
import { setTimeout } from 'node:timers/promises';
|
|
import { appRoot } from './target.mjs';
|
|
import { PACKAGER, stageApp } from './stage.mjs';
|
|
|
|
export async function createDmg(source, output, { run = execFileSync, sleep = setTimeout } = {}) {
|
|
await rm(output, { force: true });
|
|
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
try {
|
|
run('/usr/bin/hdiutil', ['create', '-volname', 'Open DeepTutor', '-srcfolder', source, '-fs', 'APFS', '-format', 'ULFO', output], {
|
|
stdio: ['ignore', 'inherit', 'pipe'], env: { ...process.env, LC_ALL: 'C' },
|
|
});
|
|
return;
|
|
} catch (error) {
|
|
if (error.stderr) process.stderr.write(error.stderr);
|
|
await rm(output, { force: true });
|
|
const busy = error.status === 1 && !error.signal && /^hdiutil: create failed - Resource busy\s*$/m.test(error.stderr?.toString() ?? '');
|
|
if (!busy || attempt === 3) throw error;
|
|
const delay = attempt * 2000;
|
|
console.warn(`DMG creation hit a busy resource; retrying in ${delay / 1000}s (${attempt + 1}/3).`);
|
|
await sleep(delay);
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Shared by platforms/macos-arm64 and platforms/macos-x64: a signed .app inside a DMG. */
|
|
export async function packageMac(target) {
|
|
const { stage, version, pkg, out } = await stageApp(target);
|
|
// 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.join(appRoot, 'assets/entitlements.mac.plist');
|
|
const [built] = await packager({
|
|
...PACKAGER, dir: stage, out,
|
|
appVersion: version, buildVersion: version, electronVersion: pkg.devDependencies.electron,
|
|
platform: 'darwin', arch: target.arch, icon: path.join(appRoot, 'assets/icon.icns'),
|
|
extraResource: [target.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 }) } } : {}),
|
|
});
|
|
const bundle = path.join(built, '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' });
|
|
|
|
const dmgStage = path.join(target.local, 'dmg');
|
|
const dmg = path.join(out, `${target.artifact}-v${version}.dmg`);
|
|
await rm(dmgStage, { recursive: true, force: true });
|
|
await mkdir(dmgStage, { recursive: true });
|
|
await cp(bundle, path.join(dmgStage, 'Open DeepTutor.app'), { recursive: true, verbatimSymlinks: true });
|
|
await cp(path.join(built, 'LICENSES.chromium.html'), path.join(dmgStage, 'LICENSES.chromium.html'));
|
|
await symlink('/Applications', path.join(dmgStage, 'Applications'));
|
|
await createDmg(dmgStage, dmg);
|
|
await rm(dmgStage, { recursive: true, force: true });
|
|
return [bundle, dmg];
|
|
}
|