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";
|
2023-08-21 16:16:47 +02:00
|
|
|
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;
|
2024-02-11 22:42:45 +01:00
|
|
|
/**
|
|
|
|
* Build a migration step for several settings.
|
|
|
|
* All settings will be checked and set to the default if non-existent.
|
|
|
|
* @param version
|
|
|
|
* @param migrationStore
|
|
|
|
* @param options
|
|
|
|
*/
|
|
|
|
const buildMigration = (
|
|
|
|
version: string,
|
|
|
|
migrationStore: { get: (str: string) => string; set: (str: string, val: unknown) => void },
|
|
|
|
options: Array<{ key: string; value: unknown }>
|
|
|
|
) => {
|
|
|
|
console.log(`running migrations for ${version}`);
|
|
|
|
options.forEach(({ key, value }) => {
|
|
|
|
const valueToSet = migrationStore.get(key) ?? value;
|
|
|
|
console.log(` - setting ${key} to ${value}`);
|
|
|
|
migrationStore.set(key, valueToSet);
|
|
|
|
});
|
|
|
|
};
|
2019-11-03 11:18:01 +01:00
|
|
|
|
2023-05-07 15:45:45 +02:00
|
|
|
export const settingsStore = new Store({
|
2019-11-03 11:18:01 +01:00
|
|
|
defaults: {
|
2023-04-20 19:07:44 +02:00
|
|
|
adBlock: false,
|
2023-04-27 11:35:00 +02:00
|
|
|
api: true,
|
2019-11-03 11:18:01 +01:00
|
|
|
apiSettings: {
|
|
|
|
port: 47836,
|
|
|
|
},
|
2023-05-18 17:56:45 +02:00
|
|
|
customCSS: [],
|
2023-04-27 11:35:00 +02:00
|
|
|
disableBackgroundThrottle: true,
|
2022-04-23 22:59:32 +02:00
|
|
|
disableHardwareMediaKeys: false,
|
2021-01-10 13:52:22 +01:00
|
|
|
enableCustomHotkeys: false,
|
2021-04-19 20:43:25 +02:00
|
|
|
enableDiscord: false,
|
2023-08-21 16:16:47 +02:00
|
|
|
discord: {
|
2024-02-11 22:42:45 +01:00
|
|
|
showSong: true,
|
2024-01-08 20:23:26 +01:00
|
|
|
idleText: "Browsing Tidal",
|
2024-02-11 22:42:45 +01:00
|
|
|
usingText: "Playing media on TIDAL",
|
|
|
|
includeTimestamps: true,
|
2023-08-21 16:16:47 +02:00
|
|
|
detailsPrefix: "Listening to ",
|
|
|
|
buttonText: "Play on Tidal",
|
|
|
|
},
|
2023-07-30 02:38:01 +02:00
|
|
|
ListenBrainz: {
|
|
|
|
enabled: false,
|
|
|
|
api: "https://api.listenbrainz.org",
|
|
|
|
token: "",
|
2023-08-28 14:19:12 +02:00
|
|
|
delay: 5000,
|
2023-07-30 02:38:01 +02:00
|
|
|
},
|
2022-05-07 18:13:36 +02:00
|
|
|
flags: {
|
|
|
|
disableHardwareMediaKeys: false,
|
2023-08-07 20:48:29 +02:00
|
|
|
enableWaylandSupport: true,
|
|
|
|
gpuRasterization: true,
|
2022-05-07 18:13:36 +02:00
|
|
|
},
|
2023-04-27 11:35:00 +02:00
|
|
|
menuBar: true,
|
|
|
|
minimizeOnClose: false,
|
|
|
|
mpris: false,
|
|
|
|
notifications: true,
|
|
|
|
playBackControl: true,
|
|
|
|
singleInstance: true,
|
|
|
|
skipArtists: false,
|
|
|
|
skippedArtists: [""],
|
2023-05-09 23:57:16 +02:00
|
|
|
theme: "none",
|
2023-04-27 11:35:00 +02:00
|
|
|
trayIcon: true,
|
|
|
|
updateFrequency: 500,
|
|
|
|
windowBounds: { width: 800, height: 600 },
|
2022-05-07 18:13:36 +02:00
|
|
|
},
|
|
|
|
migrations: {
|
|
|
|
"3.1.0": (migrationStore) => {
|
|
|
|
console.log("running migrations for 3.1.0");
|
|
|
|
migrationStore.set(
|
|
|
|
settings.flags.disableHardwareMediaKeys,
|
|
|
|
migrationStore.get("disableHardwareMediaKeys") ?? false
|
|
|
|
);
|
|
|
|
},
|
2023-08-28 14:19:12 +02:00
|
|
|
"5.7.0": (migrationStore) => {
|
|
|
|
console.log("running migrations for 5.7.0");
|
|
|
|
migrationStore.set(
|
|
|
|
settings.ListenBrainz.delay,
|
|
|
|
migrationStore.get(settings.ListenBrainz.delay) ?? 5000
|
|
|
|
);
|
|
|
|
},
|
2024-01-07 15:42:00 +01:00
|
|
|
"5.8.0": (migrationStore) => {
|
|
|
|
console.log("running migrations for 5.8.0");
|
|
|
|
migrationStore.set(
|
|
|
|
settings.discord.includeTimestamps,
|
|
|
|
migrationStore.get(settings.discord.includeTimestamps) ?? true
|
|
|
|
);
|
|
|
|
},
|
2024-02-11 22:42:45 +01:00
|
|
|
"5.9.0": (migrationStore) => {
|
|
|
|
buildMigration("5.9.0", migrationStore, [
|
|
|
|
{ key: settings.discord.showSong, value: "true" },
|
|
|
|
{ key: settings.discord.idleText, value: "Browsing Tidal" },
|
|
|
|
{
|
|
|
|
key: settings.discord.usingText,
|
|
|
|
value: "Playing media on TIDAL",
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
2019-10-30 22:49:04 +01:00
|
|
|
},
|
2019-11-03 11:18:01 +01:00
|
|
|
});
|
2019-10-30 22:49:04 +01:00
|
|
|
|
|
|
|
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({
|
2023-08-23 20:40:02 +02:00
|
|
|
width: 650,
|
|
|
|
height: 700,
|
2023-05-14 23:48:13 +02:00
|
|
|
resizable: true,
|
2019-11-03 18:52:15 +01:00
|
|
|
show: false,
|
2022-09-25 12:50:41 +02:00
|
|
|
transparent: true,
|
2019-11-03 18:52:15 +01:00
|
|
|
frame: false,
|
2022-09-25 12:50:41 +02:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-05-13 22:45:15 +02:00
|
|
|
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") {
|
2019-11-03 20:22:59 +01:00
|
|
|
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;
|
2019-10-30 22:49:04 +01:00
|
|
|
};
|