From 7f9df4f66e67cad479efc9d747254d8a206511ed Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sun, 28 Nov 2021 15:52:14 +0200 Subject: [PATCH] Multiple improvements - added action buttons (open launcher's folder, winecfg, winetricks) - improved i18n.translate method which now can use user-provided placeholders - disabled text selection ability --- public/html/settings.html | 8 ++++++ public/locales/de.json | 1 + public/locales/en-us.json | 1 + public/locales/en.json | 1 + public/locales/es.json | 1 + public/locales/fr.json | 1 + public/locales/id.json | 1 + public/locales/ja.json | 1 + public/locales/ko.json | 1 + public/locales/pt.json | 1 + public/locales/ru.json | 1 + public/locales/th.json | 1 + public/locales/vi.json | 1 + public/locales/zh-cn.json | 1 + public/locales/zh-tw.json | 1 + src/sass/basic.sass | 2 ++ src/sass/components.sass | 5 +++- src/ts/lib/i18n.ts | 16 +++++++---- src/ts/settings.ts | 56 ++++++++++++++++++++++++++++++++++++++- 19 files changed, 94 insertions(+), 7 deletions(-) diff --git a/public/html/settings.html b/public/html/settings.html index 428606f..91bac00 100644 --- a/public/html/settings.html +++ b/public/html/settings.html @@ -129,6 +129,14 @@ +

+ +
+ + + +
+
diff --git a/public/locales/de.json b/public/locales/de.json index 6140d10..98d2320 100644 --- a/public/locales/de.json +++ b/public/locales/de.json @@ -11,6 +11,7 @@ "Light": "Hell", "Dark": "Dunkel", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "Vorinstallation erförderlich", "ToggleShadersText": "Verwenden Sie die Home-Taste (POS 1), um Shader im Spiel ein/aus-zuschalten", "Shaders": "Shadern", diff --git a/public/locales/en-us.json b/public/locales/en-us.json index 22b350d..748950f 100644 --- a/public/locales/en-us.json +++ b/public/locales/en-us.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/en.json b/public/locales/en.json index efc9022..9771774 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/es.json b/public/locales/es.json index efc9022..9771774 100644 --- a/public/locales/es.json +++ b/public/locales/es.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/fr.json b/public/locales/fr.json index efc9022..9771774 100644 --- a/public/locales/fr.json +++ b/public/locales/fr.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/id.json b/public/locales/id.json index d29417b..490e0c5 100644 --- a/public/locales/id.json +++ b/public/locales/id.json @@ -11,6 +11,7 @@ "Light": "Terang", "Dark": "Gelap", "System": "Sistem", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pra-pemasangan dibutuhkan", "ToggleShadersText": "Gunakan tombol Home untuk menyalakan/mematikan shader di dalam Game", "Shaders": "Shader", diff --git a/public/locales/ja.json b/public/locales/ja.json index f56658b..520b4dc 100644 --- a/public/locales/ja.json +++ b/public/locales/ja.json @@ -11,6 +11,7 @@ "Light": "ライト", "Dark": "暗い", "System": "システム", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "事前インストールが必要", "ToggleShadersText": "ホームボタンを使用してゲーム内のシェーダを切り替えます", "Shaders": "シェーダ", diff --git a/public/locales/ko.json b/public/locales/ko.json index ffb561d..aae02fb 100644 --- a/public/locales/ko.json +++ b/public/locales/ko.json @@ -11,6 +11,7 @@ "Light": "빛", "Dark": "어두운", "System": "시스템", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "사전 설치 필요", "ToggleShadersText": "홈 버튼을 사용하여 게임에서 쉐이더를 전환하십시오", "Shaders": "쉐이더", diff --git a/public/locales/pt.json b/public/locales/pt.json index efc9022..9771774 100644 --- a/public/locales/pt.json +++ b/public/locales/pt.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/ru.json b/public/locales/ru.json index 73028e1..d279d90 100644 --- a/public/locales/ru.json +++ b/public/locales/ru.json @@ -11,6 +11,7 @@ "Light": "Светлая", "Dark": "Тёмная", "System": "Системная", + "HasNotInstalled": "{0} не установлен", "PreInstallationRequired": "требуется предустановка", "ToggleShadersText": "Используйте кнопку Home для переключения шейдеров в игре", "Shaders": "Шейдеры", diff --git a/public/locales/th.json b/public/locales/th.json index efc9022..9771774 100644 --- a/public/locales/th.json +++ b/public/locales/th.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/vi.json b/public/locales/vi.json index efc9022..9771774 100644 --- a/public/locales/vi.json +++ b/public/locales/vi.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/zh-cn.json b/public/locales/zh-cn.json index bcc83db..ce30760 100644 --- a/public/locales/zh-cn.json +++ b/public/locales/zh-cn.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/public/locales/zh-tw.json b/public/locales/zh-tw.json index 82d610b..6c9ed19 100644 --- a/public/locales/zh-tw.json +++ b/public/locales/zh-tw.json @@ -11,6 +11,7 @@ "Light": "Light", "Dark": "Dark", "System": "System", + "HasNotInstalled": "{0} has not installed", "PreInstallationRequired": "pre-installation required", "ToggleShadersText": "Use Home button to toggle shaders in the game", "Shaders": "Shaders", diff --git a/src/sass/basic.sass b/src/sass/basic.sass index 8281912..14a1dde 100644 --- a/src/sass/basic.sass +++ b/src/sass/basic.sass @@ -4,6 +4,8 @@ body margin: 0 padding: 0 + user-select: none + img.background position: absolute diff --git a/src/sass/components.sass b/src/sass/components.sass index 7ea0e87..8bdcd61 100644 --- a/src/sass/components.sass +++ b/src/sass/components.sass @@ -358,9 +358,12 @@ color: map.get($theme-map, "text") - &:hover + &:hover:not([disabled]) background-color: map.get($theme-map, "background2") + &[disabled] + cursor: default + .button-primary background-color: map.get($theme-map, "background2") diff --git a/src/ts/lib/i18n.ts b/src/ts/lib/i18n.ts index 58d8918..a50c4e7 100644 --- a/src/ts/lib/i18n.ts +++ b/src/ts/lib/i18n.ts @@ -16,7 +16,7 @@ export default class i18n public static loadedLanguage: any; - public static translate (phrase: string): string + public static translate (phrase: string, placeholders: string[] = []): string { if (i18n.loadedLanguage === undefined) this.setLang(navigator.language); @@ -24,13 +24,19 @@ export default class i18n let translation = i18n.loadedLanguage[phrase] ?? phrase; let item; - while ((item = /\{([a-zA-Z\.]+)\}/g.exec(translation)) !== null) + while ((item = /\{([a-zA-Z0-9\.]+)\}/g.exec(translation)) !== null) { - let value: any = constants; + if (/^-?\d+$/.test(item[1])) + translation = translation.replace(item[0], placeholders[parseInt(item[1])]); + + else + { + let value: any = constants; - item[1].split('.').forEach(ref => value = value[ref]); + item[1].split('.').forEach(ref => value = value[ref]); - translation = translation.replace(item[0], value); + translation = translation.replace(item[0], value); + } } return translation; diff --git a/src/ts/settings.ts b/src/ts/settings.ts index 0aa431a..ecac76a 100644 --- a/src/ts/settings.ts +++ b/src/ts/settings.ts @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); const { ipcRenderer } = require('electron'); -const { exec } = require('child_process'); +const { exec, spawn } = require('child_process'); const commandExists = require('command-exists').sync; @@ -92,6 +92,60 @@ $(() => { } }); + /** + * Action buttons + */ + + $('#general-action-buttons #launcher-folder').on('click', () => { + spawn('xdg-open', [constants.launcherDir]); + }); + + /** + * winetricks button + */ + if (!commandExists('winetricks')) + { + $('#general-action-buttons #winetricks').on('click', () => { + exec('winetricks', { + env: { + ...process.env, + WINEPREFIX: constants.prefixDir + } + }); + }); + } + + else + { + $('#general-action-buttons #winetricks') + .addClass('hint--top hint--small') + .attr('data-hint', LauncherUI.i18n.translate('HasNotInstalled', ['winetricks'])) + .attr('disabled', 'disabled'); + } + + /** + * winecfg button + */ + if (!commandExists('winecfg')) + { + $('#general-action-buttons #winecfg').on('click', () => { + exec('winecfg', { + env: { + ...process.env, + WINEPREFIX: constants.prefixDir + } + }); + }); + } + + else + { + $('#general-action-buttons #winecfg') + .addClass('hint--top hint--small') + .attr('data-hint', LauncherUI.i18n.translate('HasNotInstalled', ['winecfg'])) + .attr('disabled', 'disabled'); + } + /** * HUD */