mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-10-20 17:01:24 -07:00
test: cut low-value tests, rewrite the rest around behavior, parallelize lanes (#285)
This commit is contained in:
1 parent
4b6842d034
commit
b48083ddd8
368 files changed
+18045
-60331
No files matched your search
+9
-91
@@ -18,6 +18,7 @@
|
||||
|
||||
import { clipboard, contextBridge, ipcRenderer, IpcRendererEvent, webUtils } from 'electron';
|
||||
import { resolveOverlayLayerFromArgv } from './preload-args';
|
||||
import { createIpcListenerFactories } from './preload-ipc-listeners';
|
||||
import type {
|
||||
SubtitleData,
|
||||
SubtitlePosition,
|
||||
@@ -82,101 +83,18 @@ import type {
|
||||
import { IPC_CHANNELS } from './shared/ipc/contracts';
|
||||
import type { SubtitleGenerationProgress } from './shared/subtitle-generation';
|
||||
|
||||
const {
|
||||
createQueuedIpcListener,
|
||||
createQueuedIpcListenerWithPayload,
|
||||
createLatestValueIpcListenerWithPayload,
|
||||
} = createIpcListenerFactories((channel, handler) =>
|
||||
ipcRenderer.on(channel, (_event, payload: unknown) => handler(payload)),
|
||||
);
|
||||
|
||||
const overlayLayer = resolveOverlayLayerFromArgv(process.argv);
|
||||
const onSubtitleSelectionOpen = createQueuedIpcListener(IPC_CHANNELS.event.subtitleSelectionOpen);
|
||||
const onSubtitleGenerationOpen = createQueuedIpcListener(IPC_CHANNELS.event.subtitleGenerationOpen);
|
||||
|
||||
type EmptyListener = () => void;
|
||||
type PayloadedListener<T> = (payload: T) => void;
|
||||
|
||||
function createQueuedIpcListener(channel: string): (listener: EmptyListener) => void {
|
||||
let count = 0;
|
||||
const listeners: EmptyListener[] = [];
|
||||
|
||||
const dispatch = (): void => {
|
||||
if (listeners.length === 0) {
|
||||
count += 1;
|
||||
return;
|
||||
}
|
||||
for (const listener of listeners) {
|
||||
listener();
|
||||
}
|
||||
};
|
||||
|
||||
ipcRenderer.on(channel, () => {
|
||||
dispatch();
|
||||
});
|
||||
|
||||
return (listener: EmptyListener): void => {
|
||||
listeners.push(listener);
|
||||
while (count > 0) {
|
||||
count -= 1;
|
||||
listener();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createQueuedIpcListenerWithPayload<T>(
|
||||
channel: string,
|
||||
normalize: (payload: unknown) => T,
|
||||
): (listener: PayloadedListener<T>) => void {
|
||||
const pending: T[] = [];
|
||||
const listeners: PayloadedListener<T>[] = [];
|
||||
|
||||
const dispatch = (payload: T): void => {
|
||||
if (listeners.length === 0) {
|
||||
pending.push(payload);
|
||||
return;
|
||||
}
|
||||
for (const listener of listeners) {
|
||||
listener(payload);
|
||||
}
|
||||
};
|
||||
|
||||
ipcRenderer.on(channel, (_event: IpcRendererEvent, payloadArg: unknown) => {
|
||||
dispatch(normalize(payloadArg));
|
||||
});
|
||||
|
||||
return (listener: PayloadedListener<T>): void => {
|
||||
listeners.push(listener);
|
||||
while (pending.length > 0) {
|
||||
const payload = pending.shift();
|
||||
listener(payload as T);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createLatestValueIpcListenerWithPayload<T>(
|
||||
channel: string,
|
||||
normalize: (payload: unknown) => T,
|
||||
): (listener: PayloadedListener<T>) => void {
|
||||
let pending: T | undefined;
|
||||
const listeners: PayloadedListener<T>[] = [];
|
||||
|
||||
const dispatch = (payload: T): void => {
|
||||
if (listeners.length === 0) {
|
||||
pending = payload;
|
||||
return;
|
||||
}
|
||||
for (const listener of listeners) {
|
||||
listener(payload);
|
||||
}
|
||||
};
|
||||
|
||||
ipcRenderer.on(channel, (_event: IpcRendererEvent, payloadArg: unknown) => {
|
||||
dispatch(normalize(payloadArg));
|
||||
});
|
||||
|
||||
return (listener: PayloadedListener<T>): void => {
|
||||
listeners.push(listener);
|
||||
if (pending !== undefined) {
|
||||
const payload = pending;
|
||||
pending = undefined;
|
||||
listener(payload);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const onOpenRuntimeOptionsEvent = createQueuedIpcListener(IPC_CHANNELS.event.runtimeOptionsOpen);
|
||||
const onOpenSessionHelpEvent = createQueuedIpcListenerWithPayload<SessionHelpOpenPayload>(
|
||||
IPC_CHANNELS.event.sessionHelpOpen,
|
||||
|
||||
Reference in new issue
Block a user