mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-10 04:46:07 -08:00
* refactor(main): drop remaining pass-through main-deps builders Jellyfin client-info/setup-window/remote, overlay shortcuts/visibility/ layout/window-factory, config hot-reload, and startup bootstrap factory builders only forwarded deps. Callers now pass deps to the handlers directly; createWatchConfigPathHandler moves into config-hot-reload-handlers. * refactor(main): fold small-logic main-deps builders into their handlers Tray click, mpv client factory, startup bootstrap exit callbacks, overlay runtime options, and dictionary roots/runtime builders move their logic into the owning handler or call site. The two duplicated dictionary-root builders become one createBuildDictionaryRootsHandler(vendorDirName). * refactor(main): fold cli command context builders into the factory createCliCommandContextFactory now adapts appState and main services to the CLI command context deps directly (socket-path change notification, texthooker port/websocket URL, browser-open default). The pass-through cli-command-context-main-deps and cli-command-context-deps layers are removed; their behavioural tests now run against the factory's context. * refactor(main): fold subtitle tokenization builder into the mpv composer The tokenizer deps builder's logic (known-word lookup recording and the character-dictionary gate on name matching) becomes buildTokenizerRuntimeOptions in mpv-runtime-composer, tested through the composer. The MeCab check and dictionary prewarm handlers move to subtitle-tokenization-warmup.ts, and the unused BuiltMainDeps type is removed from composer contracts. * refactor(main): drop redundant tokenizer deps keys and cast * refactor(main): end the main-deps builder pattern mpv-main-event-main-deps becomes mpv-main-event-binding-deps (createMpvMainEventBindingDeps), returning the binding deps directly instead of a thunk; it owns the subtitle-recording state. The will-quit cleanup adapter likewise returns its deps directly, and the pass-through app-lifecycle activate builders are removed. * docs: drop references to main-deps builders
99 lines
3.0 KiB
TypeScript
99 lines
3.0 KiB
TypeScript
type TrayIconLike = {
|
|
isEmpty: () => boolean;
|
|
resize: (options: {
|
|
width: number;
|
|
height: number;
|
|
quality?: 'best' | 'better' | 'good';
|
|
}) => TrayIconLike;
|
|
setTemplateImage: (enabled: boolean) => void;
|
|
};
|
|
|
|
type TrayLike = {
|
|
setContextMenu: (menu: any) => void;
|
|
setToolTip: (tooltip: string) => void;
|
|
on: (event: 'click', handler: () => void) => void;
|
|
destroy: () => void;
|
|
};
|
|
|
|
export function createEnsureTrayHandler(deps: {
|
|
getTray: () => TrayLike | null;
|
|
setTray: (tray: TrayLike | null) => void;
|
|
buildTrayMenu: () => any;
|
|
resolveTrayIconPath: () => string | null;
|
|
createImageFromPath: (iconPath: string) => TrayIconLike;
|
|
createEmptyImage: () => TrayIconLike;
|
|
createTray: (icon: TrayIconLike) => TrayLike;
|
|
trayTooltip: string;
|
|
platform: string;
|
|
logWarn: (message: string) => void;
|
|
ensureOverlayVisibleFromTrayClick: () => void;
|
|
}) {
|
|
return (): void => {
|
|
const existingTray = deps.getTray();
|
|
if (existingTray) {
|
|
existingTray.setContextMenu(deps.buildTrayMenu());
|
|
return;
|
|
}
|
|
|
|
const iconPath = deps.resolveTrayIconPath();
|
|
let trayIcon = iconPath ? deps.createImageFromPath(iconPath) : deps.createEmptyImage();
|
|
if (trayIcon.isEmpty()) {
|
|
deps.logWarn('Tray icon asset not found; using empty icon placeholder.');
|
|
}
|
|
if (deps.platform === 'darwin' && !trayIcon.isEmpty()) {
|
|
trayIcon = trayIcon.resize({ width: 18, height: 18, quality: 'best' });
|
|
trayIcon.setTemplateImage(true);
|
|
}
|
|
if (deps.platform === 'linux' && !trayIcon.isEmpty()) {
|
|
trayIcon = trayIcon.resize({ width: 20, height: 20 });
|
|
}
|
|
|
|
let tray: TrayLike;
|
|
try {
|
|
tray = deps.createTray(trayIcon);
|
|
} catch (error) {
|
|
const reason = error instanceof Error ? error.message : String(error);
|
|
if (deps.platform === 'linux') {
|
|
deps.logWarn(
|
|
`Unable to create Linux tray icon. Ensure your desktop has a StatusNotifier/AppIndicator tray host. ${reason}`,
|
|
);
|
|
} else {
|
|
deps.logWarn(`Unable to create tray icon. ${reason}`);
|
|
}
|
|
return;
|
|
}
|
|
tray.setToolTip(deps.trayTooltip);
|
|
tray.setContextMenu(deps.buildTrayMenu());
|
|
tray.on('click', () => {
|
|
deps.ensureOverlayVisibleFromTrayClick();
|
|
});
|
|
deps.setTray(tray);
|
|
};
|
|
}
|
|
|
|
export function createDestroyTrayHandler(deps: {
|
|
getTray: () => TrayLike | null;
|
|
setTray: (tray: TrayLike | null) => void;
|
|
}) {
|
|
return (): void => {
|
|
const tray = deps.getTray();
|
|
if (!tray) return;
|
|
tray.destroy();
|
|
deps.setTray(null);
|
|
};
|
|
}
|
|
|
|
// Tray icon click: boot the overlay runtime on first use, then show the visible overlay.
|
|
export function createEnsureOverlayVisibleFromTrayClickHandler(deps: {
|
|
isOverlayRuntimeInitialized: () => boolean;
|
|
initializeOverlayRuntime: () => void;
|
|
setVisibleOverlayVisible: (visible: boolean) => void;
|
|
}) {
|
|
return (): void => {
|
|
if (!deps.isOverlayRuntimeInitialized()) {
|
|
deps.initializeOverlayRuntime();
|
|
}
|
|
deps.setVisibleOverlayVisible(true);
|
|
};
|
|
}
|