mirror of
				https://github.com/Mastermindzh/tidal-hifi.git
				synced 2025-10-31 16:59:09 +01:00 
			
		
		
		
	added player status and worked on getting the integrations working with i3: 9714b2fa1d
				
					
				
			This commit is contained in:
		| @@ -40,7 +40,7 @@ When I started this project there weren't any Linux apps that offered Tidal's "h | ||||
|  | ||||
| ## Integrations | ||||
|  | ||||
| - [i3 blocks config]() - My dotfiles where I use this app to fetch currently playing music | ||||
| - [i3 blocks config](https://github.com/Mastermindzh/dotfiles/commit/9714b2fa1d670108ce811d5511fd3b7a43180647) - My dotfiles where I use this app to fetch currently playing music (direct commit) | ||||
|  | ||||
| ## Why not extend existing projects? | ||||
|  | ||||
|   | ||||
							
								
								
									
										4
									
								
								src/constants/statuses.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/constants/statuses.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| module.exports = { | ||||
|   playing: "playing", | ||||
|   paused: "paused", | ||||
| }; | ||||
| @@ -83,3 +83,7 @@ app.on("activate", function() { | ||||
| ipcMain.on("update-info", (event, arg) => { | ||||
|   mediaInfoModule.update(arg); | ||||
| }); | ||||
|  | ||||
| ipcMain.on("update-status", (event, arg) => { | ||||
|   mediaInfoModule.updateStatus(arg); | ||||
| }); | ||||
|   | ||||
| @@ -4,6 +4,7 @@ const { settings } = require("./scripts/settings"); | ||||
| const { ipcRenderer } = require("electron"); | ||||
| const { app } = require("electron").remote; | ||||
| const { downloadFile } = require("./scripts/download"); | ||||
| const statuses = require("./constants/statuses"); | ||||
| const hotkeys = require("./scripts/hotkeys"); | ||||
| const globalEvents = require("./constants/globalEvents"); | ||||
| const notifier = require("node-notifier"); | ||||
| @@ -210,6 +211,19 @@ function addIPCEventListeners() { | ||||
|   }); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Update the current status of tidal (e.g playing or paused) | ||||
|  */ | ||||
| function updateStatus() { | ||||
|   const play = elements.get("play"); | ||||
|   let status = statuses.paused; | ||||
|   // if play button is NOT visible tidal is playing | ||||
|   if (!play) { | ||||
|     status = statuses.playing; | ||||
|   } | ||||
|   ipcRenderer.send("update-status", status); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Watch for song changes and update title + notify | ||||
|  */ | ||||
| @@ -218,6 +232,8 @@ setInterval(function() { | ||||
|   const artists = elements.getText("artists"); | ||||
|   const songDashArtistTitle = `${title} - ${artists}`; | ||||
|  | ||||
|   updateStatus(); | ||||
|  | ||||
|   if (getTitle() !== songDashArtistTitle) { | ||||
|     setTitle(songDashArtistTitle); | ||||
|  | ||||
|   | ||||
| @@ -2,10 +2,20 @@ const express = require("express"); | ||||
| const { mediaInfo } = require("./mediaInfo"); | ||||
| const settingsModule = require("./settings"); | ||||
| const globalEvents = require("./../constants/globalEvents"); | ||||
| const statuses = require("./../constants/statuses"); | ||||
|  | ||||
| const expressModule = {}; | ||||
| var fs = require("fs"); | ||||
|  | ||||
| /** | ||||
|  * Function to enable tidal-hifi's express api | ||||
|  */ | ||||
| expressModule.run = function(mainWindow) { | ||||
|   /** | ||||
|    * Shorthand to handle a fire and forget global event | ||||
|    * @param {*} res | ||||
|    * @param {*} action | ||||
|    */ | ||||
|   function handleGlobalEvent(res, action) { | ||||
|     mainWindow.webContents.send("globalEvent", action); | ||||
|     res.sendStatus(200); | ||||
| @@ -18,6 +28,13 @@ expressModule.run = function(mainWindow) { | ||||
|   expressApp.get("/pause", (req, res) => handleGlobalEvent(res, globalEvents.pause)); | ||||
|   expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next)); | ||||
|   expressApp.get("/previous", (req, res) => handleGlobalEvent(res, globalEvents.previous)); | ||||
|   expressApp.get("/playpause", (req, res) => { | ||||
|     if (mediaInfo.status == statuses.playing) { | ||||
|       handleGlobalEvent(res, globalEvents.pause); | ||||
|     } else { | ||||
|       handleGlobalEvent(res, globalEvents.play); | ||||
|     } | ||||
|   }); | ||||
|   expressApp.get("/image", (req, res) => { | ||||
|     var stream = fs.createReadStream(mediaInfo.icon); | ||||
|     stream.on("open", function() { | ||||
|   | ||||
| @@ -1,18 +1,33 @@ | ||||
| const statuses = require("./../constants/statuses"); | ||||
|  | ||||
| const mediaInfo = { | ||||
|   title: "", | ||||
|   artist: "", | ||||
|   icon: "", | ||||
|   status: statuses.paused, | ||||
| }; | ||||
| const mediaInfoModule = { | ||||
|   mediaInfo, | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Update artist and song info in the mediaInfo constant | ||||
|  */ | ||||
| mediaInfoModule.update = function(arg) { | ||||
|   mediaInfo.title = propOrDefault(arg.title); | ||||
|   mediaInfo.artist = propOrDefault(arg.message); | ||||
|   mediaInfo.icon = propOrDefault(arg.icon); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Update tidal's status in the mediaInfo constant | ||||
|  */ | ||||
| mediaInfoModule.updateStatus = function(status) { | ||||
|   if (Object.values(statuses).includes(status)) { | ||||
|     mediaInfo.status = status; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Return the property or a default value | ||||
|  * @param {*} prop property to check | ||||
|   | ||||
		Reference in New Issue
	
	Block a user