Skip to content

Commit

Permalink
Added IT Army API key to the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
opengs committed Jan 19, 2024
1 parent c708c4e commit 1b7e1ef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src-electron/electron-preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ const settingsAPI = {
itarmy: {
async setUUID (data: SettingsData['itarmy']['uuid']): Promise<void> {
return await ipcRenderer.invoke('settings:itarmy:uuid', data)
},
async setAPIKey (data: SettingsData['itarmy']['apiKey']): Promise<void> {
return await ipcRenderer.invoke('settings:itarmy:apiKey', data)
}
},
bootstrap: {
Expand Down
27 changes: 24 additions & 3 deletions src-electron/handlers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -58,7 +59,8 @@ export class Settings {
activity: 'DO_NOTHING'
},
itarmy: {
uuid: ''
uuid: '',
apiKey: ''
},
bootstrap: {
step: 'LANGUAGE',
Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
})
Expand Down
14 changes: 14 additions & 0 deletions src/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
debounce="500"
type="number"
/>
<q-input
outlined
label="IT Army API Key"
class="q-mt-sm"
v-model="itArmyAPIKey"
@update:model-value="setItArmyAPIKey"
debounce="500"
/>
</q-card-section>

<q-card-section>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1b7e1ef

Please sign in to comment.