mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-08-03 11:31:20 +02:00
transitioning to ts
This commit is contained in:
@@ -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,23 @@
|
||||
const express = require("express");
|
||||
import { BrowserWindow } from "electron";
|
||||
import express, { Response } from "express";
|
||||
import fs from "fs";
|
||||
const { mediaInfo } = require("./mediaInfo");
|
||||
const { store, settings } = require("./settings");
|
||||
const globalEvents = require("./../constants/globalEvents");
|
||||
const statuses = require("./../constants/statuses");
|
||||
const expressModule = {};
|
||||
const fs = require("fs");
|
||||
|
||||
let expressInstance;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param {*} res
|
||||
* @param {*} action
|
||||
*/
|
||||
function handleGlobalEvent(res, action) {
|
||||
function handleGlobalEvent(res: Response, action: any) {
|
||||
mainWindow.webContents.send("globalEvent", action);
|
||||
res.sendStatus(200);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ expressModule.run = function (mainWindow) {
|
||||
expressApp.get("/", (req, res) => res.send("Hello World!"));
|
||||
expressApp.get("/current", (req, res) => res.json({ ...mediaInfo, artist: mediaInfo.artists }));
|
||||
expressApp.get("/image", (req, res) => {
|
||||
var stream = fs.createReadStream(mediaInfo.icon);
|
||||
const stream = fs.createReadStream(mediaInfo.icon);
|
||||
stream.on("open", function () {
|
||||
res.set("Content-Type", "image/png");
|
||||
stream.pipe(res);
|
||||
@@ -50,21 +50,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", () => {});
|
||||
expressInstance.on("error", function (e) {
|
||||
let message = e.code;
|
||||
if (e.code === "EADDRINUSE") {
|
||||
message = `Port ${port} in use.`;
|
||||
}
|
||||
const { dialog } = require("electron");
|
||||
dialog.showErrorBox("Api failed to start.", message);
|
||||
});
|
||||
} else {
|
||||
expressInstance = undefined;
|
||||
}
|
||||
let port = store.get(settings.apiSettings.port);
|
||||
|
||||
const expressInstance = expressApp.listen(port, "127.0.0.1", () => {});
|
||||
expressInstance.on("error", function (e: { code: string }) {
|
||||
let message = e.code;
|
||||
if (e.code === "EADDRINUSE") {
|
||||
message = `Port ${port} in use.`;
|
||||
}
|
||||
const { dialog } = require("electron");
|
||||
dialog.showErrorBox("Api failed to start.", message);
|
||||
});
|
||||
};
|
||||
|
||||
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,4 +1,4 @@
|
||||
const { Menu, app } = require("electron");
|
||||
import { BrowserWindow, Menu, app } from "electron";
|
||||
const { showSettingsWindow } = require("./settings");
|
||||
const isMac = process.platform === "darwin";
|
||||
const { name } = require("./../constants/values");
|
||||
@@ -19,9 +19,7 @@ const quitMenuEntry = {
|
||||
accelerator: "Control+Q",
|
||||
};
|
||||
|
||||
const menuModule = {};
|
||||
|
||||
menuModule.getMenu = function (mainWindow) {
|
||||
export const getMenu = function (mainWindow: BrowserWindow) {
|
||||
const toggleWindow = {
|
||||
label: "Toggle Window",
|
||||
click: function () {
|
||||
@@ -113,11 +111,9 @@ menuModule.getMenu = function (mainWindow) {
|
||||
quitMenuEntry,
|
||||
];
|
||||
|
||||
return Menu.buildFromTemplate(mainMenu);
|
||||
return Menu.buildFromTemplate(mainMenu as any);
|
||||
};
|
||||
|
||||
menuModule.addMenu = function (mainWindow) {
|
||||
Menu.setApplicationMenu(menuModule.getMenu(mainWindow));
|
||||
export const addMenu = function (mainWindow: BrowserWindow) {
|
||||
Menu.setApplicationMenu(getMenu(mainWindow));
|
||||
};
|
||||
|
||||
module.exports = menuModule;
|
@@ -1,5 +1,6 @@
|
||||
const Store = require("electron-store");
|
||||
const settings = require("./../constants/settings");
|
||||
|
||||
const settings = require("../constants/settings");
|
||||
const path = require("path");
|
||||
const { BrowserWindow } = require("electron");
|
||||
|
||||
|
@@ -1,9 +1,10 @@
|
||||
const { Tray } = require("electron");
|
||||
const { getMenu } = require("./menu");
|
||||
const trayModule = {};
|
||||
let tray;
|
||||
import { BrowserWindow, Tray } from "electron";
|
||||
|
||||
trayModule.addTray = function (mainWindow, options = { icon: "" }) {
|
||||
const { getMenu } = require("./menu");
|
||||
|
||||
let tray: Tray;
|
||||
|
||||
export const addTray = function (mainWindow: BrowserWindow, options = { icon: "" }) {
|
||||
tray = new Tray(options.icon);
|
||||
tray.setIgnoreDoubleClickEvents(true);
|
||||
tray.setToolTip("Tidal-hifi");
|
||||
@@ -25,10 +26,8 @@ trayModule.addTray = function (mainWindow, options = { icon: "" }) {
|
||||
});
|
||||
};
|
||||
|
||||
trayModule.refreshTray = function (mainWindow) {
|
||||
export const refreshTray = function (mainWindow: BrowserWindow) {
|
||||
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;
|
||||
};
|
Reference in New Issue
Block a user