From c4c084ee0c1f6837bafe23e85b6f0ff470236451 Mon Sep 17 00:00:00 2001 From: Core Date: Tue, 10 Dec 2024 15:56:50 +0000 Subject: [PATCH] fix: various type and logic errors --- src/main/base/browserwindow.ts | 11 +++++++---- src/main/base/utils.ts | 5 +++-- src/main/plugins/chromecast.ts | 11 ++++++----- src/main/plugins/raop.ts | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index 8d29ec544..4ffc0536f 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -884,7 +884,7 @@ export class BrowserWindow { if (url.endsWith("/")) url = url.slice(0, -1); let response = await utils.fetch(`${url}/archive/refs/heads/main.zip`); let repo = url.split("/").slice(-2).join("/"); - let apiRepo = await utils.fetch(`https://api.github.com/repos/${repo}`).then((res) => res.json()) as { id: number}; + let apiRepo = await utils.fetch(`https://api.github.com/repos/${repo}`).then((res) => res.json()) as { id: number }; console.debug(`REPO ID: ${apiRepo.id}`); // extract the files from the first folder in the zip response let zip = new AdmZip(await response.buffer()); @@ -927,7 +927,7 @@ export class BrowserWindow { "User-Agent": utils.getWindow().webContents.getUserAgent(), }, }) - .then((res) => res.json()) as { id: number} + .then((res) => res.json()) as { id: number } console.error(apiRepo); console.debug(`REPO ID: ${apiRepo.id}`); // extract the files from the first folder in the zip response @@ -1206,7 +1206,7 @@ export class BrowserWindow { var inputIndex = 0; - for (var index = 0; index < length; ) { + for (var index = 0; index < length;) { result[index++] = leftChannel[inputIndex]; result[index++] = rightChannel[inputIndex]; inputIndex++; @@ -1300,7 +1300,10 @@ export class BrowserWindow { //let newaudio = [leftpcm, rightpcm]; // console.log(newaudio.length); - let pcmData = Buffer.from(new Int8Array(interleave16(bitratechange(Int16Array.from(newaudio[0], (x) => convert(x))), bitratechange(Int16Array.from(newaudio[1], (x) => convert(x)))).buffer)); + const pcmData = Buffer.from(new Uint8Array(interleave16( + bitratechange(Int16Array.from(newaudio[0], (x) => convert(x))), + bitratechange(Int16Array.from(newaudio[1], (x) => convert(x))) + ).buffer)); if (!this.headerSent) { console.log("new header"); diff --git a/src/main/base/utils.ts b/src/main/base/utils.ts index 4fa1bfc99..d5dc0bc51 100644 --- a/src/main/base/utils.ts +++ b/src/main/base/utils.ts @@ -118,10 +118,11 @@ export class utils { */ static getLocale(language: string, key?: string): string | object { let i18n: any = {}; + if (!this.i18n[language]) { - i18n = this.i18n["en"][0].content; + i18n = this.i18n["en-US"][0].content; } else { - i18n = this.i18n[language ?? "en"][0].content; + i18n = this.i18n[language ?? "en-US"][0].content; } if (key) { diff --git a/src/main/plugins/chromecast.ts b/src/main/plugins/chromecast.ts index f62e344a5..4451779b5 100644 --- a/src/main/plugins/chromecast.ts +++ b/src/main/plugins/chromecast.ts @@ -1,8 +1,9 @@ import electron from "electron"; import os from "os"; -import {CiderReceiver} from "../base/castreceiver.js"; +import { CiderReceiver } from "../base/castreceiver.js"; import MediaRendererClient from "upnp-mediarenderer-client"; import request from "request"; +// @ts-expect-error import castv2 from "castv2-client"; import mdnsjs from "mdns-js"; @@ -274,7 +275,7 @@ export default class ChromecastPlugin { this.connectedHosts[device.host] = client; this.activeConnections.push(client); } - } catch (e) {} + } catch (e) { } } } @@ -328,7 +329,7 @@ export default class ChromecastPlugin { this.activeConnections.forEach((client: any) => { try { client.stop(); - } catch (e) {} + } catch (e) { } }); this.activeConnections = []; this.connectedHosts = {}; @@ -338,13 +339,13 @@ export default class ChromecastPlugin { /** * Runs on app stop */ - onBeforeQuit(): void {} + onBeforeQuit(): void { } /** * Runs on song change * @param attributes Music Attributes */ - onNowPlayingItemDidChange(attributes: any): void {} + onNowPlayingItemDidChange(attributes: any): void { } onRendererReady(): void { this._win.webContents.executeJavaScript(`ipcRenderer.sendSync('get-port')`).then((result: any) => { diff --git a/src/main/plugins/raop.ts b/src/main/plugins/raop.ts index 3fa097f7b..668bf796b 100644 --- a/src/main/plugins/raop.ts +++ b/src/main/plugins/raop.ts @@ -326,7 +326,7 @@ export default class RAOP { // if (err) throw err; // console.log('It\'s saved!'); // }); - this.airtunes.circularBuffer.write(Buffer.from(Int8Array.from(result.outbuffer))); + this.airtunes.circularBuffer.write(Buffer.from(new Uint8Array(result.outbuffer))); }); this.worker.on("error", (error: any) => {