Files
privacy.sexy/scripts/check-desktop-runtime-errors/app/extractors/windows.js
undergroundwires 04b3133500 Add automated checks for desktop app runtime #233
- Add automation script for building, packaging, installing, executing
  and verifying Electron distrubtions across macOS, Ubuntu and Windows.
- Add GitHub workflow to run the script to test distributions using the
  script.
- Update README with new workflow status badge.
- Add application initialization log to desktop applications to be able
  to test against crashes before application initialization.
2023-08-21 01:35:19 +02:00

39 lines
1.3 KiB
JavaScript

import { mkdtemp, rmdir } from 'fs/promises';
import { join } from 'path';
import { tmpdir } from 'os';
import { findSingleFileByExtension, exists } from '../../utils/io.js';
import { log, die } from '../../utils/log.js';
import { runCommand } from '../../utils/run-command.js';
export async function prepareWindowsApp(desktopDistPath) {
const workdir = await mkdtemp(join(tmpdir(), 'win-nsis-installation-'));
if (await exists(workdir)) {
log(`Temporary directory ${workdir} already exists, cleaning up...`);
await rmdir(workdir, { recursive: true });
}
const { appExecutablePath } = await installNsis(workdir, desktopDistPath);
return {
appExecutablePath,
cleanup: async () => {
log(`Cleaning up working directory ${workdir}...`);
await rmdir(workdir, { recursive: true });
},
};
}
async function installNsis(installationPath, desktopDistPath) {
const { absolutePath: installerPath } = await findSingleFileByExtension('exe', desktopDistPath);
log(`Silently installing contents of ${installerPath} to ${installationPath}...`);
const { error } = await runCommand(`"${installerPath}" /S /D=${installationPath}`);
if (error) {
die(`Failed to install.\n${error}`);
}
const { absolutePath: appExecutablePath } = await findSingleFileByExtension('exe', installationPath);
return {
appExecutablePath,
};
}