aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-02-23 18:18:38 +0100
committer0neGal <mail@0negal.com>2022-02-23 18:18:38 +0100
commit70309583c81622ff5f5d41e2a9b85df287792326 (patch)
tree1c798b113b19f1c5ffe68dec5b577ac79dae3cac /src
parent815106a3e1214196b25a380d83e826473840f948 (diff)
parente96135cbc3877423f4c6c012c5d7e09436e5b32c (diff)
downloadViper-70309583c81622ff5f5d41e2a9b85df287792326.tar.gz
Viper-70309583c81622ff5f5d41e2a9b85df287792326.zip
Merge 0neGal/viper into settings-page
Diffstat (limited to 'src')
-rw-r--r--src/lang.js44
-rw-r--r--src/utils.js10
2 files changed, 30 insertions, 24 deletions
diff --git a/src/lang.js b/src/lang.js
index b3cbb43..8174174 100644
--- a/src/lang.js
+++ b/src/lang.js
@@ -1,35 +1,37 @@
const fs = require("fs");
-var lang = "en"; // Default language
+const enLang = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8"));
+let lang = "";
+var langObj = {};
-// Loads fallback/default language strings
-var langDef = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8"));
-// If settins are set it'll try to set the language to that instead of
-// the default, however if it can't find it, it'll still fallback to the
-// default language. This might happen as the default language is
-// retrieved from the renderer's navigator.language, which may have
-// languages we don't support yet.
-if (fs.existsSync("viper.json")) {
- lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang;
- if (! lang) {lang = "en"} // Uses fallback, if language isn't set
- if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) {
- if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) {
- lang = lang.replace(/-.*$/, "");
- } else {
- lang = "en"; // Uses fallback if language doesn't exist
+function _loadTranslation() {
+ if (fs.existsSync("viper.json")) {
+ lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang;
+ if (! lang) {lang = "en"}
+ if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) {
+ if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) {
+ lang = lang.replace(/-.*$/, "");
+ } else {
+ lang = "en";
+ }
}
+ } else {
+ lang = "en";
}
+ langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8"));
}
-var langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8"));
module.exports = (string) => {
- if (langObj[string]) { // Returns string from language
+ if (lang === "")
+ _loadTranslation();
+
+ if (langObj[string]) {
return langObj[string];
- } else { // If string doesn't exist
- if (langDef[string]) { // Retrieves from default lang instead
- return langDef[string];
+ } else {
+ if (enLang[string]) {
+ return enLang[string];
} else {
// If it's not in the default lang either, it returns the
// string, this is absolute fallback.
diff --git a/src/utils.js b/src/utils.js
index 5055a2e..2449a73 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -75,9 +75,9 @@ 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.
-northstar_auto_updates: {
+function handleNorthstarAutoUpdating() {
if (!settings.autoupdate || !fs.existsSync("viper.json") || settings.gamepath.length === 0) {
- break northstar_auto_updates;
+ return;
}
async function _checkForUpdates() {
@@ -313,7 +313,11 @@ function updatevp(autoinstall) {
}
autoUpdater.on("error", (info) => {cli.exit(1)});
- autoUpdater.on("update-not-available", (info) => {cli.exit()});
+ autoUpdater.on("update-not-available", (info) => {
+ // only check for N* updates if Viper itself has no updates
+ handleNorthstarAutoUpdating();
+ cli.exit();
+ });
autoUpdater.checkForUpdatesAndNotify();
}