mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-04-28 15:38:51 +02:00
feat: replace hardcoded selector with setting implements #543
This commit is contained in:
parent
6385375fd6
commit
90d81d2178
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Electron: Main",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/node_modules/electron/dist/electron",
|
||||||
|
"args": ["."],
|
||||||
|
"protocol": "inspector",
|
||||||
|
"env": {
|
||||||
|
"ELECTRON_DISABLE_SECURITY_WARNINGS": "false"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tidal-hifi",
|
"name": "tidal-hifi",
|
||||||
"version": "5.18.2",
|
"version": "5.19.0",
|
||||||
"description": "Tidal on Electron with widevine(hifi) support",
|
"description": "Tidal on Electron with widevine(hifi) support",
|
||||||
"main": "ts-dist/main.js",
|
"main": "ts-dist/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import { MediaInfo } from "../models/mediaInfo";
|
import { Logger } from "../../features/logger";
|
||||||
import { MediaStatus } from "../models/mediaStatus";
|
import { MediaInfo } from "../../models/mediaInfo";
|
||||||
import { RepeatState } from "../models/repeatState";
|
import { MediaStatus } from "../../models/mediaStatus";
|
||||||
import { DomTidalController } from "./DomController/DomTidalController";
|
import { RepeatState } from "../../models/repeatState";
|
||||||
import { TidalController } from "./TidalController";
|
import { DomTidalController } from "../DomController/DomTidalController";
|
||||||
|
import { TidalController } from "../TidalController";
|
||||||
|
|
||||||
export class MediaSessionTidalController implements TidalController {
|
export class StateController implements TidalController {
|
||||||
public domMediaController: TidalController;
|
public domMediaController: TidalController;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.domMediaController = new DomTidalController();
|
this.domMediaController = new DomTidalController();
|
||||||
|
|
||||||
|
Logger.log("Initialized domController as a backup controller");
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
onMediaInfoUpdate(callback: (state: Partial<MediaInfo>) => void): void {
|
onMediaInfoUpdate(callback: (state: Partial<MediaInfo>) => void): void {
|
4
src/constants/controller.ts
Normal file
4
src/constants/controller.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export const tidalControllers = {
|
||||||
|
domController: "domController",
|
||||||
|
stateController: "stateController",
|
||||||
|
};
|
@ -13,6 +13,7 @@ export const settings = {
|
|||||||
advanced: {
|
advanced: {
|
||||||
root: "advanced",
|
root: "advanced",
|
||||||
tidalUrl: "advanced.tidalUrl",
|
tidalUrl: "advanced.tidalUrl",
|
||||||
|
controllerType: "advanced.controllerType",
|
||||||
},
|
},
|
||||||
api: "api",
|
api: "api",
|
||||||
apiSettings: {
|
apiSettings: {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"openapi": "3.1.0",
|
"openapi": "3.1.0",
|
||||||
"info": {
|
"info": {
|
||||||
"title": "TIDAL Hi-Fi API",
|
"title": "TIDAL Hi-Fi API",
|
||||||
"version": "5.18.2",
|
"version": "5.19.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"license": {
|
"license": {
|
||||||
"name": "MIT",
|
"name": "MIT",
|
||||||
@ -21,7 +21,9 @@
|
|||||||
"/current": {
|
"/current": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Get current media info",
|
"summary": "Get current media info",
|
||||||
"tags": ["current"],
|
"tags": [
|
||||||
|
"current"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Current media info",
|
"description": "Current media info",
|
||||||
@ -39,7 +41,9 @@
|
|||||||
"/current/image": {
|
"/current/image": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Get current media image",
|
"summary": "Get current media image",
|
||||||
"tags": ["current"],
|
"tags": [
|
||||||
|
"current"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Current media image",
|
"description": "Current media image",
|
||||||
@ -61,7 +65,9 @@
|
|||||||
"/player/play": {
|
"/player/play": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Play the current media",
|
"summary": "Play the current media",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -79,7 +85,9 @@
|
|||||||
"/player/favorite/toggle": {
|
"/player/favorite/toggle": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Add the current media to your favorites, or remove it if its already added to your favorites",
|
"summary": "Add the current media to your favorites, or remove it if its already added to your favorites",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -97,7 +105,9 @@
|
|||||||
"/player/pause": {
|
"/player/pause": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Pause the current media",
|
"summary": "Pause the current media",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -115,7 +125,9 @@
|
|||||||
"/player/next": {
|
"/player/next": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Play the next song",
|
"summary": "Play the next song",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -133,7 +145,9 @@
|
|||||||
"/player/previous": {
|
"/player/previous": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Play the previous song",
|
"summary": "Play the previous song",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -151,7 +165,9 @@
|
|||||||
"/player/shuffle/toggle": {
|
"/player/shuffle/toggle": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Play the previous song",
|
"summary": "Play the previous song",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -169,7 +185,9 @@
|
|||||||
"/player/repeat/toggle": {
|
"/player/repeat/toggle": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Toggle the repeat status, toggles between \"off\" , \"single\" and \"all\"",
|
"summary": "Toggle the repeat status, toggles between \"off\" , \"single\" and \"all\"",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -187,7 +205,9 @@
|
|||||||
"/player/playpause": {
|
"/player/playpause": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Start playing the media if paused, or pause the media if playing",
|
"summary": "Start playing the media if paused, or pause the media if playing",
|
||||||
"tags": ["player"],
|
"tags": [
|
||||||
|
"player"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok",
|
"description": "Ok",
|
||||||
@ -205,7 +225,9 @@
|
|||||||
"/settings/skipped-artists": {
|
"/settings/skipped-artists": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "get a list of artists that TIDAL Hi-Fi will skip if skipping is enabled",
|
"summary": "get a list of artists that TIDAL Hi-Fi will skip if skipping is enabled",
|
||||||
"tags": ["settings"],
|
"tags": [
|
||||||
|
"settings"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "The list book.",
|
"description": "The list book.",
|
||||||
@ -221,7 +243,9 @@
|
|||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Add new artists to the list of skipped artists",
|
"summary": "Add new artists to the list of skipped artists",
|
||||||
"tags": ["settings"],
|
"tags": [
|
||||||
|
"settings"
|
||||||
|
],
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"required": true,
|
"required": true,
|
||||||
"content": {
|
"content": {
|
||||||
@ -242,7 +266,9 @@
|
|||||||
"/settings/skipped-artists/delete": {
|
"/settings/skipped-artists/delete": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Remove artists from the list of skipped artists",
|
"summary": "Remove artists from the list of skipped artists",
|
||||||
"tags": ["settings"],
|
"tags": [
|
||||||
|
"settings"
|
||||||
|
],
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"required": true,
|
"required": true,
|
||||||
"content": {
|
"content": {
|
||||||
@ -263,7 +289,9 @@
|
|||||||
"/settings/skipped-artists/current": {
|
"/settings/skipped-artists/current": {
|
||||||
"post": {
|
"post": {
|
||||||
"summary": "Add the current artist to the list of skipped artists",
|
"summary": "Add the current artist to the list of skipped artists",
|
||||||
"tags": ["settings"],
|
"tags": [
|
||||||
|
"settings"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok"
|
"description": "Ok"
|
||||||
@ -272,7 +300,9 @@
|
|||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"summary": "Remove the current artist from the list of skipped artists",
|
"summary": "Remove the current artist from the list of skipped artists",
|
||||||
"tags": ["settings"],
|
"tags": [
|
||||||
|
"settings"
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Ok"
|
"description": "Ok"
|
||||||
@ -283,7 +313,9 @@
|
|||||||
"/image": {
|
"/image": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Get current image",
|
"summary": "Get current image",
|
||||||
"tags": ["legacy"],
|
"tags": [
|
||||||
|
"legacy"
|
||||||
|
],
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -306,7 +338,9 @@
|
|||||||
"/play": {
|
"/play": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Play the current media",
|
"summary": "Play the current media",
|
||||||
"tags": ["legacy"],
|
"tags": [
|
||||||
|
"legacy"
|
||||||
|
],
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -325,7 +359,9 @@
|
|||||||
"/favorite/toggle": {
|
"/favorite/toggle": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Add the current media to your favorites, or remove it if its already added to your favorites",
|
"summary": "Add the current media to your favorites, or remove it if its already added to your favorites",
|
||||||
"tags": ["legacy"],
|
"tags": [
|
||||||
|
"legacy"
|
||||||
|
],
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -344,7 +380,9 @@
|
|||||||
"/pause": {
|
"/pause": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Pause the current media",
|
"summary": "Pause the current media",
|
||||||
"tags": ["legacy"],
|
"tags": [
|
||||||
|
"legacy"
|
||||||
|
],
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -363,7 +401,9 @@
|
|||||||
"/next": {
|
"/next": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Play the next song",
|
"summary": "Play the next song",
|
||||||
"tags": ["legacy"],
|
"tags": [
|
||||||
|
"legacy"
|
||||||
|
],
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -382,7 +422,9 @@
|
|||||||
"/previous": {
|
"/previous": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Play the previous song",
|
"summary": "Play the previous song",
|
||||||
"tags": ["legacy"],
|
"tags": [
|
||||||
|
"legacy"
|
||||||
|
],
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -401,7 +443,9 @@
|
|||||||
"/playpause": {
|
"/playpause": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Toggle play/pause",
|
"summary": "Toggle play/pause",
|
||||||
"tags": ["legacy"],
|
"tags": [
|
||||||
|
"legacy"
|
||||||
|
],
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -514,7 +558,10 @@
|
|||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"example": ["Artist1", "Artist2"]
|
"example": [
|
||||||
|
"Artist1",
|
||||||
|
"Artist2"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -61,7 +61,8 @@ let adBlock: HTMLInputElement,
|
|||||||
discord_show_song: HTMLInputElement,
|
discord_show_song: HTMLInputElement,
|
||||||
discord_show_idle: HTMLInputElement,
|
discord_show_idle: HTMLInputElement,
|
||||||
discord_idle_text: HTMLInputElement,
|
discord_idle_text: HTMLInputElement,
|
||||||
discord_using_text: HTMLInputElement;
|
discord_using_text: HTMLInputElement,
|
||||||
|
controllerType: HTMLSelectElement;
|
||||||
|
|
||||||
addCustomCss(app);
|
addCustomCss(app);
|
||||||
|
|
||||||
@ -157,6 +158,7 @@ function refreshSettings() {
|
|||||||
discord_show_idle.checked = settingsStore.get(settings.discord.showIdle);
|
discord_show_idle.checked = settingsStore.get(settings.discord.showIdle);
|
||||||
discord_idle_text.value = settingsStore.get(settings.discord.idleText);
|
discord_idle_text.value = settingsStore.get(settings.discord.idleText);
|
||||||
discord_using_text.value = settingsStore.get(settings.discord.usingText);
|
discord_using_text.value = settingsStore.get(settings.discord.usingText);
|
||||||
|
controllerType.value = settingsStore.get(settings.advanced.controllerType);
|
||||||
|
|
||||||
// set state of all switches with additional settings
|
// set state of all switches with additional settings
|
||||||
Object.values(switchesWithSettings).forEach((settingSwitch) => {
|
Object.values(switchesWithSettings).forEach((settingSwitch) => {
|
||||||
@ -277,6 +279,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
discord_show_idle = get("discord_show_idle");
|
discord_show_idle = get("discord_show_idle");
|
||||||
discord_using_text = get("discord_using_text");
|
discord_using_text = get("discord_using_text");
|
||||||
discord_idle_text = get("discord_idle_text");
|
discord_idle_text = get("discord_idle_text");
|
||||||
|
controllerType = get<HTMLSelectElement>("controllerType");
|
||||||
|
|
||||||
refreshSettings();
|
refreshSettings();
|
||||||
addInputListener(adBlock, settings.adBlock);
|
addInputListener(adBlock, settings.adBlock);
|
||||||
@ -322,4 +325,5 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
addInputListener(discord_show_idle, settings.discord.showIdle);
|
addInputListener(discord_show_idle, settings.discord.showIdle);
|
||||||
addInputListener(discord_idle_text, settings.discord.idleText);
|
addInputListener(discord_idle_text, settings.discord.idleText);
|
||||||
addInputListener(discord_using_text, settings.discord.usingText);
|
addInputListener(discord_using_text, settings.discord.usingText);
|
||||||
|
addSelectListener(controllerType, settings.advanced.controllerType);
|
||||||
});
|
});
|
||||||
|
@ -382,6 +382,16 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="group__option">
|
||||||
|
<div class="group__description">
|
||||||
|
<h4>Controller Type</h4>
|
||||||
|
<p>Select the type of controller to use.</p>
|
||||||
|
<select id="controllerType" class="select-input">
|
||||||
|
<option value="domController">DOM Controller</option>
|
||||||
|
<option value="stateController">State Controller</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="group">
|
<div class="group">
|
||||||
<p class="group__title">Flags</p>
|
<p class="group__title">Flags</p>
|
||||||
|
@ -22,8 +22,8 @@ import { settingsStore } from "./scripts/settings";
|
|||||||
import { setTitle } from "./scripts/window-functions";
|
import { setTitle } from "./scripts/window-functions";
|
||||||
import { DomControllerOptions } from "./TidalControllers/DomController/DomControllerOptions";
|
import { DomControllerOptions } from "./TidalControllers/DomController/DomControllerOptions";
|
||||||
import { DomTidalController } from "./TidalControllers/DomController/DomTidalController";
|
import { DomTidalController } from "./TidalControllers/DomController/DomTidalController";
|
||||||
import { MediaSessionTidalController } from "./TidalControllers/MediaSessionTidalController";
|
|
||||||
import { TidalController } from "./TidalControllers/TidalController";
|
import { TidalController } from "./TidalControllers/TidalController";
|
||||||
|
import { tidalControllers } from "./constants/controller";
|
||||||
|
|
||||||
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
|
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
|
||||||
const staticTitle = "TIDAL Hi-Fi";
|
const staticTitle = "TIDAL Hi-Fi";
|
||||||
@ -39,16 +39,21 @@ let tidalController: TidalController;
|
|||||||
let controllerOptions = {};
|
let controllerOptions = {};
|
||||||
let currentMediaInfo = getEmptyMediaInfo();
|
let currentMediaInfo = getEmptyMediaInfo();
|
||||||
|
|
||||||
// TODO: replace with setting
|
switch (settingsStore.get(settings.advanced.controllerType)) {
|
||||||
// eslint-disable-next-line no-constant-condition
|
case tidalControllers.stateController: {
|
||||||
if (true) {
|
Logger.log("stateController initialized");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
tidalController = new DomTidalController();
|
tidalController = new DomTidalController();
|
||||||
const domControllerOptions: DomControllerOptions = {
|
const domControllerOptions: DomControllerOptions = {
|
||||||
refreshInterval: getDomUpdateFrequency(),
|
refreshInterval: getDomUpdateFrequency(),
|
||||||
};
|
};
|
||||||
controllerOptions = domControllerOptions;
|
controllerOptions = domControllerOptions;
|
||||||
} else {
|
Logger.log("domController initialized");
|
||||||
tidalController = new MediaSessionTidalController();
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,7 @@ export const settingsStore = new Store({
|
|||||||
adBlock: false,
|
adBlock: false,
|
||||||
advanced: {
|
advanced: {
|
||||||
tidalUrl: "https://listen.tidal.com",
|
tidalUrl: "https://listen.tidal.com",
|
||||||
|
controllerType: "domController",
|
||||||
},
|
},
|
||||||
api: true,
|
api: true,
|
||||||
apiSettings: {
|
apiSettings: {
|
||||||
@ -120,6 +121,11 @@ export const settingsStore = new Store({
|
|||||||
"5.16.0": (migrationStore) => {
|
"5.16.0": (migrationStore) => {
|
||||||
buildMigration("5.16.0", migrationStore, [{ key: settings.discord.showIdle, value: "true" }]);
|
buildMigration("5.16.0", migrationStore, [{ key: settings.discord.showIdle, value: "true" }]);
|
||||||
},
|
},
|
||||||
|
"5.19.0": (migrationStore) => {
|
||||||
|
buildMigration("5.19.0", migrationStore, [
|
||||||
|
{ key: settings.advanced.controllerType, value: "domController" },
|
||||||
|
]);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user