tidal-hifi/src/scripts/settings.ts

106 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-05-07 15:45:45 +02:00
import Store from "electron-store";
2023-05-01 23:23:43 +02:00
2023-05-07 15:45:45 +02:00
import { BrowserWindow } from "electron";
import path from "path";
import { settings } from "../constants/settings";
2019-11-03 18:52:15 +01:00
2023-05-07 15:45:45 +02:00
let settingsWindow: BrowserWindow;
2023-05-07 15:45:45 +02:00
export const settingsStore = new Store({
defaults: {
adBlock: false,
api: true,
apiSettings: {
port: 47836,
},
customCSS: [],
disableBackgroundThrottle: true,
disableHardwareMediaKeys: false,
enableCustomHotkeys: false,
enableDiscord: false,
discord: {
detailsPrefix: "Listening to ",
buttonText: "Play on Tidal",
},
2023-07-30 02:38:01 +02:00
ListenBrainz: {
enabled: false,
api: "https://api.listenbrainz.org",
token: "",
},
flags: {
disableHardwareMediaKeys: false,
enableWaylandSupport: true,
gpuRasterization: true,
},
menuBar: true,
minimizeOnClose: false,
mpris: false,
notifications: true,
playBackControl: true,
singleInstance: true,
skipArtists: false,
skippedArtists: [""],
theme: "none",
trayIcon: true,
updateFrequency: 500,
windowBounds: { width: 800, height: 600 },
},
migrations: {
"3.1.0": (migrationStore) => {
console.log("running migrations for 3.1.0");
migrationStore.set(
settings.flags.disableHardwareMediaKeys,
migrationStore.get("disableHardwareMediaKeys") ?? false
);
},
},
});
const settingsModule = {
2023-05-07 15:45:45 +02:00
// settings,
2019-11-03 18:52:15 +01:00
settingsWindow,
};
2023-05-07 15:45:45 +02:00
export const createSettingsWindow = function () {
2019-11-03 18:52:15 +01:00
settingsWindow = new BrowserWindow({
width: 650,
height: 700,
resizable: true,
2019-11-03 18:52:15 +01:00
show: false,
transparent: true,
2019-11-03 18:52:15 +01:00
frame: false,
title: "TIDAL Hi-Fi settings",
2019-11-03 18:52:15 +01:00
webPreferences: {
preload: path.join(__dirname, "../pages/settings/preload.js"),
plugins: true,
nodeIntegration: true,
},
});
settingsWindow.on("close", (event: Event) => {
2019-11-03 18:52:15 +01:00
if (settingsWindow != null) {
event.preventDefault();
settingsWindow.hide();
}
});
settingsWindow.loadURL(`file://${__dirname}/../pages/settings/settings.html`);
settingsModule.settingsWindow = settingsWindow;
};
2023-05-07 15:45:45 +02:00
export const showSettingsWindow = function (tab = "general") {
settingsWindow.webContents.send("goToTab", tab);
2019-11-03 18:52:15 +01:00
// refresh data just before showing the window
settingsWindow.webContents.send("refreshData");
settingsWindow.show();
};
2023-05-07 15:45:45 +02:00
export const hideSettingsWindow = function () {
2019-11-03 18:52:15 +01:00
settingsWindow.hide();
};
2023-05-07 15:45:45 +02:00
export const closeSettingsWindow = function () {
2019-11-03 18:52:15 +01:00
settingsWindow = null;
};