mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-22 13:32:42 +01:00
Merge pull request #225 from Mastermindzh/feature/typescript
Feature/typescript
This commit is contained in:
commit
cc26bfa080
@ -10,6 +10,10 @@ 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
Normal file
12
.eslintrc
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"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,6 +5,10 @@ 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,6 +5,10 @@ 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
|
||||||
@ -16,7 +20,7 @@ jobs:
|
|||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@master
|
- uses: actions/setup-node@master
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 19
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- uses: actions/upload-artifact@master
|
- uses: actions/upload-artifact@master
|
||||||
@ -25,12 +29,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: 16
|
node-version: 19
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- uses: actions/upload-artifact@master
|
- uses: actions/upload-artifact@master
|
||||||
@ -44,7 +48,7 @@ jobs:
|
|||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-node@master
|
- uses: actions/setup-node@master
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 19
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- uses: actions/upload-artifact@master
|
- uses: actions/upload-artifact@master
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,3 +12,5 @@ build/linux/arch/*
|
|||||||
|
|
||||||
# JetBrains IDE configuration
|
# JetBrains IDE configuration
|
||||||
.idea
|
.idea
|
||||||
|
ts-dist/**
|
||||||
|
ts-dist
|
||||||
|
13
.stylelintrc.json
Normal file
13
.stylelintrc.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"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,3 +1,13 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": ["hifi", "rescrobbler", "widevine"]
|
"cSpell.words": [
|
||||||
|
"flac",
|
||||||
|
"geqnfr",
|
||||||
|
"hifi",
|
||||||
|
"playpause",
|
||||||
|
"rescrobbler",
|
||||||
|
"trackid",
|
||||||
|
"tracklist",
|
||||||
|
"widevine",
|
||||||
|
"xesam"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,11 @@ 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
|
||||||
|
3669
package-lock.json
generated
3669
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@ -1,10 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "tidal-hifi",
|
"name": "tidal-hifi",
|
||||||
"version": "5.1.0",
|
"version": "5.2.0",
|
||||||
"description": "Tidal on Electron with widevine(hifi) support",
|
"description": "Tidal on Electron with widevine(hifi) support",
|
||||||
"main": "src/main.js",
|
"main": "ts-dist/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",
|
||||||
@ -14,12 +18,11 @@
|
|||||||
"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",
|
||||||
"prestart": "npm run sass",
|
"prebuilder": "npm run compile",
|
||||||
"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",
|
||||||
"sass-lint": "sass-lint -vc ./sass-lint.yml ./src/pages/settings/settings.scss",
|
"style-lint": "npx stylelint **/*.scss",
|
||||||
"sass-lint-fix": "sass-lint-auto-fix ./src/pages/settings/settings.scss --config-sass-lint ./sass-lint.yml"
|
"style-lint-fix": "npx stylelint --fix **/*.scss"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"electron",
|
"electron",
|
||||||
@ -42,13 +45,24 @@
|
|||||||
},
|
},
|
||||||
"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.7",
|
"prettier": "^2.8.8",
|
||||||
"sass-lint": "^1.13.1",
|
"stylelint": "^15.6.0",
|
||||||
"sass-lint-auto-fix": "^0.21.2"
|
"stylelint-config-standard": "^33.0.0",
|
||||||
|
"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"
|
||||||
}
|
}
|
@ -1,21 +0,0 @@
|
|||||||
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,6 +1,4 @@
|
|||||||
const flags = {
|
export const flags: { [key: string]: { flag: string; value?: string }[] } = {
|
||||||
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 @@
|
|||||||
const globalEvents = {
|
export const globalEvents = {
|
||||||
play: "play",
|
play: "play",
|
||||||
pause: "pause",
|
pause: "pause",
|
||||||
playPause: "playPause",
|
playPause: "playPause",
|
||||||
@ -11,5 +11,3 @@ const globalEvents = {
|
|||||||
storeChanged: "storeChanged",
|
storeChanged: "storeChanged",
|
||||||
error: "error",
|
error: "error",
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = globalEvents;
|
|
@ -1,9 +1,7 @@
|
|||||||
const globalEvents = require("./globalEvents");
|
import { globalEvents } from "./globalEvents";
|
||||||
|
|
||||||
const mediaKeys = {
|
export 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 },
|
||||||
*/
|
*/
|
||||||
const settings = {
|
export const settings = {
|
||||||
adBlock: "adBlock",
|
adBlock: "adBlock",
|
||||||
api: "api",
|
api: "api",
|
||||||
apiSettings: {
|
apiSettings: {
|
||||||
@ -21,6 +21,7 @@ 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",
|
||||||
},
|
},
|
||||||
@ -40,5 +41,3 @@ const settings = {
|
|||||||
height: "windowBounds.height",
|
height: "windowBounds.height",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = settings;
|
|
@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export const statuses = {
|
||||||
playing: "playing",
|
playing: "playing",
|
||||||
paused: "paused",
|
paused: "paused",
|
||||||
};
|
};
|
@ -1,3 +1,3 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
name: "tidal-hifi",
|
name: "tidal-hifi",
|
||||||
};
|
};
|
1
src/declarations.d.ts
vendored
Normal file
1
src/declarations.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare module "mpris-service";
|
@ -1,44 +1,47 @@
|
|||||||
require("@electron/remote/main").initialize();
|
import { enable, initialize } from "@electron/remote/main";
|
||||||
const {
|
import {
|
||||||
app,
|
|
||||||
BrowserWindow,
|
BrowserWindow,
|
||||||
|
app,
|
||||||
components,
|
components,
|
||||||
globalShortcut,
|
globalShortcut,
|
||||||
ipcMain,
|
ipcMain,
|
||||||
protocol,
|
protocol,
|
||||||
session,
|
session,
|
||||||
} = require("electron");
|
} from "electron";
|
||||||
const {
|
import path from "path";
|
||||||
settings,
|
import { flags } from "./constants/flags";
|
||||||
store,
|
import { globalEvents } from "./constants/globalEvents";
|
||||||
createSettingsWindow,
|
import { mediaKeys } from "./constants/mediaKeys";
|
||||||
showSettingsWindow,
|
import { initRPC, rpc, unRPC } from "./scripts/discord";
|
||||||
|
import { startExpress } from "./scripts/express";
|
||||||
|
import { updateMediaInfo } from "./scripts/mediaInfo";
|
||||||
|
import { addMenu } from "./scripts/menu";
|
||||||
|
import {
|
||||||
closeSettingsWindow,
|
closeSettingsWindow,
|
||||||
|
createSettingsWindow,
|
||||||
hideSettingsWindow,
|
hideSettingsWindow,
|
||||||
} = require("./scripts/settings");
|
showSettingsWindow,
|
||||||
const { addTray, refreshTray } = require("./scripts/tray");
|
settingsStore,
|
||||||
const { addMenu } = require("./scripts/menu");
|
} from "./scripts/settings";
|
||||||
const path = require("path");
|
import { settings } from "./constants/settings";
|
||||||
|
import { addTray, refreshTray } from "./scripts/tray";
|
||||||
|
import { MediaInfo } from "./models/mediaInfo";
|
||||||
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");
|
|
||||||
|
|
||||||
let mainWindow;
|
initialize();
|
||||||
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 flags = store.get().flags;
|
const flagsFromSettings = settingsStore.get(settings.flags.root);
|
||||||
if (flags) {
|
if (flagsFromSettings) {
|
||||||
for (const [key, value] of Object.entries(flags)) {
|
for (const [key, value] of Object.entries(flags)) {
|
||||||
if (value) {
|
if (value) {
|
||||||
flagValues[key].forEach((flag) => {
|
flags[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);
|
||||||
});
|
});
|
||||||
@ -57,7 +60,7 @@ function setFlags() {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function syncMenuBarWithStore() {
|
function syncMenuBarWithStore() {
|
||||||
const fixedMenuBar = store.get(settings.menuBar);
|
const fixedMenuBar = !!settingsStore.get(settings.menuBar);
|
||||||
|
|
||||||
mainWindow.autoHideMenuBar = !fixedMenuBar;
|
mainWindow.autoHideMenuBar = !fixedMenuBar;
|
||||||
mainWindow.setMenuBarVisibility(fixedMenuBar);
|
mainWindow.setMenuBarVisibility(fixedMenuBar);
|
||||||
@ -70,7 +73,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 (store.get(settings.singleInstance)) {
|
if (settingsStore.get(settings.singleInstance)) {
|
||||||
const gotTheLock = app.requestSingleInstanceLock();
|
const gotTheLock = app.requestSingleInstanceLock();
|
||||||
|
|
||||||
if (!gotTheLock) {
|
if (!gotTheLock) {
|
||||||
@ -80,13 +83,13 @@ function isMainInstanceOrMultipleInstancesAllowed() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWindow(options = {}) {
|
function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
||||||
// 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: store && store.get(settings.windowBounds.width),
|
width: settingsStore && settingsStore.get(settings.windowBounds.width),
|
||||||
height: store && store.get(settings.windowBounds.height),
|
height: settingsStore && settingsStore.get(settings.windowBounds.height),
|
||||||
icon,
|
icon,
|
||||||
backgroundColor: options.backgroundColor,
|
backgroundColor: options.backgroundColor,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
@ -97,23 +100,20 @@ function createWindow(options = {}) {
|
|||||||
devTools: true, // I like tinkering, others might too
|
devTools: true, // I like tinkering, others might too
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
require("@electron/remote/main").enable(mainWindow.webContents);
|
enable(mainWindow.webContents);
|
||||||
registerHttpProtocols();
|
registerHttpProtocols();
|
||||||
syncMenuBarWithStore();
|
syncMenuBarWithStore();
|
||||||
|
|
||||||
// load the Tidal website
|
// load the Tidal website
|
||||||
mainWindow.loadURL(tidalUrl);
|
mainWindow.loadURL(tidalUrl);
|
||||||
|
|
||||||
if (store.get(settings.disableBackgroundThrottle)) {
|
if (settingsStore.get(settings.disableBackgroundThrottle)) {
|
||||||
// prevent setInterval lag
|
// prevent setInterval lag
|
||||||
mainWindow.webContents.setBackgroundThrottling(false);
|
mainWindow.webContents.setBackgroundThrottling(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run stuff after first load
|
mainWindow.on("close", function (event: CloseEvent) {
|
||||||
mainWindow.webContents.once("did-finish-load", () => {});
|
if (settingsStore.get(settings.minimizeOnClose)) {
|
||||||
|
|
||||||
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,14 +126,13 @@ function createWindow(options = {}) {
|
|||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
mainWindow.on("resize", () => {
|
mainWindow.on("resize", () => {
|
||||||
let { width, height } = mainWindow.getBounds();
|
const { 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, _callback) => {
|
protocol.registerHttpProtocol(PROTOCOL_PREFIX, (request) => {
|
||||||
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)) {
|
||||||
@ -144,7 +143,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[key]}`);
|
mainWindow.webContents.send("globalEvent", `${(mediaKeys as any)[key]}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -157,7 +156,7 @@ app.on("ready", async () => {
|
|||||||
await components.whenReady();
|
await components.whenReady();
|
||||||
|
|
||||||
// Adblock
|
// Adblock
|
||||||
if (store.get(settings.adBlock)) {
|
if (settingsStore.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 });
|
||||||
@ -169,9 +168,12 @@ app.on("ready", async () => {
|
|||||||
addMenu(mainWindow);
|
addMenu(mainWindow);
|
||||||
createSettingsWindow();
|
createSettingsWindow();
|
||||||
addGlobalShortcuts();
|
addGlobalShortcuts();
|
||||||
store.get(settings.trayIcon) && addTray(mainWindow, { icon }) && refreshTray();
|
if (settingsStore.get(settings.trayIcon)) {
|
||||||
store.get(settings.api) && expressModule.run(mainWindow);
|
addTray(mainWindow, { icon });
|
||||||
store.get(settings.enableDiscord) && discordModule.initRPC();
|
refreshTray(mainWindow);
|
||||||
|
}
|
||||||
|
settingsStore.get(settings.api) && startExpress(mainWindow);
|
||||||
|
settingsStore.get(settings.enableDiscord) && initRPC();
|
||||||
} else {
|
} else {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
@ -186,35 +188,35 @@ app.on("activate", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on("browser-window-created", (_, window) => {
|
app.on("browser-window-created", (_, window) => {
|
||||||
require("@electron/remote/main").enable(window.webContents);
|
enable(window.webContents);
|
||||||
});
|
});
|
||||||
|
|
||||||
// IPC
|
// IPC
|
||||||
ipcMain.on(globalEvents.updateInfo, (_event, arg) => {
|
ipcMain.on(globalEvents.updateInfo, (_event, arg: MediaInfo) => {
|
||||||
mediaInfoModule.update(arg);
|
updateMediaInfo(arg);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.hideSettings, (_event, _arg) => {
|
ipcMain.on(globalEvents.hideSettings, () => {
|
||||||
hideSettingsWindow();
|
hideSettingsWindow();
|
||||||
});
|
});
|
||||||
ipcMain.on(globalEvents.showSettings, (_event, _arg) => {
|
ipcMain.on(globalEvents.showSettings, () => {
|
||||||
showSettingsWindow();
|
showSettingsWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.refreshMenuBar, (_event, _arg) => {
|
ipcMain.on(globalEvents.refreshMenuBar, () => {
|
||||||
syncMenuBarWithStore();
|
syncMenuBarWithStore();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.storeChanged, (_event, _arg) => {
|
ipcMain.on(globalEvents.storeChanged, () => {
|
||||||
syncMenuBarWithStore();
|
syncMenuBarWithStore();
|
||||||
|
|
||||||
if (store.get(settings.enableDiscord) && !discordModule.rpc) {
|
if (settingsStore.get(settings.enableDiscord) && !rpc) {
|
||||||
discordModule.initRPC();
|
initRPC();
|
||||||
} else if (!store.get(settings.enableDiscord) && discordModule.rpc) {
|
} else if (!settingsStore.get(settings.enableDiscord) && rpc) {
|
||||||
discordModule.unRPC();
|
unRPC();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(globalEvents.error, (event, _arg) => {
|
ipcMain.on(globalEvents.error, (event) => {
|
||||||
console.log(event);
|
console.log(event);
|
||||||
});
|
});
|
13
src/models/mediaInfo.ts
Normal file
13
src/models/mediaInfo.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
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;
|
||||||
|
}
|
4
src/models/mediaStatus.ts
Normal file
4
src/models/mediaStatus.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export enum MediaStatus {
|
||||||
|
playing = "playing",
|
||||||
|
paused = "paused",
|
||||||
|
}
|
12
src/models/options.ts
Normal file
12
src/models/options.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
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 @@
|
|||||||
let adBlock,
|
import remote from "@electron/remote";
|
||||||
api,
|
import { ipcRenderer, shell } from "electron";
|
||||||
customCSS,
|
import { globalEvents } from "../../constants/globalEvents";
|
||||||
disableBackgroundThrottle,
|
import { settings } from "../../constants/settings";
|
||||||
disableHardwareMediaKeys,
|
import { settingsStore } from "./../../scripts/settings";
|
||||||
enableCustomHotkeys,
|
|
||||||
enableDiscord,
|
let adBlock: HTMLInputElement,
|
||||||
gpuRasterization,
|
api: HTMLInputElement,
|
||||||
menuBar,
|
customCSS: HTMLInputElement,
|
||||||
minimizeOnClose,
|
disableBackgroundThrottle: HTMLInputElement,
|
||||||
mpris,
|
disableHardwareMediaKeys: HTMLInputElement,
|
||||||
notifications,
|
enableCustomHotkeys: HTMLInputElement,
|
||||||
playBackControl,
|
enableDiscord: HTMLInputElement,
|
||||||
port,
|
gpuRasterization: HTMLInputElement,
|
||||||
singleInstance,
|
menuBar: HTMLInputElement,
|
||||||
skipArtists,
|
minimizeOnClose: HTMLInputElement,
|
||||||
skippedArtists,
|
mpris: HTMLInputElement,
|
||||||
trayIcon,
|
notifications: HTMLInputElement,
|
||||||
updateFrequency;
|
playBackControl: HTMLInputElement,
|
||||||
|
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 = store.get(settings.adBlock);
|
adBlock.checked = settingsStore.get(settings.adBlock);
|
||||||
api.checked = store.get(settings.api);
|
api.checked = settingsStore.get(settings.api);
|
||||||
customCSS.value = store.get(settings.customCSS);
|
customCSS.value = settingsStore.get(settings.customCSS);
|
||||||
disableBackgroundThrottle.checked = store.get("disableBackgroundThrottle");
|
disableBackgroundThrottle.checked = settingsStore.get(settings.disableBackgroundThrottle);
|
||||||
disableHardwareMediaKeys.checked = store.get(settings.flags.disableHardwareMediaKeys);
|
disableHardwareMediaKeys.checked = settingsStore.get(settings.flags.disableHardwareMediaKeys);
|
||||||
enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys);
|
enableCustomHotkeys.checked = settingsStore.get(settings.enableCustomHotkeys);
|
||||||
enableDiscord.checked = store.get(settings.enableDiscord);
|
enableDiscord.checked = settingsStore.get(settings.enableDiscord);
|
||||||
gpuRasterization.checked = store.get(settings.flags.gpuRasterization);
|
gpuRasterization.checked = settingsStore.get(settings.flags.gpuRasterization);
|
||||||
menuBar.checked = store.get(settings.menuBar);
|
menuBar.checked = settingsStore.get(settings.menuBar);
|
||||||
minimizeOnClose.checked = store.get(settings.minimizeOnClose);
|
minimizeOnClose.checked = settingsStore.get(settings.minimizeOnClose);
|
||||||
mpris.checked = store.get(settings.mpris);
|
mpris.checked = settingsStore.get(settings.mpris);
|
||||||
notifications.checked = store.get(settings.notifications);
|
notifications.checked = settingsStore.get(settings.notifications);
|
||||||
playBackControl.checked = store.get(settings.playBackControl);
|
playBackControl.checked = settingsStore.get(settings.playBackControl);
|
||||||
port.value = store.get(settings.apiSettings.port);
|
port.value = settingsStore.get(settings.apiSettings.port);
|
||||||
singleInstance.checked = store.get(settings.singleInstance);
|
singleInstance.checked = settingsStore.get(settings.singleInstance);
|
||||||
skipArtists.checked = store.get(settings.skipArtists);
|
skipArtists.checked = settingsStore.get(settings.skipArtists);
|
||||||
skippedArtists.value = store.get(settings.skippedArtists).join("\n");
|
skippedArtists.value = settingsStore.get<string, string[]>(settings.skippedArtists).join("\n");
|
||||||
trayIcon.checked = store.get(settings.trayIcon);
|
trayIcon.checked = settingsStore.get(settings.trayIcon);
|
||||||
updateFrequency.value = store.get(settings.updateFrequency);
|
updateFrequency.value = settingsStore.get(settings.updateFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open an url in the default browsers
|
* Open an url in the default browsers
|
||||||
*/
|
*/
|
||||||
function openExternal(url) {
|
function openExternal(url: string) {
|
||||||
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() {
|
||||||
app.relaunch();
|
remote.app.relaunch();
|
||||||
app.exit();
|
remote.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) {
|
function get(id: string): HTMLInputElement {
|
||||||
return document.getElementById(id);
|
return document.getElementById(id) as HTMLInputElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
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.getAttribute("data-url"));
|
openExternal((event.target as HTMLElement).getAttribute("data-url"));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
function addInputListener(source, key) {
|
function addInputListener(source: HTMLInputElement, key: string) {
|
||||||
source.addEventListener("input", function (_event, _data) {
|
source.addEventListener("input", () => {
|
||||||
if (this.value === "on") {
|
if (source.value === "on") {
|
||||||
store.set(key, source.checked);
|
settingsStore.set(key, source.checked);
|
||||||
} else {
|
} else {
|
||||||
store.set(key, this.value);
|
settingsStore.set(key, source.value);
|
||||||
}
|
}
|
||||||
ipcRenderer.send(globalEvents.storeChanged);
|
ipcRenderer.send(globalEvents.storeChanged);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTextAreaListener(source, key) {
|
function addTextAreaListener(source: HTMLInputElement, key: string) {
|
||||||
source.addEventListener("input", function (_event, _data) {
|
source.addEventListener("input", () => {
|
||||||
store.set(key, source.value.split("\n"));
|
settingsStore.set(key, source.value.split("\n"));
|
||||||
ipcRenderer.send(globalEvents.storeChanged);
|
ipcRenderer.send(globalEvents.storeChanged);
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -3,7 +3,6 @@
|
|||||||
$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;
|
||||||
@ -36,16 +35,14 @@ $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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,6 +59,7 @@ html {
|
|||||||
|
|
||||||
.external-link {
|
.external-link {
|
||||||
@extend button;
|
@extend button;
|
||||||
|
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +78,7 @@ html {
|
|||||||
|
|
||||||
&__drag-area {
|
&__drag-area {
|
||||||
@include drag;
|
@include drag;
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
@ -90,6 +89,7 @@ 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: .7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Settings tabs ---
|
// --- Settings tabs ---
|
||||||
@ -125,8 +125,9 @@ 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;
|
||||||
@ -138,7 +139,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;
|
||||||
}
|
}
|
||||||
@ -156,7 +157,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +218,7 @@ html {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
padding: 5px 0;
|
padding: 5px 0;
|
||||||
transition: .2s;
|
transition: 0.2s;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-bottom: solid 1px $grey-333;
|
border-bottom: solid 1px $grey-333;
|
||||||
outline: none;
|
outline: none;
|
||||||
@ -237,38 +238,36 @@ 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;
|
||||||
top: 0;
|
inset: 0;
|
||||||
right: 0;
|
transition: 0.4s;
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
transition: .4s;
|
|
||||||
border-radius: 40px;
|
border-radius: 40px;
|
||||||
background-color: $tidal-grey-darkest;
|
background-color: $tidal-grey-darkest;
|
||||||
|
|
||||||
@ -278,7 +277,7 @@ html {
|
|||||||
left: 2px;
|
left: 2px;
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
transition: .4s;
|
transition: 0.4s;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: $white;
|
background-color: $white;
|
||||||
content: "";
|
content: "";
|
||||||
@ -294,7 +293,7 @@ html {
|
|||||||
min-height: 50px;
|
min-height: 50px;
|
||||||
max-height: 100px;
|
max-height: 100px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
transition: .2s;
|
transition: 0.2s;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-bottom: 1px solid transparent;
|
border-bottom: 1px solid transparent;
|
||||||
background: $tidal-grey-darkest;
|
background: $tidal-grey-darkest;
|
||||||
@ -345,11 +344,12 @@ 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: .2s;
|
transition: 0.2s;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
background: $tidal-grey-darker;
|
background: $tidal-grey-darker;
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
const { setTitle } = require("./scripts/window-functions");
|
import { Notification, app, dialog } from "@electron/remote";
|
||||||
const { dialog, process, Notification } = require("@electron/remote");
|
import { ipcRenderer } from "electron";
|
||||||
const { store, settings } = require("./scripts/settings");
|
import Player from "mpris-service";
|
||||||
const { ipcRenderer } = require("electron");
|
import { globalEvents } from "./constants/globalEvents";
|
||||||
const { app } = require("@electron/remote");
|
import { settings } from "./constants/settings";
|
||||||
const { downloadFile } = require("./scripts/download");
|
import { statuses } from "./constants/statuses";
|
||||||
const statuses = require("./constants/statuses");
|
import { Options } from "./models/options";
|
||||||
const hotkeys = require("./scripts/hotkeys");
|
import { downloadFile } from "./scripts/download";
|
||||||
const globalEvents = require("./constants/globalEvents");
|
import { addHotkey } from "./scripts/hotkeys";
|
||||||
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;
|
let player: Player;
|
||||||
let currentPlayStatus = statuses.paused;
|
let currentPlayStatus = statuses.paused;
|
||||||
|
|
||||||
const elements = {
|
const elements = {
|
||||||
@ -45,7 +47,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) {
|
get: function (key: string) {
|
||||||
return window.document.querySelector(this[key.toLowerCase()]);
|
return window.document.querySelector(this[key.toLowerCase()]);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -74,7 +76,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.textContent);
|
if (artists) return Array.from(artists).map((artist) => (artist as HTMLElement).textContent);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
@ -84,7 +86,7 @@ const elements = {
|
|||||||
* @param {Array} artistsArray
|
* @param {Array} artistsArray
|
||||||
* @returns {String} artists
|
* @returns {String} artists
|
||||||
*/
|
*/
|
||||||
getArtistsString: function (artistsArray) {
|
getArtistsString: function (artistsArray: string[]) {
|
||||||
if (artistsArray.length > 0) return artistsArray.join(", ");
|
if (artistsArray.length > 0) return artistsArray.join(", ");
|
||||||
return "unknown artist(s)";
|
return "unknown artist(s)";
|
||||||
},
|
},
|
||||||
@ -120,7 +122,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) {
|
getText: function (key: string) {
|
||||||
const element = this.get(key);
|
const element = this.get(key);
|
||||||
return element ? element.textContent : "";
|
return element ? element.textContent : "";
|
||||||
},
|
},
|
||||||
@ -129,7 +131,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) {
|
click: function (key: string) {
|
||||||
this.get(key).click();
|
this.get(key).click();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@ -138,7 +140,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) {
|
focus: function (key: string) {
|
||||||
return this.get(key).focus();
|
return this.get(key).focus();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -146,7 +148,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 = store.get(customCSS);
|
style.innerHTML = settingsStore.get(settings.customCSS);
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -156,7 +158,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 = store.get(updateFrequency);
|
const storeValue = settingsStore.get(settings.updateFrequency) as number;
|
||||||
const defaultValue = 500;
|
const defaultValue = 500;
|
||||||
|
|
||||||
if (!isNaN(storeValue)) {
|
if (!isNaN(storeValue)) {
|
||||||
@ -185,41 +187,41 @@ function playPause() {
|
|||||||
* https://defkey.com/tidal-desktop-shortcuts
|
* https://defkey.com/tidal-desktop-shortcuts
|
||||||
*/
|
*/
|
||||||
function addHotKeys() {
|
function addHotKeys() {
|
||||||
if (store.get(settings.enableCustomHotkeys)) {
|
if (settingsStore.get(settings.enableCustomHotkeys)) {
|
||||||
hotkeys.add("Control+p", function () {
|
addHotkey("Control+p", function () {
|
||||||
elements.click("account").click("settings");
|
elements.click("account").click("settings");
|
||||||
});
|
});
|
||||||
hotkeys.add("Control+l", function () {
|
addHotkey("Control+l", function () {
|
||||||
handleLogout();
|
handleLogout();
|
||||||
});
|
});
|
||||||
|
|
||||||
hotkeys.add("Control+h", function () {
|
addHotkey("Control+h", function () {
|
||||||
elements.click("home");
|
elements.click("home");
|
||||||
});
|
});
|
||||||
|
|
||||||
hotkeys.add("backspace", function () {
|
addHotkey("backspace", function () {
|
||||||
elements.click("back");
|
elements.click("back");
|
||||||
});
|
});
|
||||||
|
|
||||||
hotkeys.add("shift+backspace", function () {
|
addHotkey("shift+backspace", function () {
|
||||||
elements.click("forward");
|
elements.click("forward");
|
||||||
});
|
});
|
||||||
|
|
||||||
hotkeys.add("control+u", function () {
|
addHotkey("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(true);
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
hotkeys.add("control+r", function () {
|
addHotkey("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
|
||||||
hotkeys.add("control+=", function () {
|
addHotkey("control+=", function () {
|
||||||
ipcRenderer.send(globalEvents.showSettings);
|
ipcRenderer.send(globalEvents.showSettings);
|
||||||
});
|
});
|
||||||
hotkeys.add("control+0", function () {
|
addHotkey("control+0", function () {
|
||||||
ipcRenderer.send(globalEvents.showSettings);
|
ipcRenderer.send(globalEvents.showSettings);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -231,28 +233,26 @@ function addHotKeys() {
|
|||||||
function handleLogout() {
|
function handleLogout() {
|
||||||
const logoutOptions = ["Cancel", "Yes, please", "No, thanks"];
|
const logoutOptions = ["Cancel", "Yes, please", "No, thanks"];
|
||||||
|
|
||||||
dialog.showMessageBox(
|
dialog
|
||||||
null,
|
.showMessageBox(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,
|
||||||
},
|
})
|
||||||
function (response) {
|
.then((result: { response: number }) => {
|
||||||
if (logoutOptions.indexOf("Yes, please") == response) {
|
if (logoutOptions.indexOf("Yes, please") == result.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);
|
||||||
i = window.localStorage.length + 1;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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() {
|
||||||
let pause = elements.get("pause");
|
const 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) {
|
function convertDuration(duration: string) {
|
||||||
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) {
|
|||||||
*
|
*
|
||||||
* @param {*} options
|
* @param {*} options
|
||||||
*/
|
*/
|
||||||
function updateMediaInfo(options, notify) {
|
function updateMediaInfo(options: Options, notify: boolean) {
|
||||||
if (options) {
|
if (options) {
|
||||||
ipcRenderer.send(globalEvents.updateInfo, options);
|
ipcRenderer.send(globalEvents.updateInfo, options);
|
||||||
if (store.get(settings.notifications) && notify) {
|
if (settingsStore.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) {
|
function updateMediaSession(options: 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,6 +401,8 @@ setInterval(function () {
|
|||||||
current,
|
current,
|
||||||
duration,
|
duration,
|
||||||
"app-name": appName,
|
"app-name": appName,
|
||||||
|
image: "",
|
||||||
|
icon: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const titleOrArtistsChanged = currentSong !== songDashArtistTitle;
|
const titleOrArtistsChanged = currentSong !== songDashArtistTitle;
|
||||||
@ -413,7 +415,7 @@ setInterval(function () {
|
|||||||
|
|
||||||
const image = elements.getSongIcon();
|
const image = elements.getSongIcon();
|
||||||
|
|
||||||
new Promise((resolve) => {
|
new Promise<void>((resolve) => {
|
||||||
if (image.startsWith("http")) {
|
if (image.startsWith("http")) {
|
||||||
options.image = image;
|
options.image = image;
|
||||||
downloadFile(image, notificationPath).then(
|
downloadFile(image, notificationPath).then(
|
||||||
@ -430,23 +432,20 @@ 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) {
|
function skipArtistsIfFoundInSkippedArtistsList(artists: string[]) {
|
||||||
if (store.get(skipArtists)) {
|
if (settingsStore.get(settings.skipArtists)) {
|
||||||
const skippedArtists = store.get(settings.skippedArtists);
|
const skippedArtists = settingsStore.get<string, string[]>(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);
|
||||||
@ -459,9 +458,8 @@ setInterval(function () {
|
|||||||
}
|
}
|
||||||
}, getUpdateFrequency());
|
}, getUpdateFrequency());
|
||||||
|
|
||||||
if (process.platform === "linux" && store.get(settings.mpris)) {
|
if (process.platform === "linux" && settingsStore.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",
|
||||||
@ -478,7 +476,7 @@ if (process.platform === "linux" && store.get(settings.mpris)) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
var events = {
|
const events = {
|
||||||
next: "next",
|
next: "next",
|
||||||
previous: "previous",
|
previous: "previous",
|
||||||
pause: "pause",
|
pause: "pause",
|
||||||
@ -488,7 +486,7 @@ if (process.platform === "linux" && store.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];
|
@ -1,95 +0,0 @@
|
|||||||
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;
|
|
88
src/scripts/discord.ts
Normal file
88
src/scripts/discord.ts
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
@ -1,26 +0,0 @@
|
|||||||
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;
|
|
23
src/scripts/download.ts
Normal file
23
src/scripts/download.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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,23 +1,24 @@
|
|||||||
const express = require("express");
|
import { BrowserWindow, dialog } from "electron";
|
||||||
const { mediaInfo } = require("./mediaInfo");
|
import express, { Response } from "express";
|
||||||
const { store, settings } = require("./settings");
|
import fs from "fs";
|
||||||
const globalEvents = require("./../constants/globalEvents");
|
import { globalEvents } from "./../constants/globalEvents";
|
||||||
const statuses = require("./../constants/statuses");
|
import { statuses } from "./../constants/statuses";
|
||||||
const expressModule = {};
|
import { mediaInfo } from "./mediaInfo";
|
||||||
const fs = require("fs");
|
import { settingsStore } from "./settings";
|
||||||
|
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, action) {
|
function handleGlobalEvent(res: Response, action: string) {
|
||||||
mainWindow.webContents.send("globalEvent", action);
|
mainWindow.webContents.send("globalEvent", action);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
@ -26,7 +27,7 @@ expressModule.run = function (mainWindow) {
|
|||||||
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) => {
|
||||||
var stream = fs.createReadStream(mediaInfo.icon);
|
const 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);
|
||||||
@ -37,7 +38,7 @@ expressModule.run = function (mainWindow) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (store.get(settings.playBackControl)) {
|
if (settingsStore.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));
|
||||||
@ -50,21 +51,16 @@ expressModule.run = function (mainWindow) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (store.get(settings.api)) {
|
|
||||||
let port = store.get(settings.apiSettings.port);
|
|
||||||
|
|
||||||
expressInstance = expressApp.listen(port, "127.0.0.1", () => {});
|
const port = settingsStore.get<string, number>(settings.apiSettings.port);
|
||||||
expressInstance.on("error", function (e) {
|
|
||||||
let message = e.code;
|
const expressInstance = expressApp.listen(port, "127.0.0.1");
|
||||||
if (e.code === "EADDRINUSE") {
|
expressInstance.on("error", function (e: { code: string }) {
|
||||||
message = `Port ${port} in use.`;
|
let message = e.code;
|
||||||
}
|
if (e.code === "EADDRINUSE") {
|
||||||
const { dialog } = require("electron");
|
message = `Port ${port} in use.`;
|
||||||
dialog.showErrorBox("Api failed to start.", message);
|
}
|
||||||
});
|
|
||||||
} else {
|
dialog.showErrorBox("Api failed to start.", message);
|
||||||
expressInstance = undefined;
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = expressModule;
|
|
@ -1,11 +0,0 @@
|
|||||||
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;
|
|
11
src/scripts/hotkeys.ts
Normal file
11
src/scripts/hotkeys.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
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,6 +1,7 @@
|
|||||||
const statuses = require("./../constants/statuses");
|
import { MediaInfo } from "../models/mediaInfo";
|
||||||
|
import { statuses } from "./../constants/statuses";
|
||||||
|
|
||||||
const mediaInfo = {
|
export const mediaInfo = {
|
||||||
title: "",
|
title: "",
|
||||||
artists: "",
|
artists: "",
|
||||||
album: "",
|
album: "",
|
||||||
@ -11,14 +12,8 @@ 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);
|
||||||
@ -35,8 +30,6 @@ mediaInfoModule.update = function (arg) {
|
|||||||
* @param {*} prop property to check
|
* @param {*} prop property to check
|
||||||
* @param {*} defaultValue defaults to ""
|
* @param {*} defaultValue defaults to ""
|
||||||
*/
|
*/
|
||||||
function propOrDefault(prop, defaultValue = "") {
|
function propOrDefault(prop: string, defaultValue = "") {
|
||||||
return prop ? prop : defaultValue;
|
return prop ? prop : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = mediaInfoModule;
|
|
@ -1,7 +1,7 @@
|
|||||||
const { Menu, app } = require("electron");
|
import { BrowserWindow, Menu, app } from "electron";
|
||||||
const { showSettingsWindow } = require("./settings");
|
import { showSettingsWindow } from "./settings";
|
||||||
const isMac = process.platform === "darwin";
|
const isMac = process.platform === "darwin";
|
||||||
const { name } = require("./../constants/values");
|
import name from "./../constants/values";
|
||||||
|
|
||||||
const settingsMenuEntry = {
|
const settingsMenuEntry = {
|
||||||
label: "Settings",
|
label: "Settings",
|
||||||
@ -19,9 +19,7 @@ const quitMenuEntry = {
|
|||||||
accelerator: "Control+Q",
|
accelerator: "Control+Q",
|
||||||
};
|
};
|
||||||
|
|
||||||
const menuModule = {};
|
export const getMenu = function (mainWindow: BrowserWindow) {
|
||||||
|
|
||||||
menuModule.getMenu = function (mainWindow) {
|
|
||||||
const toggleWindow = {
|
const toggleWindow = {
|
||||||
label: "Toggle Window",
|
label: "Toggle Window",
|
||||||
click: function () {
|
click: function () {
|
||||||
@ -113,11 +111,9 @@ menuModule.getMenu = function (mainWindow) {
|
|||||||
quitMenuEntry,
|
quitMenuEntry,
|
||||||
];
|
];
|
||||||
|
|
||||||
return Menu.buildFromTemplate(mainMenu);
|
return Menu.buildFromTemplate(mainMenu as any);
|
||||||
};
|
};
|
||||||
|
|
||||||
menuModule.addMenu = function (mainWindow) {
|
export const addMenu = function (mainWindow: BrowserWindow) {
|
||||||
Menu.setApplicationMenu(menuModule.getMenu(mainWindow));
|
Menu.setApplicationMenu(getMenu(mainWindow));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = menuModule;
|
|
@ -1,11 +1,12 @@
|
|||||||
const Store = require("electron-store");
|
import Store from "electron-store";
|
||||||
const settings = require("./../constants/settings");
|
|
||||||
const path = require("path");
|
|
||||||
const { BrowserWindow } = require("electron");
|
|
||||||
|
|
||||||
let settingsWindow;
|
import { settings } from "../constants/settings";
|
||||||
|
import path from "path";
|
||||||
|
import { BrowserWindow } from "electron";
|
||||||
|
|
||||||
const store = new Store({
|
let settingsWindow: BrowserWindow;
|
||||||
|
|
||||||
|
export const settingsStore = new Store({
|
||||||
defaults: {
|
defaults: {
|
||||||
adBlock: false,
|
adBlock: false,
|
||||||
api: true,
|
api: true,
|
||||||
@ -45,12 +46,11 @@ const store = new Store({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const settingsModule = {
|
const settingsModule = {
|
||||||
store,
|
// settings,
|
||||||
settings,
|
|
||||||
settingsWindow,
|
settingsWindow,
|
||||||
};
|
};
|
||||||
|
|
||||||
settingsModule.createSettingsWindow = function () {
|
export const createSettingsWindow = function () {
|
||||||
settingsWindow = new BrowserWindow({
|
settingsWindow = new BrowserWindow({
|
||||||
width: 700,
|
width: 700,
|
||||||
height: 600,
|
height: 600,
|
||||||
@ -66,7 +66,7 @@ settingsModule.createSettingsWindow = function () {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
settingsWindow.on("close", (event) => {
|
settingsWindow.on("close", (event: Event) => {
|
||||||
if (settingsWindow != null) {
|
if (settingsWindow != null) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
settingsWindow.hide();
|
settingsWindow.hide();
|
||||||
@ -78,19 +78,17 @@ settingsModule.createSettingsWindow = function () {
|
|||||||
settingsModule.settingsWindow = settingsWindow;
|
settingsModule.settingsWindow = settingsWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
settingsModule.showSettingsWindow = function (tab = "general") {
|
export const 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();
|
||||||
};
|
};
|
||||||
settingsModule.hideSettingsWindow = function () {
|
export const hideSettingsWindow = function () {
|
||||||
settingsWindow.hide();
|
settingsWindow.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
settingsModule.closeSettingsWindow = function () {
|
export const closeSettingsWindow = function () {
|
||||||
settingsWindow = null;
|
settingsWindow = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = settingsModule;
|
|
@ -1,9 +1,9 @@
|
|||||||
const { Tray } = require("electron");
|
import { BrowserWindow, Tray } from "electron";
|
||||||
const { getMenu } = require("./menu");
|
import { getMenu } from "./menu";
|
||||||
const trayModule = {};
|
|
||||||
let tray;
|
|
||||||
|
|
||||||
trayModule.addTray = function (mainWindow, options = { icon: "" }) {
|
let tray: Tray;
|
||||||
|
|
||||||
|
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,10 +25,8 @@ trayModule.addTray = function (mainWindow, options = { icon: "" }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
trayModule.refreshTray = function (mainWindow) {
|
export const refreshTray = function (mainWindow: BrowserWindow) {
|
||||||
if (!tray) {
|
if (!tray) {
|
||||||
trayModule.addTray(mainWindow);
|
addTray(mainWindow);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = trayModule;
|
|
@ -1,11 +0,0 @@
|
|||||||
const windowFunctions = {};
|
|
||||||
|
|
||||||
windowFunctions.setTitle = function(title) {
|
|
||||||
window.document.title = title;
|
|
||||||
};
|
|
||||||
|
|
||||||
windowFunctions.getTitle = function() {
|
|
||||||
return window.document.title;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = windowFunctions;
|
|
7
src/scripts/window-functions.ts
Normal file
7
src/scripts/window-functions.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
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
Normal file
60
src/types/mpris-service.d.ts
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
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;
|
||||||
|
}
|
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"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…
Reference in New Issue
Block a user