refactor(external-playback): improve session handling and remove dismiss functionality

This commit is contained in:
4gray committed 2026-03-14 11:55:26 +01:00
1 parent ec84eea924
commit c42e35b48d
8 files changed
+77 -27

No files matched your search

@@ -94,22 +94,57 @@ describe('ExternalPlaybackService', () => {
contentType: 'vod',
})
).toBeNull();
expect(service.visibleSession()).toBeNull();
});
it('delegates close requests for closable sessions', async () => {
const session = createSession({ status: 'opened' });
listener?.(session);
closeExternalPlayerSession.mockResolvedValue(
createSession({
...session,
status: 'closed',
canClose: false,
updatedAt: '2026-03-07T10:00:10.000Z',
})
);
await service.closeActiveSession();
expect(closeExternalPlayerSession).toHaveBeenCalledWith(session.id);
expect(service.visibleSession()).toBeNull();
});
it('can close a specific session directly', async () => {
const session = createSession({ id: 'session-2', status: 'playing' });
closeExternalPlayerSession.mockResolvedValue(
createSession({
...session,
status: 'closed',
canClose: false,
updatedAt: '2026-03-07T10:00:12.000Z',
})
);
await service.closeSession(session);
expect(closeExternalPlayerSession).toHaveBeenCalledWith('session-2');
});
it('hides terminal sessions from the dock', () => {
listener?.(createSession({ status: 'closed', canClose: false }));
expect(service.visibleSession()).toBeNull();
listener?.(
createSession({
id: 'session-3',
status: 'error',
error: 'Launch failed',
canClose: false,
})
);
expect(service.visibleSession()).toBeNull();
});
});
@@ -10,7 +10,11 @@ export class ExternalPlaybackService {
readonly visibleSession = computed(() => {
const session = this.activeSession();
if (!session || session.status === 'closed') {
if (
!session ||
session.status === 'closed' ||
session.status === 'error'
) {
return null;
}
@@ -43,11 +47,43 @@ export class ExternalPlaybackService {
async closeSession(
session: ExternalPlayerSession | null | undefined
): Promise<void> {
if (!session?.canClose || !window.electron?.closeExternalPlayerSession) {
if (!session) {
return;
}
await window.electron.closeExternalPlayerSession(session.id);
if (!session.canClose || !window.electron?.closeExternalPlayerSession) {
this.dismissedSessionId.set(session.id);
return;
}
const previousDismissedSessionId = this.dismissedSessionId();
this.dismissedSessionId.set(session.id);
try {
const updatedSession = await window.electron.closeExternalPlayerSession(
session.id
);
if (updatedSession) {
this.handleSessionUpdate(updatedSession);
return;
}
this.activeSession.update((current) =>
current?.id === session.id
? {
...current,
status: 'closed',
canClose: false,
updatedAt: new Date().toISOString(),
}
: current
);
} catch (error) {
if (this.dismissedSessionId() === session.id) {
this.dismissedSessionId.set(previousDismissedSessionId);
}
throw error;
}
}
findMatchingSession(