Skip to content

Commit

Permalink
try with electron
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Nov 29, 2023
1 parent c180907 commit c810473
Show file tree
Hide file tree
Showing 17 changed files with 332 additions and 275 deletions.
4 changes: 2 additions & 2 deletions bindings/packager/nodejs/__test__/index.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ test("log error", async (t) => {
? process.env.PACKAGER_FORMATS.split(",")
: null,
},
{ verbosity: 2 }
{ verbosity: 2 },
),
undefined
undefined,
);
});
2 changes: 1 addition & 1 deletion bindings/packager/nodejs/generate-config-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require("path");

// compile from file
compileFromFile(
path.join(__dirname, "../../../crates/packager/schema.json")
path.join(__dirname, "../../../crates/packager/schema.json"),
).then((ts) => {
for (const dir of ["src-ts", "build"]) {
try {
Expand Down
4 changes: 2 additions & 2 deletions bindings/packager/nodejs/src-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function packageApp(config: Config = {}, options?: Options) {
async function packageAndSignApp(
config: Config = {},
signingConfig: SigningConfig,
options?: Options
options?: Options,
) {
const conf = await runPlugins();

Expand All @@ -56,7 +56,7 @@ async function packageAndSignApp(

cargoPackager.packageAndSignApp(
JSON.stringify(packagerConfig),
JSON.stringify(signingConfig)
JSON.stringify(signingConfig),
);
}

Expand Down
Binary file removed bindings/updater/nodejs/__test__/app/32x32.png
Binary file not shown.
Binary file added bindings/updater/nodejs/__test__/app/electron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions bindings/updater/nodejs/__test__/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'"
/>
<title>Hello World!</title>
</head>

<body>
<h1>Hello World!</h1>
We are using Node.js <span id="node-version"></span>, Chromium
<span id="chrome-version"></span>, and Electron
<span id="electron-version"></span>.
</body>
</html>
79 changes: 42 additions & 37 deletions bindings/updater/nodejs/__test__/app/main.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
const { checkUpdate } = require("../../index.js");
const { version } = require("./dist/ver.js");
const { join } = require("path");
const { app } = require("electron");
const { join } = require("node:path");
const { checkUpdate } = require("@crabnebula/updater");

console.log(version);
const UPDATER_PUB_KEY =
"dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDQ2Njc0OTE5Mzk2Q0ExODkKUldTSm9XdzVHVWxuUmtJdjB4RnRXZGVqR3NQaU5SVitoTk1qNFFWQ3pjL2hZWFVDOFNrcEVvVlcK";

const updaterFormat = process.env["UPDATER_FORMAT"];
const appimg = process.env["APPIMAGE"];
const isLinux = process.platfrom !== "win32" && process.platfrom !== "darwin";
const CURRENT_VERSION = "{{version}}";

checkUpdate(version, {
pubkey:
"dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDQ2Njc0OTE5Mzk2Q0ExODkKUldTSm9XdzVHVWxuUmtJdjB4RnRXZGVqR3NQaU5SVitoTk1qNFFWQ3pjL2hZWFVDOFNrcEVvVlcK",
endpoints: ["http://localhost:3007"],
executablePath: isLinux && appimg ? appimg : undefined,
windows: {
installerArgs:
// /D sets the default installation directory ($INSTDIR),
// overriding InstallDir and InstallDirRegKey.
// It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces.
// Only absolute paths are supported.
// NOTE: we only need this because this is an integration test and we don't want to install the app in the programs folder
updaterFormat === "nsis"
? [`/D=${join(process.execPath, "..")}`]
: undefined,
},
})
.then((u) => {
if (u) {
u.downloadAndInstall()
.then((_) => {
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});
app.whenReady().then(async () => {
console.log(CURRENT_VERSION);

const updaterFormat = process.env["UPDATER_FORMAT"];
const appimg = process.env["APPIMAGE"];
const isLinux = process.platfrom !== "win32" && process.platfrom !== "darwin";

try {
const update = await checkUpdate(CURRENT_VERSION, {
pubkey: UPDATER_PUB_KEY,
endpoints: ["http://localhost:3007"],
executablePath: isLinux && appimg ? appimg : undefined,
windows: {
installerArgs:
// /D sets the default installation directory ($INSTDIR),
// overriding InstallDir and InstallDirRegKey.
// It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces.
// Only absolute paths are supported.
// NOTE: we only need this because this is an integration test and we don't want to install the app in the programs folder
updaterFormat === "nsis"
? [`/D=${join(process.execPath, "..")}`]
: undefined,
},
});

if (update) {
try {
await update.downloadAndInstall();
process.exit(0);
} catch (e) {
console.error(e);
process.exit(1);
}
} else {
process.exit(0);
}
})
.catch((e) => {
} catch (e) {
console.error(e);
process.exit(1);
});
}
});
28 changes: 22 additions & 6 deletions bindings/updater/nodejs/__test__/app/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
{
"name": "updater-app-test",
"bin": "main.js",
"scripts": {
"build": "pkg . -t host -o ./dist/updater-app-test"
"name": "electron-app",
"productName": "ElectronApp",
"version": "1.0.0",
"description": "Hello World!",
"main": "main.js",
"repository": {
"type": "git",
"url": "git+https://github.com/crabnebula-dev/cargo-packager.git"
},
"author": "CrabNebula Ltd.",
"license": "MIT",
"bugs": {
"url": "https://github.com/crabnebula-dev/cargo-packager/issues"
},
"homepage": "https://github.com/crabnebula-dev/cargo-packager#readme",
"dependencies": {
"@crabnebula/updater": "../.."
},
"devDependencies": {
"pkg": "^5.8.1",
"@crabnebula/packager": "../../../../packager/nodejs"
"electron": "^27.0.3"
},
"packager": {
"outDir": "./dist",
"identifier": "com.electron.example",
"icons": [
"electron.png"
]
}
}
10 changes: 10 additions & 0 deletions bindings/updater/nodejs/__test__/app/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
window.addEventListener("DOMContentLoaded", () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector);
if (element) element.innerText = text;
};

for (const dependency of ["chrome", "node", "electron"]) {
replaceText(`${dependency}-version`, process.versions[dependency]);
}
});
Loading

0 comments on commit c810473

Please sign in to comment.