Skip to content

Commit 62b2ace

Browse files
A userVendicated
andauthored
Add support for Flatpak for Git updating (#274)
Co-authored-by: Ven <[email protected]>
1 parent 41dddc9 commit 62b2ace

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

scripts/patcher/install.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const {
3939
getDarwinDirs,
4040
getLinuxDirs,
4141
ENTRYPOINT,
42+
question
4243
} = require("./common");
4344

4445
switch (process.platform) {
@@ -62,15 +63,14 @@ async function install(installations) {
6263
// Attempt to give flatpak perms
6364
if (selected.isFlatpak) {
6465
try {
65-
const { branch } = selected;
6666
const cwd = process.cwd();
67-
const globalCmd = `flatpak override ${branch} --filesystem=${cwd}`;
68-
const userCmd = `flatpak override --user ${branch} --filesystem=${cwd}`;
67+
const globalCmd = `flatpak override ${selected.branch} --filesystem=${cwd}`;
68+
const userCmd = `flatpak override --user ${selected.branch} --filesystem=${cwd}`;
6969
const cmd = selected.location.startsWith("/home")
7070
? userCmd
7171
: globalCmd;
7272
execSync(cmd);
73-
console.log("Successfully gave write perms to Discord Flatpak.");
73+
console.log("Gave write perms to Discord Flatpak.");
7474
} catch (e) {
7575
console.log("Failed to give write perms to Discord Flatpak.");
7676
console.log(
@@ -79,6 +79,29 @@ async function install(installations) {
7979
);
8080
process.exit(1);
8181
}
82+
83+
const answer = await question(
84+
`Would you like to allow ${selected.branch} to talk to org.freedesktop.Flatpak?\n` +
85+
"This is essentially full host access but necessary to spawn git. Without it, the updater will not work\n" +
86+
"Consider using the http based updater (using the gui installer) instead if you want to maintain the sandbox.\n" +
87+
"[y/N]: "
88+
);
89+
90+
if (["y", "yes", "yeah"].includes(answer.toLowerCase())) {
91+
try {
92+
const globalCmd = `flatpak override ${selected.branch} --talk-name=org.freedesktop.Flatpak`;
93+
const userCmd = `flatpak override --user ${selected.branch} --talk-name=org.freedesktop.Flatpak`;
94+
const cmd = selected.location.startsWith("/home")
95+
? userCmd
96+
: globalCmd;
97+
execSync(cmd);
98+
console.log("Sucessfully gave talk permission");
99+
} catch (err) {
100+
console.error("Failed to give talk permission\n", err);
101+
}
102+
} else {
103+
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`);
104+
}
82105
}
83106

84107
for (const version of selected.versions) {

src/ipcMain/updater/git.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ const VENCORD_SRC_DIR = join(__dirname, "..");
2828

2929
const execFile = promisify(cpExecFile);
3030

31+
const isFlatpak = Boolean(process.env.FLATPAK_ID?.includes("discordapp") || process.env.FLATPAK_ID?.includes("Discord"));
32+
3133
function git(...args: string[]) {
32-
return execFile("git", args, {
33-
cwd: VENCORD_SRC_DIR
34-
});
34+
const opts = { cwd: VENCORD_SRC_DIR };
35+
36+
if (isFlatpak) return execFile("flatpak-spawn", ["--host", "git", ...args], opts);
37+
else return execFile("git", args, opts);
3538
}
3639

3740
async function getRepo() {
@@ -61,9 +64,13 @@ async function pull() {
6164
}
6265

6366
async function build() {
64-
const res = await execFile("node", ["scripts/build/build.mjs"], {
65-
cwd: VENCORD_SRC_DIR
66-
});
67+
const opts = { cwd: VENCORD_SRC_DIR };
68+
69+
let res;
70+
71+
if (isFlatpak) res = await execFile("flatpak-spawn", ["--host", "node", "scripts/build/build.mjs"], opts);
72+
else res = await execFile("node", ["scripts/build/build.mjs"], opts);
73+
6774
return !res.stderr.includes("Build failed");
6875
}
6976

0 commit comments

Comments
 (0)