Skip to content

Commit

Permalink
fix(treeview): Remove long picUrl (#975)
Browse files Browse the repository at this point in the history
* fix(treeview): Remove long picUrl

* fix lint

---------

Co-authored-by: mcwindy <noreply@cn>
  • Loading branch information
mcwindy and mcwindy authored Apr 11, 2024
1 parent 107bf7d commit 88edc52
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/client/src/utils/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class IPCClient<T, U = T> {

resolve(true);
})
.catch(() => resolve(false)),
.catch(() => resolve(false))
);
}

Expand Down Expand Up @@ -92,14 +92,20 @@ const ipc = new IPCClient<IPCClientMsg, IPCServerMsg>(ipcServerPath);
const ipcB = new IPCClient<IPCBroadcastMsg>(ipcBroadcastServerPath);

let _nextChann = 0;
const removePicUrl = (items?: PlayTreeItemData[]) => {
if (items)
for (const item of items) {
if ("al" in item && item.al.picUrl.length > 1000) item.al.picUrl = "";
}
};

export const IPC = {
requestPool: <CSConnPool>new Map(),

connect: (
ipcHandler: Parameters<typeof ipc.connect>[0],
ipcBHandler: Parameters<typeof ipcB.connect>[0],
retry = 4,
retry = 4
): Promise<[boolean, boolean]> => Promise.all([ipc.connect(ipcHandler, retry), ipcB.connect(ipcBHandler, retry)]),
disconnect: () => {
ipc.disconnect();
Expand All @@ -123,7 +129,7 @@ export const IPC = {
next: next && "mainSong" in next ? next.mainSong : next,
play,
seek,
}),
})
)
.catch(console.error);
},
Expand Down Expand Up @@ -154,16 +160,21 @@ export const IPC = {
volume: (level: number) => ipc.send({ t: IPCPlayer.volume, level }),
speed: (speed: number) => ipc.send({ t: IPCPlayer.speed, speed }),
seek: (seekOffset: number) => ipc.send({ t: IPCPlayer.seek, seekOffset }),
add: (items: readonly PlayTreeItemData[], index?: number) => ipcB.send({ t: IPCQueue.add, items, index }),
add: (items: PlayTreeItemData[], index?: number) => {
removePicUrl(items);
ipcB.send({ t: IPCQueue.add, items, index });
},
clear: () => ipcB.send({ t: IPCQueue.clear }),
delete: (id: number | string) => ipcB.send({ t: IPCQueue.delete, id }),
fm: (uid: number) => ipc.send({ t: IPCQueue.fm, uid }),
new: (items?: readonly PlayTreeItemData[]) =>
new: (items?: PlayTreeItemData[]) => {
removePicUrl(items);
ipcB.send(
items
? { t: IPCQueue.new, id: QueueProvider.id + 1, items }
: { t: IPCQueue.new, id: QueueProvider.id, items: QueueProvider.songs },
),
: { t: IPCQueue.new, id: QueueProvider.id, items: QueueProvider.songs }
);
},
playSong: (id: number | string) => ipcB.send({ t: IPCQueue.play, id }),
random: () => ipcB.send({ t: IPCQueue.new, id: QueueProvider.id + 1, items: QueueProvider.random() }),
shift: (index: number) => ipcB.send({ t: IPCQueue.shift, index }),
Expand Down

0 comments on commit 88edc52

Please sign in to comment.