Add support for Flatpak for Git updating (#274)

Co-authored-by: Ven <vendicated@riseup.net>
This commit is contained in:
A user 2022-12-02 12:55:53 -03:00 committed by GitHub
parent 41dddc9eee
commit 62b2acebe6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 10 deletions

View file

@ -39,6 +39,7 @@ const {
getDarwinDirs, getDarwinDirs,
getLinuxDirs, getLinuxDirs,
ENTRYPOINT, ENTRYPOINT,
question
} = require("./common"); } = require("./common");
switch (process.platform) { switch (process.platform) {
@ -62,15 +63,14 @@ async function install(installations) {
// Attempt to give flatpak perms // Attempt to give flatpak perms
if (selected.isFlatpak) { if (selected.isFlatpak) {
try { try {
const { branch } = selected;
const cwd = process.cwd(); const cwd = process.cwd();
const globalCmd = `flatpak override ${branch} --filesystem=${cwd}`; const globalCmd = `flatpak override ${selected.branch} --filesystem=${cwd}`;
const userCmd = `flatpak override --user ${branch} --filesystem=${cwd}`; const userCmd = `flatpak override --user ${selected.branch} --filesystem=${cwd}`;
const cmd = selected.location.startsWith("/home") const cmd = selected.location.startsWith("/home")
? userCmd ? userCmd
: globalCmd; : globalCmd;
execSync(cmd); execSync(cmd);
console.log("Successfully gave write perms to Discord Flatpak."); console.log("Gave write perms to Discord Flatpak.");
} catch (e) { } catch (e) {
console.log("Failed to give write perms to Discord Flatpak."); console.log("Failed to give write perms to Discord Flatpak.");
console.log( console.log(
@ -79,6 +79,29 @@ async function install(installations) {
); );
process.exit(1); process.exit(1);
} }
const answer = await question(
`Would you like to allow ${selected.branch} to talk to org.freedesktop.Flatpak?\n` +
"This is essentially full host access but necessary to spawn git. Without it, the updater will not work\n" +
"Consider using the http based updater (using the gui installer) instead if you want to maintain the sandbox.\n" +
"[y/N]: "
);
if (["y", "yes", "yeah"].includes(answer.toLowerCase())) {
try {
const globalCmd = `flatpak override ${selected.branch} --talk-name=org.freedesktop.Flatpak`;
const userCmd = `flatpak override --user ${selected.branch} --talk-name=org.freedesktop.Flatpak`;
const cmd = selected.location.startsWith("/home")
? userCmd
: globalCmd;
execSync(cmd);
console.log("Sucessfully gave talk permission");
} catch (err) {
console.error("Failed to give talk permission\n", err);
}
} else {
console.log(`Not giving full host access. If you change your mind later, you can run:\nflatpak override ${selected.branch} --talk-name=org.freedesktop.Flatpak`);
}
} }
for (const version of selected.versions) { for (const version of selected.versions) {

View file

@ -28,10 +28,13 @@ const VENCORD_SRC_DIR = join(__dirname, "..");
const execFile = promisify(cpExecFile); const execFile = promisify(cpExecFile);
const isFlatpak = Boolean(process.env.FLATPAK_ID?.includes("discordapp") || process.env.FLATPAK_ID?.includes("Discord"));
function git(...args: string[]) { function git(...args: string[]) {
return execFile("git", args, { const opts = { cwd: VENCORD_SRC_DIR };
cwd: VENCORD_SRC_DIR
}); if (isFlatpak) return execFile("flatpak-spawn", ["--host", "git", ...args], opts);
else return execFile("git", args, opts);
} }
async function getRepo() { async function getRepo() {
@ -61,9 +64,13 @@ async function pull() {
} }
async function build() { async function build() {
const res = await execFile("node", ["scripts/build/build.mjs"], { const opts = { cwd: VENCORD_SRC_DIR };
cwd: VENCORD_SRC_DIR
}); let res;
if (isFlatpak) res = await execFile("flatpak-spawn", ["--host", "node", "scripts/build/build.mjs"], opts);
else res = await execFile("node", ["scripts/build/build.mjs"], opts);
return !res.stderr.includes("Build failed"); return !res.stderr.includes("Build failed");
} }