mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
fix(api-server): use ipc instead of ipcMain
This commit is contained in:
@ -70,6 +70,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
|
|||||||
// Custom
|
// Custom
|
||||||
init(backendCtx) {
|
init(backendCtx) {
|
||||||
this.app = new Hono();
|
this.app = new Hono();
|
||||||
|
|
||||||
const ws = createNodeWebSocket({
|
const ws = createNodeWebSocket({
|
||||||
app: this.app,
|
app: this.app,
|
||||||
});
|
});
|
||||||
@ -121,7 +122,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
|
|||||||
() => this.volumeState,
|
() => this.volumeState,
|
||||||
);
|
);
|
||||||
registerAuth(this.app, backendCtx);
|
registerAuth(this.app, backendCtx);
|
||||||
registerWebsocket(this.app, ws);
|
registerWebsocket(this.app, backendCtx, ws);
|
||||||
|
|
||||||
// swagger
|
// swagger
|
||||||
this.app.openAPIRegistry.registerComponent(
|
this.app.openAPIRegistry.registerComponent(
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { ipcMain } from 'electron';
|
|
||||||
import { createRoute } from '@hono/zod-openapi';
|
import { createRoute } from '@hono/zod-openapi';
|
||||||
|
|
||||||
import { type NodeWebSocket } from '@hono/node-ws';
|
import { type NodeWebSocket } from '@hono/node-ws';
|
||||||
@ -15,6 +14,8 @@ import type { WSContext } from 'hono/ws';
|
|||||||
import type { Context, Next } from 'hono';
|
import type { Context, Next } from 'hono';
|
||||||
import type { RepeatMode, VolumeState } from '@/types/datahost-get-state';
|
import type { RepeatMode, VolumeState } from '@/types/datahost-get-state';
|
||||||
import type { HonoApp } from '../types';
|
import type { HonoApp } from '../types';
|
||||||
|
import type { BackendContext } from '@/types/contexts';
|
||||||
|
import type { APIServerConfig } from '@/plugins/api-server/config';
|
||||||
|
|
||||||
enum DataTypes {
|
enum DataTypes {
|
||||||
PlayerInfo = 'PLAYER_INFO',
|
PlayerInfo = 'PLAYER_INFO',
|
||||||
@ -36,7 +37,11 @@ type PlayerState = {
|
|||||||
shuffle: boolean;
|
shuffle: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const register = (app: HonoApp, nodeWebSocket: NodeWebSocket) => {
|
export const register = (
|
||||||
|
app: HonoApp,
|
||||||
|
{ ipc }: BackendContext<APIServerConfig>,
|
||||||
|
{ upgradeWebSocket }: NodeWebSocket,
|
||||||
|
) => {
|
||||||
let volumeState: VolumeState | undefined = undefined;
|
let volumeState: VolumeState | undefined = undefined;
|
||||||
let repeat: RepeatMode = 'NONE';
|
let repeat: RepeatMode = 'NONE';
|
||||||
let shuffle = false;
|
let shuffle = false;
|
||||||
@ -89,7 +94,7 @@ export const register = (app: HonoApp, nodeWebSocket: NodeWebSocket) => {
|
|||||||
lastSongInfo = { ...songInfo };
|
lastSongInfo = { ...songInfo };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('ytmd:volume-changed', (_, newVolumeState: VolumeState) => {
|
ipc.on('ytmd:volume-changed', (newVolumeState: VolumeState) => {
|
||||||
volumeState = newVolumeState;
|
volumeState = newVolumeState;
|
||||||
send(DataTypes.VolumeChanged, {
|
send(DataTypes.VolumeChanged, {
|
||||||
volume: volumeState.state,
|
volume: volumeState.state,
|
||||||
@ -97,16 +102,16 @@ export const register = (app: HonoApp, nodeWebSocket: NodeWebSocket) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('ytmd:repeat-changed', (_, mode: RepeatMode) => {
|
ipc.on('ytmd:repeat-changed', (mode: RepeatMode) => {
|
||||||
repeat = mode;
|
repeat = mode;
|
||||||
send(DataTypes.RepeatChanged, { repeat });
|
send(DataTypes.RepeatChanged, { repeat });
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('ytmd:seeked', (_, t: number) => {
|
ipc.on('ytmd:seeked', (t: number) => {
|
||||||
send(DataTypes.PositionChanged, { position: t });
|
send(DataTypes.PositionChanged, { position: t });
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('ytmd:shuffle-changed', (_, newShuffle: boolean) => {
|
ipc.on('ytmd:shuffle-changed', (newShuffle: boolean) => {
|
||||||
shuffle = newShuffle;
|
shuffle = newShuffle;
|
||||||
send(DataTypes.ShuffleChanged, { shuffle });
|
send(DataTypes.ShuffleChanged, { shuffle });
|
||||||
});
|
});
|
||||||
@ -123,7 +128,7 @@ export const register = (app: HonoApp, nodeWebSocket: NodeWebSocket) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
nodeWebSocket.upgradeWebSocket(() => ({
|
upgradeWebSocket(() => ({
|
||||||
onOpen(_, ws) {
|
onOpen(_, ws) {
|
||||||
// "Unsafe argument of type `WSContext<WebSocket>` assigned to a parameter of type `WSContext<WebSocket>`. (@typescript-eslint/no-unsafe-argument)" ????? what?
|
// "Unsafe argument of type `WSContext<WebSocket>` assigned to a parameter of type `WSContext<WebSocket>`. (@typescript-eslint/no-unsafe-argument)" ????? what?
|
||||||
sockets.add(ws as WSContext<WebSocket>);
|
sockets.add(ws as WSContext<WebSocket>);
|
||||||
|
|||||||
Reference in New Issue
Block a user