now using electron-store to save settings between launches

This commit is contained in:
2019-11-03 11:18:01 +01:00
parent 3d334cd19e
commit 6ef4a0854d
8 changed files with 195 additions and 31 deletions

25
src/constants/settings.js Normal file
View 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;

View File

@@ -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() {

View File

@@ -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);
},
() => {}
);

View File

@@ -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;

View File

@@ -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,
};