mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-23 04:46:08 -08:00
Controller: layouts for the media timing review and duplicate card dialogs (#313)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
696462a82e
commit
6d0f37ac21
50 files changed
+4555
-46
No files matched your search
@@ -129,3 +129,60 @@ test('applyControllerConfigUpdate ignores reserved profile ids', () => {
|
||||
assert.equal(Object.hasOwn(next.profiles ?? {}, 'prototype'), false);
|
||||
assert.equal(next.profiles?.['pad-1']?.label, 'Pad 1');
|
||||
});
|
||||
|
||||
test('applyControllerConfigUpdate merges review bindings per action inside a profile', () => {
|
||||
const next = applyControllerConfigUpdate(
|
||||
{
|
||||
profiles: {
|
||||
'pad-1': {
|
||||
bindings: { toggleLookup: { kind: 'button', buttonIndex: 0 } },
|
||||
reviewBindings: {
|
||||
confirm: { press: { kind: 'button', buttonIndex: 1 } },
|
||||
cancel: { kind: 'none' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
profiles: {
|
||||
'pad-1': {
|
||||
reviewBindings: {
|
||||
cancel: {
|
||||
kind: 'combo',
|
||||
press: { kind: 'button', buttonIndex: 0 },
|
||||
hold: { kind: 'button', buttonIndex: 4 },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual(next.profiles?.['pad-1'], {
|
||||
bindings: { toggleLookup: { kind: 'button', buttonIndex: 0 } },
|
||||
reviewBindings: {
|
||||
confirm: { press: { kind: 'button', buttonIndex: 1 } },
|
||||
cancel: {
|
||||
kind: 'combo',
|
||||
press: { kind: 'button', buttonIndex: 0 },
|
||||
hold: { kind: 'button', buttonIndex: 4 },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('applyControllerConfigUpdate merges field grouping bindings next to review bindings', () => {
|
||||
const next = applyControllerConfigUpdate(
|
||||
{
|
||||
reviewBindings: { confirm: { kind: 'none' } },
|
||||
fieldGroupingBindings: { back: { kind: 'none' } },
|
||||
},
|
||||
{ fieldGroupingBindings: { cancelMerge: { press: { kind: 'face', letter: 'b' } } } },
|
||||
);
|
||||
|
||||
assert.deepEqual(next.reviewBindings, { confirm: { kind: 'none' } });
|
||||
assert.deepEqual(next.fieldGroupingBindings, {
|
||||
back: { kind: 'none' },
|
||||
cancelMerge: { press: { kind: 'face', letter: 'b' } },
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,9 @@ import type { ControllerConfigUpdate, RawConfig } from '../types';
|
||||
|
||||
type RawControllerConfig = NonNullable<RawConfig['controller']>;
|
||||
type RawControllerBindings = NonNullable<RawControllerConfig['bindings']>;
|
||||
type RawControllerScreenBindings = Record<string, unknown>;
|
||||
/** Per-dialog controller layouts stored as per-action patches. */
|
||||
const SCREEN_BINDING_KEYS = ['reviewBindings', 'fieldGroupingBindings'] as const;
|
||||
type RawControllerButtonIndices = NonNullable<RawControllerConfig['buttonIndices']>;
|
||||
type RawControllerProfiles = NonNullable<RawControllerConfig['profiles']>;
|
||||
type RawControllerProfile = NonNullable<RawControllerProfiles[string]>;
|
||||
@@ -27,6 +30,34 @@ function mergeBindingPatch(
|
||||
return nextBindings;
|
||||
}
|
||||
|
||||
function mergeScreenBindingPatch(
|
||||
currentBindings: RawControllerScreenBindings | undefined,
|
||||
updateBindings: RawControllerScreenBindings | undefined,
|
||||
): RawControllerScreenBindings | undefined {
|
||||
if (!currentBindings && !updateBindings) return undefined;
|
||||
const nextBindings: RawControllerScreenBindings = { ...(currentBindings ?? {}) };
|
||||
for (const [action, binding] of Object.entries(updateBindings ?? {})) {
|
||||
if (binding === undefined) continue;
|
||||
nextBindings[action] = structuredClone(binding);
|
||||
}
|
||||
return nextBindings;
|
||||
}
|
||||
|
||||
/** Merges every per-dialog layout patch from `update` onto `current` into `target`. */
|
||||
function mergeScreenBindingPatches(
|
||||
current: Partial<Record<(typeof SCREEN_BINDING_KEYS)[number], unknown>> | undefined,
|
||||
update: Partial<Record<(typeof SCREEN_BINDING_KEYS)[number], unknown>>,
|
||||
target: Partial<Record<(typeof SCREEN_BINDING_KEYS)[number], unknown>>,
|
||||
): void {
|
||||
for (const key of SCREEN_BINDING_KEYS) {
|
||||
const merged = mergeScreenBindingPatch(
|
||||
current?.[key] as RawControllerScreenBindings | undefined,
|
||||
update[key] as RawControllerScreenBindings | undefined,
|
||||
);
|
||||
if (merged) target[key] = merged;
|
||||
}
|
||||
}
|
||||
|
||||
function mergeButtonIndexPatch(
|
||||
currentButtonIndices: RawControllerButtonIndices | undefined,
|
||||
updateButtonIndices: RawControllerButtonIndices | undefined,
|
||||
@@ -60,6 +91,8 @@ function mergeControllerProfile(
|
||||
nextProfile.bindings = bindings;
|
||||
}
|
||||
|
||||
mergeScreenBindingPatches(currentProfile, updateProfile, nextProfile);
|
||||
|
||||
return nextProfile;
|
||||
}
|
||||
|
||||
@@ -85,6 +118,8 @@ export function applyControllerConfigUpdate(
|
||||
nextController.bindings = bindings;
|
||||
}
|
||||
|
||||
mergeScreenBindingPatches(currentController, update, nextController);
|
||||
|
||||
if (currentController?.profiles || update.profiles) {
|
||||
const nextProfiles: RawControllerProfiles = {};
|
||||
for (const [profileId, profile] of Object.entries(currentController?.profiles ?? {}) as Array<
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
createHarness,
|
||||
type FakeOverlayWindowInit,
|
||||
} from './overlay-runtime-test-harness';
|
||||
import type { OverlayHostedModal } from '../shared/ipc/contracts';
|
||||
import { IPC_CHANNELS, type OverlayHostedModal } from '../shared/ipc/contracts';
|
||||
|
||||
const SUBSYNC_PAYLOAD = {
|
||||
ffsubsyncAvailable: true,
|
||||
@@ -749,3 +749,42 @@ test('Linux keeps the dedicated modal window unmapped until the renderer opens t
|
||||
assert.equal(modal.isVisible(), true);
|
||||
assert.equal(modal.ignoreMouseEvents, false);
|
||||
});
|
||||
|
||||
test('modal window path suspends the main overlay controller until the last modal closes', () => {
|
||||
const main = new FakeOverlayWindow({ visible: true });
|
||||
const h = createHarness({ main, modal: new FakeOverlayWindow() });
|
||||
const suspendMessages = () =>
|
||||
main.sent.filter(([channel]) => channel === IPC_CHANNELS.event.controllerSuspendedChanged);
|
||||
|
||||
h.runtime.sendToActiveOverlayWindow(
|
||||
'media-timing-review:open',
|
||||
{ reviewId: 'r-1' },
|
||||
{ restoreOnModalClose: 'media-timing-review', preferModalWindow: true },
|
||||
);
|
||||
h.runtime.notifyOverlayModalOpened('media-timing-review');
|
||||
assert.deepEqual(suspendMessages(), [[IPC_CHANNELS.event.controllerSuspendedChanged, true]]);
|
||||
|
||||
h.runtime.handleOverlayModalClosed('media-timing-review');
|
||||
assert.deepEqual(suspendMessages(), [
|
||||
[IPC_CHANNELS.event.controllerSuspendedChanged, true],
|
||||
[IPC_CHANNELS.event.controllerSuspendedChanged, false],
|
||||
]);
|
||||
});
|
||||
|
||||
test('a modal hosted in the main overlay keeps that overlay controller active', () => {
|
||||
const main = new FakeOverlayWindow({ visible: true });
|
||||
const h = createHarness({ main, createModal: () => new FakeOverlayWindow() });
|
||||
|
||||
h.runtime.sendToActiveOverlayWindow(
|
||||
'media-timing-review:open',
|
||||
{ reviewId: 'r-1' },
|
||||
{ restoreOnModalClose: 'media-timing-review' },
|
||||
);
|
||||
h.runtime.notifyOverlayModalOpened('media-timing-review');
|
||||
h.runtime.handleOverlayModalClosed('media-timing-review');
|
||||
|
||||
assert.equal(
|
||||
main.sent.some(([channel]) => channel === IPC_CHANNELS.event.controllerSuspendedChanged),
|
||||
false,
|
||||
);
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BrowserWindow } from 'electron';
|
||||
import type { OverlayHostedModal } from '../shared/ipc/contracts';
|
||||
import { IPC_CHANNELS, type OverlayHostedModal } from '../shared/ipc/contracts';
|
||||
import type { WindowGeometry } from '../types';
|
||||
import type { HyprlandPlacementStatus } from '../core/services/hyprland-window-placement';
|
||||
import { applyOverlayClickThrough } from '../core/services/overlay-click-through';
|
||||
@@ -83,6 +83,7 @@ export function createOverlayModalRuntimeService(
|
||||
let modalActive = false;
|
||||
let mainWindowMousePassthroughForcedByModal = false;
|
||||
let mainWindowHiddenByModal = false;
|
||||
let mainWindowControllerSuspended = false;
|
||||
let modalWindowPrimedForImmediateShow = false;
|
||||
let pendingModalWindowReveal: BrowserWindow | null = null;
|
||||
let pendingModalWindowRevealTimeout: RevealFallbackHandle | null = null;
|
||||
@@ -411,6 +412,16 @@ export function createOverlayModalRuntimeService(
|
||||
mainWindowHiddenByModal = false;
|
||||
};
|
||||
|
||||
// The hidden main overlay keeps polling the gamepad (background throttling is off), so
|
||||
// tell it to stand down while the modal window owns the controller.
|
||||
const setMainWindowControllerSuspended = (suspended: boolean): void => {
|
||||
if (mainWindowControllerSuspended === suspended) return;
|
||||
mainWindowControllerSuspended = suspended;
|
||||
const mainWindow = deps.getMainWindow();
|
||||
if (!mainWindow || mainWindow.isDestroyed()) return;
|
||||
mainWindow.webContents.send(IPC_CHANNELS.event.controllerSuspendedChanged, suspended);
|
||||
};
|
||||
|
||||
const scheduleModalWindowReveal = (window: BrowserWindow): void => {
|
||||
pendingModalWindowReveal = window;
|
||||
if (pendingModalWindowRevealTimeout !== null) {
|
||||
@@ -560,6 +571,7 @@ export function createOverlayModalRuntimeService(
|
||||
}
|
||||
mainWindowMousePassthroughForcedByModal = false;
|
||||
setMainWindowVisibilityForModal(false);
|
||||
setMainWindowControllerSuspended(false);
|
||||
try {
|
||||
options.onFinalModalClosed?.();
|
||||
} catch {
|
||||
@@ -591,6 +603,7 @@ export function createOverlayModalRuntimeService(
|
||||
const handOffMainWindowToModal = (): void => {
|
||||
setMainWindowMousePassthroughForModal(true);
|
||||
setMainWindowVisibilityForModal(true);
|
||||
setMainWindowControllerSuspended(true);
|
||||
};
|
||||
|
||||
if (targetIsModalWindow && deferModalRevealUntilOpened) {
|
||||
|
||||
Reference in new issue
Block a user