aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-06-20 00:11:19 +0200
committerGitHub <noreply@github.com>2024-06-20 00:11:19 +0200
commit25adf3d3369526ad393d4086ad2c82963bc02345 (patch)
treefb9b95a174b1490fd60689160f88732b746da2bb /src/modules
parent0f40ecfdf1d351762e6b0bc525b3d716756c5643 (diff)
parent6c2df3103bca1b782101601b088f550f2662ee99 (diff)
downloadViper-25adf3d3369526ad393d4086ad2c82963bc02345.tar.gz
Viper-25adf3d3369526ad393d4086ad2c82963bc02345.zip
Merge branch 'main' into gamepad-support
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/in_path.js24
-rw-r--r--src/modules/launch.js195
-rw-r--r--src/modules/settings.js4
3 files changed, 201 insertions, 22 deletions
diff --git a/src/modules/in_path.js b/src/modules/in_path.js
new file mode 100644
index 0000000..49288c1
--- /dev/null
+++ b/src/modules/in_path.js
@@ -0,0 +1,24 @@
+const fs = require("fs");
+const join = require("path").join;
+
+// checks whether `executable_to_check` is in `$PATH`
+module.exports = (executable_to_check) => {
+ // get folders in `$PATH`
+ let path_dirs = process.env["PATH"].split(":");
+
+ // run through folders
+ for (let i = 0; i < path_dirs.length; i++) {
+ // path to executable this iteration
+ let executable = join(path_dirs[i], executable_to_check);
+
+ // if `executable` exists and is a file, then we found it
+ if (fs.existsSync(executable)
+ && fs.statSync(executable).isFile()) {
+
+ return true;
+ }
+ }
+
+ // we didn't find `executable_to_check`
+ return false;
+}
diff --git a/src/modules/launch.js b/src/modules/launch.js
index 7faf372..fab80c7 100644
--- a/src/modules/launch.js
+++ b/src/modules/launch.js
@@ -1,10 +1,11 @@
-const exec = require("child_process").exec;
-const ipcMain = require("electron").ipcMain;
+const { ipcMain, shell } = require("electron");
+const { exec, execSync } = require("child_process");
const cli = require("../cli");
const win = require("../win");
const lang = require("../lang");
+const in_path = require("./in_path");
const settings = require("./settings");
console = require("./console");
@@ -17,37 +18,187 @@ ipcMain.on("launch", (_, game_version) => {
//
// either Northstar or Vanilla. Linux support is not currently a thing,
// however it'll be added at some point.
-function launch(game_version) {
- // return early, and show error message if on Linux
- if (process.platform == "linux") {
- win().alert(lang("cli.launch.linux_error"));
- console.error(lang("cli.launch.linux_error"));
- cli.exit(1);
- return;
- }
+function launch(game_version, method = settings().linux_launch_method) {
+ console.info(
+ lang("general.launching"),
+ game_version || "Northstar" + "..."
+ )
// change current directory to gamepath
process.chdir(settings().gamepath);
let launch_args = settings().nsargs || "";
- // launch the requested game version
- switch(game_version) {
- case "vanilla":
- console.info(lang("general.launching"), "Vanilla...");
- exec("Titanfall2.exe " + launch_args, {
- cwd: settings().gamepath
+ // add `-vanilla` or `-northstar` depending on `game_version`
+ if (game_version == "vanilla") {
+ launch_args += " -vanilla"
+ } else {
+ launch_args += " -northstar"
+ }
+
+
+ // Linux launch support
+ if (process.platform == "linux") {
+ let flatpak_id = "com.valvesoftware.Steam";
+ let steam_run_str = `steam://run/1237970//${launch_args}/`;
+ console.log(steam_run_str)
+
+ // returns whether the Flatpak version of Steam is installed
+ let flatpak_steam_installed = () => {
+ // this will throw an error if the command fails,
+ // either because of an error with the command, or
+ // because it's not installed, either way,
+ // indicating it's not installed
+ try {
+ execSync(
+ `flatpak info ${flatpak_id}`
+ )
+
+ return true;
+ }catch(err) {}
+
+ return false;
+ }
+
+ switch(method) {
+ case "steam_auto":
+ // if a Steam executable is found, use that
+ if (in_path("steam")) {
+ return launch(game_version, "steam_executable");
+
+ // is Flatpak (likely) installed?
+ } else if (in_path("flatpak")) {
+
+ if (flatpak_steam_installed()) {
+ return launch(game_version, "steam_flatpak");
+ }
+ }
+
+ // fallback to Steam protocol
+ return launch(game_version, "steam_protocol");
+
+ case "steam_flatpak":
+ // make sure Flatpak is installed, and show an error
+ // toast if not
+ if (! in_path("flatpak")) {
+ win().toast({
+ scheme: "error",
+ title: lang("gui.toast.title.missing_flatpak"),
+ description: lang(
+ "gui.toast.desc.missing_flatpak"
+ )
+ })
+ return;
+ }
+
+ // make sure the Flatpak version of Steam is installed,
+ // and show an error toast if not
+ if (! flatpak_steam_installed()) {
+ win().toast({
+ scheme: "error",
+ title: lang(
+ "gui.toast.title.missing_flatpak_steam"
+ ),
+ description: lang(
+ "gui.toast.desc.missing_flatpak_steam"
+ )
+ })
+ return;
+ }
+
+ // attempt to launch the game with Flatpak Steam
+ exec(`flatpak run ${flatpak_id} "${steam_run_str}"`, {
+
+ cwd: settings().gamepath
+ })
+
+ return;
+
+ case "steam_executable":
+ // make sure Steam is installed, and show an error toast
+ // if not
+ if (! in_path("steam")) {
+ win().toast({
+ scheme: "error",
+ title: lang("gui.toast.title.missing_steam"),
+ description: lang(
+ "gui.toast.desc.missing_steam"
+ )
+ })
+ return;
+ }
+
+ // attempt to launch the game with the Steam executable
+ exec(`steam "${steam_run_str}"`, {
+ cwd: settings().gamepath
+ })
+
+ return;
+
+ case "steam_protocol":
+ // attempt to launch the game with the Steam protocol
+ shell.openExternal(steam_run_str)
+
+ return;
+ }
+
+ // launch Vanilla with custom command
+ let command = settings().linux_launch_cmd_ns;
+ if (game_version == "vanilla") {
+ command = settings().linux_launch_cmd_vanilla;
+ }
+
+ // make sure the custom command is not just whitespace, and show
+ // an error toast if it is
+ if (! command.trim()) {
+ win().toast({
+ scheme: "error",
+ title: lang("gui.toast.title.missing_launch_command"),
+ description: lang(
+ "gui.toast.desc.missing_launch_command"
+ )
})
- break;
- default:
- console.info(lang("general.launching"), "Northstar...");
- exec("NorthstarLauncher.exe " + launch_args, {
- cwd: settings().gamepath
+ return;
+ }
+
+ // launch Northstar with custom command
+ try {
+ exec(command, {
+ cwd: settings().gamepath,
+ env: {
+ ...process.env,
+ TF_ARGS: launch_args
+ }
})
+ }catch(err) {
+ // show error if custom commands fails
+ // this should basically never trigger, it should only
+ // trigger if `command` isn't set to something valid
+ win().toast({
+ scheme: "error",
+ title: lang("gui.toast.title.failed_launch_command"),
+ description: lang(
+ "gui.toast.desc.failed_launch_command"
+ )
+ })
+ }
+
+ return;
+ }
- break;
+ // default launches with Northstar
+ let executable = "NorthstarLauncher.exe"
+
+ // change over to using vanilla executable
+ if (game_version == "vanilla") {
+ executable = "Titanfall2.exe"
}
+
+ // launch executable/game
+ exec(executable + " " + launch_args, {
+ cwd: settings().gamepath
+ })
}
module.exports = launch;
diff --git a/src/modules/settings.js b/src/modules/settings.js
index d513ec9..60d6be0 100644
--- a/src/modules/settings.js
+++ b/src/modules/settings.js
@@ -47,6 +47,10 @@ var settings = {
nsargs: "-multiple",
zip: "/northstar.zip",
+ linux_launch_cmd_ns: "",
+ linux_launch_cmd_vanilla: "",
+ linux_launch_method: "steam_auto",
+
// these files won't be overwritten when installing/updating
// Northstar, useful for config files
excludes: [