don't attempt to edit /etc/hosts or use pkexec when running as flatpak

This commit is contained in:
Laurin Neff 2022-02-01 22:55:51 +01:00
parent 58c2b71594
commit b6542a6a4b
No known key found for this signature in database
GPG key ID: ACC6088154D0F6C7
2 changed files with 18 additions and 7 deletions

View file

@ -186,4 +186,13 @@ export default class Launcher
}); });
}); });
} }
public static async isFlatpak(): Promise<boolean> {
try {
const stats = await Neutralino.filesystem.getStats("/.flatpak-info");
return stats.isFile;
} catch (error) {
return false;
}
}
}; };

View file

@ -8,6 +8,7 @@ import { DebugThread } from '@empathize/framework/dist/meta/Debug';
import constants from './Constants'; import constants from './Constants';
import Game from './Game'; import Game from './Game';
import AbstractInstaller from './core/AbstractInstaller'; import AbstractInstaller from './core/AbstractInstaller';
import Launcher from './Launcher';
declare const Neutralino; declare const Neutralino;
@ -38,6 +39,7 @@ class Stream extends AbstractInstaller
const patchDir = `${await constants.paths.launcherDir}/dawn/${version.replaceAll('.', '')}`; const patchDir = `${await constants.paths.launcherDir}/dawn/${version.replaceAll('.', '')}`;
const gameDir = await constants.paths.gameDir; const gameDir = await constants.paths.gameDir;
const isFlatpak = await Launcher.isFlatpak();
/** /**
* Patch out the testing phase content from the shell files * 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`), () => 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 * Remove /etc/hosts editing if running in Flatpak
* Let's keep the old removal in case of future issues */
() => Neutralino.os.execCommand(`cd "${path.addSlashes(patchDir)}" && sed -i '/^# ===========================================================/,+68d' patch.sh`), () => isFlatpak ? Neutralino.os.execCommand(`cd "${path.addSlashes(patchDir)}" && sed -i '/^# ===========================================================/,+68d' patch.sh`) : null,
*/
/** /**
* Remove test version restrictions from the anti-login crash patch * Remove test version restrictions from the anti-login crash patch
@ -73,8 +74,9 @@ class Stream extends AbstractInstaller
/** /**
* Execute the main patch installation script * 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 * Execute the anti-login crash patch installation script
@ -91,11 +93,11 @@ class Stream extends AbstractInstaller
function: 'Patch/Stream', function: 'Patch/Stream',
message: [ message: [
'Patch script output:', '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) if (this.onPatchFinish)
this.onPatchFinish(this.patchResult); this.onPatchFinish(this.patchResult);