Files
Vesktop/scripts/build/sandboxFix.mjs
Vendicated aa17c80514 Fix various potential issues
- Screenshare Picker: fix stream never starting on Windows & macOS due to using venmic without linux guard
- make Vencord downloads atomic for increased resilience
- `--repair`: exit instead of hanging when the download fails
- fix relaunch & autostart on AppImage
- show an error dialog with prompt to repair when startup fails
- Updater: ensure only one Window is opened to avoid issues
- update-aur: fix env var names, avoid printing the aur ssh key
- use tighter permission request handlers to avoid granting frames broad permissions
- prevent the main window from navigating away from Discord
- only serve thumbnails over IPC when screenshare picker is open, so renderer can't screenshot system at will
- fix Vesktop crashing if saved settings files contain invalid values
- write settings atomically, debounce saving window bounds
- Reset Vesktop: delete data on next start to avoid issues on Windows due to file locking
- handle discord:// deep links while already running
- Tray: guard against destroyed Tray

Based on findings by Claude Opus 5.5
2026-11-05 04:21:15 +01:00

77 lines
2.2 KiB
JavaScript

/*
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
// Based on https://github.com/gergof/electron-builder-sandbox-fix/blob/master/lib/index.js
import fs from "fs/promises";
import path from "path";
import AppImageTarget from "app-builder-lib/out/targets/appimage/AppImageTarget.js";
let isApplied = false;
export async function applyAppImageSandboxFix() {
if (process.platform !== "linux") {
// this fix is only required on linux
return;
}
if (isApplied) return;
isApplied = true;
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 )"
ARGS=()
if [[ "$SteamOS" == "1" && "$SteamGamepadUI" == "1" ]]; then
echo "Running Vesktop on SteamOS, disabling sandbox"
ARGS+=(--no-sandbox)
fi
exec "$SCRIPT_DIR/${this.packager.executableName}.bin" "\${ARGS[@]}" "$@"
`.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;
};
}