Timeline
- 10:00 (Context) Analyzed
snap_dualrepo; identified PowerShell script execution as the primary latency bottleneck (~1.5s). - 10:15 (Action) Replaced
Process.runbased capture with nativepackage:win32GDI calls. - 10:30 (Action) Refactored
CaptureServiceto offload image processing to background Isolates. - 10:45 (Observation) Capture latency dropped to <50ms; UI freezes eliminated.
ctx:
- 10:00 The initial implementation relied on spawning a PowerShell process to capture the screen. The overhead of spinning up the .NET runtime for every screenshot made “instant” capture impossible.
- 10:05 Identified that image decoding and encoding were occurring on the main UI thread, causing the application to hang visibly during the crop/save phase.
act:
- 10:15 Integrated
package:win32anddart:ffi. ImplementedBitBltinNativeScreenshotServiceto copy screen pixels directly into a DartUint8List, bypassing disk I/O entirely. - 10:25 Modified
CropOverlayto accept in-memory image data (Uint8List) instead of file paths, removing the need for intermediate temporary files. - 10:35 Wrapped the heavy
imagelibrary operations (decode, crop, encode) incompute()functions to move them to a background Isolate.
obs:
- 10:40 Direct GDI capture is orders of magnitude faster than scripting. The “snap” is now effectively instant.
- 10:45 The “UI Janky” feeling during saving is gone. Using Isolates for image processing allows the loading/success animations to play smoothly while the CPU crunches pixels in the background.
open:
- 11:00 The current GDI implementation grabs the Virtual Screen bounds. Need to verify behavior on mixed-DPI multi-monitor setups to ensure coordinate mapping remains accurate.
- 11:00 Consider adding a global low-level keyboard hook (Win32 API) to trigger captures even when the app doesn’t have focus.