mirror of
				https://github.com/Mastermindzh/tidal-hifi.git
				synced 2025-11-04 10:49:26 +01:00 
			
		
		
		
	added player status and worked on getting the integrations working with i3: 9714b2fa1d
				
					
				
			This commit is contained in:
		@@ -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