mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-25 06:43:48 +01:00
feat: added first typescript support
Didn't add many types yet. Just used to test out typescript compiler, copying files and building. Now that all that seems to go well I can start converting all files to .ts and then adding proper typing everywhere
This commit is contained in:
parent
68f0c89ec2
commit
412f1ae3e3
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"
|
||||||
|
]
|
||||||
|
}
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ build/linux/arch/*
|
|||||||
|
|
||||||
# JetBrains IDE configuration
|
# JetBrains IDE configuration
|
||||||
.idea
|
.idea
|
||||||
|
ts-dist/**
|
||||||
|
3400
package-lock.json
generated
3400
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -2,9 +2,13 @@
|
|||||||
"name": "tidal-hifi",
|
"name": "tidal-hifi",
|
||||||
"version": "5.1.0",
|
"version": "5.1.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\"",
|
||||||
|
"sass-and-copy": "npm run sass && npm run copy-files",
|
||||||
|
"copy-files": "rsync -av --exclude '*.ts' --exclude '*.scss' ./src/pages ts-dist",
|
||||||
"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,8 +18,7 @@
|
|||||||
"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",
|
||||||
"style-lint": "npx stylelint **/*.scss",
|
"style-lint": "npx stylelint **/*.scss",
|
||||||
@ -42,8 +45,11 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@mastermindzh/prettier-config": "^1.0.0",
|
"@mastermindzh/prettier-config": "^1.0.0",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.59.1",
|
||||||
|
"@typescript-eslint/parser": "^5.59.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.8",
|
||||||
@ -51,6 +57,8 @@
|
|||||||
"stylelint-config-standard": "^33.0.0",
|
"stylelint-config-standard": "^33.0.0",
|
||||||
"stylelint-config-standard-scss": "^9.0.0",
|
"stylelint-config-standard-scss": "^9.0.0",
|
||||||
"stylelint-prettier": "^3.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,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",
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
require("@electron/remote/main").initialize();
|
import { initialize, enable } from "@electron/remote/main";
|
||||||
const {
|
import {
|
||||||
app,
|
app,
|
||||||
BrowserWindow,
|
BrowserWindow,
|
||||||
components,
|
components,
|
||||||
@ -7,38 +7,40 @@ const {
|
|||||||
ipcMain,
|
ipcMain,
|
||||||
protocol,
|
protocol,
|
||||||
session,
|
session,
|
||||||
} = require("electron");
|
} from "electron";
|
||||||
const {
|
import {
|
||||||
settings,
|
settings,
|
||||||
store,
|
store,
|
||||||
createSettingsWindow,
|
createSettingsWindow,
|
||||||
showSettingsWindow,
|
showSettingsWindow,
|
||||||
closeSettingsWindow,
|
closeSettingsWindow,
|
||||||
hideSettingsWindow,
|
hideSettingsWindow,
|
||||||
} = require("./scripts/settings");
|
} from "./scripts/settings";
|
||||||
const { addTray, refreshTray } = require("./scripts/tray");
|
import { addTray, refreshTray } from "./scripts/tray";
|
||||||
const { addMenu } = require("./scripts/menu");
|
import { addMenu } from "./scripts/menu";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
|
import expressModule from "./scripts/express";
|
||||||
|
import mediaKeys from "./constants/mediaKeys";
|
||||||
|
import mediaInfoModule from "./scripts/mediaInfo";
|
||||||
|
import discordModule from "./scripts/discord";
|
||||||
|
import globalEvents from "./constants/globalEvents";
|
||||||
|
import flagValues from "./constants/flags";
|
||||||
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: any;
|
||||||
|
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 flags = store.get(settings.flags.root);
|
||||||
if (flags) {
|
if (flags) {
|
||||||
for (const [key, value] of Object.entries(flags)) {
|
for (const [key, value] of Object.entries(flags)) {
|
||||||
if (value) {
|
if (value) {
|
||||||
flagValues[key].forEach((flag) => {
|
(flagValues as any)[key].forEach((flag: any) => {
|
||||||
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);
|
||||||
});
|
});
|
||||||
@ -80,7 +82,7 @@ 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,
|
||||||
@ -97,7 +99,7 @@ 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();
|
||||||
|
|
||||||
@ -109,11 +111,8 @@ function createWindow(options = {}) {
|
|||||||
mainWindow.webContents.setBackgroundThrottling(false);
|
mainWindow.webContents.setBackgroundThrottling(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run stuff after first load
|
mainWindow.on("close", function (event: any) {
|
||||||
mainWindow.webContents.once("did-finish-load", () => {});
|
if (store.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,8 +125,7 @@ function createWindow(options = {}) {
|
|||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
mainWindow.on("resize", () => {
|
mainWindow.on("resize", () => {
|
||||||
let { width, height } = mainWindow.getBounds();
|
const { width, height } = mainWindow.getBounds();
|
||||||
|
|
||||||
store.set(settings.windowBounds.root, { width, height });
|
store.set(settings.windowBounds.root, { width, height });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -144,7 +142,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]}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -169,7 +167,10 @@ app.on("ready", async () => {
|
|||||||
addMenu(mainWindow);
|
addMenu(mainWindow);
|
||||||
createSettingsWindow();
|
createSettingsWindow();
|
||||||
addGlobalShortcuts();
|
addGlobalShortcuts();
|
||||||
store.get(settings.trayIcon) && addTray(mainWindow, { icon }) && refreshTray();
|
if (store.get(settings.trayIcon)) {
|
||||||
|
addTray(mainWindow, { icon });
|
||||||
|
refreshTray();
|
||||||
|
}
|
||||||
store.get(settings.api) && expressModule.run(mainWindow);
|
store.get(settings.api) && expressModule.run(mainWindow);
|
||||||
store.get(settings.enableDiscord) && discordModule.initRPC();
|
store.get(settings.enableDiscord) && discordModule.initRPC();
|
||||||
} else {
|
} else {
|
||||||
@ -186,7 +187,7 @@ 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
|
@ -18,9 +18,9 @@ let adBlock,
|
|||||||
trayIcon,
|
trayIcon,
|
||||||
updateFrequency;
|
updateFrequency;
|
||||||
|
|
||||||
const { store, settings } = require("./../../scripts/settings");
|
const { store, settings } = require("../../scripts/settings");
|
||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer } = require("electron");
|
||||||
const globalEvents = require("./../../constants/globalEvents");
|
const globalEvents = require("../../constants/globalEvents");
|
||||||
const remote = require("@electron/remote");
|
const remote = require("@electron/remote");
|
||||||
const { app } = remote;
|
const { app } = remote;
|
||||||
/**
|
/**
|
||||||
|
@ -3,7 +3,15 @@ const { app, ipcMain } = require("electron");
|
|||||||
const globalEvents = require("../constants/globalEvents");
|
const globalEvents = require("../constants/globalEvents");
|
||||||
const clientId = "833617820704440341";
|
const clientId = "833617820704440341";
|
||||||
const mediaInfoModule = require("./mediaInfo");
|
const mediaInfoModule = require("./mediaInfo");
|
||||||
const discordModule = [];
|
const discordModule = {
|
||||||
|
rpc: {},
|
||||||
|
unRPC: function () {
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
initRPC: function () {
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
function timeToSeconds(timeArray) {
|
function timeToSeconds(timeArray) {
|
||||||
let minutes = timeArray[0] * 1;
|
let minutes = timeArray[0] * 1;
|
||||||
|
@ -13,12 +13,7 @@ const mediaInfo = {
|
|||||||
};
|
};
|
||||||
const mediaInfoModule = {
|
const mediaInfoModule = {
|
||||||
mediaInfo,
|
mediaInfo,
|
||||||
};
|
update: function (arg) {
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
||||||
@ -28,6 +23,7 @@ mediaInfoModule.update = function (arg) {
|
|||||||
mediaInfo.current = propOrDefault(arg.current);
|
mediaInfo.current = propOrDefault(arg.current);
|
||||||
mediaInfo.duration = propOrDefault(arg.duration);
|
mediaInfo.duration = propOrDefault(arg.duration);
|
||||||
mediaInfo.image = propOrDefault(arg.image);
|
mediaInfo.image = propOrDefault(arg.image);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"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