2025-01-31 13:05:04 +00:00
|
|
|
import * as os from "node:os";
|
|
|
|
import * as fs from "node:fs";
|
2025-02-03 08:30:37 +00:00
|
|
|
import * as path from "node:path";
|
|
|
|
import * as plist from "plist";
|
|
|
|
import { AfterPackContext, Arch, Configuration as BaseConfiguration, Platform } from "electron-builder";
|
|
|
|
import { computeData } from "app-builder-lib/out/asar/integrity";
|
|
|
|
import { readFile, writeFile } from "node:fs/promises";
|
2024-01-03 16:29:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This script has different outputs depending on your os platform.
|
|
|
|
*
|
|
|
|
* On Windows:
|
|
|
|
* Prefixes the nightly version with `0.0.1-nightly.` as it breaks if it is not semver
|
|
|
|
* Passes $ED_SIGNTOOL_THUMBPRINT and $ED_SIGNTOOL_SUBJECT_NAME to
|
2025-01-31 13:05:04 +00:00
|
|
|
* build.win.signtoolOptions.signingHashAlgorithms and build.win.signtoolOptions.certificateSubjectName respectively if specified.
|
2024-01-03 16:29:48 +00:00
|
|
|
*
|
|
|
|
* On Linux:
|
|
|
|
* Replaces spaces in the product name with dashes as spaces in paths can cause issues
|
|
|
|
* Removes libsqlcipher0 recommended dependency if env SQLCIPHER_BUNDLED is asserted.
|
|
|
|
* Passes $ED_DEBIAN_CHANGELOG to build.deb.fpm if specified
|
|
|
|
*/
|
|
|
|
|
|
|
|
const NIGHTLY_APP_ID = "im.riot.nightly";
|
|
|
|
const NIGHTLY_DEB_NAME = "element-nightly";
|
|
|
|
|
2024-04-08 11:38:54 +01:00
|
|
|
interface Pkg {
|
|
|
|
name: string;
|
|
|
|
productName: string;
|
|
|
|
description: string;
|
|
|
|
version: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
type Writable<T> = NonNullable<
|
|
|
|
T extends Function ? T : T extends object ? { -readonly [K in keyof T]: Writable<T[K]> } : T
|
|
|
|
>;
|
|
|
|
|
|
|
|
const pkg: Pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
|
|
|
|
|
|
|
interface Configuration extends BaseConfiguration {
|
|
|
|
extraMetadata: Partial<Pick<Pkg, "version">> & Omit<Pkg, "version">;
|
2024-05-13 11:25:13 +01:00
|
|
|
linux: BaseConfiguration["linux"];
|
2024-04-08 11:38:54 +01:00
|
|
|
win: BaseConfiguration["win"];
|
|
|
|
mac: BaseConfiguration["mac"];
|
|
|
|
deb: {
|
|
|
|
fpm: string[];
|
|
|
|
} & BaseConfiguration["deb"];
|
|
|
|
}
|
2024-01-03 16:29:48 +00:00
|
|
|
|
2025-02-03 08:30:37 +00:00
|
|
|
async function injectAsarIntegrity(context: AfterPackContext) {
|
|
|
|
const packager = context.packager;
|
|
|
|
|
|
|
|
// We only need to re-generate asar on universal Mac builds, due to https://github.com/electron/universal/issues/116
|
|
|
|
if (packager.platform !== Platform.MAC || context.arch !== Arch.universal) return;
|
|
|
|
|
|
|
|
const resourcesPath = packager.getResourcesDir(context.appOutDir);
|
|
|
|
const asarIntegrity = await computeData({
|
|
|
|
resourcesPath,
|
|
|
|
resourcesRelativePath: "Resources",
|
|
|
|
resourcesDestinationPath: resourcesPath,
|
|
|
|
extraResourceMatchers: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
const plistPath = path.join(resourcesPath, "..", "Info.plist");
|
|
|
|
const data = plist.parse(await readFile(plistPath, "utf8")) as unknown as Writable<plist.PlistObject>;
|
|
|
|
data["ElectronAsarIntegrity"] = asarIntegrity as unknown as Writable<plist.PlistValue>;
|
|
|
|
await writeFile(plistPath, plist.build(data));
|
|
|
|
}
|
|
|
|
|
2024-01-03 16:29:48 +00:00
|
|
|
/**
|
|
|
|
* @type {import('electron-builder').Configuration}
|
|
|
|
* @see https://www.electron.build/configuration/configuration
|
|
|
|
*/
|
2025-01-31 13:05:04 +00:00
|
|
|
const config: Omit<Writable<Configuration>, "electronFuses"> & {
|
|
|
|
// Make all fuses required to ensure they are all explicitly specified
|
|
|
|
electronFuses: Required<Configuration["electronFuses"]>;
|
|
|
|
} = {
|
2024-01-03 16:29:48 +00:00
|
|
|
appId: "im.riot.app",
|
|
|
|
asarUnpack: "**/*.node",
|
2025-01-31 13:05:04 +00:00
|
|
|
electronFuses: {
|
|
|
|
enableCookieEncryption: true,
|
|
|
|
onlyLoadAppFromAsar: true,
|
|
|
|
grantFileProtocolExtraPrivileges: false,
|
|
|
|
|
|
|
|
runAsNode: false,
|
|
|
|
enableNodeOptionsEnvironmentVariable: false,
|
|
|
|
enableNodeCliInspectArguments: false,
|
|
|
|
// We need to reset the signature if we are not signing on darwin otherwise it won't launch
|
|
|
|
resetAdHocDarwinSignature: !process.env.APPLE_TEAM_ID,
|
|
|
|
|
|
|
|
loadBrowserProcessSpecificV8Snapshot: false,
|
2025-02-03 08:30:37 +00:00
|
|
|
enableEmbeddedAsarIntegrityValidation: true,
|
|
|
|
},
|
|
|
|
afterPack: async (context: AfterPackContext) => {
|
|
|
|
await injectAsarIntegrity(context);
|
2024-01-09 15:56:04 +00:00
|
|
|
},
|
2024-01-03 16:29:48 +00:00
|
|
|
files: [
|
|
|
|
"package.json",
|
|
|
|
{
|
|
|
|
from: ".hak/hakModules",
|
|
|
|
to: "node_modules",
|
|
|
|
},
|
|
|
|
"lib/**",
|
|
|
|
],
|
|
|
|
extraResources: [
|
|
|
|
{
|
|
|
|
from: "res/img",
|
|
|
|
to: "img",
|
|
|
|
},
|
|
|
|
"webapp.asar",
|
|
|
|
],
|
|
|
|
extraMetadata: {
|
2024-01-11 11:35:21 +00:00
|
|
|
name: pkg.name,
|
2024-01-03 16:29:48 +00:00
|
|
|
productName: pkg.productName,
|
|
|
|
description: pkg.description,
|
|
|
|
},
|
|
|
|
linux: {
|
|
|
|
target: ["tar.gz", "deb"],
|
|
|
|
category: "Network;InstantMessaging;Chat",
|
|
|
|
maintainer: "support@element.io",
|
|
|
|
icon: "build/icons",
|
|
|
|
},
|
|
|
|
deb: {
|
|
|
|
packageCategory: "net",
|
|
|
|
depends: [
|
|
|
|
"libgtk-3-0",
|
|
|
|
"libnotify4",
|
|
|
|
"libnss3",
|
|
|
|
"libxss1",
|
|
|
|
"libxtst6",
|
|
|
|
"xdg-utils",
|
|
|
|
"libatspi2.0-0",
|
|
|
|
"libuuid1",
|
|
|
|
"libsecret-1-0",
|
|
|
|
"libasound2",
|
|
|
|
"libgbm1",
|
|
|
|
],
|
|
|
|
recommends: ["libsqlcipher0", "element-io-archive-keyring"],
|
|
|
|
fpm: [
|
|
|
|
"--deb-field",
|
|
|
|
"Replaces: riot-desktop (<< 1.7.0), riot-web (<< 1.7.0)",
|
|
|
|
"--deb-field",
|
|
|
|
"Breaks: riot-desktop (<< 1.7.0), riot-web (<< 1.7.0)",
|
2024-10-30 10:41:55 +00:00
|
|
|
"--deb-pre-depends",
|
|
|
|
"libc6 (>= 2.31)",
|
2024-01-03 16:29:48 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
mac: {
|
|
|
|
category: "public.app-category.social-networking",
|
|
|
|
darkModeSupport: true,
|
|
|
|
hardenedRuntime: true,
|
|
|
|
gatekeeperAssess: true,
|
2025-02-03 09:00:13 +00:00
|
|
|
// @ts-expect-error - due to https://github.com/electron/osx-sign/issues/344
|
|
|
|
strictVerify: "strict",
|
2024-01-03 16:29:48 +00:00
|
|
|
entitlements: "./build/entitlements.mac.plist",
|
|
|
|
icon: "build/icons/icon.icns",
|
2025-01-31 13:05:04 +00:00
|
|
|
mergeASARs: true,
|
2024-01-03 16:29:48 +00:00
|
|
|
},
|
|
|
|
win: {
|
2024-04-15 17:33:30 +01:00
|
|
|
target: ["squirrel", "msi"],
|
2025-01-31 13:05:04 +00:00
|
|
|
signtoolOptions: {
|
|
|
|
signingHashAlgorithms: ["sha256"],
|
|
|
|
},
|
2024-01-03 16:29:48 +00:00
|
|
|
icon: "build/icons/icon.ico",
|
|
|
|
},
|
2024-04-15 17:33:30 +01:00
|
|
|
msi: {
|
|
|
|
perMachine: true,
|
|
|
|
},
|
2024-01-03 16:29:48 +00:00
|
|
|
directories: {
|
|
|
|
output: "dist",
|
|
|
|
},
|
|
|
|
protocols: [
|
|
|
|
{
|
|
|
|
name: "element",
|
2024-05-13 11:25:13 +01:00
|
|
|
schemes: ["io.element.desktop", "element"],
|
2024-01-03 16:29:48 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow specifying windows signing cert via env vars
|
|
|
|
* @param {string} process.env.ED_SIGNTOOL_SUBJECT_NAME
|
|
|
|
* @param {string} process.env.ED_SIGNTOOL_THUMBPRINT
|
|
|
|
*/
|
|
|
|
if (process.env.ED_SIGNTOOL_SUBJECT_NAME && process.env.ED_SIGNTOOL_THUMBPRINT) {
|
2025-01-31 13:05:04 +00:00
|
|
|
config.win.signtoolOptions!.certificateSubjectName = process.env.ED_SIGNTOOL_SUBJECT_NAME;
|
|
|
|
config.win.signtoolOptions!.certificateSha1 = process.env.ED_SIGNTOOL_THUMBPRINT;
|
2024-01-03 16:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow specifying nightly version via env var
|
|
|
|
* @param {string} process.env.ED_NIGHTLY
|
|
|
|
*/
|
|
|
|
if (process.env.ED_NIGHTLY) {
|
|
|
|
config.deb.fpm = []; // Clear the fpm as the breaks deb fields don't apply to nightly
|
|
|
|
|
|
|
|
config.appId = NIGHTLY_APP_ID;
|
|
|
|
config.extraMetadata.productName += " Nightly";
|
2024-01-09 15:56:04 +00:00
|
|
|
config.extraMetadata.name += "-nightly";
|
2024-01-03 16:29:48 +00:00
|
|
|
config.extraMetadata.description += " (nightly unstable build)";
|
|
|
|
config.deb.fpm.push("--name", NIGHTLY_DEB_NAME);
|
|
|
|
|
|
|
|
let version = process.env.ED_NIGHTLY;
|
|
|
|
if (os.platform() === "win32") {
|
|
|
|
// The windows packager relies on parsing this as semver, so we have to make it look like one.
|
|
|
|
// This will give our update packages really stupid names, but we probably can't change that either
|
|
|
|
// because squirrel windows parses them for the version too. We don't really care: nobody sees them.
|
|
|
|
// We just give the installer a static name, so you'll just see this in the 'about' dialog.
|
|
|
|
// Turns out if you use 0.0.0 here it makes Squirrel windows crash, so we use 0.0.1.
|
|
|
|
version = "0.0.1-nightly." + version;
|
|
|
|
}
|
|
|
|
config.extraMetadata.version = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os.platform() === "linux") {
|
|
|
|
// Electron crashes on debian if there's a space in the path.
|
|
|
|
// https://github.com/vector-im/element-web/issues/13171
|
|
|
|
config.extraMetadata.productName = config.extraMetadata.productName.replace(/ /g, "-");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow specifying deb changelog via env var
|
|
|
|
* @param {string} process.env.ED_DEB_CHANGELOG
|
|
|
|
*/
|
|
|
|
if (process.env.ED_DEBIAN_CHANGELOG) {
|
|
|
|
config.deb.fpm.push(`--deb-changelog=${process.env.ED_DEBIAN_CHANGELOG}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.SQLCIPHER_BUNDLED) {
|
|
|
|
// Remove sqlcipher dependency when using bundled
|
|
|
|
config.deb.recommends = config.deb.recommends?.filter((d) => d !== "libsqlcipher0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 11:38:54 +01:00
|
|
|
export default config;
|