mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-07-28 00:22:26 +02:00
now using electron-store to save settings between launches
This commit is contained in:
25
src/constants/settings.js
Normal file
25
src/constants/settings.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Object to type my settings file:
|
||||
*
|
||||
* notifications: true,
|
||||
* api: true,
|
||||
* apiSettings: {
|
||||
* port: 47836,
|
||||
* },
|
||||
* windowBounds: { width: 800, height: 600 },
|
||||
*/
|
||||
const settings = {
|
||||
notifications: "notifications",
|
||||
api: "api",
|
||||
apiSettings: {
|
||||
root: "apiSettings",
|
||||
port: "apiSettings.port",
|
||||
},
|
||||
windowBounds: {
|
||||
root: "windowBounds",
|
||||
width: "windowBounds.width",
|
||||
height: "windowBounds.height",
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = settings;
|
@@ -1,5 +1,5 @@
|
||||
const { app, BrowserWindow, globalShortcut, ipcMain } = require("electron");
|
||||
const { settings } = require("./scripts/settings");
|
||||
const { settings, store } = require("./scripts/settings");
|
||||
const { addTray, refreshTray } = require("./scripts/tray");
|
||||
|
||||
const path = require("path");
|
||||
@@ -49,6 +49,11 @@ function createWindow(options = {}) {
|
||||
mainWindow.on("closed", function() {
|
||||
mainWindow = null;
|
||||
});
|
||||
mainWindow.on("resize", () => {
|
||||
let { width, height } = mainWindow.getBounds();
|
||||
|
||||
store.set(settings.windowBounds.root, { width, height });
|
||||
});
|
||||
}
|
||||
|
||||
function addGlobalShortcuts() {
|
||||
@@ -67,7 +72,7 @@ app.on("ready", () => {
|
||||
addGlobalShortcuts();
|
||||
addTray({ icon });
|
||||
refreshTray();
|
||||
settings.api && expressModule.run(mainWindow);
|
||||
store.get(settings.api) && expressModule.run(mainWindow);
|
||||
});
|
||||
|
||||
app.on("activate", function() {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
const { setTitle, getTitle } = require("./scripts/window-functions");
|
||||
const { dialog } = require("electron").remote;
|
||||
const { settings } = require("./scripts/settings");
|
||||
const { store, settings } = require("./scripts/settings");
|
||||
const { ipcRenderer } = require("electron");
|
||||
const { app } = require("electron").remote;
|
||||
const { downloadFile } = require("./scripts/download");
|
||||
@@ -260,7 +260,7 @@ setInterval(function() {
|
||||
}).then(
|
||||
() => {
|
||||
ipcRenderer.send("update-info", options);
|
||||
settings.notifications && notifier.notify(options);
|
||||
store.get(settings.notifications) && notifier.notify(options);
|
||||
},
|
||||
() => {}
|
||||
);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
const express = require("express");
|
||||
const { mediaInfo } = require("./mediaInfo");
|
||||
const settingsModule = require("./settings");
|
||||
const { store, settings } = require("./settings");
|
||||
const globalEvents = require("./../constants/globalEvents");
|
||||
const statuses = require("./../constants/statuses");
|
||||
|
||||
@@ -47,7 +47,7 @@ expressModule.run = function(mainWindow) {
|
||||
});
|
||||
});
|
||||
|
||||
expressApp.listen(settingsModule.settings.apiSettings.port, () => {});
|
||||
expressApp.listen(store.get(settings.apiSettings.port), () => {});
|
||||
};
|
||||
|
||||
module.exports = expressModule;
|
||||
|
@@ -1,12 +1,19 @@
|
||||
const settings = {
|
||||
notifications: true,
|
||||
api: true,
|
||||
apiSettings: {
|
||||
port: 47836,
|
||||
const Store = require("electron-store");
|
||||
const settings = require("./../constants/settings");
|
||||
|
||||
const store = new Store({
|
||||
defaults: {
|
||||
notifications: true,
|
||||
api: true,
|
||||
apiSettings: {
|
||||
port: 47836,
|
||||
},
|
||||
windowBounds: { width: 800, height: 600 },
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const settingsModule = {
|
||||
store,
|
||||
settings,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user