mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-13 20:56:19 -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
@@ -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