mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-16 13:55:51 -07:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
e11a5fea0d
|
|||
|
f73fe179d0
|
|||
| 2938e7a32a | |||
| 82f6b4705a | |||
| a02c33dac4 |
@@ -0,0 +1,5 @@
|
|||||||
|
type: internal
|
||||||
|
area: docs
|
||||||
|
|
||||||
|
- Excluded the `/main/` and `/v/<version>/` docs trees from search indexing with a self-referential canonical, `noindex,follow`, and a matching `X-Robots-Tag` header, so crawlers spend their budget on the current docs instead of ~30 archived copies of every page.
|
||||||
|
- Restored `<lastmod>` dates in the docs sitemap, which were silently dropped because production builds render from an untracked release snapshot.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
type: fixed
|
||||||
|
area: overlay
|
||||||
|
|
||||||
|
- Dedicated overlay modals are prewarmed on macOS and Windows so shortcuts open them promptly on the first press. Windows now refreshes the hidden modal renderer between sessions to keep later modals interactive. On macOS, reused modals and the in-app stats window also open above fullscreen mpv on its current Space instead of appearing on another desktop or forcing a Space change.
|
||||||
|
- Updated subtitle ASS observation to mpv's current `sub-text/ass` property, removing its deprecation warning.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: fixed
|
||||||
|
area: overlay
|
||||||
|
|
||||||
|
- Fixed system-wide mouse lag on Windows while SubMiner is running: the overlay no longer installs Electron's global mouse hook for click-through forwarding, and the mpv window tracker no longer blocks the app on repeated PowerShell command-line lookups.
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
import { existsSync, readFileSync, statSync } from 'node:fs';
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
||||||
import { extname, join, posix, resolve, sep } from 'node:path';
|
import { extname, join, posix, resolve, sep } from 'node:path';
|
||||||
import type { DefaultTheme, HeadConfig, TransformContext, UserConfig } from 'vitepress';
|
import type { DefaultTheme, HeadConfig, TransformContext, UserConfig } from 'vitepress';
|
||||||
@@ -26,6 +27,9 @@ function optionalEnv(value: string | undefined): string | undefined {
|
|||||||
const base = normalizeBase(optionalEnv(process.env.SUBMINER_DOCS_BASE) ?? '/');
|
const base = normalizeBase(optionalEnv(process.env.SUBMINER_DOCS_BASE) ?? '/');
|
||||||
const outDir = optionalEnv(process.env.SUBMINER_DOCS_OUT_DIR);
|
const outDir = optionalEnv(process.env.SUBMINER_DOCS_OUT_DIR);
|
||||||
const docsSourceDir = optionalEnv(process.env.SUBMINER_DOCS_SOURCE_DIR) ?? process.cwd();
|
const docsSourceDir = optionalEnv(process.env.SUBMINER_DOCS_SOURCE_DIR) ?? process.cwd();
|
||||||
|
// The tracked `docs-site/` checkout, which stays a git working tree even when
|
||||||
|
// `docsSourceDir` points at an untracked release snapshot. Used for git lookups only.
|
||||||
|
const repoDocsDir = optionalEnv(process.env.SUBMINER_DOCS_REPO_DIR) ?? process.cwd();
|
||||||
const channel = normalizeChannel(optionalEnv(process.env.SUBMINER_DOCS_CHANNEL));
|
const channel = normalizeChannel(optionalEnv(process.env.SUBMINER_DOCS_CHANNEL));
|
||||||
const docsVersion = optionalEnv(process.env.SUBMINER_DOCS_VERSION);
|
const docsVersion = optionalEnv(process.env.SUBMINER_DOCS_VERSION);
|
||||||
const latestStable = optionalEnv(process.env.SUBMINER_DOCS_LATEST_STABLE) ?? 'v0.18.0';
|
const latestStable = optionalEnv(process.env.SUBMINER_DOCS_LATEST_STABLE) ?? 'v0.18.0';
|
||||||
@@ -82,15 +86,18 @@ function pageToRoute(page: string): string | null {
|
|||||||
return route ? `/${route}` : '/';
|
return route ? `/${route}` : '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only the root channel is indexable. `main` and every /v/<version>/ archive are
|
||||||
|
// near-verbatim copies of it, so they own their URL via a self-referential canonical
|
||||||
|
// and are excluded from the index instead of being consolidated onto root. Uniform
|
||||||
|
// self-canonical plus noindex avoids mixing noindex with a cross-page canonical,
|
||||||
|
// which Google treats as a conflicting signal.
|
||||||
|
const isIndexableChannel = channel === 'stable-root';
|
||||||
|
|
||||||
function pageToCanonicalHref(page: string): string | null {
|
function pageToCanonicalHref(page: string): string | null {
|
||||||
const route = pageToRoute(page);
|
const route = pageToRoute(page);
|
||||||
if (!route) return null;
|
if (!route) return null;
|
||||||
|
|
||||||
if (channel === 'main') {
|
if (!isIndexableChannel) {
|
||||||
return `${DOCS_HOSTNAME}${canonicalRouteWithBase(route)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel === 'stable-archive' && docsVersion !== latestStable) {
|
|
||||||
return `${DOCS_HOSTNAME}${canonicalRouteWithBase(route)}`;
|
return `${DOCS_HOSTNAME}${canonicalRouteWithBase(route)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +113,9 @@ function transformPageHead({ page }: TransformContext): HeadConfig[] {
|
|||||||
const href = pageToCanonicalHref(page);
|
const href = pageToCanonicalHref(page);
|
||||||
const head: HeadConfig[] = href ? [['link', { rel: 'canonical', href }]] : [];
|
const head: HeadConfig[] = href ? [['link', { rel: 'canonical', href }]] : [];
|
||||||
|
|
||||||
if (channel === 'main') {
|
// Crawlable so links still pass through, but out of the index: ~30 archived copies
|
||||||
|
// of every page otherwise soak up the crawl budget the current docs need.
|
||||||
|
if (!isIndexableChannel) {
|
||||||
head.push(['meta', { name: 'robots', content: 'noindex,follow' }]);
|
head.push(['meta', { name: 'robots', content: 'noindex,follow' }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +296,39 @@ const versionItems = [
|
|||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function sitemapUrlToPage(url: string): string {
|
||||||
|
const route = url.replace(/\.html$/, '').replace(/^\/+|\/+$/g, '');
|
||||||
|
return route ? `${route}.md` : 'index.md';
|
||||||
|
}
|
||||||
|
|
||||||
|
// VitePress derives <lastmod> by running `git log` inside its source dir. Production
|
||||||
|
// builds point that at an untracked snapshot of the release tag, so the lookup comes
|
||||||
|
// back empty and the sitemap ships with no dates at all. Resolve it from the tracked
|
||||||
|
// checkout at the ref being built instead.
|
||||||
|
function lastModifiedFor(url: string): string | undefined {
|
||||||
|
const ref = docsVersion && docsVersion !== 'main' ? docsVersion : 'HEAD';
|
||||||
|
const result = spawnSync('git', ['log', '-1', '--format=%cI', ref, '--', sitemapUrlToPage(url)], {
|
||||||
|
cwd: repoDocsDir,
|
||||||
|
encoding: 'utf8',
|
||||||
|
});
|
||||||
|
|
||||||
|
return (result.status === 0 && result.stdout.trim()) || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only the root channel publishes a sitemap. Archived and `main` builds would emit
|
||||||
|
// their own copies listing the same canonical URLs, which just advertises the
|
||||||
|
// duplicate trees we are trying to keep out of the index.
|
||||||
|
const sitemap: UserConfig['sitemap'] = isIndexableChannel
|
||||||
|
? {
|
||||||
|
hostname: DOCS_HOSTNAME,
|
||||||
|
transformItems(items) {
|
||||||
|
return items
|
||||||
|
.filter((item) => item.url !== 'README' && item.url !== `${DOCS_HOSTNAME}/README`)
|
||||||
|
.map((item) => ({ ...item, lastmod: item.lastmod ?? lastModifiedFor(item.url) }));
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const nav: DefaultTheme.NavItem[] = [
|
const nav: DefaultTheme.NavItem[] = [
|
||||||
{ text: 'Home', link: '/' },
|
{ text: 'Home', link: '/' },
|
||||||
{ text: 'Get Started', link: '/installation' },
|
{ text: 'Get Started', link: '/installation' },
|
||||||
@@ -419,14 +461,7 @@ const config: UserConfig = {
|
|||||||
appearance: 'dark',
|
appearance: 'dark',
|
||||||
cleanUrls: true,
|
cleanUrls: true,
|
||||||
metaChunk: true,
|
metaChunk: true,
|
||||||
sitemap: {
|
sitemap,
|
||||||
hostname: DOCS_HOSTNAME,
|
|
||||||
transformItems(items) {
|
|
||||||
return items.filter(
|
|
||||||
(item) => item.url !== 'README' && item.url !== `${DOCS_HOSTNAME}/README`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
transformHead: transformPageHead,
|
transformHead: transformPageHead,
|
||||||
lastUpdated: true,
|
lastUpdated: true,
|
||||||
srcExclude: ['subagents/**', 'README.md'],
|
srcExclude: ['subagents/**', 'README.md'],
|
||||||
|
|||||||
+3
-1
@@ -38,8 +38,10 @@ bun run docs:dev
|
|||||||
The public docs root is stable-only:
|
The public docs root is stable-only:
|
||||||
|
|
||||||
- `/` serves the latest stable release docs.
|
- `/` serves the latest stable release docs.
|
||||||
- `/main/` serves development docs from `main` and is marked `noindex,follow`.
|
- `/main/` serves development docs from `main`.
|
||||||
- `/v/<version>/` serves stable release archives.
|
- `/v/<version>/` serves stable release archives.
|
||||||
- Prerelease tags do not update the docs site.
|
- Prerelease tags do not update the docs site.
|
||||||
|
|
||||||
|
Only `/` is indexable. `/main/` and every `/v/<version>/` page carries a self-referential canonical plus `noindex,follow`, and the generated `_headers` file repeats that as an `X-Robots-Tag`. They stay crawlable so their links still resolve, but ~30 archived copies of every page would otherwise consume the crawl budget the current docs need. Only the root build emits `sitemap.xml`, and its `<lastmod>` dates come from `git log` against the tracked checkout at the released tag, because the build renders from an untracked snapshot that VitePress cannot date itself.
|
||||||
|
|
||||||
Keep Cloudflare Git auto-deploy disabled. The production deploy is `.github/workflows/docs-pages.yml`, which uploads `.tmp/docs-versioned-site` with `--branch main` so tag-triggered runs update Production instead of creating preview deployments.
|
Keep Cloudflare Git auto-deploy disabled. The production deploy is `.github/workflows/docs-pages.yml`, which uploads `.tmp/docs-versioned-site` with `--branch main` so tag-triggered runs update Production instead of creating preview deployments.
|
||||||
|
|||||||
+39
-11
@@ -56,34 +56,43 @@ test('main docs canonical uses /main/ and emits noindex', async () => {
|
|||||||
{ rel: 'canonical', href: 'https://docs.subminer.moe/main/' },
|
{ rel: 'canonical', href: 'https://docs.subminer.moe/main/' },
|
||||||
]);
|
]);
|
||||||
expect(head).toContainEqual(['meta', { name: 'robots', content: 'noindex,follow' }]);
|
expect(head).toContainEqual(['meta', { name: 'robots', content: 'noindex,follow' }]);
|
||||||
|
expect(mainDocsConfig.sitemap).toBeUndefined();
|
||||||
|
|
||||||
process.env.SUBMINER_DOCS_CHANNEL = previousChannel;
|
process.env.SUBMINER_DOCS_CHANNEL = previousChannel;
|
||||||
process.env.SUBMINER_DOCS_BASE = previousBase;
|
process.env.SUBMINER_DOCS_BASE = previousBase;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('latest stable archive canonical points to root equivalent', async () => {
|
test.each([
|
||||||
|
['latest stable', 'v0.14.0', '/v/0.14.0/', 'https://docs.subminer.moe/v/0.14.0/usage'],
|
||||||
|
['superseded', 'v0.12.0', '/v/0.12.0/', 'https://docs.subminer.moe/v/0.12.0/usage'],
|
||||||
|
])(
|
||||||
|
'%s archive keeps a self-referential canonical and stays out of the index',
|
||||||
|
async (_label, version, base, expectedCanonical) => {
|
||||||
const previousChannel = process.env.SUBMINER_DOCS_CHANNEL;
|
const previousChannel = process.env.SUBMINER_DOCS_CHANNEL;
|
||||||
const previousBase = process.env.SUBMINER_DOCS_BASE;
|
const previousBase = process.env.SUBMINER_DOCS_BASE;
|
||||||
const previousVersion = process.env.SUBMINER_DOCS_VERSION;
|
const previousVersion = process.env.SUBMINER_DOCS_VERSION;
|
||||||
const previousLatest = process.env.SUBMINER_DOCS_LATEST_STABLE;
|
const previousLatest = process.env.SUBMINER_DOCS_LATEST_STABLE;
|
||||||
process.env.SUBMINER_DOCS_CHANNEL = 'stable-archive';
|
process.env.SUBMINER_DOCS_CHANNEL = 'stable-archive';
|
||||||
process.env.SUBMINER_DOCS_BASE = '/v/0.14.0/';
|
process.env.SUBMINER_DOCS_BASE = base;
|
||||||
process.env.SUBMINER_DOCS_VERSION = 'v0.14.0';
|
process.env.SUBMINER_DOCS_VERSION = version;
|
||||||
process.env.SUBMINER_DOCS_LATEST_STABLE = 'v0.14.0';
|
process.env.SUBMINER_DOCS_LATEST_STABLE = 'v0.14.0';
|
||||||
const { default: latestArchiveConfig } = await import('./.vitepress/config?latest-archive');
|
try {
|
||||||
|
const { default: archiveConfig } = await import(`./.vitepress/config?archive-${version}`);
|
||||||
|
|
||||||
const head = await latestArchiveConfig.transformHead?.(makeTransformContext('usage.md'));
|
const head = await archiveConfig.transformHead?.(makeTransformContext('usage.md'));
|
||||||
|
|
||||||
expect(head).toContainEqual([
|
|
||||||
'link',
|
|
||||||
{ rel: 'canonical', href: 'https://docs.subminer.moe/usage' },
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
expect(head).toContainEqual(['link', { rel: 'canonical', href: expectedCanonical }]);
|
||||||
|
expect(head).toContainEqual(['meta', { name: 'robots', content: 'noindex,follow' }]);
|
||||||
|
// A sitemap here would advertise the archive tree we just excluded.
|
||||||
|
expect(archiveConfig.sitemap).toBeUndefined();
|
||||||
|
} finally {
|
||||||
process.env.SUBMINER_DOCS_CHANNEL = previousChannel;
|
process.env.SUBMINER_DOCS_CHANNEL = previousChannel;
|
||||||
process.env.SUBMINER_DOCS_BASE = previousBase;
|
process.env.SUBMINER_DOCS_BASE = previousBase;
|
||||||
process.env.SUBMINER_DOCS_VERSION = previousVersion;
|
process.env.SUBMINER_DOCS_VERSION = previousVersion;
|
||||||
process.env.SUBMINER_DOCS_LATEST_STABLE = previousLatest;
|
process.env.SUBMINER_DOCS_LATEST_STABLE = previousLatest;
|
||||||
});
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('stable archive theme links stay on the selected version', async () => {
|
test('stable archive theme links stay on the selected version', async () => {
|
||||||
const previousCwd = process.cwd();
|
const previousCwd = process.cwd();
|
||||||
@@ -433,3 +442,22 @@ test('docs sitemap excludes duplicate README page from indexable URLs', async ()
|
|||||||
|
|
||||||
expect(transformedItems?.map((item) => item.url)).toEqual(['', 'usage']);
|
expect(transformedItems?.map((item) => item.url)).toEqual(['', 'usage']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('docs sitemap dates every URL from the tracked checkout', async () => {
|
||||||
|
const previousRepoDir = process.env.SUBMINER_DOCS_REPO_DIR;
|
||||||
|
// Production builds render from an untracked snapshot, so the date has to come from
|
||||||
|
// the real checkout rather than VitePress's own srcDir git lookup.
|
||||||
|
process.env.SUBMINER_DOCS_REPO_DIR = docsSiteDir;
|
||||||
|
try {
|
||||||
|
const { default: sitemapConfig } = await import('./.vitepress/config?sitemap-lastmod');
|
||||||
|
|
||||||
|
const items = await sitemapConfig.sitemap?.transformItems?.([{ url: '' }, { url: 'usage' }]);
|
||||||
|
|
||||||
|
expect(items).toHaveLength(2);
|
||||||
|
for (const item of items ?? []) {
|
||||||
|
expect(item.lastmod).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
process.env.SUBMINER_DOCS_REPO_DIR = previousRepoDir;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -129,7 +129,11 @@ coming and prefetching would otherwise idle for the rest of the cue.
|
|||||||
path, empty or stale bounding shapes produced invisible or clipped subtitles even though the
|
path, empty or stale bounding shapes produced invisible or clipped subtitles even though the
|
||||||
overlay window remained mapped above mpv.
|
overlay window remained mapped above mpv.
|
||||||
- Pointer pass-through should continue to use `setIgnoreMouseEvents(true, { forward: true })` and
|
- Pointer pass-through should continue to use `setIgnoreMouseEvents(true, { forward: true })` and
|
||||||
the Linux cursor-poll fallback, not bounding-shape clipping.
|
the Linux cursor-poll fallback, not bounding-shape clipping. Note that on Windows click-through
|
||||||
|
must go through `applyOverlayClickThrough()` (`src/core/services/overlay-click-through.ts`),
|
||||||
|
which omits `forward: true` there: Electron implements forwarding with a global low-level mouse
|
||||||
|
hook that lags mouse input system-wide whenever the main thread stalls; the Windows cursor poll
|
||||||
|
handles overlay wake-up instead.
|
||||||
- Visible-overlay show/reset marks Linux pointer passthrough state dirty even when the logical
|
- Visible-overlay show/reset marks Linux pointer passthrough state dirty even when the logical
|
||||||
interaction state is already inactive. The next cursor-poll tick must still reapply
|
interaction state is already inactive. The next cursor-poll tick must still reapply
|
||||||
`setIgnoreMouseEvents(true, { forward: true })`; otherwise a newly shown Electron overlay can keep
|
`setIgnoreMouseEvents(true, { forward: true })`; otherwise a newly shown Electron overlay can keep
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"name": "subminer",
|
"name": "subminer",
|
||||||
"productName": "SubMiner",
|
"productName": "SubMiner",
|
||||||
"desktopName": "SubMiner.desktop",
|
"desktopName": "SubMiner.desktop",
|
||||||
"version": "0.19.3",
|
"version": "0.19.4-beta.1",
|
||||||
"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",
|
||||||
|
|||||||
@@ -106,9 +106,12 @@ function M.create(ctx)
|
|||||||
|
|
||||||
local function get_subtitle_ass_property()
|
local function get_subtitle_ass_property()
|
||||||
local ass_text = mp.get_property("sub-text/ass")
|
local ass_text = mp.get_property("sub-text/ass")
|
||||||
|
if ass_text ~= nil then
|
||||||
if type(ass_text) == "string" and ass_text ~= "" then
|
if type(ass_text) == "string" and ass_text ~= "" then
|
||||||
return ass_text
|
return ass_text
|
||||||
end
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
ass_text = mp.get_property("sub-text-ass")
|
ass_text = mp.get_property("sub-text-ass")
|
||||||
if type(ass_text) == "string" and ass_text ~= "" then
|
if type(ass_text) == "string" and ass_text ~= "" then
|
||||||
return ass_text
|
return ass_text
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ function M.create(ctx)
|
|||||||
elseif action_id == "triggerFieldGrouping" then
|
elseif action_id == "triggerFieldGrouping" then
|
||||||
return { "--trigger-field-grouping" }
|
return { "--trigger-field-grouping" }
|
||||||
elseif action_id == "triggerSubsync" then
|
elseif action_id == "triggerSubsync" then
|
||||||
return { "--trigger-subsync" }
|
return { "--session-action", '{"actionId":"triggerSubsync"}' }
|
||||||
elseif action_id == "mineSentence" then
|
elseif action_id == "mineSentence" then
|
||||||
return { "--mine-sentence" }
|
return { "--mine-sentence" }
|
||||||
elseif action_id == "mineSentenceMultiple" then
|
elseif action_id == "mineSentenceMultiple" then
|
||||||
@@ -251,7 +251,7 @@ function M.create(ctx)
|
|||||||
elseif action_id == "markWatched" then
|
elseif action_id == "markWatched" then
|
||||||
return { "--mark-watched" }
|
return { "--mark-watched" }
|
||||||
elseif action_id == "openRuntimeOptions" then
|
elseif action_id == "openRuntimeOptions" then
|
||||||
return { "--open-runtime-options" }
|
return { "--session-action", '{"actionId":"openRuntimeOptions"}' }
|
||||||
elseif action_id == "openJimaku" then
|
elseif action_id == "openJimaku" then
|
||||||
return { "--open-jimaku" }
|
return { "--open-jimaku" }
|
||||||
elseif action_id == "openTsukihime" or action_id == "openAnimetosho" then
|
elseif action_id == "openTsukihime" or action_id == "openAnimetosho" then
|
||||||
@@ -259,7 +259,7 @@ function M.create(ctx)
|
|||||||
elseif action_id == "openYoutubePicker" then
|
elseif action_id == "openYoutubePicker" then
|
||||||
return { "--open-youtube-picker" }
|
return { "--open-youtube-picker" }
|
||||||
elseif action_id == "openSessionHelp" then
|
elseif action_id == "openSessionHelp" then
|
||||||
return { "--open-session-help" }
|
return { "--session-action", '{"actionId":"openSessionHelp"}' }
|
||||||
elseif action_id == "openCharacterDictionaryManager" then
|
elseif action_id == "openCharacterDictionaryManager" then
|
||||||
return { "--session-action", '{"actionId":"openCharacterDictionaryManager"}' }
|
return { "--session-action", '{"actionId":"openCharacterDictionaryManager"}' }
|
||||||
elseif action_id == "openControllerSelect" then
|
elseif action_id == "openControllerSelect" then
|
||||||
|
|||||||
+13
-1
@@ -4,6 +4,7 @@ function M.create(ctx)
|
|||||||
local mp = ctx.mp
|
local mp = ctx.mp
|
||||||
local input = ctx.input
|
local input = ctx.input
|
||||||
local process = ctx.process
|
local process = ctx.process
|
||||||
|
local state = ctx.state
|
||||||
local subminer_log = ctx.log.subminer_log
|
local subminer_log = ctx.log.subminer_log
|
||||||
local show_osd = ctx.log.show_osd
|
local show_osd = ctx.log.show_osd
|
||||||
|
|
||||||
@@ -93,7 +94,18 @@ function M.create(ctx)
|
|||||||
if not ensure_binary_for_menu() then
|
if not ensure_binary_for_menu() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
process.run_control_command_async("open-session-help")
|
process.run_binary_command_async({
|
||||||
|
state.binary_path,
|
||||||
|
"--session-action",
|
||||||
|
'{"actionId":"openSessionHelp"}',
|
||||||
|
}, function(ok, result, error)
|
||||||
|
if ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local reason = error or (result and result.stderr) or "unknown error"
|
||||||
|
subminer_log("warn", "session-bindings", "Session action failed: " .. tostring(reason))
|
||||||
|
show_osd("Session action failed")
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+38
-66
@@ -1,80 +1,52 @@
|
|||||||
> This is a prerelease build for testing. Stable changelog and docs-site updates remain pending until the final stable release.
|
> This is a prerelease build for testing. Stable changelog and docs-site updates remain pending until the final stable release.
|
||||||
|
|
||||||
<!-- prerelease-base-version: 0.19.0 -->
|
<!-- prerelease-base-version: 0.19.4 -->
|
||||||
|
|
||||||
## Highlights
|
## Highlights
|
||||||
### Added
|
### Added
|
||||||
|
- **Library Merge and Move**
|
||||||
- **Sync Stats & History**
|
- Duplicate library cards for the same show can now be combined: select cards in the library grid, choose "Merge Selected," and pick which entry to keep. Sessions, mined cards, and watch time move over, and future episodes stay matched to the merged card.
|
||||||
- New **Sync Stats & History** window (tray menu) and `subminer sync <host>` command keep mining stats and watch history in sync between machines over SSH, with saved devices, per-host sync direction, and live stage-by-stage progress.
|
- Episodes can be reassigned to a different library entry with a "→" button on the episode row, fixing cases where a file lands under the wrong title. Manual assignments survive later filename parsing, Jellyfin refreshes, and season repair.
|
||||||
- Merges are safe to repeat: data combines without duplicates, and hosts with auto-sync enabled sync automatically in the background on a schedule, reporting results as overlay notifications.
|
- Exact AniList matches with compatible seasons now merge automatically, while fuzzy matches show up as a dismissible "Possible duplicate" prompt instead of merging without confirmation.
|
||||||
- Manual snapshot tools (create, merge, reveal, delete) and connection testing cover one-off transfers; Windows machines running the built-in OpenSSH Server work as sync remotes too, with no setup needed beyond SSH access. Power users can script transfers directly with `--push`/`--pull`, `--check`, `--snapshot`/`--merge`, and `--json` flags.
|
|
||||||
|
|
||||||
- **TsukiHime Subtitle Downloads**
|
|
||||||
- Download Japanese and secondary-language subtitles for the current video directly from TsukiHime, mirroring the existing Jimaku flow.
|
|
||||||
- Press `Ctrl+Shift+T` to search by tabs for the primary and secondary languages; the matching release is found automatically from the video filename and loads straight into mpv, no API key required.
|
|
||||||
|
|
||||||
- **Post-Playback History Menu**
|
|
||||||
- After a watch-history episode ends or mpv closes, the fzf/rofi launcher returns to that series with options to play the previous or next episode, rewatch, pick another episode, or quit SubMiner.
|
|
||||||
- Previous/Next continue across season directories, so you can binge a show without manually browsing folders.
|
|
||||||
- The menu shown right after picking a series from `subminer -H` now offers the previous episode too, matching the post-playback menu.
|
|
||||||
|
|
||||||
- **Known-Word Highlighting by Anki Maturity**
|
|
||||||
- Subtitle highlights for known words can now be colored by Anki card maturity (new, learning, young, mature), similar to asbplayer. Enable it with `ankiConnect.knownWords.maturityEnabled`, or toggle it live during a session.
|
|
||||||
- The mature-interval threshold and the four tier colors are configurable, and the in-session help legend shows the active tier colors while maturity highlighting is on.
|
|
||||||
- Tiers follow Anki's own card state: a lapsed card correctly shows as learning rather than young, and a note is treated as mature if any of its cards are mature. Stats and other known-word tools stay accurate with this new data.
|
|
||||||
|
|
||||||
- **Stats Library Entry Deletion**
|
|
||||||
- Added a "Delete Entry" action in the stats Library detail view that removes an entire title in one step: every episode, session, subtitle line, rollup, cover, and vocabulary count derived from it. Previously a mistaken entry had to be cleared episode by episode and still lingered in the Library.
|
|
||||||
- Delete progress (session, session group, episode, or full entry) now shows app-wide as a progress bar plus a status toast, staying visible across tabs and windows instead of disappearing when you switch away.
|
|
||||||
- Deletes are dramatically faster on large libraries, and opening the Vocabulary tab no longer stalls; the first launch after upgrading migrates the stats database in place to support this.
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- **Clipboard-Video Shortcut**
|
|
||||||
- The "append clipboard video to queue" shortcut is now configurable via `shortcuts.appendClipboardVideoToQueue` instead of being fixed.
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- **Anki Audio Generation on Network Drives**
|
||||||
|
- Fixed sentence-audio generation timing out on slow network-mounted video files with many subtitle and font-attachment streams.
|
||||||
|
- Extraction now uses bounded probing and a two-minute budget, and failures show a clear error instead of a cryptic one.
|
||||||
|
- **Duplicate Subtitle Line Stats**
|
||||||
|
- Fixed karaoke openings and animated signs (which record one subtitle event per animation frame) inflating word and kanji counts and skewing "Top Repeated Words." Ordinary repeated dialogue and rewatches are unaffected.
|
||||||
|
- Already-inflated stats can be cleaned up with the new "Duplicates" button in the Vocabulary tab, or `subminer stats cleanup --duplicate-lines` (supports `--dry-run` and `--lookback-days`). Only the affected subtitle lines and vocabulary counts are touched; watch time and lines-seen totals are untouched.
|
||||||
|
- **Overlay Modals on macOS and Windows**
|
||||||
|
- Fixed overlay modals and the stats window opening on the wrong macOS Space, or forcing a Space switch, when mpv is fullscreen. They now open above fullscreen mpv on its current Space.
|
||||||
|
- Modals are now prewarmed on macOS and Windows so shortcuts open them promptly, and Windows keeps the hidden modal responsive between sessions.
|
||||||
|
- **Wayland File Drag-and-Drop**
|
||||||
|
- Fixed dragging subtitle and video files from file managers like Thunar onto the overlay on native Wayland; dropped files are now resolved and sent to mpv.
|
||||||
|
- **Windows Mouse Lag**
|
||||||
|
- Fixed system-wide mouse lag while SubMiner is running on Windows, caused by a global mouse hook and blocking window lookups during click-through tracking.
|
||||||
|
- **Mining Clip Accuracy**
|
||||||
|
- Fixed mined audio and animated image clips sometimes capturing the wrong subtitle line when audio extraction was slow. The clip range is now locked in at the moment of lookup, so audio and image clips always match.
|
||||||
|
- **Linux Notifications**
|
||||||
|
- Character dictionary progress notifications on Linux now update in place instead of flickering off and back on with every status change.
|
||||||
|
- **Stats Delete Performance**
|
||||||
|
- Fixed stats deletes freezing the dashboard; deletes now reliably run off the main thread, with automatic retry if the delete worker crashes.
|
||||||
|
- Deletes, library merges/moves, and AniList reassignments are now much faster because totals are updated incrementally instead of rebuilt from scratch, and no longer erase lifetime totals older than the recent session history.
|
||||||
|
- Session deletes on large libraries dropped from minutes to milliseconds.
|
||||||
|
|
||||||
- **Word Highlighting Accuracy**
|
### Docs
|
||||||
- Fixed several incorrect word highlighting and annotation cases: inconsistent part-of-speech exclusions on merged quote-particle tokens, missing annotations for rare kanji, katakana punctuation wrongly treated as non-kana noise, and certain kanji vocabulary skipped for next-level ("N+1") highlighting.
|
- **Feature Demos Page**
|
||||||
|
- Hidden the unfinished feature demos page from the documentation sidebar; it's still reachable by direct URL.
|
||||||
- **AniList Season Resolution**
|
|
||||||
- Season 2 and later episodes now resolve to the correct AniList entry by walking sequel relations instead of guessing from the title, so watch progress, the character dictionary, and cover art for later seasons no longer silently fall back to season 1.
|
|
||||||
- Manual AniList overrides now stay in effect for every episode in the same season (by folder and detected season), and setting an override now fixes both the character dictionary and AniList watch progress together instead of needing separate corrections.
|
|
||||||
|
|
||||||
- **Startup Playback Pausing Too Early**
|
|
||||||
- Fixed playback resuming before subtitle processing finished warming up, which could briefly show untranslated subtitles right after opening a video.
|
|
||||||
- Most noticeable when resuming mid-episode or when a subtitle cue starts within the first couple of seconds.
|
|
||||||
|
|
||||||
- **Linux AppImage Crash Notification on Quit**
|
|
||||||
- Fixed a spurious "Service Crash" desktop notification appearing after closing a video when running the Linux AppImage.
|
|
||||||
- If needed, the mount-keepalive behavior behind this fix can be disabled with `SUBMINER_NO_APPIMAGE_MOUNT_KEEPALIVE=1`.
|
|
||||||
|
|
||||||
- **AnkiConnect Proxy Port Conflict**
|
|
||||||
- Fixed video playback failing to start when another process already held the configured AnkiConnect proxy port; SubMiner now shows a notification explaining how to resolve the conflict instead of crashing.
|
|
||||||
|
|
||||||
- **Stats & Settings Reliability**
|
|
||||||
- Fixed session stats reporting zero known words after the known-word cache gained maturity tiers.
|
|
||||||
- Hardened the stats server against malformed requests, stalled AniList lookups, media mismatches during word mining, and missing Yomitan connections.
|
|
||||||
- AnkiConnect settings validation now preserves valid custom configurations while safely falling back on invalid values instead of failing.
|
|
||||||
|
|
||||||
- **Stats Library Cover After Relink**
|
|
||||||
- Relinking a title to a different AniList entry now updates its cover art in the stats Library grid, not just the detail view, so unrelated titles no longer end up sharing the wrong cover.
|
|
||||||
|
|
||||||
- **Rofi Menu Prompt Spacing**
|
|
||||||
- Rofi menu prompts now keep a space between the prompt label and the input field instead of crowding the search placeholder text.
|
|
||||||
|
|
||||||
## What's Changed
|
## What's Changed
|
||||||
|
|
||||||
- feat(shortcuts): make clipboard-video-append shortcut configurable by @ksyasuda in #158
|
- feat(stats): add library entry merge and episode move by @ksyasuda in #190
|
||||||
- refactor(tokenizer): extract subtitle annotation filter into rule table by @ksyasuda in #162
|
- fix(stats): stop counting duplicate typeset subtitle lines by @ksyasuda in #191
|
||||||
- refactor(tsukihime): swap Animetosho backend for TsukiHime API by @ksyasuda in #165
|
- fix(media): tolerate slow MKV audio extraction by @ksyasuda in #195
|
||||||
- refactor: split anki-connect and stats-server resolvers into modules by @ksyasuda in #169
|
- fix(stats): subtract lifetime totals incrementally on delete by @ksyasuda in #196
|
||||||
- feat(launcher): add post-playback history menu with previous episode by @ksyasuda in #170
|
- fix(anki): snapshot mining media clip timing by @ksyasuda in #197
|
||||||
- Anki maturity-based known-word highlighting by @ksyasuda in #172
|
- fix(notifications): replace Linux progress updates in place by @ksyasuda in #198
|
||||||
- fix(anilist): resolve later seasons via sequel relations, not title guessing by @ksyasuda in #173
|
- fix(overlay): support native Wayland file drag-and-drop by @ksyasuda in #199
|
||||||
- feat(stats): add library entry deletion and app-wide delete progress by @ksyasuda in #174
|
- fix(overlay): keep macOS modal windows on fullscreen Spaces by @ksyasuda in #200
|
||||||
|
- fix(overlay): prevent Windows mouse lag during click-through tracking by @ksyasuda in #201
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,17 @@ const archiveCacheRoot = join(repoRoot, '.tmp/docs-versioned-archive-cache');
|
|||||||
const maxCloudflareFiles = 20_000;
|
const maxCloudflareFiles = 20_000;
|
||||||
const maxCloudflareFileBytes = 25 * 1024 * 1024;
|
const maxCloudflareFileBytes = 25 * 1024 * 1024;
|
||||||
|
|
||||||
|
// Cloudflare Pages header rules for the whole deployment. Mirrors the `noindex,follow`
|
||||||
|
// meta tag the non-root channels emit, so the duplicate trees stay out of the index
|
||||||
|
// even for responses a crawler takes without parsing the HTML.
|
||||||
|
const deployHeaders = `# Generated by scripts/build-versioned-docs.ts. Do not edit by hand.
|
||||||
|
/main/*
|
||||||
|
X-Robots-Tag: noindex, follow
|
||||||
|
|
||||||
|
/v/*
|
||||||
|
X-Robots-Tag: noindex, follow
|
||||||
|
`;
|
||||||
|
|
||||||
function run(
|
function run(
|
||||||
command: string,
|
command: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
@@ -173,6 +184,7 @@ function buildDocs(options: {
|
|||||||
SUBMINER_DOCS_BASE: options.base,
|
SUBMINER_DOCS_BASE: options.base,
|
||||||
SUBMINER_DOCS_OUT_DIR: options.outDir,
|
SUBMINER_DOCS_OUT_DIR: options.outDir,
|
||||||
SUBMINER_DOCS_SOURCE_DIR: options.snapshotDocsSite,
|
SUBMINER_DOCS_SOURCE_DIR: options.snapshotDocsSite,
|
||||||
|
SUBMINER_DOCS_REPO_DIR: currentDocsSite,
|
||||||
SUBMINER_DOCS_CHANNEL: options.channel,
|
SUBMINER_DOCS_CHANNEL: options.channel,
|
||||||
SUBMINER_DOCS_VERSION: options.version ?? '',
|
SUBMINER_DOCS_VERSION: options.version ?? '',
|
||||||
SUBMINER_DOCS_LATEST_STABLE: options.latestStable,
|
SUBMINER_DOCS_LATEST_STABLE: options.latestStable,
|
||||||
@@ -378,6 +390,7 @@ function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
writeFileSync(join(aggregateOutDir, 'versions.json'), `${JSON.stringify(manifest, null, 2)}\n`);
|
writeFileSync(join(aggregateOutDir, 'versions.json'), `${JSON.stringify(manifest, null, 2)}\n`);
|
||||||
|
writeFileSync(join(aggregateOutDir, '_headers'), deployHeaders);
|
||||||
assertCloudflarePagesLimits(aggregateOutDir);
|
assertCloudflarePagesLimits(aggregateOutDir);
|
||||||
const prunedArchives = pruneArchiveCacheGenerations({
|
const prunedArchives = pruneArchiveCacheGenerations({
|
||||||
cacheRoot: archiveCacheRoot,
|
cacheRoot: archiveCacheRoot,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import {
|
|||||||
parseSubsyncManualRunRequest,
|
parseSubsyncManualRunRequest,
|
||||||
parseYoutubePickerResolveRequest,
|
parseYoutubePickerResolveRequest,
|
||||||
} from '../../shared/ipc/validators';
|
} from '../../shared/ipc/validators';
|
||||||
|
import { applyOverlayClickThrough } from './overlay-click-through';
|
||||||
|
|
||||||
const { ipcMain } = electron;
|
const { ipcMain } = electron;
|
||||||
|
|
||||||
@@ -442,8 +443,14 @@ export function registerIpcHandlers(deps: IpcServiceDeps, ipc: IpcMainRegistrar
|
|||||||
const senderWindow =
|
const senderWindow =
|
||||||
electron.BrowserWindow?.fromWebContents((event as IpcMainEvent).sender) ?? null;
|
electron.BrowserWindow?.fromWebContents((event as IpcMainEvent).sender) ?? null;
|
||||||
if (senderWindow && !senderWindow.isDestroyed()) {
|
if (senderWindow && !senderWindow.isDestroyed()) {
|
||||||
|
// Route forwarding requests through the platform-aware helper so Windows never
|
||||||
|
// installs Electron's global mouse hook (see overlay-click-through.ts).
|
||||||
|
if (ignore && parsedOptions?.forward) {
|
||||||
|
applyOverlayClickThrough(senderWindow);
|
||||||
|
} else {
|
||||||
senderWindow.setIgnoreMouseEvents(ignore, parsedOptions);
|
senderWindow.setIgnoreMouseEvents(ignore, parsedOptions);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
deps.onOverlayMouseInteractionChanged?.(!ignore, senderWindow);
|
deps.onOverlayMouseInteractionChanged?.(!ignore, senderWindow);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const MPV_SUBTITLE_PROPERTY_OBSERVATIONS: string[] = [
|
|||||||
'sub-scale-by-window',
|
'sub-scale-by-window',
|
||||||
'osd-height',
|
'osd-height',
|
||||||
'osd-dimensions',
|
'osd-dimensions',
|
||||||
'sub-text-ass',
|
'sub-text/ass',
|
||||||
'sub-border-size',
|
'sub-border-size',
|
||||||
'sub-shadow-offset',
|
'sub-shadow-offset',
|
||||||
'sub-ass-override',
|
'sub-ass-override',
|
||||||
@@ -74,7 +74,7 @@ const MPV_INITIAL_PROPERTY_REQUESTS: Array<MpvProtocolCommand> = [
|
|||||||
request_id: MPV_REQUEST_ID_SUBTEXT,
|
request_id: MPV_REQUEST_ID_SUBTEXT,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: ['get_property', 'sub-text-ass'],
|
command: ['get_property', 'sub-text/ass'],
|
||||||
request_id: MPV_REQUEST_ID_SUBTEXT_ASS,
|
request_id: MPV_REQUEST_ID_SUBTEXT_ASS,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -129,6 +129,28 @@ test('dispatchMpvProtocolMessage emits subtitle text on property change', async
|
|||||||
assert.deepEqual(state.events, [{ text: '字幕', isOverlayVisible: false }]);
|
assert.deepEqual(state.events, [{ text: '字幕', isOverlayVisible: false }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('dispatchMpvProtocolMessage emits ASS subtitle text from the current mpv property', async () => {
|
||||||
|
const { deps, state } = createDeps();
|
||||||
|
|
||||||
|
await dispatchMpvProtocolMessage(
|
||||||
|
{ event: 'property-change', name: 'sub-text/ass', data: '{\\b1}字幕' },
|
||||||
|
deps,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(state.events, [{ text: '{\\b1}字幕' }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dispatchMpvProtocolMessage emits ASS subtitle text from the legacy mpv property', async () => {
|
||||||
|
const { deps, state } = createDeps();
|
||||||
|
|
||||||
|
await dispatchMpvProtocolMessage(
|
||||||
|
{ event: 'property-change', name: 'sub-text-ass', data: '{\\b1}字幕' },
|
||||||
|
deps,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(state.events, [{ text: '{\\b1}字幕' }]);
|
||||||
|
});
|
||||||
|
|
||||||
test('dispatchMpvProtocolMessage emits subtitle track changes', async () => {
|
test('dispatchMpvProtocolMessage emits subtitle track changes', async () => {
|
||||||
const { deps, state } = createDeps({
|
const { deps, state } = createDeps({
|
||||||
emitSubtitleTrackChange: (payload) => state.events.push(payload),
|
emitSubtitleTrackChange: (payload) => state.events.push(payload),
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ export async function dispatchMpvProtocolMessage(
|
|||||||
isOverlayVisible: overlayVisible,
|
isOverlayVisible: overlayVisible,
|
||||||
});
|
});
|
||||||
deps.setCurrentSubText(nextSubText);
|
deps.setCurrentSubText(nextSubText);
|
||||||
} else if (msg.name === 'sub-text-ass') {
|
} else if (msg.name === 'sub-text/ass' || msg.name === 'sub-text-ass') {
|
||||||
deps.emitSubtitleAssChange({ text: (msg.data as string) || '' });
|
deps.emitSubtitleAssChange({ text: (msg.data as string) || '' });
|
||||||
} else if (msg.name === 'sub-start') {
|
} else if (msg.name === 'sub-start') {
|
||||||
deps.setCurrentSubStart((msg.data as number) || 0);
|
deps.setCurrentSubStart((msg.data as number) || 0);
|
||||||
|
|||||||
@@ -505,6 +505,17 @@ test('MpvIpcClient reconnect replays property subscriptions and initial state re
|
|||||||
(command as { command: unknown[] }).command[1] === 1 &&
|
(command as { command: unknown[] }).command[1] === 1 &&
|
||||||
(command as { command: unknown[] }).command[2] === 'sub-text',
|
(command as { command: unknown[] }).command[2] === 'sub-text',
|
||||||
);
|
);
|
||||||
|
const hasAssSubtitleSubscription = commands.some(
|
||||||
|
(command) =>
|
||||||
|
Array.isArray((command as { command: unknown[] }).command) &&
|
||||||
|
(command as { command: unknown[] }).command[0] === 'observe_property' &&
|
||||||
|
(command as { command: unknown[] }).command[2] === 'sub-text/ass',
|
||||||
|
);
|
||||||
|
const hasDeprecatedAssSubtitleProperty = commands.some(
|
||||||
|
(command) =>
|
||||||
|
Array.isArray((command as { command: unknown[] }).command) &&
|
||||||
|
(command as { command: unknown[] }).command.includes('sub-text-ass'),
|
||||||
|
);
|
||||||
const hasPathRequest = commands.some(
|
const hasPathRequest = commands.some(
|
||||||
(command) =>
|
(command) =>
|
||||||
Array.isArray((command as { command: unknown[] }).command) &&
|
Array.isArray((command as { command: unknown[] }).command) &&
|
||||||
@@ -514,6 +525,8 @@ test('MpvIpcClient reconnect replays property subscriptions and initial state re
|
|||||||
|
|
||||||
assert.equal(hasSecondaryVisibilityReset, true);
|
assert.equal(hasSecondaryVisibilityReset, true);
|
||||||
assert.equal(hasTrackSubscription, true);
|
assert.equal(hasTrackSubscription, true);
|
||||||
|
assert.equal(hasAssSubtitleSubscription, true);
|
||||||
|
assert.equal(hasDeprecatedAssSubtitleProperty, false);
|
||||||
assert.equal(hasPathRequest, true);
|
assert.equal(hasPathRequest, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
|
||||||
|
import { applyOverlayClickThrough } from './overlay-click-through';
|
||||||
|
|
||||||
|
test('applyOverlayClickThrough requests forwarding only off Windows', () => {
|
||||||
|
const calls: Array<{ ignore: boolean; forward: boolean }> = [];
|
||||||
|
const window = {
|
||||||
|
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
|
||||||
|
calls.push({ ignore, forward: options?.forward === true });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
applyOverlayClickThrough(window, true);
|
||||||
|
applyOverlayClickThrough(window, false);
|
||||||
|
|
||||||
|
assert.deepEqual(calls, [
|
||||||
|
{ ignore: true, forward: false },
|
||||||
|
{ ignore: true, forward: true },
|
||||||
|
]);
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
type ClickThroughWindow = {
|
||||||
|
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts an overlay window into click-through mode. Forwarded mouse-move ({ forward: true }) is
|
||||||
|
* what lets renderer hover tracking wake a click-through overlay, but on Windows Electron
|
||||||
|
* implements it with a global WH_MOUSE_LL hook whose callback runs on the main-process message
|
||||||
|
* loop, so any main-thread stall delays mouse input system-wide (electron/electron#10183).
|
||||||
|
* Windows instead wakes the overlay via the main-process cursor poll
|
||||||
|
* (tickWindowsOverlayPointerInteraction), so no forwarding is requested there. macOS still
|
||||||
|
* needs forwarding for renderer hover tracking; Linux ignores the flag entirely
|
||||||
|
* (electron/electron#16777).
|
||||||
|
*
|
||||||
|
* Pass isWindowsPlatform when the caller already carries a platform flag (tests simulate
|
||||||
|
* platforms through it); otherwise the real process.platform decides.
|
||||||
|
*/
|
||||||
|
export function applyOverlayClickThrough(
|
||||||
|
window: ClickThroughWindow,
|
||||||
|
isWindowsPlatform?: boolean,
|
||||||
|
): void {
|
||||||
|
if (isWindowsPlatform ?? process.platform === 'win32') {
|
||||||
|
window.setIgnoreMouseEvents(true);
|
||||||
|
} else {
|
||||||
|
window.setIgnoreMouseEvents(true, { forward: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -848,7 +848,7 @@ test('Windows visible overlay stays click-through and binds to mpv while tracked
|
|||||||
} as never);
|
} as never);
|
||||||
|
|
||||||
assert.ok(calls.includes('opacity:0'));
|
assert.ok(calls.includes('opacity:0'));
|
||||||
assert.ok(calls.includes('mouse-ignore:true:forward'));
|
assert.ok(calls.includes('mouse-ignore:true:plain'));
|
||||||
assert.ok(calls.includes('show-inactive'));
|
assert.ok(calls.includes('show-inactive'));
|
||||||
assert.ok(calls.includes('sync-windows-z-order'));
|
assert.ok(calls.includes('sync-windows-z-order'));
|
||||||
assert.ok(!calls.includes('move-top'));
|
assert.ok(!calls.includes('move-top'));
|
||||||
@@ -1060,7 +1060,7 @@ test('tracked Windows overlay refresh rebinds while already visible', () => {
|
|||||||
isWindowsPlatform: true,
|
isWindowsPlatform: true,
|
||||||
} as never);
|
} as never);
|
||||||
|
|
||||||
assert.ok(calls.includes('mouse-ignore:true:forward'));
|
assert.ok(calls.includes('mouse-ignore:true:plain'));
|
||||||
assert.ok(calls.includes('sync-windows-z-order'));
|
assert.ok(calls.includes('sync-windows-z-order'));
|
||||||
assert.ok(!calls.includes('move-top'));
|
assert.ok(!calls.includes('move-top'));
|
||||||
assert.ok(!calls.includes('show'));
|
assert.ok(!calls.includes('show'));
|
||||||
@@ -1134,7 +1134,7 @@ test('forced passthrough still reapplies while visible on Windows', () => {
|
|||||||
forceMousePassthrough: true,
|
forceMousePassthrough: true,
|
||||||
} as never);
|
} as never);
|
||||||
|
|
||||||
assert.ok(calls.includes('mouse-ignore:true:forward'));
|
assert.ok(calls.includes('mouse-ignore:true:plain'));
|
||||||
assert.ok(!calls.includes('always-on-top:false'));
|
assert.ok(!calls.includes('always-on-top:false'));
|
||||||
assert.ok(!calls.includes('move-top'));
|
assert.ok(!calls.includes('move-top'));
|
||||||
assert.ok(calls.includes('sync-windows-z-order'));
|
assert.ok(calls.includes('sync-windows-z-order'));
|
||||||
@@ -1339,7 +1339,7 @@ test('tracked Windows overlay rebinds without hiding when tracker focus changes'
|
|||||||
|
|
||||||
assert.ok(!calls.includes('always-on-top:false'));
|
assert.ok(!calls.includes('always-on-top:false'));
|
||||||
assert.ok(!calls.includes('move-top'));
|
assert.ok(!calls.includes('move-top'));
|
||||||
assert.ok(calls.includes('mouse-ignore:true:forward'));
|
assert.ok(calls.includes('mouse-ignore:true:plain'));
|
||||||
assert.ok(calls.includes('sync-windows-z-order'));
|
assert.ok(calls.includes('sync-windows-z-order'));
|
||||||
assert.ok(!calls.includes('ensure-level'));
|
assert.ok(!calls.includes('ensure-level'));
|
||||||
assert.ok(!calls.includes('enforce-order'));
|
assert.ok(!calls.includes('enforce-order'));
|
||||||
@@ -1489,7 +1489,7 @@ test('tracked Windows overlay reshows click-through even if focus state is stale
|
|||||||
isWindowsPlatform: true,
|
isWindowsPlatform: true,
|
||||||
} as never);
|
} as never);
|
||||||
|
|
||||||
assert.ok(calls.includes('mouse-ignore:true:forward'));
|
assert.ok(calls.includes('mouse-ignore:true:plain'));
|
||||||
assert.ok(calls.includes('show-inactive'));
|
assert.ok(calls.includes('show-inactive'));
|
||||||
assert.ok(!calls.includes('show'));
|
assert.ok(!calls.includes('show'));
|
||||||
});
|
});
|
||||||
@@ -1532,7 +1532,7 @@ test('tracked Windows overlay binds above mpv even when tracker focus lags', ()
|
|||||||
|
|
||||||
assert.ok(!calls.includes('always-on-top:false'));
|
assert.ok(!calls.includes('always-on-top:false'));
|
||||||
assert.ok(!calls.includes('move-top'));
|
assert.ok(!calls.includes('move-top'));
|
||||||
assert.ok(calls.includes('mouse-ignore:true:forward'));
|
assert.ok(calls.includes('mouse-ignore:true:plain'));
|
||||||
assert.ok(calls.includes('sync-windows-z-order'));
|
assert.ok(calls.includes('sync-windows-z-order'));
|
||||||
assert.ok(!calls.includes('ensure-level'));
|
assert.ok(!calls.includes('ensure-level'));
|
||||||
});
|
});
|
||||||
@@ -2193,7 +2193,7 @@ test('Windows preserves visible overlay and rebinds to mpv while tracker transie
|
|||||||
assert.ok(!calls.includes('show'));
|
assert.ok(!calls.includes('show'));
|
||||||
assert.ok(!calls.includes('always-on-top:false'));
|
assert.ok(!calls.includes('always-on-top:false'));
|
||||||
assert.ok(!calls.includes('move-top'));
|
assert.ok(!calls.includes('move-top'));
|
||||||
assert.ok(calls.includes('mouse-ignore:true:forward'));
|
assert.ok(calls.includes('mouse-ignore:true:plain'));
|
||||||
assert.ok(calls.includes('sync-windows-z-order'));
|
assert.ok(calls.includes('sync-windows-z-order'));
|
||||||
assert.ok(!calls.includes('ensure-level'));
|
assert.ok(!calls.includes('ensure-level'));
|
||||||
assert.ok(calls.includes('sync-shortcuts'));
|
assert.ok(calls.includes('sync-shortcuts'));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { BrowserWindow } from 'electron';
|
import type { BrowserWindow } from 'electron';
|
||||||
import { BaseWindowTracker } from '../../window-trackers';
|
import { BaseWindowTracker } from '../../window-trackers';
|
||||||
import { WindowGeometry } from '../../types';
|
import { WindowGeometry } from '../../types';
|
||||||
|
import { applyOverlayClickThrough } from './overlay-click-through';
|
||||||
import { OVERLAY_WINDOW_CONTENT_READY_FLAG } from './overlay-window-flags';
|
import { OVERLAY_WINDOW_CONTENT_READY_FLAG } from './overlay-window-flags';
|
||||||
|
|
||||||
const WINDOWS_OVERLAY_REVEAL_DELAY_MS = 48;
|
const WINDOWS_OVERLAY_REVEAL_DELAY_MS = 48;
|
||||||
@@ -117,7 +118,7 @@ export function updateVisibleOverlayVisibility(args: {
|
|||||||
clearPendingWindowsOverlayReveal(mainWindow);
|
clearPendingWindowsOverlayReveal(mainWindow);
|
||||||
setOverlayWindowOpacity(mainWindow, 0);
|
setOverlayWindowOpacity(mainWindow, 0);
|
||||||
}
|
}
|
||||||
mainWindow.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(mainWindow, args.isWindowsPlatform);
|
||||||
releaseOverlayWindowLevel(mainWindow);
|
releaseOverlayWindowLevel(mainWindow);
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
args.syncOverlayShortcuts();
|
args.syncOverlayShortcuts();
|
||||||
@@ -215,7 +216,7 @@ export function updateVisibleOverlayVisibility(args: {
|
|||||||
shouldPreserveWindowsOverlayDuringFocusHandoff ||
|
shouldPreserveWindowsOverlayDuringFocusHandoff ||
|
||||||
(hasWindowsForegroundProcessSignal && windowsForegroundProcessName === 'mpv');
|
(hasWindowsForegroundProcessSignal && windowsForegroundProcessName === 'mpv');
|
||||||
if (shouldIgnoreMouseEvents) {
|
if (shouldIgnoreMouseEvents) {
|
||||||
mainWindow.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(mainWindow, args.isWindowsPlatform);
|
||||||
} else {
|
} else {
|
||||||
mainWindow.setIgnoreMouseEvents(false);
|
mainWindow.setIgnoreMouseEvents(false);
|
||||||
}
|
}
|
||||||
@@ -263,7 +264,7 @@ export function updateVisibleOverlayVisibility(args: {
|
|||||||
if (hasNonNativeInputRegion) {
|
if (hasNonNativeInputRegion) {
|
||||||
mainWindow.setIgnoreMouseEvents(false);
|
mainWindow.setIgnoreMouseEvents(false);
|
||||||
} else {
|
} else {
|
||||||
mainWindow.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(mainWindow, args.isWindowsPlatform);
|
||||||
}
|
}
|
||||||
if (args.isWindowsPlatform) {
|
if (args.isWindowsPlatform) {
|
||||||
scheduleWindowsOverlayReveal(
|
scheduleWindowsOverlayReveal(
|
||||||
@@ -424,7 +425,7 @@ export function updateVisibleOverlayVisibility(args: {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
args.setTrackerNotReadyWarningShown(false);
|
args.setTrackerNotReadyWarningShown(false);
|
||||||
mainWindow.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(mainWindow, args.isWindowsPlatform);
|
||||||
releaseOverlayWindowLevel(mainWindow);
|
releaseOverlayWindowLevel(mainWindow);
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
args.syncOverlayShortcuts();
|
args.syncOverlayShortcuts();
|
||||||
|
|||||||
@@ -15,6 +15,32 @@ test('overlay window config explicitly disables renderer sandbox for preload com
|
|||||||
assert.equal(options.webPreferences?.backgroundThrottling, false);
|
assert.equal(options.webPreferences?.backgroundThrottling, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('macOS modal overlay uses a fullscreen auxiliary panel without changing the passive overlay', () => {
|
||||||
|
const visibleOptions = buildOverlayWindowOptions('visible', {
|
||||||
|
isDev: false,
|
||||||
|
platform: 'darwin',
|
||||||
|
yomitanSession: null,
|
||||||
|
});
|
||||||
|
const modalOptions = buildOverlayWindowOptions('modal', {
|
||||||
|
isDev: false,
|
||||||
|
platform: 'darwin',
|
||||||
|
yomitanSession: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(visibleOptions.type, undefined);
|
||||||
|
assert.equal(modalOptions.type, 'panel');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('non-macOS modal overlay remains a regular window', () => {
|
||||||
|
const options = buildOverlayWindowOptions('modal', {
|
||||||
|
isDev: false,
|
||||||
|
platform: 'linux',
|
||||||
|
yomitanSession: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(options.type, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
test('Linux visible overlay window allows compositor resize for mpv-sized placement', () => {
|
test('Linux visible overlay window allows compositor resize for mpv-sized placement', () => {
|
||||||
const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform');
|
const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform');
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
export const OVERLAY_WINDOW_CONTENT_READY_FLAG = '__subminerOverlayContentReady';
|
export const OVERLAY_WINDOW_CONTENT_READY_FLAG = '__subminerOverlayContentReady';
|
||||||
|
export const OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG = '__subminerOverlayDocumentLoaded';
|
||||||
|
|||||||
@@ -12,15 +12,17 @@ export function buildOverlayWindowOptions(
|
|||||||
options: {
|
options: {
|
||||||
isDev: boolean;
|
isDev: boolean;
|
||||||
linuxX11FullscreenOverlay?: boolean;
|
linuxX11FullscreenOverlay?: boolean;
|
||||||
|
platform?: NodeJS.Platform;
|
||||||
yomitanSession?: Session | null;
|
yomitanSession?: Session | null;
|
||||||
},
|
},
|
||||||
): BrowserWindowConstructorOptions {
|
): BrowserWindowConstructorOptions {
|
||||||
const showNativeDebugFrame = process.platform === 'win32' && options.isDev;
|
const platform = options.platform ?? process.platform;
|
||||||
const isLinuxVisibleOverlay = process.platform === 'linux' && kind === 'visible';
|
const showNativeDebugFrame = platform === 'win32' && options.isDev;
|
||||||
|
const isLinuxVisibleOverlay = platform === 'linux' && kind === 'visible';
|
||||||
const isLinuxFullscreenOverlay =
|
const isLinuxFullscreenOverlay =
|
||||||
isLinuxVisibleOverlay && options.linuxX11FullscreenOverlay === true;
|
isLinuxVisibleOverlay && options.linuxX11FullscreenOverlay === true;
|
||||||
const shouldStartAlwaysOnTop =
|
const shouldStartAlwaysOnTop =
|
||||||
!(process.platform === 'win32' && kind === 'visible') &&
|
!(platform === 'win32' && kind === 'visible') &&
|
||||||
(!isLinuxVisibleOverlay || isLinuxFullscreenOverlay);
|
(!isLinuxVisibleOverlay || isLinuxFullscreenOverlay);
|
||||||
const shouldAllowCompositorResize = isLinuxVisibleOverlay && !isLinuxFullscreenOverlay;
|
const shouldAllowCompositorResize = isLinuxVisibleOverlay && !isLinuxFullscreenOverlay;
|
||||||
|
|
||||||
@@ -41,7 +43,10 @@ export function buildOverlayWindowOptions(
|
|||||||
hasShadow: false,
|
hasShadow: false,
|
||||||
focusable: !isLinuxFullscreenOverlay,
|
focusable: !isLinuxFullscreenOverlay,
|
||||||
acceptFirstMouse: true,
|
acceptFirstMouse: true,
|
||||||
...(process.platform === 'win32' ? { thickFrame: showNativeDebugFrame } : {}),
|
// A macOS panel is a fullscreen auxiliary window, so modal surfaces stay on the
|
||||||
|
// active mpv Space instead of opening on SubMiner's last regular desktop.
|
||||||
|
...(platform === 'darwin' && kind === 'modal' ? { type: 'panel' as const } : {}),
|
||||||
|
...(platform === 'win32' ? { thickFrame: showNativeDebugFrame } : {}),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, '..', '..', 'preload.js'),
|
preload: path.join(__dirname, '..', '..', 'preload.js'),
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ import {
|
|||||||
} from './hyprland-window-placement';
|
} from './hyprland-window-placement';
|
||||||
import { buildOverlayWindowOptions, OVERLAY_WINDOW_TITLES } from './overlay-window-options';
|
import { buildOverlayWindowOptions, OVERLAY_WINDOW_TITLES } from './overlay-window-options';
|
||||||
import { normalizeOverlayWindowBoundsForPlatform } from './overlay-window-bounds';
|
import { normalizeOverlayWindowBoundsForPlatform } from './overlay-window-bounds';
|
||||||
import { OVERLAY_WINDOW_CONTENT_READY_FLAG } from './overlay-window-flags';
|
import {
|
||||||
|
OVERLAY_WINDOW_CONTENT_READY_FLAG,
|
||||||
|
OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG,
|
||||||
|
} from './overlay-window-flags';
|
||||||
export { OVERLAY_WINDOW_CONTENT_READY_FLAG } from './overlay-window-flags';
|
export { OVERLAY_WINDOW_CONTENT_READY_FLAG } from './overlay-window-flags';
|
||||||
|
|
||||||
const logger = createLogger('main:overlay-window');
|
const logger = createLogger('main:overlay-window');
|
||||||
@@ -133,6 +136,9 @@ export function createOverlayWindow(
|
|||||||
(window as BrowserWindow & { [OVERLAY_WINDOW_CONTENT_READY_FLAG]?: boolean })[
|
(window as BrowserWindow & { [OVERLAY_WINDOW_CONTENT_READY_FLAG]?: boolean })[
|
||||||
OVERLAY_WINDOW_CONTENT_READY_FLAG
|
OVERLAY_WINDOW_CONTENT_READY_FLAG
|
||||||
] = false;
|
] = false;
|
||||||
|
(window as BrowserWindow & { [OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG]?: boolean })[
|
||||||
|
OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG
|
||||||
|
] = false;
|
||||||
|
|
||||||
if (!(process.platform === 'win32' && kind === 'visible')) {
|
if (!(process.platform === 'win32' && kind === 'visible')) {
|
||||||
options.ensureOverlayWindowLevel(window);
|
options.ensureOverlayWindowLevel(window);
|
||||||
@@ -144,11 +150,20 @@ export function createOverlayWindow(
|
|||||||
});
|
});
|
||||||
|
|
||||||
window.webContents.on('did-finish-load', () => {
|
window.webContents.on('did-finish-load', () => {
|
||||||
|
(window as BrowserWindow & { [OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG]?: boolean })[
|
||||||
|
OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG
|
||||||
|
] = true;
|
||||||
window.setTitle(OVERLAY_WINDOW_TITLES[kind]);
|
window.setTitle(OVERLAY_WINDOW_TITLES[kind]);
|
||||||
options.onRuntimeOptionsChanged();
|
options.onRuntimeOptionsChanged();
|
||||||
options.onWindowDidFinishLoad?.();
|
options.onWindowDidFinishLoad?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.webContents.on('did-start-loading', () => {
|
||||||
|
(window as BrowserWindow & { [OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG]?: boolean })[
|
||||||
|
OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG
|
||||||
|
] = false;
|
||||||
|
});
|
||||||
|
|
||||||
window.webContents.on('page-title-updated', (event) => {
|
window.webContents.on('page-title-updated', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
window.setTitle(OVERLAY_WINDOW_TITLES[kind]);
|
window.setTitle(OVERLAY_WINDOW_TITLES[kind]);
|
||||||
|
|||||||
@@ -57,7 +57,9 @@ export function shouldHideStatsWindowForInput(input: Electron.Input, toggleKey:
|
|||||||
export function buildStatsWindowOptions(options: {
|
export function buildStatsWindowOptions(options: {
|
||||||
preloadPath: string;
|
preloadPath: string;
|
||||||
bounds?: WindowGeometry | null;
|
bounds?: WindowGeometry | null;
|
||||||
|
platform?: NodeJS.Platform;
|
||||||
}): BrowserWindowConstructorOptions {
|
}): BrowserWindowConstructorOptions {
|
||||||
|
const platform = options.platform ?? process.platform;
|
||||||
return {
|
return {
|
||||||
title: STATS_WINDOW_TITLE,
|
title: STATS_WINDOW_TITLE,
|
||||||
x: options.bounds?.x,
|
x: options.bounds?.x,
|
||||||
@@ -73,6 +75,9 @@ export function buildStatsWindowOptions(options: {
|
|||||||
focusable: true,
|
focusable: true,
|
||||||
acceptFirstMouse: true,
|
acceptFirstMouse: true,
|
||||||
fullscreenable: false,
|
fullscreenable: false,
|
||||||
|
// Panels join fullscreen Spaces on macOS without moving the user back to the
|
||||||
|
// desktop where SubMiner last owned a regular application window.
|
||||||
|
...(platform === 'darwin' ? { type: 'panel' as const } : {}),
|
||||||
backgroundColor: '#24273a',
|
backgroundColor: '#24273a',
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
@@ -84,6 +89,12 @@ export function buildStatsWindowOptions(options: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldPresentStatsWindowAfterLoad(
|
||||||
|
platform: NodeJS.Platform = process.platform,
|
||||||
|
): boolean {
|
||||||
|
return platform === 'darwin';
|
||||||
|
}
|
||||||
|
|
||||||
export function resolveStatsWindowOuterBoundsForContent(
|
export function resolveStatsWindowOuterBoundsForContent(
|
||||||
window: StatsWindowBoundsController,
|
window: StatsWindowBoundsController,
|
||||||
target: WindowGeometry,
|
target: WindowGeometry,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
scheduleStatsWindowPostShowReconciles,
|
scheduleStatsWindowPostShowReconciles,
|
||||||
showStatsNativeConfirmDialog,
|
showStatsNativeConfirmDialog,
|
||||||
shouldHideStatsWindowForInput,
|
shouldHideStatsWindowForInput,
|
||||||
|
shouldPresentStatsWindowAfterLoad,
|
||||||
} from './stats-window-runtime';
|
} from './stats-window-runtime';
|
||||||
|
|
||||||
test('buildStatsWindowOptions uses tracked overlay bounds and preload-friendly web preferences', () => {
|
test('buildStatsWindowOptions uses tracked overlay bounds and preload-friendly web preferences', () => {
|
||||||
@@ -40,6 +41,30 @@ test('buildStatsWindowOptions uses tracked overlay bounds and preload-friendly w
|
|||||||
assert.equal(options.webPreferences?.sandbox, true);
|
assert.equal(options.webPreferences?.sandbox, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('buildStatsWindowOptions uses a fullscreen auxiliary panel on macOS', () => {
|
||||||
|
const options = buildStatsWindowOptions({
|
||||||
|
preloadPath: '/tmp/preload-stats.js',
|
||||||
|
platform: 'darwin',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(options.type, 'panel');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('buildStatsWindowOptions remains a regular window off macOS', () => {
|
||||||
|
const options = buildStatsWindowOptions({
|
||||||
|
preloadPath: '/tmp/preload-stats.js',
|
||||||
|
platform: 'linux',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(options.type, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stats panels present after document load on macOS', () => {
|
||||||
|
assert.equal(shouldPresentStatsWindowAfterLoad('darwin'), true);
|
||||||
|
assert.equal(shouldPresentStatsWindowAfterLoad('linux'), false);
|
||||||
|
assert.equal(shouldPresentStatsWindowAfterLoad('win32'), false);
|
||||||
|
});
|
||||||
|
|
||||||
test('shouldHideStatsWindowForInput matches Escape and configured bare toggle key', () => {
|
test('shouldHideStatsWindowForInput matches Escape and configured bare toggle key', () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
shouldHideStatsWindowForInput(
|
shouldHideStatsWindowForInput(
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
scheduleStatsWindowPostShowReconciles,
|
scheduleStatsWindowPostShowReconciles,
|
||||||
showStatsNativeConfirmDialog,
|
showStatsNativeConfirmDialog,
|
||||||
shouldHideStatsWindowForInput,
|
shouldHideStatsWindowForInput,
|
||||||
|
shouldPresentStatsWindowAfterLoad,
|
||||||
STATS_WINDOW_TITLE,
|
STATS_WINDOW_TITLE,
|
||||||
} from './stats-window-runtime.js';
|
} from './stats-window-runtime.js';
|
||||||
import { ensureHyprlandWindowFloatingByTitle } from './hyprland-window-placement.js';
|
import { ensureHyprlandWindowFloatingByTitle } from './hyprland-window-placement.js';
|
||||||
@@ -209,10 +210,15 @@ export function toggleStatsOverlay(options: StatsWindowOptions): void {
|
|||||||
options.onVisibilityChanged?.(false);
|
options.onVisibilityChanged?.(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
statsWindow.once('ready-to-show', () => {
|
const showInitialStatsWindow = () => {
|
||||||
if (!statsWindow) return;
|
if (!statsWindow) return;
|
||||||
showStatsWindow(statsWindow, options);
|
showStatsWindow(statsWindow, options);
|
||||||
});
|
};
|
||||||
|
if (shouldPresentStatsWindowAfterLoad()) {
|
||||||
|
statsWindow.webContents.once('did-finish-load', showInitialStatsWindow);
|
||||||
|
} else {
|
||||||
|
statsWindow.once('ready-to-show', showInitialStatsWindow);
|
||||||
|
}
|
||||||
|
|
||||||
statsWindow.on('blur', () => {
|
statsWindow.on('blur', () => {
|
||||||
if (!statsWindow || statsWindow.isDestroyed() || !statsWindow.isVisible()) {
|
if (!statsWindow || statsWindow.isDestroyed() || !statsWindow.isVisible()) {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
* layer that keeps the two views consistent by construction.
|
* layer that keeps the two views consistent by construction.
|
||||||
* 2. Otherwise (embedded track nobody parsed, a source whose timings mpv has shifted)
|
* 2. Otherwise (embedded track nobody parsed, a source whose timings mpv has shifted)
|
||||||
* fall back to timing alone. No authoring metadata is available live -- mpv delivers
|
* fall back to timing alone. No authoring metadata is available live -- mpv delivers
|
||||||
* `sub-text-ass` after `sub-start`/`sub-end`, so any ASS text read here belongs to the
|
* `sub-text/ass` after `sub-start`/`sub-end`, so any ASS text read here belongs to the
|
||||||
* previous event -- which puts this layer in the same position as the SRT path in
|
* previous event -- which puts this layer in the same position as the SRT path in
|
||||||
* `subtitle-cue-dedup`, and it uses that path's deliberately strict bounds.
|
* `subtitle-cue-dedup`, and it uses that path's deliberately strict bounds.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -24,10 +24,17 @@ import {
|
|||||||
shouldForwardStartupArgvViaAppControl,
|
shouldForwardStartupArgvViaAppControl,
|
||||||
applyBackgroundBootstrapCommandLineSwitches,
|
applyBackgroundBootstrapCommandLineSwitches,
|
||||||
applyEarlyLinuxCommandLineSwitches,
|
applyEarlyLinuxCommandLineSwitches,
|
||||||
|
resolveAppControlHandoffTimeoutMs,
|
||||||
resolveLinuxPasswordStoreValue,
|
resolveLinuxPasswordStoreValue,
|
||||||
spawnDetachedApp,
|
spawnDetachedApp,
|
||||||
} from './main-entry-runtime';
|
} from './main-entry-runtime';
|
||||||
|
|
||||||
|
test('app-control handoffs allow for macOS application activation latency', () => {
|
||||||
|
assert.equal(resolveAppControlHandoffTimeoutMs('darwin'), 3000);
|
||||||
|
assert.equal(resolveAppControlHandoffTimeoutMs('linux'), 500);
|
||||||
|
assert.equal(resolveAppControlHandoffTimeoutMs('win32'), 500);
|
||||||
|
});
|
||||||
|
|
||||||
test('detached app launch policy stays in the startup runtime utilities', () => {
|
test('detached app launch policy stays in the startup runtime utilities', () => {
|
||||||
const entrySource = fs.readFileSync(path.join(process.cwd(), 'src/main-entry.ts'), 'utf8');
|
const entrySource = fs.readFileSync(path.join(process.cwd(), 'src/main-entry.ts'), 'utf8');
|
||||||
const runtimeSource = fs.readFileSync(
|
const runtimeSource = fs.readFileSync(
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ const TRANSPORTED_APP_ARGC_ENV = 'SUBMINER_APP_ARGC';
|
|||||||
const TRANSPORTED_APP_ARG_PREFIX = 'SUBMINER_APP_ARG_';
|
const TRANSPORTED_APP_ARG_PREFIX = 'SUBMINER_APP_ARG_';
|
||||||
const MAX_TRANSPORTED_APP_ARGS = 256;
|
const MAX_TRANSPORTED_APP_ARGS = 256;
|
||||||
const APP_NAME = 'SubMiner';
|
const APP_NAME = 'SubMiner';
|
||||||
|
const DEFAULT_APP_CONTROL_HANDOFF_TIMEOUT_MS = 500;
|
||||||
|
const MACOS_APP_CONTROL_HANDOFF_TIMEOUT_MS = 3000;
|
||||||
const MPV_LONG_OPTIONS_WITH_SEPARATE_VALUES = new Set([
|
const MPV_LONG_OPTIONS_WITH_SEPARATE_VALUES = new Set([
|
||||||
'--alang',
|
'--alang',
|
||||||
'--audio-file',
|
'--audio-file',
|
||||||
@@ -186,6 +188,14 @@ export function shouldForwardStartupArgvViaAppControl(
|
|||||||
return hasExplicitCommand(args);
|
return hasExplicitCommand(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resolveAppControlHandoffTimeoutMs(
|
||||||
|
platform: NodeJS.Platform = process.platform,
|
||||||
|
): number {
|
||||||
|
return platform === 'darwin'
|
||||||
|
? MACOS_APP_CONTROL_HANDOFF_TIMEOUT_MS
|
||||||
|
: DEFAULT_APP_CONTROL_HANDOFF_TIMEOUT_MS;
|
||||||
|
}
|
||||||
|
|
||||||
function readTransportedStartupArgs(env: NodeJS.ProcessEnv): string[] | null {
|
function readTransportedStartupArgs(env: NodeJS.ProcessEnv): string[] | null {
|
||||||
const rawCount = env[TRANSPORTED_APP_ARGC_ENV];
|
const rawCount = env[TRANSPORTED_APP_ARGC_ENV];
|
||||||
if (rawCount === undefined) {
|
if (rawCount === undefined) {
|
||||||
|
|||||||
+2
-1
@@ -9,6 +9,7 @@ import {
|
|||||||
normalizeLaunchMpvTargets,
|
normalizeLaunchMpvTargets,
|
||||||
normalizeStartupArgv,
|
normalizeStartupArgv,
|
||||||
applyEarlyLinuxCommandLineSwitches,
|
applyEarlyLinuxCommandLineSwitches,
|
||||||
|
resolveAppControlHandoffTimeoutMs,
|
||||||
sanitizeStartupEnv,
|
sanitizeStartupEnv,
|
||||||
sanitizeBackgroundEnv,
|
sanitizeBackgroundEnv,
|
||||||
sanitizeHelpEnv,
|
sanitizeHelpEnv,
|
||||||
@@ -214,7 +215,7 @@ async function forwardStartupArgvViaAppControlIfAvailable(): Promise<boolean> {
|
|||||||
|
|
||||||
const result = await sendAppControlCommand(process.argv, {
|
const result = await sendAppControlCommand(process.argv, {
|
||||||
configDir: userDataPath,
|
configDir: userDataPath,
|
||||||
timeoutMs: 500,
|
timeoutMs: resolveAppControlHandoffTimeoutMs(),
|
||||||
});
|
});
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
app.exit(0);
|
app.exit(0);
|
||||||
|
|||||||
+5
-1
@@ -331,6 +331,7 @@ import {
|
|||||||
acquireYoutubeSubtitleTrack,
|
acquireYoutubeSubtitleTrack,
|
||||||
acquireYoutubeSubtitleTracks,
|
acquireYoutubeSubtitleTracks,
|
||||||
} from './core/services/youtube/generate';
|
} from './core/services/youtube/generate';
|
||||||
|
import { applyOverlayClickThrough } from './core/services/overlay-click-through';
|
||||||
import { createYoutubeMediaCacheService } from './core/services/youtube/media-cache';
|
import { createYoutubeMediaCacheService } from './core/services/youtube/media-cache';
|
||||||
import { resolveYoutubePlaybackUrl } from './core/services/youtube/playback-resolve';
|
import { resolveYoutubePlaybackUrl } from './core/services/youtube/playback-resolve';
|
||||||
import { probeYoutubeTracks } from './core/services/youtube/track-probe';
|
import { probeYoutubeTracks } from './core/services/youtube/track-probe';
|
||||||
@@ -5009,6 +5010,9 @@ function syncLinuxVisibleOverlayMpvFullscreenMode(fullscreen: boolean): void {
|
|||||||
|
|
||||||
function initializeOverlayRuntime(): void {
|
function initializeOverlayRuntime(): void {
|
||||||
initializeOverlayRuntimeHandler();
|
initializeOverlayRuntimeHandler();
|
||||||
|
if (!(appState.initialArgs && isHeadlessInitialCommand(appState.initialArgs))) {
|
||||||
|
overlayModalRuntime.primeModalWindow();
|
||||||
|
}
|
||||||
appState.ankiIntegration?.setRecordCardsMinedCallback(recordTrackedCardsMined);
|
appState.ankiIntegration?.setRecordCardsMinedCallback(recordTrackedCardsMined);
|
||||||
appState.ankiIntegration?.setKnownWordCacheUpdatedCallback(
|
appState.ankiIntegration?.setKnownWordCacheUpdatedCallback(
|
||||||
refreshCurrentSubtitleAfterKnownWordUpdate,
|
refreshCurrentSubtitleAfterKnownWordUpdate,
|
||||||
@@ -5466,7 +5470,7 @@ const { registerIpcRuntimeHandlers } = composeIpcRuntimeHandlers({
|
|||||||
senderWindow === modalWindow &&
|
senderWindow === modalWindow &&
|
||||||
!senderWindow.isDestroyed()
|
!senderWindow.isDestroyed()
|
||||||
) {
|
) {
|
||||||
senderWindow.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(senderWindow);
|
||||||
senderWindow.hide();
|
senderWindow.hide();
|
||||||
}
|
}
|
||||||
handleOverlayModalClosedHandler(modal);
|
handleOverlayModalClosedHandler(modal);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type MockWindow = {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
url: string;
|
url: string;
|
||||||
contentReady: boolean;
|
contentReady: boolean;
|
||||||
|
documentLoaded: boolean;
|
||||||
loadCallbacks: Array<() => void>;
|
loadCallbacks: Array<() => void>;
|
||||||
readyToShowCallbacks: Array<() => void>;
|
readyToShowCallbacks: Array<() => void>;
|
||||||
};
|
};
|
||||||
@@ -31,6 +32,7 @@ function createMockWindow(): MockWindow & {
|
|||||||
getShowCount: () => number;
|
getShowCount: () => number;
|
||||||
getHideCount: () => number;
|
getHideCount: () => number;
|
||||||
show: () => void;
|
show: () => void;
|
||||||
|
showInactive: () => void;
|
||||||
hide: () => void;
|
hide: () => void;
|
||||||
destroy: () => void;
|
destroy: () => void;
|
||||||
focus: () => void;
|
focus: () => void;
|
||||||
@@ -61,6 +63,7 @@ function createMockWindow(): MockWindow & {
|
|||||||
loading: false,
|
loading: false,
|
||||||
url: 'file:///overlay/index.html?layer=modal',
|
url: 'file:///overlay/index.html?layer=modal',
|
||||||
contentReady: true,
|
contentReady: true,
|
||||||
|
documentLoaded: true,
|
||||||
loadCallbacks: [],
|
loadCallbacks: [],
|
||||||
readyToShowCallbacks: [],
|
readyToShowCallbacks: [],
|
||||||
};
|
};
|
||||||
@@ -84,6 +87,10 @@ function createMockWindow(): MockWindow & {
|
|||||||
state.visible = true;
|
state.visible = true;
|
||||||
state.showCount += 1;
|
state.showCount += 1;
|
||||||
},
|
},
|
||||||
|
showInactive: () => {
|
||||||
|
state.visible = true;
|
||||||
|
state.showCount += 1;
|
||||||
|
},
|
||||||
hide: () => {
|
hide: () => {
|
||||||
state.visible = false;
|
state.visible = false;
|
||||||
state.hideCount += 1;
|
state.hideCount += 1;
|
||||||
@@ -96,6 +103,10 @@ function createMockWindow(): MockWindow & {
|
|||||||
state.focused = true;
|
state.focused = true;
|
||||||
},
|
},
|
||||||
emitDidFinishLoad: () => {
|
emitDidFinishLoad: () => {
|
||||||
|
state.documentLoaded = true;
|
||||||
|
(
|
||||||
|
window as typeof window & { __subminerOverlayDocumentLoaded?: boolean }
|
||||||
|
).__subminerOverlayDocumentLoaded = true;
|
||||||
const callbacks = state.loadCallbacks.splice(0);
|
const callbacks = state.loadCallbacks.splice(0);
|
||||||
for (const callback of callbacks) {
|
for (const callback of callbacks) {
|
||||||
callback();
|
callback();
|
||||||
@@ -197,9 +208,22 @@ function createMockWindow(): MockWindow & {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(window, 'documentLoaded', {
|
||||||
|
get: () => state.documentLoaded,
|
||||||
|
set: (value: boolean) => {
|
||||||
|
state.documentLoaded = value;
|
||||||
|
(
|
||||||
|
window as typeof window & { __subminerOverlayDocumentLoaded?: boolean }
|
||||||
|
).__subminerOverlayDocumentLoaded = value;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
(
|
(
|
||||||
window as typeof window & { __subminerOverlayContentReady?: boolean }
|
window as typeof window & { __subminerOverlayContentReady?: boolean }
|
||||||
).__subminerOverlayContentReady = state.contentReady;
|
).__subminerOverlayContentReady = state.contentReady;
|
||||||
|
(
|
||||||
|
window as typeof window & { __subminerOverlayDocumentLoaded?: boolean }
|
||||||
|
).__subminerOverlayDocumentLoaded = state.documentLoaded;
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
@@ -259,6 +283,73 @@ test('sendToActiveOverlayWindow creates modal window lazily when absent', () =>
|
|||||||
assert.deepEqual(window.sent, [['jimaku:open']]);
|
assert.deepEqual(window.sent, [['jimaku:open']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const platform of ['darwin', 'win32'] as const) {
|
||||||
|
test(`primeModalWindow creates and warms a hidden modal on ${platform}`, () => {
|
||||||
|
const modalWindow = createMockWindow();
|
||||||
|
modalWindow.loading = true;
|
||||||
|
modalWindow.url = '';
|
||||||
|
modalWindow.contentReady = false;
|
||||||
|
modalWindow.documentLoaded = false;
|
||||||
|
let currentModal: ReturnType<typeof createMockWindow> | null = null;
|
||||||
|
let createCalls = 0;
|
||||||
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getModalWindow: () => currentModal as never,
|
||||||
|
createModalWindow: () => {
|
||||||
|
createCalls += 1;
|
||||||
|
currentModal = modalWindow;
|
||||||
|
return modalWindow as never;
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 1, y: 2, width: 300, height: 200 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
},
|
||||||
|
{ platform },
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(runtime.primeModalWindow(), true);
|
||||||
|
assert.equal(createCalls, 1);
|
||||||
|
assert.equal(modalWindow.isVisible(), false);
|
||||||
|
|
||||||
|
modalWindow.loading = false;
|
||||||
|
modalWindow.url = 'file:///overlay/index.html?layer=modal';
|
||||||
|
modalWindow.emitDidFinishLoad();
|
||||||
|
modalWindow.emitReadyToShow();
|
||||||
|
modalWindow.contentReady = true;
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
runtime.sendToActiveOverlayWindow('session-help:open', undefined, {
|
||||||
|
restoreOnModalClose: 'session-help',
|
||||||
|
preferModalWindow: true,
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
assert.equal(createCalls, 1);
|
||||||
|
assert.equal(modalWindow.isVisible(), true);
|
||||||
|
assert.deepEqual(modalWindow.sent, [['session-help:open']]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test('primeModalWindow leaves Linux modal creation lazy', () => {
|
||||||
|
let createCalls = 0;
|
||||||
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getModalWindow: () => null,
|
||||||
|
createModalWindow: () => {
|
||||||
|
createCalls += 1;
|
||||||
|
return createMockWindow() as never;
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
},
|
||||||
|
{ platform: 'linux' },
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(runtime.primeModalWindow(), false);
|
||||||
|
assert.equal(createCalls, 0);
|
||||||
|
});
|
||||||
|
|
||||||
test('sendToActiveOverlayWindow does not retain restore state when modal creation fails', () => {
|
test('sendToActiveOverlayWindow does not retain restore state when modal creation fails', () => {
|
||||||
const runtime = createOverlayModalRuntimeService({
|
const runtime = createOverlayModalRuntimeService({
|
||||||
getMainWindow: () => null,
|
getMainWindow: () => null,
|
||||||
@@ -301,7 +392,7 @@ test('sendToActiveOverlayWindow waits for blank modal URL before sending open co
|
|||||||
window.loading = false;
|
window.loading = false;
|
||||||
window.url = 'file:///overlay/index.html?layer=modal';
|
window.url = 'file:///overlay/index.html?layer=modal';
|
||||||
window.emitDidFinishLoad();
|
window.emitDidFinishLoad();
|
||||||
assert.deepEqual(window.sent, []);
|
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
||||||
|
|
||||||
window.contentReady = true;
|
window.contentReady = true;
|
||||||
window.emitReadyToShow();
|
window.emitReadyToShow();
|
||||||
@@ -311,15 +402,18 @@ test('sendToActiveOverlayWindow waits for blank modal URL before sending open co
|
|||||||
assert.equal(window.getShowCount(), 1);
|
assert.equal(window.getShowCount(), 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handleOverlayModalClosed hides modal window only after all pending modals close', () => {
|
test('handleOverlayModalClosed keeps the modal window warm after all pending modals close', () => {
|
||||||
const window = createMockWindow();
|
const window = createMockWindow();
|
||||||
const runtime = createOverlayModalRuntimeService({
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
getMainWindow: () => null,
|
getMainWindow: () => null,
|
||||||
getModalWindow: () => window as never,
|
getModalWindow: () => window as never,
|
||||||
createModalWindow: () => window as never,
|
createModalWindow: () => window as never,
|
||||||
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
setModalWindowBounds: () => {},
|
setModalWindowBounds: () => {},
|
||||||
});
|
},
|
||||||
|
{ platform: 'darwin' },
|
||||||
|
);
|
||||||
|
|
||||||
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
restoreOnModalClose: 'runtime-options',
|
restoreOnModalClose: 'runtime-options',
|
||||||
@@ -342,7 +436,9 @@ test('handleOverlayModalClosed hides modal window only after all pending modals
|
|||||||
assert.equal(window.isDestroyed(), false);
|
assert.equal(window.isDestroyed(), false);
|
||||||
|
|
||||||
runtime.handleOverlayModalClosed('subsync');
|
runtime.handleOverlayModalClosed('subsync');
|
||||||
assert.equal(window.isDestroyed(), true);
|
assert.equal(window.isDestroyed(), false);
|
||||||
|
assert.equal(window.isVisible(), false);
|
||||||
|
assert.equal(window.ignoreMouseEvents, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sendToActiveOverlayWindow prefers visible main overlay window for modal open', () => {
|
test('sendToActiveOverlayWindow prefers visible main overlay window for modal open', () => {
|
||||||
@@ -464,6 +560,46 @@ test('modal window path restores visible main overlay before modal input deactiv
|
|||||||
assert.deepEqual(events, ['state:true:visible:true', 'state:false:visible:true']);
|
assert.deepEqual(events, ['state:true:visible:true', 'state:false:visible:true']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('macOS maps a new modal panel before focusing SubMiner and hiding the subtitle overlay', () => {
|
||||||
|
const mainWindow = createMockWindow();
|
||||||
|
mainWindow.visible = true;
|
||||||
|
const modalWindow = createMockWindow();
|
||||||
|
const events: string[] = [];
|
||||||
|
const showInactive = modalWindow.showInactive;
|
||||||
|
modalWindow.showInactive = () => {
|
||||||
|
events.push('show-inactive');
|
||||||
|
showInactive();
|
||||||
|
};
|
||||||
|
const hideMainWindow = mainWindow.hide;
|
||||||
|
mainWindow.hide = () => {
|
||||||
|
events.push('hide-main');
|
||||||
|
hideMainWindow();
|
||||||
|
};
|
||||||
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
|
getMainWindow: () => mainWindow as never,
|
||||||
|
getModalWindow: () => modalWindow as never,
|
||||||
|
createModalWindow: () => modalWindow as never,
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: 'darwin',
|
||||||
|
focusApplication: () => events.push('focus-application'),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
|
preferModalWindow: true,
|
||||||
|
});
|
||||||
|
runtime.notifyOverlayModalOpened('runtime-options');
|
||||||
|
|
||||||
|
assert.deepEqual(events, ['show-inactive', 'focus-application', 'hide-main']);
|
||||||
|
assert.equal(modalWindow.isVisible(), true);
|
||||||
|
assert.equal(mainWindow.isVisible(), false);
|
||||||
|
});
|
||||||
|
|
||||||
test('modal window path runs final close handoff before modal input deactivates', () => {
|
test('modal window path runs final close handoff before modal input deactivates', () => {
|
||||||
const mainWindow = createMockWindow();
|
const mainWindow = createMockWindow();
|
||||||
mainWindow.visible = true;
|
mainWindow.visible = true;
|
||||||
@@ -650,15 +786,18 @@ test('handleOverlayModalClosed is a no-op when no modal window can be targeted',
|
|||||||
assert.deepEqual(state, []);
|
assert.deepEqual(state, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handleOverlayModalClosed destroys modal window for single kiku modal', () => {
|
test('handleOverlayModalClosed hides and retains modal window for single kiku modal', () => {
|
||||||
const window = createMockWindow();
|
const window = createMockWindow();
|
||||||
const runtime = createOverlayModalRuntimeService({
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
getMainWindow: () => null,
|
getMainWindow: () => null,
|
||||||
getModalWindow: () => window as never,
|
getModalWindow: () => window as never,
|
||||||
createModalWindow: () => window as never,
|
createModalWindow: () => window as never,
|
||||||
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
setModalWindowBounds: () => {},
|
setModalWindowBounds: () => {},
|
||||||
});
|
},
|
||||||
|
{ platform: 'darwin' },
|
||||||
|
);
|
||||||
|
|
||||||
runtime.sendToActiveOverlayWindow(
|
runtime.sendToActiveOverlayWindow(
|
||||||
'kiku:field-grouping-open',
|
'kiku:field-grouping-open',
|
||||||
@@ -669,7 +808,9 @@ test('handleOverlayModalClosed destroys modal window for single kiku modal', ()
|
|||||||
);
|
);
|
||||||
runtime.handleOverlayModalClosed('kiku');
|
runtime.handleOverlayModalClosed('kiku');
|
||||||
|
|
||||||
assert.equal(window.isDestroyed(), true);
|
assert.equal(window.isDestroyed(), false);
|
||||||
|
assert.equal(window.isVisible(), false);
|
||||||
|
assert.equal(window.ignoreMouseEvents, true);
|
||||||
assert.equal(runtime.getRestoreVisibleOverlayOnModalClose().size, 0);
|
assert.equal(runtime.getRestoreVisibleOverlayOnModalClose().size, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -719,8 +860,10 @@ test('modal fallback reveal skips showing window when content is not ready', asy
|
|||||||
assert.equal(window.ignoreMouseEvents, false);
|
assert.equal(window.ignoreMouseEvents, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sendToActiveOverlayWindow waits for modal ready-to-show before delivering open event', () => {
|
test('sendToActiveOverlayWindow delivers on first modal load without waiting for ready-to-show', () => {
|
||||||
const window = createMockWindow();
|
const window = createMockWindow();
|
||||||
|
window.loading = true;
|
||||||
|
window.url = '';
|
||||||
window.contentReady = false;
|
window.contentReady = false;
|
||||||
const runtime = createOverlayModalRuntimeService({
|
const runtime = createOverlayModalRuntimeService({
|
||||||
getMainWindow: () => null,
|
getMainWindow: () => null,
|
||||||
@@ -738,16 +881,100 @@ test('sendToActiveOverlayWindow waits for modal ready-to-show before delivering
|
|||||||
|
|
||||||
assert.equal(sent, true);
|
assert.equal(sent, true);
|
||||||
assert.deepEqual(window.sent, []);
|
assert.deepEqual(window.sent, []);
|
||||||
|
window.loading = false;
|
||||||
|
window.url = 'file:///overlay/index.html?layer=modal';
|
||||||
window.emitDidFinishLoad();
|
window.emitDidFinishLoad();
|
||||||
assert.deepEqual(window.sent, []);
|
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
||||||
|
|
||||||
window.contentReady = true;
|
window.contentReady = true;
|
||||||
window.emitReadyToShow();
|
window.emitReadyToShow();
|
||||||
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('sendToActiveOverlayWindow delivers when the modal loaded before listeners were registered', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
window.contentReady = false;
|
||||||
|
const runtime = createOverlayModalRuntimeService({
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getModalWindow: () => window as never,
|
||||||
|
createModalWindow: () => {
|
||||||
|
throw new Error('modal window should not be created when already present');
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
||||||
|
|
||||||
|
window.contentReady = true;
|
||||||
|
window.emitReadyToShow();
|
||||||
|
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sendToActiveOverlayWindow does not infer document readiness from a pending file URL', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
window.contentReady = false;
|
||||||
|
window.documentLoaded = false;
|
||||||
|
window.loading = false;
|
||||||
|
const runtime = createOverlayModalRuntimeService({
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getModalWindow: () => window as never,
|
||||||
|
createModalWindow: () => {
|
||||||
|
throw new Error('modal window should not be created when already present');
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
assert.deepEqual(window.sent, []);
|
||||||
|
|
||||||
|
window.emitDidFinishLoad();
|
||||||
|
assert.deepEqual(window.sent, [['runtime-options:open']]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sendToActiveOverlayWindow rejects stale content readiness during document reload', () => {
|
||||||
|
const window = createMockWindow();
|
||||||
|
window.contentReady = true;
|
||||||
|
window.documentLoaded = false;
|
||||||
|
window.loading = false;
|
||||||
|
const runtime = createOverlayModalRuntimeService({
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getModalWindow: () => window as never,
|
||||||
|
createModalWindow: () => {
|
||||||
|
throw new Error('modal window should not be created when already present');
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
runtime.sendToActiveOverlayWindow('session-help:open', undefined, {
|
||||||
|
restoreOnModalClose: 'session-help',
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
assert.deepEqual(window.sent, []);
|
||||||
|
|
||||||
|
window.emitDidFinishLoad();
|
||||||
|
assert.deepEqual(window.sent, [['session-help:open']]);
|
||||||
|
});
|
||||||
|
|
||||||
test('sendToActiveOverlayWindow flushes every queued load and ready listener before sending', () => {
|
test('sendToActiveOverlayWindow flushes every queued load and ready listener before sending', () => {
|
||||||
const window = createMockWindow();
|
const window = createMockWindow();
|
||||||
|
window.loading = true;
|
||||||
|
window.url = '';
|
||||||
window.contentReady = false;
|
window.contentReady = false;
|
||||||
const runtime = createOverlayModalRuntimeService({
|
const runtime = createOverlayModalRuntimeService({
|
||||||
getMainWindow: () => null,
|
getMainWindow: () => null,
|
||||||
@@ -773,29 +1000,73 @@ test('sendToActiveOverlayWindow flushes every queued load and ready listener bef
|
|||||||
);
|
);
|
||||||
assert.deepEqual(window.sent, []);
|
assert.deepEqual(window.sent, []);
|
||||||
|
|
||||||
|
window.loading = false;
|
||||||
|
window.url = 'file:///overlay/index.html?layer=modal';
|
||||||
window.emitDidFinishLoad();
|
window.emitDidFinishLoad();
|
||||||
assert.deepEqual(window.sent, []);
|
assert.deepEqual(window.sent, [['runtime-options:open'], ['session-help:open']]);
|
||||||
|
|
||||||
window.contentReady = true;
|
window.contentReady = true;
|
||||||
window.emitReadyToShow();
|
window.emitReadyToShow();
|
||||||
assert.deepEqual(window.sent, [['runtime-options:open'], ['session-help:open']]);
|
assert.deepEqual(window.sent, [['runtime-options:open'], ['session-help:open']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('modal reopen creates a fresh window after close destroys the previous one', () => {
|
test('modal reopen reuses the warm window and shows it immediately on macOS', () => {
|
||||||
const firstWindow = createMockWindow();
|
const modalWindow = createMockWindow();
|
||||||
const secondWindow = createMockWindow();
|
let createCalls = 0;
|
||||||
let currentModal: ReturnType<typeof createMockWindow> | null = firstWindow;
|
|
||||||
|
|
||||||
const runtime = createOverlayModalRuntimeService({
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
getMainWindow: () => null,
|
getMainWindow: () => null,
|
||||||
getModalWindow: () => currentModal as never,
|
getModalWindow: () => modalWindow as never,
|
||||||
createModalWindow: () => {
|
createModalWindow: () => {
|
||||||
currentModal = secondWindow;
|
createCalls += 1;
|
||||||
return secondWindow as never;
|
return modalWindow as never;
|
||||||
},
|
},
|
||||||
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
setModalWindowBounds: () => {},
|
setModalWindowBounds: () => {},
|
||||||
|
},
|
||||||
|
{ platform: 'darwin' },
|
||||||
|
);
|
||||||
|
|
||||||
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
});
|
});
|
||||||
|
runtime.notifyOverlayModalOpened('runtime-options');
|
||||||
|
runtime.handleOverlayModalClosed('runtime-options');
|
||||||
|
|
||||||
|
assert.equal(modalWindow.isDestroyed(), false);
|
||||||
|
assert.equal(modalWindow.isVisible(), false);
|
||||||
|
|
||||||
|
const sent = runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
|
restoreOnModalClose: 'runtime-options',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(sent, true);
|
||||||
|
assert.equal(createCalls, 0);
|
||||||
|
assert.equal(modalWindow.isVisible(), true);
|
||||||
|
assert.equal(modalWindow.getShowCount(), 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('modal reopen on Windows uses a fresh prewarmed interactive window', () => {
|
||||||
|
const firstWindow = createMockWindow();
|
||||||
|
const replacementWindow = createMockWindow();
|
||||||
|
let currentModal = firstWindow;
|
||||||
|
let createCalls = 0;
|
||||||
|
|
||||||
|
const runtime = createOverlayModalRuntimeService(
|
||||||
|
{
|
||||||
|
getMainWindow: () => null,
|
||||||
|
getModalWindow: () => currentModal as never,
|
||||||
|
createModalWindow: () => {
|
||||||
|
createCalls += 1;
|
||||||
|
currentModal = replacementWindow;
|
||||||
|
return replacementWindow as never;
|
||||||
|
},
|
||||||
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
|
setModalWindowBounds: () => {},
|
||||||
|
},
|
||||||
|
{ platform: 'win32' },
|
||||||
|
);
|
||||||
|
|
||||||
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
restoreOnModalClose: 'runtime-options',
|
restoreOnModalClose: 'runtime-options',
|
||||||
@@ -804,30 +1075,30 @@ test('modal reopen creates a fresh window after close destroys the previous one'
|
|||||||
runtime.handleOverlayModalClosed('runtime-options');
|
runtime.handleOverlayModalClosed('runtime-options');
|
||||||
|
|
||||||
assert.equal(firstWindow.isDestroyed(), true);
|
assert.equal(firstWindow.isDestroyed(), true);
|
||||||
|
assert.equal(currentModal, replacementWindow);
|
||||||
|
assert.equal(replacementWindow.isVisible(), false);
|
||||||
|
assert.equal(createCalls, 1);
|
||||||
|
|
||||||
const sent = runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
const sent = runtime.sendToActiveOverlayWindow('session-help:open', undefined, {
|
||||||
restoreOnModalClose: 'runtime-options',
|
restoreOnModalClose: 'session-help',
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(sent, true);
|
assert.equal(sent, true);
|
||||||
assert.equal(currentModal, secondWindow);
|
assert.equal(createCalls, 1);
|
||||||
assert.equal(secondWindow.getShowCount(), 0);
|
assert.equal(replacementWindow.isVisible(), true);
|
||||||
|
assert.equal(replacementWindow.ignoreMouseEvents, false);
|
||||||
|
assert.deepEqual(replacementWindow.sent, [['session-help:open']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('modal reopen after close-destroy notifies state change on fresh window lifecycle', () => {
|
test('modal reopen on the warm window notifies state change for each lifecycle', () => {
|
||||||
const firstWindow = createMockWindow();
|
const modalWindow = createMockWindow();
|
||||||
const secondWindow = createMockWindow();
|
|
||||||
let currentModal: ReturnType<typeof createMockWindow> | null = firstWindow;
|
|
||||||
const state: boolean[] = [];
|
const state: boolean[] = [];
|
||||||
|
|
||||||
const runtime = createOverlayModalRuntimeService(
|
const runtime = createOverlayModalRuntimeService(
|
||||||
{
|
{
|
||||||
getMainWindow: () => null,
|
getMainWindow: () => null,
|
||||||
getModalWindow: () => currentModal as never,
|
getModalWindow: () => modalWindow as never,
|
||||||
createModalWindow: () => {
|
createModalWindow: () => modalWindow as never,
|
||||||
currentModal = secondWindow;
|
|
||||||
return secondWindow as never;
|
|
||||||
},
|
|
||||||
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
|
||||||
setModalWindowBounds: () => {},
|
setModalWindowBounds: () => {},
|
||||||
},
|
},
|
||||||
@@ -835,6 +1106,7 @@ test('modal reopen after close-destroy notifies state change on fresh window lif
|
|||||||
onModalStateChange: (active: boolean): void => {
|
onModalStateChange: (active: boolean): void => {
|
||||||
state.push(active);
|
state.push(active);
|
||||||
},
|
},
|
||||||
|
platform: 'darwin',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -845,7 +1117,7 @@ test('modal reopen after close-destroy notifies state change on fresh window lif
|
|||||||
runtime.handleOverlayModalClosed('runtime-options');
|
runtime.handleOverlayModalClosed('runtime-options');
|
||||||
|
|
||||||
assert.deepEqual(state, [true, false]);
|
assert.deepEqual(state, [true, false]);
|
||||||
assert.equal(firstWindow.isDestroyed(), true);
|
assert.equal(modalWindow.isDestroyed(), false);
|
||||||
|
|
||||||
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
|
||||||
restoreOnModalClose: 'runtime-options',
|
restoreOnModalClose: 'runtime-options',
|
||||||
@@ -853,7 +1125,7 @@ test('modal reopen after close-destroy notifies state change on fresh window lif
|
|||||||
runtime.notifyOverlayModalOpened('runtime-options');
|
runtime.notifyOverlayModalOpened('runtime-options');
|
||||||
|
|
||||||
assert.deepEqual(state, [true, false, true]);
|
assert.deepEqual(state, [true, false, true]);
|
||||||
assert.equal(currentModal, secondWindow);
|
assert.equal(modalWindow.isVisible(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('visible stale modal window is made interactive again before reopening', () => {
|
test('visible stale modal window is made interactive again before reopening', () => {
|
||||||
|
|||||||
+100
-18
@@ -2,7 +2,11 @@ import type { BrowserWindow } from 'electron';
|
|||||||
import type { OverlayHostedModal } from '../shared/ipc/contracts';
|
import type { OverlayHostedModal } from '../shared/ipc/contracts';
|
||||||
import type { WindowGeometry } from '../types';
|
import type { WindowGeometry } from '../types';
|
||||||
import type { HyprlandPlacementStatus } from '../core/services/hyprland-window-placement';
|
import type { HyprlandPlacementStatus } from '../core/services/hyprland-window-placement';
|
||||||
import { OVERLAY_WINDOW_CONTENT_READY_FLAG } from '../core/services/overlay-window-flags';
|
import { applyOverlayClickThrough } from '../core/services/overlay-click-through';
|
||||||
|
import {
|
||||||
|
OVERLAY_WINDOW_CONTENT_READY_FLAG,
|
||||||
|
OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG,
|
||||||
|
} from '../core/services/overlay-window-flags';
|
||||||
|
|
||||||
const MODAL_REVEAL_FALLBACK_DELAY_MS = 250;
|
const MODAL_REVEAL_FALLBACK_DELAY_MS = 250;
|
||||||
// The dedicated modal window maps asynchronously on Wayland; a single reconcile can fire
|
// The dedicated modal window maps asynchronously on Wayland; a single reconcile can fire
|
||||||
@@ -39,6 +43,7 @@ export interface OverlayWindowResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface OverlayModalRuntime {
|
export interface OverlayModalRuntime {
|
||||||
|
primeModalWindow: () => boolean;
|
||||||
sendToActiveOverlayWindow: (
|
sendToActiveOverlayWindow: (
|
||||||
channel: string,
|
channel: string,
|
||||||
payload?: unknown,
|
payload?: unknown,
|
||||||
@@ -59,6 +64,8 @@ export interface OverlayModalRuntime {
|
|||||||
type RevealFallbackHandle = NonNullable<Parameters<typeof globalThis.clearTimeout>[0]>;
|
type RevealFallbackHandle = NonNullable<Parameters<typeof globalThis.clearTimeout>[0]>;
|
||||||
|
|
||||||
export interface OverlayModalRuntimeOptions {
|
export interface OverlayModalRuntimeOptions {
|
||||||
|
platform?: NodeJS.Platform;
|
||||||
|
focusApplication?: () => void;
|
||||||
onModalStateChange?: (isActive: boolean) => void;
|
onModalStateChange?: (isActive: boolean) => void;
|
||||||
onFinalModalClosed?: () => void;
|
onFinalModalClosed?: () => void;
|
||||||
scheduleRevealFallback?: (callback: () => void, delayMs: number) => RevealFallbackHandle;
|
scheduleRevealFallback?: (callback: () => void, delayMs: number) => RevealFallbackHandle;
|
||||||
@@ -79,6 +86,11 @@ export function createOverlayModalRuntimeService(
|
|||||||
let pendingModalWindowReveal: BrowserWindow | null = null;
|
let pendingModalWindowReveal: BrowserWindow | null = null;
|
||||||
let pendingModalWindowRevealTimeout: RevealFallbackHandle | null = null;
|
let pendingModalWindowRevealTimeout: RevealFallbackHandle | null = null;
|
||||||
const modalWindowBoundsReconcileGenerations = new WeakMap<BrowserWindow, number>();
|
const modalWindowBoundsReconcileGenerations = new WeakMap<BrowserWindow, number>();
|
||||||
|
const modalWindowPrimeListenersRegistered = new WeakSet<BrowserWindow>();
|
||||||
|
const platform = options.platform ?? process.platform;
|
||||||
|
const shouldPrimeModalWindow = platform === 'darwin' || platform === 'win32';
|
||||||
|
const reuseModalWindowAfterClose = platform === 'darwin';
|
||||||
|
const focusApplication = options.focusApplication ?? requestOverlayApplicationFocus;
|
||||||
const scheduleRevealFallback = (callback: () => void, delayMs: number): RevealFallbackHandle =>
|
const scheduleRevealFallback = (callback: () => void, delayMs: number): RevealFallbackHandle =>
|
||||||
(options.scheduleRevealFallback ?? globalThis.setTimeout)(callback, delayMs);
|
(options.scheduleRevealFallback ?? globalThis.setTimeout)(callback, delayMs);
|
||||||
const clearRevealFallback = (timeout: RevealFallbackHandle): void =>
|
const clearRevealFallback = (timeout: RevealFallbackHandle): void =>
|
||||||
@@ -134,7 +146,11 @@ export function createOverlayModalRuntimeService(
|
|||||||
}
|
}
|
||||||
const overlayWindow = window as BrowserWindow & {
|
const overlayWindow = window as BrowserWindow & {
|
||||||
[OVERLAY_WINDOW_CONTENT_READY_FLAG]?: boolean;
|
[OVERLAY_WINDOW_CONTENT_READY_FLAG]?: boolean;
|
||||||
|
[OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG]?: boolean;
|
||||||
};
|
};
|
||||||
|
if (overlayWindow[OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG] === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
typeof overlayWindow[OVERLAY_WINDOW_CONTENT_READY_FLAG] === 'boolean' &&
|
typeof overlayWindow[OVERLAY_WINDOW_CONTENT_READY_FLAG] === 'boolean' &&
|
||||||
overlayWindow[OVERLAY_WINDOW_CONTENT_READY_FLAG] !== true
|
overlayWindow[OVERLAY_WINDOW_CONTENT_READY_FLAG] !== true
|
||||||
@@ -145,6 +161,50 @@ export function createOverlayModalRuntimeService(
|
|||||||
return currentURL !== '' && currentURL !== 'about:blank';
|
return currentURL !== '' && currentURL !== 'about:blank';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isWindowLoadedForIpc = (window: BrowserWindow): boolean => {
|
||||||
|
if (window.isDestroyed() || window.webContents.isLoading()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const overlayWindow = window as BrowserWindow & {
|
||||||
|
[OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG]?: boolean;
|
||||||
|
};
|
||||||
|
if (overlayWindow[OVERLAY_WINDOW_DOCUMENT_LOADED_FLAG] !== true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const currentURL = window.webContents.getURL();
|
||||||
|
return currentURL !== '' && currentURL !== 'about:blank';
|
||||||
|
};
|
||||||
|
|
||||||
|
const markModalWindowPrimed = (window: BrowserWindow): void => {
|
||||||
|
if (deps.getModalWindow() !== window || !isWindowLoadedForIpc(window)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modalWindowPrimedForImmediateShow = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const primeModalWindow = (): boolean => {
|
||||||
|
if (!shouldPrimeModalWindow) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const modalWindow = resolveModalWindow();
|
||||||
|
if (!modalWindow) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
deps.setModalWindowBounds(deps.getModalGeometry());
|
||||||
|
if (isWindowReadyForIpc(modalWindow)) {
|
||||||
|
modalWindowPrimedForImmediateShow = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!modalWindowPrimeListenersRegistered.has(modalWindow)) {
|
||||||
|
modalWindowPrimeListenersRegistered.add(modalWindow);
|
||||||
|
modalWindow.webContents.once('did-finish-load', () => markModalWindowPrimed(modalWindow));
|
||||||
|
modalWindow.once('ready-to-show', () => markModalWindowPrimed(modalWindow));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const elevateModalWindow = (window: BrowserWindow): void => {
|
const elevateModalWindow = (window: BrowserWindow): void => {
|
||||||
if (window.isDestroyed()) return;
|
if (window.isDestroyed()) return;
|
||||||
window.setAlwaysOnTop(true, 'screen-saver', 3);
|
window.setAlwaysOnTop(true, 'screen-saver', 3);
|
||||||
@@ -205,16 +265,19 @@ export function createOverlayModalRuntimeService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let delivered = false;
|
let delivered = false;
|
||||||
const deliverWhenReady = (): void => {
|
const deliver = (isReady: () => boolean): void => {
|
||||||
if (delivered || window.isDestroyed() || !isWindowReadyForIpc(window)) {
|
if (delivered || window.isDestroyed() || !isReady()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delivered = true;
|
delivered = true;
|
||||||
sendNow(window);
|
sendNow(window);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.webContents.once('did-finish-load', deliverWhenReady);
|
// A hidden macOS panel may not emit ready-to-show until it is presented. The
|
||||||
window.once('ready-to-show', deliverWhenReady);
|
// renderer can safely receive IPC as soon as its document has finished loading.
|
||||||
|
window.webContents.once('did-finish-load', () => deliver(() => isWindowLoadedForIpc(window)));
|
||||||
|
window.once('ready-to-show', () => deliver(() => isWindowReadyForIpc(window)));
|
||||||
|
deliver(() => isWindowLoadedForIpc(window));
|
||||||
};
|
};
|
||||||
|
|
||||||
const showModalWindow = (
|
const showModalWindow = (
|
||||||
@@ -224,13 +287,20 @@ export function createOverlayModalRuntimeService(
|
|||||||
} = { passThroughMouseEvents: false },
|
} = { passThroughMouseEvents: false },
|
||||||
): void => {
|
): void => {
|
||||||
setWindowFocusable(window);
|
setWindowFocusable(window);
|
||||||
requestOverlayApplicationFocus();
|
const wasVisible = window.isVisible();
|
||||||
if (!window.isVisible()) {
|
if (!wasVisible && platform === 'darwin') {
|
||||||
|
// Mapping the panel first keeps it attached to mpv's active fullscreen Space.
|
||||||
|
window.showInactive();
|
||||||
|
focusApplication();
|
||||||
|
} else {
|
||||||
|
focusApplication();
|
||||||
|
}
|
||||||
|
if (!wasVisible && platform !== 'darwin') {
|
||||||
window.show();
|
window.show();
|
||||||
}
|
}
|
||||||
elevateModalWindow(window);
|
elevateModalWindow(window);
|
||||||
if (options.passThroughMouseEvents) {
|
if (options.passThroughMouseEvents) {
|
||||||
window.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(window, platform === 'win32');
|
||||||
} else {
|
} else {
|
||||||
window.setIgnoreMouseEvents(false);
|
window.setIgnoreMouseEvents(false);
|
||||||
}
|
}
|
||||||
@@ -245,11 +315,11 @@ export function createOverlayModalRuntimeService(
|
|||||||
|
|
||||||
const ensureModalWindowInteractive = (window: BrowserWindow): void => {
|
const ensureModalWindowInteractive = (window: BrowserWindow): void => {
|
||||||
setWindowFocusable(window);
|
setWindowFocusable(window);
|
||||||
requestOverlayApplicationFocus();
|
|
||||||
window.setIgnoreMouseEvents(false);
|
window.setIgnoreMouseEvents(false);
|
||||||
elevateModalWindow(window);
|
elevateModalWindow(window);
|
||||||
|
|
||||||
if (window.isVisible()) {
|
if (window.isVisible()) {
|
||||||
|
focusApplication();
|
||||||
window.focus();
|
window.focus();
|
||||||
window.webContents.focus();
|
window.webContents.focus();
|
||||||
const reconcileGeneration = nextModalWindowBoundsReconcileGeneration(window);
|
const reconcileGeneration = nextModalWindowBoundsReconcileGeneration(window);
|
||||||
@@ -291,7 +361,7 @@ export function createOverlayModalRuntimeService(
|
|||||||
mainWindowMousePassthroughForcedByModal = false;
|
mainWindowMousePassthroughForcedByModal = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mainWindow.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(mainWindow, platform === 'win32');
|
||||||
mainWindowMousePassthroughForcedByModal = true;
|
mainWindowMousePassthroughForcedByModal = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -447,9 +517,21 @@ export function createOverlayModalRuntimeService(
|
|||||||
if (restoreVisibleOverlayOnModalClose.size === 0) {
|
if (restoreVisibleOverlayOnModalClose.size === 0) {
|
||||||
clearPendingModalWindowReveal();
|
clearPendingModalWindowReveal();
|
||||||
if (modalWindow && !modalWindow.isDestroyed()) {
|
if (modalWindow && !modalWindow.isDestroyed()) {
|
||||||
|
if (reuseModalWindowAfterClose) {
|
||||||
|
applyOverlayClickThrough(modalWindow, false);
|
||||||
|
modalWindow.hide();
|
||||||
|
markModalWindowPrimed(modalWindow);
|
||||||
|
} else {
|
||||||
modalWindow.destroy();
|
modalWindow.destroy();
|
||||||
}
|
|
||||||
modalWindowPrimedForImmediateShow = false;
|
modalWindowPrimedForImmediateShow = false;
|
||||||
|
// Reusing a transparent click-through BrowserWindow can leave later modal sessions
|
||||||
|
// non-interactive on Windows. Recycle the renderer after every close, then warm its
|
||||||
|
// replacement so the next shortcut still opens promptly.
|
||||||
|
if (platform === 'win32') {
|
||||||
|
primeModalWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
mainWindowMousePassthroughForcedByModal = false;
|
mainWindowMousePassthroughForcedByModal = false;
|
||||||
setMainWindowVisibilityForModal(false);
|
setMainWindowVisibilityForModal(false);
|
||||||
try {
|
try {
|
||||||
@@ -478,17 +560,16 @@ export function createOverlayModalRuntimeService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const modalWindow = deps.getModalWindow();
|
const modalWindow = deps.getModalWindow();
|
||||||
|
if (targetWindow.isVisible()) {
|
||||||
|
ensureModalWindowInteractive(targetWindow);
|
||||||
|
} else {
|
||||||
|
showModalWindow(targetWindow);
|
||||||
|
}
|
||||||
|
|
||||||
if (modalWindow && !modalWindow.isDestroyed() && targetWindow === modalWindow) {
|
if (modalWindow && !modalWindow.isDestroyed() && targetWindow === modalWindow) {
|
||||||
setMainWindowMousePassthroughForModal(true);
|
setMainWindowMousePassthroughForModal(true);
|
||||||
setMainWindowVisibilityForModal(true);
|
setMainWindowVisibilityForModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetWindow.isVisible()) {
|
|
||||||
ensureModalWindowInteractive(targetWindow);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showModalWindow(targetWindow);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const waitForModalOpen = async (modal: OverlayHostedModal, timeoutMs: number): Promise<boolean> =>
|
const waitForModalOpen = async (modal: OverlayHostedModal, timeoutMs: number): Promise<boolean> =>
|
||||||
@@ -515,6 +596,7 @@ export function createOverlayModalRuntimeService(
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
primeModalWindow,
|
||||||
sendToActiveOverlayWindow,
|
sendToActiveOverlayWindow,
|
||||||
openRuntimeOptionsPalette,
|
openRuntimeOptionsPalette,
|
||||||
openJimaku,
|
openJimaku,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { applyOverlayClickThrough } from '../../core/services/overlay-click-through';
|
||||||
|
|
||||||
type StatsOverlayVisibilityWindow = {
|
type StatsOverlayVisibilityWindow = {
|
||||||
isDestroyed: () => boolean;
|
isDestroyed: () => boolean;
|
||||||
isVisible: () => boolean;
|
isVisible: () => boolean;
|
||||||
@@ -8,7 +10,7 @@ function makeOverlayMousePassive(window: StatsOverlayVisibilityWindow | null): v
|
|||||||
if (!window || window.isDestroyed() || !window.isVisible()) {
|
if (!window || window.isDestroyed() || !window.isVisible()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createStatsOverlayVisibilityChangeHandler(deps: {
|
export function createStatsOverlayVisibilityChangeHandler(deps: {
|
||||||
|
|||||||
@@ -31,6 +31,20 @@ function makeSpawn(): { spawn: SyncLauncherSpawn; children: FakeChild[]; command
|
|||||||
return { spawn, children, commands };
|
return { spawn, children, commands };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForResult<T>(promise: Promise<T>, timeoutMs = 3000): Promise<T> {
|
||||||
|
let timeout: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
try {
|
||||||
|
return await Promise.race([
|
||||||
|
promise,
|
||||||
|
new Promise<never>((_, reject) => {
|
||||||
|
timeout = setTimeout(() => reject(new Error('Timed out waiting for result.')), timeoutMs);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
} finally {
|
||||||
|
if (timeout !== null) clearTimeout(timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test('runSyncLauncher parses NDJSON events across chunk boundaries', async () => {
|
test('runSyncLauncher parses NDJSON events across chunk boundaries', async () => {
|
||||||
const { spawn, children, commands } = makeSpawn();
|
const { spawn, children, commands } = makeSpawn();
|
||||||
const events: SyncProgressEvent[] = [];
|
const events: SyncProgressEvent[] = [];
|
||||||
@@ -96,7 +110,9 @@ test('runSyncLauncher settles after exit when close never arrives', async () =>
|
|||||||
// so `close` never fires.
|
// so `close` never fires.
|
||||||
child.emit('exit', 1, null);
|
child.emit('exit', 1, null);
|
||||||
|
|
||||||
const result = await handle.done;
|
// Keep the isolated Bun test process alive while the production drain timer
|
||||||
|
// remains unref'ed, and fail instead of hanging if the result never settles.
|
||||||
|
const result = await waitForResult(handle.done);
|
||||||
assert.equal(result.ok, false);
|
assert.equal(result.ok, false);
|
||||||
assert.match(result.error ?? '', /remote refused/);
|
assert.match(result.error ?? '', /remote refused/);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export function runSyncLauncher(options: {
|
|||||||
spawn?: SyncLauncherSpawn;
|
spawn?: SyncLauncherSpawn;
|
||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
}): SyncLauncherRunHandle {
|
}): SyncLauncherRunHandle {
|
||||||
const spawn =
|
const spawn: SyncLauncherSpawn =
|
||||||
options.spawn ??
|
options.spawn ??
|
||||||
((command, args) => {
|
((command, args) => {
|
||||||
// The child must boot as a full Electron app (its entry handles
|
// The child must boot as a full Electron app (its entry handles
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { type BrowserWindow, screen } from 'electron';
|
import { type BrowserWindow, screen } from 'electron';
|
||||||
import { execFile } from 'node:child_process';
|
import { execFile } from 'node:child_process';
|
||||||
import { startOverlayWindowTracker as startOverlayWindowTrackerCore } from '../../core/services';
|
import { startOverlayWindowTracker as startOverlayWindowTrackerCore } from '../../core/services';
|
||||||
|
import { applyOverlayClickThrough } from '../../core/services/overlay-click-through';
|
||||||
import { isHeadlessInitialCommand, type CliArgs } from '../../cli/args';
|
import { isHeadlessInitialCommand, type CliArgs } from '../../cli/args';
|
||||||
import type { OverlayContentMeasurement, WindowGeometry } from '../../types';
|
import type { OverlayContentMeasurement, WindowGeometry } from '../../types';
|
||||||
import { createWindowTracker as createWindowTrackerCore } from '../../window-trackers';
|
import { createWindowTracker as createWindowTrackerCore } from '../../window-trackers';
|
||||||
@@ -603,7 +604,7 @@ export function createVisibleOverlayInteractionRuntime(deps: VisibleOverlayInter
|
|||||||
if (active) {
|
if (active) {
|
||||||
mainWindow.setIgnoreMouseEvents(false);
|
mainWindow.setIgnoreMouseEvents(false);
|
||||||
} else {
|
} else {
|
||||||
mainWindow.setIgnoreMouseEvents(true, { forward: true });
|
applyOverlayClickThrough(mainWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+100
-28
@@ -1,4 +1,4 @@
|
|||||||
import { execFileSync } from 'node:child_process';
|
import { execFile } from 'node:child_process';
|
||||||
import koffi from 'koffi';
|
import koffi from 'koffi';
|
||||||
import { matchesMpvSocketPathInCommandLine } from './mpv-socket-match';
|
import { matchesMpvSocketPathInCommandLine } from './mpv-socket-match';
|
||||||
|
|
||||||
@@ -173,16 +173,52 @@ function getProcessNameByPid(pid: number): string | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const processCommandLineCache = new Map<number, string>();
|
// Short-lived cache so the 250ms poll doesn't re-query every top-level window's process
|
||||||
|
// on each pass. The TTL bounds staleness from PID reuse.
|
||||||
|
const PROCESS_NAME_CACHE_TTL_MS = 5_000;
|
||||||
|
const PROCESS_NAME_CACHE_PRUNE_THRESHOLD = 512;
|
||||||
|
const processNameCache = new Map<number, { name: string | null; expiresAtMs: number }>();
|
||||||
|
|
||||||
function getProcessCommandLineByPid(pid: number): string | null {
|
function getCachedProcessNameByPid(pid: number): string | null {
|
||||||
if (processCommandLineCache.has(pid)) {
|
const nowMs = Date.now();
|
||||||
return processCommandLineCache.get(pid) ?? null;
|
const cached = processNameCache.get(pid);
|
||||||
|
if (cached && cached.expiresAtMs > nowMs) {
|
||||||
|
return cached.name;
|
||||||
}
|
}
|
||||||
|
const name = getProcessNameByPid(pid);
|
||||||
|
processNameCache.set(pid, { name, expiresAtMs: nowMs + PROCESS_NAME_CACHE_TTL_MS });
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
let commandLine: string | null = null;
|
function pruneExpiredProcessNames(nowMs: number): void {
|
||||||
try {
|
if (processNameCache.size <= PROCESS_NAME_CACHE_PRUNE_THRESHOLD) return;
|
||||||
const output = execFileSync(
|
for (const [pid, entry] of processNameCache) {
|
||||||
|
if (entry.expiresAtMs <= nowMs) {
|
||||||
|
processNameCache.delete(pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProcessCommandLineCacheEntry =
|
||||||
|
| { state: 'resolved'; commandLine: string; expiresAtMs: number; refreshInFlight: boolean }
|
||||||
|
| { state: 'pending' }
|
||||||
|
| { state: 'failed'; retryAtMs: number; backoffMs: number };
|
||||||
|
|
||||||
|
const COMMAND_LINE_RETRY_INITIAL_BACKOFF_MS = 2_000;
|
||||||
|
const COMMAND_LINE_RETRY_MAX_BACKOFF_MS = 30_000;
|
||||||
|
// A process command line never changes, so a resolved entry only has to expire to survive
|
||||||
|
// Windows PID reuse (a dead mpv's PID handed to a new instance, whose stale socket path would
|
||||||
|
// otherwise match the wrong window forever). Longer than the process-name TTL because each
|
||||||
|
// refresh costs a PowerShell spawn, and the cached value keeps being served while the refresh
|
||||||
|
// runs, so expiry never interrupts window matching.
|
||||||
|
const COMMAND_LINE_CACHE_TTL_MS = 60_000;
|
||||||
|
const processCommandLineCache = new Map<number, ProcessCommandLineCacheEntry>();
|
||||||
|
|
||||||
|
function queryProcessCommandLine(
|
||||||
|
pid: number,
|
||||||
|
onResult: (commandLine: string | null) => void,
|
||||||
|
): void {
|
||||||
|
execFile(
|
||||||
'powershell.exe',
|
'powershell.exe',
|
||||||
[
|
[
|
||||||
'-NoProfile',
|
'-NoProfile',
|
||||||
@@ -195,21 +231,67 @@ function getProcessCommandLineByPid(pid: number): string | null {
|
|||||||
{
|
{
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
windowsHide: true,
|
windowsHide: true,
|
||||||
stdio: ['ignore', 'pipe', 'ignore'],
|
|
||||||
timeout: 1500,
|
timeout: 1500,
|
||||||
},
|
},
|
||||||
).trim();
|
(error, stdout) => {
|
||||||
commandLine = output.length > 0 ? output : null;
|
const output = error ? '' : stdout.trim();
|
||||||
} catch {
|
onResult(output.length > 0 ? output : null);
|
||||||
commandLine = null;
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolves a process command line via a background PowerShell lookup. Returns null until the
|
||||||
|
// first lookup completes; the caller's next poll picks up the cached result. Failures are
|
||||||
|
// negative-cached with exponential backoff: the synchronous version of this lookup could
|
||||||
|
// block the main thread for its full 1.5s timeout on every 250ms poll, which (combined with
|
||||||
|
// the forward:true mouse hook) stalled mouse input system-wide.
|
||||||
|
function getProcessCommandLineByPid(pid: number): string | null {
|
||||||
|
const entry = processCommandLineCache.get(pid);
|
||||||
|
const nowMs = Date.now();
|
||||||
|
|
||||||
|
if (entry?.state === 'resolved') {
|
||||||
|
if (nowMs >= entry.expiresAtMs && !entry.refreshInFlight) {
|
||||||
|
entry.refreshInFlight = true;
|
||||||
|
queryProcessCommandLine(pid, (commandLine) => {
|
||||||
|
processCommandLineCache.set(pid, {
|
||||||
|
state: 'resolved',
|
||||||
|
// A failed refresh is usually a transient query error rather than a dead process
|
||||||
|
// (a gone process owns no window, so it is never looked up again). Keep the last
|
||||||
|
// known command line and re-check after the next TTL.
|
||||||
|
commandLine: commandLine ?? entry.commandLine,
|
||||||
|
expiresAtMs: Date.now() + COMMAND_LINE_CACHE_TTL_MS,
|
||||||
|
refreshInFlight: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return entry.commandLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entry?.state === 'pending') return null;
|
||||||
|
if (entry?.state === 'failed' && nowMs < entry.retryAtMs) return null;
|
||||||
|
|
||||||
|
const nextBackoffMs =
|
||||||
|
entry?.state === 'failed'
|
||||||
|
? Math.min(entry.backoffMs * 2, COMMAND_LINE_RETRY_MAX_BACKOFF_MS)
|
||||||
|
: COMMAND_LINE_RETRY_INITIAL_BACKOFF_MS;
|
||||||
|
processCommandLineCache.set(pid, { state: 'pending' });
|
||||||
|
queryProcessCommandLine(pid, (commandLine) => {
|
||||||
if (commandLine !== null) {
|
if (commandLine !== null) {
|
||||||
processCommandLineCache.set(pid, commandLine);
|
processCommandLineCache.set(pid, {
|
||||||
|
state: 'resolved',
|
||||||
|
commandLine,
|
||||||
|
expiresAtMs: Date.now() + COMMAND_LINE_CACHE_TTL_MS,
|
||||||
|
refreshInFlight: false,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
processCommandLineCache.delete(pid);
|
processCommandLineCache.set(pid, {
|
||||||
|
state: 'failed',
|
||||||
|
retryAtMs: Date.now() + nextBackoffMs,
|
||||||
|
backoffMs: nextBackoffMs,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return commandLine;
|
});
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findMpvWindows(targetSocketPath?: string | null): MpvPollResult {
|
export function findMpvWindows(targetSocketPath?: string | null): MpvPollResult {
|
||||||
@@ -217,8 +299,7 @@ export function findMpvWindows(targetSocketPath?: string | null): MpvPollResult
|
|||||||
const matches: MpvWindowMatch[] = [];
|
const matches: MpvWindowMatch[] = [];
|
||||||
let hasMinimized = false;
|
let hasMinimized = false;
|
||||||
let hasFocused = false;
|
let hasFocused = false;
|
||||||
const processNameCache = new Map<number, string | null>();
|
pruneExpiredProcessNames(Date.now());
|
||||||
const processCommandLineLookupCache = new Map<number, string | null>();
|
|
||||||
|
|
||||||
const cb = koffi.register((hwnd: number, _lParam: number) => {
|
const cb = koffi.register((hwnd: number, _lParam: number) => {
|
||||||
if (!IsWindowVisible(hwnd)) return true;
|
if (!IsWindowVisible(hwnd)) return true;
|
||||||
@@ -228,21 +309,12 @@ export function findMpvWindows(targetSocketPath?: string | null): MpvPollResult
|
|||||||
const pidValue = pid[0]!;
|
const pidValue = pid[0]!;
|
||||||
if (pidValue === 0) return true;
|
if (pidValue === 0) return true;
|
||||||
|
|
||||||
let processName = processNameCache.get(pidValue);
|
const processName = getCachedProcessNameByPid(pidValue);
|
||||||
if (processName === undefined) {
|
|
||||||
processName = getProcessNameByPid(pidValue);
|
|
||||||
processNameCache.set(pidValue, processName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!processName || processName.toLowerCase() !== 'mpv') return true;
|
if (!processName || processName.toLowerCase() !== 'mpv') return true;
|
||||||
|
|
||||||
let commandLine: string | null = null;
|
let commandLine: string | null = null;
|
||||||
if (targetSocketPath) {
|
if (targetSocketPath) {
|
||||||
commandLine = processCommandLineLookupCache.get(pidValue) ?? null;
|
|
||||||
if (!processCommandLineLookupCache.has(pidValue)) {
|
|
||||||
commandLine = getProcessCommandLineByPid(pidValue);
|
commandLine = getProcessCommandLineByPid(pidValue);
|
||||||
processCommandLineLookupCache.set(pidValue, commandLine);
|
|
||||||
}
|
|
||||||
if (!commandLine || !matchesMpvSocketPathInCommandLine(commandLine, targetSocketPath)) {
|
if (!commandLine || !matchesMpvSocketPathInCommandLine(commandLine, targetSocketPath)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user