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
10 changes: 7 additions & 3 deletions scripts/desktop-nsh-package-common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export function stampDevAppIdentity(appDir, rootDir = root, platform = process.p
const winIcon = join(rootDir, "src", "apps", "desktop", "icons", "openbitfun-app-icon.ico");
const destIcon = join(appDir, "icon.ico");
if (existsSync(winIcon)) {
mkdirSync(appDir, { recursive: true });
copyFileSync(winIcon, destIcon);
}
}
Expand Down Expand Up @@ -599,10 +600,10 @@ export function requireFiles(files) {
}

/**
* Records how a package directory was built next to it (not inside it):
* `<package dir>.package.json`.
* Writes the build receipt next to the package. Portable desktop updates also
* need the receipt inside the signed archive to identify the installation.
*/
export function writePackageInfo(packageDir, { profile, target, identity, version, executable }) {
export function writePackageInfo(packageDir, { profile, target, identity, version, executable, inBundle = false }) {
const info = {
schemaVersion: 1,
profile,
Expand All @@ -615,6 +616,9 @@ export function writePackageInfo(packageDir, { profile, target, identity, versio
assemblyDigest: identity.assemblyDigest,
};
writeFileSync(`${packageDir}.package.json`, `${JSON.stringify(info, null, 2)}\n`);
if (inBundle) {
writeFileSync(join(packageDir, "openbitfun-package.json"), `${JSON.stringify(info, null, 2)}\n`);
}
return info;
}

Expand Down
12 changes: 12 additions & 0 deletions scripts/desktop-nsh-package-common.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
runnerTargetDir,
shouldParallelizeCargo,
stageRunnerBinary,
stampDevAppIdentity,
writeWebBundleManifest,
} from './desktop-nsh-package-common.mjs';
import { desktopDevServerArgs } from './desktop-nsh-dev.mjs';
Expand Down Expand Up @@ -159,6 +160,17 @@ test('products without declared icons use the committed OpenBitFun icons', () =>
assert.equal(productIcon({ icons: { macos: '/brand/app.icns' } }, 'macos'), '/brand/app.icns');
});

test('Windows development identity can be stamped in a clean checkout', (t) => {
const work = mkdtempSync(join(tmpdir(), 'openbitfun-windows-dev-icon-'));
t.after(() => rmSync(work, { recursive: true, force: true }));
const icons = join(work, 'src', 'apps', 'desktop', 'icons');
mkdirSync(icons, { recursive: true });
writeFileSync(join(icons, 'openbitfun-app-icon.ico'), 'icon fixture');
const appDir = join(work, 'target', 'desktop-nsh', 'nsh');
stampDevAppIdentity(appDir, work, 'win32');
assert.equal(readFileSync(join(appDir, 'icon.ico'), 'utf8'), 'icon fixture');
});

test('the packaged web bundle carries its ui-bundle.json, over the untouched files and the product id', () => {
const site = mkdtempSync(join(tmpdir(), 'nsh-web-'));
writeFileSync(join(site, 'index.html'), '<!doctype html>');
Expand Down
8 changes: 2 additions & 6 deletions scripts/desktop-release-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
// macOS manual installer (`manual_installers["darwin-<arch>"]`).
// OpenBitFun-nsh_<version>_<x64|arm64>-windows.zip (+ .sig)
// OpenBitFun-nsh_<version>_<x86_64|aarch64>-linux.tar.gz (+ .sig)
// Windows and Linux manual downloads (`manual_installers["windows-*"]`,
// `manual_installers["linux-*"]`). There is no native installer or
// in-place updater for them yet, so `platforms` never carries a
// `windows-*` or `linux-*` key: an older Tauri package under a newer
// manifest version would make an installed Tauri app reinstall it in a
// loop, while a missing key makes it report that no package exists.
// Windows and Linux portable downloads. An updater manifest can also
// list these archives under native `*-nsh` platform keys.
import { basename } from 'node:path';

const NATIVE_UPDATER = /^OpenBitFun-nsh_(.+)_(aarch64|x86_64)\.app\.tar\.gz$/;
Expand Down
19 changes: 12 additions & 7 deletions scripts/generate-tauri-latest-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
// platforms["darwin-<arch>-nsh"] the native updater archive + signature
// platforms["darwin-<arch>"] the SAME archive + signature: the bridge an
// installed Tauri build updates through
// no windows-* / linux-* platform keys (no native in-place updater yet)
// Windows/Linux native entries are emitted when requested with
// --required-platforms and point to the signed portable archives.
// manual_installers["darwin-<arch>"] the DMG
// manual_installers["windows-x86_64"] the native Windows zip
// manual_installers["linux-<arch>"] the native Linux tarball
Expand Down Expand Up @@ -70,16 +71,10 @@ if (Object.keys(platforms).length === 0) {
fail('No signed native updater archives were found. Expected OpenBitFun-nsh_<version>_<arch>.app.tar.gz with its .sig.');
}

const missingPlatforms = requiredPlatforms.filter((platform) => !platforms[platform]);
if (missingPlatforms.length > 0) {
fail(`Missing required updater platforms: ${missingPlatforms.join(', ')}`);
}

const manifest = {
version,
notes: notesFile && existsSync(notesFile) ? readFileSync(notesFile, 'utf8').trim() : '',
pub_date: new Date().toISOString(),
platforms: Object.fromEntries(Object.entries(platforms).sort(([a], [b]) => a.localeCompare(b))),
};

// What a person downloads and installs by hand: the macOS DMG (the updater
Expand All @@ -105,6 +100,10 @@ if (installerAssetsDir) {
}
const url = releaseUrl(basename(file));
manualInstallers[asset.platform] = { url, signature_url: `${url}.sig` };
const nativeKey = `${asset.platform}-nsh`;
if (/^(windows|linux)-/.test(asset.platform) && requiredPlatforms.includes(nativeKey)) {
platforms[nativeKey] = { url, signature: readFileSync(signaturePath, 'utf8').trim() };
}
}
}

Expand All @@ -113,6 +112,12 @@ if (missingManual.length > 0) {
fail(`Missing required manual installers: ${missingManual.join(', ')}`);
}

const missingPlatforms = requiredPlatforms.filter((platform) => !platforms[platform]);
if (missingPlatforms.length > 0) {
fail(`Missing required updater platforms: ${missingPlatforms.join(', ')}`);
}
manifest.platforms = Object.fromEntries(Object.entries(platforms).sort(([a], [b]) => a.localeCompare(b)));

if (Object.keys(manualInstallers).length > 0) {
manifest.manual_installers = Object.fromEntries(
Object.entries(manualInstallers).sort(([a], [b]) => a.localeCompare(b)),
Expand Down
7 changes: 3 additions & 4 deletions scripts/package-desktop-nsh-linux.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
// Usage: node scripts/package-desktop-nsh-linux.mjs [--profile release|release-fast]
// [--target x86_64-unknown-linux-gnu] [--skip-build] [--product-config <product.jsonc>]
// Build dependencies: GTK 4, libadwaita and WebKitGTK 6 development packages
// (see the `desktop-nsh-linux` CI job). AppImage/deb packaging and in-place
// updates are a later step: the native updater refuses to install on Linux
// and points to the download page instead.
// (see the `desktop-nsh-linux` CI job). The native updater replaces this
// portable package in a writable installation directory.

import { chmodSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
Expand Down Expand Up @@ -103,7 +102,7 @@ profile ${identity.productId}-nsh /opt/${identity.productId}/openbitfun-nsh flag
`);

const arch = (options.target ?? process.arch).includes("aarch64") || process.arch === "arm64" ? "aarch64" : "x86_64";
writePackageInfo(app, { ...options, identity, version: pkg.version, executable: "openbitfun-nsh" });
writePackageInfo(app, { ...options, identity, version: pkg.version, inBundle: true, executable: "openbitfun-nsh" });
const archive = join(outDir, `${appName}-nsh_${pkg.version}_${arch}-linux.tar.gz`);
rmSync(archive, { force: true });
run("tar", ["-czf", archive, "-C", join(outDir, "linux"), appName]);
Expand Down
6 changes: 2 additions & 4 deletions scripts/package-desktop-nsh-windows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
// [--target x86_64-pc-windows-msvc] [--skip-build] [--no-installer]
// [--product-config <product.jsonc>]
// Requires Rust 1.97 or newer for the NSH crates and
// the WebView2 runtime on the machine that runs the app. In-place updates of this
// layout are a later step: the native updater refuses to install on Windows and
// points to the download page instead.
// the WebView2 runtime on the machine that runs the app.

import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
import { join } from "node:path";
Expand Down Expand Up @@ -92,7 +90,7 @@ copyResources(
);

const arch = (options.target ?? process.arch).includes("aarch64") || process.arch === "arm64" ? "arm64" : "x64";
writePackageInfo(app, { ...options, identity, version: pkg.version, executable });
writePackageInfo(app, { ...options, identity, version: pkg.version, inBundle: true, executable });
const archive = join(outDir, `${appName}-nsh_${pkg.version}_${arch}-windows.zip`);
rmSync(archive, { force: true });
if (process.platform === "win32") {
Expand Down
5 changes: 3 additions & 2 deletions scripts/sync-nsh-vendor-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { buildSync } from 'esbuild';
import { compileString } from 'sass';
import { createRequire } from 'node:module';
import { dirname, join, relative, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand All @@ -32,6 +30,7 @@ export const VENDOR_TARGETS = [

/** The pinned PDF.js dependency and its renderer are compiled as a classic script. */
export function preparePdfRendererAsset({ check = false } = {}) {
const { buildSync } = require('esbuild');
const distribution = dirname(require.resolve('pdfjs-dist/package.json'));
const directories = ['cmaps', 'standard_fonts', 'wasm'];
const licenses = [join(distribution, 'LICENSE')];
Expand Down Expand Up @@ -79,6 +78,8 @@ export function preparePdfRendererAsset({ check = false } = {}) {

/** Compiles the built-in chart renderer and its pinned dependencies for the isolated document. */
export function prepareFigureRendererAsset({ check = false } = {}) {
const { buildSync } = require('esbuild');
const { compileString } = require('sass');
const chartDir = dirname(require.resolve('echarts/package.json'));
const chartRequire = createRequire(join(chartDir, 'package.json'));
const reactDomDir = dirname(require.resolve('react-dom/package.json'));
Expand Down
24 changes: 23 additions & 1 deletion scripts/tauri-release-manifest.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test('native release manifest bridges installed Tauri builds to the native macOS
assert.equal(verified.status, 0, verified.stderr);
});

test('Windows and Linux never get updater keys, and a diverging bridge is rejected', (t) => {
test('Stable rejects Windows and Linux updater keys and a diverging bridge', (t) => {
const release = nativeRelease(t);
assert.equal(collect(release).status, 0);
assert.equal(generate(release).status, 0);
Expand All @@ -153,6 +153,28 @@ test('Windows and Linux never get updater keys, and a diverging bridge is reject
assert.notEqual(verify(release.out).status, 0);
});

test('requested Windows and Linux native keys use the signed portable downloads', (t) => {
const version = '2.0.0';
const release = nativeRelease(t, version);
assert.equal(collect(release, version).status, 0);
const portable = ['windows-x86_64', 'linux-x86_64', 'linux-aarch64'];
const keys = [...NATIVE_UPDATER_PLATFORMS.split(','), ...portable.map(platform => `${platform}-nsh`)].join(',');
const generated = generate(release, version, ['--required-platforms', keys]);
assert.equal(generated.status, 0, generated.stderr);
const manifest = JSON.parse(fs.readFileSync(release.out, 'utf8'));
for (const platform of portable) {
const update = manifest.platforms[`${platform}-nsh`];
assert.equal(update.url, manifest.manual_installers[platform].url);
assert.equal(update.signature, `signature of ${path.basename(update.url)}`);
assert.equal(manifest.platforms[platform], undefined);
}
const verified = run('scripts/verify-tauri-latest-json.mjs', [
'--manifest', release.out, '--version', version, '--required-platforms', keys,
'--forbidden-platform-prefixes', '',
]);
assert.equal(verified.status, 0, verified.stderr);
});

test('native updater collection rejects archives either updater would refuse', (t) => {
const release = nativeRelease(t);
const archive = path.join(release.assets, 'macos-x64', 'bundle', 'macos', 'OpenBitFun-nsh_1.2.3_x86_64.app.tar.gz');
Expand Down
14 changes: 11 additions & 3 deletions scripts/verify-tauri-latest-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const requiredManualPlatforms = parseListArg(args['required-manual-platforms'] |
// `darwin-<arch>` keys that must carry exactly the native `darwin-<arch>-nsh`
// archive and signature: the update bridge for installed Tauri builds.
const bridgePlatforms = parseListArg(args['bridge-platforms'] || '');
// Platform key prefixes the manifest must not carry (`windows-,linux-`: no native
// in-place updater yet, and an older Tauri package would reinstall in a loop).
// Releases can omit portable updates while the installer archives are present.
const forbiddenPlatformPrefixes = parseListArg(args['forbidden-platform-prefixes'] || '');
const checkUrls = ['1', 'true', 'yes'].includes(String(args['check-urls'] || '').toLowerCase());

Expand Down Expand Up @@ -56,9 +55,18 @@ for (const platform of Object.keys(manifest.platforms)) {
if (prefix) {
fail(`Platform ${platform} is not allowed in this manifest (forbidden prefix ${prefix})`);
}
if (/^(windows|linux)-/.test(platform) && !/^(windows|linux)-(aarch64|x86_64)-nsh$/.test(platform)) {
fail(`Portable updater ${platform} must use a native platform key`);
}
}

const manualInstallers = manifest.manual_installers || {};
for (const [platform, entry] of Object.entries(manifest.platforms)) {
if (/^(windows|linux)-/.test(platform) &&
manualInstallers[platform.slice(0, -4)]?.url !== entry.url) {
fail(`Portable updater ${platform} does not match its installer URL`);
}
}
const missingManual = requiredManualPlatforms.filter((platform) => !manualInstallers[platform]);
if (missingManual.length > 0) {
fail(`Missing required manual installers: ${missingManual.join(', ')}`);
Expand Down Expand Up @@ -114,7 +122,7 @@ function parseArgs(rawArgs) {
}
const key = arg.slice(2);
const value = rawArgs[i + 1];
if (!value || value.startsWith('--')) {
if (value === undefined || value.startsWith('--')) {
fail(`Missing value for --${key}`);
}
parsed[key] = value;
Expand Down
6 changes: 4 additions & 2 deletions src/apps/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,10 @@ If installation fails, the pending update remains available to retry. Use

On macOS the update replaces the application bundle in place (asking for an
administrator password when the bundle's folder is not writable) and restarts.
Windows and Linux builds report that in-place installation is not available yet;
download the new package from openbitfun.com.
On Windows and Linux, extract the full portable package into a user-writable
directory to enable in-place updates when the feed offers a native update for
the platform. The app stages and verifies the archive before offering a restart.
Linux requires a filesystem that supports atomic directory exchange.

Installed builds of the earlier Tauri-based desktop update into the native app on
macOS through their usual update flow: the release lists the native package under
Expand Down
2 changes: 1 addition & 1 deletion src/apps/desktop/src/api/update_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{io::Write, path::Path, sync::OnceLock};

pub(crate) const PROGRESS_EVENT: &str = "openbitfun-update-progress";
const RECORD_NAME: &str = "pending.json";
const RECEIPT_NAME: &str = "install-result.json";
pub(crate) const RECEIPT_NAME: &str = "install-result.json";

// Serialize downloads and installs at the host, including calls from multiple windows.
pub(crate) static UPDATE: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
Expand Down
1 change: 1 addition & 0 deletions src/apps/desktop/src/backend_protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod dispatch_generated;
mod events;
pub mod ffi;
mod native_commands;
pub(crate) use native_commands::start_automatic_updates;
pub mod ws;

use std::future::Future;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(super) use pet::{
hide_agent_companion_desktop_pet, resize_agent_companion_desktop_pet,
show_agent_companion_desktop_pet,
};
pub(crate) use update::start_automatic_updates;
pub(super) use update::{
check_for_updates, download_update, get_pending_update, install_pending_update,
};
Expand Down
Loading