Merge branch 'main' into 'main'

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

See merge request KRypt0n_/an-anime-game-launcher!31
This commit is contained in:
Observer KRypt0n_ 2022-02-02 06:41:19 +00:00
commit d806e82ab3
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 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);