From 1b7e1efdd0f28866b7b1c325c339fd09ca377acf Mon Sep 17 00:00:00 2001 From: Mykola Zhyhallo Date: Fri, 19 Jan 2024 09:27:30 +0100 Subject: [PATCH] Added IT Army API key to the settings --- src-electron/electron-preload.ts | 3 +++ src-electron/handlers/settings.ts | 27 ++++++++++++++++++++++++--- src/pages/SettingsPage.vue | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src-electron/electron-preload.ts b/src-electron/electron-preload.ts index bb1aec2..96fd229 100644 --- a/src-electron/electron-preload.ts +++ b/src-electron/electron-preload.ts @@ -191,6 +191,9 @@ const settingsAPI = { itarmy: { async setUUID (data: SettingsData['itarmy']['uuid']): Promise { return await ipcRenderer.invoke('settings:itarmy:uuid', data) + }, + async setAPIKey (data: SettingsData['itarmy']['apiKey']): Promise { + return await ipcRenderer.invoke('settings:itarmy:apiKey', data) } }, bootstrap: { diff --git a/src-electron/handlers/settings.ts b/src-electron/handlers/settings.ts index 32e9b1c..204c58f 100644 --- a/src-electron/handlers/settings.ts +++ b/src-electron/handlers/settings.ts @@ -21,7 +21,8 @@ export interface SettingsData { activity: 'DO_NOTHING' | 'MINIMAL' }, itarmy: { - uuid: string + uuid: string, + apiKey: string }, bootstrap: { step: 'LANGUAGE' | 'DATA_FOLDER' | 'MODULES_CONFIGURATION' | 'ITARMY_UUID' | 'DONE' @@ -58,7 +59,8 @@ export class Settings { activity: 'DO_NOTHING' }, itarmy: { - uuid: '' + uuid: '', + apiKey: '' }, bootstrap: { step: 'LANGUAGE', @@ -103,10 +105,15 @@ export class Settings { private applyLoadBackwardsCompatibility() { if (this.data.itarmy === undefined) { this.data.itarmy = { - uuid: '' + uuid: '', + apiKey: '' } } + if (this.data.itarmy.apiKey === undefined) { + this.data.itarmy.apiKey = '' + } + if (this.data.system.language === undefined) { this.data.system.language = 'en-US' } @@ -248,6 +255,16 @@ export class Settings { this.settingsChangedEmiter.emit('settingsChanged', this.data) } + async setItArmyApiKey(data: SettingsData['itarmy']['apiKey']) { + if (!this.loaded) { + await this.load() + } + + this.data.itarmy.apiKey = data + await this.save() + this.settingsChangedEmiter.emit('settingsChanged', this.data) + } + async setBootstrapStep(data: SettingsData['bootstrap']['step']) { if (!this.loaded) { await this.load() @@ -363,6 +380,10 @@ export function handleSettings(settings: Settings) { await settings.setItArmyUUID(data) }) + ipcMain.handle('settings:itarmy:apiKey', async (_e, data: SettingsData['itarmy']['apiKey']) => { + await settings.setItArmyApiKey(data) + }) + ipcMain.handle('settings:bootstrap:step', async (_e, data: SettingsData['bootstrap']['step']) => { await settings.setBootstrapStep(data) }) diff --git a/src/pages/SettingsPage.vue b/src/pages/SettingsPage.vue index af847e0..06bbf60 100644 --- a/src/pages/SettingsPage.vue +++ b/src/pages/SettingsPage.vue @@ -146,6 +146,14 @@ debounce="500" type="number" /> + @@ -346,6 +354,11 @@ async function setItArmyUUID(newValue: string | number | null) { await window.settingsAPI.itarmy.setUUID(String(newValue)); } +const itArmyAPIKey = ref(""); +async function setItArmyAPIKey(newValue: string | number | null) { + await window.settingsAPI.itarmy.setAPIKey(String(newValue)); +} + const deleteStatisticsDialog = ref(false); async function deleteStatistics() { await window.executionEngineAPI.deleteStatistics(); @@ -393,6 +406,7 @@ async function loadSettings() { sheduleActivity.value = settings.schedule.activity; modulesDataFolderPath.value = settings.modules.dataPath; itArmyUUID.value = settings.itarmy.uuid; + itArmyAPIKey.value = settings.itarmy.apiKey; guiDarkMode.value = settings.gui.darkMode; guiMatrixMode.value = settings.gui.matrixMode; matrixModeUnlocked.value = settings.gui.matrixModeUnlocked;