Revert "Revert "Done to stop breaks on testing""
This reverts commit 009fae24fc
.
This commit is contained in:
parent
009fae24fc
commit
d7416ac629
1 changed files with 50 additions and 57 deletions
|
@ -2,6 +2,7 @@ import * as ElectronStore from 'electron-store';
|
|||
import * as electron from "electron";
|
||||
import {app} from "electron";
|
||||
import fetch from "electron-fetch";
|
||||
|
||||
export class Store {
|
||||
static cfg: ElectronStore;
|
||||
|
||||
|
@ -259,13 +260,7 @@ export class Store {
|
|||
}
|
||||
},
|
||||
}
|
||||
private migrations: any = {
|
||||
'>=1.4.3': (store: ElectronStore) => {
|
||||
if (typeof store.get('connectivity.discord_rpc') == 'number' || typeof store.get('connectivity.discord_rpc') == 'string') {
|
||||
store.delete('connectivity.discord_rpc');
|
||||
}
|
||||
},
|
||||
}
|
||||
private migrations: any = {}
|
||||
private schema: ElectronStore.Schema<any> = {
|
||||
"connectivity.discord_rpc": {
|
||||
type: 'object'
|
||||
|
@ -278,57 +273,13 @@ export class Store {
|
|||
defaults: this.defaults,
|
||||
schema: this.schema,
|
||||
migrations: this.migrations,
|
||||
clearInvalidConfig: true
|
||||
clearInvalidConfig: false //disabled for now
|
||||
});
|
||||
|
||||
Store.cfg.set(this.mergeStore(this.defaults, Store.cfg.store))
|
||||
this.ipcHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge Configurations
|
||||
* @param target The target configuration
|
||||
* @param source The source configuration
|
||||
*/
|
||||
private mergeStore = (target: { [x: string]: any; }, source: { [x: string]: any; }) => {
|
||||
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
|
||||
for (const key of Object.keys(source)) {
|
||||
if (key.includes('migrations')) {
|
||||
continue;
|
||||
}
|
||||
if (source[key] instanceof Array) {
|
||||
continue
|
||||
}
|
||||
if (source[key] instanceof Object) Object.assign(source[key], this.mergeStore(target[key], source[key]))
|
||||
}
|
||||
// Join `target` and modified `source`
|
||||
Object.assign(target || {}, source)
|
||||
return target
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* IPC Handler
|
||||
*/
|
||||
private ipcHandler(): void {
|
||||
electron.ipcMain.handle('getStoreValue', (_event, key, defaultValue) => {
|
||||
return (defaultValue ? Store.cfg.get(key, true) : Store.cfg.get(key));
|
||||
});
|
||||
|
||||
electron.ipcMain.handle('setStoreValue', (_event, key, value) => {
|
||||
Store.cfg.set(key, value);
|
||||
});
|
||||
|
||||
electron.ipcMain.on('getStore', (event) => {
|
||||
event.returnValue = Store.cfg.store
|
||||
})
|
||||
|
||||
electron.ipcMain.on('setStore', (_event, store) => {
|
||||
Store.cfg.store = store
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
static pushToCloud(): void {
|
||||
if (Store.cfg.get('connectUser.auth') === null) return;
|
||||
var syncData = Object();
|
||||
|
@ -366,4 +317,46 @@ export class Store {
|
|||
body: JSON.stringify(postBody)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge Configurations
|
||||
* @param target The target configuration
|
||||
* @param source The source configuration
|
||||
*/
|
||||
private mergeStore = (target: { [x: string]: any; }, source: { [x: string]: any; }) => {
|
||||
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
|
||||
for (const key of Object.keys(source)) {
|
||||
if (key.includes('migrations')) {
|
||||
continue;
|
||||
}
|
||||
if (source[key] instanceof Array) {
|
||||
continue
|
||||
}
|
||||
if (source[key] instanceof Object) Object.assign(source[key], this.mergeStore(target[key], source[key]))
|
||||
}
|
||||
// Join `target` and modified `source`
|
||||
Object.assign(target || {}, source)
|
||||
return target
|
||||
}
|
||||
|
||||
/**
|
||||
* IPC Handler
|
||||
*/
|
||||
private ipcHandler(): void {
|
||||
electron.ipcMain.handle('getStoreValue', (_event, key, defaultValue) => {
|
||||
return (defaultValue ? Store.cfg.get(key, true) : Store.cfg.get(key));
|
||||
});
|
||||
|
||||
electron.ipcMain.handle('setStoreValue', (_event, key, value) => {
|
||||
Store.cfg.set(key, value);
|
||||
});
|
||||
|
||||
electron.ipcMain.on('getStore', (event) => {
|
||||
event.returnValue = Store.cfg.store
|
||||
})
|
||||
|
||||
electron.ipcMain.on('setStore', (_event, store) => {
|
||||
Store.cfg.store = store
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue