Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native electron notifications and album text #90

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.7.0

- Switched to the native Notifier (removed node-notifier)
- Album art now also has a name, based on [best effort](https://github.com/Mastermindzh/tidal-hifi/pull/88#pullrequestreview-840814847)

## 2.6.0

- Add album images to mediainfo and discord

## 2.5.0

- Notify-send now correctly shows "Tidal Hifi" as the program name

- Updated dependencies (including electron itself)

### known issues
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ To install and work with the code on this project follow these steps:
- API for status and playback
- Custom [integrations](#integrations)
- [Settings feature](./docs/settings.png) to disable certain functionality. (`ctrl+=`)
- AlbumArt in integrations ([best-effort](https://github.com/Mastermindzh/tidal-hifi/pull/88#pullrequestreview-840814847))

## Integrations

Expand Down
109 changes: 8 additions & 101 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tidal-hifi",
"version": "2.5.0",
"version": "2.7.0",
"description": "Tidal on Electron with widevine(hifi) support",
"main": "src/main.js",
"scripts": {
Expand Down Expand Up @@ -28,7 +28,6 @@
"express": "^4.17.1",
"hotkeys-js": "^3.8.7",
"mpris-service": "^2.1.2",
"node-notifier": "^10.0.0",
"request": "^2.88.2"
},
"devDependencies": {
Expand Down
34 changes: 31 additions & 3 deletions src/preload.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { setTitle } = require("./scripts/window-functions");
const { dialog, process } = require("electron").remote;
const { dialog, process, Notification } = require("electron").remote;
const { store, 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");
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
let currentSong = "";
let player;
Expand Down Expand Up @@ -39,6 +38,10 @@ const elements = {
duration: '*[data-test="duration-time"]',
bar: '*[data-test="progress-bar"]',
footer: "#footerPlayer",
album_header_title: '.header-details [data-test="title"]',
playing_title: 'span[data-test="table-cell-title"].css-geqnfr',
album_name_cell: '[data-test="table-cell-album"]',
tracklist_row: '[data-test="tracklist-row"]',

/**
* Get an element from the dom
Expand Down Expand Up @@ -77,6 +80,26 @@ const elements = {
return "unknown artist(s)";
},

getAlbumName: function () {
//If listening to an album, get its name from the header title
if(window.location.href.includes('/album/')) {
const albumName = window.document.querySelector(this.album_header_title);
if(albumName) {
return albumName.textContent;
}
//If listening to a playlist or a mix, get album name from the list
} else if(window.location.href.includes('/playlist/') || window.location.href.includes('/mix/')) {
if(currentPlayStatus === statuses.playing) {
const row = window.document.querySelector(this.playing_title).closest(this.tracklist_row);
if(row) {
return row.querySelector(this.album_name_cell).textContent;
}
}
}

return "";
},

/**
* Shorthand function to get the text of a dom element
* @param {*} key key in elements object to fetch
Expand Down Expand Up @@ -251,13 +274,16 @@ function convertDuration(duration) {
function updateMediaInfo(options, notify) {
if (options) {
ipcRenderer.send(globalEvents.updateInfo, options);
store.get(settings.notifications) && notify && notifier.notify(options);
if(store.get(settings.notifications) && notify) {
new Notification({ title: options.title, body: options.message, icon: options.icon}).show();
}
if (player) {
player.metadata = {
...player.metadata,
...{
"xesam:title": options.title,
"xesam:artist": [options.message],
"xesam:album": options.album,
"mpris:artUrl": options.image,
"mpris:length": convertDuration(options.duration) * 1000 * 1000,
},
Expand Down Expand Up @@ -290,6 +316,7 @@ function updateURL() {
setInterval(function () {
const title = elements.getText("title");
const artists = elements.getArtists();
const album = elements.getAlbumName();
const current = elements.getText("current");
const duration = elements.getText("duration");
const appName = "Tidal Hifi";
Expand All @@ -299,6 +326,7 @@ setInterval(function () {
const options = {
title,
message: artists,
album: album,
status: currentStatus,
url: currentURL,
current: current,
Expand Down
1 change: 1 addition & 0 deletions src/scripts/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const observer = (event, arg) => {
startTimestamp: parseInt(now),
endTimestamp: parseInt(remaining),
largeImageKey: mediaInfoModule.mediaInfo.image,
largeImageText: (mediaInfoModule.mediaInfo.album) ? mediaInfoModule.mediaInfo.album : `${idleStatus.largeImageText}`,
buttons: [{ label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url }],
},
});
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/mediaInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const statuses = require("./../constants/statuses");
const mediaInfo = {
title: "",
artist: "",
album: "",
icon: "",
status: statuses.paused,
url: "",
Expand All @@ -20,6 +21,7 @@ const mediaInfoModule = {
mediaInfoModule.update = function (arg) {
mediaInfo.title = propOrDefault(arg.title);
mediaInfo.artist = propOrDefault(arg.message);
mediaInfo.album = propOrDefault(arg.album);
mediaInfo.icon = propOrDefault(arg.icon);
mediaInfo.url = propOrDefault(arg.url);
mediaInfo.status = propOrDefault(arg.status);
Expand Down