From b5a7007baa112c734998337bcd1692ea36547116 Mon Sep 17 00:00:00 2001 From: Maroxy Date: Sun, 28 Nov 2021 19:02:23 +0100 Subject: [PATCH] Configure reset to default --- entry.js | 6 +++++- public/html/settings.html | 1 + src/ts/index.ts | 3 ++- src/ts/lib/PrefixSelector.ts | 14 +++++++++++--- src/ts/settings.ts | 6 +++++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/entry.js b/entry.js index 60e2567..84f0f41 100644 --- a/entry.js +++ b/entry.js @@ -124,7 +124,11 @@ app.whenReady().then(() => { ipcMain.on('prefix-con', async () => { const result = await dialog.showOpenDialog({ properties: ['openDirectory'] }); if(result.filePaths.length == 0) return; - mainWindow.webContents.send('change-prefix', { 'dir': result.filePaths[0] }); + mainWindow.webContents.send('change-prefix', { 'type': 'change', 'dir': result.filePaths[0] }); + }); + + ipcMain.on('prefix-reset', async () => { + mainWindow.webContents.send('change-prefix', { 'type': 'reset' }); }); ipcMain.on('prefix-changed', async () => { diff --git a/public/html/settings.html b/public/html/settings.html index 1fb5e96..21d67d2 100644 --- a/public/html/settings.html +++ b/public/html/settings.html @@ -116,6 +116,7 @@ empty +
diff --git a/src/ts/index.ts b/src/ts/index.ts index fdf0309..a9b3213 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -61,7 +61,8 @@ $(() => { }); ipcRenderer.on('change-prefix', (event: void, data: any) => { - PrefixSelector.set(data.dir); + if(data.type == 'change') PrefixSelector.set(data.dir); + if(data.type == 'reset') PrefixSelector.Default(); LauncherUI.updateLauncherState(); ipcRenderer.send('prefix-changed'); }); diff --git a/src/ts/lib/PrefixSelector.ts b/src/ts/lib/PrefixSelector.ts index 0248315..e96a439 100644 --- a/src/ts/lib/PrefixSelector.ts +++ b/src/ts/lib/PrefixSelector.ts @@ -19,7 +19,7 @@ export default class PrefixSelector } else if (fs.existsSync(path.join(location, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'))) { const config = fs.readFileSync(path.join(location, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'), { encoding: 'ascii' }); const version = /([1-9]+\.[0-9]+\.[0-9]+)_[\d]+_[\d]+/.exec(config)![1]; - + LauncherLib.updateConfig('version', version); LauncherLib.updateConfig('prefix', location); this.prefix = location; @@ -40,16 +40,24 @@ export default class PrefixSelector if (fs.existsSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'Persistent'))) { const version = fs.readFileSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'Persistent', 'ScriptVersion'), { encoding: 'UTF-8' }).toString(); - console.log(version); + + LauncherLib.updateConfig('version', version); + LauncherLib.updateConfig('prefix', dp); + this.prefix = dp; } else if (fs.existsSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'))) { const config = fs.readFileSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'), { encoding: 'ascii' }); const version = /([1-9]+\.[0-9]+\.[0-9]+)_[\d]+_[\d]+/.exec(config)![1]; - console.log(version); + + LauncherLib.updateConfig('version', version); + LauncherLib.updateConfig('prefix', dp); + this.prefix = dp; } else { console.log('Game not found.'); // Unset version if game is not found. LauncherLib.updateConfig('version', null); + LauncherLib.updateConfig('prefix', dp); + this.prefix = dp; } } diff --git a/src/ts/settings.ts b/src/ts/settings.ts index 3328ded..68db7b7 100644 --- a/src/ts/settings.ts +++ b/src/ts/settings.ts @@ -59,7 +59,7 @@ $(() => { */ $('#prefixloc span').text(LauncherLib.getConfig('prefix')); - + ipcRenderer.on('prefix-changed', () => { $('#prefixloc span').text(LauncherLib.getConfig('prefix')); }) @@ -68,6 +68,10 @@ $(() => { ipcRenderer.send('prefix-con'); }) + $('#prefixloc #defprefix').on('click', () => { + ipcRenderer.send('prefix-reset'); + }) + /** * Game voice language */