aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-02-26 00:16:08 +0100
committerGitHub <noreply@github.com>2022-02-26 00:16:08 +0100
commitc4fc36d2c9fd732b5c63b7cf47e647c06a33743d (patch)
tree35f2ee022afba594847ec495dc8258610f2a5411 /src/utils.js
parente96135cbc3877423f4c6c012c5d7e09436e5b32c (diff)
parentdec0a7d23767b518284ca69f93ce06a0783de8ce (diff)
downloadViper-c4fc36d2c9fd732b5c63b7cf47e647c06a33743d.tar.gz
Viper-c4fc36d2c9fd732b5c63b7cf47e647c06a33743d.zip
Merge pull request #85 from 0neGal/settings-page
feat: Settings page
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/utils.js b/src/utils.js
index 336017f..6069a46 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -22,11 +22,13 @@ process.chdir(app.getPath("appData"));
var settings = {
gamepath: "",
lang: "en-US",
+ nsupdate: true,
autoupdate: true,
+ nsargs: "-multiple",
zip: "/northstar.zip",
// These files won't be overwritten when installing/updating
- // Northstar, useful for config file.
+ // Northstar, useful for config files
excludes: [
"ns_startup_args.txt",
"ns_startup_args_dedi.txt"
@@ -73,8 +75,8 @@ async function isGameRunning() {
//
// It uses isGameRunning() to ensure it doesn't run while the game is
// running, as that may have all kinds of issues.
-function handleNorthstarAutoUpdating() {
- if (!settings.autoupdate || !fs.existsSync("viper.json") || settings.gamepath.length === 0) {
+function handleNorthstarUpdating() {
+ if (! settings.nsupdate || ! fs.existsSync("viper.json") || settings.gamepath.length === 0) {
return;
}
@@ -170,8 +172,13 @@ async function setpath(win, forcedialog) {
// As to not have to do the same one liner a million times, this
// function exists, as the name suggests, it simply writes the current
// settings to the disk.
-function saveSettings() {
- fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify(settings));
+//
+// You can also pass a settings object to the function and it'll try and
+// merge it together with the already existing settings
+function saveSettings(obj = {}) {
+ settings = {...settings, ...obj};
+ fs.writeFileSync(path.join(settings.gamepath, "ns_startup_args.txt"), settings.nsargs);
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings, ...obj}));
}
// Returns the current Northstar version
@@ -299,6 +306,13 @@ async function update() {
function updatevp(autoinstall) {
const { autoUpdater } = require("electron-updater");
+ if (! autoUpdater.isUpdaterActive()) {
+ if (settings.nsupdate) {
+ handleNorthstarUpdating();
+ }
+ return cli.exit();
+ }
+
if (autoinstall) {
autoUpdater.on("update-downloaded", (info) => {
autoUpdater.quitAndInstall();
@@ -307,8 +321,11 @@ function updatevp(autoinstall) {
autoUpdater.on("error", (info) => {cli.exit(1)});
autoUpdater.on("update-not-available", (info) => {
- // only check for N* updates if Viper itself has no updates
- handleNorthstarAutoUpdating();
+ // only check for NS updates if Viper itself has no updates and
+ // if NS auto updates is enabled.
+ if (settings.nsupdate || cli.hasArgs()) {
+ handleNorthstarUpdating();
+ }
cli.exit();
});
@@ -756,9 +773,11 @@ module.exports = {
setpath,
updatevp,
settings,
+ saveSettings,
getNSVersion,
getTF2Version,
isGameRunning,
+ handleNorthstarUpdating,
setlang: (lang) => {
settings.lang = lang;
saveSettings();