changed mediaSessionController to API Controller

This commit is contained in:
2025-09-01 13:08:42 +02:00
parent 9cbb55fae7
commit 40907f7b7f
5 changed files with 82 additions and 34 deletions

View File

@@ -5,13 +5,12 @@ import { RepeatState } from "../../models/repeatState";
import { DomTidalController } from "../DomController/DomTidalController";
import { TidalController } from "../TidalController";
export class MediaSessionController implements TidalController {
export class TidalApiController implements TidalController {
public domMediaController: TidalController;
constructor() {
this.domMediaController = new DomTidalController();
Logger.log("Initialized domController as a backup controller");
Logger.log("[TidalApiController] - Initialized domController as a backup controller");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onMediaInfoUpdate(callback: (state: Partial<MediaInfo>) => void): void {

View File

@@ -1,4 +1,4 @@
export const tidalControllers = {
domController: "domController",
mediaSessionController: "mediaSessionController",
tidalApiController: "tidalApiController",
};

View File

@@ -21,7 +21,9 @@
"/current": {
"get": {
"summary": "Get current media info",
"tags": ["current"],
"tags": [
"current"
],
"responses": {
"200": {
"description": "Current media info",
@@ -39,7 +41,9 @@
"/current/image": {
"get": {
"summary": "Get current media image",
"tags": ["current"],
"tags": [
"current"
],
"responses": {
"200": {
"description": "Current media image",
@@ -61,7 +65,9 @@
"/player/play": {
"post": {
"summary": "Play the current media",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -79,7 +85,9 @@
"/player/favorite/toggle": {
"post": {
"summary": "Add the current media to your favorites, or remove it if its already added to your favorites",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -97,7 +105,9 @@
"/player/pause": {
"post": {
"summary": "Pause the current media",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -115,7 +125,9 @@
"/player/next": {
"post": {
"summary": "Play the next song",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -133,7 +145,9 @@
"/player/previous": {
"post": {
"summary": "Play the previous song",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -151,7 +165,9 @@
"/player/shuffle/toggle": {
"post": {
"summary": "Play the previous song",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -169,7 +185,9 @@
"/player/repeat/toggle": {
"post": {
"summary": "Toggle the repeat status, toggles between \"off\" , \"single\" and \"all\"",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -187,7 +205,9 @@
"/player/playpause": {
"post": {
"summary": "Start playing the media if paused, or pause the media if playing",
"tags": ["player"],
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
@@ -205,7 +225,9 @@
"/settings/skipped-artists": {
"get": {
"summary": "get a list of artists that TIDAL Hi-Fi will skip if skipping is enabled",
"tags": ["settings"],
"tags": [
"settings"
],
"responses": {
"200": {
"description": "The list book.",
@@ -221,7 +243,9 @@
},
"post": {
"summary": "Add new artists to the list of skipped artists",
"tags": ["settings"],
"tags": [
"settings"
],
"requestBody": {
"required": true,
"content": {
@@ -242,7 +266,9 @@
"/settings/skipped-artists/delete": {
"post": {
"summary": "Remove artists from the list of skipped artists",
"tags": ["settings"],
"tags": [
"settings"
],
"requestBody": {
"required": true,
"content": {
@@ -263,7 +289,9 @@
"/settings/skipped-artists/current": {
"post": {
"summary": "Add the current artist to the list of skipped artists",
"tags": ["settings"],
"tags": [
"settings"
],
"responses": {
"200": {
"description": "Ok"
@@ -272,7 +300,9 @@
},
"delete": {
"summary": "Remove the current artist from the list of skipped artists",
"tags": ["settings"],
"tags": [
"settings"
],
"responses": {
"200": {
"description": "Ok"
@@ -283,7 +313,9 @@
"/image": {
"get": {
"summary": "Get current image",
"tags": ["legacy"],
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
@@ -306,7 +338,9 @@
"/play": {
"get": {
"summary": "Play the current media",
"tags": ["legacy"],
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
@@ -325,7 +359,9 @@
"/favorite/toggle": {
"get": {
"summary": "Add the current media to your favorites, or remove it if its already added to your favorites",
"tags": ["legacy"],
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
@@ -344,7 +380,9 @@
"/pause": {
"get": {
"summary": "Pause the current media",
"tags": ["legacy"],
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
@@ -363,7 +401,9 @@
"/next": {
"get": {
"summary": "Play the next song",
"tags": ["legacy"],
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
@@ -382,7 +422,9 @@
"/previous": {
"get": {
"summary": "Play the previous song",
"tags": ["legacy"],
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
@@ -401,7 +443,9 @@
"/playpause": {
"get": {
"summary": "Toggle play/pause",
"tags": ["legacy"],
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
@@ -514,7 +558,10 @@
"items": {
"type": "string"
},
"example": ["Artist1", "Artist2"]
"example": [
"Artist1",
"Artist2"
]
}
}
},
@@ -532,4 +579,4 @@
"description": "The settings management API"
}
]
}
}

View File

@@ -388,7 +388,7 @@
<p>Select the type of controller to use.</p>
<select id="controllerType" class="select-input">
<option value="domController">DOM Controller</option>
<option value="mediaSessionController">Media Session Controller</option>
<option value="tidalApiController">Tidal Api Controller (beta)</option>
</select>
</div>
</div>

View File

@@ -1,6 +1,7 @@
import { app, dialog, Notification } from "@electron/remote";
import { clipboard, ipcRenderer } from "electron";
import Player from "mpris-service";
import { tidalControllers } from "./constants/controller";
import { globalEvents } from "./constants/globalEvents";
import { settings } from "./constants/settings";
import { downloadIcon } from "./features/icon/downloadIcon";
@@ -20,10 +21,10 @@ import { addHotkey } from "./scripts/hotkeys";
import { ObjectToDotNotation } from "./scripts/objectUtilities";
import { settingsStore } from "./scripts/settings";
import { setTitle } from "./scripts/window-functions";
import { TidalApiController } from "./TidalControllers/apiController/TidalApiController";
import { DomControllerOptions } from "./TidalControllers/DomController/DomControllerOptions";
import { DomTidalController } from "./TidalControllers/DomController/DomTidalController";
import { TidalController } from "./TidalControllers/TidalController";
import { tidalControllers } from "./constants/controller";
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
const staticTitle = "TIDAL Hi-Fi";
@@ -40,8 +41,9 @@ let controllerOptions = {};
let currentMediaInfo = getEmptyMediaInfo();
switch (settingsStore.get(settings.advanced.controllerType)) {
case tidalControllers.mediaSessionController: {
Logger.log("mediaSessionController initialized");
case tidalControllers.tidalApiController: {
tidalController = new TidalApiController();
Logger.log("TidalApiController initialized");
break;
}
@@ -348,11 +350,11 @@ function updateListenBrainz(mediaInfo: MediaInfo) {
mediaInfo.title,
mediaInfo.artists,
mediaInfo.status,
convertDurationToSeconds(mediaInfo.duration)
convertDurationToSeconds(mediaInfo.duration),
);
scrobbleWaitingForDelay = false;
},
settingsStore.get(settings.ListenBrainz.delay) ?? 0
settingsStore.get(settings.ListenBrainz.delay) ?? 0,
);
}
}