mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-05-14 14:53:05 +02:00
Compare commits
No commits in common. "42a70534f2f68e2c1b9fe0b8380d75ffa73920f6" and "8d44ff8afb2cfe3cc848cc94a83a42d026e2b337" have entirely different histories.
42a70534f2
...
8d44ff8afb
@ -10,10 +10,6 @@ insert_final_newline = true
|
|||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
[**.ts]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
[**.json]
|
[**.json]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
12
.eslintrc
12
.eslintrc
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"root": true,
|
|
||||||
"parser": "@typescript-eslint/parser",
|
|
||||||
"plugins": [
|
|
||||||
"@typescript-eslint"
|
|
||||||
],
|
|
||||||
"extends": [
|
|
||||||
"eslint:recommended",
|
|
||||||
"plugin:@typescript-eslint/eslint-recommended",
|
|
||||||
"plugin:@typescript-eslint/recommended"
|
|
||||||
]
|
|
||||||
}
|
|
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -5,10 +5,6 @@ on:
|
|||||||
branches-ignore:
|
branches-ignore:
|
||||||
- master
|
- master
|
||||||
- develop
|
- develop
|
||||||
pull_request:
|
|
||||||
branches-ignore:
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
jobs:
|
jobs:
|
||||||
build_on_linux:
|
build_on_linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
12
.github/workflows/release.yml
vendored
12
.github/workflows/release.yml
vendored
@ -5,10 +5,6 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- develop
|
- develop
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_on_linux:
|
build_on_linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -20,7 +16,7 @@ jobs:
|
|||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@master
|
- uses: actions/setup-node@master
|
||||||
with:
|
with:
|
||||||
node-version: 19
|
node-version: 16
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- uses: actions/upload-artifact@master
|
- uses: actions/upload-artifact@master
|
||||||
@ -29,12 +25,12 @@ jobs:
|
|||||||
path: dist/
|
path: dist/
|
||||||
|
|
||||||
build_on_mac:
|
build_on_mac:
|
||||||
runs-on: macos-latest
|
runs-on: macOS-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@master
|
- uses: actions/setup-node@master
|
||||||
with:
|
with:
|
||||||
node-version: 19
|
node-version: 16
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- uses: actions/upload-artifact@master
|
- uses: actions/upload-artifact@master
|
||||||
@ -48,7 +44,7 @@ jobs:
|
|||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@master
|
- uses: actions/setup-node@master
|
||||||
with:
|
with:
|
||||||
node-version: 19
|
node-version: 16
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- uses: actions/upload-artifact@master
|
- uses: actions/upload-artifact@master
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,6 +12,3 @@ build/linux/arch/*
|
|||||||
|
|
||||||
# JetBrains IDE configuration
|
# JetBrains IDE configuration
|
||||||
.idea
|
.idea
|
||||||
ts-dist/**
|
|
||||||
ts-dist
|
|
||||||
.sass-cache
|
|
||||||
|
Binary file not shown.
@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"plugins": [
|
|
||||||
"stylelint-prettier"
|
|
||||||
],
|
|
||||||
"extends": [
|
|
||||||
"stylelint-config-standard-scss"
|
|
||||||
],
|
|
||||||
"rules": {
|
|
||||||
"prettier/prettier": true,
|
|
||||||
"scss/at-extend-no-missing-placeholder": null,
|
|
||||||
"no-descending-specificity": null
|
|
||||||
}
|
|
||||||
}
|
|
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@ -1,13 +1,3 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": [
|
"cSpell.words": ["hifi", "rescrobbler", "widevine"]
|
||||||
"flac",
|
|
||||||
"geqnfr",
|
|
||||||
"hifi",
|
|
||||||
"playpause",
|
|
||||||
"rescrobbler",
|
|
||||||
"trackid",
|
|
||||||
"tracklist",
|
|
||||||
"widevine",
|
|
||||||
"xesam"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,6 @@ 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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## 5.2.0
|
|
||||||
|
|
||||||
- moved from Javascript to Typescript for all files
|
|
||||||
- use `npm run watch` to watch for changes & recompile typescript and sass files
|
|
||||||
|
|
||||||
## 5.1.0
|
## 5.1.0
|
||||||
|
|
||||||
### New features
|
### New features
|
||||||
|
3647
package-lock.json
generated
3647
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@ -1,14 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "tidal-hifi",
|
"name": "tidal-hifi",
|
||||||
"version": "5.2.0",
|
"version": "5.1.0",
|
||||||
"description": "Tidal on Electron with widevine(hifi) support",
|
"description": "Tidal on Electron with widevine(hifi) support",
|
||||||
"main": "ts-dist/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "electron .",
|
"start": "electron .",
|
||||||
"compile": "tsc && npm run sass-and-copy",
|
|
||||||
"watch": "tsc-watch --onSuccess \"npm run sass-and-copy\"",
|
|
||||||
"copy-files": "copyfiles -u 1 --exclude './src/**/*.ts' --exclude './src/**/*.scss' \"./src/**/*\" ts-dist",
|
|
||||||
"sass-and-copy": "npm run sass && npm run copy-files",
|
|
||||||
"build": "npm run builder -- -c ./build/electron-builder.yml",
|
"build": "npm run builder -- -c ./build/electron-builder.yml",
|
||||||
"build-deb": "npm run builder -- -c ./build/electron-builder.deb.yml",
|
"build-deb": "npm run builder -- -c ./build/electron-builder.deb.yml",
|
||||||
"build-unpacked": "npm run builder -- -c ./build/electron-builder.unpacked.yml",
|
"build-unpacked": "npm run builder -- -c ./build/electron-builder.unpacked.yml",
|
||||||
@ -18,11 +14,12 @@
|
|||||||
"build-wl": "npm run builder -- -c ./build/electron-builder.yml -wl",
|
"build-wl": "npm run builder -- -c ./build/electron-builder.yml -wl",
|
||||||
"build-mac": "npm run builder -- -c ./build/electron-builder.yml -m",
|
"build-mac": "npm run builder -- -c ./build/electron-builder.yml -m",
|
||||||
"build-base": "npm run builder -- -c ./build/electron-builder.base.yml",
|
"build-base": "npm run builder -- -c ./build/electron-builder.base.yml",
|
||||||
"prebuilder": "npm run compile",
|
"prestart": "npm run sass",
|
||||||
|
"prebuilder": "npm run sass",
|
||||||
"builder": "electron-builder --publish=never",
|
"builder": "electron-builder --publish=never",
|
||||||
"sass": "sass ./src/pages/settings/settings.scss ./src/pages/settings/settings.css",
|
"sass": "sass ./src/pages/settings/settings.scss ./src/pages/settings/settings.css",
|
||||||
"style-lint": "npx stylelint **/*.scss",
|
"sass-lint": "sass-lint -vc ./sass-lint.yml ./src/pages/settings/settings.scss",
|
||||||
"style-lint-fix": "npx stylelint --fix **/*.scss"
|
"sass-lint-fix": "sass-lint-auto-fix ./src/pages/settings/settings.scss --config-sass-lint ./sass-lint.yml"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"electron",
|
"electron",
|
||||||
@ -45,24 +42,13 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@mastermindzh/prettier-config": "^1.0.0",
|
"@mastermindzh/prettier-config": "^1.0.0",
|
||||||
"@types/discord-rpc": "^4.0.4",
|
|
||||||
"@types/express": "^4.17.17",
|
|
||||||
"@types/request": "^2.48.8",
|
|
||||||
"@typescript-eslint/eslint-plugin": "^5.59.1",
|
|
||||||
"@typescript-eslint/parser": "^5.59.1",
|
|
||||||
"copyfiles": "^2.4.1",
|
|
||||||
"electron": "git+https://github.com/castlabs/electron-releases.git#v24.1.2+wvcus",
|
"electron": "git+https://github.com/castlabs/electron-releases.git#v24.1.2+wvcus",
|
||||||
"electron-builder": "^24.2.1",
|
"electron-builder": "^24.2.1",
|
||||||
"eslint": "^8.39.0",
|
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"markdown-toc": "^1.2.0",
|
"markdown-toc": "^1.2.0",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.7",
|
||||||
"stylelint": "^15.6.0",
|
"sass-lint": "^1.13.1",
|
||||||
"stylelint-config-standard": "^33.0.0",
|
"sass-lint-auto-fix": "^0.21.2"
|
||||||
"stylelint-config-standard-scss": "^9.0.0",
|
|
||||||
"stylelint-prettier": "^3.0.0",
|
|
||||||
"tsc-watch": "^6.0.4",
|
|
||||||
"typescript": "^5.0.4"
|
|
||||||
},
|
},
|
||||||
"prettier": "@mastermindzh/prettier-config"
|
"prettier": "@mastermindzh/prettier-config"
|
||||||
}
|
}
|
21
sass-lint.yml
Normal file
21
sass-lint.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
rules:
|
||||||
|
property-sort-order:
|
||||||
|
- 1
|
||||||
|
- order: "smacss"
|
||||||
|
class-name-format:
|
||||||
|
- 1
|
||||||
|
- convention: "hyphenatedbem"
|
||||||
|
quotes:
|
||||||
|
- 1
|
||||||
|
- style: "double"
|
||||||
|
nesting-depth:
|
||||||
|
- 1
|
||||||
|
- max-depth: 3
|
||||||
|
placeholder-in-extend:
|
||||||
|
- 0
|
||||||
|
no-vendor-prefixes:
|
||||||
|
- 0
|
||||||
|
empty-line-between-blocks:
|
||||||
|
- 0
|
||||||
|
force-pseudo-nesting:
|
||||||
|
- 0
|
@ -1,4 +1,6 @@
|
|||||||
export const flags: { [key: string]: { flag: string; value?: string }[] } = {
|
const flags = {
|
||||||
gpuRasterization: [{ flag: "enable-gpu-rasterization", value: undefined }],
|
gpuRasterization: [{ flag: "enable-gpu-rasterization", value: undefined }],
|
||||||
disableHardwareMediaKeys: [{ flag: "disable-features", value: "HardwareMediaKeyHandling" }],
|
disableHardwareMediaKeys: [{ flag: "disable-features", value: "HardwareMediaKeyHandling" }],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = flags;
|
@ -1,4 +1,4 @@
|
|||||||
export const globalEvents = {
|
const globalEvents = {
|
||||||
play: "play",
|
play: "play",
|
||||||
pause: "pause",
|
pause: "pause",
|
||||||
playPause: "playPause",
|
playPause: "playPause",
|
||||||
@ -11,3 +11,5 @@ export const globalEvents = {
|
|||||||
storeChanged: "storeChanged",
|
storeChanged: "storeChanged",
|
||||||
error: "error",
|
error: "error",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = globalEvents;
|
@ -1,7 +1,9 @@
|
|||||||
import { globalEvents } from "./globalEvents";
|
const globalEvents = require("./globalEvents");
|
||||||
|
|
||||||
export const mediaKeys = {
|
const mediaKeys = {
|
||||||
MediaPlayPause: globalEvents.playPause,
|
MediaPlayPause: globalEvents.playPause,
|
||||||
MediaNextTrack: globalEvents.next,
|
MediaNextTrack: globalEvents.next,
|
||||||
MediaPreviousTrack: globalEvents.previous,
|
MediaPreviousTrack: globalEvents.previous,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = mediaKeys;
|
@ -8,7 +8,7 @@
|
|||||||
* },
|
* },
|
||||||
* windowBounds: { width: 800, height: 600 },
|
* windowBounds: { width: 800, height: 600 },
|
||||||
*/
|
*/
|
||||||
export const settings = {
|
const settings = {
|
||||||
adBlock: "adBlock",
|
adBlock: "adBlock",
|
||||||
api: "api",
|
api: "api",
|
||||||
apiSettings: {
|
apiSettings: {
|
||||||
@ -21,7 +21,6 @@ export const settings = {
|
|||||||
enableCustomHotkeys: "enableCustomHotkeys",
|
enableCustomHotkeys: "enableCustomHotkeys",
|
||||||
enableDiscord: "enableDiscord",
|
enableDiscord: "enableDiscord",
|
||||||
flags: {
|
flags: {
|
||||||
root: "flags",
|
|
||||||
disableHardwareMediaKeys: "flags.disableHardwareMediaKeys",
|
disableHardwareMediaKeys: "flags.disableHardwareMediaKeys",
|
||||||
gpuRasterization: "flags.gpuRasterization",
|
gpuRasterization: "flags.gpuRasterization",
|
||||||
},
|
},
|
||||||
@ -41,3 +40,5 @@ export const settings = {
|
|||||||
height: "windowBounds.height",
|
height: "windowBounds.height",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = settings;
|
@ -1,4 +1,4 @@
|
|||||||
export const statuses = {
|
module.exports = {
|
||||||
playing: "playing",
|
playing: "playing",
|
||||||
paused: "paused",
|
paused: "paused",
|
||||||
};
|
};
|
@ -1,3 +1,3 @@
|
|||||||
export default {
|
module.exports = {
|
||||||
name: "tidal-hifi",
|
name: "tidal-hifi",
|
||||||
};
|
};
|
1
src/declarations.d.ts
vendored
1
src/declarations.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
declare module "mpris-service";
|
|
@ -1,47 +1,44 @@
|
|||||||
import { enable, initialize } from "@electron/remote/main";
|
require("@electron/remote/main").initialize();
|
||||||
import {
|
const {
|
||||||
BrowserWindow,
|
|
||||||
app,
|
app,
|
||||||
|
BrowserWindow,
|
||||||
components,
|
components,
|
||||||
globalShortcut,
|
globalShortcut,
|
||||||
ipcMain,
|
ipcMain,
|
||||||
protocol,
|
protocol,
|
||||||
session,
|
session,
|
||||||
} from "electron";
|
} = require("electron");
|
||||||
import path from "path";
|
const {
|
||||||
import { flags } from "./constants/flags";
|
settings,
|
||||||
import { globalEvents } from "./constants/globalEvents";
|
store,
|
||||||
import { mediaKeys } from "./constants/mediaKeys";
|
|
||||||
import { initRPC, rpc, unRPC } from "./scripts/discord";
|
|
||||||
import { startExpress } from "./scripts/express";
|
|
||||||
import { updateMediaInfo } from "./scripts/mediaInfo";
|
|
||||||
import { addMenu } from "./scripts/menu";
|
|
||||||
import {
|
|
||||||
closeSettingsWindow,
|
|
||||||
createSettingsWindow,
|
createSettingsWindow,
|
||||||
hideSettingsWindow,
|
|
||||||
showSettingsWindow,
|
showSettingsWindow,
|
||||||
settingsStore,
|
closeSettingsWindow,
|
||||||
} from "./scripts/settings";
|
hideSettingsWindow,
|
||||||
import { settings } from "./constants/settings";
|
} = require("./scripts/settings");
|
||||||
import { addTray, refreshTray } from "./scripts/tray";
|
const { addTray, refreshTray } = require("./scripts/tray");
|
||||||
import { MediaInfo } from "./models/mediaInfo";
|
const { addMenu } = require("./scripts/menu");
|
||||||
|
const path = require("path");
|
||||||
const tidalUrl = "https://listen.tidal.com";
|
const tidalUrl = "https://listen.tidal.com";
|
||||||
|
const expressModule = require("./scripts/express");
|
||||||
|
const mediaKeys = require("./constants/mediaKeys");
|
||||||
|
const mediaInfoModule = require("./scripts/mediaInfo");
|
||||||
|
const discordModule = require("./scripts/discord");
|
||||||
|
const globalEvents = require("./constants/globalEvents");
|
||||||
|
const flagValues = require("./constants/flags");
|
||||||
|
|
||||||
initialize();
|
let mainWindow;
|
||||||
|
let icon = path.join(__dirname, "../assets/icon.png");
|
||||||
let mainWindow: BrowserWindow;
|
|
||||||
const icon = path.join(__dirname, "../assets/icon.png");
|
|
||||||
const PROTOCOL_PREFIX = "tidal";
|
const PROTOCOL_PREFIX = "tidal";
|
||||||
|
|
||||||
setFlags();
|
setFlags();
|
||||||
|
|
||||||
function setFlags() {
|
function setFlags() {
|
||||||
const flagsFromSettings = settingsStore.get(settings.flags.root);
|
const flags = store.get().flags;
|
||||||
if (flagsFromSettings) {
|
if (flags) {
|
||||||
for (const [key, value] of Object.entries(flags)) {
|
for (const [key, value] of Object.entries(flags)) {
|
||||||
if (value) {
|
if (value) {
|
||||||
flags[key].forEach((flag) => {
|
flagValues[key].forEach((flag) => {
|
||||||
console.log(`enabling command line switch ${flag.flag} with value ${flag.value}`);
|
console.log(`enabling command line switch ${flag.flag} with value ${flag.value}`);
|
||||||
app.commandLine.appendSwitch(flag.flag, flag.value);
|
app.commandLine.appendSwitch(flag.flag, flag.value);
|
||||||
});
|
});
|
||||||
@ -60,7 +57,7 @@ function setFlags() {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function syncMenuBarWithStore() {
|
function syncMenuBarWithStore() {
|
||||||
const fixedMenuBar = !!settingsStore.get(settings.menuBar);
|
const fixedMenuBar = store.get(settings.menuBar);
|
||||||
|
|
||||||
mainWindow.autoHideMenuBar = !fixedMenuBar;
|
mainWindow.autoHideMenuBar = !fixedMenuBar;
|
||||||
mainWindow.setMenuBarVisibility(fixedMenuBar);
|
mainWindow.setMenuBarVisibility(fixedMenuBar);
|
||||||
@ -73,7 +70,7 @@ function syncMenuBarWithStore() {
|
|||||||
* @returns true if singInstance is not requested, otherwise true/false based on whether the current window is the main window
|
* @returns true if singInstance is not requested, otherwise true/false based on whether the current window is the main window
|
||||||
*/
|
*/
|
||||||
function isMainInstanceOrMultipleInstancesAllowed() {
|
function isMainInstanceOrMultipleInstancesAllowed() {
|
||||||
if (settingsStore.get(settings.singleInstance)) {
|
if (store.get(settings.singleInstance)) {
|
||||||
const gotTheLock = app.requestSingleInstanceLock();
|
const gotTheLock = app.requestSingleInstanceLock();
|
||||||
|
|
||||||
if (!gotTheLock) {
|
if (!gotTheLock) {
|
||||||
@ -83,13 +80,13 @@ function isMainInstanceOrMultipleInstancesAllowed() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
function createWindow(options = {}) {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
x: options.x,
|
x: options.x,
|
||||||
y: options.y,
|
y: options.y,
|
||||||
width: settingsStore && settingsStore.get(settings.windowBounds.width),
|
width: store && store.get(settings.windowBounds.width),
|
||||||
height: settingsStore && settingsStore.get(settings.windowBounds.height),
|
height: store && store.get(settings.windowBounds.height),
|
||||||
icon,
|
icon,
|
||||||
backgroundColor: options.backgroundColor,
|
backgroundColor: options.backgroundColor,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
@ -100,20 +97,23 @@ function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
|||||||
devTools: true, // I like tinkering, others might too
|
devTools: true, // I like tinkering, others might too
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
enable(mainWindow.webContents);
|
require("@electron/remote/main").enable(mainWindow.webContents);
|
||||||
registerHttpProtocols();
|
registerHttpProtocols();
|
||||||
syncMenuBarWithStore();
|
syncMenuBarWithStore();
|
||||||
|
|
||||||
// load the Tidal website
|
// load the Tidal website
|
||||||
mainWindow.loadURL(tidalUrl);
|
mainWindow.loadURL(tidalUrl);
|
||||||
|
|
||||||
if (settingsStore.get(settings.disableBackgroundThrottle)) {
|
if (store.get(settings.disableBackgroundThrottle)) {
|
||||||
// prevent setInterval lag
|
// prevent setInterval lag
|
||||||
mainWindow.webContents.setBackgroundThrottling(false);
|
mainWindow.webContents.setBackgroundThrottling(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.on("close", function (event: CloseEvent) {
|
// run stuff after first load
|
||||||
if (settingsStore.get(settings.minimizeOnClose)) {
|
mainWindow.webContents.once("did-finish-load", () => {});
|
||||||
|
|
||||||
|
mainWindow.on("close", function (event) {
|
||||||
|
if (!app.isQuiting && store.get(settings.minimizeOnClose)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
refreshTray(mainWindow);
|
refreshTray(mainWindow);
|
||||||
@ -126,13 +126,14 @@ function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
|||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
mainWindow.on("resize", () => {
|
mainWindow.on("resize", () => {
|
||||||
const { width, height } = mainWindow.getBounds();
|
let { width, height } = mainWindow.getBounds();
|
||||||
settingsStore.set(settings.windowBounds.root, { width, height });
|
|
||||||
|
store.set(settings.windowBounds.root, { width, height });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerHttpProtocols() {
|
function registerHttpProtocols() {
|
||||||
protocol.registerHttpProtocol(PROTOCOL_PREFIX, (request) => {
|
protocol.registerHttpProtocol(PROTOCOL_PREFIX, (request, _callback) => {
|
||||||
mainWindow.loadURL(`${tidalUrl}/${request.url.substring(PROTOCOL_PREFIX.length + 3)}`);
|
mainWindow.loadURL(`${tidalUrl}/${request.url.substring(PROTOCOL_PREFIX.length + 3)}`);
|
||||||
});
|
});
|
||||||
if (!app.isDefaultProtocolClient(PROTOCOL_PREFIX)) {
|
if (!app.isDefaultProtocolClient(PROTOCOL_PREFIX)) {
|
||||||
@ -143,7 +144,7 @@ function registerHttpProtocols() {
|
|||||||
function addGlobalShortcuts() {
|
function addGlobalShortcuts() {
|
||||||
Object.keys(mediaKeys).forEach((key) => {
|
Object.keys(mediaKeys).forEach((key) => {
|
||||||
globalShortcut.register(`${key}`, () => {
|
globalShortcut.register(`${key}`, () => {
|
||||||
mainWindow.webContents.send("globalEvent", `${(mediaKeys as any)[key]}`);
|
mainWindow.webContents.send("globalEvent", `${mediaKeys[key]}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -156,7 +157,7 @@ app.on("ready", async () => {
|
|||||||
await components.whenReady();
|
await components.whenReady();
|
||||||
|
|
||||||
// Adblock
|
// Adblock
|
||||||
if (settingsStore.get(settings.adBlock)) {
|
if (store.get(settings.adBlock)) {
|
||||||
const filter = { urls: ["https://listen.tidal.com/*"] };
|
const filter = { urls: ["https://listen.tidal.com/*"] };
|
||||||
session.defaultSession.webRequest.onBeforeRequest(filter, (details, callback) => {
|
session.defaultSession.webRequest.onBeforeRequest(filter, (details, callback) => {
|
||||||
if (details.url.match(/\/users\/.*\d\?country/)) callback({ cancel: true });
|
if (details.url.match(/\/users\/.*\d\?country/)) callback({ cancel: true });
|
||||||
@ -168,12 +169,9 @@ app.on("ready", async () => {
|
|||||||
addMenu(mainWindow);
|
addMenu(mainWindow);
|
||||||
createSettingsWindow();
|
createSettingsWindow();
|
||||||
addGlobalShortcuts();
|
addGlobalShortcuts();
|
||||||
if (settingsStore.get(settings.trayIcon)) {
|
store.get(settings.trayIcon) && addTray(mainWindow, { icon }) && refreshTray();
|
||||||
addTray(mainWindow, { icon });
|
store.get(settings.api) && expressModule.run(mainWindow);
|
||||||
refreshTray(mainWindow);
|
store.get(settings.enableDiscord) && discordModule.initRPC();
|
||||||
}
|
|
||||||
settingsStore.get(settings.api) && startExpress(mainWindow);
|
|
||||||
settingsStore.get(settings.enableDiscord) && initRPC();
|
|
||||||
} else {
|
} else {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
@ -188,35 +186,35 @@ app.on("activate", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on("browser-window-created", (_, window) => {
|
app.on("browser-window-created", (_, window) => {
|
||||||
enable(window.webContents);
|
require("@electron/remote/main").enable(window.webContents);
|
||||||
});
|
});
|
||||||
|
|
||||||
// IPC
|
// IPC
|
||||||
ipcMain.on(globalEvents.updateInfo, (_event, arg: MediaInfo) => {
|
ipcMain.on(globalEvents.updateInfo, (_event, arg) => {
|
||||||
updateMediaInfo(arg);
|
mediaInfoModule.update(arg);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.hideSettings, () => {
|
ipcMain.on(globalEvents.hideSettings, (_event, _arg) => {
|
||||||
hideSettingsWindow();
|
hideSettingsWindow();
|
||||||
});
|
});
|
||||||
ipcMain.on(globalEvents.showSettings, () => {
|
ipcMain.on(globalEvents.showSettings, (_event, _arg) => {
|
||||||
showSettingsWindow();
|
showSettingsWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.refreshMenuBar, () => {
|
ipcMain.on(globalEvents.refreshMenuBar, (_event, _arg) => {
|
||||||
syncMenuBarWithStore();
|
syncMenuBarWithStore();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.storeChanged, () => {
|
ipcMain.on(globalEvents.storeChanged, (_event, _arg) => {
|
||||||
syncMenuBarWithStore();
|
syncMenuBarWithStore();
|
||||||
|
|
||||||
if (settingsStore.get(settings.enableDiscord) && !rpc) {
|
if (store.get(settings.enableDiscord) && !discordModule.rpc) {
|
||||||
initRPC();
|
discordModule.initRPC();
|
||||||
} else if (!settingsStore.get(settings.enableDiscord) && rpc) {
|
} else if (!store.get(settings.enableDiscord) && discordModule.rpc) {
|
||||||
unRPC();
|
discordModule.unRPC();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.error, (event) => {
|
ipcMain.on(globalEvents.error, (event, _arg) => {
|
||||||
console.log(event);
|
console.log(event);
|
||||||
});
|
});
|
@ -1,13 +0,0 @@
|
|||||||
import { MediaStatus } from "./mediaStatus";
|
|
||||||
|
|
||||||
export interface MediaInfo {
|
|
||||||
title: string;
|
|
||||||
artists: string;
|
|
||||||
album: string;
|
|
||||||
icon: string;
|
|
||||||
status: MediaStatus;
|
|
||||||
url: string;
|
|
||||||
current: string;
|
|
||||||
duration: string;
|
|
||||||
image: string;
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
export enum MediaStatus {
|
|
||||||
playing = "playing",
|
|
||||||
paused = "paused",
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
export interface Options {
|
|
||||||
title: string;
|
|
||||||
artists: string;
|
|
||||||
album: string;
|
|
||||||
status: string;
|
|
||||||
url: string;
|
|
||||||
current: string;
|
|
||||||
duration: string;
|
|
||||||
"app-name": string;
|
|
||||||
image: string;
|
|
||||||
icon: string;
|
|
||||||
}
|
|
@ -1,58 +1,58 @@
|
|||||||
import remote from "@electron/remote";
|
let adBlock,
|
||||||
import { ipcRenderer, shell } from "electron";
|
api,
|
||||||
import { globalEvents } from "../../constants/globalEvents";
|
customCSS,
|
||||||
import { settings } from "../../constants/settings";
|
disableBackgroundThrottle,
|
||||||
import { settingsStore } from "./../../scripts/settings";
|
disableHardwareMediaKeys,
|
||||||
|
enableCustomHotkeys,
|
||||||
let adBlock: HTMLInputElement,
|
enableDiscord,
|
||||||
api: HTMLInputElement,
|
gpuRasterization,
|
||||||
customCSS: HTMLInputElement,
|
menuBar,
|
||||||
disableBackgroundThrottle: HTMLInputElement,
|
minimizeOnClose,
|
||||||
disableHardwareMediaKeys: HTMLInputElement,
|
mpris,
|
||||||
enableCustomHotkeys: HTMLInputElement,
|
notifications,
|
||||||
enableDiscord: HTMLInputElement,
|
playBackControl,
|
||||||
gpuRasterization: HTMLInputElement,
|
port,
|
||||||
menuBar: HTMLInputElement,
|
singleInstance,
|
||||||
minimizeOnClose: HTMLInputElement,
|
skipArtists,
|
||||||
mpris: HTMLInputElement,
|
skippedArtists,
|
||||||
notifications: HTMLInputElement,
|
trayIcon,
|
||||||
playBackControl: HTMLInputElement,
|
updateFrequency;
|
||||||
port: HTMLInputElement,
|
|
||||||
singleInstance: HTMLInputElement,
|
|
||||||
skipArtists: HTMLInputElement,
|
|
||||||
skippedArtists: HTMLInputElement,
|
|
||||||
trayIcon: HTMLInputElement,
|
|
||||||
updateFrequency: HTMLInputElement;
|
|
||||||
|
|
||||||
|
const { store, settings } = require("./../../scripts/settings");
|
||||||
|
const { ipcRenderer } = require("electron");
|
||||||
|
const globalEvents = require("./../../constants/globalEvents");
|
||||||
|
const remote = require("@electron/remote");
|
||||||
|
const { app } = remote;
|
||||||
/**
|
/**
|
||||||
* Sync the UI forms with the current settings
|
* Sync the UI forms with the current settings
|
||||||
*/
|
*/
|
||||||
function refreshSettings() {
|
function refreshSettings() {
|
||||||
adBlock.checked = settingsStore.get(settings.adBlock);
|
adBlock.checked = store.get(settings.adBlock);
|
||||||
api.checked = settingsStore.get(settings.api);
|
api.checked = store.get(settings.api);
|
||||||
customCSS.value = settingsStore.get(settings.customCSS);
|
customCSS.value = store.get(settings.customCSS);
|
||||||
disableBackgroundThrottle.checked = settingsStore.get(settings.disableBackgroundThrottle);
|
disableBackgroundThrottle.checked = store.get("disableBackgroundThrottle");
|
||||||
disableHardwareMediaKeys.checked = settingsStore.get(settings.flags.disableHardwareMediaKeys);
|
disableHardwareMediaKeys.checked = store.get(settings.flags.disableHardwareMediaKeys);
|
||||||
enableCustomHotkeys.checked = settingsStore.get(settings.enableCustomHotkeys);
|
enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys);
|
||||||
enableDiscord.checked = settingsStore.get(settings.enableDiscord);
|
enableDiscord.checked = store.get(settings.enableDiscord);
|
||||||
gpuRasterization.checked = settingsStore.get(settings.flags.gpuRasterization);
|
gpuRasterization.checked = store.get(settings.flags.gpuRasterization);
|
||||||
menuBar.checked = settingsStore.get(settings.menuBar);
|
menuBar.checked = store.get(settings.menuBar);
|
||||||
minimizeOnClose.checked = settingsStore.get(settings.minimizeOnClose);
|
minimizeOnClose.checked = store.get(settings.minimizeOnClose);
|
||||||
mpris.checked = settingsStore.get(settings.mpris);
|
mpris.checked = store.get(settings.mpris);
|
||||||
notifications.checked = settingsStore.get(settings.notifications);
|
notifications.checked = store.get(settings.notifications);
|
||||||
playBackControl.checked = settingsStore.get(settings.playBackControl);
|
playBackControl.checked = store.get(settings.playBackControl);
|
||||||
port.value = settingsStore.get(settings.apiSettings.port);
|
port.value = store.get(settings.apiSettings.port);
|
||||||
singleInstance.checked = settingsStore.get(settings.singleInstance);
|
singleInstance.checked = store.get(settings.singleInstance);
|
||||||
skipArtists.checked = settingsStore.get(settings.skipArtists);
|
skipArtists.checked = store.get(settings.skipArtists);
|
||||||
skippedArtists.value = settingsStore.get<string, string[]>(settings.skippedArtists).join("\n");
|
skippedArtists.value = store.get(settings.skippedArtists).join("\n");
|
||||||
trayIcon.checked = settingsStore.get(settings.trayIcon);
|
trayIcon.checked = store.get(settings.trayIcon);
|
||||||
updateFrequency.value = settingsStore.get(settings.updateFrequency);
|
updateFrequency.value = store.get(settings.updateFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open an url in the default browsers
|
* Open an url in the default browsers
|
||||||
*/
|
*/
|
||||||
function openExternal(url: string) {
|
function openExternal(url) {
|
||||||
|
const { shell } = require("electron");
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,40 +67,40 @@ function hide() {
|
|||||||
* Restart tidal-hifi after changes
|
* Restart tidal-hifi after changes
|
||||||
*/
|
*/
|
||||||
function restart() {
|
function restart() {
|
||||||
remote.app.relaunch();
|
app.relaunch();
|
||||||
remote.app.exit();
|
app.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind UI components to functions after DOMContentLoaded
|
* Bind UI components to functions after DOMContentLoaded
|
||||||
*/
|
*/
|
||||||
window.addEventListener("DOMContentLoaded", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
function get(id: string): HTMLInputElement {
|
function get(id) {
|
||||||
return document.getElementById(id) as HTMLInputElement;
|
return document.getElementById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("close").addEventListener("click", hide);
|
document.getElementById("close").addEventListener("click", hide);
|
||||||
document.getElementById("restart").addEventListener("click", restart);
|
document.getElementById("restart").addEventListener("click", restart);
|
||||||
document.querySelectorAll(".external-link").forEach((elem) =>
|
document.querySelectorAll(".external-link").forEach((elem) =>
|
||||||
elem.addEventListener("click", function (event) {
|
elem.addEventListener("click", function (event) {
|
||||||
openExternal((event.target as HTMLElement).getAttribute("data-url"));
|
openExternal(event.target.getAttribute("data-url"));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
function addInputListener(source: HTMLInputElement, key: string) {
|
function addInputListener(source, key) {
|
||||||
source.addEventListener("input", () => {
|
source.addEventListener("input", function (_event, _data) {
|
||||||
if (source.value === "on") {
|
if (this.value === "on") {
|
||||||
settingsStore.set(key, source.checked);
|
store.set(key, source.checked);
|
||||||
} else {
|
} else {
|
||||||
settingsStore.set(key, source.value);
|
store.set(key, this.value);
|
||||||
}
|
}
|
||||||
ipcRenderer.send(globalEvents.storeChanged);
|
ipcRenderer.send(globalEvents.storeChanged);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTextAreaListener(source: HTMLInputElement, key: string) {
|
function addTextAreaListener(source, key) {
|
||||||
source.addEventListener("input", () => {
|
source.addEventListener("input", function (_event, _data) {
|
||||||
settingsStore.set(key, source.value.split("\n"));
|
store.set(key, source.value.split("\n"));
|
||||||
ipcRenderer.send(globalEvents.storeChanged);
|
ipcRenderer.send(globalEvents.storeChanged);
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -3,6 +3,7 @@
|
|||||||
$black: #17171a;
|
$black: #17171a;
|
||||||
$grey-333: #333;
|
$grey-333: #333;
|
||||||
$white: #f9f9f9;
|
$white: #f9f9f9;
|
||||||
|
|
||||||
$tidal-blue: #0ff;
|
$tidal-blue: #0ff;
|
||||||
$tidal-grey: #72777f;
|
$tidal-grey: #72777f;
|
||||||
$tidal-grey-darker: #404248;
|
$tidal-grey-darker: #404248;
|
||||||
@ -35,14 +36,16 @@ $tidal-grey-darkest: #242528;
|
|||||||
src: url("fonts/NotoSans-Bold.ttf") format("truetype");
|
src: url("fonts/NotoSans-Bold.ttf") format("truetype");
|
||||||
}
|
}
|
||||||
|
|
||||||
$font1: "Noto Sans", helvetica, sans-serif;
|
$font1: "Noto Sans", Helvetica, sans-serif;
|
||||||
|
|
||||||
// --- Mixins ---
|
// --- Mixins ---
|
||||||
|
|
||||||
@mixin drag($enabled: true) {
|
@mixin drag($enabled: true) {
|
||||||
@if $enabled {
|
@if $enabled {
|
||||||
-webkit-app-region: drag;
|
-webkit-app-region: drag;
|
||||||
} @else {
|
}
|
||||||
|
|
||||||
|
@else {
|
||||||
-webkit-app-region: no-drag;
|
-webkit-app-region: no-drag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +62,6 @@ html {
|
|||||||
|
|
||||||
.external-link {
|
.external-link {
|
||||||
@extend button;
|
@extend button;
|
||||||
|
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +80,6 @@ html {
|
|||||||
|
|
||||||
&__drag-area {
|
&__drag-area {
|
||||||
@include drag;
|
@include drag;
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
@ -89,7 +90,6 @@ html {
|
|||||||
&__close-button {
|
&__close-button {
|
||||||
@extend button;
|
@extend button;
|
||||||
@include drag(false);
|
@include drag(false);
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 12px;
|
top: 12px;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
@ -106,7 +106,7 @@ html {
|
|||||||
display: block;
|
display: block;
|
||||||
width: 18px;
|
width: 18px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
opacity: 0.7;
|
opacity: .7;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Settings tabs ---
|
// --- Settings tabs ---
|
||||||
@ -125,9 +125,8 @@ html {
|
|||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
& + label {
|
&+label {
|
||||||
@include drag(false);
|
@include drag(false);
|
||||||
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-right: 35px;
|
margin-right: 35px;
|
||||||
@ -139,7 +138,7 @@ html {
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:checked + label {
|
&:checked+label {
|
||||||
border-bottom: 2px solid $tidal-blue;
|
border-bottom: 2px solid $tidal-blue;
|
||||||
color: $tidal-blue;
|
color: $tidal-blue;
|
||||||
}
|
}
|
||||||
@ -157,7 +156,7 @@ html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@for $i from 1 to 6 {
|
@for $i from 1 to 6 {
|
||||||
.settings > input:nth-child(#{$i * 2 - 1}):checked ~ & > .tabs__section:nth-child(#{$i}) {
|
.settings>input:nth-child(#{$i*2-1}):checked~&>.tabs__section:nth-child(#{$i}) {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +217,7 @@ html {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
padding: 5px 0;
|
padding: 5px 0;
|
||||||
transition: 0.2s;
|
transition: .2s;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-bottom: solid 1px $grey-333;
|
border-bottom: solid 1px $grey-333;
|
||||||
outline: none;
|
outline: none;
|
||||||
@ -238,36 +237,38 @@ html {
|
|||||||
|
|
||||||
.switch {
|
.switch {
|
||||||
$this: &;
|
$this: &;
|
||||||
|
|
||||||
position: relative;
|
position: relative;
|
||||||
min-width: 50px;
|
min-width: 50px;
|
||||||
height: 28px;
|
height: 28px;
|
||||||
|
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
|
|
||||||
input {
|
input {
|
||||||
transform: scale(0);
|
transform: scale(0);
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|
||||||
&:checked + #{$this}__slider {
|
&:checked+#{$this}__slider {
|
||||||
background-color: $tidal-blue;
|
background-color: $tidal-blue;
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
transform: translateX(22px);
|
transform: translateX(22px);
|
||||||
background-color: $white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus + #{$this}__slider {
|
&:focus+#{$this}__slider {
|
||||||
box-shadow: inset 0 0 0 1px $tidal-blue;
|
box-shadow: inset 0 0 0 1px $tidal-blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__slider {
|
&__slider {
|
||||||
@extend button;
|
@extend button;
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
top: 0;
|
||||||
transition: 0.4s;
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
transition: .4s;
|
||||||
border-radius: 40px;
|
border-radius: 40px;
|
||||||
background-color: $tidal-grey-darkest;
|
background-color: $tidal-grey-darkest;
|
||||||
|
|
||||||
@ -277,7 +278,7 @@ html {
|
|||||||
left: 2px;
|
left: 2px;
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
transition: 0.4s;
|
transition: .4s;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: $white;
|
background-color: $white;
|
||||||
content: "";
|
content: "";
|
||||||
@ -293,7 +294,7 @@ html {
|
|||||||
min-height: 50px;
|
min-height: 50px;
|
||||||
max-height: 100px;
|
max-height: 100px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
transition: 0.2s;
|
transition: .2s;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-bottom: 1px solid transparent;
|
border-bottom: 1px solid transparent;
|
||||||
background: $tidal-grey-darkest;
|
background: $tidal-grey-darkest;
|
||||||
@ -344,12 +345,11 @@ html {
|
|||||||
|
|
||||||
&__button {
|
&__button {
|
||||||
@extend button;
|
@extend button;
|
||||||
|
|
||||||
display: block;
|
display: block;
|
||||||
height: 48px;
|
height: 48px;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
padding: 0 24px;
|
padding: 0 24px;
|
||||||
transition: 0.2s;
|
transition: .2s;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
background: $tidal-grey-darker;
|
background: $tidal-grey-darker;
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
import { Notification, app, dialog } from "@electron/remote";
|
const { setTitle } = require("./scripts/window-functions");
|
||||||
import { ipcRenderer } from "electron";
|
const { dialog, process, Notification } = require("@electron/remote");
|
||||||
import Player from "mpris-service";
|
const { store, settings } = require("./scripts/settings");
|
||||||
import { globalEvents } from "./constants/globalEvents";
|
const { ipcRenderer } = require("electron");
|
||||||
import { settings } from "./constants/settings";
|
const { app } = require("@electron/remote");
|
||||||
import { statuses } from "./constants/statuses";
|
const { downloadFile } = require("./scripts/download");
|
||||||
import { Options } from "./models/options";
|
const statuses = require("./constants/statuses");
|
||||||
import { downloadFile } from "./scripts/download";
|
const hotkeys = require("./scripts/hotkeys");
|
||||||
import { addHotkey } from "./scripts/hotkeys";
|
const globalEvents = require("./constants/globalEvents");
|
||||||
|
const { skipArtists, updateFrequency, customCSS } = require("./constants/settings");
|
||||||
import { settingsStore } from "./scripts/settings";
|
|
||||||
import { setTitle } from "./scripts/window-functions";
|
|
||||||
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
|
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
|
||||||
const appName = "Tidal Hifi";
|
const appName = "Tidal Hifi";
|
||||||
let currentSong = "";
|
let currentSong = "";
|
||||||
let player: Player;
|
let player;
|
||||||
let currentPlayStatus = statuses.paused;
|
let currentPlayStatus = statuses.paused;
|
||||||
|
|
||||||
const elements = {
|
const elements = {
|
||||||
@ -47,7 +45,7 @@ const elements = {
|
|||||||
* Get an element from the dom
|
* Get an element from the dom
|
||||||
* @param {*} key key in elements object to fetch
|
* @param {*} key key in elements object to fetch
|
||||||
*/
|
*/
|
||||||
get: function (key: string) {
|
get: function (key) {
|
||||||
return window.document.querySelector(this[key.toLowerCase()]);
|
return window.document.querySelector(this[key.toLowerCase()]);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ const elements = {
|
|||||||
|
|
||||||
if (footer) {
|
if (footer) {
|
||||||
const artists = footer.querySelectorAll(this.artists);
|
const artists = footer.querySelectorAll(this.artists);
|
||||||
if (artists) return Array.from(artists).map((artist) => (artist as HTMLElement).textContent);
|
if (artists) return Array.from(artists).map((artist) => artist.textContent);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
@ -86,7 +84,7 @@ const elements = {
|
|||||||
* @param {Array} artistsArray
|
* @param {Array} artistsArray
|
||||||
* @returns {String} artists
|
* @returns {String} artists
|
||||||
*/
|
*/
|
||||||
getArtistsString: function (artistsArray: string[]) {
|
getArtistsString: function (artistsArray) {
|
||||||
if (artistsArray.length > 0) return artistsArray.join(", ");
|
if (artistsArray.length > 0) return artistsArray.join(", ");
|
||||||
return "unknown artist(s)";
|
return "unknown artist(s)";
|
||||||
},
|
},
|
||||||
@ -122,7 +120,7 @@ const elements = {
|
|||||||
* Shorthand function to get the text of a dom element
|
* Shorthand function to get the text of a dom element
|
||||||
* @param {*} key key in elements object to fetch
|
* @param {*} key key in elements object to fetch
|
||||||
*/
|
*/
|
||||||
getText: function (key: string) {
|
getText: function (key) {
|
||||||
const element = this.get(key);
|
const element = this.get(key);
|
||||||
return element ? element.textContent : "";
|
return element ? element.textContent : "";
|
||||||
},
|
},
|
||||||
@ -131,7 +129,7 @@ const elements = {
|
|||||||
* Shorthand function to click a dom element
|
* Shorthand function to click a dom element
|
||||||
* @param {*} key key in elements object to fetch
|
* @param {*} key key in elements object to fetch
|
||||||
*/
|
*/
|
||||||
click: function (key: string) {
|
click: function (key) {
|
||||||
this.get(key).click();
|
this.get(key).click();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@ -140,7 +138,7 @@ const elements = {
|
|||||||
* Shorthand function to focus a dom element
|
* Shorthand function to focus a dom element
|
||||||
* @param {*} key key in elements object to fetch
|
* @param {*} key key in elements object to fetch
|
||||||
*/
|
*/
|
||||||
focus: function (key: string) {
|
focus: function (key) {
|
||||||
return this.get(key).focus();
|
return this.get(key).focus();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -148,7 +146,7 @@ const elements = {
|
|||||||
function addCustomCss() {
|
function addCustomCss() {
|
||||||
window.addEventListener("DOMContentLoaded", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
const style = document.createElement("style");
|
const style = document.createElement("style");
|
||||||
style.innerHTML = settingsStore.get(settings.customCSS);
|
style.innerHTML = store.get(customCSS);
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -158,7 +156,7 @@ function addCustomCss() {
|
|||||||
* make sure it returns a number, if not use the default
|
* make sure it returns a number, if not use the default
|
||||||
*/
|
*/
|
||||||
function getUpdateFrequency() {
|
function getUpdateFrequency() {
|
||||||
const storeValue = settingsStore.get(settings.updateFrequency) as number;
|
const storeValue = store.get(updateFrequency);
|
||||||
const defaultValue = 500;
|
const defaultValue = 500;
|
||||||
|
|
||||||
if (!isNaN(storeValue)) {
|
if (!isNaN(storeValue)) {
|
||||||
@ -187,41 +185,41 @@ function playPause() {
|
|||||||
* https://defkey.com/tidal-desktop-shortcuts
|
* https://defkey.com/tidal-desktop-shortcuts
|
||||||
*/
|
*/
|
||||||
function addHotKeys() {
|
function addHotKeys() {
|
||||||
if (settingsStore.get(settings.enableCustomHotkeys)) {
|
if (store.get(settings.enableCustomHotkeys)) {
|
||||||
addHotkey("Control+p", function () {
|
hotkeys.add("Control+p", function () {
|
||||||
elements.click("account").click("settings");
|
elements.click("account").click("settings");
|
||||||
});
|
});
|
||||||
addHotkey("Control+l", function () {
|
hotkeys.add("Control+l", function () {
|
||||||
handleLogout();
|
handleLogout();
|
||||||
});
|
});
|
||||||
|
|
||||||
addHotkey("Control+h", function () {
|
hotkeys.add("Control+h", function () {
|
||||||
elements.click("home");
|
elements.click("home");
|
||||||
});
|
});
|
||||||
|
|
||||||
addHotkey("backspace", function () {
|
hotkeys.add("backspace", function () {
|
||||||
elements.click("back");
|
elements.click("back");
|
||||||
});
|
});
|
||||||
|
|
||||||
addHotkey("shift+backspace", function () {
|
hotkeys.add("shift+backspace", function () {
|
||||||
elements.click("forward");
|
elements.click("forward");
|
||||||
});
|
});
|
||||||
|
|
||||||
addHotkey("control+u", function () {
|
hotkeys.add("control+u", function () {
|
||||||
// reloading window without cache should show the update bar if applicable
|
// reloading window without cache should show the update bar if applicable
|
||||||
window.location.reload();
|
window.location.reload(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
addHotkey("control+r", function () {
|
hotkeys.add("control+r", function () {
|
||||||
elements.click("repeat");
|
elements.click("repeat");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// always add the hotkey for the settings window
|
// always add the hotkey for the settings window
|
||||||
addHotkey("control+=", function () {
|
hotkeys.add("control+=", function () {
|
||||||
ipcRenderer.send(globalEvents.showSettings);
|
ipcRenderer.send(globalEvents.showSettings);
|
||||||
});
|
});
|
||||||
addHotkey("control+0", function () {
|
hotkeys.add("control+0", function () {
|
||||||
ipcRenderer.send(globalEvents.showSettings);
|
ipcRenderer.send(globalEvents.showSettings);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -233,26 +231,28 @@ function addHotKeys() {
|
|||||||
function handleLogout() {
|
function handleLogout() {
|
||||||
const logoutOptions = ["Cancel", "Yes, please", "No, thanks"];
|
const logoutOptions = ["Cancel", "Yes, please", "No, thanks"];
|
||||||
|
|
||||||
dialog
|
dialog.showMessageBox(
|
||||||
.showMessageBox(null, {
|
null,
|
||||||
|
{
|
||||||
type: "question",
|
type: "question",
|
||||||
title: "Logging out",
|
title: "Logging out",
|
||||||
message: "Are you sure you want to log out?",
|
message: "Are you sure you want to log out?",
|
||||||
buttons: logoutOptions,
|
buttons: logoutOptions,
|
||||||
defaultId: 2,
|
defaultId: 2,
|
||||||
})
|
},
|
||||||
.then((result: { response: number }) => {
|
function (response) {
|
||||||
if (logoutOptions.indexOf("Yes, please") == result.response) {
|
if (logoutOptions.indexOf("Yes, please") == response) {
|
||||||
for (let i = 0; i < window.localStorage.length; i++) {
|
for (let i = 0; i < window.localStorage.length; i++) {
|
||||||
const key = window.localStorage.key(i);
|
const key = window.localStorage.key(i);
|
||||||
if (key.startsWith("_TIDAL_activeSession")) {
|
if (key.startsWith("_TIDAL_activeSession")) {
|
||||||
window.localStorage.removeItem(key);
|
window.localStorage.removeItem(key);
|
||||||
break;
|
i = window.localStorage.length + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFullScreenListeners() {
|
function addFullScreenListeners() {
|
||||||
@ -293,7 +293,7 @@ function addIPCEventListeners() {
|
|||||||
* Update the current status of tidal (e.g playing or paused)
|
* Update the current status of tidal (e.g playing or paused)
|
||||||
*/
|
*/
|
||||||
function getCurrentlyPlayingStatus() {
|
function getCurrentlyPlayingStatus() {
|
||||||
const pause = elements.get("pause");
|
let pause = elements.get("pause");
|
||||||
let status = undefined;
|
let status = undefined;
|
||||||
|
|
||||||
// if pause button is visible tidal is playing
|
// if pause button is visible tidal is playing
|
||||||
@ -309,7 +309,7 @@ function getCurrentlyPlayingStatus() {
|
|||||||
* Convert the duration from MM:SS to seconds
|
* Convert the duration from MM:SS to seconds
|
||||||
* @param {*} duration
|
* @param {*} duration
|
||||||
*/
|
*/
|
||||||
function convertDuration(duration: string) {
|
function convertDuration(duration) {
|
||||||
const parts = duration.split(":");
|
const parts = duration.split(":");
|
||||||
return parseInt(parts[1]) + 60 * parseInt(parts[0]);
|
return parseInt(parts[1]) + 60 * parseInt(parts[0]);
|
||||||
}
|
}
|
||||||
@ -319,10 +319,10 @@ function convertDuration(duration: string) {
|
|||||||
*
|
*
|
||||||
* @param {*} options
|
* @param {*} options
|
||||||
*/
|
*/
|
||||||
function updateMediaInfo(options: Options, notify: boolean) {
|
function updateMediaInfo(options, notify) {
|
||||||
if (options) {
|
if (options) {
|
||||||
ipcRenderer.send(globalEvents.updateInfo, options);
|
ipcRenderer.send(globalEvents.updateInfo, options);
|
||||||
if (settingsStore.get(settings.notifications) && notify) {
|
if (store.get(settings.notifications) && notify) {
|
||||||
new Notification({ title: options.title, body: options.artists, icon: options.icon }).show();
|
new Notification({ title: options.title, body: options.artists, icon: options.icon }).show();
|
||||||
}
|
}
|
||||||
if (player) {
|
if (player) {
|
||||||
@ -361,7 +361,7 @@ function getTrackID() {
|
|||||||
return window.location;
|
return window.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMediaSession(options: Options) {
|
function updateMediaSession(options) {
|
||||||
if ("mediaSession" in navigator) {
|
if ("mediaSession" in navigator) {
|
||||||
navigator.mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
title: options.title,
|
title: options.title,
|
||||||
@ -401,8 +401,6 @@ setInterval(function () {
|
|||||||
current,
|
current,
|
||||||
duration,
|
duration,
|
||||||
"app-name": appName,
|
"app-name": appName,
|
||||||
image: "",
|
|
||||||
icon: "",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const titleOrArtistsChanged = currentSong !== songDashArtistTitle;
|
const titleOrArtistsChanged = currentSong !== songDashArtistTitle;
|
||||||
@ -415,7 +413,7 @@ setInterval(function () {
|
|||||||
|
|
||||||
const image = elements.getSongIcon();
|
const image = elements.getSongIcon();
|
||||||
|
|
||||||
new Promise<void>((resolve) => {
|
new Promise((resolve) => {
|
||||||
if (image.startsWith("http")) {
|
if (image.startsWith("http")) {
|
||||||
options.image = image;
|
options.image = image;
|
||||||
downloadFile(image, notificationPath).then(
|
downloadFile(image, notificationPath).then(
|
||||||
@ -432,20 +430,23 @@ setInterval(function () {
|
|||||||
// if the image can't be found on the page continue without it
|
// if the image can't be found on the page continue without it
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(
|
||||||
|
() => {
|
||||||
updateMediaInfo(options, titleOrArtistsChanged);
|
updateMediaInfo(options, titleOrArtistsChanged);
|
||||||
if (titleOrArtistsChanged) {
|
if (titleOrArtistsChanged) {
|
||||||
updateMediaSession(options);
|
updateMediaSession(options);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
() => {}
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* automatically skip a song if the artists are found in the list of artists to skip
|
* automatically skip a song if the artists are found in the list of artists to skip
|
||||||
* @param {*} artists array of artists
|
* @param {*} artists array of artists
|
||||||
*/
|
*/
|
||||||
function skipArtistsIfFoundInSkippedArtistsList(artists: string[]) {
|
function skipArtistsIfFoundInSkippedArtistsList(artists) {
|
||||||
if (settingsStore.get(settings.skipArtists)) {
|
if (store.get(skipArtists)) {
|
||||||
const skippedArtists = settingsStore.get<string, string[]>(settings.skippedArtists);
|
const skippedArtists = store.get(settings.skippedArtists);
|
||||||
if (skippedArtists.length > 0) {
|
if (skippedArtists.length > 0) {
|
||||||
const artistsToSkip = skippedArtists.map((artist) => artist);
|
const artistsToSkip = skippedArtists.map((artist) => artist);
|
||||||
const artistNames = Object.values(artists).map((artist) => artist);
|
const artistNames = Object.values(artists).map((artist) => artist);
|
||||||
@ -458,8 +459,9 @@ setInterval(function () {
|
|||||||
}
|
}
|
||||||
}, getUpdateFrequency());
|
}, getUpdateFrequency());
|
||||||
|
|
||||||
if (process.platform === "linux" && settingsStore.get(settings.mpris)) {
|
if (process.platform === "linux" && store.get(settings.mpris)) {
|
||||||
try {
|
try {
|
||||||
|
const Player = require("mpris-service");
|
||||||
player = Player({
|
player = Player({
|
||||||
name: "tidal-hifi",
|
name: "tidal-hifi",
|
||||||
identity: "tidal-hifi",
|
identity: "tidal-hifi",
|
||||||
@ -476,7 +478,7 @@ if (process.platform === "linux" && settingsStore.get(settings.mpris)) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
const events = {
|
var events = {
|
||||||
next: "next",
|
next: "next",
|
||||||
previous: "previous",
|
previous: "previous",
|
||||||
pause: "pause",
|
pause: "pause",
|
||||||
@ -486,7 +488,7 @@ if (process.platform === "linux" && settingsStore.get(settings.mpris)) {
|
|||||||
loopStatus: "repeat",
|
loopStatus: "repeat",
|
||||||
shuffle: "shuffle",
|
shuffle: "shuffle",
|
||||||
seek: "seek",
|
seek: "seek",
|
||||||
} as { [key: string]: string };
|
};
|
||||||
Object.keys(events).forEach(function (eventName) {
|
Object.keys(events).forEach(function (eventName) {
|
||||||
player.on(eventName, function () {
|
player.on(eventName, function () {
|
||||||
const eventValue = events[eventName];
|
const eventValue = events[eventName];
|
95
src/scripts/discord.js
Normal file
95
src/scripts/discord.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
const discordrpc = require("discord-rpc");
|
||||||
|
const { app, ipcMain } = require("electron");
|
||||||
|
const globalEvents = require("../constants/globalEvents");
|
||||||
|
const clientId = "833617820704440341";
|
||||||
|
const mediaInfoModule = require("./mediaInfo");
|
||||||
|
const discordModule = [];
|
||||||
|
|
||||||
|
function timeToSeconds(timeArray) {
|
||||||
|
let minutes = timeArray[0] * 1;
|
||||||
|
let seconds = minutes * 60 + timeArray[1] * 1;
|
||||||
|
return seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
let rpc;
|
||||||
|
const observer = (event, arg) => {
|
||||||
|
if (mediaInfoModule.mediaInfo.status == "paused" && rpc) {
|
||||||
|
rpc.setActivity(idleStatus);
|
||||||
|
} else if (rpc) {
|
||||||
|
const currentSeconds = timeToSeconds(mediaInfoModule.mediaInfo.current.split(":"));
|
||||||
|
const durationSeconds = timeToSeconds(mediaInfoModule.mediaInfo.duration.split(":"));
|
||||||
|
const date = new Date();
|
||||||
|
const now = (date.getTime() / 1000) | 0;
|
||||||
|
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
|
||||||
|
if (mediaInfoModule.mediaInfo.url) {
|
||||||
|
rpc.setActivity({
|
||||||
|
...idleStatus,
|
||||||
|
...{
|
||||||
|
details: `Listening to ${mediaInfoModule.mediaInfo.title}`,
|
||||||
|
state: mediaInfoModule.mediaInfo.artists
|
||||||
|
? mediaInfoModule.mediaInfo.artists
|
||||||
|
: "unknown artist(s)",
|
||||||
|
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 }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
rpc.setActivity({
|
||||||
|
...idleStatus,
|
||||||
|
...{
|
||||||
|
details: `Watching ${mediaInfoModule.mediaInfo.title}`,
|
||||||
|
state: mediaInfoModule.mediaInfo.artists,
|
||||||
|
startTimestamp: parseInt(now),
|
||||||
|
endTimestamp: parseInt(remaining),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const idleStatus = {
|
||||||
|
details: `Browsing Tidal`,
|
||||||
|
largeImageKey: "tidal-hifi-icon",
|
||||||
|
largeImageText: `Tidal HiFi ${app.getVersion()}`,
|
||||||
|
instance: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the discord rpc and listen on globalEvents.updateInfo
|
||||||
|
*/
|
||||||
|
discordModule.initRPC = function () {
|
||||||
|
rpc = new discordrpc.Client({ transport: "ipc" });
|
||||||
|
rpc.login({ clientId }).then(
|
||||||
|
() => {
|
||||||
|
discordModule.rpc = rpc;
|
||||||
|
|
||||||
|
rpc.on("ready", () => {
|
||||||
|
rpc.setActivity(idleStatus);
|
||||||
|
});
|
||||||
|
ipcMain.on(globalEvents.updateInfo, observer);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
console.error("Can't connect to Discord, is it running?");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove any RPC connection with discord and remove the event listener on globalEvents.updateInfo
|
||||||
|
*/
|
||||||
|
discordModule.unRPC = function () {
|
||||||
|
if (rpc) {
|
||||||
|
rpc.clearActivity();
|
||||||
|
rpc.destroy();
|
||||||
|
rpc = false;
|
||||||
|
discordModule.rpc = undefined;
|
||||||
|
ipcMain.removeListener(globalEvents.updateInfo, observer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = discordModule;
|
@ -1,88 +0,0 @@
|
|||||||
import { Client } from "discord-rpc";
|
|
||||||
import { app, ipcMain } from "electron";
|
|
||||||
import { globalEvents } from "../constants/globalEvents";
|
|
||||||
import { MediaStatus } from "../models/mediaStatus";
|
|
||||||
import { mediaInfo } from "./mediaInfo";
|
|
||||||
|
|
||||||
const clientId = "833617820704440341";
|
|
||||||
|
|
||||||
function timeToSeconds(timeArray: string[]) {
|
|
||||||
const minutes = parseInt(timeArray[0]) * 1;
|
|
||||||
const seconds = minutes * 60 + parseInt(timeArray[1]) * 1;
|
|
||||||
return seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
export let rpc: Client;
|
|
||||||
|
|
||||||
const observer = () => {
|
|
||||||
if (mediaInfo.status == MediaStatus.paused && rpc) {
|
|
||||||
rpc.setActivity(idleStatus);
|
|
||||||
} else if (rpc) {
|
|
||||||
const currentSeconds = timeToSeconds(mediaInfo.current.split(":"));
|
|
||||||
const durationSeconds = timeToSeconds(mediaInfo.duration.split(":"));
|
|
||||||
const date = new Date();
|
|
||||||
const now = (date.getTime() / 1000) | 0;
|
|
||||||
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
|
|
||||||
if (mediaInfo.url) {
|
|
||||||
rpc.setActivity({
|
|
||||||
...idleStatus,
|
|
||||||
...{
|
|
||||||
details: `Listening to ${mediaInfo.title}`,
|
|
||||||
state: mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)",
|
|
||||||
startTimestamp: now,
|
|
||||||
endTimestamp: remaining,
|
|
||||||
largeImageKey: mediaInfo.image,
|
|
||||||
largeImageText: mediaInfo.album ? mediaInfo.album : `${idleStatus.largeImageText}`,
|
|
||||||
buttons: [{ label: "Play on Tidal", url: mediaInfo.url }],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
rpc.setActivity({
|
|
||||||
...idleStatus,
|
|
||||||
...{
|
|
||||||
details: `Watching ${mediaInfo.title}`,
|
|
||||||
state: mediaInfo.artists,
|
|
||||||
startTimestamp: now,
|
|
||||||
endTimestamp: remaining,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const idleStatus = {
|
|
||||||
details: `Browsing Tidal`,
|
|
||||||
largeImageKey: "tidal-hifi-icon",
|
|
||||||
largeImageText: `Tidal HiFi ${app.getVersion()}`,
|
|
||||||
instance: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up the discord rpc and listen on globalEvents.updateInfo
|
|
||||||
*/
|
|
||||||
export const initRPC = () => {
|
|
||||||
rpc = new Client({ transport: "ipc" });
|
|
||||||
rpc.login({ clientId }).then(
|
|
||||||
() => {
|
|
||||||
rpc.on("ready", () => {
|
|
||||||
rpc.setActivity(idleStatus);
|
|
||||||
});
|
|
||||||
ipcMain.on(globalEvents.updateInfo, observer);
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
console.error("Can't connect to Discord, is it running?");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove any RPC connection with discord and remove the event listener on globalEvents.updateInfo
|
|
||||||
*/
|
|
||||||
export const unRPC = () => {
|
|
||||||
if (rpc) {
|
|
||||||
rpc.clearActivity();
|
|
||||||
rpc.destroy();
|
|
||||||
rpc = null;
|
|
||||||
ipcMain.removeListener(globalEvents.updateInfo, observer);
|
|
||||||
}
|
|
||||||
};
|
|
26
src/scripts/download.js
Normal file
26
src/scripts/download.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const download = {};
|
||||||
|
const request = require("request");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* download and save a file
|
||||||
|
* @param {*} fileUrl url to download
|
||||||
|
* @param {*} targetPath path to save it at
|
||||||
|
*/
|
||||||
|
download.downloadFile = function(fileUrl, targetPath) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var req = request({
|
||||||
|
method: "GET",
|
||||||
|
uri: fileUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
var out = fs.createWriteStream(targetPath);
|
||||||
|
req.pipe(out);
|
||||||
|
|
||||||
|
req.on("end", resolve);
|
||||||
|
|
||||||
|
req.on("error", reject);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = download;
|
@ -1,23 +0,0 @@
|
|||||||
import fs from "fs";
|
|
||||||
import request from "request";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* download and save a file
|
|
||||||
* @param {string} fileUrl url to download
|
|
||||||
* @param {string} targetPath path to save it at
|
|
||||||
*/
|
|
||||||
export const downloadFile = function (fileUrl: string, targetPath: string) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const req = request({
|
|
||||||
method: "GET",
|
|
||||||
uri: fileUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
const out = fs.createWriteStream(targetPath);
|
|
||||||
req.pipe(out);
|
|
||||||
|
|
||||||
req.on("end", resolve);
|
|
||||||
|
|
||||||
req.on("error", reject);
|
|
||||||
});
|
|
||||||
};
|
|
@ -1,24 +1,23 @@
|
|||||||
import { BrowserWindow, dialog } from "electron";
|
const express = require("express");
|
||||||
import express, { Response } from "express";
|
const { mediaInfo } = require("./mediaInfo");
|
||||||
import fs from "fs";
|
const { store, settings } = require("./settings");
|
||||||
import { globalEvents } from "./../constants/globalEvents";
|
const globalEvents = require("./../constants/globalEvents");
|
||||||
import { statuses } from "./../constants/statuses";
|
const statuses = require("./../constants/statuses");
|
||||||
import { mediaInfo } from "./mediaInfo";
|
const expressModule = {};
|
||||||
import { settingsStore } from "./settings";
|
const fs = require("fs");
|
||||||
import { settings } from "../constants/settings";
|
|
||||||
|
let expressInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to enable tidal-hifi's express api
|
* Function to enable tidal-hifi's express api
|
||||||
*/
|
*/
|
||||||
|
expressModule.run = function (mainWindow) {
|
||||||
// expressModule.run = function (mainWindow)
|
|
||||||
export const startExpress = (mainWindow: BrowserWindow) => {
|
|
||||||
/**
|
/**
|
||||||
* Shorthand to handle a fire and forget global event
|
* Shorthand to handle a fire and forget global event
|
||||||
* @param {*} res
|
* @param {*} res
|
||||||
* @param {*} action
|
* @param {*} action
|
||||||
*/
|
*/
|
||||||
function handleGlobalEvent(res: Response, action: string) {
|
function handleGlobalEvent(res, action) {
|
||||||
mainWindow.webContents.send("globalEvent", action);
|
mainWindow.webContents.send("globalEvent", action);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
@ -27,7 +26,7 @@ export const startExpress = (mainWindow: BrowserWindow) => {
|
|||||||
expressApp.get("/", (req, res) => res.send("Hello World!"));
|
expressApp.get("/", (req, res) => res.send("Hello World!"));
|
||||||
expressApp.get("/current", (req, res) => res.json({ ...mediaInfo, artist: mediaInfo.artists }));
|
expressApp.get("/current", (req, res) => res.json({ ...mediaInfo, artist: mediaInfo.artists }));
|
||||||
expressApp.get("/image", (req, res) => {
|
expressApp.get("/image", (req, res) => {
|
||||||
const stream = fs.createReadStream(mediaInfo.icon);
|
var stream = fs.createReadStream(mediaInfo.icon);
|
||||||
stream.on("open", function () {
|
stream.on("open", function () {
|
||||||
res.set("Content-Type", "image/png");
|
res.set("Content-Type", "image/png");
|
||||||
stream.pipe(res);
|
stream.pipe(res);
|
||||||
@ -38,7 +37,7 @@ export const startExpress = (mainWindow: BrowserWindow) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (settingsStore.get(settings.playBackControl)) {
|
if (store.get(settings.playBackControl)) {
|
||||||
expressApp.get("/play", (req, res) => handleGlobalEvent(res, globalEvents.play));
|
expressApp.get("/play", (req, res) => handleGlobalEvent(res, globalEvents.play));
|
||||||
expressApp.get("/pause", (req, res) => handleGlobalEvent(res, globalEvents.pause));
|
expressApp.get("/pause", (req, res) => handleGlobalEvent(res, globalEvents.pause));
|
||||||
expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next));
|
expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next));
|
||||||
@ -51,16 +50,21 @@ export const startExpress = (mainWindow: BrowserWindow) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (store.get(settings.api)) {
|
||||||
|
let port = store.get(settings.apiSettings.port);
|
||||||
|
|
||||||
const port = settingsStore.get<string, number>(settings.apiSettings.port);
|
expressInstance = expressApp.listen(port, "127.0.0.1", () => {});
|
||||||
|
expressInstance.on("error", function (e) {
|
||||||
const expressInstance = expressApp.listen(port, "127.0.0.1");
|
|
||||||
expressInstance.on("error", function (e: { code: string }) {
|
|
||||||
let message = e.code;
|
let message = e.code;
|
||||||
if (e.code === "EADDRINUSE") {
|
if (e.code === "EADDRINUSE") {
|
||||||
message = `Port ${port} in use.`;
|
message = `Port ${port} in use.`;
|
||||||
}
|
}
|
||||||
|
const { dialog } = require("electron");
|
||||||
dialog.showErrorBox("Api failed to start.", message);
|
dialog.showErrorBox("Api failed to start.", message);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
expressInstance = undefined;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = expressModule;
|
11
src/scripts/hotkeys.js
Normal file
11
src/scripts/hotkeys.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const hotkeyjs = require("hotkeys-js");
|
||||||
|
const hotkeys = {};
|
||||||
|
|
||||||
|
hotkeys.add = function(keys, func) {
|
||||||
|
hotkeyjs(keys, function(event, args) {
|
||||||
|
event.preventDefault();
|
||||||
|
func(event, args);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = hotkeys;
|
@ -1,11 +0,0 @@
|
|||||||
import hotkeyjs, { HotkeysEvent } from "hotkeys-js";
|
|
||||||
|
|
||||||
export const addHotkey = function (
|
|
||||||
keys: string,
|
|
||||||
func: (event?: KeyboardEvent, args?: HotkeysEvent) => void
|
|
||||||
) {
|
|
||||||
hotkeyjs(keys, function (event, args) {
|
|
||||||
event.preventDefault();
|
|
||||||
func(event, args);
|
|
||||||
});
|
|
||||||
};
|
|
@ -1,7 +1,6 @@
|
|||||||
import { MediaInfo } from "../models/mediaInfo";
|
const statuses = require("./../constants/statuses");
|
||||||
import { statuses } from "./../constants/statuses";
|
|
||||||
|
|
||||||
export const mediaInfo = {
|
const mediaInfo = {
|
||||||
title: "",
|
title: "",
|
||||||
artists: "",
|
artists: "",
|
||||||
album: "",
|
album: "",
|
||||||
@ -12,8 +11,14 @@ export const mediaInfo = {
|
|||||||
duration: "",
|
duration: "",
|
||||||
image: "tidal-hifi-icon",
|
image: "tidal-hifi-icon",
|
||||||
};
|
};
|
||||||
|
const mediaInfoModule = {
|
||||||
|
mediaInfo,
|
||||||
|
};
|
||||||
|
|
||||||
export const updateMediaInfo = (arg: MediaInfo) => {
|
/**
|
||||||
|
* Update artist and song info in the mediaInfo constant
|
||||||
|
*/
|
||||||
|
mediaInfoModule.update = function (arg) {
|
||||||
mediaInfo.title = propOrDefault(arg.title);
|
mediaInfo.title = propOrDefault(arg.title);
|
||||||
mediaInfo.artists = propOrDefault(arg.artists);
|
mediaInfo.artists = propOrDefault(arg.artists);
|
||||||
mediaInfo.album = propOrDefault(arg.album);
|
mediaInfo.album = propOrDefault(arg.album);
|
||||||
@ -30,6 +35,8 @@ export const updateMediaInfo = (arg: MediaInfo) => {
|
|||||||
* @param {*} prop property to check
|
* @param {*} prop property to check
|
||||||
* @param {*} defaultValue defaults to ""
|
* @param {*} defaultValue defaults to ""
|
||||||
*/
|
*/
|
||||||
function propOrDefault(prop: string, defaultValue = "") {
|
function propOrDefault(prop, defaultValue = "") {
|
||||||
return prop ? prop : defaultValue;
|
return prop ? prop : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = mediaInfoModule;
|
@ -1,7 +1,7 @@
|
|||||||
import { BrowserWindow, Menu, app } from "electron";
|
const { Menu, app } = require("electron");
|
||||||
import { showSettingsWindow } from "./settings";
|
const { showSettingsWindow } = require("./settings");
|
||||||
const isMac = process.platform === "darwin";
|
const isMac = process.platform === "darwin";
|
||||||
import name from "./../constants/values";
|
const { name } = require("./../constants/values");
|
||||||
|
|
||||||
const settingsMenuEntry = {
|
const settingsMenuEntry = {
|
||||||
label: "Settings",
|
label: "Settings",
|
||||||
@ -19,7 +19,9 @@ const quitMenuEntry = {
|
|||||||
accelerator: "Control+Q",
|
accelerator: "Control+Q",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMenu = function (mainWindow: BrowserWindow) {
|
const menuModule = {};
|
||||||
|
|
||||||
|
menuModule.getMenu = function (mainWindow) {
|
||||||
const toggleWindow = {
|
const toggleWindow = {
|
||||||
label: "Toggle Window",
|
label: "Toggle Window",
|
||||||
click: function () {
|
click: function () {
|
||||||
@ -111,9 +113,11 @@ export const getMenu = function (mainWindow: BrowserWindow) {
|
|||||||
quitMenuEntry,
|
quitMenuEntry,
|
||||||
];
|
];
|
||||||
|
|
||||||
return Menu.buildFromTemplate(mainMenu as any);
|
return Menu.buildFromTemplate(mainMenu);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addMenu = function (mainWindow: BrowserWindow) {
|
menuModule.addMenu = function (mainWindow) {
|
||||||
Menu.setApplicationMenu(getMenu(mainWindow));
|
Menu.setApplicationMenu(menuModule.getMenu(mainWindow));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = menuModule;
|
@ -1,12 +1,11 @@
|
|||||||
import Store from "electron-store";
|
const Store = require("electron-store");
|
||||||
|
const settings = require("./../constants/settings");
|
||||||
|
const path = require("path");
|
||||||
|
const { BrowserWindow } = require("electron");
|
||||||
|
|
||||||
import { settings } from "../constants/settings";
|
let settingsWindow;
|
||||||
import path from "path";
|
|
||||||
import { BrowserWindow } from "electron";
|
|
||||||
|
|
||||||
let settingsWindow: BrowserWindow;
|
const store = new Store({
|
||||||
|
|
||||||
export const settingsStore = new Store({
|
|
||||||
defaults: {
|
defaults: {
|
||||||
adBlock: false,
|
adBlock: false,
|
||||||
api: true,
|
api: true,
|
||||||
@ -46,11 +45,12 @@ export const settingsStore = new Store({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const settingsModule = {
|
const settingsModule = {
|
||||||
// settings,
|
store,
|
||||||
|
settings,
|
||||||
settingsWindow,
|
settingsWindow,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createSettingsWindow = function () {
|
settingsModule.createSettingsWindow = function () {
|
||||||
settingsWindow = new BrowserWindow({
|
settingsWindow = new BrowserWindow({
|
||||||
width: 700,
|
width: 700,
|
||||||
height: 600,
|
height: 600,
|
||||||
@ -66,7 +66,7 @@ export const createSettingsWindow = function () {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
settingsWindow.on("close", (event: Event) => {
|
settingsWindow.on("close", (event) => {
|
||||||
if (settingsWindow != null) {
|
if (settingsWindow != null) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
settingsWindow.hide();
|
settingsWindow.hide();
|
||||||
@ -78,17 +78,19 @@ export const createSettingsWindow = function () {
|
|||||||
settingsModule.settingsWindow = settingsWindow;
|
settingsModule.settingsWindow = settingsWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const showSettingsWindow = function (tab = "general") {
|
settingsModule.showSettingsWindow = function (tab = "general") {
|
||||||
settingsWindow.webContents.send("goToTab", tab);
|
settingsWindow.webContents.send("goToTab", tab);
|
||||||
|
|
||||||
// refresh data just before showing the window
|
// refresh data just before showing the window
|
||||||
settingsWindow.webContents.send("refreshData");
|
settingsWindow.webContents.send("refreshData");
|
||||||
settingsWindow.show();
|
settingsWindow.show();
|
||||||
};
|
};
|
||||||
export const hideSettingsWindow = function () {
|
settingsModule.hideSettingsWindow = function () {
|
||||||
settingsWindow.hide();
|
settingsWindow.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const closeSettingsWindow = function () {
|
settingsModule.closeSettingsWindow = function () {
|
||||||
settingsWindow = null;
|
settingsWindow = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = settingsModule;
|
@ -1,9 +1,9 @@
|
|||||||
import { BrowserWindow, Tray } from "electron";
|
const { Tray } = require("electron");
|
||||||
import { getMenu } from "./menu";
|
const { getMenu } = require("./menu");
|
||||||
|
const trayModule = {};
|
||||||
|
let tray;
|
||||||
|
|
||||||
let tray: Tray;
|
trayModule.addTray = function (mainWindow, options = { icon: "" }) {
|
||||||
|
|
||||||
export const addTray = function (mainWindow: BrowserWindow, options = { icon: "" }) {
|
|
||||||
tray = new Tray(options.icon);
|
tray = new Tray(options.icon);
|
||||||
tray.setIgnoreDoubleClickEvents(true);
|
tray.setIgnoreDoubleClickEvents(true);
|
||||||
tray.setToolTip("Tidal-hifi");
|
tray.setToolTip("Tidal-hifi");
|
||||||
@ -25,8 +25,10 @@ export const addTray = function (mainWindow: BrowserWindow, options = { icon: ""
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const refreshTray = function (mainWindow: BrowserWindow) {
|
trayModule.refreshTray = function (mainWindow) {
|
||||||
if (!tray) {
|
if (!tray) {
|
||||||
addTray(mainWindow);
|
trayModule.addTray(mainWindow);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = trayModule;
|
11
src/scripts/window-functions.js
Normal file
11
src/scripts/window-functions.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const windowFunctions = {};
|
||||||
|
|
||||||
|
windowFunctions.setTitle = function(title) {
|
||||||
|
window.document.title = title;
|
||||||
|
};
|
||||||
|
|
||||||
|
windowFunctions.getTitle = function() {
|
||||||
|
return window.document.title;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = windowFunctions;
|
@ -1,7 +0,0 @@
|
|||||||
export const setTitle = function (title: string) {
|
|
||||||
window.document.title = title;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getTitle = function () {
|
|
||||||
return window.document.title;
|
|
||||||
};
|
|
60
src/types/mpris-service.d.ts
vendored
60
src/types/mpris-service.d.ts
vendored
@ -1,60 +0,0 @@
|
|||||||
declare class InitOptions {
|
|
||||||
name: string;
|
|
||||||
identity: string;
|
|
||||||
supportedUriSchemes: string[];
|
|
||||||
supportedMimeTypes: string[];
|
|
||||||
supportedInterfaces: string[];
|
|
||||||
desktopEntry: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class Player {
|
|
||||||
metadata: {
|
|
||||||
"xesam:title": string;
|
|
||||||
"xesam:artist": string[];
|
|
||||||
"xesam:album": string;
|
|
||||||
"mpris:artUrl": string;
|
|
||||||
"mpris:length": number;
|
|
||||||
"mpris:trackid": string;
|
|
||||||
// other options
|
|
||||||
[key: string]: string | number | string[] | object;
|
|
||||||
};
|
|
||||||
playbackStatus: string;
|
|
||||||
identity: string;
|
|
||||||
fullscreen: boolean;
|
|
||||||
supportedUriSchemes: string[];
|
|
||||||
supportedMimeTypes: string[];
|
|
||||||
canQuit: boolean;
|
|
||||||
canRaise: boolean;
|
|
||||||
canSetFullscreen: boolean;
|
|
||||||
hasTrackList: boolean;
|
|
||||||
desktopEntry: string;
|
|
||||||
loopStatus: string;
|
|
||||||
shuffle: boolean;
|
|
||||||
volume: number;
|
|
||||||
canControl: boolean;
|
|
||||||
canPause: boolean;
|
|
||||||
canPlay: boolean;
|
|
||||||
canSeek: boolean;
|
|
||||||
canGoNext: boolean;
|
|
||||||
canGoPrevious: boolean;
|
|
||||||
rate: number;
|
|
||||||
minimumRate: number;
|
|
||||||
maximumRate: number;
|
|
||||||
playlists: string[];
|
|
||||||
activePlaylist: string;
|
|
||||||
|
|
||||||
constructor(opts: { name: string; supportedInterfaces?: string[] });
|
|
||||||
constructor(opts: InitOptions);
|
|
||||||
|
|
||||||
getPosition(): number;
|
|
||||||
seeked(): void;
|
|
||||||
getTrackIndex(trackId: number): number;
|
|
||||||
getTrack(trackId: number): string;
|
|
||||||
addTrack(track: object): void;
|
|
||||||
removeTrack(trackId: number): number;
|
|
||||||
getPlaylistIndex(playlistId: number): number;
|
|
||||||
setPlaylists(playlists: object): void;
|
|
||||||
setActivePlaylist(playlistId: number): void;
|
|
||||||
|
|
||||||
on(event: string | symbol, listener: (...args: object[]) => void): this;
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"typeRoots": ["src/types"],
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "ES6",
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"sourceMap": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"outDir": "ts-dist",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"*": ["node_modules/*"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"include": ["src/**/*"]
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user