-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proper fix for disabling sandbox on steamos (#206)
Co-authored-by: Vendicated <[email protected]>
- Loading branch information
1 parent
9521c28
commit b245354
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0 | ||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience | ||
* Copyright (c) 2023 Vendicated and Vencord contributors | ||
*/ | ||
|
||
// Based on https://github.com/gergof/electron-builder-sandbox-fix/blob/master/lib/index.js | ||
|
||
const fs = require("fs/promises"); | ||
const path = require("path"); | ||
let isApplied = false; | ||
|
||
const hook = async () => { | ||
if (isApplied) return; | ||
isApplied = true; | ||
if (process.platform !== "linux") { | ||
// this fix is only required on linux | ||
return; | ||
} | ||
const AppImageTarget = require("app-builder-lib/out/targets/AppImageTarget"); | ||
const oldBuildMethod = AppImageTarget.default.prototype.build; | ||
AppImageTarget.default.prototype.build = async function (...args) { | ||
console.log("Running AppImage builder hook", args); | ||
const oldPath = args[0]; | ||
const newPath = oldPath + "-appimage-sandbox-fix"; | ||
// just in case | ||
try { | ||
await fs.rm(newPath, { | ||
recursive: true | ||
}); | ||
} catch {} | ||
|
||
console.log("Copying to apply appimage fix", oldPath, newPath); | ||
await fs.cp(oldPath, newPath, { | ||
recursive: true | ||
}); | ||
args[0] = newPath; | ||
|
||
const executable = path.join(newPath, this.packager.executableName); | ||
|
||
const loaderScript = ` | ||
#!/usr/bin/env bash | ||
SCRIPT_DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )" | ||
IS_STEAMOS=0 | ||
if [[ "$SteamOS" == "1" && "$SteamGamepadUI" == "1" ]]; then | ||
echo "Running Vesktop on SteamOS, disabling sandbox" | ||
IS_STEAMOS=1 | ||
fi | ||
exec "$SCRIPT_DIR/${this.packager.executableName}.bin" "$([ "$IS_STEAMOS" == 1 ] && echo '--no-sandbox')" "$@" | ||
`.trim(); | ||
|
||
try { | ||
await fs.rename(executable, executable + ".bin"); | ||
await fs.writeFile(executable, loaderScript); | ||
await fs.chmod(executable, 0o755); | ||
} catch (e) { | ||
console.error("failed to create loder for sandbox fix: " + e.message); | ||
throw new Error("Failed to create loader for sandbox fix"); | ||
} | ||
|
||
const ret = await oldBuildMethod.apply(this, args); | ||
|
||
await fs.rm(newPath, { | ||
recursive: true | ||
}); | ||
|
||
return ret; | ||
}; | ||
}; | ||
|
||
module.exports = hook; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters