BUGFIX: Electron app does not run on Linux due to incompatible glibc version and wrong usage of net.fetch (#2114)

This commit is contained in:
catloversg
2025-05-09 16:37:46 +07:00
committed by GitHub
parent 70343ca4c3
commit 290557332c
3 changed files with 9 additions and 15 deletions

View File

@@ -28,7 +28,7 @@ const debounce = require("lodash/debounce");
const Store = require("electron-store");
const store = new Store();
const path = require("path");
const { realpathSync } = require("fs");
const { realpathSync, readFileSync } = require("fs");
const { fileURLToPath } = require("url");
log.transports.file.level = store.get("file-log-level", "info");
@@ -188,8 +188,8 @@ app.on("ready", async () => {
let relativePath;
/**
* "realpathSync" will throw an error if "filePath" points to a non-existent file. If an error is thrown here, the
* electron app will crash immediately. We can use fs.existsSync to check "filePath" before using it, but it's best
* to try-catch the entire code block and avoid unexpected issues.
* Electron app will not write any error logs, and the request will fail silently. We can use fs.existsSync to check
* "filePath" before using it, but it's best to try-catch the entire code block.
*/
try {
filePath = fileURLToPath(url);
@@ -197,13 +197,7 @@ app.on("ready", async () => {
relativePath = path.relative(__dirname, realPath);
// Only allow access to files in "dist" folder or html files in the same directory
if (method === "GET" && (relativePath.startsWith("dist") || relativePath.match(/^[a-zA-Z-_]*\.html/))) {
/**
* By default, requests made by net.fetch go through custom protocol handlers, so we have to explicitly tell it
* to bypass those handles; otherwise, it creates an infinite loop.
*
* Ref: https://github.com/electron/electron/issues/39402
*/
return net.fetch(realPath, { bypassCustomProtocolHandlers: true });
return new Response(readFileSync(realPath));
}
} catch (error) {
log.error(error);

View File

@@ -8,16 +8,16 @@
"name": "bitburner",
"version": "3.0.0",
"dependencies": {
"@catloversg/steamworks.js": "0.0.1",
"@catloversg/steamworks.js": "0.0.2",
"electron-log": "^4.4.8",
"electron-store": "^8.1.0",
"lodash": "^4.17.21"
}
},
"node_modules/@catloversg/steamworks.js": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/@catloversg/steamworks.js/-/steamworks.js-0.0.1.tgz",
"integrity": "sha512-Kj3JZUVqYuLsF34g/N/Ap/aWsJHJoWKbvn/R19fzlZTJY+XMv5myRcngUuydwzvJzHR+BhVk7FzQVV8D8w5x1Q==",
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/@catloversg/steamworks.js/-/steamworks.js-0.0.2.tgz",
"integrity": "sha512-EPB7vQFZa0zGw+Ft4SHiHIDZ7UcuM/XUiyzPo5a9Pf+g5XmcvjIEjo8wKwk7Ox0DOjmSJ+s8GmOD/TDDQW5jgg==",
"license": "MIT",
"dependencies": {
"@types/node": "*"

View File

@@ -24,7 +24,7 @@
"buildResources": "public"
},
"dependencies": {
"@catloversg/steamworks.js": "0.0.1",
"@catloversg/steamworks.js": "0.0.2",
"electron-log": "^4.4.8",
"electron-store": "^8.1.0",
"lodash": "^4.17.21"