Done to stop breaks on testing
This commit is contained in:
parent
873c626096
commit
fe3d4922e4
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 * as electron from "electron";
|
||||||
import {app} from "electron";
|
import {app} from "electron";
|
||||||
import fetch from "electron-fetch";
|
import fetch from "electron-fetch";
|
||||||
|
|
||||||
export class Store {
|
export class Store {
|
||||||
static cfg: ElectronStore;
|
static cfg: ElectronStore;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ export class Store {
|
||||||
"CommandOrControl",
|
"CommandOrControl",
|
||||||
"G"
|
"G"
|
||||||
],
|
],
|
||||||
"songs" : [
|
"songs": [
|
||||||
"CommandOrControl",
|
"CommandOrControl",
|
||||||
"J"
|
"J"
|
||||||
],
|
],
|
||||||
|
@ -80,17 +81,17 @@ export class Store {
|
||||||
],
|
],
|
||||||
"audioSettings": [
|
"audioSettings": [
|
||||||
"CommandOrControl",
|
"CommandOrControl",
|
||||||
process.platform == "darwin" ? "Option" : (process.platform == "linux" ? "Shift": "Alt"),
|
process.platform == "darwin" ? "Option" : (process.platform == "linux" ? "Shift" : "Alt"),
|
||||||
"A"
|
"A"
|
||||||
],
|
],
|
||||||
"pluginMenu": [
|
"pluginMenu": [
|
||||||
"CommandOrControl",
|
"CommandOrControl",
|
||||||
process.platform == "darwin" ? "Option" : (process.platform == "linux" ? "Shift": "Alt"),
|
process.platform == "darwin" ? "Option" : (process.platform == "linux" ? "Shift" : "Alt"),
|
||||||
"P"
|
"P"
|
||||||
],
|
],
|
||||||
"castToDevices": [
|
"castToDevices": [
|
||||||
"CommandOrControl",
|
"CommandOrControl",
|
||||||
process.platform == "darwin" ? "Option" : (process.platform == "linux" ? "Shift": "Alt"),
|
process.platform == "darwin" ? "Option" : (process.platform == "linux" ? "Shift" : "Alt"),
|
||||||
"C"
|
"C"
|
||||||
],
|
],
|
||||||
"settings": [
|
"settings": [
|
||||||
|
@ -259,13 +260,7 @@ export class Store {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
private migrations: any = {
|
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 schema: ElectronStore.Schema<any> = {
|
private schema: ElectronStore.Schema<any> = {
|
||||||
"connectivity.discord_rpc": {
|
"connectivity.discord_rpc": {
|
||||||
type: 'object'
|
type: 'object'
|
||||||
|
@ -278,57 +273,13 @@ export class Store {
|
||||||
defaults: this.defaults,
|
defaults: this.defaults,
|
||||||
schema: this.schema,
|
schema: this.schema,
|
||||||
migrations: this.migrations,
|
migrations: this.migrations,
|
||||||
clearInvalidConfig: true
|
clearInvalidConfig: false //disabled for now
|
||||||
});
|
});
|
||||||
|
|
||||||
Store.cfg.set(this.mergeStore(this.defaults, Store.cfg.store))
|
Store.cfg.set(this.mergeStore(this.defaults, Store.cfg.store))
|
||||||
this.ipcHandler();
|
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 {
|
static pushToCloud(): void {
|
||||||
if (Store.cfg.get('connectUser.auth') === null) return;
|
if (Store.cfg.get('connectUser.auth') === null) return;
|
||||||
var syncData = Object();
|
var syncData = Object();
|
||||||
|
@ -366,4 +317,46 @@ export class Store {
|
||||||
body: JSON.stringify(postBody)
|
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