Bread has been achieved.
- Window now creates and loads properly (Due to config not being created halted vue) - Foundation for app.ts created for functions to run in certain stages of the app (start/init, ready, exit) - Electron-Store created in class ConfigStore. Store instance stored in ConfigStore.store. Gets a bit compilicated and might change the class or variable name later on.
This commit is contained in:
parent
7cdb0afaa4
commit
a7b5b36590
4 changed files with 196 additions and 35 deletions
48
src/main/base/app.ts
Normal file
48
src/main/base/app.ts
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import * as electron from 'electron';
|
||||||
|
|
||||||
|
export class App {
|
||||||
|
constructor() {
|
||||||
|
console.log('App started');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles all actions that occur for the app on start (Mainly commandline arguments)
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
public start(store: any): void {
|
||||||
|
console.log('App started');
|
||||||
|
|
||||||
|
switch (store.get("visual.hw_acceleration")) {
|
||||||
|
default:
|
||||||
|
case "default":
|
||||||
|
electron.app.commandLine.appendSwitch('enable-accelerated-mjpeg-decode')
|
||||||
|
electron.app.commandLine.appendSwitch('enable-accelerated-video')
|
||||||
|
electron.app.commandLine.appendSwitch('disable-gpu-driver-bug-workarounds')
|
||||||
|
electron.app.commandLine.appendSwitch('ignore-gpu-blacklist')
|
||||||
|
electron.app.commandLine.appendSwitch('enable-native-gpu-memory-buffers')
|
||||||
|
electron.app.commandLine.appendSwitch('enable-accelerated-video-decode');
|
||||||
|
electron.app.commandLine.appendSwitch('enable-gpu-rasterization');
|
||||||
|
electron.app.commandLine.appendSwitch('enable-native-gpu-memory-buffers');
|
||||||
|
electron.app.commandLine.appendSwitch('enable-oop-rasterization');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "webgpu":
|
||||||
|
console.info("WebGPU is enabled.");
|
||||||
|
electron.app.commandLine.appendSwitch('enable-unsafe-webgpu')
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "disabled":
|
||||||
|
console.info("Hardware acceleration is disabled.");
|
||||||
|
electron.app.commandLine.appendSwitch('disable-gpu')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public stop() {
|
||||||
|
console.log('App stopped');
|
||||||
|
}
|
||||||
|
|
||||||
|
public ready() {
|
||||||
|
console.log('App ready');
|
||||||
|
}
|
||||||
|
}
|
123
src/main/base/store.ts
Normal file
123
src/main/base/store.ts
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
import * as Store from 'electron-store';
|
||||||
|
import * as electron from "electron";
|
||||||
|
|
||||||
|
export class ConfigStore {
|
||||||
|
public store: Store | undefined;
|
||||||
|
|
||||||
|
private defaults: any = {
|
||||||
|
"general": {
|
||||||
|
"close_behavior": 0, // 0 = close, 1 = minimize, 2 = minimize to tray
|
||||||
|
"startup_behavior": 0, // 0 = nothing, 1 = open on startup
|
||||||
|
"discord_rpc": 1, // 0 = disabled, 1 = enabled as Cider, 2 = enabled as Apple Music
|
||||||
|
"discordClearActivityOnPause": 1, // 0 = disabled, 1 = enabled
|
||||||
|
"volume": 1
|
||||||
|
},
|
||||||
|
"home": {
|
||||||
|
"followedArtists": [],
|
||||||
|
"favoriteItems": []
|
||||||
|
},
|
||||||
|
"audio": {
|
||||||
|
"quality": "990",
|
||||||
|
"seamless_audio": true,
|
||||||
|
"normalization": false,
|
||||||
|
"spatial": false,
|
||||||
|
"spatial_properties": {
|
||||||
|
"presets": [],
|
||||||
|
"gain": 0.8,
|
||||||
|
"listener_position": [0, 0, 0],
|
||||||
|
"audio_position": [0, 0, 0],
|
||||||
|
"room_dimensions": {
|
||||||
|
"width": 32,
|
||||||
|
"height": 12,
|
||||||
|
"depth": 32
|
||||||
|
},
|
||||||
|
"room_materials": {
|
||||||
|
"left": 'metal',
|
||||||
|
"right": 'metal',
|
||||||
|
"front": 'brick-bare',
|
||||||
|
"back": 'brick-bare',
|
||||||
|
"down": 'acoustic-ceiling-tiles',
|
||||||
|
"up": 'acoustic-ceiling-tiles',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visual": {
|
||||||
|
"theme": "",
|
||||||
|
"scrollbars": 0, // 0 = show on hover, 2 = always hide, 3 = always show
|
||||||
|
"refresh_rate": 0,
|
||||||
|
"animated_artwork": "limited", // 0 = always, 1 = limited, 2 = never
|
||||||
|
"animated_artwork_qualityLevel": 1,
|
||||||
|
"bg_artwork_rotation": false,
|
||||||
|
"hw_acceleration": "default", // default, webgpu, disabled
|
||||||
|
"window_transparency": "disabled"
|
||||||
|
},
|
||||||
|
"lyrics": {
|
||||||
|
"enable_mxm": false,
|
||||||
|
"mxm_karaoke": false,
|
||||||
|
"mxm_language": "en",
|
||||||
|
"enable_yt": false,
|
||||||
|
},
|
||||||
|
"lastfm": {
|
||||||
|
"enabled": false,
|
||||||
|
"scrobble_after": 30,
|
||||||
|
"auth_token": "",
|
||||||
|
"enabledRemoveFeaturingArtists": true,
|
||||||
|
"NowPlaying": "true"
|
||||||
|
},
|
||||||
|
"advanced": {
|
||||||
|
"AudioContext": false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private migrations: any = {}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.store = new Store({
|
||||||
|
name: 'cider-config',
|
||||||
|
defaults: this.defaults,
|
||||||
|
migrations: this.migrations,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.store.set(this.mergeStore(this.defaults, this.store.store))
|
||||||
|
this.ipcHandler(this.store);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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(cfg: Store | any): void {
|
||||||
|
electron.ipcMain.handle('getStoreValue', (event, key, defaultValue) => {
|
||||||
|
return (defaultValue ? cfg.get(key, true) : cfg.get(key));
|
||||||
|
});
|
||||||
|
|
||||||
|
electron.ipcMain.handle('setStoreValue', (event, key, value) => {
|
||||||
|
cfg.set(key, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
electron.ipcMain.on('getStore', (event) => {
|
||||||
|
event.returnValue = cfg.store
|
||||||
|
})
|
||||||
|
|
||||||
|
electron.ipcMain.on('setStore', (event, store) => {
|
||||||
|
cfg.store = store
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,9 +10,15 @@ import {Stream} from "stream";
|
||||||
|
|
||||||
export class Win {
|
export class Win {
|
||||||
win: any | undefined = null;
|
win: any | undefined = null;
|
||||||
app: electron.App | undefined;
|
app: any | undefined = null;
|
||||||
|
store: any | undefined = null;
|
||||||
devMode: boolean = !electron.app.isPackaged;
|
devMode: boolean = !electron.app.isPackaged;
|
||||||
|
|
||||||
|
constructor(app: electron.App, store: any) {
|
||||||
|
this.app = app;
|
||||||
|
this.store = store;
|
||||||
|
}
|
||||||
|
|
||||||
private paths: any = {
|
private paths: any = {
|
||||||
srcPath: path.join(__dirname, "../../src"),
|
srcPath: path.join(__dirname, "../../src"),
|
||||||
resourcePath: path.join(__dirname, "../../resources"),
|
resourcePath: path.join(__dirname, "../../resources"),
|
||||||
|
@ -124,7 +130,7 @@ export class Win {
|
||||||
private startWebServer(): void {
|
private startWebServer(): void {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// TODO: app.use(express.static(path.join(this.paths.srcPath, './renderer/')));
|
app.use(express.static(path.join(this.paths.srcPath, './renderer/')));
|
||||||
app.set("views", path.join(this.paths.srcPath, './renderer/views'));
|
app.set("views", path.join(this.paths.srcPath, './renderer/views'));
|
||||||
app.set("view engine", "ejs");
|
app.set("view engine", "ejs");
|
||||||
|
|
||||||
|
@ -277,24 +283,6 @@ export class Win {
|
||||||
return await yt.search(u)
|
return await yt.search(u)
|
||||||
})
|
})
|
||||||
|
|
||||||
electron.ipcMain.handle('getStoreValue', (event, key, defaultValue) => {
|
|
||||||
// return (defaultValue ? app.cfg.get(key, true) : app.cfg.get(key));
|
|
||||||
return null
|
|
||||||
});
|
|
||||||
|
|
||||||
electron.ipcMain.handle('setStoreValue', (event, key, value) => {
|
|
||||||
// app.cfg.set(key, value);
|
|
||||||
});
|
|
||||||
|
|
||||||
electron.ipcMain.on('getStore', (event) => {
|
|
||||||
// event.returnValue = app.cfg.store
|
|
||||||
event.returnValue = null
|
|
||||||
})
|
|
||||||
|
|
||||||
electron.ipcMain.on('setStore', (event, store) => {
|
|
||||||
// app.cfg.store = store
|
|
||||||
})
|
|
||||||
|
|
||||||
electron.ipcMain.handle('setVibrancy', (event, key, value) => {
|
electron.ipcMain.handle('setVibrancy', (event, key, value) => {
|
||||||
this.win.setVibrancy(value)
|
this.win.setVibrancy(value)
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,28 +12,30 @@ import { app } from 'electron';
|
||||||
//
|
//
|
||||||
|
|
||||||
import {Win} from "./base/win";
|
import {Win} from "./base/win";
|
||||||
|
import {ConfigStore} from "./base/store";
|
||||||
|
|
||||||
const Cider = new Win()
|
const config = new ConfigStore();
|
||||||
|
console.log(config)
|
||||||
|
|
||||||
app.on("ready", () => {
|
const Cider = new Win(app, config.store)
|
||||||
Cider.createWindow();
|
|
||||||
});
|
|
||||||
|
|
||||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* App Event Handlers
|
* App Event Handlers
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||||
|
|
||||||
// app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
// if (app.isQuiting) { app.quit(); return; }
|
|
||||||
//
|
|
||||||
// console.log('[Cider] Application is Ready. Creating Window.')
|
console.log('[Cider] Application is Ready. Creating Window.')
|
||||||
// if (!app.isPackaged) {
|
if (!app.isPackaged) {
|
||||||
// console.info('[Cider] Running in development mode.')
|
console.info('[Cider] Running in development mode.')
|
||||||
// require('vue-devtools').install()
|
require('vue-devtools').install()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // CiderBase.Start()
|
Cider.createWindow();
|
||||||
// });
|
|
||||||
|
// CiderBase.Start()
|
||||||
|
});
|
||||||
//
|
//
|
||||||
// app.on('before-quit', () => {
|
// app.on('before-quit', () => {
|
||||||
// app.isQuiting = true;
|
// app.isQuiting = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue