From 221684b06258c849b10bf11f2f9922947cc6b9b9 Mon Sep 17 00:00:00 2001 From: peancored Date: Mon, 5 Feb 2024 02:28:16 +0000 Subject: [PATCH] Fix memory leak --- src/main/preload.ts | 2 +- src/renderer/components/SheetMusic/SheetMusic.tsx | 2 +- src/renderer/components/SheetMusic/styles.ts | 4 ++-- src/renderer/views/SelectSongView/SelectSongView.tsx | 4 ++-- src/renderer/views/SongView/SongView.tsx | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/preload.ts b/src/main/preload.ts index 6cbfbf0..56c45ee 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -21,7 +21,7 @@ const electronHandler = { ipcRenderer.removeListener(channel, subscription); }; }, - once(channel: Channels, func: (...args: unknown[]) => void) { + once(channel: Channels, func: (...args: T[]) => void) { ipcRenderer.once(channel, (_event, ...args) => func(...args)); }, }, diff --git a/src/renderer/components/SheetMusic/SheetMusic.tsx b/src/renderer/components/SheetMusic/SheetMusic.tsx index d25667e..0d7e5bb 100644 --- a/src/renderer/components/SheetMusic/SheetMusic.tsx +++ b/src/renderer/components/SheetMusic/SheetMusic.tsx @@ -96,7 +96,7 @@ export function SheetMusic({ width: stave.getWidth() + 10, height: stave.getHeight(), }} - highlighted={isHighlighted} + $highlighted={isHighlighted} onClick={() => { if (!midi) { return; diff --git a/src/renderer/components/SheetMusic/styles.ts b/src/renderer/components/SheetMusic/styles.ts index 5211e46..9fb2eaf 100644 --- a/src/renderer/components/SheetMusic/styles.ts +++ b/src/renderer/components/SheetMusic/styles.ts @@ -21,14 +21,14 @@ export const MeasureHighlighted = css` background: ${theme.color.primaryLightest}; `; -export const MeasureHighlight = styled.button<{ highlighted: boolean }>` +export const MeasureHighlight = styled.button<{ $highlighted: boolean }>` position: absolute; z-index: -3; border-radius: ${theme.borderRadius}px; border: 0; background: transparent; cursor: pointer; - ${(props) => (props.highlighted ? MeasureHighlighted : '')} + ${(props) => (props.$highlighted ? MeasureHighlighted : '')} &:hover { background: ${theme.color.background}; diff --git a/src/renderer/views/SelectSongView/SelectSongView.tsx b/src/renderer/views/SelectSongView/SelectSongView.tsx index 901c2fd..2834d40 100644 --- a/src/renderer/views/SelectSongView/SelectSongView.tsx +++ b/src/renderer/views/SelectSongView/SelectSongView.tsx @@ -20,7 +20,7 @@ export function SelectSongView() { useEffect(() => { window.electron.ipcRenderer.sendMessage('load-song-list'); - window.electron.ipcRenderer.on( + window.electron.ipcRenderer.once( 'load-song-list', (arg) => { setSongList(arg); @@ -85,7 +85,7 @@ export function SelectSongView() { icon={} onClick={() => { window.electron.ipcRenderer.sendMessage('rescan-songs'); - window.electron.ipcRenderer.on( + window.electron.ipcRenderer.once( 'rescan-songs', (arg) => { setSongList(arg); diff --git a/src/renderer/views/SongView/SongView.tsx b/src/renderer/views/SongView/SongView.tsx index e552389..b4cd0b3 100644 --- a/src/renderer/views/SongView/SongView.tsx +++ b/src/renderer/views/SongView/SongView.tsx @@ -40,7 +40,7 @@ export function SongView() { const navigate = useNavigate(); const loadSong = useCallback(() => { - window.electron.ipcRenderer.on( + window.electron.ipcRenderer.once( 'load-song', ({ data, midi, audio }) => { setMidiData(midi); @@ -249,7 +249,7 @@ export function SongView() {