mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
6eda768261
|
|||
|
ceea10cba1
|
|||
|
9d73971f3b
|
|||
|
a2735eaedc
|
|||
|
b989508ece
|
|||
|
978cb8c401
|
@@ -2,9 +2,11 @@ project_name: "SubMiner"
|
|||||||
default_status: "To Do"
|
default_status: "To Do"
|
||||||
statuses: ["To Do", "In Progress", "Done"]
|
statuses: ["To Do", "In Progress", "Done"]
|
||||||
labels: []
|
labels: []
|
||||||
|
definition_of_done: []
|
||||||
date_format: yyyy-mm-dd
|
date_format: yyyy-mm-dd
|
||||||
max_column_width: 20
|
max_column_width: 20
|
||||||
auto_open_browser: true
|
default_editor: "nvim"
|
||||||
|
auto_open_browser: false
|
||||||
default_port: 6420
|
default_port: 6420
|
||||||
remote_operations: true
|
remote_operations: true
|
||||||
auto_commit: false
|
auto_commit: false
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ export default {
|
|||||||
],
|
],
|
||||||
appearance: 'dark',
|
appearance: 'dark',
|
||||||
cleanUrls: true,
|
cleanUrls: true,
|
||||||
|
metaChunk: true,
|
||||||
|
sitemap: { hostname: 'https://docs.subminer.moe' },
|
||||||
lastUpdated: true,
|
lastUpdated: true,
|
||||||
srcExclude: ['subagents/**'],
|
srcExclude: ['subagents/**'],
|
||||||
markdown: {
|
markdown: {
|
||||||
@@ -94,6 +96,18 @@ export default {
|
|||||||
search: {
|
search: {
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
},
|
},
|
||||||
|
footer: {
|
||||||
|
message: 'Released under the GPL-3.0 License.',
|
||||||
|
copyright: 'Copyright © 2026-present sudacode',
|
||||||
|
},
|
||||||
|
editLink: {
|
||||||
|
pattern: 'https://github.com/ksyasuda/SubMiner/edit/main/docs/:path',
|
||||||
|
text: 'Edit this page on GitHub',
|
||||||
|
},
|
||||||
|
outline: { level: [2, 3], label: 'On this page' },
|
||||||
|
externalLinkIcon: true,
|
||||||
|
docFooter: { prev: 'Previous', next: 'Next' },
|
||||||
|
returnToTopLabel: 'Back to top',
|
||||||
socialLinks: [{ icon: 'github', link: 'https://github.com/ksyasuda/SubMiner' }],
|
socialLinks: [{ icon: 'github', link: 'https://github.com/ksyasuda/SubMiner' }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -450,6 +450,8 @@ Setup flow details:
|
|||||||
2. Leave `anilist.accessToken` empty and restart SubMiner (or run `--anilist-setup`) to trigger setup.
|
2. Leave `anilist.accessToken` empty and restart SubMiner (or run `--anilist-setup`) to trigger setup.
|
||||||
3. Approve access in AniList.
|
3. Approve access in AniList.
|
||||||
4. Callback flow returns to SubMiner via `subminer://anilist-setup?...`, and SubMiner stores the token automatically.
|
4. Callback flow returns to SubMiner via `subminer://anilist-setup?...`, and SubMiner stores the token automatically.
|
||||||
|
- Encryption backend: Linux defaults to `gnome-libsecret`.
|
||||||
|
Override with `--password-store=<backend>` (for example `--password-store=basic_text`).
|
||||||
|
|
||||||
Token + detection notes:
|
Token + detection notes:
|
||||||
|
|
||||||
@@ -506,6 +508,7 @@ Jellyfin integration is optional and disabled by default. When enabled, SubMiner
|
|||||||
| `transcodeVideoCodec` | string | Preferred transcode video codec fallback (default: `h264`) |
|
| `transcodeVideoCodec` | string | Preferred transcode video codec fallback (default: `h264`) |
|
||||||
|
|
||||||
Jellyfin auth session (`accessToken` + `userId`) is stored in local encrypted storage after login/setup.
|
Jellyfin auth session (`accessToken` + `userId`) is stored in local encrypted storage after login/setup.
|
||||||
|
- On Linux, token storage defaults to `gnome-libsecret` for `safeStorage`. Override with `--password-store=<backend>` on launcher/app invocations when needed.
|
||||||
|
|
||||||
Launcher subcommands:
|
Launcher subcommands:
|
||||||
|
|
||||||
@@ -514,6 +517,7 @@ Launcher subcommands:
|
|||||||
- `subminer jellyfin --logout` clears stored credentials.
|
- `subminer jellyfin --logout` clears stored credentials.
|
||||||
- `subminer jellyfin -p` opens play picker.
|
- `subminer jellyfin -p` opens play picker.
|
||||||
- `subminer jellyfin -d` starts cast discovery mode.
|
- `subminer jellyfin -d` starts cast discovery mode.
|
||||||
|
- These launcher commands also accept `--password-store=<backend>` to override the launcher-app forwarded Electron switch.
|
||||||
|
|
||||||
See [Jellyfin Integration](/jellyfin-integration) for the full setup and cast-to-device guide.
|
See [Jellyfin Integration](/jellyfin-integration) for the full setup and cast-to-device guide.
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ SubMiner includes an optional Jellyfin CLI integration for:
|
|||||||
|
|
||||||
- Jellyfin server URL and user credentials
|
- Jellyfin server URL and user credentials
|
||||||
- For `--jellyfin-play`: connected mpv IPC socket (`--start` or existing mpv plugin workflow)
|
- For `--jellyfin-play`: connected mpv IPC socket (`--start` or existing mpv plugin workflow)
|
||||||
|
- On Linux, token encryption defaults to `gnome-libsecret`; pass `--password-store=<backend>` to override.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
@@ -150,6 +151,7 @@ User-visible errors are shown through CLI logs and mpv OSD for:
|
|||||||
## Security Notes and Limitations
|
## Security Notes and Limitations
|
||||||
|
|
||||||
- Jellyfin auth session (`accessToken` + `userId`) is stored in local encrypted token storage after login/setup.
|
- Jellyfin auth session (`accessToken` + `userId`) is stored in local encrypted token storage after login/setup.
|
||||||
|
- Launcher wrappers support `--password-store=<backend>` and forward it through to the app process.
|
||||||
- Optional environment overrides are supported: `SUBMINER_JELLYFIN_ACCESS_TOKEN` and `SUBMINER_JELLYFIN_USER_ID`.
|
- Optional environment overrides are supported: `SUBMINER_JELLYFIN_ACCESS_TOKEN` and `SUBMINER_JELLYFIN_USER_ID`.
|
||||||
- Treat both token storage and config files as secrets and avoid committing them.
|
- Treat both token storage and config files as secrets and avoid committing them.
|
||||||
- Password is used only for login and is not stored.
|
- Password is used only for login and is not stored.
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ SubMiner.AppImage --help # Show all options
|
|||||||
- `--background` defaults to quieter logging (`warn`) unless `--log-level` is set.
|
- `--background` defaults to quieter logging (`warn`) unless `--log-level` is set.
|
||||||
- `--background` launched from a terminal detaches and returns the prompt; stop it with tray Quit or `SubMiner.AppImage --stop`.
|
- `--background` launched from a terminal detaches and returns the prompt; stop it with tray Quit or `SubMiner.AppImage --stop`.
|
||||||
- Linux desktop launcher starts SubMiner with `--background` by default (via electron-builder `linux.executableArgs`).
|
- Linux desktop launcher starts SubMiner with `--background` by default (via electron-builder `linux.executableArgs`).
|
||||||
|
- On Linux, the app now defaults `safeStorage` to `gnome-libsecret` for encrypted token persistence.
|
||||||
|
Launcher pass-through commands also support `--password-store=<backend>` and forward it to the app when present.
|
||||||
|
Override with e.g. `--password-store=basic_text`.
|
||||||
- Use both when needed, for example `SubMiner.AppImage --start --dev --log-level debug`.
|
- Use both when needed, for example `SubMiner.AppImage --start --dev --log-level debug`.
|
||||||
|
|
||||||
### Launcher Subcommands
|
### Launcher Subcommands
|
||||||
|
|||||||
@@ -10,9 +10,16 @@ export async function runJellyfinCommand(context: LauncherCommandContext): Promi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const appendPasswordStore = (forwarded: string[]): void => {
|
||||||
|
if (args.passwordStore) {
|
||||||
|
forwarded.push('--password-store', args.passwordStore);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (args.jellyfin) {
|
if (args.jellyfin) {
|
||||||
const forwarded = ['--jellyfin'];
|
const forwarded = ['--jellyfin'];
|
||||||
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
||||||
|
appendPasswordStore(forwarded);
|
||||||
runAppCommandWithInherit(appPath, forwarded);
|
runAppCommandWithInherit(appPath, forwarded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,12 +42,14 @@ export async function runJellyfinCommand(context: LauncherCommandContext): Promi
|
|||||||
password,
|
password,
|
||||||
];
|
];
|
||||||
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
||||||
|
appendPasswordStore(forwarded);
|
||||||
runAppCommandWithInherit(appPath, forwarded);
|
runAppCommandWithInherit(appPath, forwarded);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.jellyfinLogout) {
|
if (args.jellyfinLogout) {
|
||||||
const forwarded = ['--jellyfin-logout'];
|
const forwarded = ['--jellyfin-logout'];
|
||||||
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
||||||
|
appendPasswordStore(forwarded);
|
||||||
runAppCommandWithInherit(appPath, forwarded);
|
runAppCommandWithInherit(appPath, forwarded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +67,7 @@ export async function runJellyfinCommand(context: LauncherCommandContext): Promi
|
|||||||
if (args.jellyfinDiscovery) {
|
if (args.jellyfinDiscovery) {
|
||||||
const forwarded = ['--start'];
|
const forwarded = ['--start'];
|
||||||
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
||||||
|
appendPasswordStore(forwarded);
|
||||||
runAppCommandWithInherit(appPath, forwarded);
|
runAppCommandWithInherit(appPath, forwarded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ export function createDefaultArgs(launcherConfig: LauncherYoutubeSubgenConfig):
|
|||||||
texthookerOnly: false,
|
texthookerOnly: false,
|
||||||
useRofi: false,
|
useRofi: false,
|
||||||
logLevel: 'info',
|
logLevel: 'info',
|
||||||
|
passwordStore: '',
|
||||||
target: '',
|
target: '',
|
||||||
targetKind: '',
|
targetKind: '',
|
||||||
};
|
};
|
||||||
@@ -161,6 +162,7 @@ export function applyRootOptionsToArgs(
|
|||||||
if (typeof options.profile === 'string') parsed.profile = options.profile;
|
if (typeof options.profile === 'string') parsed.profile = options.profile;
|
||||||
if (options.start === true) parsed.startOverlay = true;
|
if (options.start === true) parsed.startOverlay = true;
|
||||||
if (typeof options.logLevel === 'string') parsed.logLevel = parseLogLevel(options.logLevel);
|
if (typeof options.logLevel === 'string') parsed.logLevel = parseLogLevel(options.logLevel);
|
||||||
|
if (typeof options.passwordStore === 'string') parsed.passwordStore = options.passwordStore;
|
||||||
if (options.rofi === true) parsed.useRofi = true;
|
if (options.rofi === true) parsed.useRofi = true;
|
||||||
if (options.startOverlay === true) parsed.autoStartOverlay = true;
|
if (options.startOverlay === true) parsed.autoStartOverlay = true;
|
||||||
if (options.texthooker === false) parsed.useTexthooker = false;
|
if (options.texthooker === false) parsed.useTexthooker = false;
|
||||||
@@ -175,6 +177,9 @@ export function applyInvocationsToArgs(parsed: Args, invocations: CliInvocations
|
|||||||
if (invocations.jellyfinInvocation.logLevel) {
|
if (invocations.jellyfinInvocation.logLevel) {
|
||||||
parsed.logLevel = parseLogLevel(invocations.jellyfinInvocation.logLevel);
|
parsed.logLevel = parseLogLevel(invocations.jellyfinInvocation.logLevel);
|
||||||
}
|
}
|
||||||
|
if (typeof invocations.jellyfinInvocation.passwordStore === 'string') {
|
||||||
|
parsed.passwordStore = invocations.jellyfinInvocation.passwordStore;
|
||||||
|
}
|
||||||
const action = (invocations.jellyfinInvocation.action || '').toLowerCase();
|
const action = (invocations.jellyfinInvocation.action || '').toLowerCase();
|
||||||
if (action && !['setup', 'discovery', 'play', 'login', 'logout'].includes(action)) {
|
if (action && !['setup', 'discovery', 'play', 'login', 'logout'].includes(action)) {
|
||||||
fail(`Unknown jellyfin action: ${invocations.jellyfinInvocation.action}`);
|
fail(`Unknown jellyfin action: ${invocations.jellyfinInvocation.action}`);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export interface JellyfinInvocation {
|
|||||||
server?: string;
|
server?: string;
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
|
passwordStore?: string;
|
||||||
logLevel?: string;
|
logLevel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +169,7 @@ export function parseCliPrograms(
|
|||||||
.option('-s, --server <url>', 'Jellyfin server URL')
|
.option('-s, --server <url>', 'Jellyfin server URL')
|
||||||
.option('-u, --username <name>', 'Jellyfin username')
|
.option('-u, --username <name>', 'Jellyfin username')
|
||||||
.option('-w, --password <pass>', 'Jellyfin password')
|
.option('-w, --password <pass>', 'Jellyfin password')
|
||||||
|
.option('--password-store <backend>', 'Pass through Electron safeStorage backend')
|
||||||
.option('--log-level <level>', 'Log level')
|
.option('--log-level <level>', 'Log level')
|
||||||
.action((action: string | undefined, options: Record<string, unknown>) => {
|
.action((action: string | undefined, options: Record<string, unknown>) => {
|
||||||
jellyfinInvocation = {
|
jellyfinInvocation = {
|
||||||
@@ -180,6 +182,7 @@ export function parseCliPrograms(
|
|||||||
server: typeof options.server === 'string' ? options.server : undefined,
|
server: typeof options.server === 'string' ? options.server : undefined,
|
||||||
username: typeof options.username === 'string' ? options.username : undefined,
|
username: typeof options.username === 'string' ? options.username : undefined,
|
||||||
password: typeof options.password === 'string' ? options.password : undefined,
|
password: typeof options.password === 'string' ? options.password : undefined,
|
||||||
|
passwordStore: typeof options.passwordStore === 'string' ? options.passwordStore : undefined,
|
||||||
logLevel: typeof options.logLevel === 'string' ? options.logLevel : undefined,
|
logLevel: typeof options.logLevel === 'string' ? options.logLevel : undefined,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -395,5 +395,6 @@ export async function runJellyfinPlayMenu(
|
|||||||
}
|
}
|
||||||
const forwarded = ['--start', '--jellyfin-play', '--jellyfin-item-id', itemId];
|
const forwarded = ['--start', '--jellyfin-play', '--jellyfin-item-id', itemId];
|
||||||
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
if (args.logLevel !== 'info') forwarded.push('--log-level', args.logLevel);
|
||||||
|
if (args.passwordStore) forwarded.push('--password-store', args.passwordStore);
|
||||||
runAppCommandWithInheritLogged(appPath, forwarded, args.logLevel, 'jellyfin-play');
|
runAppCommandWithInheritLogged(appPath, forwarded, args.logLevel, 'jellyfin-play');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,3 +207,33 @@ test('jellyfin login routes credentials to app command', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('jellyfin setup forwards password-store to app command', () => {
|
||||||
|
withTempDir((root) => {
|
||||||
|
const homeDir = path.join(root, 'home');
|
||||||
|
const xdgConfigHome = path.join(root, 'xdg');
|
||||||
|
const appPath = path.join(root, 'fake-subminer.sh');
|
||||||
|
const capturePath = path.join(root, 'captured-args.txt');
|
||||||
|
fs.writeFileSync(
|
||||||
|
appPath,
|
||||||
|
'#!/bin/sh\nif [ -n "$SUBMINER_TEST_CAPTURE" ]; then printf "%s\\n" "$@" > "$SUBMINER_TEST_CAPTURE"; fi\nexit 0\n',
|
||||||
|
);
|
||||||
|
fs.chmodSync(appPath, 0o755);
|
||||||
|
|
||||||
|
const env = {
|
||||||
|
...makeTestEnv(homeDir, xdgConfigHome),
|
||||||
|
SUBMINER_APPIMAGE_PATH: appPath,
|
||||||
|
SUBMINER_TEST_CAPTURE: capturePath,
|
||||||
|
};
|
||||||
|
const result = runLauncher(
|
||||||
|
['jf', 'setup', '--password-store', 'gnome-libsecret'],
|
||||||
|
env,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(result.status, 0);
|
||||||
|
assert.equal(
|
||||||
|
fs.readFileSync(capturePath, 'utf8'),
|
||||||
|
'--jellyfin\n--password-store\ngnome-libsecret\n',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -30,6 +30,17 @@ test('parseArgs maps jellyfin play action and log-level override', () => {
|
|||||||
assert.equal(parsed.logLevel, 'debug');
|
assert.equal(parsed.logLevel, 'debug');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('parseArgs forwards jellyfin password-store option', () => {
|
||||||
|
const parsed = parseArgs(
|
||||||
|
['jf', 'setup', '--password-store', 'gnome-libsecret'],
|
||||||
|
'subminer',
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(parsed.jellyfin, true);
|
||||||
|
assert.equal(parsed.passwordStore, 'gnome-libsecret');
|
||||||
|
});
|
||||||
|
|
||||||
test('parseArgs maps config show action', () => {
|
test('parseArgs maps config show action', () => {
|
||||||
const parsed = parseArgs(['config', 'show'], 'subminer', {});
|
const parsed = parseArgs(['config', 'show'], 'subminer', {});
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ export interface Args {
|
|||||||
texthookerOnly: boolean;
|
texthookerOnly: boolean;
|
||||||
useRofi: boolean;
|
useRofi: boolean;
|
||||||
logLevel: LogLevel;
|
logLevel: LogLevel;
|
||||||
|
passwordStore: string;
|
||||||
target: string;
|
target: string;
|
||||||
targetKind: '' | 'file' | 'url';
|
targetKind: '' | 'file' | 'url';
|
||||||
jimakuApiKey: string;
|
jimakuApiKey: string;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "subminer",
|
"name": "subminer",
|
||||||
"version": "0.1.0",
|
"version": "0.1.2",
|
||||||
"description": "All-in-one sentence mining overlay with AnkiConnect and dictionary integration",
|
"description": "All-in-one sentence mining overlay with AnkiConnect and dictionary integration",
|
||||||
"packageManager": "bun@1.3.5",
|
"packageManager": "bun@1.3.5",
|
||||||
"main": "dist/main-entry.js",
|
"main": "dist/main-entry.js",
|
||||||
|
|||||||
@@ -30,10 +30,18 @@ function createStorage(encryptionAvailable: boolean): SafeStorageLike {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createPassthroughStorage(): SafeStorageLike {
|
||||||
|
return {
|
||||||
|
isEncryptionAvailable: () => true,
|
||||||
|
encryptString: (value: string) => Buffer.from(value, 'utf-8'),
|
||||||
|
decryptString: (value: Buffer) => value.toString('utf-8'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
test('anilist token store saves and loads encrypted token', () => {
|
test('anilist token store saves and loads encrypted token', () => {
|
||||||
const filePath = createTempTokenFile();
|
const filePath = createTempTokenFile();
|
||||||
const store = createAnilistTokenStore(filePath, createLogger(), createStorage(true));
|
const store = createAnilistTokenStore(filePath, createLogger(), createStorage(true));
|
||||||
store.saveToken(' demo-token ');
|
assert.equal(store.saveToken(' demo-token '), true);
|
||||||
|
|
||||||
const payload = JSON.parse(fs.readFileSync(filePath, 'utf-8')) as {
|
const payload = JSON.parse(fs.readFileSync(filePath, 'utf-8')) as {
|
||||||
encryptedToken?: string;
|
encryptedToken?: string;
|
||||||
@@ -44,16 +52,13 @@ test('anilist token store saves and loads encrypted token', () => {
|
|||||||
assert.equal(store.loadToken(), 'demo-token');
|
assert.equal(store.loadToken(), 'demo-token');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('anilist token store falls back to plaintext when encryption unavailable', () => {
|
test('anilist token store refuses to persist token when encryption unavailable', () => {
|
||||||
const filePath = createTempTokenFile();
|
const filePath = createTempTokenFile();
|
||||||
const store = createAnilistTokenStore(filePath, createLogger(), createStorage(false));
|
const store = createAnilistTokenStore(filePath, createLogger(), createStorage(false));
|
||||||
store.saveToken('plain-token');
|
assert.equal(store.saveToken('plain-token'), false);
|
||||||
|
|
||||||
const payload = JSON.parse(fs.readFileSync(filePath, 'utf-8')) as {
|
assert.equal(fs.existsSync(filePath), false);
|
||||||
plaintextToken?: string;
|
assert.equal(store.loadToken(), null);
|
||||||
};
|
|
||||||
assert.equal(payload.plaintextToken, 'plain-token');
|
|
||||||
assert.equal(store.loadToken(), 'plain-token');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('anilist token store migrates legacy plaintext to encrypted', () => {
|
test('anilist token store migrates legacy plaintext to encrypted', () => {
|
||||||
@@ -75,6 +80,13 @@ test('anilist token store migrates legacy plaintext to encrypted', () => {
|
|||||||
assert.equal(payload.plaintextToken, undefined);
|
assert.equal(payload.plaintextToken, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('anilist token store refuses passthrough safeStorage implementation', () => {
|
||||||
|
const filePath = createTempTokenFile();
|
||||||
|
const store = createAnilistTokenStore(filePath, createLogger(), createPassthroughStorage());
|
||||||
|
assert.equal(store.saveToken('demo-token'), false);
|
||||||
|
assert.equal(store.loadToken(), null);
|
||||||
|
});
|
||||||
|
|
||||||
test('anilist token store clears persisted token file', () => {
|
test('anilist token store clears persisted token file', () => {
|
||||||
const filePath = createTempTokenFile();
|
const filePath = createTempTokenFile();
|
||||||
const store = createAnilistTokenStore(filePath, createLogger(), createStorage(true));
|
const store = createAnilistTokenStore(filePath, createLogger(), createStorage(true));
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ interface PersistedTokenPayload {
|
|||||||
|
|
||||||
export interface AnilistTokenStore {
|
export interface AnilistTokenStore {
|
||||||
loadToken: () => string | null;
|
loadToken: () => string | null;
|
||||||
saveToken: (token: string) => void;
|
saveToken: (token: string) => boolean;
|
||||||
clearToken: () => void;
|
clearToken: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ export interface SafeStorageLike {
|
|||||||
isEncryptionAvailable: () => boolean;
|
isEncryptionAvailable: () => boolean;
|
||||||
encryptString: (value: string) => Buffer;
|
encryptString: (value: string) => Buffer;
|
||||||
decryptString: (value: Buffer) => string;
|
decryptString: (value: Buffer) => string;
|
||||||
|
getSelectedStorageBackend?: () => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureDirectory(filePath: string): void {
|
function ensureDirectory(filePath: string): void {
|
||||||
@@ -38,9 +39,80 @@ export function createAnilistTokenStore(
|
|||||||
info: (message: string) => void;
|
info: (message: string) => void;
|
||||||
warn: (message: string, details?: unknown) => void;
|
warn: (message: string, details?: unknown) => void;
|
||||||
error: (message: string, details?: unknown) => void;
|
error: (message: string, details?: unknown) => void;
|
||||||
|
warnUser?: (message: string) => void;
|
||||||
},
|
},
|
||||||
storage: SafeStorageLike = electron.safeStorage,
|
storage: SafeStorageLike = electron.safeStorage,
|
||||||
): AnilistTokenStore {
|
): AnilistTokenStore {
|
||||||
|
let safeStorageUsable: boolean | null = null;
|
||||||
|
|
||||||
|
const getSelectedBackend = (): string => {
|
||||||
|
if (typeof storage.getSelectedStorageBackend !== 'function') {
|
||||||
|
return 'unsupported';
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return storage.getSelectedStorageBackend();
|
||||||
|
} catch {
|
||||||
|
return 'error';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSafeStorageDebugContext = (): string =>
|
||||||
|
JSON.stringify({
|
||||||
|
platform: process.platform,
|
||||||
|
dbusSession: process.env.DBUS_SESSION_BUS_ADDRESS,
|
||||||
|
xdgRuntimeDir: process.env.XDG_RUNTIME_DIR,
|
||||||
|
display: process.env.DISPLAY,
|
||||||
|
waylandDisplay: process.env.WAYLAND_DISPLAY,
|
||||||
|
hasDefaultApp: Boolean(process.defaultApp),
|
||||||
|
selectedSafeStorageBackend: getSelectedBackend(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const isSafeStorageUsable = (): boolean => {
|
||||||
|
if (safeStorageUsable != null) return safeStorageUsable;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!storage.isEncryptionAvailable()) {
|
||||||
|
notifyUser(
|
||||||
|
`AniList token encryption unavailable: safeStorage.isEncryptionAvailable() is false. ` +
|
||||||
|
`Context: ${getSafeStorageDebugContext()}`,
|
||||||
|
);
|
||||||
|
safeStorageUsable = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const probe = storage.encryptString('__subminer_anilist_probe__');
|
||||||
|
if (probe.equals(Buffer.from('__subminer_anilist_probe__'))) {
|
||||||
|
notifyUser(
|
||||||
|
'AniList token encryption probe failed: safeStorage.encryptString() returned plaintext bytes.',
|
||||||
|
);
|
||||||
|
safeStorageUsable = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const roundTrip = storage.decryptString(probe);
|
||||||
|
if (roundTrip !== '__subminer_anilist_probe__') {
|
||||||
|
notifyUser(
|
||||||
|
'AniList token encryption probe failed: encrypt/decrypt round trip returned unexpected content.',
|
||||||
|
);
|
||||||
|
safeStorageUsable = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
safeStorageUsable = true;
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('AniList token encryption probe failed.', error);
|
||||||
|
notifyUser(
|
||||||
|
`AniList token encryption unavailable: safeStorage probe threw an error. ` +
|
||||||
|
`Context: ${getSafeStorageDebugContext()}`,
|
||||||
|
);
|
||||||
|
safeStorageUsable = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const notifyUser = (message: string): void => {
|
||||||
|
logger.warn(message);
|
||||||
|
logger.warnUser?.(message);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loadToken(): string | null {
|
loadToken(): string | null {
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
@@ -51,18 +123,33 @@ export function createAnilistTokenStore(
|
|||||||
const parsed = JSON.parse(raw) as PersistedTokenPayload;
|
const parsed = JSON.parse(raw) as PersistedTokenPayload;
|
||||||
if (typeof parsed.encryptedToken === 'string' && parsed.encryptedToken.length > 0) {
|
if (typeof parsed.encryptedToken === 'string' && parsed.encryptedToken.length > 0) {
|
||||||
const encrypted = Buffer.from(parsed.encryptedToken, 'base64');
|
const encrypted = Buffer.from(parsed.encryptedToken, 'base64');
|
||||||
if (!storage.isEncryptionAvailable()) {
|
if (!isSafeStorageUsable()) {
|
||||||
logger.warn('AniList token encryption is not available on this system.');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const decrypted = storage.decryptString(encrypted).trim();
|
const decrypted = storage.decryptString(encrypted).trim();
|
||||||
return decrypted.length > 0 ? decrypted : null;
|
if (decrypted.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return decrypted;
|
||||||
}
|
}
|
||||||
if (typeof parsed.plaintextToken === 'string' && parsed.plaintextToken.trim().length > 0) {
|
if (
|
||||||
// Legacy fallback: migrate plaintext token to encrypted storage on load.
|
typeof parsed.plaintextToken === 'string' &&
|
||||||
const plaintext = parsed.plaintextToken.trim();
|
parsed.plaintextToken.trim().length > 0
|
||||||
this.saveToken(plaintext);
|
) {
|
||||||
return plaintext;
|
if (storage.isEncryptionAvailable()) {
|
||||||
|
if (!isSafeStorageUsable()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const plaintext = parsed.plaintextToken.trim();
|
||||||
|
notifyUser('AniList token plaintext fallback payload found. Migrating to encrypted storage.');
|
||||||
|
this.saveToken(plaintext);
|
||||||
|
return plaintext;
|
||||||
|
}
|
||||||
|
notifyUser(
|
||||||
|
'AniList token plaintext was found but ignored because safe storage is unavailable.',
|
||||||
|
);
|
||||||
|
this.clearToken();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to read AniList token store.', error);
|
logger.error('Failed to read AniList token store.', error);
|
||||||
@@ -70,28 +157,28 @@ export function createAnilistTokenStore(
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
saveToken(token: string): void {
|
saveToken(token: string): boolean {
|
||||||
const trimmed = token.trim();
|
const trimmed = token.trim();
|
||||||
if (trimmed.length === 0) {
|
if (trimmed.length === 0) {
|
||||||
this.clearToken();
|
this.clearToken();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!storage.isEncryptionAvailable()) {
|
if (!isSafeStorageUsable()) {
|
||||||
logger.warn('AniList token encryption unavailable; storing token in plaintext fallback.');
|
notifyUser(
|
||||||
writePayload(filePath, {
|
'AniList token encryption is unavailable; refusing to store access token. Re-login required after restart.',
|
||||||
plaintextToken: trimmed,
|
);
|
||||||
updatedAt: Date.now(),
|
return false;
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const encrypted = storage.encryptString(trimmed);
|
const encrypted = storage.encryptString(trimmed);
|
||||||
writePayload(filePath, {
|
writePayload(filePath, {
|
||||||
encryptedToken: encrypted.toString('base64'),
|
encryptedToken: encrypted.toString('base64'),
|
||||||
updatedAt: Date.now(),
|
updatedAt: Date.now(),
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to persist AniList token.', error);
|
logger.error('Failed to persist AniList token.', error);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -233,5 +233,6 @@ test('registerIpcHandlers ignores malformed fire-and-forget payloads', () => {
|
|||||||
|
|
||||||
handlers.on.get(IPC_CHANNELS.command.overlayModalClosed)!({}, 'not-a-modal');
|
handlers.on.get(IPC_CHANNELS.command.overlayModalClosed)!({}, 'not-a-modal');
|
||||||
handlers.on.get(IPC_CHANNELS.command.overlayModalClosed)!({}, 'subsync');
|
handlers.on.get(IPC_CHANNELS.command.overlayModalClosed)!({}, 'subsync');
|
||||||
assert.deepEqual(modals, ['subsync']);
|
handlers.on.get(IPC_CHANNELS.command.overlayModalClosed)!({}, 'kiku');
|
||||||
|
assert.deepEqual(modals, ['subsync', 'kiku']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ export function createFieldGroupingCallbackRuntime<T extends string>(options: {
|
|||||||
getResolver: options.getResolver,
|
getResolver: options.getResolver,
|
||||||
setResolver: options.setResolver,
|
setResolver: options.setResolver,
|
||||||
sendRequestToVisibleOverlay: (data) =>
|
sendRequestToVisibleOverlay: (data) =>
|
||||||
options.sendToVisibleOverlay('kiku:field-grouping-request', data),
|
options.sendToVisibleOverlay('kiku:field-grouping-request', data, {
|
||||||
|
restoreOnModalClose: 'kiku' as T,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ test('overlay manager initializes with empty windows and hidden overlays', () =>
|
|||||||
assert.equal(manager.getMainWindow(), null);
|
assert.equal(manager.getMainWindow(), null);
|
||||||
assert.equal(manager.getInvisibleWindow(), null);
|
assert.equal(manager.getInvisibleWindow(), null);
|
||||||
assert.equal(manager.getSecondaryWindow(), null);
|
assert.equal(manager.getSecondaryWindow(), null);
|
||||||
|
assert.equal(manager.getModalWindow(), null);
|
||||||
assert.equal(manager.getVisibleOverlayVisible(), false);
|
assert.equal(manager.getVisibleOverlayVisible(), false);
|
||||||
assert.equal(manager.getInvisibleOverlayVisible(), false);
|
assert.equal(manager.getInvisibleOverlayVisible(), false);
|
||||||
assert.deepEqual(manager.getOverlayWindows(), []);
|
assert.deepEqual(manager.getOverlayWindows(), []);
|
||||||
@@ -27,14 +28,19 @@ test('overlay manager stores window references and returns stable window order',
|
|||||||
const secondaryWindow = {
|
const secondaryWindow = {
|
||||||
isDestroyed: () => false,
|
isDestroyed: () => false,
|
||||||
} as unknown as Electron.BrowserWindow;
|
} as unknown as Electron.BrowserWindow;
|
||||||
|
const modalWindow = {
|
||||||
|
isDestroyed: () => false,
|
||||||
|
} as unknown as Electron.BrowserWindow;
|
||||||
|
|
||||||
manager.setMainWindow(visibleWindow);
|
manager.setMainWindow(visibleWindow);
|
||||||
manager.setInvisibleWindow(invisibleWindow);
|
manager.setInvisibleWindow(invisibleWindow);
|
||||||
manager.setSecondaryWindow(secondaryWindow);
|
manager.setSecondaryWindow(secondaryWindow);
|
||||||
|
manager.setModalWindow(modalWindow);
|
||||||
|
|
||||||
assert.equal(manager.getMainWindow(), visibleWindow);
|
assert.equal(manager.getMainWindow(), visibleWindow);
|
||||||
assert.equal(manager.getInvisibleWindow(), invisibleWindow);
|
assert.equal(manager.getInvisibleWindow(), invisibleWindow);
|
||||||
assert.equal(manager.getSecondaryWindow(), secondaryWindow);
|
assert.equal(manager.getSecondaryWindow(), secondaryWindow);
|
||||||
|
assert.equal(manager.getModalWindow(), modalWindow);
|
||||||
assert.equal(manager.getOverlayWindow('visible'), visibleWindow);
|
assert.equal(manager.getOverlayWindow('visible'), visibleWindow);
|
||||||
assert.equal(manager.getOverlayWindow('invisible'), invisibleWindow);
|
assert.equal(manager.getOverlayWindow('invisible'), invisibleWindow);
|
||||||
assert.deepEqual(manager.getOverlayWindows(), [visibleWindow, invisibleWindow, secondaryWindow]);
|
assert.deepEqual(manager.getOverlayWindows(), [visibleWindow, invisibleWindow, secondaryWindow]);
|
||||||
@@ -51,6 +57,9 @@ test('overlay manager excludes destroyed windows', () => {
|
|||||||
manager.setSecondaryWindow({
|
manager.setSecondaryWindow({
|
||||||
isDestroyed: () => true,
|
isDestroyed: () => true,
|
||||||
} as unknown as Electron.BrowserWindow);
|
} as unknown as Electron.BrowserWindow);
|
||||||
|
manager.setModalWindow({
|
||||||
|
isDestroyed: () => false,
|
||||||
|
} as unknown as Electron.BrowserWindow);
|
||||||
|
|
||||||
assert.equal(manager.getOverlayWindows().length, 1);
|
assert.equal(manager.getOverlayWindows().length, 1);
|
||||||
});
|
});
|
||||||
@@ -93,6 +102,10 @@ test('overlay manager broadcasts to non-destroyed windows', () => {
|
|||||||
manager.setMainWindow(aliveWindow);
|
manager.setMainWindow(aliveWindow);
|
||||||
manager.setInvisibleWindow(deadWindow);
|
manager.setInvisibleWindow(deadWindow);
|
||||||
manager.setSecondaryWindow(secondaryWindow);
|
manager.setSecondaryWindow(secondaryWindow);
|
||||||
|
manager.setModalWindow({
|
||||||
|
isDestroyed: () => false,
|
||||||
|
webContents: { send: () => {} },
|
||||||
|
} as unknown as Electron.BrowserWindow);
|
||||||
manager.broadcastToOverlayWindows('x', 1, 'a');
|
manager.broadcastToOverlayWindows('x', 1, 'a');
|
||||||
|
|
||||||
assert.deepEqual(calls, [
|
assert.deepEqual(calls, [
|
||||||
@@ -123,9 +136,17 @@ test('overlay manager applies bounds by layer', () => {
|
|||||||
invisibleCalls.push(bounds);
|
invisibleCalls.push(bounds);
|
||||||
},
|
},
|
||||||
} as unknown as Electron.BrowserWindow;
|
} as unknown as Electron.BrowserWindow;
|
||||||
|
const modalCalls: Electron.Rectangle[] = [];
|
||||||
|
const modalWindow = {
|
||||||
|
isDestroyed: () => false,
|
||||||
|
setBounds: (bounds: Electron.Rectangle) => {
|
||||||
|
modalCalls.push(bounds);
|
||||||
|
},
|
||||||
|
} as unknown as Electron.BrowserWindow;
|
||||||
manager.setMainWindow(visibleWindow);
|
manager.setMainWindow(visibleWindow);
|
||||||
manager.setInvisibleWindow(invisibleWindow);
|
manager.setInvisibleWindow(invisibleWindow);
|
||||||
manager.setSecondaryWindow(secondaryWindow);
|
manager.setSecondaryWindow(secondaryWindow);
|
||||||
|
manager.setModalWindow(modalWindow);
|
||||||
|
|
||||||
manager.setOverlayWindowBounds('visible', {
|
manager.setOverlayWindowBounds('visible', {
|
||||||
x: 10,
|
x: 10,
|
||||||
@@ -145,12 +166,19 @@ test('overlay manager applies bounds by layer', () => {
|
|||||||
width: 10,
|
width: 10,
|
||||||
height: 11,
|
height: 11,
|
||||||
});
|
});
|
||||||
|
manager.setModalWindowBounds({
|
||||||
|
x: 80,
|
||||||
|
y: 90,
|
||||||
|
width: 100,
|
||||||
|
height: 110,
|
||||||
|
});
|
||||||
|
|
||||||
assert.deepEqual(visibleCalls, [{ x: 10, y: 20, width: 30, height: 40 }]);
|
assert.deepEqual(visibleCalls, [{ x: 10, y: 20, width: 30, height: 40 }]);
|
||||||
assert.deepEqual(invisibleCalls, [
|
assert.deepEqual(invisibleCalls, [
|
||||||
{ x: 1, y: 2, width: 3, height: 4 },
|
{ x: 1, y: 2, width: 3, height: 4 },
|
||||||
{ x: 8, y: 9, width: 10, height: 11 },
|
{ x: 8, y: 9, width: 10, height: 11 },
|
||||||
]);
|
]);
|
||||||
|
assert.deepEqual(modalCalls, [{ x: 80, y: 90, width: 100, height: 110 }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('runtime-option and debug broadcasts use expected channels', () => {
|
test('runtime-option and debug broadcasts use expected channels', () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { BrowserWindow } from 'electron';
|
import type { BrowserWindow } from 'electron';
|
||||||
import { RuntimeOptionState, WindowGeometry } from '../../types';
|
import { RuntimeOptionState, WindowGeometry } from '../../types';
|
||||||
import { updateOverlayWindowBounds } from './overlay-window';
|
import { updateOverlayWindowBounds } from './overlay-window';
|
||||||
|
|
||||||
@@ -11,9 +11,12 @@ export interface OverlayManager {
|
|||||||
setInvisibleWindow: (window: BrowserWindow | null) => void;
|
setInvisibleWindow: (window: BrowserWindow | null) => void;
|
||||||
getSecondaryWindow: () => BrowserWindow | null;
|
getSecondaryWindow: () => BrowserWindow | null;
|
||||||
setSecondaryWindow: (window: BrowserWindow | null) => void;
|
setSecondaryWindow: (window: BrowserWindow | null) => void;
|
||||||
|
getModalWindow: () => BrowserWindow | null;
|
||||||
|
setModalWindow: (window: BrowserWindow | null) => void;
|
||||||
getOverlayWindow: (layer: OverlayLayer) => BrowserWindow | null;
|
getOverlayWindow: (layer: OverlayLayer) => BrowserWindow | null;
|
||||||
setOverlayWindowBounds: (layer: OverlayLayer, geometry: WindowGeometry) => void;
|
setOverlayWindowBounds: (layer: OverlayLayer, geometry: WindowGeometry) => void;
|
||||||
setSecondaryWindowBounds: (geometry: WindowGeometry) => void;
|
setSecondaryWindowBounds: (geometry: WindowGeometry) => void;
|
||||||
|
setModalWindowBounds: (geometry: WindowGeometry) => void;
|
||||||
getVisibleOverlayVisible: () => boolean;
|
getVisibleOverlayVisible: () => boolean;
|
||||||
setVisibleOverlayVisible: (visible: boolean) => void;
|
setVisibleOverlayVisible: (visible: boolean) => void;
|
||||||
getInvisibleOverlayVisible: () => boolean;
|
getInvisibleOverlayVisible: () => boolean;
|
||||||
@@ -26,6 +29,7 @@ export function createOverlayManager(): OverlayManager {
|
|||||||
let mainWindow: BrowserWindow | null = null;
|
let mainWindow: BrowserWindow | null = null;
|
||||||
let invisibleWindow: BrowserWindow | null = null;
|
let invisibleWindow: BrowserWindow | null = null;
|
||||||
let secondaryWindow: BrowserWindow | null = null;
|
let secondaryWindow: BrowserWindow | null = null;
|
||||||
|
let modalWindow: BrowserWindow | null = null;
|
||||||
let visibleOverlayVisible = false;
|
let visibleOverlayVisible = false;
|
||||||
let invisibleOverlayVisible = false;
|
let invisibleOverlayVisible = false;
|
||||||
|
|
||||||
@@ -42,6 +46,10 @@ export function createOverlayManager(): OverlayManager {
|
|||||||
setSecondaryWindow: (window) => {
|
setSecondaryWindow: (window) => {
|
||||||
secondaryWindow = window;
|
secondaryWindow = window;
|
||||||
},
|
},
|
||||||
|
getModalWindow: () => modalWindow,
|
||||||
|
setModalWindow: (window) => {
|
||||||
|
modalWindow = window;
|
||||||
|
},
|
||||||
getOverlayWindow: (layer) => (layer === 'visible' ? mainWindow : invisibleWindow),
|
getOverlayWindow: (layer) => (layer === 'visible' ? mainWindow : invisibleWindow),
|
||||||
setOverlayWindowBounds: (layer, geometry) => {
|
setOverlayWindowBounds: (layer, geometry) => {
|
||||||
updateOverlayWindowBounds(geometry, layer === 'visible' ? mainWindow : invisibleWindow);
|
updateOverlayWindowBounds(geometry, layer === 'visible' ? mainWindow : invisibleWindow);
|
||||||
@@ -49,6 +57,9 @@ export function createOverlayManager(): OverlayManager {
|
|||||||
setSecondaryWindowBounds: (geometry) => {
|
setSecondaryWindowBounds: (geometry) => {
|
||||||
updateOverlayWindowBounds(geometry, secondaryWindow);
|
updateOverlayWindowBounds(geometry, secondaryWindow);
|
||||||
},
|
},
|
||||||
|
setModalWindowBounds: (geometry) => {
|
||||||
|
updateOverlayWindowBounds(geometry, modalWindow);
|
||||||
|
},
|
||||||
getVisibleOverlayVisible: () => visibleOverlayVisible,
|
getVisibleOverlayVisible: () => visibleOverlayVisible,
|
||||||
setVisibleOverlayVisible: (visible) => {
|
setVisibleOverlayVisible: (visible) => {
|
||||||
visibleOverlayVisible = visible;
|
visibleOverlayVisible = visible;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { createLogger } from '../../logger';
|
|||||||
|
|
||||||
const logger = createLogger('main:overlay-window');
|
const logger = createLogger('main:overlay-window');
|
||||||
|
|
||||||
export type OverlayWindowKind = 'visible' | 'invisible' | 'secondary';
|
export type OverlayWindowKind = 'visible' | 'invisible' | 'secondary' | 'modal';
|
||||||
|
|
||||||
export function updateOverlayWindowBounds(
|
export function updateOverlayWindowBounds(
|
||||||
geometry: WindowGeometry,
|
geometry: WindowGeometry,
|
||||||
@@ -71,6 +71,7 @@ export function createOverlayWindow(
|
|||||||
resizable: false,
|
resizable: false,
|
||||||
hasShadow: false,
|
hasShadow: false,
|
||||||
focusable: true,
|
focusable: true,
|
||||||
|
acceptFirstMouse: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, '..', '..', 'preload.js'),
|
preload: path.join(__dirname, '..', '..', 'preload.js'),
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
@@ -115,6 +116,7 @@ export function createOverlayWindow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.webContents.on('before-input-event', (event, input) => {
|
window.webContents.on('before-input-event', (event, input) => {
|
||||||
|
if (kind === 'modal') return;
|
||||||
if (!options.isOverlayVisible(kind)) return;
|
if (!options.isOverlayVisible(kind)) return;
|
||||||
if (!options.tryHandleOverlayShortcutLocalFallback(input)) return;
|
if (!options.tryHandleOverlayShortcutLocalFallback(input)) return;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|||||||
103
src/main.ts
103
src/main.ts
@@ -30,6 +30,41 @@ import {
|
|||||||
screen,
|
screen,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
|
|
||||||
|
function getPasswordStoreArg(argv: string[]): string | null {
|
||||||
|
for (let i = 0; i < argv.length; i += 1) {
|
||||||
|
const arg = argv[i];
|
||||||
|
if (!arg?.startsWith('--password-store')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--password-store') {
|
||||||
|
const value = argv[i + 1];
|
||||||
|
if (value && !value.startsWith('--')) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [prefix, value] = arg.split('=', 2);
|
||||||
|
if (prefix === '--password-store' && value && value.trim().length > 0) {
|
||||||
|
return value.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizePasswordStoreArg(value: string): string {
|
||||||
|
const normalized = value.trim();
|
||||||
|
if (normalized.toLowerCase() === 'gnome') {
|
||||||
|
return 'gnome-libsecret';
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultPasswordStore(): string {
|
||||||
|
return 'gnome-libsecret';
|
||||||
|
}
|
||||||
|
|
||||||
protocol.registerSchemesAsPrivileged([
|
protocol.registerSchemesAsPrivileged([
|
||||||
{
|
{
|
||||||
scheme: 'chrome-extension',
|
scheme: 'chrome-extension',
|
||||||
@@ -400,6 +435,9 @@ import { resolveConfigDir } from './config/path-resolution';
|
|||||||
|
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
app.commandLine.appendSwitch('enable-features', 'GlobalShortcutsPortal');
|
app.commandLine.appendSwitch('enable-features', 'GlobalShortcutsPortal');
|
||||||
|
const passwordStore = normalizePasswordStoreArg(getPasswordStoreArg(process.argv) ?? getDefaultPasswordStore());
|
||||||
|
app.commandLine.appendSwitch('password-store', passwordStore);
|
||||||
|
console.debug(`[main] Applied --password-store ${passwordStore}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.setName('SubMiner');
|
app.setName('SubMiner');
|
||||||
@@ -447,6 +485,7 @@ let jellyfinRemoteLastProgressAtMs = 0;
|
|||||||
let jellyfinMpvAutoLaunchInFlight: Promise<boolean> | null = null;
|
let jellyfinMpvAutoLaunchInFlight: Promise<boolean> | null = null;
|
||||||
let backgroundWarmupsStarted = false;
|
let backgroundWarmupsStarted = false;
|
||||||
let yomitanLoadInFlight: Promise<Extension | null> | null = null;
|
let yomitanLoadInFlight: Promise<Extension | null> | null = null;
|
||||||
|
let notifyAnilistTokenStoreWarning: (message: string) => void = () => {};
|
||||||
|
|
||||||
const buildApplyJellyfinMpvDefaultsMainDepsHandler =
|
const buildApplyJellyfinMpvDefaultsMainDepsHandler =
|
||||||
createBuildApplyJellyfinMpvDefaultsMainDepsHandler({
|
createBuildApplyJellyfinMpvDefaultsMainDepsHandler({
|
||||||
@@ -496,6 +535,7 @@ const anilistTokenStore = createAnilistTokenStore(
|
|||||||
info: (message: string) => console.info(message),
|
info: (message: string) => console.info(message),
|
||||||
warn: (message: string, details?: unknown) => console.warn(message, details),
|
warn: (message: string, details?: unknown) => console.warn(message, details),
|
||||||
error: (message: string, details?: unknown) => console.error(message, details),
|
error: (message: string, details?: unknown) => console.error(message, details),
|
||||||
|
warnUser: (message: string) => notifyAnilistTokenStoreWarning(message),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const jellyfinTokenStore = createJellyfinTokenStore(
|
const jellyfinTokenStore = createJellyfinTokenStore(
|
||||||
@@ -518,6 +558,16 @@ const isDev = process.argv.includes('--dev') || process.argv.includes('--debug')
|
|||||||
const texthookerService = new Texthooker();
|
const texthookerService = new Texthooker();
|
||||||
const subtitleWsService = new SubtitleWebSocket();
|
const subtitleWsService = new SubtitleWebSocket();
|
||||||
const logger = createLogger('main');
|
const logger = createLogger('main');
|
||||||
|
notifyAnilistTokenStoreWarning = (message: string) => {
|
||||||
|
logger.warn(`[AniList] ${message}`);
|
||||||
|
try {
|
||||||
|
showDesktopNotification('SubMiner AniList', {
|
||||||
|
body: message,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// Notification may fail if desktop notifications are unavailable early in startup.
|
||||||
|
}
|
||||||
|
};
|
||||||
const appLogger = {
|
const appLogger = {
|
||||||
logInfo: (message: string) => {
|
logInfo: (message: string) => {
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
@@ -567,6 +617,26 @@ process.on('SIGTERM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const overlayManager = createOverlayManager();
|
const overlayManager = createOverlayManager();
|
||||||
|
let overlayModalInputExclusive = false;
|
||||||
|
let syncOverlayShortcutsForModal: (isActive: boolean) => void = () => {};
|
||||||
|
|
||||||
|
const handleModalInputStateChange = (isActive: boolean): void => {
|
||||||
|
if (overlayModalInputExclusive === isActive) return;
|
||||||
|
overlayModalInputExclusive = isActive;
|
||||||
|
if (isActive) {
|
||||||
|
const modalWindow = overlayManager.getModalWindow();
|
||||||
|
if (modalWindow && !modalWindow.isDestroyed()) {
|
||||||
|
modalWindow.setIgnoreMouseEvents(false);
|
||||||
|
modalWindow.setAlwaysOnTop(true, 'screen-saver', 1);
|
||||||
|
modalWindow.focus();
|
||||||
|
if (!modalWindow.webContents.isFocused()) {
|
||||||
|
modalWindow.webContents.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
syncOverlayShortcutsForModal(isActive);
|
||||||
|
};
|
||||||
|
|
||||||
const buildOverlayContentMeasurementStoreMainDepsHandler =
|
const buildOverlayContentMeasurementStoreMainDepsHandler =
|
||||||
createBuildOverlayContentMeasurementStoreMainDepsHandler({
|
createBuildOverlayContentMeasurementStoreMainDepsHandler({
|
||||||
now: () => Date.now(),
|
now: () => Date.now(),
|
||||||
@@ -575,6 +645,10 @@ const buildOverlayContentMeasurementStoreMainDepsHandler =
|
|||||||
const buildOverlayModalRuntimeMainDepsHandler = createBuildOverlayModalRuntimeMainDepsHandler({
|
const buildOverlayModalRuntimeMainDepsHandler = createBuildOverlayModalRuntimeMainDepsHandler({
|
||||||
getMainWindow: () => overlayManager.getMainWindow(),
|
getMainWindow: () => overlayManager.getMainWindow(),
|
||||||
getInvisibleWindow: () => overlayManager.getInvisibleWindow(),
|
getInvisibleWindow: () => overlayManager.getInvisibleWindow(),
|
||||||
|
getModalWindow: () => overlayManager.getModalWindow(),
|
||||||
|
createModalWindow: () => createModalWindow(),
|
||||||
|
getModalGeometry: () => getCurrentOverlayGeometry(),
|
||||||
|
setModalWindowBounds: (geometry) => overlayManager.setModalWindowBounds(geometry),
|
||||||
});
|
});
|
||||||
const overlayContentMeasurementStoreMainDeps = buildOverlayContentMeasurementStoreMainDepsHandler();
|
const overlayContentMeasurementStoreMainDeps = buildOverlayContentMeasurementStoreMainDepsHandler();
|
||||||
const overlayContentMeasurementStore = createOverlayContentMeasurementStore(
|
const overlayContentMeasurementStore = createOverlayContentMeasurementStore(
|
||||||
@@ -582,6 +656,9 @@ const overlayContentMeasurementStore = createOverlayContentMeasurementStore(
|
|||||||
);
|
);
|
||||||
const overlayModalRuntime = createOverlayModalRuntimeService(
|
const overlayModalRuntime = createOverlayModalRuntimeService(
|
||||||
buildOverlayModalRuntimeMainDepsHandler(),
|
buildOverlayModalRuntimeMainDepsHandler(),
|
||||||
|
{
|
||||||
|
onModalStateChange: (isActive: boolean) => handleModalInputStateChange(isActive),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
const appState = createAppState({
|
const appState = createAppState({
|
||||||
mpvSocketPath: getDefaultSocketPath(),
|
mpvSocketPath: getDefaultSocketPath(),
|
||||||
@@ -789,6 +866,13 @@ const overlayShortcutsRuntime = createOverlayShortcutsRuntimeService(
|
|||||||
},
|
},
|
||||||
})(),
|
})(),
|
||||||
);
|
);
|
||||||
|
syncOverlayShortcutsForModal = (isActive: boolean): void => {
|
||||||
|
if (isActive) {
|
||||||
|
overlayShortcutsRuntime.unregisterOverlayShortcuts();
|
||||||
|
} else {
|
||||||
|
overlayShortcutsRuntime.syncOverlayShortcuts();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const buildConfigHotReloadMessageMainDepsHandler = createBuildConfigHotReloadMessageMainDepsHandler(
|
const buildConfigHotReloadMessageMainDepsHandler = createBuildConfigHotReloadMessageMainDepsHandler(
|
||||||
{
|
{
|
||||||
@@ -2216,6 +2300,7 @@ function applyOverlayRegions(layer: 'visible' | 'invisible', geometry: WindowGeo
|
|||||||
const regions = splitOverlayGeometryForSecondaryBar(geometry);
|
const regions = splitOverlayGeometryForSecondaryBar(geometry);
|
||||||
overlayManager.setOverlayWindowBounds(layer, regions.primary);
|
overlayManager.setOverlayWindowBounds(layer, regions.primary);
|
||||||
overlayManager.setSecondaryWindowBounds(regions.secondary);
|
overlayManager.setSecondaryWindowBounds(regions.secondary);
|
||||||
|
overlayManager.setModalWindowBounds(geometry);
|
||||||
syncSecondaryOverlayWindowVisibility();
|
syncSecondaryOverlayWindowVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2276,10 +2361,20 @@ async function ensureYomitanExtensionLoaded(): Promise<Extension | null> {
|
|||||||
return yomitanExtensionRuntime.ensureYomitanExtensionLoaded();
|
return yomitanExtensionRuntime.ensureYomitanExtensionLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOverlayWindow(kind: 'visible' | 'invisible' | 'secondary'): BrowserWindow {
|
function createOverlayWindow(kind: 'visible' | 'invisible' | 'secondary' | 'modal'): BrowserWindow {
|
||||||
return createOverlayWindowHandler(kind);
|
return createOverlayWindowHandler(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createModalWindow(): BrowserWindow {
|
||||||
|
const existingWindow = overlayManager.getModalWindow();
|
||||||
|
if (existingWindow && !existingWindow.isDestroyed()) {
|
||||||
|
return existingWindow;
|
||||||
|
}
|
||||||
|
const window = createModalWindowHandler();
|
||||||
|
overlayManager.setModalWindowBounds(getCurrentOverlayGeometry());
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
function createSecondaryWindow(): BrowserWindow {
|
function createSecondaryWindow(): BrowserWindow {
|
||||||
const existingWindow = overlayManager.getSecondaryWindow();
|
const existingWindow = overlayManager.getSecondaryWindow();
|
||||||
if (existingWindow && !existingWindow.isDestroyed()) {
|
if (existingWindow && !existingWindow.isDestroyed()) {
|
||||||
@@ -2742,6 +2837,7 @@ const {
|
|||||||
createMainWindow: createMainWindowHandler,
|
createMainWindow: createMainWindowHandler,
|
||||||
createInvisibleWindow: createInvisibleWindowHandler,
|
createInvisibleWindow: createInvisibleWindowHandler,
|
||||||
createSecondaryWindow: createSecondaryWindowHandler,
|
createSecondaryWindow: createSecondaryWindowHandler,
|
||||||
|
createModalWindow: createModalWindowHandler,
|
||||||
} = createOverlayWindowRuntimeHandlers<BrowserWindow>({
|
} = createOverlayWindowRuntimeHandlers<BrowserWindow>({
|
||||||
createOverlayWindowDeps: {
|
createOverlayWindowDeps: {
|
||||||
createOverlayWindowCore: (kind, options) => createOverlayWindowCore(kind, options),
|
createOverlayWindowCore: (kind, options) => createOverlayWindowCore(kind, options),
|
||||||
@@ -2763,14 +2859,17 @@ const {
|
|||||||
overlayManager.setMainWindow(null);
|
overlayManager.setMainWindow(null);
|
||||||
} else if (windowKind === 'invisible') {
|
} else if (windowKind === 'invisible') {
|
||||||
overlayManager.setInvisibleWindow(null);
|
overlayManager.setInvisibleWindow(null);
|
||||||
} else {
|
} else if (windowKind === 'secondary') {
|
||||||
overlayManager.setSecondaryWindow(null);
|
overlayManager.setSecondaryWindow(null);
|
||||||
|
} else {
|
||||||
|
overlayManager.setModalWindow(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setMainWindow: (window) => overlayManager.setMainWindow(window),
|
setMainWindow: (window) => overlayManager.setMainWindow(window),
|
||||||
setInvisibleWindow: (window) => overlayManager.setInvisibleWindow(window),
|
setInvisibleWindow: (window) => overlayManager.setInvisibleWindow(window),
|
||||||
setSecondaryWindow: (window) => overlayManager.setSecondaryWindow(window),
|
setSecondaryWindow: (window) => overlayManager.setSecondaryWindow(window),
|
||||||
|
setModalWindow: (window) => overlayManager.setModalWindow(window),
|
||||||
});
|
});
|
||||||
const {
|
const {
|
||||||
resolveTrayIconPath: resolveTrayIconPathHandler,
|
resolveTrayIconPath: resolveTrayIconPathHandler,
|
||||||
|
|||||||
218
src/main/overlay-runtime.test.ts
Normal file
218
src/main/overlay-runtime.test.ts
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
import { createOverlayModalRuntimeService } from './overlay-runtime';
|
||||||
|
|
||||||
|
type MockWindow = {
|
||||||
|
destroyed: boolean;
|
||||||
|
visible: boolean;
|
||||||
|
focused: boolean;
|
||||||
|
ignoreMouseEvents: boolean;
|
||||||
|
webContentsFocused: boolean;
|
||||||
|
showCount: number;
|
||||||
|
hideCount: number;
|
||||||
|
sent: unknown[][];
|
||||||
|
loading: boolean;
|
||||||
|
loadCallbacks: Array<() => void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
function createMockWindow(): MockWindow & {
|
||||||
|
isDestroyed: () => boolean;
|
||||||
|
isVisible: () => boolean;
|
||||||
|
isFocused: () => boolean;
|
||||||
|
setIgnoreMouseEvents: (ignore: boolean) => void;
|
||||||
|
getShowCount: () => number;
|
||||||
|
getHideCount: () => number;
|
||||||
|
show: () => void;
|
||||||
|
hide: () => void;
|
||||||
|
focus: () => void;
|
||||||
|
webContents: {
|
||||||
|
focused: boolean;
|
||||||
|
isLoading: () => boolean;
|
||||||
|
send: (channel: string, payload?: unknown) => void;
|
||||||
|
isFocused: () => boolean;
|
||||||
|
once: (event: 'did-finish-load', cb: () => void) => void;
|
||||||
|
focus: () => void;
|
||||||
|
};
|
||||||
|
} {
|
||||||
|
const state: MockWindow = {
|
||||||
|
destroyed: false,
|
||||||
|
visible: false,
|
||||||
|
focused: false,
|
||||||
|
ignoreMouseEvents: false,
|
||||||
|
webContentsFocused: false,
|
||||||
|
showCount: 0,
|
||||||
|
hideCount: 0,
|
||||||
|
sent: [],
|
||||||
|
loading: false,
|
||||||
|
loadCallbacks: [],
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isDestroyed: () => state.destroyed,
|
||||||
|
isVisible: () => state.visible,
|
||||||
|
isFocused: () => state.focused,
|
||||||
|
setIgnoreMouseEvents: (ignore: boolean) => {
|
||||||
|
state.ignoreMouseEvents = ignore;
|
||||||
|
},
|
||||||
|
getShowCount: () => state.showCount,
|
||||||
|
getHideCount: () => state.hideCount,
|
||||||
|
show: () => {
|
||||||
|
state.visible = true;
|
||||||
|
state.showCount += 1;
|
||||||
|
},
|
||||||
|
hide: () => {
|
||||||
|
state.visible = false;
|
||||||
|
state.hideCount += 1;
|
||||||
|
},
|
||||||
|
focus: () => {
|
||||||
|
state.focused = true;
|
||||||
|
},
|
||||||
|
webContents: {
|
||||||
|
isLoading: () => state.loading,
|
||||||
|
send: (channel, payload) => {
|
||||||
|
if (payload === undefined) {
|
||||||
|
state.sent.push([channel]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.sent.push([channel, payload]);
|
||||||
|
},
|
||||||
|
focused: false,
|
||||||
|
isFocused: () => state.webContentsFocused,
|
||||||
|
once: (_event, cb) => {
|
||||||
|
state.loadCallbacks.push(cb);
|
||||||
|
},
|
||||||
|
focus: () => {
|
||||||
|
state.webContentsFocused = true;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test('sendToActiveOverlayWindow targets modal window with full geometry and tracks close restore', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
const calls: string[] = [];
|
||||||
|
const runtime = createOverlayModalRuntimeService({
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getInvisibleWindow: () => null,
|
||||||
|
getModalWindow: () => window as never,
|
||||||
|
createModalWindow: () => {
|
||||||
|
calls.push('create-modal-window');
|
||||||
|
return window as never;
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 10, y: 20, width: 300, height: 200 }),
|
||||||
|
setModalWindowBounds: (geometry) => {
|
||||||
|
calls.push(`bounds:${geometry.x},${geometry.y},${geometry.width},${geometry.height}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const sent = runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
|
});
|
||||||
|
assert.equal(sent, true);
|
||||||
|
assert.equal(runtime.getRestoreVisibleOverlayOnModalClose().has('runtime-options'), true);
|
||||||
|
assert.deepEqual(calls, ['bounds:10,20,300,200']);
|
||||||
|
assert.equal(window.getShowCount(), 1);
|
||||||
|
assert.equal(window.isFocused(), true);
|
||||||
|
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sendToActiveOverlayWindow creates modal window lazily when absent', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
let modalWindow: ReturnType<typeof createMockWindow> | null = null;
|
||||||
|
const runtime = createOverlayModalRuntimeService({
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getInvisibleWindow: () => null,
|
||||||
|
getModalWindow: () => modalWindow as never,
|
||||||
|
createModalWindow: () => {
|
||||||
|
modalWindow = window;
|
||||||
|
return modalWindow as never;
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
runtime.sendToActiveOverlayWindow('jimaku:open', undefined, { restoreOnModalClose: 'jimaku' }),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
assert.deepEqual(window.sent, [['jimaku:open']]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handleOverlayModalClosed hides modal window only after all pending modals close', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
const runtime = createOverlayModalRuntimeService({
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getInvisibleWindow: () => null,
|
||||||
|
getModalWindow: () => window as never,
|
||||||
|
createModalWindow: () => window as never,
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
|
});
|
||||||
|
runtime.sendToActiveOverlayWindow('subsync:open-manual', { sourceTracks: [] }, {
|
||||||
|
restoreOnModalClose: 'subsync',
|
||||||
|
});
|
||||||
|
|
||||||
|
runtime.handleOverlayModalClosed('runtime-options');
|
||||||
|
assert.equal(window.getHideCount(), 0);
|
||||||
|
|
||||||
|
runtime.handleOverlayModalClosed('subsync');
|
||||||
|
assert.equal(window.getHideCount(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('modal runtime notifies callers when modal input state becomes active/inactive', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
const state: boolean[] = [];
|
||||||
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getInvisibleWindow: () => null,
|
||||||
|
getModalWindow: () => window as never,
|
||||||
|
createModalWindow: () => window as never,
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onModalStateChange: (active: boolean): void => {
|
||||||
|
state.push(active);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
|
});
|
||||||
|
runtime.sendToActiveOverlayWindow('subsync:open-manual', { sourceTracks: [] }, {
|
||||||
|
restoreOnModalClose: 'subsync',
|
||||||
|
});
|
||||||
|
assert.deepEqual(state, [true]);
|
||||||
|
|
||||||
|
runtime.handleOverlayModalClosed('runtime-options');
|
||||||
|
assert.deepEqual(state, [true]);
|
||||||
|
|
||||||
|
runtime.handleOverlayModalClosed('subsync');
|
||||||
|
assert.deepEqual(state, [true, false]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handleOverlayModalClosed hides modal window for single kiku modal', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
const runtime = createOverlayModalRuntimeService({
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getInvisibleWindow: () => null,
|
||||||
|
getModalWindow: () => window as never,
|
||||||
|
createModalWindow: () => window as never,
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
runtime.sendToActiveOverlayWindow('kiku:field-grouping-open', { test: true }, {
|
||||||
|
restoreOnModalClose: 'kiku',
|
||||||
|
});
|
||||||
|
runtime.handleOverlayModalClosed('kiku');
|
||||||
|
|
||||||
|
assert.equal(window.getHideCount(), 1);
|
||||||
|
assert.equal(runtime.getRestoreVisibleOverlayOnModalClose().size, 0);
|
||||||
|
});
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
import type { BrowserWindow } from 'electron';
|
import type { BrowserWindow } from 'electron';
|
||||||
|
import type { WindowGeometry } from '../types';
|
||||||
|
|
||||||
type OverlayHostedModal = 'runtime-options' | 'subsync' | 'jimaku';
|
type OverlayHostedModal = 'runtime-options' | 'subsync' | 'jimaku' | 'kiku';
|
||||||
type OverlayHostLayer = 'visible' | 'invisible';
|
type OverlayHostLayer = 'visible' | 'invisible';
|
||||||
|
|
||||||
export interface OverlayWindowResolver {
|
export interface OverlayWindowResolver {
|
||||||
getMainWindow: () => BrowserWindow | null;
|
getMainWindow: () => BrowserWindow | null;
|
||||||
getInvisibleWindow: () => BrowserWindow | null;
|
getInvisibleWindow: () => BrowserWindow | null;
|
||||||
|
getModalWindow: () => BrowserWindow | null;
|
||||||
|
createModalWindow: () => BrowserWindow | null;
|
||||||
|
getModalGeometry: () => WindowGeometry;
|
||||||
|
setModalWindowBounds: (geometry: WindowGeometry) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OverlayModalRuntime {
|
export interface OverlayModalRuntime {
|
||||||
@@ -19,9 +24,34 @@ export interface OverlayModalRuntime {
|
|||||||
getRestoreVisibleOverlayOnModalClose: () => Set<OverlayHostedModal>;
|
getRestoreVisibleOverlayOnModalClose: () => Set<OverlayHostedModal>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createOverlayModalRuntimeService(deps: OverlayWindowResolver): OverlayModalRuntime {
|
export interface OverlayModalRuntimeOptions {
|
||||||
|
onModalStateChange?: (isActive: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createOverlayModalRuntimeService(
|
||||||
|
deps: OverlayWindowResolver,
|
||||||
|
options: OverlayModalRuntimeOptions = {},
|
||||||
|
): OverlayModalRuntime {
|
||||||
const restoreVisibleOverlayOnModalClose = new Set<OverlayHostedModal>();
|
const restoreVisibleOverlayOnModalClose = new Set<OverlayHostedModal>();
|
||||||
const overlayModalAutoShownLayer = new Map<OverlayHostedModal, OverlayHostLayer>();
|
let modalActive = false;
|
||||||
|
|
||||||
|
const notifyModalStateChange = (nextState: boolean): void => {
|
||||||
|
if (modalActive === nextState) return;
|
||||||
|
modalActive = nextState;
|
||||||
|
options.onModalStateChange?.(nextState);
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolveModalWindow = (): BrowserWindow | null => {
|
||||||
|
const existingWindow = deps.getModalWindow();
|
||||||
|
if (existingWindow && !existingWindow.isDestroyed()) {
|
||||||
|
return existingWindow;
|
||||||
|
}
|
||||||
|
const createdWindow = deps.createModalWindow();
|
||||||
|
if (!createdWindow || createdWindow.isDestroyed()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return createdWindow;
|
||||||
|
};
|
||||||
|
|
||||||
const getTargetOverlayWindow = (): {
|
const getTargetOverlayWindow = (): {
|
||||||
window: BrowserWindow;
|
window: BrowserWindow;
|
||||||
@@ -41,6 +71,15 @@ export function createOverlayModalRuntimeService(deps: OverlayWindowResolver): O
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showModalWindow = (window: BrowserWindow): void => {
|
||||||
|
window.show();
|
||||||
|
window.setIgnoreMouseEvents(false);
|
||||||
|
window.focus();
|
||||||
|
if (!window.webContents.isFocused()) {
|
||||||
|
window.webContents.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const showOverlayWindowForModal = (window: BrowserWindow, layer: OverlayHostLayer): void => {
|
const showOverlayWindowForModal = (window: BrowserWindow, layer: OverlayHostLayer): void => {
|
||||||
if (layer === 'invisible' && typeof window.showInactive === 'function') {
|
if (layer === 'invisible' && typeof window.showInactive === 'function') {
|
||||||
window.showInactive();
|
window.showInactive();
|
||||||
@@ -57,39 +96,66 @@ export function createOverlayModalRuntimeService(deps: OverlayWindowResolver): O
|
|||||||
payload?: unknown,
|
payload?: unknown,
|
||||||
runtimeOptions?: { restoreOnModalClose?: OverlayHostedModal },
|
runtimeOptions?: { restoreOnModalClose?: OverlayHostedModal },
|
||||||
): boolean => {
|
): boolean => {
|
||||||
|
const restoreOnModalClose = runtimeOptions?.restoreOnModalClose;
|
||||||
|
|
||||||
|
const sendNow = (window: BrowserWindow): void => {
|
||||||
|
if (payload === undefined) {
|
||||||
|
window.webContents.send(channel);
|
||||||
|
} else {
|
||||||
|
window.webContents.send(channel, payload);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (restoreOnModalClose) {
|
||||||
|
const modalWindow = resolveModalWindow();
|
||||||
|
if (!modalWindow) return false;
|
||||||
|
|
||||||
|
deps.setModalWindowBounds(deps.getModalGeometry());
|
||||||
|
const wasVisible = modalWindow.isVisible();
|
||||||
|
const wasModalActive = restoreVisibleOverlayOnModalClose.size > 0;
|
||||||
|
restoreVisibleOverlayOnModalClose.add(restoreOnModalClose);
|
||||||
|
if (!wasModalActive) {
|
||||||
|
notifyModalStateChange(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wasVisible) {
|
||||||
|
showModalWindow(modalWindow);
|
||||||
|
} else if (!modalWindow.isFocused()) {
|
||||||
|
showModalWindow(modalWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modalWindow.webContents.isLoading()) {
|
||||||
|
modalWindow.webContents.once('did-finish-load', () => {
|
||||||
|
if (modalWindow && !modalWindow.isDestroyed() && !modalWindow.webContents.isLoading()) {
|
||||||
|
sendNow(modalWindow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendNow(modalWindow);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const target = getTargetOverlayWindow();
|
const target = getTargetOverlayWindow();
|
||||||
if (!target) return false;
|
if (!target) return false;
|
||||||
|
|
||||||
const { window: targetWindow, layer } = target;
|
const { window: targetWindow, layer } = target;
|
||||||
const wasVisible = targetWindow.isVisible();
|
const wasVisible = targetWindow.isVisible();
|
||||||
const restoreOnModalClose = runtimeOptions?.restoreOnModalClose;
|
|
||||||
|
|
||||||
const sendNow = (): void => {
|
|
||||||
if (payload === undefined) {
|
|
||||||
targetWindow.webContents.send(channel);
|
|
||||||
} else {
|
|
||||||
targetWindow.webContents.send(channel, payload);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!wasVisible) {
|
if (!wasVisible) {
|
||||||
showOverlayWindowForModal(targetWindow, layer);
|
showOverlayWindowForModal(targetWindow, layer);
|
||||||
}
|
}
|
||||||
if (!wasVisible && restoreOnModalClose) {
|
|
||||||
restoreVisibleOverlayOnModalClose.add(restoreOnModalClose);
|
|
||||||
overlayModalAutoShownLayer.set(restoreOnModalClose, layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetWindow.webContents.isLoading()) {
|
if (targetWindow.webContents.isLoading()) {
|
||||||
targetWindow.webContents.once('did-finish-load', () => {
|
targetWindow.webContents.once('did-finish-load', () => {
|
||||||
if (targetWindow && !targetWindow.isDestroyed() && !targetWindow.webContents.isLoading()) {
|
if (targetWindow && !targetWindow.isDestroyed() && !targetWindow.webContents.isLoading()) {
|
||||||
sendNow();
|
sendNow(targetWindow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendNow();
|
sendNow(targetWindow);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,24 +168,13 @@ export function createOverlayModalRuntimeService(deps: OverlayWindowResolver): O
|
|||||||
const handleOverlayModalClosed = (modal: OverlayHostedModal): void => {
|
const handleOverlayModalClosed = (modal: OverlayHostedModal): void => {
|
||||||
if (!restoreVisibleOverlayOnModalClose.has(modal)) return;
|
if (!restoreVisibleOverlayOnModalClose.has(modal)) return;
|
||||||
restoreVisibleOverlayOnModalClose.delete(modal);
|
restoreVisibleOverlayOnModalClose.delete(modal);
|
||||||
const layer = overlayModalAutoShownLayer.get(modal);
|
const modalWindow = deps.getModalWindow();
|
||||||
overlayModalAutoShownLayer.delete(modal);
|
if (!modalWindow || modalWindow.isDestroyed()) return;
|
||||||
if (!layer) return;
|
if (restoreVisibleOverlayOnModalClose.size === 0) {
|
||||||
const shouldKeepLayerVisible = [...restoreVisibleOverlayOnModalClose].some(
|
notifyModalStateChange(false);
|
||||||
(pendingModal) => overlayModalAutoShownLayer.get(pendingModal) === layer,
|
|
||||||
);
|
|
||||||
if (shouldKeepLayerVisible) return;
|
|
||||||
|
|
||||||
if (layer === 'visible') {
|
|
||||||
const mainWindow = deps.getMainWindow();
|
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
||||||
mainWindow.hide();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const invisibleWindow = deps.getInvisibleWindow();
|
if (restoreVisibleOverlayOnModalClose.size === 0) {
|
||||||
if (invisibleWindow && !invisibleWindow.isDestroyed()) {
|
modalWindow.hide();
|
||||||
invisibleWindow.hide();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,23 @@ test('overlay content measurement store main deps builder maps callbacks', () =>
|
|||||||
test('overlay modal runtime main deps builder maps window resolvers', () => {
|
test('overlay modal runtime main deps builder maps window resolvers', () => {
|
||||||
const mainWindow = { id: 'main' };
|
const mainWindow = { id: 'main' };
|
||||||
const invisibleWindow = { id: 'invisible' };
|
const invisibleWindow = { id: 'invisible' };
|
||||||
|
const modalWindow = { id: 'modal' };
|
||||||
|
const calls: string[] = [];
|
||||||
const deps = createBuildOverlayModalRuntimeMainDepsHandler({
|
const deps = createBuildOverlayModalRuntimeMainDepsHandler({
|
||||||
getMainWindow: () => mainWindow as never,
|
getMainWindow: () => mainWindow as never,
|
||||||
getInvisibleWindow: () => invisibleWindow as never,
|
getInvisibleWindow: () => invisibleWindow as never,
|
||||||
|
getModalWindow: () => modalWindow as never,
|
||||||
|
createModalWindow: () => modalWindow as never,
|
||||||
|
getModalGeometry: () => ({ x: 1, y: 2, width: 3, height: 4 }),
|
||||||
|
setModalWindowBounds: (geometry) =>
|
||||||
|
calls.push(`modal-bounds:${geometry.x},${geometry.y},${geometry.width},${geometry.height}`),
|
||||||
})();
|
})();
|
||||||
|
|
||||||
assert.equal(deps.getMainWindow(), mainWindow);
|
assert.equal(deps.getMainWindow(), mainWindow);
|
||||||
assert.equal(deps.getInvisibleWindow(), invisibleWindow);
|
assert.equal(deps.getInvisibleWindow(), invisibleWindow);
|
||||||
|
assert.equal(deps.getModalWindow(), modalWindow);
|
||||||
|
assert.equal(deps.createModalWindow(), modalWindow);
|
||||||
|
assert.deepEqual(deps.getModalGeometry(), { x: 1, y: 2, width: 3, height: 4 });
|
||||||
|
deps.setModalWindowBounds({ x: 10, y: 20, width: 30, height: 40 });
|
||||||
|
assert.deepEqual(calls, ['modal-bounds:10,20,30,40']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,9 +14,15 @@ export function createBuildOverlayContentMeasurementStoreMainDepsHandler(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createBuildOverlayModalRuntimeMainDepsHandler(deps: OverlayWindowResolver) {
|
export function createBuildOverlayModalRuntimeMainDepsHandler(
|
||||||
|
deps: OverlayWindowResolver,
|
||||||
|
) {
|
||||||
return (): OverlayWindowResolver => ({
|
return (): OverlayWindowResolver => ({
|
||||||
getMainWindow: () => deps.getMainWindow(),
|
getMainWindow: () => deps.getMainWindow(),
|
||||||
getInvisibleWindow: () => deps.getInvisibleWindow(),
|
getInvisibleWindow: () => deps.getInvisibleWindow(),
|
||||||
|
getModalWindow: () => deps.getModalWindow(),
|
||||||
|
createModalWindow: () => deps.createModalWindow(),
|
||||||
|
getModalGeometry: () => deps.getModalGeometry(),
|
||||||
|
setModalWindowBounds: (geometry) => deps.setModalWindowBounds(geometry),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import test from 'node:test';
|
|||||||
import {
|
import {
|
||||||
createBuildCreateInvisibleWindowMainDepsHandler,
|
createBuildCreateInvisibleWindowMainDepsHandler,
|
||||||
createBuildCreateMainWindowMainDepsHandler,
|
createBuildCreateMainWindowMainDepsHandler,
|
||||||
|
createBuildCreateModalWindowMainDepsHandler,
|
||||||
createBuildCreateOverlayWindowMainDepsHandler,
|
createBuildCreateOverlayWindowMainDepsHandler,
|
||||||
createBuildCreateSecondaryWindowMainDepsHandler,
|
createBuildCreateSecondaryWindowMainDepsHandler,
|
||||||
} from './overlay-window-factory-main-deps';
|
} from './overlay-window-factory-main-deps';
|
||||||
@@ -47,5 +48,12 @@ test('overlay window factory main deps builders return mapped handlers', () => {
|
|||||||
const secondaryDeps = buildSecondaryDeps();
|
const secondaryDeps = buildSecondaryDeps();
|
||||||
secondaryDeps.setSecondaryWindow(null);
|
secondaryDeps.setSecondaryWindow(null);
|
||||||
|
|
||||||
assert.deepEqual(calls, ['set-main', 'set-invisible', 'set-secondary']);
|
const buildModalDeps = createBuildCreateModalWindowMainDepsHandler({
|
||||||
|
createOverlayWindow: () => ({ id: 'modal' }),
|
||||||
|
setModalWindow: () => calls.push('set-modal'),
|
||||||
|
});
|
||||||
|
const modalDeps = buildModalDeps();
|
||||||
|
modalDeps.setModalWindow(null);
|
||||||
|
|
||||||
|
assert.deepEqual(calls, ['set-main', 'set-invisible', 'set-secondary', 'set-modal']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
export function createBuildCreateOverlayWindowMainDepsHandler<TWindow>(deps: {
|
export function createBuildCreateOverlayWindowMainDepsHandler<TWindow>(deps: {
|
||||||
createOverlayWindowCore: (
|
createOverlayWindowCore: (
|
||||||
kind: 'visible' | 'invisible' | 'secondary',
|
kind: 'visible' | 'invisible' | 'secondary' | 'modal',
|
||||||
options: {
|
options: {
|
||||||
isDev: boolean;
|
isDev: boolean;
|
||||||
overlayDebugVisualizationEnabled: boolean;
|
overlayDebugVisualizationEnabled: boolean;
|
||||||
ensureOverlayWindowLevel: (window: TWindow) => void;
|
ensureOverlayWindowLevel: (window: TWindow) => void;
|
||||||
onRuntimeOptionsChanged: () => void;
|
onRuntimeOptionsChanged: () => void;
|
||||||
setOverlayDebugVisualizationEnabled: (enabled: boolean) => void;
|
setOverlayDebugVisualizationEnabled: (enabled: boolean) => void;
|
||||||
isOverlayVisible: (windowKind: 'visible' | 'invisible' | 'secondary') => boolean;
|
isOverlayVisible: (windowKind: 'visible' | 'invisible' | 'secondary' | 'modal') => boolean;
|
||||||
tryHandleOverlayShortcutLocalFallback: (input: Electron.Input) => boolean;
|
tryHandleOverlayShortcutLocalFallback: (input: Electron.Input) => boolean;
|
||||||
onWindowClosed: (windowKind: 'visible' | 'invisible' | 'secondary') => void;
|
onWindowClosed: (windowKind: 'visible' | 'invisible' | 'secondary' | 'modal') => void;
|
||||||
},
|
},
|
||||||
) => TWindow;
|
) => TWindow;
|
||||||
isDev: boolean;
|
isDev: boolean;
|
||||||
@@ -17,9 +17,9 @@ export function createBuildCreateOverlayWindowMainDepsHandler<TWindow>(deps: {
|
|||||||
ensureOverlayWindowLevel: (window: TWindow) => void;
|
ensureOverlayWindowLevel: (window: TWindow) => void;
|
||||||
onRuntimeOptionsChanged: () => void;
|
onRuntimeOptionsChanged: () => void;
|
||||||
setOverlayDebugVisualizationEnabled: (enabled: boolean) => void;
|
setOverlayDebugVisualizationEnabled: (enabled: boolean) => void;
|
||||||
isOverlayVisible: (windowKind: 'visible' | 'invisible' | 'secondary') => boolean;
|
isOverlayVisible: (windowKind: 'visible' | 'invisible' | 'secondary' | 'modal') => boolean;
|
||||||
tryHandleOverlayShortcutLocalFallback: (input: Electron.Input) => boolean;
|
tryHandleOverlayShortcutLocalFallback: (input: Electron.Input) => boolean;
|
||||||
onWindowClosed: (windowKind: 'visible' | 'invisible' | 'secondary') => void;
|
onWindowClosed: (windowKind: 'visible' | 'invisible' | 'secondary' | 'modal') => void;
|
||||||
}) {
|
}) {
|
||||||
return () => ({
|
return () => ({
|
||||||
createOverlayWindowCore: deps.createOverlayWindowCore,
|
createOverlayWindowCore: deps.createOverlayWindowCore,
|
||||||
@@ -35,7 +35,7 @@ export function createBuildCreateOverlayWindowMainDepsHandler<TWindow>(deps: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createBuildCreateMainWindowMainDepsHandler<TWindow>(deps: {
|
export function createBuildCreateMainWindowMainDepsHandler<TWindow>(deps: {
|
||||||
createOverlayWindow: (kind: 'visible' | 'invisible' | 'secondary') => TWindow;
|
createOverlayWindow: (kind: 'visible' | 'invisible' | 'secondary' | 'modal') => TWindow;
|
||||||
setMainWindow: (window: TWindow | null) => void;
|
setMainWindow: (window: TWindow | null) => void;
|
||||||
}) {
|
}) {
|
||||||
return () => ({
|
return () => ({
|
||||||
@@ -45,7 +45,7 @@ export function createBuildCreateMainWindowMainDepsHandler<TWindow>(deps: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createBuildCreateInvisibleWindowMainDepsHandler<TWindow>(deps: {
|
export function createBuildCreateInvisibleWindowMainDepsHandler<TWindow>(deps: {
|
||||||
createOverlayWindow: (kind: 'visible' | 'invisible' | 'secondary') => TWindow;
|
createOverlayWindow: (kind: 'visible' | 'invisible' | 'secondary' | 'modal') => TWindow;
|
||||||
setInvisibleWindow: (window: TWindow | null) => void;
|
setInvisibleWindow: (window: TWindow | null) => void;
|
||||||
}) {
|
}) {
|
||||||
return () => ({
|
return () => ({
|
||||||
@@ -55,7 +55,7 @@ export function createBuildCreateInvisibleWindowMainDepsHandler<TWindow>(deps: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createBuildCreateSecondaryWindowMainDepsHandler<TWindow>(deps: {
|
export function createBuildCreateSecondaryWindowMainDepsHandler<TWindow>(deps: {
|
||||||
createOverlayWindow: (kind: 'visible' | 'invisible' | 'secondary') => TWindow;
|
createOverlayWindow: (kind: 'visible' | 'invisible' | 'secondary' | 'modal') => TWindow;
|
||||||
setSecondaryWindow: (window: TWindow | null) => void;
|
setSecondaryWindow: (window: TWindow | null) => void;
|
||||||
}) {
|
}) {
|
||||||
return () => ({
|
return () => ({
|
||||||
@@ -63,3 +63,13 @@ export function createBuildCreateSecondaryWindowMainDepsHandler<TWindow>(deps: {
|
|||||||
setSecondaryWindow: deps.setSecondaryWindow,
|
setSecondaryWindow: deps.setSecondaryWindow,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createBuildCreateModalWindowMainDepsHandler<TWindow>(deps: {
|
||||||
|
createOverlayWindow: (kind: 'visible' | 'invisible' | 'secondary' | 'modal') => TWindow;
|
||||||
|
setModalWindow: (window: TWindow | null) => void;
|
||||||
|
}) {
|
||||||
|
return () => ({
|
||||||
|
createOverlayWindow: deps.createOverlayWindow,
|
||||||
|
setModalWindow: deps.setModalWindow,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
|||||||
import {
|
import {
|
||||||
createCreateInvisibleWindowHandler,
|
createCreateInvisibleWindowHandler,
|
||||||
createCreateMainWindowHandler,
|
createCreateMainWindowHandler,
|
||||||
|
createCreateModalWindowHandler,
|
||||||
createCreateOverlayWindowHandler,
|
createCreateOverlayWindowHandler,
|
||||||
createCreateSecondaryWindowHandler,
|
createCreateSecondaryWindowHandler,
|
||||||
} from './overlay-window-factory';
|
} from './overlay-window-factory';
|
||||||
@@ -80,3 +81,18 @@ test('create secondary window handler stores secondary window', () => {
|
|||||||
assert.equal(createSecondaryWindow(), secondaryWindow);
|
assert.equal(createSecondaryWindow(), secondaryWindow);
|
||||||
assert.deepEqual(calls, ['create:secondary', 'set:secondary']);
|
assert.deepEqual(calls, ['create:secondary', 'set:secondary']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('create modal window handler stores modal window', () => {
|
||||||
|
const calls: string[] = [];
|
||||||
|
const modalWindow = { id: 'modal' };
|
||||||
|
const createModalWindow = createCreateModalWindowHandler({
|
||||||
|
createOverlayWindow: (kind) => {
|
||||||
|
calls.push(`create:${kind}`);
|
||||||
|
return modalWindow;
|
||||||
|
},
|
||||||
|
setModalWindow: (window) => calls.push(`set:${(window as { id: string }).id}`),
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(createModalWindow(), modalWindow);
|
||||||
|
assert.deepEqual(calls, ['create:modal', 'set:modal']);
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
type OverlayWindowKind = 'visible' | 'invisible' | 'secondary';
|
type OverlayWindowKind = 'visible' | 'invisible' | 'secondary' | 'modal';
|
||||||
|
|
||||||
export function createCreateOverlayWindowHandler<TWindow>(deps: {
|
export function createCreateOverlayWindowHandler<TWindow>(deps: {
|
||||||
createOverlayWindowCore: (
|
createOverlayWindowCore: (
|
||||||
@@ -69,3 +69,14 @@ export function createCreateSecondaryWindowHandler<TWindow>(deps: {
|
|||||||
return window;
|
return window;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createCreateModalWindowHandler<TWindow>(deps: {
|
||||||
|
createOverlayWindow: (kind: OverlayWindowKind) => TWindow;
|
||||||
|
setModalWindow: (window: TWindow | null) => void;
|
||||||
|
}) {
|
||||||
|
return (): TWindow => {
|
||||||
|
const window = deps.createOverlayWindow('modal');
|
||||||
|
deps.setModalWindow(window);
|
||||||
|
return window;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ test('overlay window runtime handlers compose create/main/invisible handlers', (
|
|||||||
let mainWindow: { kind: string } | null = null;
|
let mainWindow: { kind: string } | null = null;
|
||||||
let invisibleWindow: { kind: string } | null = null;
|
let invisibleWindow: { kind: string } | null = null;
|
||||||
let secondaryWindow: { kind: string } | null = null;
|
let secondaryWindow: { kind: string } | null = null;
|
||||||
|
let modalWindow: { kind: string } | null = null;
|
||||||
let debugEnabled = false;
|
let debugEnabled = false;
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
|
|
||||||
@@ -32,6 +33,9 @@ test('overlay window runtime handlers compose create/main/invisible handlers', (
|
|||||||
setSecondaryWindow: (window) => {
|
setSecondaryWindow: (window) => {
|
||||||
secondaryWindow = window;
|
secondaryWindow = window;
|
||||||
},
|
},
|
||||||
|
setModalWindow: (window) => {
|
||||||
|
modalWindow = window;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(runtime.createOverlayWindow('visible'), { kind: 'visible' });
|
assert.deepEqual(runtime.createOverlayWindow('visible'), { kind: 'visible' });
|
||||||
@@ -46,6 +50,8 @@ test('overlay window runtime handlers compose create/main/invisible handlers', (
|
|||||||
|
|
||||||
assert.deepEqual(runtime.createSecondaryWindow(), { kind: 'secondary' });
|
assert.deepEqual(runtime.createSecondaryWindow(), { kind: 'secondary' });
|
||||||
assert.deepEqual(secondaryWindow, { kind: 'secondary' });
|
assert.deepEqual(secondaryWindow, { kind: 'secondary' });
|
||||||
|
assert.deepEqual(runtime.createModalWindow(), { kind: 'modal' });
|
||||||
|
assert.deepEqual(modalWindow, { kind: 'modal' });
|
||||||
|
|
||||||
assert.equal(debugEnabled, false);
|
assert.equal(debugEnabled, false);
|
||||||
assert.deepEqual(calls, []);
|
assert.deepEqual(calls, []);
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
createCreateInvisibleWindowHandler,
|
createCreateInvisibleWindowHandler,
|
||||||
createCreateMainWindowHandler,
|
createCreateMainWindowHandler,
|
||||||
|
createCreateModalWindowHandler,
|
||||||
createCreateOverlayWindowHandler,
|
createCreateOverlayWindowHandler,
|
||||||
createCreateSecondaryWindowHandler,
|
createCreateSecondaryWindowHandler,
|
||||||
} from './overlay-window-factory';
|
} from './overlay-window-factory';
|
||||||
import {
|
import {
|
||||||
createBuildCreateInvisibleWindowMainDepsHandler,
|
createBuildCreateInvisibleWindowMainDepsHandler,
|
||||||
createBuildCreateMainWindowMainDepsHandler,
|
createBuildCreateMainWindowMainDepsHandler,
|
||||||
|
createBuildCreateModalWindowMainDepsHandler,
|
||||||
createBuildCreateOverlayWindowMainDepsHandler,
|
createBuildCreateOverlayWindowMainDepsHandler,
|
||||||
createBuildCreateSecondaryWindowMainDepsHandler,
|
createBuildCreateSecondaryWindowMainDepsHandler,
|
||||||
} from './overlay-window-factory-main-deps';
|
} from './overlay-window-factory-main-deps';
|
||||||
@@ -20,6 +22,7 @@ export function createOverlayWindowRuntimeHandlers<TWindow>(deps: {
|
|||||||
setMainWindow: (window: TWindow | null) => void;
|
setMainWindow: (window: TWindow | null) => void;
|
||||||
setInvisibleWindow: (window: TWindow | null) => void;
|
setInvisibleWindow: (window: TWindow | null) => void;
|
||||||
setSecondaryWindow: (window: TWindow | null) => void;
|
setSecondaryWindow: (window: TWindow | null) => void;
|
||||||
|
setModalWindow: (window: TWindow | null) => void;
|
||||||
}) {
|
}) {
|
||||||
const createOverlayWindow = createCreateOverlayWindowHandler<TWindow>(
|
const createOverlayWindow = createCreateOverlayWindowHandler<TWindow>(
|
||||||
createBuildCreateOverlayWindowMainDepsHandler<TWindow>(deps.createOverlayWindowDeps)(),
|
createBuildCreateOverlayWindowMainDepsHandler<TWindow>(deps.createOverlayWindowDeps)(),
|
||||||
@@ -42,11 +45,18 @@ export function createOverlayWindowRuntimeHandlers<TWindow>(deps: {
|
|||||||
setSecondaryWindow: (window) => deps.setSecondaryWindow(window),
|
setSecondaryWindow: (window) => deps.setSecondaryWindow(window),
|
||||||
})(),
|
})(),
|
||||||
);
|
);
|
||||||
|
const createModalWindow = createCreateModalWindowHandler<TWindow>(
|
||||||
|
createBuildCreateModalWindowMainDepsHandler<TWindow>({
|
||||||
|
createOverlayWindow: (kind) => createOverlayWindow(kind),
|
||||||
|
setModalWindow: (window) => deps.setModalWindow(window),
|
||||||
|
})(),
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
createOverlayWindow,
|
createOverlayWindow,
|
||||||
createMainWindow,
|
createMainWindow,
|
||||||
createInvisibleWindow,
|
createInvisibleWindow,
|
||||||
createSecondaryWindow,
|
createSecondaryWindow,
|
||||||
|
createModalWindow,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ const overlayLayerFromArg = overlayLayerArg?.slice('--overlay-layer='.length);
|
|||||||
const overlayLayer =
|
const overlayLayer =
|
||||||
overlayLayerFromArg === 'visible' ||
|
overlayLayerFromArg === 'visible' ||
|
||||||
overlayLayerFromArg === 'invisible' ||
|
overlayLayerFromArg === 'invisible' ||
|
||||||
overlayLayerFromArg === 'secondary'
|
overlayLayerFromArg === 'secondary' ||
|
||||||
|
overlayLayerFromArg === 'modal'
|
||||||
? overlayLayerFromArg
|
? overlayLayerFromArg
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -253,7 +254,7 @@ const electronAPI: ElectronAPI = {
|
|||||||
},
|
},
|
||||||
appendClipboardVideoToQueue: (): Promise<ClipboardAppendResult> =>
|
appendClipboardVideoToQueue: (): Promise<ClipboardAppendResult> =>
|
||||||
ipcRenderer.invoke(IPC_CHANNELS.request.appendClipboardVideoToQueue),
|
ipcRenderer.invoke(IPC_CHANNELS.request.appendClipboardVideoToQueue),
|
||||||
notifyOverlayModalClosed: (modal: 'runtime-options' | 'subsync' | 'jimaku') => {
|
notifyOverlayModalClosed: (modal: 'runtime-options' | 'subsync' | 'jimaku' | 'kiku') => {
|
||||||
ipcRenderer.send(IPC_CHANNELS.command.overlayModalClosed, modal);
|
ipcRenderer.send(IPC_CHANNELS.command.overlayModalClosed, modal);
|
||||||
},
|
},
|
||||||
reportOverlayContentBounds: (measurement: OverlayContentMeasurement) => {
|
reportOverlayContentBounds: (measurement: OverlayContentMeasurement) => {
|
||||||
|
|||||||
@@ -190,3 +190,38 @@ test('resolvePlatformInfo supports secondary layer and disables mouse-ignore tog
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('resolvePlatformInfo supports modal layer and disables mouse-ignore toggles', () => {
|
||||||
|
const previousWindow = (globalThis as { window?: unknown }).window;
|
||||||
|
const previousNavigator = (globalThis as { navigator?: unknown }).navigator;
|
||||||
|
|
||||||
|
Object.defineProperty(globalThis, 'window', {
|
||||||
|
configurable: true,
|
||||||
|
value: {
|
||||||
|
electronAPI: {
|
||||||
|
getOverlayLayer: () => 'modal',
|
||||||
|
},
|
||||||
|
location: { search: '' },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
Object.defineProperty(globalThis, 'navigator', {
|
||||||
|
configurable: true,
|
||||||
|
value: {
|
||||||
|
platform: 'MacIntel',
|
||||||
|
userAgent: 'Mozilla/5.0 (Macintosh)',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const info = resolvePlatformInfo();
|
||||||
|
assert.equal(info.overlayLayer, 'modal');
|
||||||
|
assert.equal(info.isModalLayer, true);
|
||||||
|
assert.equal(info.shouldToggleMouseIgnore, false);
|
||||||
|
} finally {
|
||||||
|
Object.defineProperty(globalThis, 'window', { configurable: true, value: previousWindow });
|
||||||
|
Object.defineProperty(globalThis, 'navigator', {
|
||||||
|
configurable: true,
|
||||||
|
value: previousNavigator,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export type RendererRecoverySnapshot = {
|
|||||||
isOverlayInteractive: boolean;
|
isOverlayInteractive: boolean;
|
||||||
isOverSubtitle: boolean;
|
isOverSubtitle: boolean;
|
||||||
invisiblePositionEditMode: boolean;
|
invisiblePositionEditMode: boolean;
|
||||||
overlayLayer: 'visible' | 'invisible' | 'secondary';
|
overlayLayer: 'visible' | 'invisible' | 'secondary' | 'modal';
|
||||||
};
|
};
|
||||||
|
|
||||||
type NormalizedRendererError = {
|
type NormalizedRendererError = {
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ export function createKikuModal(
|
|||||||
|
|
||||||
setKikuPreviewError(null);
|
setKikuPreviewError(null);
|
||||||
ctx.dom.kikuPreviewJson.textContent = '';
|
ctx.dom.kikuPreviewJson.textContent = '';
|
||||||
|
window.electronAPI.notifyOverlayModalClosed('kiku');
|
||||||
|
|
||||||
ctx.state.kikuPendingChoice = null;
|
ctx.state.kikuPendingChoice = null;
|
||||||
ctx.state.kikuPreviewCompactData = null;
|
ctx.state.kikuPreviewCompactData = null;
|
||||||
|
|||||||
@@ -567,6 +567,16 @@ body.layer-secondary #secondarySubContainer {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body.layer-modal #subtitleContainer,
|
||||||
|
body.layer-modal #secondarySubContainer {
|
||||||
|
display: none !important;
|
||||||
|
pointer-events: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.layer-modal #overlay {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
#secondarySubRoot {
|
#secondarySubRoot {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
export type OverlayLayer = 'visible' | 'invisible' | 'secondary';
|
export type OverlayLayer = 'visible' | 'invisible' | 'secondary' | 'modal';
|
||||||
|
|
||||||
export type PlatformInfo = {
|
export type PlatformInfo = {
|
||||||
overlayLayer: OverlayLayer;
|
overlayLayer: OverlayLayer;
|
||||||
isInvisibleLayer: boolean;
|
isInvisibleLayer: boolean;
|
||||||
isSecondaryLayer: boolean;
|
isSecondaryLayer: boolean;
|
||||||
|
isModalLayer: boolean;
|
||||||
isLinuxPlatform: boolean;
|
isLinuxPlatform: boolean;
|
||||||
isMacOSPlatform: boolean;
|
isMacOSPlatform: boolean;
|
||||||
shouldToggleMouseIgnore: boolean;
|
shouldToggleMouseIgnore: boolean;
|
||||||
@@ -16,7 +17,10 @@ export function resolvePlatformInfo(): PlatformInfo {
|
|||||||
const overlayLayerFromPreload = window.electronAPI.getOverlayLayer();
|
const overlayLayerFromPreload = window.electronAPI.getOverlayLayer();
|
||||||
const queryLayer = new URLSearchParams(window.location.search).get('layer');
|
const queryLayer = new URLSearchParams(window.location.search).get('layer');
|
||||||
const overlayLayerFromQuery: OverlayLayer | null =
|
const overlayLayerFromQuery: OverlayLayer | null =
|
||||||
queryLayer === 'visible' || queryLayer === 'invisible' || queryLayer === 'secondary'
|
queryLayer === 'visible' ||
|
||||||
|
queryLayer === 'invisible' ||
|
||||||
|
queryLayer === 'secondary' ||
|
||||||
|
queryLayer === 'modal'
|
||||||
? queryLayer
|
? queryLayer
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -24,12 +28,14 @@ export function resolvePlatformInfo(): PlatformInfo {
|
|||||||
overlayLayerFromQuery ??
|
overlayLayerFromQuery ??
|
||||||
(overlayLayerFromPreload === 'visible' ||
|
(overlayLayerFromPreload === 'visible' ||
|
||||||
overlayLayerFromPreload === 'invisible' ||
|
overlayLayerFromPreload === 'invisible' ||
|
||||||
overlayLayerFromPreload === 'secondary'
|
overlayLayerFromPreload === 'secondary' ||
|
||||||
|
overlayLayerFromPreload === 'modal'
|
||||||
? overlayLayerFromPreload
|
? overlayLayerFromPreload
|
||||||
: 'visible');
|
: 'visible');
|
||||||
|
|
||||||
const isInvisibleLayer = overlayLayer === 'invisible';
|
const isInvisibleLayer = overlayLayer === 'invisible';
|
||||||
const isSecondaryLayer = overlayLayer === 'secondary';
|
const isSecondaryLayer = overlayLayer === 'secondary';
|
||||||
|
const isModalLayer = overlayLayer === 'modal';
|
||||||
const isLinuxPlatform = navigator.platform.toLowerCase().includes('linux');
|
const isLinuxPlatform = navigator.platform.toLowerCase().includes('linux');
|
||||||
const isMacOSPlatform =
|
const isMacOSPlatform =
|
||||||
navigator.platform.toLowerCase().includes('mac') || /mac/i.test(navigator.userAgent);
|
navigator.platform.toLowerCase().includes('mac') || /mac/i.test(navigator.userAgent);
|
||||||
@@ -38,9 +44,10 @@ export function resolvePlatformInfo(): PlatformInfo {
|
|||||||
overlayLayer,
|
overlayLayer,
|
||||||
isInvisibleLayer,
|
isInvisibleLayer,
|
||||||
isSecondaryLayer,
|
isSecondaryLayer,
|
||||||
|
isModalLayer,
|
||||||
isLinuxPlatform,
|
isLinuxPlatform,
|
||||||
isMacOSPlatform,
|
isMacOSPlatform,
|
||||||
shouldToggleMouseIgnore: !isLinuxPlatform && !isSecondaryLayer,
|
shouldToggleMouseIgnore: !isLinuxPlatform && !isSecondaryLayer && !isModalLayer,
|
||||||
invisiblePositionEditToggleCode: 'KeyP',
|
invisiblePositionEditToggleCode: 'KeyP',
|
||||||
invisiblePositionStepPx: 1,
|
invisiblePositionStepPx: 1,
|
||||||
invisiblePositionStepFastPx: 4,
|
invisiblePositionStepFastPx: 4,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { OverlayContentMeasurement, RuntimeOptionId, RuntimeOptionValue } from '../../types';
|
import type { OverlayContentMeasurement, RuntimeOptionId, RuntimeOptionValue } from '../../types';
|
||||||
|
|
||||||
export const OVERLAY_HOSTED_MODALS = ['runtime-options', 'subsync', 'jimaku'] as const;
|
export const OVERLAY_HOSTED_MODALS = ['runtime-options', 'subsync', 'jimaku', 'kiku'] as const;
|
||||||
export type OverlayHostedModal = (typeof OVERLAY_HOSTED_MODALS)[number];
|
export type OverlayHostedModal = (typeof OVERLAY_HOSTED_MODALS)[number];
|
||||||
|
|
||||||
export const IPC_CHANNELS = {
|
export const IPC_CHANNELS = {
|
||||||
|
|||||||
@@ -728,7 +728,7 @@ export interface SubtitleHoverTokenPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ElectronAPI {
|
export interface ElectronAPI {
|
||||||
getOverlayLayer: () => 'visible' | 'invisible' | 'secondary' | null;
|
getOverlayLayer: () => 'visible' | 'invisible' | 'secondary' | 'modal' | null;
|
||||||
onSubtitle: (callback: (data: SubtitleData) => void) => void;
|
onSubtitle: (callback: (data: SubtitleData) => void) => void;
|
||||||
onVisibility: (callback: (visible: boolean) => void) => void;
|
onVisibility: (callback: (visible: boolean) => void) => void;
|
||||||
onSubtitlePosition: (callback: (position: SubtitlePosition | null) => void) => void;
|
onSubtitlePosition: (callback: (position: SubtitlePosition | null) => void) => void;
|
||||||
@@ -780,7 +780,7 @@ export interface ElectronAPI {
|
|||||||
onOpenRuntimeOptions: (callback: () => void) => void;
|
onOpenRuntimeOptions: (callback: () => void) => void;
|
||||||
onOpenJimaku: (callback: () => void) => void;
|
onOpenJimaku: (callback: () => void) => void;
|
||||||
appendClipboardVideoToQueue: () => Promise<ClipboardAppendResult>;
|
appendClipboardVideoToQueue: () => Promise<ClipboardAppendResult>;
|
||||||
notifyOverlayModalClosed: (modal: 'runtime-options' | 'subsync' | 'jimaku') => void;
|
notifyOverlayModalClosed: (modal: 'runtime-options' | 'subsync' | 'jimaku' | 'kiku') => void;
|
||||||
reportOverlayContentBounds: (measurement: OverlayContentMeasurement) => void;
|
reportOverlayContentBounds: (measurement: OverlayContentMeasurement) => void;
|
||||||
reportHoveredSubtitleToken: (tokenIndex: number | null) => void;
|
reportHoveredSubtitleToken: (tokenIndex: number | null) => void;
|
||||||
onConfigHotReload: (callback: (payload: ConfigHotReloadPayload) => void) => void;
|
onConfigHotReload: (callback: (payload: ConfigHotReloadPayload) => void) => void;
|
||||||
|
|||||||
Reference in New Issue
Block a user