mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-30 19:21:32 -07:00
[codex] Restart Jellyfin remote session after setup login (#112)
This commit is contained in:
@@ -1,6 +1,37 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { composeJellyfinRuntimeHandlers } from './jellyfin-runtime-composer';
|
||||
import {
|
||||
composeJellyfinRuntimeHandlers,
|
||||
createRestartJellyfinRemoteSessionAfterSetupLoginHandler,
|
||||
} from './jellyfin-runtime-composer';
|
||||
|
||||
test('setup login restart uses auto-connect path without an active remote session', async () => {
|
||||
const startOptions: Array<{ explicit?: boolean } | undefined> = [];
|
||||
const restart = createRestartJellyfinRemoteSessionAfterSetupLoginHandler({
|
||||
getCurrentSession: () => null,
|
||||
startJellyfinRemoteSession: async (options) => {
|
||||
startOptions.push(options);
|
||||
},
|
||||
});
|
||||
|
||||
await restart();
|
||||
|
||||
assert.deepEqual(startOptions, [undefined]);
|
||||
});
|
||||
|
||||
test('setup login restart explicitly refreshes an active remote session', async () => {
|
||||
const startOptions: Array<{ explicit?: boolean } | undefined> = [];
|
||||
const restart = createRestartJellyfinRemoteSessionAfterSetupLoginHandler({
|
||||
getCurrentSession: () => ({ stop: () => {} }),
|
||||
startJellyfinRemoteSession: async (options) => {
|
||||
startOptions.push(options);
|
||||
},
|
||||
});
|
||||
|
||||
await restart();
|
||||
|
||||
assert.deepEqual(startOptions, [{ explicit: true }]);
|
||||
});
|
||||
|
||||
test('composeJellyfinRuntimeHandlers returns callable jellyfin runtime handlers', () => {
|
||||
let activePlayback: unknown = null;
|
||||
|
||||
@@ -153,6 +153,16 @@ export type JellyfinRuntimeComposerResult = ComposerOutputs<{
|
||||
openJellyfinSetupWindow: ReturnType<typeof createOpenJellyfinSetupWindowHandler>;
|
||||
}>;
|
||||
|
||||
export function createRestartJellyfinRemoteSessionAfterSetupLoginHandler(deps: {
|
||||
getCurrentSession: () => unknown | null;
|
||||
startJellyfinRemoteSession: (options?: { explicit?: boolean }) => Promise<void>;
|
||||
}) {
|
||||
return async (): Promise<void> => {
|
||||
const hasActiveSession = deps.getCurrentSession() !== null;
|
||||
await deps.startJellyfinRemoteSession(hasActiveSession ? { explicit: true } : undefined);
|
||||
};
|
||||
}
|
||||
|
||||
export function composeJellyfinRuntimeHandlers(
|
||||
options: JellyfinRuntimeComposerOptions,
|
||||
): JellyfinRuntimeComposerResult {
|
||||
@@ -268,12 +278,19 @@ export function composeJellyfinRuntimeHandlers(
|
||||
const maybeFocusExistingJellyfinSetupWindow = createMaybeFocusExistingJellyfinSetupWindowHandler(
|
||||
options.maybeFocusExistingJellyfinSetupWindowMainDeps,
|
||||
);
|
||||
const restartJellyfinRemoteSessionAfterSetupLogin =
|
||||
createRestartJellyfinRemoteSessionAfterSetupLoginHandler({
|
||||
getCurrentSession: () => options.startJellyfinRemoteSessionMainDeps.getCurrentSession(),
|
||||
startJellyfinRemoteSession: (startOptions) => startJellyfinRemoteSession(startOptions),
|
||||
});
|
||||
const openJellyfinSetupWindow = createOpenJellyfinSetupWindowHandler(
|
||||
createBuildOpenJellyfinSetupWindowMainDepsHandler({
|
||||
...options.openJellyfinSetupWindowMainDeps,
|
||||
maybeFocusExistingSetupWindow: maybeFocusExistingJellyfinSetupWindow,
|
||||
getResolvedJellyfinConfig: () => getResolvedJellyfinConfig(),
|
||||
getJellyfinClientInfo: () => getJellyfinClientInfo(),
|
||||
restartRemoteSession: () => restartJellyfinRemoteSessionAfterSetupLogin(),
|
||||
stopRemoteSession: () => stopJellyfinRemoteSession(),
|
||||
})(),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user