-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix: Windows WGC native capture fallback & special character path encoding (double cursor bug + fail to capture screen & consistent browser capture fallback) #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
webadderall
merged 4 commits into
webadderallorg:main
from
birkls:fix/windows-wgc-capture-and-encoding
May 17, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
65c832e
fix(windows): resolve WGC capture failure and non-ASCII path encoding…
birkls 1f04674
fix(windows): address PR 517 review feedback
webadderall 7e3963f
fix(windows): preserve staged native capture outputs
webadderall f807ba3
fix(windows): clean up staged capture temp files
webadderall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { spawnSync } from "node:child_process"; | ||
|
|
||
| /** | ||
| * Represents a Windows monitor handle and its physical desktop coordinates. | ||
| */ | ||
| export interface WinMonitorHandle { | ||
| handle: number; | ||
| x: number; | ||
| y: number; | ||
| width: number; | ||
| height: number; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves raw HMONITOR handles from the Windows OS using a PowerShell bridge. | ||
| * This is necessary because Electron's display IDs are often internal hashes that | ||
| * cannot be used directly with native Windows APIs like Graphics Capture (WGC). | ||
| */ | ||
| export function getMonitorHandles(): WinMonitorHandle[] { | ||
| if (process.platform !== "win32") return []; | ||
|
|
||
| // PowerShell snippet that uses P/Invoke to call EnumDisplayMonitors and return raw handles + bounds. | ||
| const psScript = ` | ||
| Add-Type -TypeDefinition @" | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using System.Collections.Generic; | ||
|
|
||
| public class MonitorHelper { | ||
| [DllImport("user32.dll")] | ||
| public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumProc lpfnEnum, IntPtr dwData); | ||
|
|
||
| public delegate bool MonitorEnumProc(IntPtr hMonitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr dwData); | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| public struct Rect { | ||
| public int left; | ||
| public int top; | ||
| public int right; | ||
| public int bottom; | ||
| } | ||
|
|
||
| public static List<string> GetMonitors() { | ||
| List<string> result = new List<string>(); | ||
| EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, (IntPtr hMonitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr dwData) => { | ||
| result.Add(string.Format("{0}|{1}|{2}|{3}|{4}", hMonitor.ToInt64(), lprcMonitor.left, lprcMonitor.top, lprcMonitor.right - lprcMonitor.left, lprcMonitor.bottom - lprcMonitor.top)); | ||
| return true; | ||
| }, IntPtr.Zero); | ||
| return result; | ||
| } | ||
| } | ||
| "@ | ||
| [MonitorHelper]::GetMonitors() | ||
| `.trim(); | ||
|
|
||
| const result = spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", psScript], { | ||
| encoding: "utf-8", | ||
| timeout: 5000, | ||
| }); | ||
|
|
||
| if (result.error || result.status !== 0) { | ||
| // Silent failure is preferred; the caller will fall back to coordinate-based matching. | ||
| return []; | ||
| } | ||
|
|
||
| return result.stdout | ||
| .split("\n") | ||
| .map((line) => line.trim()) | ||
| .filter((line) => line.length > 0) | ||
| .map((line) => { | ||
| const [handle, x, y, width, height] = line.split("|").map(Number); | ||
| return { handle, x, y, width, height }; | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.