aboutsummaryrefslogtreecommitdiff
path: root/src/modules/launch.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-04-29 18:59:28 +0200
committer0neGal <mail@0negal.com>2024-04-29 18:59:28 +0200
commit97be082dbbe66684f3e8a558e309329cad024e27 (patch)
treeaefaf1efb20d2ac121120eff588b28e994674d45 /src/modules/launch.js
parent9b31e6dfc2277dc2b904b4319b9bc06f849c38dc (diff)
downloadViper-97be082dbbe66684f3e8a558e309329cad024e27.tar.gz
Viper-97be082dbbe66684f3e8a558e309329cad024e27.zip
actual Linux launch support
The "Steam (Auto)" launch method should ideally work in all scenarios, ideally! Obviously, I can't and haven't tested in every environment, but I've attempted to make sure it functions. Launching Vanilla and Northstar works just fine, custom launch arguments also work just fine, it works with normal Steam, Flatpak Steam, and as a fallback with the Steam Browser Protocol (`steam://`) There's also the option to set your own/custom launch command for both the Vanilla and Northstar launch options. How well they work will of course depend on what the user set them to. "Steam (Auto)" attempts to pick the right Steam launch method depending on what's available, if the Steam executable can be found, it'll use "Steam (Executable)", if it cant and Flatpak is found on top of an install of Steam through Flatpak, then "Steam (Flatpak)" is used, if all of that fails, then we attempt to use "Steam (Protocol)" Some toasts will be shown if you attempt to run the game with either "Steam (Executable)" or "Steam (Flatpak)" and they cant find the game/Steam. This isn't an issue with "Steam (Auto)"
Diffstat (limited to 'src/modules/launch.js')
-rw-r--r--src/modules/launch.js197
1 files changed, 174 insertions, 23 deletions
diff --git a/src/modules/launch.js b/src/modules/launch.js
index 73ce408..544e155 100644
--- a/src/modules/launch.js
+++ b/src/modules/launch.js
@@ -1,15 +1,16 @@
-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");
-ipcMain.on("launch-ns", launch);
+ipcMain.on("launch-ns", () => {launch()});
ipcMain.on("launch-vanilla", () => {
launch("vanilla");
})
@@ -18,37 +19,187 @@ ipcMain.on("launch-vanilla", () => {
//
// 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;