mirror of
				https://github.com/Mastermindzh/tidal-hifi.git
				synced 2025-11-04 02:39:13 +01:00 
			
		
		
		
	feat: added proper updates through the mediasession api. fixes #198
This commit is contained in:
		@@ -26,8 +26,8 @@ const observer = (event, arg) => {
 | 
			
		||||
        ...idleStatus,
 | 
			
		||||
        ...{
 | 
			
		||||
          details: `Listening to ${mediaInfoModule.mediaInfo.title}`,
 | 
			
		||||
          state: mediaInfoModule.mediaInfo.artist
 | 
			
		||||
            ? mediaInfoModule.mediaInfo.artist
 | 
			
		||||
          state: mediaInfoModule.mediaInfo.artists
 | 
			
		||||
            ? mediaInfoModule.mediaInfo.artists
 | 
			
		||||
            : "unknown artist(s)",
 | 
			
		||||
          startTimestamp: parseInt(now),
 | 
			
		||||
          endTimestamp: parseInt(remaining),
 | 
			
		||||
@@ -43,7 +43,7 @@ const observer = (event, arg) => {
 | 
			
		||||
        ...idleStatus,
 | 
			
		||||
        ...{
 | 
			
		||||
          details: `Watching ${mediaInfoModule.mediaInfo.title}`,
 | 
			
		||||
          state: mediaInfoModule.mediaInfo.artist,
 | 
			
		||||
          state: mediaInfoModule.mediaInfo.artists,
 | 
			
		||||
          startTimestamp: parseInt(now),
 | 
			
		||||
          endTimestamp: parseInt(remaining),
 | 
			
		||||
        },
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ let expressInstance;
 | 
			
		||||
/**
 | 
			
		||||
 * Function to enable tidal-hifi's express api
 | 
			
		||||
 */
 | 
			
		||||
expressModule.run = function(mainWindow) {
 | 
			
		||||
expressModule.run = function (mainWindow) {
 | 
			
		||||
  /**
 | 
			
		||||
   * Shorthand to handle a fire and forget global event
 | 
			
		||||
   * @param {*} res
 | 
			
		||||
@@ -24,14 +24,14 @@ expressModule.run = function(mainWindow) {
 | 
			
		||||
 | 
			
		||||
  const expressApp = express();
 | 
			
		||||
  expressApp.get("/", (req, res) => res.send("Hello World!"));
 | 
			
		||||
  expressApp.get("/current", (req, res) => res.json(mediaInfo));
 | 
			
		||||
  expressApp.get("/current", (req, res) => res.json({ ...mediaInfo, artist: mediaInfo.artists }));
 | 
			
		||||
  expressApp.get("/image", (req, res) => {
 | 
			
		||||
    var stream = fs.createReadStream(mediaInfo.icon);
 | 
			
		||||
    stream.on("open", function() {
 | 
			
		||||
    stream.on("open", function () {
 | 
			
		||||
      res.set("Content-Type", "image/png");
 | 
			
		||||
      stream.pipe(res);
 | 
			
		||||
    });
 | 
			
		||||
    stream.on("error", function() {
 | 
			
		||||
    stream.on("error", function () {
 | 
			
		||||
      res.set("Content-Type", "text/plain");
 | 
			
		||||
      res.status(404).end("Not found");
 | 
			
		||||
    });
 | 
			
		||||
@@ -54,7 +54,7 @@ expressModule.run = function(mainWindow) {
 | 
			
		||||
    let port = store.get(settings.apiSettings.port);
 | 
			
		||||
 | 
			
		||||
    expressInstance = expressApp.listen(port, "127.0.0.1", () => {});
 | 
			
		||||
    expressInstance.on("error", function(e) {
 | 
			
		||||
    expressInstance.on("error", function (e) {
 | 
			
		||||
      let message = e.code;
 | 
			
		||||
      if (e.code === "EADDRINUSE") {
 | 
			
		||||
        message = `Port ${port} in use.`;
 | 
			
		||||
 
 | 
			
		||||
@@ -2,14 +2,14 @@ const statuses = require("./../constants/statuses");
 | 
			
		||||
 | 
			
		||||
const mediaInfo = {
 | 
			
		||||
  title: "",
 | 
			
		||||
  artist: "",
 | 
			
		||||
  artists: "",
 | 
			
		||||
  album: "",
 | 
			
		||||
  icon: "",
 | 
			
		||||
  status: statuses.paused,
 | 
			
		||||
  url: "",
 | 
			
		||||
  current: "",
 | 
			
		||||
  duration: "",
 | 
			
		||||
  image: "tidal-hifi-icon"
 | 
			
		||||
  image: "tidal-hifi-icon",
 | 
			
		||||
};
 | 
			
		||||
const mediaInfoModule = {
 | 
			
		||||
  mediaInfo,
 | 
			
		||||
@@ -20,7 +20,7 @@ const mediaInfoModule = {
 | 
			
		||||
 */
 | 
			
		||||
mediaInfoModule.update = function (arg) {
 | 
			
		||||
  mediaInfo.title = propOrDefault(arg.title);
 | 
			
		||||
  mediaInfo.artist = propOrDefault(arg.message);
 | 
			
		||||
  mediaInfo.artists = propOrDefault(arg.artists);
 | 
			
		||||
  mediaInfo.album = propOrDefault(arg.album);
 | 
			
		||||
  mediaInfo.icon = propOrDefault(arg.icon);
 | 
			
		||||
  mediaInfo.url = propOrDefault(arg.url);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user