From b6542a6a4b7c9906dc21f5caa0e0b640f601bdf6 Mon Sep 17 00:00:00 2001 From: Laurin Neff Date: Tue, 1 Feb 2022 22:55:51 +0100 Subject: [PATCH] don't attempt to edit /etc/hosts or use pkexec when running as flatpak --- src/ts/Launcher.ts | 9 +++++++++ src/ts/Patch.ts | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ts/Launcher.ts b/src/ts/Launcher.ts index eb0498f..f0b99a0 100644 --- a/src/ts/Launcher.ts +++ b/src/ts/Launcher.ts @@ -186,4 +186,13 @@ export default class Launcher }); }); } + + public static async isFlatpak(): Promise { + try { + const stats = await Neutralino.filesystem.getStats("/.flatpak-info"); + return stats.isFile; + } catch (error) { + return false; + } + } }; diff --git a/src/ts/Patch.ts b/src/ts/Patch.ts index aa37dc6..119b571 100644 --- a/src/ts/Patch.ts +++ b/src/ts/Patch.ts @@ -8,6 +8,7 @@ import { DebugThread } from '@empathize/framework/dist/meta/Debug'; import constants from './Constants'; import Game from './Game'; import AbstractInstaller from './core/AbstractInstaller'; +import Launcher from './Launcher'; declare const Neutralino; @@ -38,6 +39,7 @@ class Stream extends AbstractInstaller const patchDir = `${await constants.paths.launcherDir}/dawn/${version.replaceAll('.', '')}`; const gameDir = await constants.paths.gameDir; + const isFlatpak = await Launcher.isFlatpak(); /** * Patch out the testing phase content from the shell files @@ -51,10 +53,9 @@ class Stream extends AbstractInstaller () => Neutralino.os.execCommand(`cd "${path.addSlashes(patchDir)}" && sed -i '/^echo "If you would like to test this patch, modify this script and remove the line below this one."/,+5d' patch.sh`), /** - * Remove /etc/hosts editing due to sudo permissions - * Let's keep the old removal in case of future issues - () => Neutralino.os.execCommand(`cd "${path.addSlashes(patchDir)}" && sed -i '/^# ===========================================================/,+68d' patch.sh`), - */ + * Remove /etc/hosts editing if running in Flatpak + */ + () => isFlatpak ? Neutralino.os.execCommand(`cd "${path.addSlashes(patchDir)}" && sed -i '/^# ===========================================================/,+68d' patch.sh`) : null, /** * Remove test version restrictions from the anti-login crash patch @@ -73,8 +74,9 @@ class Stream extends AbstractInstaller /** * Execute the main patch installation script + * Use pkexec if not running in Flatpak */ - () => Neutralino.os.execCommand(`yes yes | pkexec bash -c 'cd "${path.addSlashes(gameDir)}" ; "${path.addSlashes(patchDir)}/patch.sh"'`), + () => Neutralino.os.execCommand(`yes yes | ${isFlatpak ? '' : 'pkexec'} bash -c 'cd "${path.addSlashes(gameDir)}" ; "${path.addSlashes(patchDir)}/patch.sh"'`), /** * Execute the anti-login crash patch installation script @@ -91,11 +93,11 @@ class Stream extends AbstractInstaller function: 'Patch/Stream', message: [ 'Patch script output:', - ...outputs[4].stdOut.split(/\r\n|\r|\n/) + ...outputs[5].stdOut.split(/\r\n|\r|\n/) ] }); - this.patchResult = outputs[4].stdOut.includes('==> Patch applied! Enjoy the game'); + this.patchResult = outputs[5].stdOut.includes('==> Patch applied! Enjoy the game'); if (this.onPatchFinish) this.onPatchFinish(this.patchResult);