diff --git a/index.js b/index.js index 83ef65ab..09bb8d48 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,13 @@ const {app} = require('electron'); // Creating the Application Window and Calling all the Functions function CreateWindow() { if (app.isQuiting) { app.quit(); return; } + + // store + const Store = require("electron-store"); + app.cfg = new Store({ + defaults: {volume: 1}, + }); + /** CIDER **/ const ciderwin = require("./resources/functions/cider-base") app.win = ciderwin diff --git a/resources/cider-ui/index.js b/resources/cider-ui/index.js index c6903ad2..0a4b4d8c 100644 --- a/resources/cider-ui/index.js +++ b/resources/cider-ui/index.js @@ -275,6 +275,10 @@ const app = new Vue({ } } + // Set the volume + ipcRenderer.invoke('getStoreValue', 'volume').then((value) => { + self.mk.volume = value + }) // load cached library if (localStorage.getItem("librarySongs") != null) { @@ -396,6 +400,10 @@ const app = new Vue({ } }) + this.mk.addEventListener(MusicKit.Events.playbackVolumeDidChange, (_a) => { + ipcRenderer.invoke('setStoreValue', 'volume', this.mk.volume) + }) + this.apiCall('https://api.music.apple.com/v1/me/library/playlists', res => { self.playlists.listing = res.data }) diff --git a/resources/functions/cider-base.js b/resources/functions/cider-base.js index e2afe0b2..2da5f175 100644 --- a/resources/functions/cider-base.js +++ b/resources/functions/cider-base.js @@ -1,4 +1,4 @@ -const {BrowserWindow, ipcMain, shell} = require("electron") +const {BrowserWindow, ipcMain, shell, app} = require("electron") const {join} = require("path") const getPort = require("get-port"); const express = require("express"); @@ -43,7 +43,10 @@ const CiderBase = { } } + CiderBase.InitWebServer() + + // Create the BrowserWindow if (process.platform === "darwin" || process.platform === "linux") { win = new BrowserWindow(options) } else { @@ -51,17 +54,6 @@ const CiderBase = { win = new BrowserWindow(options) } - win.webContents.setWindowOpenHandler(({url}) => { - if (url.includes("apple") || url.includes("localhost")) { - return { action: "allow"} - } - shell.openExternal(url).catch(() => {}) - return { - action: 'deny' - } - }) - - // intercept "https://js-cdn.music.apple.com/hls.js/2.141.0/hls.js/hls.js" and redirect to local file "./apple-hls.js" instead win.webContents.session.webRequest.onBeforeRequest( { @@ -95,18 +87,31 @@ const CiderBase = { }) // IPC stuff (listeners) - ipcMain.on('close', () => { // listen for close event win.close(); }) + ipcMain.handle('getStoreValue', (event, key, defaultValue) => { + return (defaultValue ? app.cfg.get(key, true) : app.cfg.get(key)); + }); + + ipcMain.handle('setStoreValue', (event, key, value) => { + app.cfg.set(key, value); + }); + + ipcMain.on('getStore', (event) => { + event.returnValue = app.cfg.store + }) + + ipcMain.on('setStore', (event, store) => { + app.cfg.store = store + }) + ipcMain.on('maximize', () => { // listen for maximize event - if (win.maximizable) { - win.maximize(); - win.maximizable = false; + if (win.isMaximized()) { + win.unmaximize() } else { - win.unmaximize(); - win.maximizable = true; + win.maximize() } }) @@ -115,13 +120,13 @@ const CiderBase = { }) if (process.platform === "win32") { - var WND_STATE = { + let WND_STATE = { MINIMIZED: 0, NORMAL: 1, MAXIMIZED: 2, FULL_SCREEN: 3 } - var wndState = WND_STATE.NORMAL + let wndState = WND_STATE.NORMAL win.on("resize", (_event) => { const isMaximized = win.isMaximized() @@ -141,13 +146,27 @@ const CiderBase = { } }) } + + // Set window Handler + win.webContents.setWindowOpenHandler(({url}) => { + if (url.includes("apple") || url.includes("localhost")) { + return { action: "allow"} + } + shell.openExternal(url).catch(() => {}) + return { + action: 'deny' + } + }) + return win }, + EnvironmentVariables: { "env": { platform: os.platform() } }, + async InitWebServer() { const webRemotePort = await getPort({port : 9000}); const webapp = express(); @@ -164,6 +183,7 @@ const CiderBase = { console.log(`Web Remote listening on port ${webRemotePort}`); }); }, + } module.exports = CiderBase; \ No newline at end of file