mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
fix: use specific listener cleanup instead of removeAllListeners
Return unsubscribe function from onPlaybackPositionUpdate to ensure only the specific listener is removed on destroy, preventing issues with multiple store instances. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0219d3253e
commit
9cd278256b
3 files changed
+34
-34
No files matched your search
@@ -28,15 +28,12 @@ contextBridge.exposeInMainWorld('electron', {
|
||||
) => {
|
||||
ipcRenderer.on('EPG_PROGRESS_UPDATE', (_event, data) => callback(data));
|
||||
},
|
||||
// Playback position update listener
|
||||
// Playback position update listener - returns unsubscribe function
|
||||
onPlaybackPositionUpdate: (callback: (data: any) => void) => {
|
||||
ipcRenderer.on('playback-position-update', (_event, data) =>
|
||||
callback(data)
|
||||
);
|
||||
},
|
||||
// Remove playback position listener
|
||||
removePlaybackPositionListener: () => {
|
||||
ipcRenderer.removeAllListeners('playback-position-update');
|
||||
const handler = (_event: Electron.IpcRendererEvent, data: any) =>
|
||||
callback(data);
|
||||
ipcRenderer.on('playback-position-update', handler);
|
||||
return () => ipcRenderer.off('playback-position-update', handler);
|
||||
},
|
||||
// DB save content progress listener
|
||||
onDbSaveContentProgress: (callback: (count: number) => void) => {
|
||||
|
||||
@@ -365,31 +365,35 @@ export function withPlaybackPositions() {
|
||||
};
|
||||
}),
|
||||
|
||||
withHooks({
|
||||
onInit(store) {
|
||||
if (window.electron?.onPlaybackPositionUpdate) {
|
||||
window.electron.onPlaybackPositionUpdate((data: any) => {
|
||||
console.log(
|
||||
'[withPlaybackPositions] Received update:',
|
||||
data
|
||||
withHooks((store) => {
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
|
||||
return {
|
||||
onInit() {
|
||||
if (window.electron?.onPlaybackPositionUpdate) {
|
||||
unsubscribe = window.electron.onPlaybackPositionUpdate(
|
||||
(data: any) => {
|
||||
console.log(
|
||||
'[withPlaybackPositions] Received update:',
|
||||
data
|
||||
);
|
||||
// Ensure playlistId is present
|
||||
if (data.playlistId) {
|
||||
store.savePosition(data.playlistId, data);
|
||||
} else {
|
||||
console.warn(
|
||||
'[withPlaybackPositions] Missing playlistId in update',
|
||||
data
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
// Ensure playlistId is present
|
||||
if (data.playlistId) {
|
||||
store.savePosition(data.playlistId, data);
|
||||
} else {
|
||||
console.warn(
|
||||
'[withPlaybackPositions] Missing playlistId in update',
|
||||
data
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
onDestroy(store) {
|
||||
if (window.electron?.removePlaybackPositionListener) {
|
||||
window.electron.removePlaybackPositionListener();
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
onDestroy() {
|
||||
unsubscribe?.();
|
||||
},
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
Vendored
+1
-2
@@ -17,8 +17,7 @@ interface Window {
|
||||
onEpgProgress: (callback: (data: { url: string; status: 'loading' | 'complete' | 'error'; stats?: { totalChannels: number; totalPrograms: number }; error?: string }) => void) => void;
|
||||
onDbSaveContentProgress: (callback: (count: number) => void) => void;
|
||||
removeDbSaveContentProgress: () => void;
|
||||
onPlaybackPositionUpdate: (callback: (data: any) => void) => void;
|
||||
removePlaybackPositionListener: () => void;
|
||||
onPlaybackPositionUpdate: (callback: (data: any) => void) => () => void;
|
||||
|
||||
// Files & System
|
||||
saveFileDialog: (defaultPath: string, filters?: { name: string; extensions: string[] }[]) => Promise<any>;
|
||||
|
||||
Reference in new issue
Block a user