diff --git a/package.json b/package.json index 5e3b211..e1d8682 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "package.json", "LICENSE" ], + "afterPack": "scripts/build/fixSandbox.js", "linux": { "icon": "build/icon.icns", "category": "Network", diff --git a/scripts/build/fixSandbox.js b/scripts/build/fixSandbox.js new file mode 100644 index 0000000..98b769d --- /dev/null +++ b/scripts/build/fixSandbox.js @@ -0,0 +1,46 @@ +/* + * 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"); + +const log = (message, dotFormatting = chalk.blue) => { + console.log(` ${dotFormatting("•")} ${message}`); +}; + +const afterPackHook = async params => { + if (process.platform !== "linux") { + // this fix is only required on linux + return; + } + + const executable = path.join(params.appOutDir, params.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/${params.packager.executableName}.bin" "$([ "$IS_STEAMOS" == 1 ] && echo '--no-sandbox')" "$@" +`; + + 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"); + } +}; + +module.exports = afterPackHook;