A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.

9 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-browser.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-browser.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-browser.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 toolbar: Back and Forward are greyed out when there's nowhere to go cc08c7a 1 week, 2 days ago History
build-mac.mjs · 6.2 KB · 116 lines
1#!/usr/bin/env node
2/**
3 * The Mac app people download: dbbasic-browser.app, zipped.
4 *
5 * npm run build:mac → release/dbbasic-browser.app
6 * release/dbbasic-browser-<version>-macos-<arch>.zip (+ a .json beside it)
7 * npm run build:mac -- --allow-dirty a trial build from uncommitted changes, named so it can't pass for a release
8 *
9 * It is Electron's own Electron.app (the one npm installed and checked against Electron's published checksums) with
10 * our name, icon and version, and the standalone build (scripts/build-standalone.mjs) in Contents/Resources/app.
11 * It is for the processor of the Electron that npm installed, so build on an Apple-chip Mac for macos-arm64.
12 *
13 * A release is built from one commit, the one its tag points at: the working tree must be clean, and the build says
14 * so when HEAD has no version tag yet. The .json records the file's name, size, SHA-256, the commit and the tag.
15 *
16 * The app is signed ad hoc only (no Apple Developer ID), so macOS warns the first time it is opened.
17 * The zip is made with ditto, which keeps the bundle's symlinks and permissions; other zip tools can break the app.
18 */
19import { execFileSync } from "node:child_process";
20import { createHash } from "node:crypto";
21import { cpSync, createReadStream, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
22import { createRequire } from "node:module";
23import { dirname, join } from "node:path";
24import { fileURLToPath } from "node:url";
25
26if (process.platform !== "darwin") {
27 console.error("build-mac: run this on a Mac (it uses ditto, codesign and the Mac Electron.app)");
28 process.exit(2);
29}
30
31const root = join(dirname(fileURLToPath(import.meta.url)), "..");
32const NAME = "dbbasic-browser";
33const BUNDLE_ID = "com.askrobots.dbbasic-browser";
34const allowDirty = process.argv.includes("--allow-dirty");
35const run = (cmd, args, opts = {}) => (execFileSync(cmd, args, { cwd: root, encoding: "utf8", ...opts }) ?? "").trim();
36
37// ---- which commit, which version ----
38const commit = run("git", ["rev-parse", "HEAD"]);
39const dirty = run("git", ["status", "--porcelain"]) !== "";
40if (dirty && !allowDirty) {
41 console.error("build-mac: the working tree has uncommitted changes. A release is built from one commit: commit first,\n" +
42 "or pass --allow-dirty for a trial build (its name says so).");
43 process.exit(1);
44}
45const { displayVersion } = await import(join(root, "src", "version.ts"));
46const semver = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).version;
47const shown = displayVersion(semver);
48const tags = run("git", ["tag", "--points-at", "HEAD"]).split("\n").filter(Boolean);
49const tagged = tags.includes(shown);
50
51// ---- the Electron.app to start from ----
52const electronBin = createRequire(import.meta.url)("electron");
53const srcApp = join(dirname(electronBin), "..", "..");
54const electronVersion = readFileSync(join(srcApp, "..", "version"), "utf8").trim();
55const archs = run("lipo", ["-archs", electronBin]).split(/\s+/);
56const arch = archs.length === 1 && archs[0] === "arm64" ? "arm64" : archs.length === 1 && archs[0] === "x86_64" ? "x64" : null;
57if (!arch) {
58 console.error(`build-mac: expected an arm64 or x86_64 Electron, found: ${archs.join(" ")}`);
59 process.exit(1);
60}
61
62// ---- build the app's files ----
63run("npm", ["run", "build:standalone"], { stdio: "inherit" });
64
65const out = join(root, "release");
66const appDir = join(out, `${NAME}.app`);
67rmSync(out, { recursive: true, force: true });
68mkdirSync(out, { recursive: true });
69try {
70 run("cp", ["-cR", srcApp, appDir]); // an APFS clone where possible: fast, no extra disk
71} catch {
72 cpSync(srcApp, appDir, { recursive: true, verbatimSymlinks: true });
73}
74const res = join(appDir, "Contents", "Resources");
75rmSync(join(res, "default_app.asar"), { force: true }); // Electron's sample app; ours goes in Resources/app
76cpSync(join(root, "standalone"), join(res, "app"), { recursive: true });
77cpSync(join(root, "assets", "icon.icns"), join(res, "electron.icns")); // CFBundleIconFile names this file
78
79const plist = join(appDir, "Contents", "Info.plist");
80const pb = (cmd) => execFileSync("/usr/libexec/PlistBuddy", ["-c", cmd, plist], { stdio: ["ignore", "ignore", "pipe"] });
81const setKey = (key, value) => {
82 try { pb(`Delete :${key}`); } catch { /* not there yet */ }
83 pb(`Add :${key} string ${value}`);
84};
85setKey("CFBundleName", NAME);
86setKey("CFBundleDisplayName", NAME);
87setKey("CFBundleIdentifier", BUNDLE_ID);
88setKey("CFBundleShortVersionString", semver.replace(/-.*/, "")); // macOS wants plain numbers here
89setKey("CFBundleVersion", semver.replace(/-.*/, ""));
90setKey("LSApplicationCategoryType", "public.app-category.productivity");
91setKey("DBBasicCommit", commit);
92try { pb("Delete :ElectronAsarIntegrity"); } catch { /* the sample app's hash; there is no asar now */ }
93
94// Changing the bundle breaks Electron's signature, and an Apple-chip Mac won't run unsigned code: sign it ad hoc.
95run("codesign", ["--force", "--deep", "--sign", "-", appDir], { stdio: "ignore" });
96run("codesign", ["--verify", "--deep", "--strict", appDir]);
97
98// ---- the zip, and what it is ----
99const suffix = dirty ? `-dev-${commit.slice(0, 7)}` : "";
100const zipName = `${NAME}-${shown}${suffix}-macos-${arch}.zip`;
101const zip = join(out, zipName);
102run("ditto", ["-c", "-k", "--sequesterRsrc", "--keepParent", appDir, zip]);
103const sha256 = await new Promise((resolve, reject) => {
104 const h = createHash("sha256");
105 createReadStream(zip).on("data", (d) => h.update(d)).on("end", () => resolve(h.digest("hex"))).on("error", reject);
106});
107const size = statSync(zip).size;
108const info = { file: zipName, platform: `macos-${arch}`, size, sha256, commit, tag: tagged ? shown : null, version: shown, electron: electronVersion, dirty };
109writeFileSync(join(out, `${zipName}.json`), JSON.stringify(info, null, 2) + "\n");
110
111console.log(`\n${zip}`);
112console.log(` ${(size / 1024 / 1024).toFixed(1)} MB (${size} bytes)`);
113console.log(` sha256 ${sha256}`);
114console.log(` commit ${commit}${dirty ? " plus uncommitted changes (trial build, not for upload)" : ""}`);
115if (!dirty && !tagged) console.log(` HEAD has no ${shown} tag yet: tag this commit before uploading the zip to its release.`);
116if (existsSync(appDir)) console.log(` app: ${appDir}`);