added several dev improvements

This commit is contained in:
2023-07-23 23:07:19 +02:00
parent ad05b767d8
commit 6969de8270
9 changed files with 260 additions and 6 deletions

View File

@@ -10,4 +10,5 @@ export const globalEvents = {
showSettings: "showSettings",
storeChanged: "storeChanged",
error: "error",
log: "log",
};

33
src/features/logger.ts Normal file
View File

@@ -0,0 +1,33 @@
import { IpcMain, IpcRenderer } from "electron";
import { globalEvents } from "../constants/globalEvents";
export class Logger {
/**
*
* @param ipcRenderer renderer IPC client so we can send messages to the main thread
*/
constructor(private ipcRenderer: IpcRenderer) {}
/**
* Subscribe to watch for logs from the IPC client
* @param ipcMain main thread IPC client so we can subscribe to events
*/
public static watch(ipcMain: IpcMain) {
ipcMain.on(globalEvents.log, (event, content, object) => {
console.log(content, JSON.stringify(object, null, 2));
});
}
/**
* Log content to STDOut
* @param content
* @param object js(on) object that will be prettyPrinted
*/
public log(content: string, object: object = {}) {
if (this.ipcRenderer) {
this.ipcRenderer.send(globalEvents.log, { content, object });
} else {
console.log(`${content} \n ${JSON.stringify(object, null, 2)}`);
}
}
}

View File

@@ -26,6 +26,7 @@ import {
import { settings } from "./constants/settings";
import { addTray, refreshTray } from "./scripts/tray";
import { MediaInfo } from "./models/mediaInfo";
import { Logger } from "./features/logger";
const tidalUrl = "https://listen.tidal.com";
initialize();
@@ -220,3 +221,5 @@ ipcMain.on(globalEvents.storeChanged, () => {
ipcMain.on(globalEvents.error, (event) => {
console.log(event);
});
Logger.watch(ipcMain);

View File

@@ -1,4 +1,4 @@
import remote, { app } from "@electron/remote";
import { app } from "@electron/remote";
import { ipcRenderer, shell } from "electron";
import fs from "fs";
import { globalEvents } from "../../constants/globalEvents";
@@ -107,8 +107,8 @@ function hide() {
* Restart tidal-hifi after changes
*/
function restart() {
remote.app.relaunch();
remote.app.exit();
app.relaunch();
app.exit();
}
/**