superbased 2.0.6 → 3.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -26
- package/README.md +198 -290
- package/bin/superbased.js +7 -0
- package/package.json +42 -140
- package/SUPERBASED_SKILL.md +0 -1660
- package/dist/electron/ai/ai-client.d.ts +0 -45
- package/dist/electron/ai/ai-client.d.ts.map +0 -1
- package/dist/electron/ai/ai-client.js +0 -205
- package/dist/electron/ai/ai-client.js.map +0 -1
- package/dist/electron/ai/context-builder.d.ts +0 -8
- package/dist/electron/ai/context-builder.d.ts.map +0 -1
- package/dist/electron/ai/context-builder.js +0 -28
- package/dist/electron/ai/context-builder.js.map +0 -1
- package/dist/electron/ai/instruction-parser.d.ts +0 -11
- package/dist/electron/ai/instruction-parser.d.ts.map +0 -1
- package/dist/electron/ai/instruction-parser.js +0 -47
- package/dist/electron/ai/instruction-parser.js.map +0 -1
- package/dist/electron/ai/orchestrator.d.ts +0 -17
- package/dist/electron/ai/orchestrator.d.ts.map +0 -1
- package/dist/electron/ai/orchestrator.js +0 -53
- package/dist/electron/ai/orchestrator.js.map +0 -1
- package/dist/electron/ai/providers/anthropic.d.ts +0 -6
- package/dist/electron/ai/providers/anthropic.d.ts.map +0 -1
- package/dist/electron/ai/providers/anthropic.js +0 -67
- package/dist/electron/ai/providers/anthropic.js.map +0 -1
- package/dist/electron/ai/providers/azure-openai.d.ts +0 -12
- package/dist/electron/ai/providers/azure-openai.d.ts.map +0 -1
- package/dist/electron/ai/providers/azure-openai.js +0 -87
- package/dist/electron/ai/providers/azure-openai.js.map +0 -1
- package/dist/electron/ai/providers/gemini.d.ts +0 -6
- package/dist/electron/ai/providers/gemini.d.ts.map +0 -1
- package/dist/electron/ai/providers/gemini.js +0 -49
- package/dist/electron/ai/providers/gemini.js.map +0 -1
- package/dist/electron/ai/providers/openai.d.ts +0 -6
- package/dist/electron/ai/providers/openai.d.ts.map +0 -1
- package/dist/electron/ai/providers/openai.js +0 -68
- package/dist/electron/ai/providers/openai.js.map +0 -1
- package/dist/electron/core/auth-store.d.ts +0 -15
- package/dist/electron/core/auth-store.d.ts.map +0 -1
- package/dist/electron/core/auth-store.js +0 -86
- package/dist/electron/core/auth-store.js.map +0 -1
- package/dist/electron/core/config.d.ts +0 -6
- package/dist/electron/core/config.d.ts.map +0 -1
- package/dist/electron/core/config.js +0 -81
- package/dist/electron/core/config.js.map +0 -1
- package/dist/electron/core/file-logger.d.ts +0 -17
- package/dist/electron/core/file-logger.d.ts.map +0 -1
- package/dist/electron/core/file-logger.js +0 -74
- package/dist/electron/core/file-logger.js.map +0 -1
- package/dist/electron/core/input-injection/index.d.ts +0 -6
- package/dist/electron/core/input-injection/index.d.ts.map +0 -1
- package/dist/electron/core/input-injection/index.js +0 -31
- package/dist/electron/core/input-injection/index.js.map +0 -1
- package/dist/electron/core/input-injection/macos.d.ts +0 -3
- package/dist/electron/core/input-injection/macos.d.ts.map +0 -1
- package/dist/electron/core/input-injection/macos.js +0 -14
- package/dist/electron/core/input-injection/macos.js.map +0 -1
- package/dist/electron/core/input-injection/windows.d.ts +0 -3
- package/dist/electron/core/input-injection/windows.d.ts.map +0 -1
- package/dist/electron/core/input-injection/windows.js +0 -119
- package/dist/electron/core/input-injection/windows.js.map +0 -1
- package/dist/electron/core/json-store.d.ts +0 -26
- package/dist/electron/core/json-store.d.ts.map +0 -1
- package/dist/electron/core/json-store.js +0 -132
- package/dist/electron/core/json-store.js.map +0 -1
- package/dist/electron/core/paths.d.ts +0 -17
- package/dist/electron/core/paths.d.ts.map +0 -1
- package/dist/electron/core/paths.js +0 -117
- package/dist/electron/core/paths.js.map +0 -1
- package/dist/electron/core/platform.d.ts +0 -24
- package/dist/electron/core/platform.d.ts.map +0 -1
- package/dist/electron/core/platform.js +0 -18
- package/dist/electron/core/platform.js.map +0 -1
- package/dist/electron/core/process-coord.d.ts +0 -19
- package/dist/electron/core/process-coord.d.ts.map +0 -1
- package/dist/electron/core/process-coord.js +0 -124
- package/dist/electron/core/process-coord.js.map +0 -1
- package/dist/electron/core/serialize-schema.d.ts +0 -35
- package/dist/electron/core/serialize-schema.d.ts.map +0 -1
- package/dist/electron/core/serialize-schema.js +0 -89
- package/dist/electron/core/serialize-schema.js.map +0 -1
- package/dist/electron/core/settings-schema.d.ts +0 -81
- package/dist/electron/core/settings-schema.d.ts.map +0 -1
- package/dist/electron/core/settings-schema.js +0 -1370
- package/dist/electron/core/settings-schema.js.map +0 -1
- package/dist/electron/db/database.d.ts +0 -154
- package/dist/electron/db/database.d.ts.map +0 -1
- package/dist/electron/db/database.js +0 -637
- package/dist/electron/db/database.js.map +0 -1
- package/dist/electron/db/models.d.ts +0 -26
- package/dist/electron/db/models.d.ts.map +0 -1
- package/dist/electron/db/models.js +0 -4
- package/dist/electron/db/models.js.map +0 -1
- package/dist/electron/logger.d.ts +0 -9
- package/dist/electron/logger.d.ts.map +0 -1
- package/dist/electron/logger.js +0 -32
- package/dist/electron/logger.js.map +0 -1
- package/dist/electron/main.js +0 -3652
- package/dist/electron/modules/accessibility/macos-provider.d.ts +0 -8
- package/dist/electron/modules/accessibility/macos-provider.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/macos-provider.js +0 -94
- package/dist/electron/modules/accessibility/macos-provider.js.map +0 -1
- package/dist/electron/modules/accessibility/provider.d.ts +0 -12
- package/dist/electron/modules/accessibility/provider.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/provider.js +0 -52
- package/dist/electron/modules/accessibility/provider.js.map +0 -1
- package/dist/electron/modules/accessibility/types.d.ts +0 -63
- package/dist/electron/modules/accessibility/types.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/types.js +0 -6
- package/dist/electron/modules/accessibility/types.js.map +0 -1
- package/dist/electron/modules/accessibility/windows-provider.d.ts +0 -8
- package/dist/electron/modules/accessibility/windows-provider.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/windows-provider.js +0 -85
- package/dist/electron/modules/accessibility/windows-provider.js.map +0 -1
- package/dist/electron/modules/active-window.d.ts +0 -6
- package/dist/electron/modules/active-window.d.ts.map +0 -1
- package/dist/electron/modules/active-window.js +0 -76
- package/dist/electron/modules/active-window.js.map +0 -1
- package/dist/electron/modules/api-server.d.ts +0 -11
- package/dist/electron/modules/api-server.d.ts.map +0 -1
- package/dist/electron/modules/api-server.js +0 -2759
- package/dist/electron/modules/api-server.js.map +0 -1
- package/dist/electron/modules/auth.d.ts +0 -42
- package/dist/electron/modules/auth.d.ts.map +0 -1
- package/dist/electron/modules/auth.js +0 -193
- package/dist/electron/modules/auth.js.map +0 -1
- package/dist/electron/modules/azure-speech-realtime.d.ts +0 -48
- package/dist/electron/modules/azure-speech-realtime.d.ts.map +0 -1
- package/dist/electron/modules/azure-speech-realtime.js +0 -543
- package/dist/electron/modules/azure-speech-realtime.js.map +0 -1
- package/dist/electron/modules/capture-modes.d.ts +0 -19
- package/dist/electron/modules/capture-modes.d.ts.map +0 -1
- package/dist/electron/modules/capture-modes.js +0 -100
- package/dist/electron/modules/capture-modes.js.map +0 -1
- package/dist/electron/modules/capture.d.ts +0 -24
- package/dist/electron/modules/capture.d.ts.map +0 -1
- package/dist/electron/modules/capture.js +0 -191
- package/dist/electron/modules/capture.js.map +0 -1
- package/dist/electron/modules/clipboard.d.ts +0 -6
- package/dist/electron/modules/clipboard.d.ts.map +0 -1
- package/dist/electron/modules/clipboard.js +0 -26
- package/dist/electron/modules/clipboard.js.map +0 -1
- package/dist/electron/modules/color-picker.d.ts +0 -4
- package/dist/electron/modules/color-picker.d.ts.map +0 -1
- package/dist/electron/modules/color-picker.js +0 -233
- package/dist/electron/modules/color-picker.js.map +0 -1
- package/dist/electron/modules/compose-screenshots.d.ts +0 -8
- package/dist/electron/modules/compose-screenshots.d.ts.map +0 -1
- package/dist/electron/modules/compose-screenshots.js +0 -86
- package/dist/electron/modules/compose-screenshots.js.map +0 -1
- package/dist/electron/modules/context-menu-detect.d.ts +0 -47
- package/dist/electron/modules/context-menu-detect.d.ts.map +0 -1
- package/dist/electron/modules/context-menu-detect.js +0 -272
- package/dist/electron/modules/context-menu-detect.js.map +0 -1
- package/dist/electron/modules/dictation.d.ts +0 -27
- package/dist/electron/modules/dictation.d.ts.map +0 -1
- package/dist/electron/modules/dictation.js +0 -1231
- package/dist/electron/modules/dictation.js.map +0 -1
- package/dist/electron/modules/error-reporter.d.ts +0 -7
- package/dist/electron/modules/error-reporter.d.ts.map +0 -1
- package/dist/electron/modules/error-reporter.js +0 -65
- package/dist/electron/modules/error-reporter.js.map +0 -1
- package/dist/electron/modules/gif-util.d.ts +0 -9
- package/dist/electron/modules/gif-util.d.ts.map +0 -1
- package/dist/electron/modules/gif-util.js +0 -63
- package/dist/electron/modules/gif-util.js.map +0 -1
- package/dist/electron/modules/gui-automation-errors.d.ts +0 -11
- package/dist/electron/modules/gui-automation-errors.d.ts.map +0 -1
- package/dist/electron/modules/gui-automation-errors.js +0 -79
- package/dist/electron/modules/gui-automation-errors.js.map +0 -1
- package/dist/electron/modules/gui-automation-telemetry.d.ts +0 -38
- package/dist/electron/modules/gui-automation-telemetry.d.ts.map +0 -1
- package/dist/electron/modules/gui-automation-telemetry.js +0 -200
- package/dist/electron/modules/gui-automation-telemetry.js.map +0 -1
- package/dist/electron/modules/gui-automation.d.ts +0 -1143
- package/dist/electron/modules/gui-automation.d.ts.map +0 -1
- package/dist/electron/modules/gui-automation.js +0 -8769
- package/dist/electron/modules/gui-automation.js.map +0 -1
- package/dist/electron/modules/hotkeys.d.ts +0 -5
- package/dist/electron/modules/hotkeys.d.ts.map +0 -1
- package/dist/electron/modules/hotkeys.js +0 -64
- package/dist/electron/modules/hotkeys.js.map +0 -1
- package/dist/electron/modules/human-input/index.d.ts +0 -35
- package/dist/electron/modules/human-input/index.d.ts.map +0 -1
- package/dist/electron/modules/human-input/index.js +0 -163
- package/dist/electron/modules/human-input/index.js.map +0 -1
- package/dist/electron/modules/human-input/keyboard/timing.d.ts +0 -38
- package/dist/electron/modules/human-input/keyboard/timing.d.ts.map +0 -1
- package/dist/electron/modules/human-input/keyboard/timing.js +0 -57
- package/dist/electron/modules/human-input/keyboard/timing.js.map +0 -1
- package/dist/electron/modules/human-input/mouse/path.d.ts +0 -24
- package/dist/electron/modules/human-input/mouse/path.d.ts.map +0 -1
- package/dist/electron/modules/human-input/mouse/path.js +0 -80
- package/dist/electron/modules/human-input/mouse/path.js.map +0 -1
- package/dist/electron/modules/human-input/mouse/velocity.d.ts +0 -48
- package/dist/electron/modules/human-input/mouse/velocity.d.ts.map +0 -1
- package/dist/electron/modules/human-input/mouse/velocity.js +0 -93
- package/dist/electron/modules/human-input/mouse/velocity.js.map +0 -1
- package/dist/electron/modules/human-input/profiles.d.ts +0 -90
- package/dist/electron/modules/human-input/profiles.d.ts.map +0 -1
- package/dist/electron/modules/human-input/profiles.js +0 -124
- package/dist/electron/modules/human-input/profiles.js.map +0 -1
- package/dist/electron/modules/human-input/rng.d.ts +0 -16
- package/dist/electron/modules/human-input/rng.d.ts.map +0 -1
- package/dist/electron/modules/human-input/rng.js +0 -101
- package/dist/electron/modules/human-input/rng.js.map +0 -1
- package/dist/electron/modules/human-input/salt.d.ts +0 -15
- package/dist/electron/modules/human-input/salt.d.ts.map +0 -1
- package/dist/electron/modules/human-input/salt.js +0 -48
- package/dist/electron/modules/human-input/salt.js.map +0 -1
- package/dist/electron/modules/image-utils.d.ts +0 -20
- package/dist/electron/modules/image-utils.d.ts.map +0 -1
- package/dist/electron/modules/image-utils.js +0 -80
- package/dist/electron/modules/image-utils.js.map +0 -1
- package/dist/electron/modules/keystroke.d.ts +0 -7
- package/dist/electron/modules/keystroke.d.ts.map +0 -1
- package/dist/electron/modules/keystroke.js +0 -53
- package/dist/electron/modules/keystroke.js.map +0 -1
- package/dist/electron/modules/license.d.ts +0 -25
- package/dist/electron/modules/license.d.ts.map +0 -1
- package/dist/electron/modules/license.js +0 -175
- package/dist/electron/modules/license.js.map +0 -1
- package/dist/electron/modules/mcp-config.d.ts +0 -16
- package/dist/electron/modules/mcp-config.d.ts.map +0 -1
- package/dist/electron/modules/mcp-config.js +0 -146
- package/dist/electron/modules/mcp-config.js.map +0 -1
- package/dist/electron/modules/ocr.d.ts +0 -3
- package/dist/electron/modules/ocr.d.ts.map +0 -1
- package/dist/electron/modules/ocr.js +0 -188
- package/dist/electron/modules/ocr.js.map +0 -1
- package/dist/electron/modules/ollama/capability.d.ts +0 -32
- package/dist/electron/modules/ollama/capability.d.ts.map +0 -1
- package/dist/electron/modules/ollama/capability.js +0 -117
- package/dist/electron/modules/ollama/capability.js.map +0 -1
- package/dist/electron/modules/ollama/client.d.ts +0 -14
- package/dist/electron/modules/ollama/client.d.ts.map +0 -1
- package/dist/electron/modules/ollama/client.js +0 -134
- package/dist/electron/modules/ollama/client.js.map +0 -1
- package/dist/electron/modules/ollama/detector.d.ts +0 -29
- package/dist/electron/modules/ollama/detector.d.ts.map +0 -1
- package/dist/electron/modules/ollama/detector.js +0 -177
- package/dist/electron/modules/ollama/detector.js.map +0 -1
- package/dist/electron/modules/ollama/dispatcher.d.ts +0 -36
- package/dist/electron/modules/ollama/dispatcher.d.ts.map +0 -1
- package/dist/electron/modules/ollama/dispatcher.js +0 -97
- package/dist/electron/modules/ollama/dispatcher.js.map +0 -1
- package/dist/electron/modules/ollama/router.d.ts +0 -51
- package/dist/electron/modules/ollama/router.d.ts.map +0 -1
- package/dist/electron/modules/ollama/router.js +0 -201
- package/dist/electron/modules/ollama/router.js.map +0 -1
- package/dist/electron/modules/pin-window.d.ts +0 -3
- package/dist/electron/modules/pin-window.d.ts.map +0 -1
- package/dist/electron/modules/pin-window.js +0 -64
- package/dist/electron/modules/pin-window.js.map +0 -1
- package/dist/electron/modules/platform/dpi.d.ts +0 -2
- package/dist/electron/modules/platform/dpi.d.ts.map +0 -1
- package/dist/electron/modules/platform/dpi.js +0 -48
- package/dist/electron/modules/platform/dpi.js.map +0 -1
- package/dist/electron/modules/platform/errors.d.ts +0 -13
- package/dist/electron/modules/platform/errors.d.ts.map +0 -1
- package/dist/electron/modules/platform/errors.js +0 -36
- package/dist/electron/modules/platform/errors.js.map +0 -1
- package/dist/electron/modules/platform/index.d.ts +0 -24
- package/dist/electron/modules/platform/index.d.ts.map +0 -1
- package/dist/electron/modules/platform/index.js +0 -133
- package/dist/electron/modules/platform/index.js.map +0 -1
- package/dist/electron/modules/platform/interfaces.d.ts +0 -140
- package/dist/electron/modules/platform/interfaces.d.ts.map +0 -1
- package/dist/electron/modules/platform/interfaces.js +0 -14
- package/dist/electron/modules/platform/interfaces.js.map +0 -1
- package/dist/electron/modules/platform/macos/ax.d.ts +0 -15
- package/dist/electron/modules/platform/macos/ax.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/ax.js +0 -222
- package/dist/electron/modules/platform/macos/ax.js.map +0 -1
- package/dist/electron/modules/platform/macos/capture.d.ts +0 -14
- package/dist/electron/modules/platform/macos/capture.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/capture.js +0 -106
- package/dist/electron/modules/platform/macos/capture.js.map +0 -1
- package/dist/electron/modules/platform/macos/input.d.ts +0 -16
- package/dist/electron/modules/platform/macos/input.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/input.js +0 -342
- package/dist/electron/modules/platform/macos/input.js.map +0 -1
- package/dist/electron/modules/platform/macos/launch.d.ts +0 -10
- package/dist/electron/modules/platform/macos/launch.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/launch.js +0 -114
- package/dist/electron/modules/platform/macos/launch.js.map +0 -1
- package/dist/electron/modules/platform/macos/session.d.ts +0 -8
- package/dist/electron/modules/platform/macos/session.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/session.js +0 -17
- package/dist/electron/modules/platform/macos/session.js.map +0 -1
- package/dist/electron/modules/platform/macos/window.d.ts +0 -31
- package/dist/electron/modules/platform/macos/window.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/window.js +0 -271
- package/dist/electron/modules/platform/macos/window.js.map +0 -1
- package/dist/electron/modules/platform/shared.d.ts +0 -10
- package/dist/electron/modules/platform/shared.d.ts.map +0 -1
- package/dist/electron/modules/platform/shared.js +0 -201
- package/dist/electron/modules/platform/shared.js.map +0 -1
- package/dist/electron/modules/platform/types.d.ts +0 -182
- package/dist/electron/modules/platform/types.d.ts.map +0 -1
- package/dist/electron/modules/platform/types.js +0 -24
- package/dist/electron/modules/platform/types.js.map +0 -1
- package/dist/electron/modules/platform/windows/ax.d.ts +0 -15
- package/dist/electron/modules/platform/windows/ax.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/ax.js +0 -277
- package/dist/electron/modules/platform/windows/ax.js.map +0 -1
- package/dist/electron/modules/platform/windows/capture.d.ts +0 -14
- package/dist/electron/modules/platform/windows/capture.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/capture.js +0 -115
- package/dist/electron/modules/platform/windows/capture.js.map +0 -1
- package/dist/electron/modules/platform/windows/input.d.ts +0 -17
- package/dist/electron/modules/platform/windows/input.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/input.js +0 -422
- package/dist/electron/modules/platform/windows/input.js.map +0 -1
- package/dist/electron/modules/platform/windows/launch.d.ts +0 -10
- package/dist/electron/modules/platform/windows/launch.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/launch.js +0 -185
- package/dist/electron/modules/platform/windows/launch.js.map +0 -1
- package/dist/electron/modules/platform/windows/session.d.ts +0 -8
- package/dist/electron/modules/platform/windows/session.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/session.js +0 -87
- package/dist/electron/modules/platform/windows/session.js.map +0 -1
- package/dist/electron/modules/platform/windows/tray.d.ts +0 -13
- package/dist/electron/modules/platform/windows/tray.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/tray.js +0 -390
- package/dist/electron/modules/platform/windows/tray.js.map +0 -1
- package/dist/electron/modules/platform/windows/window.d.ts +0 -30
- package/dist/electron/modules/platform/windows/window.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/window.js +0 -444
- package/dist/electron/modules/platform/windows/window.js.map +0 -1
- package/dist/electron/modules/recording/ai-analysis.d.ts +0 -8
- package/dist/electron/modules/recording/ai-analysis.d.ts.map +0 -1
- package/dist/electron/modules/recording/ai-analysis.js +0 -88
- package/dist/electron/modules/recording/ai-analysis.js.map +0 -1
- package/dist/electron/modules/recording/capture-queue.d.ts +0 -48
- package/dist/electron/modules/recording/capture-queue.d.ts.map +0 -1
- package/dist/electron/modules/recording/capture-queue.js +0 -409
- package/dist/electron/modules/recording/capture-queue.js.map +0 -1
- package/dist/electron/modules/recording/cli.d.ts +0 -13
- package/dist/electron/modules/recording/cli.d.ts.map +0 -1
- package/dist/electron/modules/recording/cli.js +0 -135
- package/dist/electron/modules/recording/cli.js.map +0 -1
- package/dist/electron/modules/recording/http-api.d.ts +0 -3
- package/dist/electron/modules/recording/http-api.d.ts.map +0 -1
- package/dist/electron/modules/recording/http-api.js +0 -236
- package/dist/electron/modules/recording/http-api.js.map +0 -1
- package/dist/electron/modules/recording/index.d.ts +0 -15
- package/dist/electron/modules/recording/index.d.ts.map +0 -1
- package/dist/electron/modules/recording/index.js +0 -154
- package/dist/electron/modules/recording/index.js.map +0 -1
- package/dist/electron/modules/recording/input-hook-provider.d.ts +0 -15
- package/dist/electron/modules/recording/input-hook-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/input-hook-provider.js +0 -5
- package/dist/electron/modules/recording/input-hook-provider.js.map +0 -1
- package/dist/electron/modules/recording/mcp-tool.d.ts +0 -13
- package/dist/electron/modules/recording/mcp-tool.d.ts.map +0 -1
- package/dist/electron/modules/recording/mcp-tool.js +0 -81
- package/dist/electron/modules/recording/mcp-tool.js.map +0 -1
- package/dist/electron/modules/recording/monitor-analyzer.d.ts +0 -40
- package/dist/electron/modules/recording/monitor-analyzer.d.ts.map +0 -1
- package/dist/electron/modules/recording/monitor-analyzer.js +0 -220
- package/dist/electron/modules/recording/monitor-analyzer.js.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-provider.d.ts +0 -28
- package/dist/electron/modules/recording/providers/change-detect-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-provider.js +0 -181
- package/dist/electron/modules/recording/providers/change-detect-provider.js.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.d.ts +0 -15
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.js +0 -62
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.js.map +0 -1
- package/dist/electron/modules/recording/providers/periodic-provider.d.ts +0 -15
- package/dist/electron/modules/recording/providers/periodic-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/periodic-provider.js +0 -55
- package/dist/electron/modules/recording/providers/periodic-provider.js.map +0 -1
- package/dist/electron/modules/recording/providers/provider-factory.d.ts +0 -15
- package/dist/electron/modules/recording/providers/provider-factory.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/provider-factory.js +0 -97
- package/dist/electron/modules/recording/providers/provider-factory.js.map +0 -1
- package/dist/electron/modules/recording/providers/uiohook-provider.d.ts +0 -19
- package/dist/electron/modules/recording/providers/uiohook-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/uiohook-provider.js +0 -267
- package/dist/electron/modules/recording/providers/uiohook-provider.js.map +0 -1
- package/dist/electron/modules/recording/recording-session.d.ts +0 -29
- package/dist/electron/modules/recording/recording-session.d.ts.map +0 -1
- package/dist/electron/modules/recording/recording-session.js +0 -389
- package/dist/electron/modules/recording/recording-session.js.map +0 -1
- package/dist/electron/modules/recording/session-alignment.d.ts +0 -32
- package/dist/electron/modules/recording/session-alignment.d.ts.map +0 -1
- package/dist/electron/modules/recording/session-alignment.js +0 -103
- package/dist/electron/modules/recording/session-alignment.js.map +0 -1
- package/dist/electron/modules/recording/session-export.d.ts +0 -2
- package/dist/electron/modules/recording/session-export.d.ts.map +0 -1
- package/dist/electron/modules/recording/session-export.js +0 -287
- package/dist/electron/modules/recording/session-export.js.map +0 -1
- package/dist/electron/modules/recording/trigger-engine.d.ts +0 -62
- package/dist/electron/modules/recording/trigger-engine.d.ts.map +0 -1
- package/dist/electron/modules/recording/trigger-engine.js +0 -553
- package/dist/electron/modules/recording/trigger-engine.js.map +0 -1
- package/dist/electron/modules/recording/visual-diff.d.ts +0 -17
- package/dist/electron/modules/recording/visual-diff.d.ts.map +0 -1
- package/dist/electron/modules/recording/visual-diff.js +0 -109
- package/dist/electron/modules/recording/visual-diff.js.map +0 -1
- package/dist/electron/modules/redact.d.ts +0 -34
- package/dist/electron/modules/redact.d.ts.map +0 -1
- package/dist/electron/modules/redact.js +0 -583
- package/dist/electron/modules/redact.js.map +0 -1
- package/dist/electron/modules/scroll-calibration.d.ts +0 -152
- package/dist/electron/modules/scroll-calibration.d.ts.map +0 -1
- package/dist/electron/modules/scroll-calibration.js +0 -271
- package/dist/electron/modules/scroll-calibration.js.map +0 -1
- package/dist/electron/modules/scroll-capture.d.ts +0 -21
- package/dist/electron/modules/scroll-capture.d.ts.map +0 -1
- package/dist/electron/modules/scroll-capture.js +0 -134
- package/dist/electron/modules/scroll-capture.js.map +0 -1
- package/dist/electron/modules/sequence-locate.d.ts +0 -126
- package/dist/electron/modules/sequence-locate.d.ts.map +0 -1
- package/dist/electron/modules/sequence-locate.js +0 -356
- package/dist/electron/modules/sequence-locate.js.map +0 -1
- package/dist/electron/modules/store.d.ts +0 -18
- package/dist/electron/modules/store.d.ts.map +0 -1
- package/dist/electron/modules/store.js +0 -126
- package/dist/electron/modules/store.js.map +0 -1
- package/dist/electron/modules/stt/capability-probe.d.ts +0 -67
- package/dist/electron/modules/stt/capability-probe.d.ts.map +0 -1
- package/dist/electron/modules/stt/capability-probe.js +0 -331
- package/dist/electron/modules/stt/capability-probe.js.map +0 -1
- package/dist/electron/modules/stt/macos-engine.d.ts +0 -20
- package/dist/electron/modules/stt/macos-engine.d.ts.map +0 -1
- package/dist/electron/modules/stt/macos-engine.js +0 -231
- package/dist/electron/modules/stt/macos-engine.js.map +0 -1
- package/dist/electron/modules/stt/model-manager.d.ts +0 -87
- package/dist/electron/modules/stt/model-manager.d.ts.map +0 -1
- package/dist/electron/modules/stt/model-manager.js +0 -321
- package/dist/electron/modules/stt/model-manager.js.map +0 -1
- package/dist/electron/modules/stt/router.d.ts +0 -35
- package/dist/electron/modules/stt/router.d.ts.map +0 -1
- package/dist/electron/modules/stt/router.js +0 -263
- package/dist/electron/modules/stt/router.js.map +0 -1
- package/dist/electron/modules/stt/sherpa-engine.d.ts +0 -43
- package/dist/electron/modules/stt/sherpa-engine.d.ts.map +0 -1
- package/dist/electron/modules/stt/sherpa-engine.js +0 -521
- package/dist/electron/modules/stt/sherpa-engine.js.map +0 -1
- package/dist/electron/modules/stt/types.d.ts +0 -72
- package/dist/electron/modules/stt/types.d.ts.map +0 -1
- package/dist/electron/modules/stt/types.js +0 -16
- package/dist/electron/modules/stt/types.js.map +0 -1
- package/dist/electron/modules/stt/winrt-engine.d.ts +0 -20
- package/dist/electron/modules/stt/winrt-engine.d.ts.map +0 -1
- package/dist/electron/modules/stt/winrt-engine.js +0 -238
- package/dist/electron/modules/stt/winrt-engine.js.map +0 -1
- package/dist/electron/modules/tce/content-analyzer.d.ts +0 -20
- package/dist/electron/modules/tce/content-analyzer.d.ts.map +0 -1
- package/dist/electron/modules/tce/content-analyzer.js +0 -123
- package/dist/electron/modules/tce/content-analyzer.js.map +0 -1
- package/dist/electron/modules/tce/index.d.ts +0 -54
- package/dist/electron/modules/tce/index.d.ts.map +0 -1
- package/dist/electron/modules/tce/index.js +0 -174
- package/dist/electron/modules/tce/index.js.map +0 -1
- package/dist/electron/modules/tce/layout-engine.d.ts +0 -68
- package/dist/electron/modules/tce/layout-engine.d.ts.map +0 -1
- package/dist/electron/modules/tce/layout-engine.js +0 -313
- package/dist/electron/modules/tce/layout-engine.js.map +0 -1
- package/dist/electron/modules/tce/renderer.d.ts +0 -16
- package/dist/electron/modules/tce/renderer.d.ts.map +0 -1
- package/dist/electron/modules/tce/renderer.js +0 -196
- package/dist/electron/modules/tce/renderer.js.map +0 -1
- package/dist/electron/modules/tce/themes.d.ts +0 -14
- package/dist/electron/modules/tce/themes.d.ts.map +0 -1
- package/dist/electron/modules/tce/themes.js +0 -68
- package/dist/electron/modules/tce/themes.js.map +0 -1
- package/dist/electron/modules/tce/token-estimator.d.ts +0 -30
- package/dist/electron/modules/tce/token-estimator.d.ts.map +0 -1
- package/dist/electron/modules/tce/token-estimator.js +0 -59
- package/dist/electron/modules/tce/token-estimator.js.map +0 -1
- package/dist/electron/modules/telemetry.d.ts +0 -44
- package/dist/electron/modules/telemetry.d.ts.map +0 -1
- package/dist/electron/modules/telemetry.js +0 -316
- package/dist/electron/modules/telemetry.js.map +0 -1
- package/dist/electron/modules/template-match.d.ts +0 -62
- package/dist/electron/modules/template-match.d.ts.map +0 -1
- package/dist/electron/modules/template-match.js +0 -205
- package/dist/electron/modules/template-match.js.map +0 -1
- package/dist/electron/modules/tray.d.ts +0 -24
- package/dist/electron/modules/tray.d.ts.map +0 -1
- package/dist/electron/modules/tray.js +0 -349
- package/dist/electron/modules/tray.js.map +0 -1
- package/dist/electron/modules/uiohook-manager.d.ts +0 -19
- package/dist/electron/modules/uiohook-manager.d.ts.map +0 -1
- package/dist/electron/modules/uiohook-manager.js +0 -101
- package/dist/electron/modules/uiohook-manager.js.map +0 -1
- package/dist/electron/modules/undo-stack.d.ts +0 -22
- package/dist/electron/modules/undo-stack.d.ts.map +0 -1
- package/dist/electron/modules/undo-stack.js +0 -41
- package/dist/electron/modules/undo-stack.js.map +0 -1
- package/dist/electron/modules/updater.d.ts +0 -14
- package/dist/electron/modules/updater.d.ts.map +0 -1
- package/dist/electron/modules/updater.js +0 -102
- package/dist/electron/modules/updater.js.map +0 -1
- package/dist/electron/modules/usage-link.d.ts +0 -7
- package/dist/electron/modules/usage-link.d.ts.map +0 -1
- package/dist/electron/modules/usage-link.js +0 -63
- package/dist/electron/modules/usage-link.js.map +0 -1
- package/dist/electron/modules/version-check.d.ts +0 -3
- package/dist/electron/modules/version-check.d.ts.map +0 -1
- package/dist/electron/modules/version-check.js +0 -76
- package/dist/electron/modules/version-check.js.map +0 -1
- package/dist/electron/modules/watchers/active-window-watcher.d.ts +0 -5
- package/dist/electron/modules/watchers/active-window-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/active-window-watcher.js +0 -152
- package/dist/electron/modules/watchers/active-window-watcher.js.map +0 -1
- package/dist/electron/modules/watchers/clipboard-watcher.d.ts +0 -5
- package/dist/electron/modules/watchers/clipboard-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/clipboard-watcher.js +0 -90
- package/dist/electron/modules/watchers/clipboard-watcher.js.map +0 -1
- package/dist/electron/modules/watchers/file-watcher.d.ts +0 -5
- package/dist/electron/modules/watchers/file-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/file-watcher.js +0 -91
- package/dist/electron/modules/watchers/file-watcher.js.map +0 -1
- package/dist/electron/modules/watchers/registry.d.ts +0 -34
- package/dist/electron/modules/watchers/registry.d.ts.map +0 -1
- package/dist/electron/modules/watchers/registry.js +0 -108
- package/dist/electron/modules/watchers/registry.js.map +0 -1
- package/dist/electron/modules/watchers/screen-region-service.d.ts +0 -18
- package/dist/electron/modules/watchers/screen-region-service.d.ts.map +0 -1
- package/dist/electron/modules/watchers/screen-region-service.js +0 -126
- package/dist/electron/modules/watchers/screen-region-service.js.map +0 -1
- package/dist/electron/modules/watchers/screen-region-watcher.d.ts +0 -6
- package/dist/electron/modules/watchers/screen-region-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/screen-region-watcher.js +0 -70
- package/dist/electron/modules/watchers/screen-region-watcher.js.map +0 -1
- package/dist/electron/modules/window-activate.d.ts +0 -103
- package/dist/electron/modules/window-activate.d.ts.map +0 -1
- package/dist/electron/modules/window-activate.js +0 -630
- package/dist/electron/modules/window-activate.js.map +0 -1
- package/dist/electron/modules/window-input.d.ts +0 -43
- package/dist/electron/modules/window-input.d.ts.map +0 -1
- package/dist/electron/modules/window-input.js +0 -623
- package/dist/electron/modules/window-input.js.map +0 -1
- package/dist/electron/modules/window-picker.d.ts +0 -6
- package/dist/electron/modules/window-picker.d.ts.map +0 -1
- package/dist/electron/modules/window-picker.js +0 -192
- package/dist/electron/modules/window-picker.js.map +0 -1
- package/dist/electron/modules/window-resolver.d.ts +0 -35
- package/dist/electron/modules/window-resolver.d.ts.map +0 -1
- package/dist/electron/modules/window-resolver.js +0 -210
- package/dist/electron/modules/window-resolver.js.map +0 -1
- package/dist/headless/electron/ai/ai-client.js +0 -204
- package/dist/headless/electron/ai/context-builder.js +0 -27
- package/dist/headless/electron/ai/instruction-parser.js +0 -46
- package/dist/headless/electron/core/auth-store.js +0 -85
- package/dist/headless/electron/core/config.js +0 -80
- package/dist/headless/electron/core/file-logger.js +0 -73
- package/dist/headless/electron/core/input-injection/index.js +0 -30
- package/dist/headless/electron/core/input-injection/macos.js +0 -13
- package/dist/headless/electron/core/input-injection/windows.js +0 -118
- package/dist/headless/electron/core/json-store.js +0 -131
- package/dist/headless/electron/core/paths.js +0 -116
- package/dist/headless/electron/core/platform.js +0 -17
- package/dist/headless/electron/core/process-coord.js +0 -123
- package/dist/headless/electron/core/serialize-schema.js +0 -88
- package/dist/headless/electron/core/settings-schema.js +0 -1369
- package/dist/headless/electron/db/database.js +0 -636
- package/dist/headless/electron/db/models.js +0 -3
- package/dist/headless/electron/logger.js +0 -31
- package/dist/headless/electron/modules/accessibility/macos-provider.js +0 -93
- package/dist/headless/electron/modules/accessibility/provider.js +0 -51
- package/dist/headless/electron/modules/accessibility/types.js +0 -5
- package/dist/headless/electron/modules/accessibility/windows-provider.js +0 -84
- package/dist/headless/electron/modules/active-window.js +0 -75
- package/dist/headless/electron/modules/api-server.js +0 -2758
- package/dist/headless/electron/modules/auth.js +0 -192
- package/dist/headless/electron/modules/azure-speech-realtime.js +0 -542
- package/dist/headless/electron/modules/capture.js +0 -190
- package/dist/headless/electron/modules/clipboard.js +0 -25
- package/dist/headless/electron/modules/context-menu-detect.js +0 -271
- package/dist/headless/electron/modules/dictation.js +0 -1230
- package/dist/headless/electron/modules/gui-automation-errors.js +0 -78
- package/dist/headless/electron/modules/gui-automation-telemetry.js +0 -199
- package/dist/headless/electron/modules/gui-automation.js +0 -8768
- package/dist/headless/electron/modules/human-input/keyboard/timing.js +0 -56
- package/dist/headless/electron/modules/human-input/mouse/path.js +0 -79
- package/dist/headless/electron/modules/human-input/mouse/velocity.js +0 -92
- package/dist/headless/electron/modules/human-input/profiles.js +0 -123
- package/dist/headless/electron/modules/human-input/rng.js +0 -100
- package/dist/headless/electron/modules/human-input/salt.js +0 -47
- package/dist/headless/electron/modules/image-utils.js +0 -79
- package/dist/headless/electron/modules/keystroke.js +0 -52
- package/dist/headless/electron/modules/license.js +0 -174
- package/dist/headless/electron/modules/mcp-config.js +0 -145
- package/dist/headless/electron/modules/ocr.js +0 -187
- package/dist/headless/electron/modules/ollama/capability.js +0 -116
- package/dist/headless/electron/modules/ollama/client.js +0 -133
- package/dist/headless/electron/modules/ollama/detector.js +0 -176
- package/dist/headless/electron/modules/ollama/dispatcher.js +0 -96
- package/dist/headless/electron/modules/ollama/router.js +0 -200
- package/dist/headless/electron/modules/platform/dpi.js +0 -47
- package/dist/headless/electron/modules/platform/errors.js +0 -35
- package/dist/headless/electron/modules/platform/index.js +0 -132
- package/dist/headless/electron/modules/platform/interfaces.js +0 -13
- package/dist/headless/electron/modules/platform/macos/ax.js +0 -221
- package/dist/headless/electron/modules/platform/macos/capture.js +0 -105
- package/dist/headless/electron/modules/platform/macos/input.js +0 -341
- package/dist/headless/electron/modules/platform/macos/launch.js +0 -113
- package/dist/headless/electron/modules/platform/macos/session.js +0 -16
- package/dist/headless/electron/modules/platform/macos/window.js +0 -270
- package/dist/headless/electron/modules/platform/shared.js +0 -200
- package/dist/headless/electron/modules/platform/types.js +0 -23
- package/dist/headless/electron/modules/platform/windows/ax.js +0 -276
- package/dist/headless/electron/modules/platform/windows/capture.js +0 -114
- package/dist/headless/electron/modules/platform/windows/input.js +0 -421
- package/dist/headless/electron/modules/platform/windows/launch.js +0 -184
- package/dist/headless/electron/modules/platform/windows/session.js +0 -86
- package/dist/headless/electron/modules/platform/windows/tray.js +0 -389
- package/dist/headless/electron/modules/platform/windows/window.js +0 -443
- package/dist/headless/electron/modules/recording/ai-analysis.js +0 -87
- package/dist/headless/electron/modules/recording/capture-queue.js +0 -408
- package/dist/headless/electron/modules/recording/cli.js +0 -134
- package/dist/headless/electron/modules/recording/http-api.js +0 -235
- package/dist/headless/electron/modules/recording/index.js +0 -153
- package/dist/headless/electron/modules/recording/input-hook-provider.js +0 -4
- package/dist/headless/electron/modules/recording/mcp-tool.js +0 -80
- package/dist/headless/electron/modules/recording/monitor-analyzer.js +0 -219
- package/dist/headless/electron/modules/recording/providers/change-detect-provider.js +0 -180
- package/dist/headless/electron/modules/recording/providers/change-detect-shared-wrapper.js +0 -61
- package/dist/headless/electron/modules/recording/providers/periodic-provider.js +0 -54
- package/dist/headless/electron/modules/recording/providers/provider-factory.js +0 -96
- package/dist/headless/electron/modules/recording/providers/uiohook-provider.js +0 -266
- package/dist/headless/electron/modules/recording/recording-session.js +0 -388
- package/dist/headless/electron/modules/recording/session-alignment.js +0 -102
- package/dist/headless/electron/modules/recording/session-export.js +0 -286
- package/dist/headless/electron/modules/recording/trigger-engine.js +0 -552
- package/dist/headless/electron/modules/recording/visual-diff.js +0 -108
- package/dist/headless/electron/modules/redact.js +0 -582
- package/dist/headless/electron/modules/scroll-calibration.js +0 -270
- package/dist/headless/electron/modules/sequence-locate.js +0 -355
- package/dist/headless/electron/modules/store.js +0 -125
- package/dist/headless/electron/modules/stt/capability-probe.js +0 -330
- package/dist/headless/electron/modules/stt/macos-engine.js +0 -230
- package/dist/headless/electron/modules/stt/model-manager.js +0 -320
- package/dist/headless/electron/modules/stt/router.js +0 -262
- package/dist/headless/electron/modules/stt/sherpa-engine.js +0 -520
- package/dist/headless/electron/modules/stt/types.js +0 -15
- package/dist/headless/electron/modules/stt/winrt-engine.js +0 -237
- package/dist/headless/electron/modules/tce/content-analyzer.js +0 -122
- package/dist/headless/electron/modules/tce/index.js +0 -173
- package/dist/headless/electron/modules/tce/layout-engine.js +0 -312
- package/dist/headless/electron/modules/tce/renderer.js +0 -195
- package/dist/headless/electron/modules/tce/themes.js +0 -67
- package/dist/headless/electron/modules/tce/token-estimator.js +0 -58
- package/dist/headless/electron/modules/telemetry.js +0 -315
- package/dist/headless/electron/modules/template-match.js +0 -204
- package/dist/headless/electron/modules/uiohook-manager.js +0 -100
- package/dist/headless/electron/modules/undo-stack.js +0 -40
- package/dist/headless/electron/modules/watchers/active-window-watcher.js +0 -151
- package/dist/headless/electron/modules/watchers/clipboard-watcher.js +0 -89
- package/dist/headless/electron/modules/watchers/file-watcher.js +0 -90
- package/dist/headless/electron/modules/watchers/registry.js +0 -107
- package/dist/headless/electron/modules/watchers/screen-region-service.js +0 -125
- package/dist/headless/electron/modules/watchers/screen-region-watcher.js +0 -69
- package/dist/headless/electron/modules/window-activate.js +0 -629
- package/dist/headless/electron/modules/window-input.js +0 -622
- package/dist/headless/electron/modules/window-resolver.js +0 -209
- package/dist/headless/headless/capture-hotkey.js +0 -155
- package/dist/headless/headless/cli-auth.js +0 -158
- package/dist/headless/headless/cli.js +0 -278
- package/dist/headless/headless/config-cmd.js +0 -306
- package/dist/headless/headless/dictation-hotkey.js +0 -525
- package/dist/headless/headless/dictation-overlay.js +0 -218
- package/dist/headless/headless/doctor.js +0 -599
- package/dist/headless/headless/mic-capture.js +0 -406
- package/dist/headless/headless/ollama-cmd.js +0 -211
- package/dist/headless/headless/platform-headless.js +0 -233
- package/dist/headless/headless/server.js +0 -195
- package/dist/headless/headless/stt-cmd.js +0 -213
- package/dist/headless/headless/tui/index.mjs +0 -7
- package/dist/headless/headless/tui/plain-dump.js +0 -41
- package/dist/headless/headless/tui/settings-app.mjs +0 -744
- package/dist/headless/headless/tui/setup-wizard.mjs +0 -257
- package/dist/headless/headless/tui-bridge.js +0 -80
- package/dist/headless/headless/win32-text-injector.js +0 -359
- package/dist/headless/mic-capture.d.ts +0 -49
- package/dist/headless/mic-capture.d.ts.map +0 -1
- package/dist/headless/mic-capture.js +0 -407
- package/dist/headless/mic-capture.js.map +0 -1
- package/dist/headless/shared/constants.js +0 -65
- package/dist/headless/shared/design-tokens.js +0 -189
- package/dist/headless/shared/recording-types.js +0 -93
- package/dist/headless/shared/types.js +0 -3
- package/dist/shared/constants.d.ts +0 -100
- package/dist/shared/constants.d.ts.map +0 -1
- package/dist/shared/constants.js +0 -66
- package/dist/shared/constants.js.map +0 -1
- package/dist/shared/design-tokens.d.ts +0 -112
- package/dist/shared/design-tokens.d.ts.map +0 -1
- package/dist/shared/design-tokens.js +0 -190
- package/dist/shared/design-tokens.js.map +0 -1
- package/dist/shared/recording-types.d.ts +0 -186
- package/dist/shared/recording-types.d.ts.map +0 -1
- package/dist/shared/recording-types.js +0 -94
- package/dist/shared/recording-types.js.map +0 -1
- package/dist/shared/types.d.ts +0 -143
- package/dist/shared/types.d.ts.map +0 -1
- package/dist/shared/types.js +0 -4
- package/dist/shared/types.js.map +0 -1
- package/mcp-server/dist/api-client.js +0 -521
- package/mcp-server/dist/index.js +0 -2550
- package/mcp-server/dist/project-sense.js +0 -161
- package/mcp-server/dist/tool-categories.js +0 -161
- package/mcp-server/package.json +0 -22
package/dist/electron/main.js
DELETED
|
@@ -1,3652 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Main Electron process: app entry, window management, tray, IPC handlers
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
const electron_1 = require("electron");
|
|
41
|
-
const platform_1 = require("./core/platform");
|
|
42
|
-
const platform_electron_1 = require("./platform-electron");
|
|
43
|
-
const config_1 = require("./core/config");
|
|
44
|
-
const paths_1 = require("./core/paths");
|
|
45
|
-
// Initialize platform adapter BEFORE any module that uses getPlatform()
|
|
46
|
-
(0, platform_1.setPlatform)(platform_electron_1.electronPlatform);
|
|
47
|
-
(0, config_1.setClientType)('desktop');
|
|
48
|
-
(0, paths_1.overrideDataDir)(electron_1.app.getPath('userData'));
|
|
49
|
-
const path = __importStar(require("path"));
|
|
50
|
-
const fs = __importStar(require("fs"));
|
|
51
|
-
const tray_1 = require("./modules/tray");
|
|
52
|
-
const hotkeys_1 = require("./modules/hotkeys");
|
|
53
|
-
const auth_1 = require("./modules/auth");
|
|
54
|
-
const capture_1 = require("./modules/capture");
|
|
55
|
-
const database_1 = require("./db/database");
|
|
56
|
-
const ai_client_1 = require("./ai/ai-client");
|
|
57
|
-
const instruction_parser_1 = require("./ai/instruction-parser");
|
|
58
|
-
const context_builder_1 = require("./ai/context-builder");
|
|
59
|
-
const store_1 = require("./modules/store");
|
|
60
|
-
const active_window_1 = require("./modules/active-window");
|
|
61
|
-
const keystroke_1 = require("./modules/keystroke");
|
|
62
|
-
const nut_js_1 = require("@nut-tree-fork/nut-js");
|
|
63
|
-
const clipboard_1 = require("./modules/clipboard");
|
|
64
|
-
const constants_1 = require("../shared/constants");
|
|
65
|
-
const capture_modes_1 = require("./modules/capture-modes");
|
|
66
|
-
const pin_window_1 = require("./modules/pin-window");
|
|
67
|
-
const color_picker_1 = require("./modules/color-picker");
|
|
68
|
-
const window_picker_1 = require("./modules/window-picker");
|
|
69
|
-
const updater_1 = require("./modules/updater");
|
|
70
|
-
const tray_2 = require("./modules/tray");
|
|
71
|
-
const version_check_1 = require("./modules/version-check");
|
|
72
|
-
const ocr_1 = require("./modules/ocr");
|
|
73
|
-
const redact_1 = require("./modules/redact");
|
|
74
|
-
const logger_1 = __importDefault(require("./logger"));
|
|
75
|
-
// --- Custom protocol: serves local files without holding Windows file locks ---
|
|
76
|
-
// Must be registered BEFORE app.whenReady() per Electron docs.
|
|
77
|
-
electron_1.protocol.registerSchemesAsPrivileged([
|
|
78
|
-
{ scheme: 'sbfile', privileges: { standard: false, secure: true, supportFetchAPI: true, stream: true } },
|
|
79
|
-
]);
|
|
80
|
-
// --- Crash reporting: log uncaught errors to disk ---
|
|
81
|
-
const crashLogDir = path.join(electron_1.app.getPath('userData'), 'crash-logs');
|
|
82
|
-
function ensureCrashLogDir() {
|
|
83
|
-
if (!fs.existsSync(crashLogDir)) {
|
|
84
|
-
fs.mkdirSync(crashLogDir, { recursive: true });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function writeCrashLog(type, error) {
|
|
88
|
-
try {
|
|
89
|
-
ensureCrashLogDir();
|
|
90
|
-
const timestamp = new Date().toISOString();
|
|
91
|
-
const filename = `crash-${timestamp.replace(/[:.]/g, '-')}.log`;
|
|
92
|
-
const message = error instanceof Error ? `${error.message}\n${error.stack || ''}` : String(error);
|
|
93
|
-
const content = `[${timestamp}] ${type}\n${message}\n`;
|
|
94
|
-
fs.writeFileSync(path.join(crashLogDir, filename), content);
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
// Avoid recursive failures in the crash handler
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
process.on('uncaughtException', (error) => {
|
|
101
|
-
logger_1.default.error('Uncaught exception:', error);
|
|
102
|
-
writeCrashLog('uncaughtException', error);
|
|
103
|
-
});
|
|
104
|
-
process.on('unhandledRejection', (reason) => {
|
|
105
|
-
logger_1.default.error('Unhandled rejection:', reason);
|
|
106
|
-
writeCrashLog('unhandledRejection', reason);
|
|
107
|
-
});
|
|
108
|
-
let selectionWindow = null;
|
|
109
|
-
let overlayWindow = null;
|
|
110
|
-
let galleryWindow = null;
|
|
111
|
-
let onboardingWindow = null;
|
|
112
|
-
let recordingBarWindow = null;
|
|
113
|
-
let timelineWindow = null;
|
|
114
|
-
let startRecordingWindow = null;
|
|
115
|
-
let mainPanelWindow = null;
|
|
116
|
-
let dictationIndicatorWindow = null;
|
|
117
|
-
// Track the last active window before we take over focus
|
|
118
|
-
let lastActiveWindow = { appName: null, windowTitle: null };
|
|
119
|
-
// Pending notes for the global "paste notes" shortcut
|
|
120
|
-
let pendingNotesText = null;
|
|
121
|
-
let notesPasteShortcutRegistered = false;
|
|
122
|
-
// Overlay pin & PIP state
|
|
123
|
-
let overlayPinned = false;
|
|
124
|
-
let overlayOriginalBounds = null;
|
|
125
|
-
// Flag: if true, next selection adds to existing overlay instead of creating new one
|
|
126
|
-
let addingToExistingOverlay = false;
|
|
127
|
-
// Flag: if true, next selection triggers scroll-capture mode
|
|
128
|
-
let scrollCaptureMode = false;
|
|
129
|
-
// Guard against capture-hotkey re-entry. When the selection window is open,
|
|
130
|
-
// pressing any selection-opening hotkey (S/D/A) again is ambiguous — the old
|
|
131
|
-
// code reopened the window with mixed state (scrollCaptureMode leaking,
|
|
132
|
-
// addingToExistingOverlay stuck, simpleFullscreen teardown racing). We now
|
|
133
|
-
// claim 'selection' when opening and reset in the closed handler. Re-press
|
|
134
|
-
// while busy is treated as "cancel the current selection" — a predictable
|
|
135
|
-
// double-tap-to-dismiss gesture.
|
|
136
|
-
let selectionUIActive = false;
|
|
137
|
-
/** Returns true if the caller may open the selection window now. */
|
|
138
|
-
function tryClaimSelectionUI() {
|
|
139
|
-
if (!selectionUIActive) {
|
|
140
|
-
selectionUIActive = true;
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
// Already open — treat re-press as cancel. The closed handler resets flags.
|
|
144
|
-
logger_1.default.info('[Capture] Selection hotkey re-pressed while active — cancelling');
|
|
145
|
-
closeSelectionWindow();
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
// Thumbnail cache — invalidated when screenshots are edited
|
|
149
|
-
const thumbnailCache = new Map();
|
|
150
|
-
const isMac = process.platform === 'darwin';
|
|
151
|
-
/** Load the app icon for use in BrowserWindow constructors (Windows taskbar) */
|
|
152
|
-
let _appIcon;
|
|
153
|
-
function getAppIcon() {
|
|
154
|
-
if (isMac)
|
|
155
|
-
return undefined; // macOS uses the app bundle icon automatically
|
|
156
|
-
if (_appIcon)
|
|
157
|
-
return _appIcon;
|
|
158
|
-
const assetsDir = electron_1.app.isPackaged
|
|
159
|
-
? path.join(process.resourcesPath, 'assets')
|
|
160
|
-
: path.join(__dirname, '../../assets');
|
|
161
|
-
for (const name of ['icon.ico', 'icon-256.png', 'icon.png']) {
|
|
162
|
-
try {
|
|
163
|
-
const img = electron_1.nativeImage.createFromPath(path.join(assetsDir, name));
|
|
164
|
-
if (!img.isEmpty()) {
|
|
165
|
-
_appIcon = img;
|
|
166
|
-
return _appIcon;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
// Try next
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
/** Returns platform-aware frame options for content windows (settings, gallery, etc.) */
|
|
176
|
-
function framelessWindowOptions() {
|
|
177
|
-
if (isMac) {
|
|
178
|
-
return {
|
|
179
|
-
titleBarStyle: 'hidden',
|
|
180
|
-
trafficLightPosition: { x: 12, y: 12 },
|
|
181
|
-
fullscreenable: true,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
return { frame: false, icon: getAppIcon() };
|
|
185
|
-
}
|
|
186
|
-
function makeWindowFocusAware(win) {
|
|
187
|
-
// Set app icon on Windows (constructor icon can be ignored for transparent windows)
|
|
188
|
-
if (!isMac) {
|
|
189
|
-
const icon = getAppIcon();
|
|
190
|
-
if (icon)
|
|
191
|
-
win.setIcon(icon);
|
|
192
|
-
}
|
|
193
|
-
// Show the window above others initially, then drop to normal z-order
|
|
194
|
-
win.once('ready-to-show', () => {
|
|
195
|
-
win.show();
|
|
196
|
-
win.focus();
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Dismiss the selection window before capturing.
|
|
201
|
-
* On macOS, exits simpleFullscreen first so the OS releases the screen properly.
|
|
202
|
-
*/
|
|
203
|
-
async function dismissSelectionWindow() {
|
|
204
|
-
const t0 = performance.now();
|
|
205
|
-
if (!selectionWindow || selectionWindow.isDestroyed())
|
|
206
|
-
return;
|
|
207
|
-
let tFs = t0;
|
|
208
|
-
if (isMac && selectionWindow.isSimpleFullScreen()) {
|
|
209
|
-
selectionWindow.setSimpleFullScreen(false);
|
|
210
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
211
|
-
tFs = performance.now();
|
|
212
|
-
}
|
|
213
|
-
if (!selectionWindow.isDestroyed()) {
|
|
214
|
-
selectionWindow.hide();
|
|
215
|
-
}
|
|
216
|
-
const tHide = performance.now();
|
|
217
|
-
// macOS still sleeps 200ms post-hide because simpleFullscreen exit has
|
|
218
|
-
// user-visible animation tail. Windows doesn't need the sleep at all in
|
|
219
|
-
// the common case: getCaptureBuffer() prefers the pre-capture buffer
|
|
220
|
-
// (taken before the selection window even existed), so there's no fresh
|
|
221
|
-
// captureScreen() that would race the selection window's hide. Fresh-
|
|
222
|
-
// capture fallback path is rare and tolerates whatever frame arrives.
|
|
223
|
-
if (isMac) {
|
|
224
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
225
|
-
}
|
|
226
|
-
const tEnd = performance.now();
|
|
227
|
-
logger_1.default.info(`[Timing] dismissSelection: fsExit=${(tFs - t0).toFixed(0)}ms hide=${(tHide - tFs).toFixed(0)}ms postSleep=${(tEnd - tHide).toFixed(0)}ms total=${(tEnd - t0).toFixed(0)}ms`);
|
|
228
|
-
}
|
|
229
|
-
async function closeSelectionWindow() {
|
|
230
|
-
if (selectionWindow && !selectionWindow.isDestroyed()) {
|
|
231
|
-
selectionWindow.close();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Get a screen capture buffer for use after selection.
|
|
236
|
-
*
|
|
237
|
-
* Prefers the pre-captured buffer (taken before the selection window appeared)
|
|
238
|
-
* on every platform — saves the ~100–500ms post-selection captureScreen() call.
|
|
239
|
-
* macOS originally needed this because simpleFullscreen made re-capture
|
|
240
|
-
* unreliable; Windows never strictly required it but a fresh capture on the
|
|
241
|
-
* critical path was holding up the editor open by hundreds of ms.
|
|
242
|
-
*
|
|
243
|
-
* Trade-off: pre-capture is a frozen snapshot from selection-start, so
|
|
244
|
-
* dynamic content (video, animation) shows the frame from when the user
|
|
245
|
-
* triggered the hotkey, not the frame at selection-completion. macOS has
|
|
246
|
-
* shipped this behavior since cbdc751 (Mar 2026) without user complaints.
|
|
247
|
-
*
|
|
248
|
-
* Falls back to fresh capture if the pre-capture promise hasn't resolved yet
|
|
249
|
-
* (rare — only when the user completes selection faster than the selection
|
|
250
|
-
* window's did-finish-load handler can store the buffer).
|
|
251
|
-
*/
|
|
252
|
-
async function getCaptureBuffer() {
|
|
253
|
-
const t0 = performance.now();
|
|
254
|
-
const pre = (0, capture_1.getPreCapture)();
|
|
255
|
-
if (pre && pre.length > 1000) {
|
|
256
|
-
logger_1.default.info(`[Timing] getCaptureBuffer: pre-cap (${pre.length}B) ${(performance.now() - t0).toFixed(0)}ms`);
|
|
257
|
-
return pre;
|
|
258
|
-
}
|
|
259
|
-
logger_1.default.warn('[Capture] No pre-capture available, attempting live capture');
|
|
260
|
-
const buf = await (0, capture_1.captureScreen)();
|
|
261
|
-
logger_1.default.info(`[Timing] getCaptureBuffer: fresh (${buf.length}B) ${(performance.now() - t0).toFixed(0)}ms`);
|
|
262
|
-
return buf;
|
|
263
|
-
}
|
|
264
|
-
function attachCrashHandlers(win, windowName) {
|
|
265
|
-
win.webContents.on('render-process-gone', (_event, details) => {
|
|
266
|
-
logger_1.default.error(`[Crash] Render process gone in ${windowName}: reason=${details.reason}`);
|
|
267
|
-
if (details.reason !== 'clean-exit') {
|
|
268
|
-
win.reload();
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
function isPathSafe(filePath) {
|
|
273
|
-
const resolved = path.resolve(filePath);
|
|
274
|
-
if (resolved.includes('..'))
|
|
275
|
-
return false;
|
|
276
|
-
const capturesDir = getCapturesDir();
|
|
277
|
-
const userDataDir = electron_1.app.getPath('userData');
|
|
278
|
-
const tempDir = electron_1.app.getPath('temp');
|
|
279
|
-
if (resolved.startsWith(capturesDir) || resolved.startsWith(userDataDir) || resolved.startsWith(tempDir)) {
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
// Allow project-specific MCP captures: {projectDir}/.superbased/captures/
|
|
283
|
-
const sep = path.sep;
|
|
284
|
-
const marker = `${sep}.superbased${sep}captures${sep}`;
|
|
285
|
-
if (resolved.includes(marker) && path.isAbsolute(resolved) && fs.existsSync(resolved)) {
|
|
286
|
-
return true;
|
|
287
|
-
}
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
function getCapturesDir() {
|
|
291
|
-
const custom = (0, store_1.getSetting)('screenshotFolder');
|
|
292
|
-
if (custom) {
|
|
293
|
-
logger_1.default.info('[Captures] Custom folder:', custom, 'exists:', fs.existsSync(custom));
|
|
294
|
-
if (fs.existsSync(custom))
|
|
295
|
-
return custom;
|
|
296
|
-
}
|
|
297
|
-
const defaultDir = path.join(electron_1.app.getPath('userData'), constants_1.CAPTURES_DIR);
|
|
298
|
-
logger_1.default.info('[Captures] Using default:', defaultDir);
|
|
299
|
-
return defaultDir;
|
|
300
|
-
}
|
|
301
|
-
function ensureCapturesDir() {
|
|
302
|
-
const dir = getCapturesDir();
|
|
303
|
-
if (!fs.existsSync(dir)) {
|
|
304
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
/** Whether we've already shown the Screen Recording permission dialog this session */
|
|
308
|
-
let screenPermissionPromptShown = false;
|
|
309
|
-
/**
|
|
310
|
-
* One-time check at startup for macOS Screen Recording permission.
|
|
311
|
-
* Called once from app.whenReady() — does NOT block capture flow.
|
|
312
|
-
* getMediaAccessStatus('screen') can be unreliable (may report 'not-determined'
|
|
313
|
-
* even when granted), so we only show the prompt once per session.
|
|
314
|
-
*/
|
|
315
|
-
function checkScreenRecordingPermissionOnce() {
|
|
316
|
-
if (!isMac || screenPermissionPromptShown)
|
|
317
|
-
return;
|
|
318
|
-
const status = electron_1.systemPreferences.getMediaAccessStatus('screen');
|
|
319
|
-
logger_1.default.info(`[Capture] Screen Recording permission status: ${status}`);
|
|
320
|
-
if (status === 'granted')
|
|
321
|
-
return;
|
|
322
|
-
// Only prompt once per session — the status API can be unreliable
|
|
323
|
-
screenPermissionPromptShown = true;
|
|
324
|
-
electron_1.dialog
|
|
325
|
-
.showMessageBox({
|
|
326
|
-
type: 'info',
|
|
327
|
-
title: 'Screen Recording Permission',
|
|
328
|
-
message: 'SuperBased needs Screen Recording permission to capture your screen.',
|
|
329
|
-
detail: 'If screenshots appear blank or show only your wallpaper, please open System Settings > Privacy & Security > Screen Recording and enable SuperBased.\n\n' +
|
|
330
|
-
'You may need to restart the app after granting permission.',
|
|
331
|
-
buttons: ['Open System Settings', 'OK'],
|
|
332
|
-
defaultId: 1,
|
|
333
|
-
cancelId: 1,
|
|
334
|
-
})
|
|
335
|
-
.then((result) => {
|
|
336
|
-
if (result.response === 0) {
|
|
337
|
-
electron_1.shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture');
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
function createSelectionWindow(options) {
|
|
342
|
-
if (selectionWindow && !selectionWindow.isDestroyed()) {
|
|
343
|
-
selectionWindow.close();
|
|
344
|
-
}
|
|
345
|
-
createSelectionWindowInner(options?.mode || 'single');
|
|
346
|
-
}
|
|
347
|
-
async function createSelectionWindowInner(mode = 'single') {
|
|
348
|
-
// Capture active window info BEFORE hiding any SuperBased windows.
|
|
349
|
-
// On macOS, hiding windows shifts focus and active-win would report "SuperBased".
|
|
350
|
-
try {
|
|
351
|
-
lastActiveWindow = await (0, active_window_1.getActiveWindowInfo)();
|
|
352
|
-
}
|
|
353
|
-
catch {
|
|
354
|
-
// Non-blocking — proceed with null values
|
|
355
|
-
}
|
|
356
|
-
// If overlay is already open, treat this as "add capture to existing overlay".
|
|
357
|
-
// setOpacity(0) instead of hide(): keeps the window compositor-visible so
|
|
358
|
-
// the renderer's rAF + paint pipeline aren't throttled. Without this, the
|
|
359
|
-
// post-capture readiness signal is delayed by Chromium's hidden-window
|
|
360
|
-
// throttling and the eventual show() races an unpainted buffer (the
|
|
361
|
-
// gallery-flash on capture #N that survived three earlier fix iterations).
|
|
362
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
363
|
-
addingToExistingOverlay = true;
|
|
364
|
-
overlayWindow.setOpacity(0);
|
|
365
|
-
}
|
|
366
|
-
// Hide main panel window so it doesn't appear in the selection/capture
|
|
367
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
368
|
-
mainPanelWindow.hide();
|
|
369
|
-
}
|
|
370
|
-
// Pre-capture the screen BEFORE the selection window appears.
|
|
371
|
-
// This buffer is used for: (1) magnifier in the selection UI, and
|
|
372
|
-
// (2) on macOS, as the actual capture buffer — because macOS simpleFullscreen
|
|
373
|
-
// makes it impossible to cleanly re-capture the desktop after selection.
|
|
374
|
-
(0, capture_1.clearPreCapture)();
|
|
375
|
-
let preCapture = null;
|
|
376
|
-
try {
|
|
377
|
-
// Eagerly attach .catch() to prevent "Unhandled rejection" warnings —
|
|
378
|
-
// the promise may reject before it's awaited in the did-finish-load handler
|
|
379
|
-
preCapture = (0, capture_1.captureScreen)().catch((err) => {
|
|
380
|
-
logger_1.default.warn('[Capture] Pre-capture failed:', err);
|
|
381
|
-
return null;
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
catch {
|
|
385
|
-
// Magnifier won't work but selection still functions
|
|
386
|
-
}
|
|
387
|
-
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
|
|
388
|
-
const { width, height } = primaryDisplay.size;
|
|
389
|
-
selectionWindow = new electron_1.BrowserWindow({
|
|
390
|
-
x: 0,
|
|
391
|
-
y: 0,
|
|
392
|
-
width,
|
|
393
|
-
height,
|
|
394
|
-
frame: false,
|
|
395
|
-
transparent: true,
|
|
396
|
-
alwaysOnTop: true,
|
|
397
|
-
skipTaskbar: true,
|
|
398
|
-
resizable: false,
|
|
399
|
-
movable: false,
|
|
400
|
-
// Windows: native fullscreen covers everything.
|
|
401
|
-
// macOS: simpleFullscreen hides menu bar and dock while staying on current space.
|
|
402
|
-
fullscreen: !isMac,
|
|
403
|
-
simpleFullscreen: isMac,
|
|
404
|
-
webPreferences: {
|
|
405
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
406
|
-
contextIsolation: true,
|
|
407
|
-
nodeIntegration: false,
|
|
408
|
-
navigateOnDragDrop: false,
|
|
409
|
-
},
|
|
410
|
-
});
|
|
411
|
-
if (isMac) {
|
|
412
|
-
selectionWindow.setSimpleFullScreen(true);
|
|
413
|
-
// Place above everything including menu bar and fullscreen apps.
|
|
414
|
-
// visibleOnAllWorkspaces + visibleOnFullScreen prevents Mission Control
|
|
415
|
-
// space switching when capturing from a native fullscreen app.
|
|
416
|
-
selectionWindow.setAlwaysOnTop(true, 'screen-saver');
|
|
417
|
-
selectionWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
|
418
|
-
}
|
|
419
|
-
// Fallback Escape key handler at the main-process level (macOS simpleFullscreen
|
|
420
|
-
// can sometimes swallow renderer keyboard events)
|
|
421
|
-
selectionWindow.webContents.on('before-input-event', (_event, input) => {
|
|
422
|
-
if (input.key === 'Escape' && input.type === 'keyDown') {
|
|
423
|
-
closeSelectionWindow();
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
attachCrashHandlers(selectionWindow, 'selection');
|
|
427
|
-
selectionWindow.loadFile(path.join(__dirname, '../renderer/selection.html'));
|
|
428
|
-
selectionWindow.setIgnoreMouseEvents(false);
|
|
429
|
-
// Send the pre-captured screenshot for magnifier use after the window loads
|
|
430
|
-
// Also store it for use as the actual capture buffer on macOS
|
|
431
|
-
selectionWindow.webContents.once('did-finish-load', async () => {
|
|
432
|
-
try {
|
|
433
|
-
// Tell the renderer which mode to enter (single vs multi-region)
|
|
434
|
-
if (selectionWindow && !selectionWindow.isDestroyed()) {
|
|
435
|
-
selectionWindow.webContents.send('selection:mode', mode);
|
|
436
|
-
}
|
|
437
|
-
if (preCapture) {
|
|
438
|
-
const buf = await preCapture;
|
|
439
|
-
if (buf) {
|
|
440
|
-
(0, capture_1.storePreCapture)(buf);
|
|
441
|
-
logger_1.default.info(`[Capture] Pre-capture stored: ${buf.length} bytes`);
|
|
442
|
-
const dataUrl = `data:image/png;base64,${buf.toString('base64')}`;
|
|
443
|
-
if (selectionWindow && !selectionWindow.isDestroyed()) {
|
|
444
|
-
selectionWindow.webContents.send('selection:screen-image', dataUrl);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
catch (err) {
|
|
450
|
-
logger_1.default.warn('[Capture] Pre-capture failed:', err);
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
selectionWindow.on('closed', () => {
|
|
454
|
-
selectionWindow = null;
|
|
455
|
-
// Reset all selection-related state so the next hotkey press starts clean,
|
|
456
|
-
// regardless of whether close was via completion, Esc, or crash.
|
|
457
|
-
selectionUIActive = false;
|
|
458
|
-
addingToExistingOverlay = false;
|
|
459
|
-
scrollCaptureMode = false;
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Show the overlay window only after the renderer signals it has processed
|
|
464
|
-
* the latest state via `overlay:ready`. Used both for fresh-window creation
|
|
465
|
-
* and for the "append to existing overlay" flow — in both cases we need the
|
|
466
|
-
* renderer to commit the new state (init data or new screenshot + editor)
|
|
467
|
-
* before the user actually sees the window, otherwise stale-state paint
|
|
468
|
-
* leaks for a frame and produces the gallery-then-editor flash.
|
|
469
|
-
*
|
|
470
|
-
* Safety: 1-second timeout falls back to a forced show so a renderer crash
|
|
471
|
-
* or dropped IPC can't leave the window stuck hidden forever. The window's
|
|
472
|
-
* `closed` event clears the timer + listener so a window torn down mid-
|
|
473
|
-
* handshake doesn't leak ipcMain state.
|
|
474
|
-
*/
|
|
475
|
-
function showOverlayWhenReady() {
|
|
476
|
-
if (!overlayWindow || overlayWindow.isDestroyed())
|
|
477
|
-
return;
|
|
478
|
-
const win = overlayWindow;
|
|
479
|
-
const tRegister = performance.now();
|
|
480
|
-
const wasVisible = win.isVisible();
|
|
481
|
-
let shown = false;
|
|
482
|
-
const showNow = (reason) => {
|
|
483
|
-
if (shown)
|
|
484
|
-
return;
|
|
485
|
-
shown = true;
|
|
486
|
-
if (win.isDestroyed())
|
|
487
|
-
return;
|
|
488
|
-
logger_1.default.info(`[Timing] overlay:ready ${reason} after ${(performance.now() - tRegister).toFixed(0)}ms (wasVisible=${wasVisible})`);
|
|
489
|
-
if (win.isVisible()) {
|
|
490
|
-
// Capture #N: window stayed compositor-visible during selection via
|
|
491
|
-
// setOpacity(0) — no throttling, renderer already painted the new
|
|
492
|
-
// state. Just restore opacity to reveal it; no show()/focus dance.
|
|
493
|
-
win.setOpacity(1);
|
|
494
|
-
win.focus();
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
// Capture #1 (fresh window, show:false in constructor) — first show().
|
|
498
|
-
win.show();
|
|
499
|
-
win.setAlwaysOnTop(true);
|
|
500
|
-
win.focus();
|
|
501
|
-
setTimeout(() => {
|
|
502
|
-
if (!win.isDestroyed())
|
|
503
|
-
win.setAlwaysOnTop(false);
|
|
504
|
-
}, 300);
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
const handler = (event) => {
|
|
508
|
-
if (event.sender !== win.webContents)
|
|
509
|
-
return;
|
|
510
|
-
cleanup();
|
|
511
|
-
showNow('ready');
|
|
512
|
-
};
|
|
513
|
-
const timer = setTimeout(() => {
|
|
514
|
-
logger_1.default.warn('[Overlay] overlay:ready not received within 1s, force-showing');
|
|
515
|
-
cleanup();
|
|
516
|
-
showNow('timeout');
|
|
517
|
-
}, 1000);
|
|
518
|
-
const cleanup = () => {
|
|
519
|
-
clearTimeout(timer);
|
|
520
|
-
electron_1.ipcMain.removeListener('overlay:ready', handler);
|
|
521
|
-
};
|
|
522
|
-
electron_1.ipcMain.on('overlay:ready', handler);
|
|
523
|
-
win.once('closed', cleanup);
|
|
524
|
-
}
|
|
525
|
-
function createOverlayWindow(initData, region) {
|
|
526
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
527
|
-
overlayWindow.close();
|
|
528
|
-
}
|
|
529
|
-
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
|
|
530
|
-
const { width: screenW, height: screenH } = primaryDisplay.size;
|
|
531
|
-
// Restore last saved overlay bounds, or use defaults
|
|
532
|
-
const savedBounds = (0, store_1.getSetting)('overlayBounds');
|
|
533
|
-
let overlayWidth = savedBounds?.width || 520;
|
|
534
|
-
let overlayHeight = savedBounds?.height || (initData.inlineEditMode ? 620 : 560);
|
|
535
|
-
let x, y;
|
|
536
|
-
if (savedBounds) {
|
|
537
|
-
x = savedBounds.x;
|
|
538
|
-
y = savedBounds.y;
|
|
539
|
-
}
|
|
540
|
-
else {
|
|
541
|
-
x = region.x + region.width + 16;
|
|
542
|
-
y = region.y;
|
|
543
|
-
}
|
|
544
|
-
if (x + overlayWidth > screenW)
|
|
545
|
-
x = region.x - overlayWidth - 16;
|
|
546
|
-
if (x < 0)
|
|
547
|
-
x = 16;
|
|
548
|
-
if (y + overlayHeight > screenH)
|
|
549
|
-
y = screenH - overlayHeight - 16;
|
|
550
|
-
if (y < 0)
|
|
551
|
-
y = 16;
|
|
552
|
-
// On macOS, use titleBarStyle: 'hidden' with native traffic lights visible
|
|
553
|
-
const overlayFrameOptions = isMac
|
|
554
|
-
? { titleBarStyle: 'hidden', trafficLightPosition: { x: 12, y: 12 }, fullscreenable: false }
|
|
555
|
-
: { frame: false, icon: getAppIcon() };
|
|
556
|
-
overlayWindow = new electron_1.BrowserWindow({
|
|
557
|
-
x,
|
|
558
|
-
y,
|
|
559
|
-
width: overlayWidth,
|
|
560
|
-
height: overlayHeight,
|
|
561
|
-
minWidth: 320,
|
|
562
|
-
minHeight: 400,
|
|
563
|
-
...overlayFrameOptions,
|
|
564
|
-
transparent: true,
|
|
565
|
-
alwaysOnTop: false,
|
|
566
|
-
skipTaskbar: false,
|
|
567
|
-
resizable: true,
|
|
568
|
-
minimizable: true,
|
|
569
|
-
maximizable: false,
|
|
570
|
-
// Defer show until the renderer signals it has processed init data via
|
|
571
|
-
// `overlay:ready`. Without this, Electron's default show:true makes the
|
|
572
|
-
// window visible the moment the constructor returns — which means the
|
|
573
|
-
// user sees the React tree's initial empty state before onInit runs and
|
|
574
|
-
// the editor mounts. That was the actual root cause of the
|
|
575
|
-
// gallery-then-editor flash on auto-open captures (the prior
|
|
576
|
-
// ready-to-show / visibility:hidden tricks couldn't fix it because the
|
|
577
|
-
// window was already visible by the time React rendered anything).
|
|
578
|
-
show: false,
|
|
579
|
-
webPreferences: {
|
|
580
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
581
|
-
contextIsolation: true,
|
|
582
|
-
nodeIntegration: false,
|
|
583
|
-
navigateOnDragDrop: false,
|
|
584
|
-
},
|
|
585
|
-
});
|
|
586
|
-
const appIcon = getAppIcon();
|
|
587
|
-
if (appIcon && !isMac)
|
|
588
|
-
overlayWindow.setIcon(appIcon);
|
|
589
|
-
if (isMac) {
|
|
590
|
-
// Show on all workspaces so overlay appears on fullscreen app spaces
|
|
591
|
-
overlayWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
|
592
|
-
}
|
|
593
|
-
// Disable Chromium's hidden-window throttling. When the overlay is in the
|
|
594
|
-
// setOpacity(0)-during-selection state, visibilityState is still 'visible'
|
|
595
|
-
// (compositor-visible, just transparent) so this is mostly defensive — but
|
|
596
|
-
// if any future code path uses hide() instead, this prevents the rAF/paint
|
|
597
|
-
// throttling from delaying the readiness signal by 1-2s.
|
|
598
|
-
overlayWindow.webContents.setBackgroundThrottling(false);
|
|
599
|
-
// Window is created with show:false (see constructor). The actual show()
|
|
600
|
-
// is gated on the renderer's overlay:ready signal — see the helper.
|
|
601
|
-
showOverlayWhenReady();
|
|
602
|
-
overlayWindow.loadFile(path.join(__dirname, '../renderer/overlay.html'));
|
|
603
|
-
overlayWindow.webContents.on('did-finish-load', () => {
|
|
604
|
-
logger_1.default.info(`[Overlay] did-finish-load, sending init: screenshotPath=${initData.screenshotPath}, regionScreenshots=${(initData.regionScreenshots || []).length}`);
|
|
605
|
-
overlayWindow?.webContents.send('overlay:init', initData);
|
|
606
|
-
});
|
|
607
|
-
attachCrashHandlers(overlayWindow, 'overlay');
|
|
608
|
-
// Save bounds on move/resize
|
|
609
|
-
const saveBounds = () => {
|
|
610
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
611
|
-
const bounds = overlayWindow.getBounds();
|
|
612
|
-
(0, store_1.setSetting)('overlayBounds', bounds);
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
overlayWindow.on('moved', saveBounds);
|
|
616
|
-
overlayWindow.on('resized', saveBounds);
|
|
617
|
-
overlayWindow.on('closed', () => {
|
|
618
|
-
overlayWindow = null;
|
|
619
|
-
// Clear dictation callback when overlay closes
|
|
620
|
-
Promise.resolve().then(() => __importStar(require('./modules/dictation'))).then((mod) => mod.onDictationRecordingStart(null))
|
|
621
|
-
.catch(() => { });
|
|
622
|
-
});
|
|
623
|
-
// Set up dictation → overlay forwarding: when dictation starts recording
|
|
624
|
-
// while overlay is open, notify overlay to open the note editor
|
|
625
|
-
Promise.resolve().then(() => __importStar(require('./modules/dictation'))).then((mod) => {
|
|
626
|
-
mod.onDictationRecordingStart(() => {
|
|
627
|
-
if (overlayWindow && !overlayWindow.isDestroyed() && overlayWindow.isFocused()) {
|
|
628
|
-
overlayWindow.webContents.send('overlay:dictation-started');
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
})
|
|
632
|
-
.catch(() => { });
|
|
633
|
-
}
|
|
634
|
-
function openMainPanelSettings() {
|
|
635
|
-
createMainPanelWindow();
|
|
636
|
-
// Once the window is ready, tell it to navigate to settings
|
|
637
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
638
|
-
if (mainPanelWindow.webContents.isLoading()) {
|
|
639
|
-
mainPanelWindow.webContents.once('did-finish-load', () => {
|
|
640
|
-
mainPanelWindow?.webContents.send('navigate', 'settings');
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
mainPanelWindow.webContents.send('navigate', 'settings');
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
function createGalleryWindow() {
|
|
649
|
-
if (galleryWindow && !galleryWindow.isDestroyed()) {
|
|
650
|
-
galleryWindow.focus();
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
galleryWindow = new electron_1.BrowserWindow({
|
|
654
|
-
width: 900,
|
|
655
|
-
height: 700,
|
|
656
|
-
...framelessWindowOptions(),
|
|
657
|
-
webPreferences: {
|
|
658
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
659
|
-
contextIsolation: true,
|
|
660
|
-
nodeIntegration: false,
|
|
661
|
-
navigateOnDragDrop: false,
|
|
662
|
-
},
|
|
663
|
-
});
|
|
664
|
-
makeWindowFocusAware(galleryWindow);
|
|
665
|
-
attachCrashHandlers(galleryWindow, 'gallery');
|
|
666
|
-
galleryWindow.loadFile(path.join(__dirname, '../renderer/gallery.html'));
|
|
667
|
-
galleryWindow.on('closed', () => {
|
|
668
|
-
galleryWindow = null;
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
function createRecordingBarWindow() {
|
|
672
|
-
logger_1.default.info('[RecordingBar] Creating recording bar window');
|
|
673
|
-
if (recordingBarWindow && !recordingBarWindow.isDestroyed()) {
|
|
674
|
-
recordingBarWindow.focus();
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
|
|
678
|
-
const { width: screenW } = primaryDisplay.size;
|
|
679
|
-
recordingBarWindow = new electron_1.BrowserWindow({
|
|
680
|
-
width: 300,
|
|
681
|
-
height: 50,
|
|
682
|
-
x: Math.round(screenW / 2 - 150),
|
|
683
|
-
y: 8,
|
|
684
|
-
frame: false,
|
|
685
|
-
transparent: true,
|
|
686
|
-
alwaysOnTop: true,
|
|
687
|
-
skipTaskbar: true,
|
|
688
|
-
resizable: false,
|
|
689
|
-
focusable: false,
|
|
690
|
-
webPreferences: {
|
|
691
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
692
|
-
contextIsolation: true,
|
|
693
|
-
nodeIntegration: false,
|
|
694
|
-
navigateOnDragDrop: false,
|
|
695
|
-
},
|
|
696
|
-
});
|
|
697
|
-
attachCrashHandlers(recordingBarWindow, 'recording-bar');
|
|
698
|
-
recordingBarWindow.loadFile(path.join(__dirname, '../renderer/recording-bar.html'));
|
|
699
|
-
recordingBarWindow.setIgnoreMouseEvents(false);
|
|
700
|
-
recordingBarWindow.on('closed', () => {
|
|
701
|
-
recordingBarWindow = null;
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
function closeRecordingBarWindow() {
|
|
705
|
-
if (recordingBarWindow && !recordingBarWindow.isDestroyed()) {
|
|
706
|
-
recordingBarWindow.close();
|
|
707
|
-
recordingBarWindow = null;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
// --- Dictation indicator window (floating push-to-talk indicator) ---
|
|
711
|
-
function createDictationIndicatorWindow() {
|
|
712
|
-
logger_1.default.info('[Dictation] Creating indicator window');
|
|
713
|
-
if (dictationIndicatorWindow && !dictationIndicatorWindow.isDestroyed())
|
|
714
|
-
return;
|
|
715
|
-
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
|
|
716
|
-
const { width: screenW } = primaryDisplay.size;
|
|
717
|
-
dictationIndicatorWindow = new electron_1.BrowserWindow({
|
|
718
|
-
width: 420,
|
|
719
|
-
height: 48,
|
|
720
|
-
x: Math.round(screenW / 2 - 210),
|
|
721
|
-
y: 8,
|
|
722
|
-
frame: false,
|
|
723
|
-
transparent: true,
|
|
724
|
-
alwaysOnTop: true,
|
|
725
|
-
skipTaskbar: true,
|
|
726
|
-
resizable: false,
|
|
727
|
-
focusable: false,
|
|
728
|
-
show: false,
|
|
729
|
-
webPreferences: {
|
|
730
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
731
|
-
contextIsolation: true,
|
|
732
|
-
nodeIntegration: false,
|
|
733
|
-
navigateOnDragDrop: false,
|
|
734
|
-
},
|
|
735
|
-
});
|
|
736
|
-
attachCrashHandlers(dictationIndicatorWindow, 'dictation-indicator');
|
|
737
|
-
dictationIndicatorWindow.loadFile(path.join(__dirname, '../renderer/dictation-indicator.html'));
|
|
738
|
-
dictationIndicatorWindow.on('closed', () => {
|
|
739
|
-
dictationIndicatorWindow = null;
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
function closeDictationIndicatorWindow() {
|
|
743
|
-
if (dictationIndicatorWindow && !dictationIndicatorWindow.isDestroyed()) {
|
|
744
|
-
dictationIndicatorWindow.close();
|
|
745
|
-
dictationIndicatorWindow = null;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
// --- Timeline window ---
|
|
749
|
-
function createTimelineWindow(sessionId) {
|
|
750
|
-
logger_1.default.info('[Timeline] Creating timeline window, sessionId:', sessionId);
|
|
751
|
-
if (timelineWindow && !timelineWindow.isDestroyed()) {
|
|
752
|
-
timelineWindow.focus();
|
|
753
|
-
// If a sessionId is passed, tell it to navigate there
|
|
754
|
-
if (sessionId) {
|
|
755
|
-
timelineWindow.webContents.send('timeline:open-session', sessionId);
|
|
756
|
-
}
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
|
-
timelineWindow = new electron_1.BrowserWindow({
|
|
760
|
-
width: 960,
|
|
761
|
-
height: 700,
|
|
762
|
-
...framelessWindowOptions(),
|
|
763
|
-
webPreferences: {
|
|
764
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
765
|
-
contextIsolation: true,
|
|
766
|
-
nodeIntegration: false,
|
|
767
|
-
navigateOnDragDrop: false,
|
|
768
|
-
},
|
|
769
|
-
});
|
|
770
|
-
makeWindowFocusAware(timelineWindow);
|
|
771
|
-
attachCrashHandlers(timelineWindow, 'timeline');
|
|
772
|
-
timelineWindow.loadFile(path.join(__dirname, '../renderer/timeline.html'));
|
|
773
|
-
if (sessionId) {
|
|
774
|
-
timelineWindow.webContents.once('did-finish-load', () => {
|
|
775
|
-
timelineWindow?.webContents.send('timeline:open-session', sessionId);
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
timelineWindow.on('closed', () => {
|
|
779
|
-
timelineWindow = null;
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
function createStartRecordingWindow() {
|
|
783
|
-
logger_1.default.info('[StartRecording] Creating start recording dialog window');
|
|
784
|
-
if (startRecordingWindow && !startRecordingWindow.isDestroyed()) {
|
|
785
|
-
startRecordingWindow.focus();
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
|
-
startRecordingWindow = new electron_1.BrowserWindow({
|
|
789
|
-
width: 480,
|
|
790
|
-
height: 420,
|
|
791
|
-
...framelessWindowOptions(),
|
|
792
|
-
resizable: false,
|
|
793
|
-
center: true,
|
|
794
|
-
alwaysOnTop: false,
|
|
795
|
-
webPreferences: {
|
|
796
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
797
|
-
contextIsolation: true,
|
|
798
|
-
nodeIntegration: false,
|
|
799
|
-
navigateOnDragDrop: false,
|
|
800
|
-
},
|
|
801
|
-
});
|
|
802
|
-
attachCrashHandlers(startRecordingWindow, 'start-recording');
|
|
803
|
-
startRecordingWindow.loadFile(path.join(__dirname, '../renderer/start-recording.html'));
|
|
804
|
-
startRecordingWindow.on('closed', () => {
|
|
805
|
-
startRecordingWindow = null;
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
async function captureAndSaveRegion(fullScreenBuffer, region, suffix = '') {
|
|
809
|
-
const tStart = performance.now();
|
|
810
|
-
let croppedBuffer = await (0, capture_1.cropRegion)(fullScreenBuffer, region);
|
|
811
|
-
const tCrop = performance.now();
|
|
812
|
-
// Auto-redact sensitive content if enabled
|
|
813
|
-
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
814
|
-
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
815
|
-
if (redactSecrets || redactPII) {
|
|
816
|
-
logger_1.default.info('[Capture] Running auto-redact on captured image...');
|
|
817
|
-
const result = await (0, redact_1.autoRedact)(croppedBuffer, { secrets: redactSecrets, pii: redactPII });
|
|
818
|
-
logger_1.default.info(`[Capture] Auto-redact result: ${result.regionsFound} regions found`);
|
|
819
|
-
croppedBuffer = result.buffer;
|
|
820
|
-
}
|
|
821
|
-
const tRedact = performance.now();
|
|
822
|
-
ensureCapturesDir();
|
|
823
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
824
|
-
const filename = `capture-${timestamp}${suffix}.png`;
|
|
825
|
-
const filepath = path.join(getCapturesDir(), filename);
|
|
826
|
-
// Async via libuv worker pool — sync writeFileSync was blocking V8's event
|
|
827
|
-
// loop (50–200ms on slow disks), holding up the IPC that triggers the
|
|
828
|
-
// editor mount. The renderer reads the path via <img src=file://...>, so
|
|
829
|
-
// we still await before returning to keep the path-on-disk invariant.
|
|
830
|
-
await fs.promises.writeFile(filepath, croppedBuffer);
|
|
831
|
-
const tWrite = performance.now();
|
|
832
|
-
const captureId = (0, database_1.saveCapture)({
|
|
833
|
-
screenshotPath: filepath,
|
|
834
|
-
regionX: region.x,
|
|
835
|
-
regionY: region.y,
|
|
836
|
-
regionW: region.width,
|
|
837
|
-
regionH: region.height,
|
|
838
|
-
sourceApp: lastActiveWindow.appName,
|
|
839
|
-
windowTitle: lastActiveWindow.windowTitle,
|
|
840
|
-
});
|
|
841
|
-
const tDb = performance.now();
|
|
842
|
-
// Store last capture region for repeat-capture
|
|
843
|
-
(0, capture_modes_1.setLastCaptureRegion)(region);
|
|
844
|
-
// Track analytics
|
|
845
|
-
(0, database_1.trackAnalytics)('capture', suffix === '' ? 'manual' : 'other', 1, 0, lastActiveWindow.appName || '');
|
|
846
|
-
const tEnd = performance.now();
|
|
847
|
-
logger_1.default.info(`[Timing] captureAndSave: crop=${(tCrop - tStart).toFixed(0)}ms redact=${(tRedact - tCrop).toFixed(0)}ms write=${(tWrite - tRedact).toFixed(0)}ms db=${(tDb - tWrite).toFixed(0)}ms analytics=${(tEnd - tDb).toFixed(0)}ms total=${(tEnd - tStart).toFixed(0)}ms (${croppedBuffer.length}B)`);
|
|
848
|
-
return { filepath, captureId };
|
|
849
|
-
}
|
|
850
|
-
/**
|
|
851
|
-
* Draw a red circle click indicator on a nativeImage at the given physical pixel coordinates.
|
|
852
|
-
* Coordinates should already be in the screenshot's pixel space (converted at capture time
|
|
853
|
-
* on macOS; already physical on Windows).
|
|
854
|
-
*/
|
|
855
|
-
function drawClickIndicator(image, physX, physY) {
|
|
856
|
-
const size = image.getSize();
|
|
857
|
-
const cx = Math.round(physX);
|
|
858
|
-
const cy = Math.round(physY);
|
|
859
|
-
// Scale circle size relative to image — 12px at 1920w, proportionally larger for higher res
|
|
860
|
-
const baseSize = Math.max(size.width, size.height);
|
|
861
|
-
const radius = Math.round(baseSize * 0.008); // ~15px at 1920w, ~30px at 3840w
|
|
862
|
-
const thickness = Math.max(2, Math.round(radius * 0.25));
|
|
863
|
-
const bitmap = image.toBitmap();
|
|
864
|
-
const w = size.width;
|
|
865
|
-
const h = size.height;
|
|
866
|
-
const bpp = 4; // BGRA
|
|
867
|
-
// Draw a red circle ring (not filled) at (cx, cy)
|
|
868
|
-
for (let dy = -radius - thickness; dy <= radius + thickness; dy++) {
|
|
869
|
-
for (let dx = -radius - thickness; dx <= radius + thickness; dx++) {
|
|
870
|
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
871
|
-
if (dist >= radius - thickness / 2 && dist <= radius + thickness / 2) {
|
|
872
|
-
const px = cx + dx;
|
|
873
|
-
const py = cy + dy;
|
|
874
|
-
if (px >= 0 && px < w && py >= 0 && py < h) {
|
|
875
|
-
const offset = (py * w + px) * bpp;
|
|
876
|
-
bitmap[offset] = 68; // B
|
|
877
|
-
bitmap[offset + 1] = 68; // G
|
|
878
|
-
bitmap[offset + 2] = 239; // R (#EF4444)
|
|
879
|
-
bitmap[offset + 3] = 255; // A
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
return electron_1.nativeImage.createFromBitmap(bitmap, { width: w, height: h });
|
|
885
|
-
}
|
|
886
|
-
/** Load an image file into a nativeImage, handling WebP conversion via sharp */
|
|
887
|
-
async function loadImageForClipboard(filepath) {
|
|
888
|
-
let image = electron_1.nativeImage.createFromPath(filepath);
|
|
889
|
-
if (image.isEmpty()) {
|
|
890
|
-
const buf = fs.readFileSync(filepath);
|
|
891
|
-
image = electron_1.nativeImage.createFromBuffer(buf);
|
|
892
|
-
}
|
|
893
|
-
if (image.isEmpty()) {
|
|
894
|
-
try {
|
|
895
|
-
const sharp = require('sharp');
|
|
896
|
-
const pngBuf = await sharp(filepath).png().toBuffer();
|
|
897
|
-
image = electron_1.nativeImage.createFromBuffer(pngBuf);
|
|
898
|
-
}
|
|
899
|
-
catch {
|
|
900
|
-
logger_1.default.warn('[Copy] Cannot convert unsupported format:', filepath);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
return image;
|
|
904
|
-
}
|
|
905
|
-
// Overlay note text as a subtle banner at the bottom of an image (for clipboard copy).
|
|
906
|
-
// Returns a new PNG buffer with the note rendered. Original file is not modified.
|
|
907
|
-
async function overlayNoteOnImage(inputBuffer, noteText, imgWidth) {
|
|
908
|
-
const sharp = require('sharp');
|
|
909
|
-
const escXml = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
910
|
-
const fontSize = Math.max(12, Math.min(16, Math.floor(imgWidth / 55)));
|
|
911
|
-
const padding = 8;
|
|
912
|
-
const lineHeight = fontSize + 6;
|
|
913
|
-
const maxChars = Math.floor((imgWidth - padding * 2) / (fontSize * 0.52));
|
|
914
|
-
// Word-wrap
|
|
915
|
-
const words = noteText.split(' ');
|
|
916
|
-
const lines = [];
|
|
917
|
-
let cur = '';
|
|
918
|
-
for (const w of words) {
|
|
919
|
-
if (cur && (cur + ' ' + w).length > maxChars) {
|
|
920
|
-
lines.push(cur);
|
|
921
|
-
cur = w;
|
|
922
|
-
}
|
|
923
|
-
else {
|
|
924
|
-
cur = cur ? cur + ' ' + w : w;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
if (cur)
|
|
928
|
-
lines.push(cur);
|
|
929
|
-
if (lines.length > 4) {
|
|
930
|
-
lines.length = 4;
|
|
931
|
-
lines[3] = lines[3].slice(0, -3) + '...';
|
|
932
|
-
}
|
|
933
|
-
const bannerH = lines.length * lineHeight + padding * 2;
|
|
934
|
-
const textEls = lines
|
|
935
|
-
.map((ln, i) => `<text x="${padding}" y="${padding + (i + 1) * lineHeight - 4}" fill="#e0e0e0" font-size="${fontSize}" font-family="Segoe UI, Inter, system-ui, sans-serif">${escXml(ln)}</text>`)
|
|
936
|
-
.join('');
|
|
937
|
-
const svg = Buffer.from(`<svg width="${imgWidth}" height="${bannerH}"><rect width="${imgWidth}" height="${bannerH}" fill="#1a1a1a" rx="0"/>${textEls}</svg>`);
|
|
938
|
-
return sharp(inputBuffer)
|
|
939
|
-
.extend({ bottom: bannerH, background: { r: 26, g: 26, b: 26, alpha: 255 } })
|
|
940
|
-
.composite([{ input: svg, gravity: 'south' }])
|
|
941
|
-
.png()
|
|
942
|
-
.toBuffer();
|
|
943
|
-
}
|
|
944
|
-
// Store notes and register/manage the global paste shortcut
|
|
945
|
-
function setPendingNotes(text) {
|
|
946
|
-
pendingNotesText = text;
|
|
947
|
-
const shortcut = (0, store_1.getSetting)('notePasteShortcut') || 'CommandOrControl+Shift+N';
|
|
948
|
-
if (text && !notesPasteShortcutRegistered) {
|
|
949
|
-
try {
|
|
950
|
-
const ok = electron_1.globalShortcut.register(shortcut, async () => {
|
|
951
|
-
if (!pendingNotesText)
|
|
952
|
-
return;
|
|
953
|
-
const notes = pendingNotesText;
|
|
954
|
-
// Write notes to clipboard and simulate paste (same pattern as dictation)
|
|
955
|
-
const { saveClipboardState, writeClipboardText, restoreClipboardState } = await Promise.resolve().then(() => __importStar(require('./modules/clipboard')));
|
|
956
|
-
const { simulatePaste } = await Promise.resolve().then(() => __importStar(require('./modules/keystroke')));
|
|
957
|
-
saveClipboardState();
|
|
958
|
-
writeClipboardText(notes);
|
|
959
|
-
await simulatePaste();
|
|
960
|
-
setTimeout(() => restoreClipboardState(), 200);
|
|
961
|
-
logger_1.default.info('[Notes] Pasted notes via shortcut (' + shortcut + ')');
|
|
962
|
-
});
|
|
963
|
-
if (ok) {
|
|
964
|
-
notesPasteShortcutRegistered = true;
|
|
965
|
-
logger_1.default.info('[Notes] Shortcut registered:', shortcut);
|
|
966
|
-
// Auto-clear after 5 minutes
|
|
967
|
-
setTimeout(() => {
|
|
968
|
-
if (pendingNotesText === text) {
|
|
969
|
-
setPendingNotes(null);
|
|
970
|
-
}
|
|
971
|
-
}, 5 * 60 * 1000);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
catch (err) {
|
|
975
|
-
logger_1.default.warn('[Notes] Failed to register shortcut:', err);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
else if (!text && notesPasteShortcutRegistered) {
|
|
979
|
-
try {
|
|
980
|
-
const shortcutToUnregister = (0, store_1.getSetting)('notePasteShortcut') || 'CommandOrControl+Shift+N';
|
|
981
|
-
electron_1.globalShortcut.unregister(shortcutToUnregister);
|
|
982
|
-
}
|
|
983
|
-
catch { }
|
|
984
|
-
notesPasteShortcutRegistered = false;
|
|
985
|
-
logger_1.default.info('[Notes] Shortcut unregistered');
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
function setupIpcHandlers() {
|
|
989
|
-
// Single selection completed
|
|
990
|
-
electron_1.ipcMain.handle('capture:selection-complete', async (_event, region) => {
|
|
991
|
-
try {
|
|
992
|
-
// If adding to existing overlay, just capture and send the path back
|
|
993
|
-
if (addingToExistingOverlay) {
|
|
994
|
-
addingToExistingOverlay = false;
|
|
995
|
-
const tHandler = performance.now();
|
|
996
|
-
await dismissSelectionWindow();
|
|
997
|
-
const tDismiss = performance.now();
|
|
998
|
-
const fullScreenBuffer = await getCaptureBuffer();
|
|
999
|
-
const tCapBuf = performance.now();
|
|
1000
|
-
await closeSelectionWindow();
|
|
1001
|
-
const tClose = performance.now();
|
|
1002
|
-
const { filepath } = await captureAndSaveRegion(fullScreenBuffer, region);
|
|
1003
|
-
const tSave = performance.now();
|
|
1004
|
-
// Overlay is already at opacity:0 from createSelectionWindowInner.
|
|
1005
|
-
// Send the IPC, then handshake — showOverlayWhenReady will restore
|
|
1006
|
-
// opacity:1 once the renderer signals it has painted the post-IPC
|
|
1007
|
-
// state.
|
|
1008
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
1009
|
-
const autoOpen = !region.shiftHeld &&
|
|
1010
|
-
!region.altHeld &&
|
|
1011
|
-
(0, store_1.getSetting)('openEditorAfterCapture') !== false;
|
|
1012
|
-
overlayWindow.webContents.send('capture:screenshot-added', {
|
|
1013
|
-
path: filepath,
|
|
1014
|
-
autoOpenEditor: autoOpen,
|
|
1015
|
-
});
|
|
1016
|
-
showOverlayWhenReady();
|
|
1017
|
-
}
|
|
1018
|
-
const tEnd = performance.now();
|
|
1019
|
-
logger_1.default.info(`[Timing] capture#N append: dismiss=${(tDismiss - tHandler).toFixed(0)}ms getCap=${(tCapBuf - tDismiss).toFixed(0)}ms close=${(tClose - tCapBuf).toFixed(0)}ms save=${(tSave - tClose).toFixed(0)}ms ipc=${(tEnd - tSave).toFixed(0)}ms TOTAL=${(tEnd - tHandler).toFixed(0)}ms`);
|
|
1020
|
-
return { success: true, filepath };
|
|
1021
|
-
}
|
|
1022
|
-
// Scroll-capture mode: capture the region, then auto-scroll and capture more
|
|
1023
|
-
if (scrollCaptureMode) {
|
|
1024
|
-
scrollCaptureMode = false;
|
|
1025
|
-
await dismissSelectionWindow();
|
|
1026
|
-
await closeSelectionWindow();
|
|
1027
|
-
const scrollSettings = (0, store_1.getSetting)('scrollCapture') || {};
|
|
1028
|
-
const maxScreenshots = scrollSettings.maxScreenshots || 10;
|
|
1029
|
-
const overlapPercent = scrollSettings.overlapPercent || 15;
|
|
1030
|
-
const scrollDelayMs = scrollSettings.scrollDelayMs || 600;
|
|
1031
|
-
let pixelsPerScroll = scrollSettings.pixelsPerScroll || 0;
|
|
1032
|
-
const { performScrollCapture, calibrateScroll } = require('./modules/scroll-capture');
|
|
1033
|
-
// Auto-calibrate if not done yet
|
|
1034
|
-
if (pixelsPerScroll <= 0) {
|
|
1035
|
-
logger_1.default.info('[ScrollCapture] No calibration found, auto-calibrating...');
|
|
1036
|
-
pixelsPerScroll = await calibrateScroll(region);
|
|
1037
|
-
const current = (0, store_1.getSetting)('scrollCapture') || {};
|
|
1038
|
-
(0, store_1.setSetting)('scrollCapture', { ...current, pixelsPerScroll });
|
|
1039
|
-
}
|
|
1040
|
-
const screenshotPaths = [];
|
|
1041
|
-
let primaryCaptureId = 0;
|
|
1042
|
-
const captures = await performScrollCapture({
|
|
1043
|
-
region,
|
|
1044
|
-
maxScreenshots,
|
|
1045
|
-
overlapPercent,
|
|
1046
|
-
scrollDelayMs,
|
|
1047
|
-
pixelsPerScroll,
|
|
1048
|
-
onProgress: () => { },
|
|
1049
|
-
});
|
|
1050
|
-
// Save all captures
|
|
1051
|
-
ensureCapturesDir();
|
|
1052
|
-
for (let i = 0; i < captures.length; i++) {
|
|
1053
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
1054
|
-
const filename = `scroll-${timestamp}-${i + 1}.png`;
|
|
1055
|
-
const filepath = path.join(getCapturesDir(), filename);
|
|
1056
|
-
fs.writeFileSync(filepath, captures[i]);
|
|
1057
|
-
screenshotPaths.push(filepath);
|
|
1058
|
-
if (i === 0) {
|
|
1059
|
-
primaryCaptureId = (0, database_1.saveCapture)({
|
|
1060
|
-
screenshotPath: filepath,
|
|
1061
|
-
regionX: region.x,
|
|
1062
|
-
regionY: region.y,
|
|
1063
|
-
regionW: region.width,
|
|
1064
|
-
regionH: region.height,
|
|
1065
|
-
sourceApp: lastActiveWindow.appName,
|
|
1066
|
-
windowTitle: lastActiveWindow.windowTitle,
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
// Open overlay with all captured screenshots. Scroll capture produces a
|
|
1071
|
-
// single primary stitched result — honour openEditorAfterCapture so the
|
|
1072
|
-
// user can annotate immediately.
|
|
1073
|
-
const autoOpenAfterScroll = (0, store_1.getSetting)('openEditorAfterCapture') !== false;
|
|
1074
|
-
createOverlayWindow({
|
|
1075
|
-
screenshotPath: screenshotPaths[0],
|
|
1076
|
-
captureId: primaryCaptureId,
|
|
1077
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
1078
|
-
voiceMode: false,
|
|
1079
|
-
inlineEditMode: false,
|
|
1080
|
-
originalText: null,
|
|
1081
|
-
multiRegion: true,
|
|
1082
|
-
regionScreenshots: screenshotPaths,
|
|
1083
|
-
autoOpenEditor: autoOpenAfterScroll,
|
|
1084
|
-
}, region);
|
|
1085
|
-
return { success: true, captureId: primaryCaptureId, count: captures.length };
|
|
1086
|
-
}
|
|
1087
|
-
// Normal flow: create new overlay
|
|
1088
|
-
const tHandler = performance.now();
|
|
1089
|
-
const isInlineEdit = !!region.altHeld;
|
|
1090
|
-
let originalText = null;
|
|
1091
|
-
if (isInlineEdit) {
|
|
1092
|
-
(0, clipboard_1.saveClipboardState)();
|
|
1093
|
-
await dismissSelectionWindow();
|
|
1094
|
-
await (0, keystroke_1.simulateCopy)();
|
|
1095
|
-
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
1096
|
-
originalText = (0, clipboard_1.readClipboardText)();
|
|
1097
|
-
// originalText captured above for inline-edit undo
|
|
1098
|
-
}
|
|
1099
|
-
else {
|
|
1100
|
-
await dismissSelectionWindow();
|
|
1101
|
-
}
|
|
1102
|
-
const tDismiss = performance.now();
|
|
1103
|
-
const fullScreenBuffer = await getCaptureBuffer();
|
|
1104
|
-
const tCapBuf = performance.now();
|
|
1105
|
-
await closeSelectionWindow();
|
|
1106
|
-
const tClose = performance.now();
|
|
1107
|
-
const { filepath, captureId } = await captureAndSaveRegion(fullScreenBuffer, region);
|
|
1108
|
-
const tSave = performance.now();
|
|
1109
|
-
// Auto-open editor right after a normal single-region capture when the
|
|
1110
|
-
// setting is enabled (default). Skip for voice mode (shift-held — AI takes
|
|
1111
|
-
// over immediately) and inline-edit mode (alt-held — text rewrite flow,
|
|
1112
|
-
// no annotation surface).
|
|
1113
|
-
const autoOpenEditor = !isInlineEdit && !region.shiftHeld && (0, store_1.getSetting)('openEditorAfterCapture') !== false;
|
|
1114
|
-
createOverlayWindow({
|
|
1115
|
-
screenshotPath: filepath,
|
|
1116
|
-
captureId,
|
|
1117
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
1118
|
-
voiceMode: !!region.shiftHeld,
|
|
1119
|
-
inlineEditMode: isInlineEdit,
|
|
1120
|
-
originalText,
|
|
1121
|
-
multiRegion: false,
|
|
1122
|
-
regionScreenshots: [],
|
|
1123
|
-
autoOpenEditor,
|
|
1124
|
-
}, region);
|
|
1125
|
-
const tEnd = performance.now();
|
|
1126
|
-
logger_1.default.info(`[Timing] capture#1 normal: dismiss=${(tDismiss - tHandler).toFixed(0)}ms getCap=${(tCapBuf - tDismiss).toFixed(0)}ms close=${(tClose - tCapBuf).toFixed(0)}ms save=${(tSave - tClose).toFixed(0)}ms createOverlay=${(tEnd - tSave).toFixed(0)}ms TOTAL=${(tEnd - tHandler).toFixed(0)}ms (overlay show pending ready signal)`);
|
|
1127
|
-
return { success: true, captureId, filepath };
|
|
1128
|
-
}
|
|
1129
|
-
catch (error) {
|
|
1130
|
-
logger_1.default.error('Capture failed:', error);
|
|
1131
|
-
addingToExistingOverlay = false;
|
|
1132
|
-
return { success: false, error: String(error) };
|
|
1133
|
-
}
|
|
1134
|
-
});
|
|
1135
|
-
// Multi-selection completed
|
|
1136
|
-
electron_1.ipcMain.handle('capture:multi-selection-complete', async (_event, data) => {
|
|
1137
|
-
try {
|
|
1138
|
-
// If adding to existing overlay, append each region to the current session
|
|
1139
|
-
if (addingToExistingOverlay) {
|
|
1140
|
-
addingToExistingOverlay = false;
|
|
1141
|
-
await dismissSelectionWindow();
|
|
1142
|
-
const fullScreenBuffer = await getCaptureBuffer();
|
|
1143
|
-
await closeSelectionWindow();
|
|
1144
|
-
const appendedPaths = [];
|
|
1145
|
-
for (let i = 0; i < data.regions.length; i++) {
|
|
1146
|
-
const { filepath } = await captureAndSaveRegion(fullScreenBuffer, data.regions[i], `-region${i + 1}`);
|
|
1147
|
-
appendedPaths.push(filepath);
|
|
1148
|
-
}
|
|
1149
|
-
// Multi-region append: send all path IPCs first, then defer show()
|
|
1150
|
-
// until the renderer signals overlay:ready post-render. Multi-region
|
|
1151
|
-
// doesn't auto-open the editor (gallery view stays the target), but
|
|
1152
|
-
// the same handshake still beats the show-with-stale-state flash.
|
|
1153
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
1154
|
-
for (const p of appendedPaths) {
|
|
1155
|
-
overlayWindow.webContents.send('capture:screenshot-added', p);
|
|
1156
|
-
}
|
|
1157
|
-
showOverlayWhenReady();
|
|
1158
|
-
}
|
|
1159
|
-
return { success: true, filepaths: appendedPaths };
|
|
1160
|
-
}
|
|
1161
|
-
await dismissSelectionWindow();
|
|
1162
|
-
const fullScreenBuffer = await getCaptureBuffer();
|
|
1163
|
-
await closeSelectionWindow();
|
|
1164
|
-
// Capture each region separately
|
|
1165
|
-
const regionScreenshots = [];
|
|
1166
|
-
let primaryCaptureId = 0;
|
|
1167
|
-
let primaryFilepath = '';
|
|
1168
|
-
for (let i = 0; i < data.regions.length; i++) {
|
|
1169
|
-
const { filepath, captureId } = await captureAndSaveRegion(fullScreenBuffer, data.regions[i], `-region${i + 1}`);
|
|
1170
|
-
regionScreenshots.push(filepath);
|
|
1171
|
-
if (i === 0) {
|
|
1172
|
-
primaryCaptureId = captureId;
|
|
1173
|
-
primaryFilepath = filepath;
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
createOverlayWindow({
|
|
1177
|
-
screenshotPath: primaryFilepath,
|
|
1178
|
-
captureId: primaryCaptureId,
|
|
1179
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
1180
|
-
voiceMode: !!data.shiftHeld,
|
|
1181
|
-
inlineEditMode: false,
|
|
1182
|
-
originalText: null,
|
|
1183
|
-
multiRegion: true,
|
|
1184
|
-
regionScreenshots,
|
|
1185
|
-
}, data.regions[0]);
|
|
1186
|
-
return { success: true, captureId: primaryCaptureId };
|
|
1187
|
-
}
|
|
1188
|
-
catch (error) {
|
|
1189
|
-
logger_1.default.error('Multi-capture failed:', error);
|
|
1190
|
-
return { success: false, error: String(error) };
|
|
1191
|
-
}
|
|
1192
|
-
});
|
|
1193
|
-
electron_1.ipcMain.handle('capture:cancel', async () => {
|
|
1194
|
-
if (isMac && selectionWindow && !selectionWindow.isDestroyed() && selectionWindow.isSimpleFullScreen()) {
|
|
1195
|
-
selectionWindow.setSimpleFullScreen(false);
|
|
1196
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1197
|
-
}
|
|
1198
|
-
await closeSelectionWindow();
|
|
1199
|
-
addingToExistingOverlay = false;
|
|
1200
|
-
// Restore overlay after cancellation. Capture flow uses setOpacity(0)
|
|
1201
|
-
// (not hide()) to keep the compositor active during selection — so we
|
|
1202
|
-
// restore via setOpacity(1) instead of show().
|
|
1203
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
1204
|
-
overlayWindow.setOpacity(1);
|
|
1205
|
-
}
|
|
1206
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
1207
|
-
mainPanelWindow.show();
|
|
1208
|
-
}
|
|
1209
|
-
return { success: true };
|
|
1210
|
-
});
|
|
1211
|
-
// AI: process screenshot with instruction
|
|
1212
|
-
// Add more screenshots to existing overlay. setOpacity(0) (not hide()) so
|
|
1213
|
-
// the renderer stays compositor-visible — same reasoning as the
|
|
1214
|
-
// hotkey-driven capture flow above.
|
|
1215
|
-
electron_1.ipcMain.handle('capture:add-screenshot', async () => {
|
|
1216
|
-
if (!overlayWindow || overlayWindow.isDestroyed())
|
|
1217
|
-
return { success: false };
|
|
1218
|
-
if (!tryClaimSelectionUI())
|
|
1219
|
-
return { success: false };
|
|
1220
|
-
addingToExistingOverlay = true;
|
|
1221
|
-
overlayWindow.setOpacity(0);
|
|
1222
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1223
|
-
createSelectionWindow();
|
|
1224
|
-
return { success: true };
|
|
1225
|
-
});
|
|
1226
|
-
electron_1.ipcMain.handle('ai:process', async (event, data) => {
|
|
1227
|
-
// Require authentication for AI features
|
|
1228
|
-
if (!(0, auth_1.isAuthenticated)()) {
|
|
1229
|
-
return { success: false, error: 'Please sign in to use AI features.' };
|
|
1230
|
-
}
|
|
1231
|
-
try {
|
|
1232
|
-
// Support both single and multiple screenshot paths
|
|
1233
|
-
const paths = data.screenshotPaths || (data.screenshotPath ? [data.screenshotPath] : []);
|
|
1234
|
-
for (const p of paths) {
|
|
1235
|
-
if (!isPathSafe(p)) {
|
|
1236
|
-
return { success: false, error: 'Invalid file path' };
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
// Vision optimization: resize images to max 1568px longest edge before sending to backend
|
|
1240
|
-
const sharp = require('sharp');
|
|
1241
|
-
const imagesBase64 = [];
|
|
1242
|
-
for (const p of paths) {
|
|
1243
|
-
const buf = fs.readFileSync(p);
|
|
1244
|
-
const meta = await sharp(buf).metadata();
|
|
1245
|
-
const maxDim = Math.max(meta.width || 0, meta.height || 0);
|
|
1246
|
-
if (maxDim > 1568) {
|
|
1247
|
-
const resized = await sharp(buf)
|
|
1248
|
-
.resize({
|
|
1249
|
-
width: maxDim === meta.width ? 1568 : undefined,
|
|
1250
|
-
height: maxDim === meta.height ? 1568 : undefined,
|
|
1251
|
-
fit: 'inside',
|
|
1252
|
-
})
|
|
1253
|
-
.png()
|
|
1254
|
-
.toBuffer();
|
|
1255
|
-
imagesBase64.push(resized.toString('base64'));
|
|
1256
|
-
}
|
|
1257
|
-
else {
|
|
1258
|
-
imagesBase64.push(buf.toString('base64'));
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
// Estimate token usage for multi-image and warn if near limit
|
|
1262
|
-
if (imagesBase64.length > 1) {
|
|
1263
|
-
let totalEstTokens = 0;
|
|
1264
|
-
for (const b64 of imagesBase64) {
|
|
1265
|
-
const sizeBytes = b64.length * 0.75;
|
|
1266
|
-
const megapixels = sizeBytes / (3 * 1024 * 1024);
|
|
1267
|
-
totalEstTokens += Math.max(1600, Math.round(megapixels * 1600));
|
|
1268
|
-
}
|
|
1269
|
-
if (totalEstTokens > 80000 && !event.sender.isDestroyed()) {
|
|
1270
|
-
event.sender.send('ai:token-warning', {
|
|
1271
|
-
estimatedTokens: totalEstTokens,
|
|
1272
|
-
imageCount: imagesBase64.length,
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
const { instruction } = (0, instruction_parser_1.parseInstruction)(data.instruction);
|
|
1277
|
-
const systemPrompt = (0, store_1.getSetting)('systemPrompt') || '';
|
|
1278
|
-
const contexts = imagesBase64.map((imageBase64, i) => ({
|
|
1279
|
-
imageBase64,
|
|
1280
|
-
sourceApp: lastActiveWindow.appName,
|
|
1281
|
-
windowTitle: lastActiveWindow.windowTitle,
|
|
1282
|
-
regionIndex: i,
|
|
1283
|
-
}));
|
|
1284
|
-
const fullPrompt = (systemPrompt ? systemPrompt + '\n\n' : '') + (0, context_builder_1.buildPrompt)(instruction, contexts);
|
|
1285
|
-
let fullResponse = '';
|
|
1286
|
-
logger_1.default.info(`[AI] Starting stream via backend proxy, images=${imagesBase64.length}`);
|
|
1287
|
-
let chunksSent = 0;
|
|
1288
|
-
for await (const chunk of (0, ai_client_1.streamAIFromBackend)({
|
|
1289
|
-
imagesBase64,
|
|
1290
|
-
instruction: fullPrompt,
|
|
1291
|
-
conversationHistory: data.conversationHistory,
|
|
1292
|
-
})) {
|
|
1293
|
-
fullResponse += chunk;
|
|
1294
|
-
chunksSent++;
|
|
1295
|
-
if (!event.sender.isDestroyed()) {
|
|
1296
|
-
event.sender.send('ai:stream-chunk', chunk);
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
logger_1.default.info(`[AI] Stream finished. Chunks sent: ${chunksSent}, Response length: ${fullResponse.length}`);
|
|
1300
|
-
logger_1.default.info(`[AI] First 200 chars: ${fullResponse.slice(0, 200)}`);
|
|
1301
|
-
if (!event.sender.isDestroyed()) {
|
|
1302
|
-
event.sender.send('ai:stream-complete');
|
|
1303
|
-
logger_1.default.info('[AI] Sent stream-complete to sender');
|
|
1304
|
-
}
|
|
1305
|
-
(0, database_1.updateCapture)(data.captureId, {
|
|
1306
|
-
aiResponse: fullResponse,
|
|
1307
|
-
instruction: data.instruction,
|
|
1308
|
-
});
|
|
1309
|
-
// Track AI query analytics
|
|
1310
|
-
(0, database_1.trackAnalytics)('ai_query', '', 1, fullResponse.length);
|
|
1311
|
-
return { success: true, response: fullResponse };
|
|
1312
|
-
}
|
|
1313
|
-
catch (error) {
|
|
1314
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
1315
|
-
if (!event.sender.isDestroyed()) {
|
|
1316
|
-
event.sender.send('ai:stream-error', errorMsg);
|
|
1317
|
-
}
|
|
1318
|
-
return { success: false, error: errorMsg };
|
|
1319
|
-
}
|
|
1320
|
-
});
|
|
1321
|
-
// Screenshot classification — heuristic-based, cached per path
|
|
1322
|
-
const classificationCache = new Map();
|
|
1323
|
-
electron_1.ipcMain.handle('ai:classify-screenshot', async (_event, screenshotPath) => {
|
|
1324
|
-
if (classificationCache.has(screenshotPath)) {
|
|
1325
|
-
return { success: true, type: classificationCache.get(screenshotPath) };
|
|
1326
|
-
}
|
|
1327
|
-
try {
|
|
1328
|
-
// Use window title/app name for heuristic classification
|
|
1329
|
-
const appName = (lastActiveWindow.appName || '').toLowerCase();
|
|
1330
|
-
const title = (lastActiveWindow.windowTitle || '').toLowerCase();
|
|
1331
|
-
let type = 'general';
|
|
1332
|
-
if (/code|vs\s?code|visual studio|intellij|webstorm|sublime|vim|neovim|terminal|cmd|powershell|bash/.test(appName + ' ' + title)) {
|
|
1333
|
-
type = 'code';
|
|
1334
|
-
}
|
|
1335
|
-
else if (/error|exception|crash|fail|stack trace|traceback/.test(title)) {
|
|
1336
|
-
type = 'error';
|
|
1337
|
-
}
|
|
1338
|
-
else if (/chrome|firefox|edge|safari|opera|brave|browser/.test(appName)) {
|
|
1339
|
-
type = 'ui';
|
|
1340
|
-
}
|
|
1341
|
-
else if (/word|docs|notion|obsidian|notepad|txt|pdf|reader/.test(appName + ' ' + title)) {
|
|
1342
|
-
type = 'text';
|
|
1343
|
-
}
|
|
1344
|
-
else if (/excel|sheets|csv|table|data|sql|database/.test(appName + ' ' + title)) {
|
|
1345
|
-
type = 'data';
|
|
1346
|
-
}
|
|
1347
|
-
classificationCache.set(screenshotPath, type);
|
|
1348
|
-
return { success: true, type };
|
|
1349
|
-
}
|
|
1350
|
-
catch {
|
|
1351
|
-
return { success: true, type: 'general' };
|
|
1352
|
-
}
|
|
1353
|
-
});
|
|
1354
|
-
// Voice transcription via OpenAI Whisper
|
|
1355
|
-
// Voice transcription via backend proxy (OpenAI Whisper)
|
|
1356
|
-
electron_1.ipcMain.handle('voice:transcribe', async (_event, audioBase64) => {
|
|
1357
|
-
if (!(0, auth_1.isAuthenticated)()) {
|
|
1358
|
-
return { success: false, error: 'Please sign in to use voice features.' };
|
|
1359
|
-
}
|
|
1360
|
-
try {
|
|
1361
|
-
const text = await (0, ai_client_1.transcribeViaBackend)(audioBase64);
|
|
1362
|
-
logger_1.default.info('[Voice] Transcription:', text.slice(0, 100));
|
|
1363
|
-
return { success: true, text: text.trim() };
|
|
1364
|
-
}
|
|
1365
|
-
catch (error) {
|
|
1366
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
1367
|
-
logger_1.default.error('[Voice] Transcription error:', msg);
|
|
1368
|
-
return { success: false, error: msg };
|
|
1369
|
-
}
|
|
1370
|
-
});
|
|
1371
|
-
// Dictation: receive audio from indicator window, transcribe, paste
|
|
1372
|
-
electron_1.ipcMain.handle('dictation:audio-ready', async (_event, audioBase64) => {
|
|
1373
|
-
const { handleAudioReady } = await Promise.resolve().then(() => __importStar(require('./modules/dictation')));
|
|
1374
|
-
return handleAudioReady(audioBase64);
|
|
1375
|
-
});
|
|
1376
|
-
// Dictation: enable/disable
|
|
1377
|
-
electron_1.ipcMain.handle('dictation:set-enabled', async (_event, enabled) => {
|
|
1378
|
-
try {
|
|
1379
|
-
if (enabled && !(0, auth_1.isAuthenticated)()) {
|
|
1380
|
-
return { success: false, error: 'Please sign in to use dictation.' };
|
|
1381
|
-
}
|
|
1382
|
-
(0, store_1.setSetting)('dictationEnabled', enabled);
|
|
1383
|
-
if (enabled) {
|
|
1384
|
-
if (!dictationIndicatorWindow || dictationIndicatorWindow.isDestroyed()) {
|
|
1385
|
-
createDictationIndicatorWindow();
|
|
1386
|
-
}
|
|
1387
|
-
const { initializeDictation } = await Promise.resolve().then(() => __importStar(require('./modules/dictation')));
|
|
1388
|
-
await initializeDictation(dictationIndicatorWindow);
|
|
1389
|
-
logger_1.default.info('[Dictation] Enabled');
|
|
1390
|
-
}
|
|
1391
|
-
else {
|
|
1392
|
-
const { teardownDictation } = await Promise.resolve().then(() => __importStar(require('./modules/dictation')));
|
|
1393
|
-
await teardownDictation();
|
|
1394
|
-
if (dictationIndicatorWindow && !dictationIndicatorWindow.isDestroyed()) {
|
|
1395
|
-
dictationIndicatorWindow.hide();
|
|
1396
|
-
}
|
|
1397
|
-
logger_1.default.info('[Dictation] Disabled');
|
|
1398
|
-
}
|
|
1399
|
-
return { success: true };
|
|
1400
|
-
}
|
|
1401
|
-
catch (error) {
|
|
1402
|
-
return { success: false, error: String(error) };
|
|
1403
|
-
}
|
|
1404
|
-
});
|
|
1405
|
-
// Dictation: update settings
|
|
1406
|
-
electron_1.ipcMain.handle('dictation:set-settings', async (_event, settings) => {
|
|
1407
|
-
const current = (0, store_1.getSetting)('dictationSettings') || {};
|
|
1408
|
-
const updated = { ...current, ...settings };
|
|
1409
|
-
(0, store_1.setSetting)('dictationSettings', updated);
|
|
1410
|
-
// Update live dictation module if running
|
|
1411
|
-
try {
|
|
1412
|
-
const dictation = await Promise.resolve().then(() => __importStar(require('./modules/dictation')));
|
|
1413
|
-
if (settings.shortcutModifiers) {
|
|
1414
|
-
dictation.setDictationShortcut(settings.shortcutModifiers);
|
|
1415
|
-
}
|
|
1416
|
-
if (settings.aiCleanup !== undefined) {
|
|
1417
|
-
dictation.setDictationAICleanup(settings.aiCleanup);
|
|
1418
|
-
}
|
|
1419
|
-
if (settings.soundFeedback !== undefined) {
|
|
1420
|
-
dictation.setDictationSoundFeedback(settings.soundFeedback);
|
|
1421
|
-
}
|
|
1422
|
-
if (settings.maxDurationSeconds !== undefined) {
|
|
1423
|
-
dictation.setDictationMaxDuration(settings.maxDurationSeconds);
|
|
1424
|
-
}
|
|
1425
|
-
if (settings.excludedApps !== undefined) {
|
|
1426
|
-
dictation.setDictationExcludedApps(settings.excludedApps);
|
|
1427
|
-
}
|
|
1428
|
-
if (settings.language !== undefined) {
|
|
1429
|
-
dictation.setDictationLanguage(settings.language);
|
|
1430
|
-
}
|
|
1431
|
-
if (settings.pasteMethod !== undefined) {
|
|
1432
|
-
dictation.setDictationPasteMethod(settings.pasteMethod);
|
|
1433
|
-
}
|
|
1434
|
-
if (settings.endSilenceMs !== undefined || settings.initialSilenceMs !== undefined || settings.segmentationSilenceMs !== undefined) {
|
|
1435
|
-
dictation.setDictationTimingOptions({
|
|
1436
|
-
endSilenceMs: settings.endSilenceMs,
|
|
1437
|
-
initialSilenceMs: settings.initialSilenceMs,
|
|
1438
|
-
segmentationSilenceMs: settings.segmentationSilenceMs,
|
|
1439
|
-
});
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
catch {
|
|
1443
|
-
// Module not loaded yet
|
|
1444
|
-
}
|
|
1445
|
-
return { success: true };
|
|
1446
|
-
});
|
|
1447
|
-
// Dictation: history
|
|
1448
|
-
electron_1.ipcMain.handle('dictation:get-history', async (_event, limit) => {
|
|
1449
|
-
const { getDictationHistory } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
1450
|
-
return getDictationHistory(limit || 50);
|
|
1451
|
-
});
|
|
1452
|
-
electron_1.ipcMain.handle('dictation:clear-history', async () => {
|
|
1453
|
-
const { clearDictationHistory } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
1454
|
-
clearDictationHistory();
|
|
1455
|
-
return { success: true };
|
|
1456
|
-
});
|
|
1457
|
-
// Dictation: personal dictionary
|
|
1458
|
-
electron_1.ipcMain.handle('dictation:get-dictionary', async () => {
|
|
1459
|
-
const { getDictionaryWords } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
1460
|
-
return getDictionaryWords();
|
|
1461
|
-
});
|
|
1462
|
-
electron_1.ipcMain.handle('dictation:add-dictionary-word', async (_event, word) => {
|
|
1463
|
-
const { addDictionaryWord } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
1464
|
-
addDictionaryWord(word);
|
|
1465
|
-
return { success: true };
|
|
1466
|
-
});
|
|
1467
|
-
electron_1.ipcMain.handle('dictation:remove-dictionary-word', async (_event, id) => {
|
|
1468
|
-
const { removeDictionaryWord } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
1469
|
-
removeDictionaryWord(id);
|
|
1470
|
-
return { success: true };
|
|
1471
|
-
});
|
|
1472
|
-
electron_1.ipcMain.handle('dictation:clear-dictionary', async () => {
|
|
1473
|
-
const { clearDictionary } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
1474
|
-
clearDictionary();
|
|
1475
|
-
return { success: true };
|
|
1476
|
-
});
|
|
1477
|
-
// Dictation: real-time speech — push audio buffer
|
|
1478
|
-
electron_1.ipcMain.on('dictation:push-audio', (_event, pcmBuffer) => {
|
|
1479
|
-
Promise.resolve().then(() => __importStar(require('./modules/azure-speech-realtime'))).then((mod) => {
|
|
1480
|
-
mod.pushAudioData(pcmBuffer);
|
|
1481
|
-
}).catch(() => { });
|
|
1482
|
-
});
|
|
1483
|
-
// AI usage — daily call count
|
|
1484
|
-
electron_1.ipcMain.handle('ai:get-usage', async () => {
|
|
1485
|
-
try {
|
|
1486
|
-
const usage = await (0, ai_client_1.getAIUsage)();
|
|
1487
|
-
return { success: true, ...usage };
|
|
1488
|
-
}
|
|
1489
|
-
catch (error) {
|
|
1490
|
-
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
// Promo code redemption
|
|
1494
|
-
electron_1.ipcMain.handle('promo:redeem', async (_event, code) => {
|
|
1495
|
-
try {
|
|
1496
|
-
const redemption = await (0, ai_client_1.redeemPromoCode)(code);
|
|
1497
|
-
return { success: true, redemption };
|
|
1498
|
-
}
|
|
1499
|
-
catch (error) {
|
|
1500
|
-
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
1501
|
-
}
|
|
1502
|
-
});
|
|
1503
|
-
// Update shortcut
|
|
1504
|
-
electron_1.ipcMain.handle('settings:set-shortcut', async (_event, shortcut) => {
|
|
1505
|
-
try {
|
|
1506
|
-
const { updateShortcut } = require('./modules/hotkeys');
|
|
1507
|
-
const success = updateShortcut(shortcut, () => {
|
|
1508
|
-
if (!tryClaimSelectionUI())
|
|
1509
|
-
return;
|
|
1510
|
-
createSelectionWindow();
|
|
1511
|
-
});
|
|
1512
|
-
if (success) {
|
|
1513
|
-
(0, store_1.setSetting)('activationShortcut', shortcut);
|
|
1514
|
-
return { success: true };
|
|
1515
|
-
}
|
|
1516
|
-
return { success: false, error: 'Failed to register shortcut. It may conflict with another app.' };
|
|
1517
|
-
}
|
|
1518
|
-
catch (error) {
|
|
1519
|
-
return { success: false, error: String(error) };
|
|
1520
|
-
}
|
|
1521
|
-
});
|
|
1522
|
-
// Update multi-select shortcut
|
|
1523
|
-
electron_1.ipcMain.handle('settings:set-multi-shortcut', async (_event, shortcut) => {
|
|
1524
|
-
try {
|
|
1525
|
-
const { updateMultiShortcut } = require('./modules/hotkeys');
|
|
1526
|
-
const success = updateMultiShortcut(shortcut, () => {
|
|
1527
|
-
if (!tryClaimSelectionUI())
|
|
1528
|
-
return;
|
|
1529
|
-
createSelectionWindow({ mode: 'multi' });
|
|
1530
|
-
});
|
|
1531
|
-
if (success) {
|
|
1532
|
-
(0, store_1.setSetting)('multiSelectShortcut', shortcut);
|
|
1533
|
-
return { success: true };
|
|
1534
|
-
}
|
|
1535
|
-
return { success: false, error: 'Failed to register shortcut. It may conflict with another app.' };
|
|
1536
|
-
}
|
|
1537
|
-
catch (error) {
|
|
1538
|
-
return { success: false, error: String(error) };
|
|
1539
|
-
}
|
|
1540
|
-
});
|
|
1541
|
-
// Browse for screenshot folder
|
|
1542
|
-
electron_1.ipcMain.handle('settings:browse-folder', async () => {
|
|
1543
|
-
logger_1.default.info('[Settings] Browse folder dialog opening...');
|
|
1544
|
-
try {
|
|
1545
|
-
const result = await electron_1.dialog.showOpenDialog({
|
|
1546
|
-
properties: ['openDirectory'],
|
|
1547
|
-
title: 'Choose screenshot folder',
|
|
1548
|
-
});
|
|
1549
|
-
logger_1.default.info('[Settings] Dialog result:', result.canceled ? 'canceled' : result.filePaths);
|
|
1550
|
-
if (result.canceled || !result.filePaths.length)
|
|
1551
|
-
return { success: false };
|
|
1552
|
-
const folder = result.filePaths[0];
|
|
1553
|
-
(0, store_1.setSetting)('screenshotFolder', folder);
|
|
1554
|
-
logger_1.default.info('[Settings] Screenshot folder saved:', folder);
|
|
1555
|
-
logger_1.default.info('[Settings] Read back:', (0, store_1.getSetting)('screenshotFolder'));
|
|
1556
|
-
return { success: true, folder };
|
|
1557
|
-
}
|
|
1558
|
-
catch (error) {
|
|
1559
|
-
logger_1.default.error('[Settings] Browse dialog error:', error);
|
|
1560
|
-
return { success: false, error: String(error) };
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
// Set screenshot folder directly
|
|
1564
|
-
electron_1.ipcMain.handle('settings:set-generic', async (_event, data) => {
|
|
1565
|
-
(0, store_1.setSetting)(data.key, data.value);
|
|
1566
|
-
return { success: true };
|
|
1567
|
-
});
|
|
1568
|
-
electron_1.ipcMain.handle('settings:set-screenshot-folder', async (_event, folder) => {
|
|
1569
|
-
logger_1.default.info('[Settings] Setting screenshot folder to:', folder || '(default)');
|
|
1570
|
-
(0, store_1.setSetting)('screenshotFolder', folder);
|
|
1571
|
-
return { success: true };
|
|
1572
|
-
});
|
|
1573
|
-
// Scroll capture settings
|
|
1574
|
-
electron_1.ipcMain.handle('settings:set-scroll-capture', async (_event, settings) => {
|
|
1575
|
-
const current = (0, store_1.getSetting)('scrollCapture') || {};
|
|
1576
|
-
const updated = { ...current, ...settings };
|
|
1577
|
-
(0, store_1.setSetting)('scrollCapture', updated);
|
|
1578
|
-
// Re-register shortcut if it changed
|
|
1579
|
-
if (settings.shortcut && settings.shortcut !== current.shortcut) {
|
|
1580
|
-
electron_1.globalShortcut.unregister(current.shortcut || 'CommandOrControl+Shift+A');
|
|
1581
|
-
const success = electron_1.globalShortcut.register(settings.shortcut, () => {
|
|
1582
|
-
if (!tryClaimSelectionUI())
|
|
1583
|
-
return;
|
|
1584
|
-
scrollCaptureMode = true;
|
|
1585
|
-
createSelectionWindow();
|
|
1586
|
-
});
|
|
1587
|
-
if (!success)
|
|
1588
|
-
return { success: false, error: 'Failed to register shortcut' };
|
|
1589
|
-
}
|
|
1590
|
-
return { success: true };
|
|
1591
|
-
});
|
|
1592
|
-
// Calibrate scroll: hide settings, wait for user to position mouse on scrollable content, then measure
|
|
1593
|
-
electron_1.ipcMain.handle('settings:calibrate-scroll', async () => {
|
|
1594
|
-
try {
|
|
1595
|
-
// Hide main panel window so it's not in the way
|
|
1596
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
1597
|
-
mainPanelWindow.hide();
|
|
1598
|
-
}
|
|
1599
|
-
logger_1.default.info('[Calibrate] Settings hidden. Waiting 3s for user to position mouse over scrollable content...');
|
|
1600
|
-
// Show a native notification telling user what to do
|
|
1601
|
-
const { Notification } = require('electron');
|
|
1602
|
-
const notif = new Notification({
|
|
1603
|
-
title: 'Scroll Calibration',
|
|
1604
|
-
body: 'Move your mouse over scrollable content. Calibrating in 3 seconds...',
|
|
1605
|
-
silent: true,
|
|
1606
|
-
});
|
|
1607
|
-
notif.show();
|
|
1608
|
-
// Wait for user to move mouse to scrollable area
|
|
1609
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
1610
|
-
// Get current mouse position and create a region around it
|
|
1611
|
-
const mousePos = await nut_js_1.mouse.getPosition();
|
|
1612
|
-
logger_1.default.info(`[Calibrate] Mouse at: ${mousePos.x}, ${mousePos.y}`);
|
|
1613
|
-
const calRegion = {
|
|
1614
|
-
x: Math.max(0, mousePos.x - 200),
|
|
1615
|
-
y: Math.max(0, mousePos.y - 250),
|
|
1616
|
-
width: 400,
|
|
1617
|
-
height: 500,
|
|
1618
|
-
};
|
|
1619
|
-
const { calibrateScroll } = require('./modules/scroll-capture');
|
|
1620
|
-
const pixelsPerScroll = await calibrateScroll(calRegion);
|
|
1621
|
-
logger_1.default.info(`[Calibrate] Result: ${pixelsPerScroll} pixels per scroll unit`);
|
|
1622
|
-
// Save
|
|
1623
|
-
const current = (0, store_1.getSetting)('scrollCapture') || {};
|
|
1624
|
-
(0, store_1.setSetting)('scrollCapture', { ...current, pixelsPerScroll });
|
|
1625
|
-
// Show main panel window again
|
|
1626
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
1627
|
-
mainPanelWindow.show();
|
|
1628
|
-
}
|
|
1629
|
-
return { success: true, pixelsPerScroll };
|
|
1630
|
-
}
|
|
1631
|
-
catch (error) {
|
|
1632
|
-
logger_1.default.error('[Calibrate] Error:', error);
|
|
1633
|
-
// Show main panel window again on error
|
|
1634
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
1635
|
-
mainPanelWindow.show();
|
|
1636
|
-
}
|
|
1637
|
-
return { success: false, error: String(error) };
|
|
1638
|
-
}
|
|
1639
|
-
});
|
|
1640
|
-
// Inline edit: apply AI result to source app
|
|
1641
|
-
electron_1.ipcMain.handle('inline-edit:apply', async (_event, text) => {
|
|
1642
|
-
try {
|
|
1643
|
-
// Write AI response to clipboard
|
|
1644
|
-
(0, clipboard_1.writeClipboardText)(text);
|
|
1645
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1646
|
-
// Minimize overlay temporarily to give focus back to source app
|
|
1647
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
1648
|
-
overlayWindow.hide();
|
|
1649
|
-
}
|
|
1650
|
-
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
1651
|
-
// Simulate Ctrl+V to paste
|
|
1652
|
-
await (0, keystroke_1.simulatePaste)();
|
|
1653
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1654
|
-
// Show overlay again
|
|
1655
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
1656
|
-
overlayWindow.show();
|
|
1657
|
-
}
|
|
1658
|
-
return { success: true };
|
|
1659
|
-
}
|
|
1660
|
-
catch (error) {
|
|
1661
|
-
return { success: false, error: String(error) };
|
|
1662
|
-
}
|
|
1663
|
-
});
|
|
1664
|
-
// Inline edit: undo
|
|
1665
|
-
electron_1.ipcMain.handle('inline-edit:undo', async () => {
|
|
1666
|
-
try {
|
|
1667
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
1668
|
-
overlayWindow.hide();
|
|
1669
|
-
}
|
|
1670
|
-
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
1671
|
-
// Simulate Ctrl+Z in the source app
|
|
1672
|
-
await (0, keystroke_1.simulateUndo)();
|
|
1673
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1674
|
-
// Restore original clipboard
|
|
1675
|
-
(0, clipboard_1.restoreClipboardState)();
|
|
1676
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
1677
|
-
overlayWindow.show();
|
|
1678
|
-
}
|
|
1679
|
-
return { success: true };
|
|
1680
|
-
}
|
|
1681
|
-
catch (error) {
|
|
1682
|
-
return { success: false, error: String(error) };
|
|
1683
|
-
}
|
|
1684
|
-
});
|
|
1685
|
-
// Clipboard operations
|
|
1686
|
-
// Native file drag from overlay
|
|
1687
|
-
// Save edited image (overwrites original, or writes to new file if locked on Windows)
|
|
1688
|
-
electron_1.ipcMain.handle('overlay:save-edited-image', async (_event, data) => {
|
|
1689
|
-
logger_1.default.info('[Editor] save-edited-image called, path:', data.filepath, 'base64 length:', data.base64?.length);
|
|
1690
|
-
try {
|
|
1691
|
-
if (!isPathSafe(data.filepath)) {
|
|
1692
|
-
logger_1.default.warn('[Editor] isPathSafe REJECTED path:', data.filepath);
|
|
1693
|
-
return { success: false, error: 'Invalid file path' };
|
|
1694
|
-
}
|
|
1695
|
-
const buffer = Buffer.from(data.base64, 'base64');
|
|
1696
|
-
let savedPath = data.filepath;
|
|
1697
|
-
try {
|
|
1698
|
-
fs.writeFileSync(data.filepath, buffer);
|
|
1699
|
-
}
|
|
1700
|
-
catch (writeErr) {
|
|
1701
|
-
// On Windows, file may be locked by Chromium or other process.
|
|
1702
|
-
// Write to a sibling .edited.png file and update DB reference.
|
|
1703
|
-
const dir = path.dirname(data.filepath);
|
|
1704
|
-
const base = path.basename(data.filepath, path.extname(data.filepath));
|
|
1705
|
-
savedPath = path.join(dir, `${base}_edited.png`);
|
|
1706
|
-
logger_1.default.info('[Editor] Original locked, writing to:', savedPath);
|
|
1707
|
-
fs.writeFileSync(savedPath, buffer);
|
|
1708
|
-
// Update database record to point to the new file
|
|
1709
|
-
try {
|
|
1710
|
-
const { getDatabase } = require('./db/database');
|
|
1711
|
-
const db = getDatabase();
|
|
1712
|
-
db.prepare('UPDATE captures SET screenshot_path = ? WHERE screenshot_path = ?').run(savedPath, data.filepath);
|
|
1713
|
-
logger_1.default.info('[Editor] Updated DB screenshot_path:', data.filepath, '->', savedPath);
|
|
1714
|
-
}
|
|
1715
|
-
catch (dbErr) {
|
|
1716
|
-
logger_1.default.warn('[Editor] DB update failed (non-fatal):', dbErr);
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
logger_1.default.info('[Editor] Saved edited image:', savedPath, 'size:', buffer.length);
|
|
1720
|
-
// Invalidate thumbnail cache for both old and new paths
|
|
1721
|
-
thumbnailCache.delete(data.filepath);
|
|
1722
|
-
thumbnailCache.delete(savedPath);
|
|
1723
|
-
// Notify all windows that a capture was updated so thumbnails refresh
|
|
1724
|
-
for (const win of electron_1.BrowserWindow.getAllWindows()) {
|
|
1725
|
-
if (!win.isDestroyed()) {
|
|
1726
|
-
win.webContents.send('capture:updated', savedPath);
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
return { success: true };
|
|
1730
|
-
}
|
|
1731
|
-
catch (error) {
|
|
1732
|
-
logger_1.default.error('[Editor] save-edited-image FAILED:', error);
|
|
1733
|
-
return { success: false, error: String(error) };
|
|
1734
|
-
}
|
|
1735
|
-
});
|
|
1736
|
-
// Create temp annotated copies of images with note banners
|
|
1737
|
-
electron_1.ipcMain.handle('overlay:annotate-files', async (_event, filepaths, notesMap) => {
|
|
1738
|
-
const embedEnabled = (0, store_1.getSetting)('noteEmbedInImage') !== false;
|
|
1739
|
-
if (!embedEnabled)
|
|
1740
|
-
return { paths: filepaths };
|
|
1741
|
-
const tmpDir = electron_1.app.getPath('temp');
|
|
1742
|
-
const annotatedPaths = [];
|
|
1743
|
-
for (const fp of filepaths) {
|
|
1744
|
-
const note = notesMap[fp];
|
|
1745
|
-
if (note && fs.existsSync(fp)) {
|
|
1746
|
-
try {
|
|
1747
|
-
const sharp = require('sharp');
|
|
1748
|
-
const meta = await sharp(fp).metadata();
|
|
1749
|
-
const buf = fs.readFileSync(fp);
|
|
1750
|
-
const annotated = await overlayNoteOnImage(buf, note, meta.width || 800);
|
|
1751
|
-
const tmpPath = path.join(tmpDir, `sb-annotated-${Date.now()}-${path.basename(fp)}`);
|
|
1752
|
-
fs.writeFileSync(tmpPath, annotated);
|
|
1753
|
-
annotatedPaths.push(tmpPath);
|
|
1754
|
-
// Clean up after 2 minutes
|
|
1755
|
-
setTimeout(() => { try {
|
|
1756
|
-
fs.unlinkSync(tmpPath);
|
|
1757
|
-
}
|
|
1758
|
-
catch { } }, 120000);
|
|
1759
|
-
}
|
|
1760
|
-
catch {
|
|
1761
|
-
annotatedPaths.push(fp); // fallback to original
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
else {
|
|
1765
|
-
annotatedPaths.push(fp);
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
return { paths: annotatedPaths };
|
|
1769
|
-
});
|
|
1770
|
-
electron_1.ipcMain.on('overlay:start-drag', async (event, filepaths, notesMap) => {
|
|
1771
|
-
const validFiles = filepaths.filter((fp) => fs.existsSync(fp));
|
|
1772
|
-
if (validFiles.length === 0)
|
|
1773
|
-
return;
|
|
1774
|
-
const hasNotes = notesMap && Object.values(notesMap).some(Boolean);
|
|
1775
|
-
let dragFiles = validFiles;
|
|
1776
|
-
// Annotate files with note banners if embed is enabled
|
|
1777
|
-
if (hasNotes && (0, store_1.getSetting)('noteEmbedInImage') !== false) {
|
|
1778
|
-
const tmpDir = electron_1.app.getPath('temp');
|
|
1779
|
-
const annotated = [];
|
|
1780
|
-
for (const fp of validFiles) {
|
|
1781
|
-
const note = notesMap[fp];
|
|
1782
|
-
if (note) {
|
|
1783
|
-
try {
|
|
1784
|
-
const sharp = require('sharp');
|
|
1785
|
-
const meta = await sharp(fp).metadata();
|
|
1786
|
-
const buf = fs.readFileSync(fp);
|
|
1787
|
-
const result = await overlayNoteOnImage(buf, note, meta.width || 800);
|
|
1788
|
-
const tmpPath = path.join(tmpDir, `sb-drag-${Date.now()}-${path.basename(fp)}`);
|
|
1789
|
-
fs.writeFileSync(tmpPath, result);
|
|
1790
|
-
annotated.push(tmpPath);
|
|
1791
|
-
setTimeout(() => { try {
|
|
1792
|
-
fs.unlinkSync(tmpPath);
|
|
1793
|
-
}
|
|
1794
|
-
catch { } }, 120000);
|
|
1795
|
-
}
|
|
1796
|
-
catch {
|
|
1797
|
-
annotated.push(fp);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
else {
|
|
1801
|
-
annotated.push(fp);
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
dragFiles = annotated;
|
|
1805
|
-
}
|
|
1806
|
-
const icon = electron_1.nativeImage.createFromPath(validFiles[0]).resize({ width: 64, height: 64 });
|
|
1807
|
-
event.sender.startDrag({
|
|
1808
|
-
file: dragFiles[0],
|
|
1809
|
-
files: dragFiles,
|
|
1810
|
-
icon,
|
|
1811
|
-
});
|
|
1812
|
-
const allNotes = hasNotes ? filepaths.map((fp) => notesMap[fp]).filter(Boolean).join('\n\n') : '';
|
|
1813
|
-
logger_1.default.info('[Drag] Started native drag for', dragFiles.length, 'files', allNotes ? '(with notes)' : '');
|
|
1814
|
-
setPendingNotes(allNotes || null);
|
|
1815
|
-
});
|
|
1816
|
-
electron_1.ipcMain.handle('overlay:copy-screenshot', async (_event, filepath, clickPos, noteText) => {
|
|
1817
|
-
try {
|
|
1818
|
-
if (!fs.existsSync(filepath)) {
|
|
1819
|
-
return { success: false, error: 'File not found' };
|
|
1820
|
-
}
|
|
1821
|
-
let image = await loadImageForClipboard(filepath);
|
|
1822
|
-
if (image.isEmpty()) {
|
|
1823
|
-
return { success: false, error: 'Unsupported image format' };
|
|
1824
|
-
}
|
|
1825
|
-
// If click position provided and setting enabled, draw red circle indicator
|
|
1826
|
-
if (clickPos && clickPos.x !== undefined && clickPos.y !== undefined) {
|
|
1827
|
-
const recSettings = (0, store_1.getSetting)('recordingSettings');
|
|
1828
|
-
if (recSettings?.showClickIndicatorInCopy !== false) {
|
|
1829
|
-
image = drawClickIndicator(image, clickPos.x, clickPos.y);
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
if (noteText) {
|
|
1833
|
-
const embedEnabled = (0, store_1.getSetting)('noteEmbedInImage') !== false; // default true
|
|
1834
|
-
if (embedEnabled) {
|
|
1835
|
-
try {
|
|
1836
|
-
const pngBuf = image.toPNG();
|
|
1837
|
-
const size = image.getSize();
|
|
1838
|
-
const annotated = await overlayNoteOnImage(pngBuf, noteText, size.width);
|
|
1839
|
-
electron_1.clipboard.write({ image: electron_1.nativeImage.createFromBuffer(annotated), text: noteText });
|
|
1840
|
-
}
|
|
1841
|
-
catch (overlayErr) {
|
|
1842
|
-
logger_1.default.warn('[Copy] Note overlay failed:', overlayErr);
|
|
1843
|
-
electron_1.clipboard.write({ image, text: noteText });
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
else {
|
|
1847
|
-
electron_1.clipboard.write({ image, text: noteText });
|
|
1848
|
-
}
|
|
1849
|
-
setPendingNotes(noteText);
|
|
1850
|
-
}
|
|
1851
|
-
else {
|
|
1852
|
-
electron_1.clipboard.writeImage(image);
|
|
1853
|
-
setPendingNotes(null);
|
|
1854
|
-
}
|
|
1855
|
-
return { success: true };
|
|
1856
|
-
}
|
|
1857
|
-
catch (error) {
|
|
1858
|
-
logger_1.default.error('[Copy] copyScreenshot failed:', error);
|
|
1859
|
-
return { success: false, error: String(error) };
|
|
1860
|
-
}
|
|
1861
|
-
});
|
|
1862
|
-
// Copy multiple screenshots as a stitched composite image
|
|
1863
|
-
electron_1.ipcMain.handle('overlay:copy-multiple-screenshots', async (_event, filepaths, notesMap, direction) => {
|
|
1864
|
-
try {
|
|
1865
|
-
// Collect all notes for the selected screenshots
|
|
1866
|
-
const allNotes = notesMap
|
|
1867
|
-
? filepaths.map((fp) => notesMap[fp]).filter(Boolean).join('\n\n')
|
|
1868
|
-
: '';
|
|
1869
|
-
const embedEnabled = (0, store_1.getSetting)('noteEmbedInImage') !== false;
|
|
1870
|
-
// Helper: write image to clipboard, optionally with note overlay
|
|
1871
|
-
const writeImageWithNotes = async (imgBuf, width, notes) => {
|
|
1872
|
-
if (notes && embedEnabled) {
|
|
1873
|
-
try {
|
|
1874
|
-
const annotated = await overlayNoteOnImage(imgBuf, notes, width);
|
|
1875
|
-
electron_1.clipboard.write({ image: electron_1.nativeImage.createFromBuffer(annotated), text: notes });
|
|
1876
|
-
}
|
|
1877
|
-
catch {
|
|
1878
|
-
electron_1.clipboard.write({ image: electron_1.nativeImage.createFromBuffer(imgBuf), text: notes });
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
else if (notes) {
|
|
1882
|
-
electron_1.clipboard.write({ image: electron_1.nativeImage.createFromBuffer(imgBuf), text: notes });
|
|
1883
|
-
}
|
|
1884
|
-
else {
|
|
1885
|
-
electron_1.clipboard.writeImage(electron_1.nativeImage.createFromBuffer(imgBuf));
|
|
1886
|
-
}
|
|
1887
|
-
setPendingNotes(notes || null);
|
|
1888
|
-
};
|
|
1889
|
-
if (filepaths.length === 1) {
|
|
1890
|
-
const image = await loadImageForClipboard(filepaths[0]);
|
|
1891
|
-
const pngBuf = image.toPNG();
|
|
1892
|
-
const size = image.getSize();
|
|
1893
|
-
await writeImageWithNotes(pngBuf, size.width, allNotes);
|
|
1894
|
-
return { success: true };
|
|
1895
|
-
}
|
|
1896
|
-
const { composeScreenshots } = await Promise.resolve().then(() => __importStar(require('./modules/compose-screenshots')));
|
|
1897
|
-
const composed = await composeScreenshots(filepaths, direction || 'horizontal');
|
|
1898
|
-
await writeImageWithNotes(composed.buffer, composed.width, allNotes);
|
|
1899
|
-
return { success: true };
|
|
1900
|
-
}
|
|
1901
|
-
catch (error) {
|
|
1902
|
-
logger_1.default.error('[Copy] Merge failed:', error);
|
|
1903
|
-
return { success: false, error: String(error) };
|
|
1904
|
-
}
|
|
1905
|
-
});
|
|
1906
|
-
// Merge multiple screenshots into a single image file and return its path
|
|
1907
|
-
electron_1.ipcMain.handle('overlay:merge-to-file', async (_event, filepaths, direction) => {
|
|
1908
|
-
try {
|
|
1909
|
-
if (filepaths.length <= 1) {
|
|
1910
|
-
return { success: true, path: filepaths[0] };
|
|
1911
|
-
}
|
|
1912
|
-
const { composeScreenshots } = await Promise.resolve().then(() => __importStar(require('./modules/compose-screenshots')));
|
|
1913
|
-
const composed = await composeScreenshots(filepaths, direction || 'horizontal');
|
|
1914
|
-
const exportDir = getCapturesDir();
|
|
1915
|
-
ensureCapturesDir();
|
|
1916
|
-
const mergedPath = path.join(exportDir, `merged-${Date.now()}.png`);
|
|
1917
|
-
fs.writeFileSync(mergedPath, composed.buffer);
|
|
1918
|
-
return { success: true, path: mergedPath };
|
|
1919
|
-
}
|
|
1920
|
-
catch (err) {
|
|
1921
|
-
logger_1.default.error('[Copy] Merge-to-file failed:', err);
|
|
1922
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
1923
|
-
}
|
|
1924
|
-
});
|
|
1925
|
-
// Encode multiple screenshots into an animated GIF file and return its path.
|
|
1926
|
-
// Used by copy-gif, gif-to-file, gif-path sub-options in the copy dropdown.
|
|
1927
|
-
electron_1.ipcMain.handle('overlay:gif-to-file', async (_event, filepaths, speed) => {
|
|
1928
|
-
try {
|
|
1929
|
-
if (filepaths.length === 0) {
|
|
1930
|
-
return { success: false, error: 'No screenshots provided' };
|
|
1931
|
-
}
|
|
1932
|
-
const { composeGif } = await Promise.resolve().then(() => __importStar(require('./modules/gif-util')));
|
|
1933
|
-
const buffer = await composeGif(filepaths, { speed: speed || 'medium' });
|
|
1934
|
-
const exportDir = getCapturesDir();
|
|
1935
|
-
ensureCapturesDir();
|
|
1936
|
-
const gifPath = path.join(exportDir, `animation-${Date.now()}.gif`);
|
|
1937
|
-
fs.writeFileSync(gifPath, buffer);
|
|
1938
|
-
return { success: true, path: gifPath };
|
|
1939
|
-
}
|
|
1940
|
-
catch (err) {
|
|
1941
|
-
logger_1.default.error('[Copy] GIF encode failed:', err);
|
|
1942
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
1943
|
-
}
|
|
1944
|
-
});
|
|
1945
|
-
// Copy GIF to clipboard. On Windows/Linux, tries image/gif buffer directly.
|
|
1946
|
-
// On macOS (and as fallback everywhere), writes the GIF file and copies a
|
|
1947
|
-
// file reference so paste targets (Slack, chat apps, Finder) receive the animated GIF.
|
|
1948
|
-
electron_1.ipcMain.handle('overlay:copy-gif', async (_event, filepaths, speed) => {
|
|
1949
|
-
try {
|
|
1950
|
-
if (filepaths.length === 0) {
|
|
1951
|
-
return { success: false, error: 'No screenshots provided' };
|
|
1952
|
-
}
|
|
1953
|
-
const { composeGif } = await Promise.resolve().then(() => __importStar(require('./modules/gif-util')));
|
|
1954
|
-
const buffer = await composeGif(filepaths, { speed: speed || 'medium' });
|
|
1955
|
-
const exportDir = getCapturesDir();
|
|
1956
|
-
ensureCapturesDir();
|
|
1957
|
-
const gifPath = path.join(exportDir, `animation-${Date.now()}.gif`);
|
|
1958
|
-
fs.writeFileSync(gifPath, buffer);
|
|
1959
|
-
// Try direct GIF buffer on clipboard where supported (Windows/Linux).
|
|
1960
|
-
// NSPasteboard on macOS doesn't animate pasted GIFs, so prefer file ref.
|
|
1961
|
-
if (process.platform !== 'darwin') {
|
|
1962
|
-
try {
|
|
1963
|
-
electron_1.clipboard.writeBuffer('image/gif', buffer);
|
|
1964
|
-
return { success: true, path: gifPath };
|
|
1965
|
-
}
|
|
1966
|
-
catch (bufErr) {
|
|
1967
|
-
logger_1.default.warn('[Copy] clipboard.writeBuffer(image/gif) unsupported:', bufErr);
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
// Fallback: copy file reference (paste-as-file)
|
|
1971
|
-
const { execSync } = require('child_process');
|
|
1972
|
-
if (process.platform === 'darwin') {
|
|
1973
|
-
execSync(`osascript -e 'set the clipboard to POSIX file "${gifPath}"'`);
|
|
1974
|
-
}
|
|
1975
|
-
else if (process.platform === 'win32') {
|
|
1976
|
-
const psScript = `Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Clipboard]::SetFileDropList([string[]]@('${gifPath.replace(/'/g, "''")}'))`;
|
|
1977
|
-
execSync(`powershell -NoProfile -Command "${psScript.replace(/"/g, '\\"')}"`);
|
|
1978
|
-
}
|
|
1979
|
-
else {
|
|
1980
|
-
electron_1.clipboard.writeText(gifPath);
|
|
1981
|
-
}
|
|
1982
|
-
return { success: true, path: gifPath };
|
|
1983
|
-
}
|
|
1984
|
-
catch (err) {
|
|
1985
|
-
logger_1.default.error('[Copy] GIF copy failed:', err);
|
|
1986
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
1987
|
-
}
|
|
1988
|
-
});
|
|
1989
|
-
// Export screenshots to user's folder and copy file paths to clipboard
|
|
1990
|
-
// mode: 'files' = copy as file drop list, 'paths' = copy paths as text
|
|
1991
|
-
electron_1.ipcMain.handle('overlay:export-screenshots', async (_event, data) => {
|
|
1992
|
-
try {
|
|
1993
|
-
const { execSync } = require('child_process');
|
|
1994
|
-
// Step 1: Export/copy files to the user's screenshot folder
|
|
1995
|
-
const exportDir = getCapturesDir();
|
|
1996
|
-
ensureCapturesDir();
|
|
1997
|
-
const exportedPaths = [];
|
|
1998
|
-
for (const fp of data.filepaths) {
|
|
1999
|
-
const basename = path.basename(fp);
|
|
2000
|
-
const destPath = path.join(exportDir, basename);
|
|
2001
|
-
// If already in the target dir, use as-is
|
|
2002
|
-
if (path.normalize(fp) === path.normalize(destPath)) {
|
|
2003
|
-
exportedPaths.push(fp);
|
|
2004
|
-
}
|
|
2005
|
-
else {
|
|
2006
|
-
fs.copyFileSync(fp, destPath);
|
|
2007
|
-
exportedPaths.push(destPath);
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
// Write notes text file if any notes exist
|
|
2011
|
-
const notesMap = data.notesMap || {};
|
|
2012
|
-
const allNotes = data.filepaths
|
|
2013
|
-
.map((fp) => notesMap[fp])
|
|
2014
|
-
.filter(Boolean)
|
|
2015
|
-
.join('\n\n');
|
|
2016
|
-
let notesFilePath = null;
|
|
2017
|
-
if (allNotes) {
|
|
2018
|
-
notesFilePath = path.join(exportDir, `notes-${Date.now()}.txt`);
|
|
2019
|
-
fs.writeFileSync(notesFilePath, allNotes, 'utf-8');
|
|
2020
|
-
exportedPaths.push(notesFilePath);
|
|
2021
|
-
logger_1.default.info('[Export] Notes file written:', notesFilePath);
|
|
2022
|
-
}
|
|
2023
|
-
logger_1.default.info(`[Export] ${exportedPaths.length} files to ${exportDir}`);
|
|
2024
|
-
if (data.mode === 'paths') {
|
|
2025
|
-
// Step 2a: Copy paths as text
|
|
2026
|
-
electron_1.clipboard.writeText(exportedPaths.join('\n'));
|
|
2027
|
-
return { success: true, paths: exportedPaths };
|
|
2028
|
-
}
|
|
2029
|
-
// Step 2b: Copy as file drop list
|
|
2030
|
-
if (process.platform === 'win32') {
|
|
2031
|
-
// Windows: Write a .ps1 script, run with exec (async, non-blocking).
|
|
2032
|
-
// exec inherits parent's desktop/window station so clipboard access works.
|
|
2033
|
-
// Script sleeps after setting clipboard so the process stays alive as
|
|
2034
|
-
// clipboard owner long enough for the user to paste.
|
|
2035
|
-
const { exec: execAsync } = require('child_process');
|
|
2036
|
-
const tmpScript = path.join(electron_1.app.getPath('temp'), 'sb-copy-' + Date.now() + '.ps1');
|
|
2037
|
-
const psLines = [
|
|
2038
|
-
'Add-Type -AssemblyName System.Windows.Forms',
|
|
2039
|
-
];
|
|
2040
|
-
if (allNotes) {
|
|
2041
|
-
// Use DataObject to set both file list AND text on clipboard simultaneously
|
|
2042
|
-
psLines.push('$data = New-Object System.Windows.Forms.DataObject');
|
|
2043
|
-
psLines.push('$col = New-Object System.Collections.Specialized.StringCollection');
|
|
2044
|
-
// Only add image files to the file drop list (not the notes .txt)
|
|
2045
|
-
for (const fp of exportedPaths) {
|
|
2046
|
-
if (!fp.endsWith('.txt')) {
|
|
2047
|
-
psLines.push(`[void]$col.Add('${fp.replace(/'/g, "''")}')`);
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
psLines.push('$data.SetFileDropList($col)');
|
|
2051
|
-
psLines.push(`$data.SetText('${allNotes.replace(/'/g, "''").replace(/\r?\n/g, "`r`n")}')`);
|
|
2052
|
-
psLines.push('[System.Windows.Forms.Clipboard]::SetDataObject($data, $true)');
|
|
2053
|
-
}
|
|
2054
|
-
else {
|
|
2055
|
-
psLines.push('$col = New-Object System.Collections.Specialized.StringCollection');
|
|
2056
|
-
for (const fp of exportedPaths) {
|
|
2057
|
-
psLines.push(`[void]$col.Add('${fp.replace(/'/g, "''")}')`);
|
|
2058
|
-
}
|
|
2059
|
-
psLines.push('[System.Windows.Forms.Clipboard]::SetFileDropList($col)');
|
|
2060
|
-
}
|
|
2061
|
-
psLines.push('Start-Sleep -Seconds 5'); // Keep alive for 5s as clipboard owner
|
|
2062
|
-
fs.writeFileSync(tmpScript, psLines.join('\r\n'), 'utf8');
|
|
2063
|
-
logger_1.default.info('[Export] PS1 script written:', tmpScript);
|
|
2064
|
-
logger_1.default.info('[Export] Paths:', exportedPaths);
|
|
2065
|
-
// exec (not execSync) — runs in background, inherits desktop
|
|
2066
|
-
execAsync(`powershell.exe -NoProfile -STA -ExecutionPolicy Bypass -File "${tmpScript}"`, (err, _stdout, stderr) => {
|
|
2067
|
-
if (err)
|
|
2068
|
-
logger_1.default.error('[Export] PowerShell error:', stderr || err.message);
|
|
2069
|
-
else
|
|
2070
|
-
logger_1.default.info('[Export] PowerShell completed successfully');
|
|
2071
|
-
try {
|
|
2072
|
-
fs.unlinkSync(tmpScript);
|
|
2073
|
-
}
|
|
2074
|
-
catch { }
|
|
2075
|
-
});
|
|
2076
|
-
// Wait for clipboard to be set (PowerShell startup + Add-Type takes ~1s)
|
|
2077
|
-
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
2078
|
-
logger_1.default.info('[Export] Clipboard should be set for', exportedPaths.length, 'files');
|
|
2079
|
-
}
|
|
2080
|
-
else if (process.platform === 'darwin') {
|
|
2081
|
-
// Use NSPasteboard via AppleScript's ObjC bridge — this is the only
|
|
2082
|
-
// reliable way to set file URLs on the clipboard that macOS apps can paste
|
|
2083
|
-
const urlLines = exportedPaths
|
|
2084
|
-
.map((fp) => `set end of urlList to (current application's |NSURL|'s fileURLWithPath:"${fp}")`)
|
|
2085
|
-
.join('\n');
|
|
2086
|
-
const fullScript = [
|
|
2087
|
-
'use framework "AppKit"',
|
|
2088
|
-
'use scripting additions',
|
|
2089
|
-
'set urlList to {}',
|
|
2090
|
-
urlLines,
|
|
2091
|
-
'set pb to current application\'s NSPasteboard\'s generalPasteboard()',
|
|
2092
|
-
'pb\'s clearContents()',
|
|
2093
|
-
'pb\'s writeObjects:urlList',
|
|
2094
|
-
].join('\n');
|
|
2095
|
-
const tmpScpt = path.join(electron_1.app.getPath('temp'), 'sb-copy.applescript');
|
|
2096
|
-
fs.writeFileSync(tmpScpt, fullScript, 'utf-8');
|
|
2097
|
-
logger_1.default.info('[Export] AppleScript (NSPasteboard):', fullScript);
|
|
2098
|
-
execSync(`osascript "${tmpScpt}"`);
|
|
2099
|
-
try {
|
|
2100
|
-
fs.unlinkSync(tmpScpt);
|
|
2101
|
-
}
|
|
2102
|
-
catch { }
|
|
2103
|
-
}
|
|
2104
|
-
else {
|
|
2105
|
-
const { execFileSync } = require('child_process');
|
|
2106
|
-
const uriList = exportedPaths.map((fp) => `file://${fp}`).join('\n');
|
|
2107
|
-
execFileSync('xclip', ['-selection', 'clipboard', '-t', 'text/uri-list'], {
|
|
2108
|
-
input: uriList,
|
|
2109
|
-
timeout: 5000,
|
|
2110
|
-
});
|
|
2111
|
-
}
|
|
2112
|
-
// Register global shortcut for pasting notes
|
|
2113
|
-
setPendingNotes(allNotes || null);
|
|
2114
|
-
return { success: true, paths: exportedPaths };
|
|
2115
|
-
}
|
|
2116
|
-
catch (error) {
|
|
2117
|
-
logger_1.default.error('[Export] Failed:', error);
|
|
2118
|
-
return { success: false, error: String(error) };
|
|
2119
|
-
}
|
|
2120
|
-
});
|
|
2121
|
-
electron_1.ipcMain.handle('overlay:copy-text', async (_event, text) => {
|
|
2122
|
-
try {
|
|
2123
|
-
electron_1.clipboard.writeText(text);
|
|
2124
|
-
return { success: true };
|
|
2125
|
-
}
|
|
2126
|
-
catch (error) {
|
|
2127
|
-
return { success: false, error: String(error) };
|
|
2128
|
-
}
|
|
2129
|
-
});
|
|
2130
|
-
electron_1.ipcMain.handle('overlay:hide', async () => {
|
|
2131
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
2132
|
-
overlayWindow.close();
|
|
2133
|
-
}
|
|
2134
|
-
return { success: true };
|
|
2135
|
-
});
|
|
2136
|
-
// Overlay pin toggle
|
|
2137
|
-
electron_1.ipcMain.handle('overlay:pin', async () => {
|
|
2138
|
-
overlayPinned = !overlayPinned;
|
|
2139
|
-
return { success: true, pinned: overlayPinned };
|
|
2140
|
-
});
|
|
2141
|
-
// Overlay minimize to PIP
|
|
2142
|
-
electron_1.ipcMain.handle('overlay:minimize-pip', async () => {
|
|
2143
|
-
if (overlayWindow && !overlayWindow.isDestroyed()) {
|
|
2144
|
-
const bounds = overlayWindow.getBounds();
|
|
2145
|
-
overlayOriginalBounds = { width: bounds.width, height: bounds.height, x: bounds.x, y: bounds.y };
|
|
2146
|
-
overlayWindow.setBounds({ x: bounds.x, y: bounds.y, width: 120, height: 40 });
|
|
2147
|
-
overlayWindow.setResizable(false);
|
|
2148
|
-
}
|
|
2149
|
-
return { success: true };
|
|
2150
|
-
});
|
|
2151
|
-
// Overlay restore from PIP
|
|
2152
|
-
electron_1.ipcMain.handle('overlay:restore-pip', async () => {
|
|
2153
|
-
if (overlayWindow && !overlayWindow.isDestroyed() && overlayOriginalBounds) {
|
|
2154
|
-
overlayWindow.setBounds(overlayOriginalBounds);
|
|
2155
|
-
overlayWindow.setResizable(true);
|
|
2156
|
-
overlayOriginalBounds = null;
|
|
2157
|
-
}
|
|
2158
|
-
return { success: true };
|
|
2159
|
-
});
|
|
2160
|
-
// Dock overlay to screen edge
|
|
2161
|
-
electron_1.ipcMain.handle('overlay:dock', async (_event, side) => {
|
|
2162
|
-
if (!overlayWindow || overlayWindow.isDestroyed())
|
|
2163
|
-
return { success: false };
|
|
2164
|
-
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
|
|
2165
|
-
const { width: screenW, height: screenH } = primaryDisplay.size;
|
|
2166
|
-
const dockWidth = 420;
|
|
2167
|
-
if (side === 'undock') {
|
|
2168
|
-
// Restore saved bounds or center
|
|
2169
|
-
const saved = (0, store_1.getSetting)('overlayBounds');
|
|
2170
|
-
if (saved) {
|
|
2171
|
-
overlayWindow.setBounds(saved);
|
|
2172
|
-
}
|
|
2173
|
-
else {
|
|
2174
|
-
overlayWindow.setBounds({ x: Math.round(screenW / 2 - 260), y: 40, width: 520, height: 560 });
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
else {
|
|
2178
|
-
const x = side === 'left' ? 0 : screenW - dockWidth;
|
|
2179
|
-
overlayWindow.setBounds({ x, y: 0, width: dockWidth, height: screenH });
|
|
2180
|
-
}
|
|
2181
|
-
return { success: true, side };
|
|
2182
|
-
});
|
|
2183
|
-
// Pin to desktop
|
|
2184
|
-
electron_1.ipcMain.handle('capture:pin-to-desktop', async (_event, imagePath) => {
|
|
2185
|
-
if (!isPathSafe(imagePath)) {
|
|
2186
|
-
return { success: false, error: 'Invalid file path' };
|
|
2187
|
-
}
|
|
2188
|
-
(0, pin_window_1.pinToDesktop)(imagePath);
|
|
2189
|
-
return { success: true };
|
|
2190
|
-
});
|
|
2191
|
-
// Auto-redact an image on disk (manual trigger from renderer)
|
|
2192
|
-
electron_1.ipcMain.handle('redact:auto-redact', async (_event, data) => {
|
|
2193
|
-
try {
|
|
2194
|
-
if (!isPathSafe(data.imagePath))
|
|
2195
|
-
return { success: false, error: 'Invalid path' };
|
|
2196
|
-
const imageBuffer = fs.readFileSync(data.imagePath);
|
|
2197
|
-
const result = await (0, redact_1.autoRedact)(imageBuffer, { secrets: data.secrets, pii: data.pii });
|
|
2198
|
-
if (result.regionsFound > 0) {
|
|
2199
|
-
fs.writeFileSync(data.imagePath, result.buffer);
|
|
2200
|
-
}
|
|
2201
|
-
return { success: true, regionsFound: result.regionsFound };
|
|
2202
|
-
}
|
|
2203
|
-
catch (err) {
|
|
2204
|
-
logger_1.default.error('[Redact] Manual redact failed:', err);
|
|
2205
|
-
return { success: false, error: String(err) };
|
|
2206
|
-
}
|
|
2207
|
-
});
|
|
2208
|
-
// Export as different formats
|
|
2209
|
-
electron_1.ipcMain.handle('capture:export-format', async (_event, data) => {
|
|
2210
|
-
try {
|
|
2211
|
-
if (!isPathSafe(data.imagePath)) {
|
|
2212
|
-
return { success: false, error: 'Invalid file path' };
|
|
2213
|
-
}
|
|
2214
|
-
const sharp = require('sharp');
|
|
2215
|
-
const buf = fs.readFileSync(data.imagePath);
|
|
2216
|
-
const outputPath = data.imagePath.replace(/\.png$/i, `.${data.format}`);
|
|
2217
|
-
if (data.format === 'jpeg') {
|
|
2218
|
-
await sharp(buf).jpeg({ quality: data.quality }).toFile(outputPath);
|
|
2219
|
-
}
|
|
2220
|
-
else {
|
|
2221
|
-
await sharp(buf).webp({ quality: data.quality }).toFile(outputPath);
|
|
2222
|
-
}
|
|
2223
|
-
return { success: true, outputPath };
|
|
2224
|
-
}
|
|
2225
|
-
catch (err) {
|
|
2226
|
-
return { success: false, error: err.message };
|
|
2227
|
-
}
|
|
2228
|
-
});
|
|
2229
|
-
// Share: Imgur anonymous upload
|
|
2230
|
-
electron_1.ipcMain.handle('share:imgur-upload', async (_event, imagePath) => {
|
|
2231
|
-
try {
|
|
2232
|
-
if (!isPathSafe(imagePath)) {
|
|
2233
|
-
return { success: false, error: 'Invalid file path' };
|
|
2234
|
-
}
|
|
2235
|
-
const imageBuffer = fs.readFileSync(imagePath);
|
|
2236
|
-
const base64 = imageBuffer.toString('base64');
|
|
2237
|
-
const https = require('https');
|
|
2238
|
-
const result = await new Promise((resolve, reject) => {
|
|
2239
|
-
const postData = JSON.stringify({ image: base64, type: 'base64' });
|
|
2240
|
-
const req = https.request({
|
|
2241
|
-
hostname: 'api.imgur.com',
|
|
2242
|
-
path: '/3/image',
|
|
2243
|
-
method: 'POST',
|
|
2244
|
-
headers: {
|
|
2245
|
-
Authorization: 'Client-ID 546c25a59c58ad7',
|
|
2246
|
-
'Content-Type': 'application/json',
|
|
2247
|
-
'Content-Length': Buffer.byteLength(postData),
|
|
2248
|
-
},
|
|
2249
|
-
}, (res) => {
|
|
2250
|
-
let body = '';
|
|
2251
|
-
res.on('data', (chunk) => {
|
|
2252
|
-
body += chunk;
|
|
2253
|
-
});
|
|
2254
|
-
res.on('end', () => {
|
|
2255
|
-
try {
|
|
2256
|
-
const json = JSON.parse(body);
|
|
2257
|
-
if (json.success) {
|
|
2258
|
-
resolve({ url: json.data.link, deleteHash: json.data.deletehash });
|
|
2259
|
-
}
|
|
2260
|
-
else {
|
|
2261
|
-
reject(new Error(json.data?.error || 'Upload failed'));
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
catch {
|
|
2265
|
-
reject(new Error('Invalid response'));
|
|
2266
|
-
}
|
|
2267
|
-
});
|
|
2268
|
-
});
|
|
2269
|
-
req.on('error', reject);
|
|
2270
|
-
req.write(postData);
|
|
2271
|
-
req.end();
|
|
2272
|
-
});
|
|
2273
|
-
// Copy URL to clipboard
|
|
2274
|
-
electron_1.clipboard.writeText(result.url);
|
|
2275
|
-
return { success: true, url: result.url };
|
|
2276
|
-
}
|
|
2277
|
-
catch (err) {
|
|
2278
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
2279
|
-
}
|
|
2280
|
-
});
|
|
2281
|
-
// Share: System share dialog (Windows)
|
|
2282
|
-
electron_1.ipcMain.handle('share:system', async (_event, imagePath) => {
|
|
2283
|
-
try {
|
|
2284
|
-
if (!isPathSafe(imagePath)) {
|
|
2285
|
-
return { success: false, error: 'Invalid file path' };
|
|
2286
|
-
}
|
|
2287
|
-
const { shell } = require('electron');
|
|
2288
|
-
// On Windows, open the file with the system "Share" action
|
|
2289
|
-
await shell.openPath(imagePath);
|
|
2290
|
-
return { success: true };
|
|
2291
|
-
}
|
|
2292
|
-
catch (err) {
|
|
2293
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
2294
|
-
}
|
|
2295
|
-
});
|
|
2296
|
-
// Show file in OS file manager (Finder on macOS, Explorer on Windows)
|
|
2297
|
-
electron_1.ipcMain.handle('shell:show-in-folder', async (_event, filepath) => {
|
|
2298
|
-
try {
|
|
2299
|
-
if (!isPathSafe(filepath)) {
|
|
2300
|
-
return { success: false, error: 'Invalid file path' };
|
|
2301
|
-
}
|
|
2302
|
-
const { shell } = require('electron');
|
|
2303
|
-
shell.showItemInFolder(filepath);
|
|
2304
|
-
return { success: true };
|
|
2305
|
-
}
|
|
2306
|
-
catch (err) {
|
|
2307
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
2308
|
-
}
|
|
2309
|
-
});
|
|
2310
|
-
// Thumbnail cache: generate 256px thumbnails for gallery
|
|
2311
|
-
// thumbnailCache is declared at module level above
|
|
2312
|
-
electron_1.ipcMain.handle('capture:get-thumbnail', async (_event, imagePath) => {
|
|
2313
|
-
if (!isPathSafe(imagePath)) {
|
|
2314
|
-
return { success: false, error: 'Invalid file path' };
|
|
2315
|
-
}
|
|
2316
|
-
if (thumbnailCache.has(imagePath)) {
|
|
2317
|
-
return { success: true, dataUrl: thumbnailCache.get(imagePath) };
|
|
2318
|
-
}
|
|
2319
|
-
try {
|
|
2320
|
-
const sharp = require('sharp');
|
|
2321
|
-
const buf = await sharp(imagePath).resize(256, 256, { fit: 'inside' }).png({ quality: 60 }).toBuffer();
|
|
2322
|
-
const dataUrl = `data:image/png;base64,${buf.toString('base64')}`;
|
|
2323
|
-
thumbnailCache.set(imagePath, dataUrl);
|
|
2324
|
-
return { success: true, dataUrl };
|
|
2325
|
-
}
|
|
2326
|
-
catch {
|
|
2327
|
-
return { success: false };
|
|
2328
|
-
}
|
|
2329
|
-
});
|
|
2330
|
-
// PDF export
|
|
2331
|
-
electron_1.ipcMain.handle('capture:export-pdf', async (_event, data) => {
|
|
2332
|
-
try {
|
|
2333
|
-
if (!isPathSafe(data.imagePath)) {
|
|
2334
|
-
return { success: false, error: 'Invalid file path' };
|
|
2335
|
-
}
|
|
2336
|
-
const PDFDocument = require('pdfkit');
|
|
2337
|
-
const outputPath = data.imagePath.replace(/\.png$/i, '.pdf');
|
|
2338
|
-
return new Promise((resolve) => {
|
|
2339
|
-
const doc = new PDFDocument({ autoFirstPage: false });
|
|
2340
|
-
const stream = fs.createWriteStream(outputPath);
|
|
2341
|
-
doc.pipe(stream);
|
|
2342
|
-
// Get image dimensions
|
|
2343
|
-
const sharp = require('sharp');
|
|
2344
|
-
sharp(data.imagePath)
|
|
2345
|
-
.metadata()
|
|
2346
|
-
.then((meta) => {
|
|
2347
|
-
const imgW = meta.width || 800;
|
|
2348
|
-
const imgH = meta.height || 600;
|
|
2349
|
-
const pageW = 612; // Letter width in points
|
|
2350
|
-
const margin = 36;
|
|
2351
|
-
const contentW = pageW - margin * 2;
|
|
2352
|
-
const scale = Math.min(1, contentW / imgW);
|
|
2353
|
-
const displayW = imgW * scale;
|
|
2354
|
-
const displayH = imgH * scale;
|
|
2355
|
-
// Calculate page height needed
|
|
2356
|
-
const textHeight = data.aiResponse ? Math.ceil(data.aiResponse.length / 80) * 14 + 40 : 0;
|
|
2357
|
-
const pageH = Math.max(792, displayH + textHeight + margin * 3);
|
|
2358
|
-
doc.addPage({ size: [pageW, pageH], margin });
|
|
2359
|
-
// Title
|
|
2360
|
-
doc
|
|
2361
|
-
.fontSize(10)
|
|
2362
|
-
.fillColor('#666')
|
|
2363
|
-
.text(`SuperBased Capture — ${new Date().toLocaleString()}`, margin, margin);
|
|
2364
|
-
// Image
|
|
2365
|
-
doc.image(data.imagePath, margin, margin + 20, { width: displayW });
|
|
2366
|
-
// AI response
|
|
2367
|
-
if (data.aiResponse) {
|
|
2368
|
-
const textY = margin + 20 + displayH + 20;
|
|
2369
|
-
doc.fontSize(9).fillColor('#999').text('AI Response:', margin, textY);
|
|
2370
|
-
doc
|
|
2371
|
-
.fontSize(11)
|
|
2372
|
-
.fillColor('#333')
|
|
2373
|
-
.text(data.aiResponse, margin, textY + 14, {
|
|
2374
|
-
width: contentW,
|
|
2375
|
-
lineGap: 3,
|
|
2376
|
-
});
|
|
2377
|
-
}
|
|
2378
|
-
doc.end();
|
|
2379
|
-
stream.on('finish', () => resolve({ success: true, outputPath }));
|
|
2380
|
-
stream.on('error', (err) => resolve({ success: false, error: err.message }));
|
|
2381
|
-
})
|
|
2382
|
-
.catch((err) => resolve({ success: false, error: err.message }));
|
|
2383
|
-
});
|
|
2384
|
-
}
|
|
2385
|
-
catch (err) {
|
|
2386
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
2387
|
-
}
|
|
2388
|
-
});
|
|
2389
|
-
// Updater
|
|
2390
|
-
electron_1.ipcMain.handle('updater:check', async () => {
|
|
2391
|
-
try {
|
|
2392
|
-
await (0, updater_1.checkForUpdates)();
|
|
2393
|
-
return { success: true };
|
|
2394
|
-
}
|
|
2395
|
-
catch (error) {
|
|
2396
|
-
return { success: false, error: String(error) };
|
|
2397
|
-
}
|
|
2398
|
-
});
|
|
2399
|
-
electron_1.ipcMain.handle('updater:install', async () => {
|
|
2400
|
-
(0, updater_1.installUpdate)();
|
|
2401
|
-
return { success: true };
|
|
2402
|
-
});
|
|
2403
|
-
// Settings operations
|
|
2404
|
-
electron_1.ipcMain.handle('settings:get-all', async () => {
|
|
2405
|
-
return { ...(0, store_1.getAllSettings)(), appVersion: electron_1.app.getVersion() };
|
|
2406
|
-
});
|
|
2407
|
-
// Phase 7.1 — schema-driven renderer. Serializer resolves platformDefaults
|
|
2408
|
-
// to the current OS and drops internal/exposed:false fields. Renderer
|
|
2409
|
-
// mirrors validation locally; writes still round-trip through
|
|
2410
|
-
// `settings:set-generic` or a specialized setter.
|
|
2411
|
-
electron_1.ipcMain.handle('settings:get-schema', async () => {
|
|
2412
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
2413
|
-
const { serializeSchema } = require('./core/serialize-schema');
|
|
2414
|
-
return serializeSchema('ui');
|
|
2415
|
-
});
|
|
2416
|
-
// AI provider/model/key settings are managed via admin console only — not exposed to renderer
|
|
2417
|
-
electron_1.ipcMain.handle('settings:open', async () => {
|
|
2418
|
-
openMainPanelSettings();
|
|
2419
|
-
return { success: true };
|
|
2420
|
-
});
|
|
2421
|
-
// Phase 7.3 — deep link into a specific Settings category. Opens the main
|
|
2422
|
-
// panel to the Settings page, then fires `settings:navigate-to-category`
|
|
2423
|
-
// so the renderer's SettingsPage can setActive(category). Used by the Help
|
|
2424
|
-
// page "Open Settings to X" buttons and by the 7.2 tray status items.
|
|
2425
|
-
electron_1.ipcMain.handle('settings:open-to-category', async (_event, category) => {
|
|
2426
|
-
openMainPanelSettings();
|
|
2427
|
-
const sendCategory = () => {
|
|
2428
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
2429
|
-
mainPanelWindow.webContents.send('settings:navigate-to-category', category);
|
|
2430
|
-
}
|
|
2431
|
-
};
|
|
2432
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed() && mainPanelWindow.webContents.isLoading()) {
|
|
2433
|
-
mainPanelWindow.webContents.once('did-finish-load', sendCategory);
|
|
2434
|
-
}
|
|
2435
|
-
else {
|
|
2436
|
-
// Small delay so the renderer's settings page is mounted and listening.
|
|
2437
|
-
setTimeout(sendCategory, 100);
|
|
2438
|
-
}
|
|
2439
|
-
return { success: true };
|
|
2440
|
-
});
|
|
2441
|
-
// Database operations
|
|
2442
|
-
electron_1.ipcMain.handle('db:get-captures', async (_event, limit) => {
|
|
2443
|
-
return (0, database_1.getCaptures)(limit);
|
|
2444
|
-
});
|
|
2445
|
-
electron_1.ipcMain.handle('db:get-capture', async (_event, id) => {
|
|
2446
|
-
return (0, database_1.getCapture)(id);
|
|
2447
|
-
});
|
|
2448
|
-
electron_1.ipcMain.handle('db:search-captures', async (_event, query) => {
|
|
2449
|
-
return (0, database_1.searchCaptures)(query);
|
|
2450
|
-
});
|
|
2451
|
-
electron_1.ipcMain.handle('db:update-tags', async (_event, data) => {
|
|
2452
|
-
(0, database_1.updateCaptureTags)(data.id, data.tags);
|
|
2453
|
-
return { success: true };
|
|
2454
|
-
});
|
|
2455
|
-
electron_1.ipcMain.handle('db:update-notes', async (_event, data) => {
|
|
2456
|
-
(0, database_1.updateCaptureNotes)(data.id, data.notes);
|
|
2457
|
-
return { success: true };
|
|
2458
|
-
});
|
|
2459
|
-
electron_1.ipcMain.handle('db:get-stats', async () => {
|
|
2460
|
-
return (0, database_1.getCaptureStats)();
|
|
2461
|
-
});
|
|
2462
|
-
// ── Analytics ──
|
|
2463
|
-
electron_1.ipcMain.handle('analytics:get-summary', async () => {
|
|
2464
|
-
const { getAnalyticsSummary } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
2465
|
-
return getAnalyticsSummary();
|
|
2466
|
-
});
|
|
2467
|
-
electron_1.ipcMain.handle('analytics:get-summary-range', async (_event, startDate, endDate) => {
|
|
2468
|
-
const { getAnalyticsSummaryRange } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
2469
|
-
return getAnalyticsSummaryRange(startDate, endDate);
|
|
2470
|
-
});
|
|
2471
|
-
electron_1.ipcMain.handle('analytics:get-trend', async (_event, eventType, granularity, count) => {
|
|
2472
|
-
const db = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
2473
|
-
switch (granularity) {
|
|
2474
|
-
case 'hourly': return db.getHourlyTrend(eventType, count);
|
|
2475
|
-
case 'daily': return db.getDailyTrend(eventType, count);
|
|
2476
|
-
case 'weekly': return db.getWeeklyTrend(eventType, count);
|
|
2477
|
-
case 'monthly': return db.getMonthlyTrend(eventType, count);
|
|
2478
|
-
default: return db.getDailyTrend(eventType, count);
|
|
2479
|
-
}
|
|
2480
|
-
});
|
|
2481
|
-
electron_1.ipcMain.handle('analytics:get-top', async (_event, eventType, startDate, endDate, limit) => {
|
|
2482
|
-
const { getAnalyticsTopValues } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
2483
|
-
return getAnalyticsTopValues(eventType, startDate, endDate, limit);
|
|
2484
|
-
});
|
|
2485
|
-
// ── Token Compression Engine ──
|
|
2486
|
-
electron_1.ipcMain.handle('tce:quick-analyze', async (_event, text, settings) => {
|
|
2487
|
-
const { quickAnalyze } = await Promise.resolve().then(() => __importStar(require('./modules/tce')));
|
|
2488
|
-
return quickAnalyze(text, settings);
|
|
2489
|
-
});
|
|
2490
|
-
electron_1.ipcMain.handle('tce:compress', async (_event, text, settings) => {
|
|
2491
|
-
const { compressText } = await Promise.resolve().then(() => __importStar(require('./modules/tce')));
|
|
2492
|
-
const result = await compressText(text, settings);
|
|
2493
|
-
// Convert buffers to base64 for IPC transfer
|
|
2494
|
-
return {
|
|
2495
|
-
pages: result.pages.map((p) => ({
|
|
2496
|
-
pageNumber: p.pageNumber,
|
|
2497
|
-
totalPages: p.totalPages,
|
|
2498
|
-
imageTokens: p.imageTokens,
|
|
2499
|
-
lineRange: p.lineRange,
|
|
2500
|
-
base64: p.buffer.toString('base64'),
|
|
2501
|
-
})),
|
|
2502
|
-
metadata: result.metadata,
|
|
2503
|
-
};
|
|
2504
|
-
});
|
|
2505
|
-
// Preset operations
|
|
2506
|
-
electron_1.ipcMain.handle('presets:get-all', async () => {
|
|
2507
|
-
return (0, database_1.getPresets)();
|
|
2508
|
-
});
|
|
2509
|
-
electron_1.ipcMain.handle('presets:create', async (_event, data) => {
|
|
2510
|
-
const id = (0, database_1.createPreset)(data);
|
|
2511
|
-
return { success: true, id };
|
|
2512
|
-
});
|
|
2513
|
-
electron_1.ipcMain.handle('presets:update', async (_event, data) => {
|
|
2514
|
-
(0, database_1.updatePreset)(data);
|
|
2515
|
-
return { success: true };
|
|
2516
|
-
});
|
|
2517
|
-
electron_1.ipcMain.handle('presets:delete', async (_event, id) => {
|
|
2518
|
-
(0, database_1.deletePreset)(id);
|
|
2519
|
-
return { success: true };
|
|
2520
|
-
});
|
|
2521
|
-
// Gallery
|
|
2522
|
-
electron_1.ipcMain.handle('gallery:open', async () => {
|
|
2523
|
-
createGalleryWindow();
|
|
2524
|
-
return { success: true };
|
|
2525
|
-
});
|
|
2526
|
-
electron_1.ipcMain.handle('capture:start-region', async () => {
|
|
2527
|
-
if (!tryClaimSelectionUI())
|
|
2528
|
-
return { success: false };
|
|
2529
|
-
createSelectionWindow();
|
|
2530
|
-
return { success: true };
|
|
2531
|
-
});
|
|
2532
|
-
// Re-process: open overlay with existing capture
|
|
2533
|
-
electron_1.ipcMain.handle('capture:reprocess', async (_event, captureId) => {
|
|
2534
|
-
const capture = (0, database_1.getCapture)(captureId);
|
|
2535
|
-
if (!capture)
|
|
2536
|
-
return { success: false, error: 'Capture not found' };
|
|
2537
|
-
const region = {
|
|
2538
|
-
x: capture.region_x,
|
|
2539
|
-
y: capture.region_y,
|
|
2540
|
-
width: capture.region_w,
|
|
2541
|
-
height: capture.region_h,
|
|
2542
|
-
};
|
|
2543
|
-
createOverlayWindow({
|
|
2544
|
-
screenshotPath: capture.screenshot_path,
|
|
2545
|
-
captureId,
|
|
2546
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
2547
|
-
voiceMode: false,
|
|
2548
|
-
inlineEditMode: false,
|
|
2549
|
-
originalText: null,
|
|
2550
|
-
multiRegion: false,
|
|
2551
|
-
regionScreenshots: [],
|
|
2552
|
-
}, region);
|
|
2553
|
-
return { success: true };
|
|
2554
|
-
});
|
|
2555
|
-
// View: open editor in a separate window for a screenshot
|
|
2556
|
-
electron_1.ipcMain.handle('capture:view', async (_event, screenshotPath, clickPos, siblingPaths) => {
|
|
2557
|
-
logger_1.default.info('[Editor] capture:view called, path:', screenshotPath, 'clickPos:', clickPos);
|
|
2558
|
-
if (!isPathSafe(screenshotPath)) {
|
|
2559
|
-
logger_1.default.warn('[Editor] capture:view path rejected by isPathSafe:', screenshotPath);
|
|
2560
|
-
return { success: false, error: 'Invalid path' };
|
|
2561
|
-
}
|
|
2562
|
-
// If click position provided and setting enabled, create temp file with indicator baked in
|
|
2563
|
-
let pathForEditor = screenshotPath;
|
|
2564
|
-
if (clickPos && clickPos.x !== undefined && clickPos.y !== undefined) {
|
|
2565
|
-
const recSettings = (0, store_1.getSetting)('recordingSettings');
|
|
2566
|
-
if (recSettings?.showClickIndicatorInCopy !== false) {
|
|
2567
|
-
try {
|
|
2568
|
-
let image = await loadImageForClipboard(screenshotPath);
|
|
2569
|
-
if (!image.isEmpty()) {
|
|
2570
|
-
image = drawClickIndicator(image, clickPos.x, clickPos.y);
|
|
2571
|
-
const tmpDir = path.join(electron_1.app.getPath('temp'), 'superbased-editor');
|
|
2572
|
-
if (!fs.existsSync(tmpDir))
|
|
2573
|
-
fs.mkdirSync(tmpDir, { recursive: true });
|
|
2574
|
-
const tmpPath = path.join(tmpDir, `click_${Date.now()}.png`);
|
|
2575
|
-
fs.writeFileSync(tmpPath, image.toPNG());
|
|
2576
|
-
pathForEditor = tmpPath;
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
catch (err) {
|
|
2580
|
-
logger_1.default.warn('[Editor] Failed to draw click indicator:', err);
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
const editorWin = new electron_1.BrowserWindow({
|
|
2585
|
-
width: 900,
|
|
2586
|
-
height: 650,
|
|
2587
|
-
...framelessWindowOptions(),
|
|
2588
|
-
webPreferences: {
|
|
2589
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
2590
|
-
contextIsolation: true,
|
|
2591
|
-
nodeIntegration: false,
|
|
2592
|
-
navigateOnDragDrop: false,
|
|
2593
|
-
},
|
|
2594
|
-
});
|
|
2595
|
-
makeWindowFocusAware(editorWin);
|
|
2596
|
-
attachCrashHandlers(editorWin, 'editor');
|
|
2597
|
-
editorWin.loadFile(path.join(__dirname, '../renderer/editor.html'));
|
|
2598
|
-
editorWin.webContents.on('did-finish-load', () => {
|
|
2599
|
-
logger_1.default.info('[Editor] Sending init: display=', pathForEditor, 'savePath=', screenshotPath);
|
|
2600
|
-
editorWin.webContents.send('overlay:init', {
|
|
2601
|
-
screenshotPath: pathForEditor,
|
|
2602
|
-
savePath: screenshotPath,
|
|
2603
|
-
siblingPaths: siblingPaths || [],
|
|
2604
|
-
});
|
|
2605
|
-
});
|
|
2606
|
-
// Clean up temp file when editor closes
|
|
2607
|
-
if (pathForEditor !== screenshotPath) {
|
|
2608
|
-
editorWin.on('closed', () => {
|
|
2609
|
-
try {
|
|
2610
|
-
fs.unlinkSync(pathForEditor);
|
|
2611
|
-
}
|
|
2612
|
-
catch { /* already cleaned */ }
|
|
2613
|
-
});
|
|
2614
|
-
}
|
|
2615
|
-
return { success: true };
|
|
2616
|
-
});
|
|
2617
|
-
// Onboarding
|
|
2618
|
-
electron_1.ipcMain.handle('window:close-current', async (event) => {
|
|
2619
|
-
const win = electron_1.BrowserWindow.fromWebContents(event.sender);
|
|
2620
|
-
if (win && !win.isDestroyed())
|
|
2621
|
-
win.close();
|
|
2622
|
-
return { success: true };
|
|
2623
|
-
});
|
|
2624
|
-
electron_1.ipcMain.handle('window:minimize', async (event) => {
|
|
2625
|
-
const win = electron_1.BrowserWindow.fromWebContents(event.sender);
|
|
2626
|
-
if (win && !win.isDestroyed())
|
|
2627
|
-
win.minimize();
|
|
2628
|
-
return { success: true };
|
|
2629
|
-
});
|
|
2630
|
-
electron_1.ipcMain.handle('window:maximize', async (event) => {
|
|
2631
|
-
const win = electron_1.BrowserWindow.fromWebContents(event.sender);
|
|
2632
|
-
if (win && !win.isDestroyed()) {
|
|
2633
|
-
if (win.isMaximized()) {
|
|
2634
|
-
win.unmaximize();
|
|
2635
|
-
}
|
|
2636
|
-
else {
|
|
2637
|
-
win.maximize();
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
return { success: true };
|
|
2641
|
-
});
|
|
2642
|
-
electron_1.ipcMain.handle('onboarding:complete', async () => {
|
|
2643
|
-
(0, store_1.setSetting)('onboardingComplete', true);
|
|
2644
|
-
if (onboardingWindow && !onboardingWindow.isDestroyed()) {
|
|
2645
|
-
onboardingWindow.close();
|
|
2646
|
-
}
|
|
2647
|
-
return { success: true };
|
|
2648
|
-
});
|
|
2649
|
-
// ── Auth ──
|
|
2650
|
-
electron_1.ipcMain.handle('auth:get-state', async () => {
|
|
2651
|
-
const state = (0, auth_1.getAuthState)();
|
|
2652
|
-
return {
|
|
2653
|
-
isAuthenticated: (0, auth_1.isAuthenticated)(),
|
|
2654
|
-
email: state.email,
|
|
2655
|
-
name: state.name,
|
|
2656
|
-
plan: state.plan,
|
|
2657
|
-
userId: state.userId,
|
|
2658
|
-
};
|
|
2659
|
-
});
|
|
2660
|
-
electron_1.ipcMain.handle('auth:sign-in', async () => {
|
|
2661
|
-
(0, auth_1.openSignIn)();
|
|
2662
|
-
return { success: true };
|
|
2663
|
-
});
|
|
2664
|
-
electron_1.ipcMain.handle('auth:sign-out', async () => {
|
|
2665
|
-
(0, auth_1.signOut)();
|
|
2666
|
-
// Notify all windows of sign-out
|
|
2667
|
-
for (const win of electron_1.BrowserWindow.getAllWindows()) {
|
|
2668
|
-
if (!win.isDestroyed()) {
|
|
2669
|
-
win.webContents.send('auth:state-changed', {
|
|
2670
|
-
isAuthenticated: false,
|
|
2671
|
-
...(0, auth_1.getAuthState)(),
|
|
2672
|
-
});
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
return { success: true };
|
|
2676
|
-
});
|
|
2677
|
-
// ── Recording Feature (V3) — lazy-loaded IPC handlers ──
|
|
2678
|
-
let recordingModule = null;
|
|
2679
|
-
// Allow auto-restore on startup to set the recording module reference
|
|
2680
|
-
/** Set up frame broadcast so recording-session.ts can notify all windows */
|
|
2681
|
-
function wireFrameBroadcast(mod) {
|
|
2682
|
-
const sessionMod = mod.getSessionModule();
|
|
2683
|
-
if (sessionMod) {
|
|
2684
|
-
sessionMod.setFrameBroadcast((data) => {
|
|
2685
|
-
for (const win of electron_1.BrowserWindow.getAllWindows()) {
|
|
2686
|
-
if (!win.isDestroyed()) {
|
|
2687
|
-
win.webContents.send('recording:new-frame', data);
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
});
|
|
2691
|
-
}
|
|
2692
|
-
}
|
|
2693
|
-
electron_1.ipcMain.on('recording-module-restored', (_event, mod) => {
|
|
2694
|
-
recordingModule = mod;
|
|
2695
|
-
registerRecordingShortcuts();
|
|
2696
|
-
(0, tray_1.updateTrayRecordingState)(true, false);
|
|
2697
|
-
wireFrameBroadcast(mod);
|
|
2698
|
-
logger_1.default.info('[Recording] Module reference set from auto-restore');
|
|
2699
|
-
});
|
|
2700
|
-
// ── Recording shortcut helpers ──
|
|
2701
|
-
function registerRecordingShortcuts() {
|
|
2702
|
-
const recSettings = (0, store_1.getSetting)('recordingSettings');
|
|
2703
|
-
const shortcuts = recSettings?.shortcuts || {
|
|
2704
|
-
toggleRecord: 'CommandOrControl+Shift+R',
|
|
2705
|
-
pauseResume: 'CommandOrControl+Shift+P',
|
|
2706
|
-
manualCapture: 'CommandOrControl+Shift+M',
|
|
2707
|
-
};
|
|
2708
|
-
// Toggle start/stop recording
|
|
2709
|
-
if (shortcuts.toggleRecord) {
|
|
2710
|
-
const ok = electron_1.globalShortcut.register(shortcuts.toggleRecord, async () => {
|
|
2711
|
-
if (!recordingModule)
|
|
2712
|
-
return;
|
|
2713
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2714
|
-
if (!sessionMod)
|
|
2715
|
-
return;
|
|
2716
|
-
const session = sessionMod.getCurrentSession();
|
|
2717
|
-
if (session && session.status !== 'completed' && session.status !== 'aborted') {
|
|
2718
|
-
const sessionId = session.id;
|
|
2719
|
-
await sessionMod.stopCurrentSession();
|
|
2720
|
-
notifyRecordingStatusChange();
|
|
2721
|
-
closeRecordingBarWindow();
|
|
2722
|
-
createTimelineWindow(sessionId);
|
|
2723
|
-
}
|
|
2724
|
-
else {
|
|
2725
|
-
const rs = (0, store_1.getSetting)('recordingSettings');
|
|
2726
|
-
await sessionMod.startSession({
|
|
2727
|
-
name: `Recording ${new Date().toLocaleString()}`,
|
|
2728
|
-
profile: (rs?.defaultProfile || 'automated_test'),
|
|
2729
|
-
scope: 'all',
|
|
2730
|
-
showInGallery: rs?.showInGallery !== false,
|
|
2731
|
-
});
|
|
2732
|
-
notifyRecordingStatusChange();
|
|
2733
|
-
}
|
|
2734
|
-
});
|
|
2735
|
-
if (ok)
|
|
2736
|
-
logger_1.default.info(`[Recording] Shortcut registered: ${shortcuts.toggleRecord} (toggle)`);
|
|
2737
|
-
}
|
|
2738
|
-
// Pause/resume
|
|
2739
|
-
if (shortcuts.pauseResume) {
|
|
2740
|
-
const ok = electron_1.globalShortcut.register(shortcuts.pauseResume, async () => {
|
|
2741
|
-
if (!recordingModule)
|
|
2742
|
-
return;
|
|
2743
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2744
|
-
if (!sessionMod)
|
|
2745
|
-
return;
|
|
2746
|
-
const session = sessionMod.getCurrentSession();
|
|
2747
|
-
if (!session)
|
|
2748
|
-
return;
|
|
2749
|
-
if (session.status === 'paused') {
|
|
2750
|
-
await sessionMod.resumeCurrentSession();
|
|
2751
|
-
}
|
|
2752
|
-
else if (session.status === 'recording') {
|
|
2753
|
-
await sessionMod.pauseCurrentSession();
|
|
2754
|
-
}
|
|
2755
|
-
notifyRecordingStatusChange();
|
|
2756
|
-
});
|
|
2757
|
-
if (ok)
|
|
2758
|
-
logger_1.default.info(`[Recording] Shortcut registered: ${shortcuts.pauseResume} (pause/resume)`);
|
|
2759
|
-
}
|
|
2760
|
-
// Manual capture marker
|
|
2761
|
-
if (shortcuts.manualCapture) {
|
|
2762
|
-
const ok = electron_1.globalShortcut.register(shortcuts.manualCapture, () => {
|
|
2763
|
-
if (!recordingModule)
|
|
2764
|
-
return;
|
|
2765
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2766
|
-
if (!sessionMod)
|
|
2767
|
-
return;
|
|
2768
|
-
sessionMod.triggerManualCapture();
|
|
2769
|
-
});
|
|
2770
|
-
if (ok)
|
|
2771
|
-
logger_1.default.info(`[Recording] Shortcut registered: ${shortcuts.manualCapture} (manual capture)`);
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
function unregisterRecordingShortcuts() {
|
|
2775
|
-
const recSettings = (0, store_1.getSetting)('recordingSettings');
|
|
2776
|
-
const shortcuts = recSettings?.shortcuts || {
|
|
2777
|
-
toggleRecord: 'CommandOrControl+Shift+R',
|
|
2778
|
-
pauseResume: 'CommandOrControl+Shift+P',
|
|
2779
|
-
manualCapture: 'CommandOrControl+Shift+M',
|
|
2780
|
-
};
|
|
2781
|
-
if (shortcuts.toggleRecord)
|
|
2782
|
-
try {
|
|
2783
|
-
electron_1.globalShortcut.unregister(shortcuts.toggleRecord);
|
|
2784
|
-
}
|
|
2785
|
-
catch { }
|
|
2786
|
-
if (shortcuts.pauseResume)
|
|
2787
|
-
try {
|
|
2788
|
-
electron_1.globalShortcut.unregister(shortcuts.pauseResume);
|
|
2789
|
-
}
|
|
2790
|
-
catch { }
|
|
2791
|
-
if (shortcuts.manualCapture)
|
|
2792
|
-
try {
|
|
2793
|
-
electron_1.globalShortcut.unregister(shortcuts.manualCapture);
|
|
2794
|
-
}
|
|
2795
|
-
catch { }
|
|
2796
|
-
}
|
|
2797
|
-
/** Broadcast recording status to all windows + manage bar/timeline windows */
|
|
2798
|
-
function notifyRecordingStatusChange() {
|
|
2799
|
-
logger_1.default.info('[Recording] notifyRecordingStatusChange called');
|
|
2800
|
-
if (!recordingModule)
|
|
2801
|
-
return;
|
|
2802
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2803
|
-
const session = sessionMod?.getCurrentSession();
|
|
2804
|
-
const data = session
|
|
2805
|
-
? {
|
|
2806
|
-
status: session.status,
|
|
2807
|
-
sessionId: session.id,
|
|
2808
|
-
frameCount: session.frameCount,
|
|
2809
|
-
duration: Date.now() - session.startedAt,
|
|
2810
|
-
}
|
|
2811
|
-
: { status: 'idle' };
|
|
2812
|
-
for (const win of electron_1.BrowserWindow.getAllWindows()) {
|
|
2813
|
-
if (!win.isDestroyed()) {
|
|
2814
|
-
win.webContents.send('recording:status-change', data);
|
|
2815
|
-
}
|
|
2816
|
-
}
|
|
2817
|
-
// Update tray menu
|
|
2818
|
-
(0, tray_1.updateTrayRecordingState)(true, !!session && session.status === 'recording', !!session && session.status === 'paused');
|
|
2819
|
-
// Manage recording bar window
|
|
2820
|
-
if (session && (session.status === 'recording' || session.status === 'paused')) {
|
|
2821
|
-
// Open bar if not already open
|
|
2822
|
-
if (!recordingBarWindow || recordingBarWindow.isDestroyed()) {
|
|
2823
|
-
createRecordingBarWindow();
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
else {
|
|
2827
|
-
// Close bar when stopped/idle
|
|
2828
|
-
closeRecordingBarWindow();
|
|
2829
|
-
}
|
|
2830
|
-
}
|
|
2831
|
-
// Track last completed session for auto-opening timeline (module-scope via closure)
|
|
2832
|
-
electron_1.ipcMain.handle('recording:enable-feature', async () => {
|
|
2833
|
-
try {
|
|
2834
|
-
recordingModule = await Promise.resolve().then(() => __importStar(require('./modules/recording')));
|
|
2835
|
-
const result = await recordingModule.initialize();
|
|
2836
|
-
if (result.success) {
|
|
2837
|
-
(0, store_1.setSetting)('recordingFeatureEnabled', true);
|
|
2838
|
-
registerRecordingShortcuts();
|
|
2839
|
-
wireFrameBroadcast(recordingModule);
|
|
2840
|
-
// Register recording routes on the API server
|
|
2841
|
-
Promise.resolve().then(() => __importStar(require('./modules/api-server'))).then((apiMod) => apiMod.registerRecordingRoutesOnServer())
|
|
2842
|
-
.catch(() => { });
|
|
2843
|
-
}
|
|
2844
|
-
return { success: result.success, providerType: result.providerType, fallbackReason: result.fallbackReason };
|
|
2845
|
-
}
|
|
2846
|
-
catch (err) {
|
|
2847
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
2848
|
-
}
|
|
2849
|
-
});
|
|
2850
|
-
electron_1.ipcMain.handle('recording:disable-feature', async () => {
|
|
2851
|
-
try {
|
|
2852
|
-
unregisterRecordingShortcuts();
|
|
2853
|
-
if (recordingModule) {
|
|
2854
|
-
await recordingModule.teardown();
|
|
2855
|
-
recordingModule = null;
|
|
2856
|
-
}
|
|
2857
|
-
(0, store_1.setSetting)('recordingFeatureEnabled', false);
|
|
2858
|
-
(0, tray_1.updateTrayRecordingState)(false, false);
|
|
2859
|
-
return { success: true };
|
|
2860
|
-
}
|
|
2861
|
-
catch (err) {
|
|
2862
|
-
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
2863
|
-
}
|
|
2864
|
-
});
|
|
2865
|
-
electron_1.ipcMain.handle('recording:start', async (_event, options) => {
|
|
2866
|
-
if (!recordingModule)
|
|
2867
|
-
return { success: false, error: 'Recording feature not enabled' };
|
|
2868
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2869
|
-
if (!sessionMod)
|
|
2870
|
-
return { success: false, error: 'Session module not loaded' };
|
|
2871
|
-
const session = await sessionMod.startSession(options);
|
|
2872
|
-
notifyRecordingStatusChange();
|
|
2873
|
-
return { sessionId: session.id, status: session.status };
|
|
2874
|
-
});
|
|
2875
|
-
electron_1.ipcMain.handle('recording:stop', async () => {
|
|
2876
|
-
if (!recordingModule)
|
|
2877
|
-
return { success: false, error: 'Recording feature not enabled' };
|
|
2878
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2879
|
-
if (!sessionMod)
|
|
2880
|
-
return { success: false, error: 'Session module not loaded' };
|
|
2881
|
-
const session = await sessionMod.stopCurrentSession();
|
|
2882
|
-
if (!session)
|
|
2883
|
-
return { success: false, error: 'No active recording session' };
|
|
2884
|
-
notifyRecordingStatusChange();
|
|
2885
|
-
closeRecordingBarWindow();
|
|
2886
|
-
createTimelineWindow(session.id);
|
|
2887
|
-
// Track recording analytics
|
|
2888
|
-
const duration = Date.now() - session.startedAt;
|
|
2889
|
-
(0, database_1.trackAnalytics)('recording', 'session', 1, duration, '');
|
|
2890
|
-
(0, database_1.trackAnalytics)('recording', 'frames', session.frameCount, 0, '');
|
|
2891
|
-
return {
|
|
2892
|
-
sessionId: session.id,
|
|
2893
|
-
status: session.status,
|
|
2894
|
-
frameCount: session.frameCount,
|
|
2895
|
-
duration,
|
|
2896
|
-
};
|
|
2897
|
-
});
|
|
2898
|
-
electron_1.ipcMain.handle('recording:pause', async () => {
|
|
2899
|
-
if (!recordingModule)
|
|
2900
|
-
return { success: false, error: 'Recording feature not enabled' };
|
|
2901
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2902
|
-
if (!sessionMod)
|
|
2903
|
-
return { success: false, error: 'Session module not loaded' };
|
|
2904
|
-
await sessionMod.pauseCurrentSession();
|
|
2905
|
-
notifyRecordingStatusChange();
|
|
2906
|
-
return { success: true };
|
|
2907
|
-
});
|
|
2908
|
-
electron_1.ipcMain.handle('recording:resume', async () => {
|
|
2909
|
-
if (!recordingModule)
|
|
2910
|
-
return { success: false, error: 'Recording feature not enabled' };
|
|
2911
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2912
|
-
if (!sessionMod)
|
|
2913
|
-
return { success: false, error: 'Session module not loaded' };
|
|
2914
|
-
await sessionMod.resumeCurrentSession();
|
|
2915
|
-
notifyRecordingStatusChange();
|
|
2916
|
-
return { success: true };
|
|
2917
|
-
});
|
|
2918
|
-
electron_1.ipcMain.handle('recording:status', async () => {
|
|
2919
|
-
if (!recordingModule)
|
|
2920
|
-
return { status: 'idle' };
|
|
2921
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2922
|
-
if (!sessionMod)
|
|
2923
|
-
return { status: 'idle' };
|
|
2924
|
-
const session = sessionMod.getCurrentSession();
|
|
2925
|
-
if (!session)
|
|
2926
|
-
return { status: 'idle' };
|
|
2927
|
-
return {
|
|
2928
|
-
status: session.status,
|
|
2929
|
-
sessionId: session.id,
|
|
2930
|
-
frameCount: session.frameCount,
|
|
2931
|
-
duration: Date.now() - session.startedAt,
|
|
2932
|
-
};
|
|
2933
|
-
});
|
|
2934
|
-
electron_1.ipcMain.handle('recording:get-sessions', async () => {
|
|
2935
|
-
const { getRecordingSessions } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
2936
|
-
return getRecordingSessions();
|
|
2937
|
-
});
|
|
2938
|
-
electron_1.ipcMain.handle('recording:get-session-frames', async (_event, sessionId) => {
|
|
2939
|
-
const { getSessionFrames } = await Promise.resolve().then(() => __importStar(require('./db/database')));
|
|
2940
|
-
return getSessionFrames(sessionId);
|
|
2941
|
-
});
|
|
2942
|
-
// Manual capture marker during recording
|
|
2943
|
-
electron_1.ipcMain.handle('recording:manual-capture', async () => {
|
|
2944
|
-
if (!recordingModule)
|
|
2945
|
-
return { success: false, error: 'Recording feature not enabled' };
|
|
2946
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2947
|
-
if (!sessionMod)
|
|
2948
|
-
return { success: false, error: 'Session module not loaded' };
|
|
2949
|
-
sessionMod.triggerManualCapture();
|
|
2950
|
-
return { success: true };
|
|
2951
|
-
});
|
|
2952
|
-
// Quick record: start immediately with last-used profile, no dialog
|
|
2953
|
-
electron_1.ipcMain.handle('recording:quick-start', async () => {
|
|
2954
|
-
if (!recordingModule)
|
|
2955
|
-
return { success: false, error: 'Recording feature not enabled' };
|
|
2956
|
-
const sessionMod = recordingModule.getSessionModule();
|
|
2957
|
-
if (!sessionMod)
|
|
2958
|
-
return { success: false, error: 'Session module not loaded' };
|
|
2959
|
-
const recSettings = (0, store_1.getSetting)('recordingSettings') || {};
|
|
2960
|
-
const profile = recSettings.defaultProfile || 'automated_test';
|
|
2961
|
-
const session = await sessionMod.startSession({
|
|
2962
|
-
name: `Quick Recording ${new Date().toLocaleString()}`,
|
|
2963
|
-
profile,
|
|
2964
|
-
scope: 'all',
|
|
2965
|
-
showInGallery: recSettings.showInGallery !== false,
|
|
2966
|
-
});
|
|
2967
|
-
notifyRecordingStatusChange();
|
|
2968
|
-
return { sessionId: session.id, status: session.status };
|
|
2969
|
-
});
|
|
2970
|
-
// Recording settings
|
|
2971
|
-
electron_1.ipcMain.handle('recording:get-settings', async () => {
|
|
2972
|
-
return (0, store_1.getSetting)('recordingSettings') || {};
|
|
2973
|
-
});
|
|
2974
|
-
electron_1.ipcMain.handle('recording:set-settings', async (_event, settings) => {
|
|
2975
|
-
const current = (0, store_1.getSetting)('recordingSettings') || {};
|
|
2976
|
-
const updated = { ...current, ...settings };
|
|
2977
|
-
(0, store_1.setSetting)('recordingSettings', updated);
|
|
2978
|
-
return { success: true };
|
|
2979
|
-
});
|
|
2980
|
-
// Open timeline window
|
|
2981
|
-
electron_1.ipcMain.handle('recording:open-timeline', async (_event, sessionId) => {
|
|
2982
|
-
createTimelineWindow(sessionId);
|
|
2983
|
-
return { success: true };
|
|
2984
|
-
});
|
|
2985
|
-
// Open start recording dialog
|
|
2986
|
-
electron_1.ipcMain.handle('recording:open-start-dialog', async () => {
|
|
2987
|
-
createStartRecordingWindow();
|
|
2988
|
-
return { success: true };
|
|
2989
|
-
});
|
|
2990
|
-
}
|
|
2991
|
-
function createMainPanelWindow() {
|
|
2992
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
2993
|
-
mainPanelWindow.show();
|
|
2994
|
-
mainPanelWindow.focus();
|
|
2995
|
-
return;
|
|
2996
|
-
}
|
|
2997
|
-
mainPanelWindow = new electron_1.BrowserWindow({
|
|
2998
|
-
width: 860,
|
|
2999
|
-
height: 600,
|
|
3000
|
-
...framelessWindowOptions(),
|
|
3001
|
-
resizable: true,
|
|
3002
|
-
center: true,
|
|
3003
|
-
webPreferences: {
|
|
3004
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
3005
|
-
contextIsolation: true,
|
|
3006
|
-
nodeIntegration: false,
|
|
3007
|
-
navigateOnDragDrop: false,
|
|
3008
|
-
},
|
|
3009
|
-
});
|
|
3010
|
-
makeWindowFocusAware(mainPanelWindow);
|
|
3011
|
-
attachCrashHandlers(mainPanelWindow, 'main-panel');
|
|
3012
|
-
mainPanelWindow.loadFile(path.join(__dirname, '../renderer/main-panel.html'));
|
|
3013
|
-
mainPanelWindow.on('closed', () => {
|
|
3014
|
-
mainPanelWindow = null;
|
|
3015
|
-
});
|
|
3016
|
-
}
|
|
3017
|
-
function createOnboardingWindow() {
|
|
3018
|
-
onboardingWindow = new electron_1.BrowserWindow({
|
|
3019
|
-
width: 560,
|
|
3020
|
-
height: 520,
|
|
3021
|
-
...framelessWindowOptions(),
|
|
3022
|
-
resizable: false,
|
|
3023
|
-
center: true,
|
|
3024
|
-
webPreferences: {
|
|
3025
|
-
preload: path.join(__dirname, 'preload.js'),
|
|
3026
|
-
contextIsolation: true,
|
|
3027
|
-
nodeIntegration: false,
|
|
3028
|
-
navigateOnDragDrop: false,
|
|
3029
|
-
},
|
|
3030
|
-
});
|
|
3031
|
-
attachCrashHandlers(onboardingWindow, 'onboarding');
|
|
3032
|
-
onboardingWindow.loadFile(path.join(__dirname, '../renderer/onboarding.html'));
|
|
3033
|
-
onboardingWindow.on('closed', () => {
|
|
3034
|
-
onboardingWindow = null;
|
|
3035
|
-
});
|
|
3036
|
-
}
|
|
3037
|
-
// ── Full-screen capture (no region selection) ──
|
|
3038
|
-
async function doFullScreenCapture() {
|
|
3039
|
-
try {
|
|
3040
|
-
const fullBuffer = await (0, capture_modes_1.captureFullScreen)();
|
|
3041
|
-
ensureCapturesDir();
|
|
3042
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
3043
|
-
const filename = `fullscreen-${timestamp}.png`;
|
|
3044
|
-
const filepath = path.join(getCapturesDir(), filename);
|
|
3045
|
-
fs.writeFileSync(filepath, fullBuffer);
|
|
3046
|
-
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
|
|
3047
|
-
const { width, height } = primaryDisplay.size;
|
|
3048
|
-
const captureId = (0, database_1.saveCapture)({
|
|
3049
|
-
screenshotPath: filepath,
|
|
3050
|
-
regionX: 0,
|
|
3051
|
-
regionY: 0,
|
|
3052
|
-
regionW: width,
|
|
3053
|
-
regionH: height,
|
|
3054
|
-
sourceApp: lastActiveWindow.appName,
|
|
3055
|
-
windowTitle: lastActiveWindow.windowTitle,
|
|
3056
|
-
});
|
|
3057
|
-
// Copy to clipboard
|
|
3058
|
-
const ni = electron_1.nativeImage.createFromBuffer(fullBuffer);
|
|
3059
|
-
electron_1.clipboard.writeImage(ni);
|
|
3060
|
-
// Show overlay
|
|
3061
|
-
createOverlayWindow({
|
|
3062
|
-
screenshotPath: filepath,
|
|
3063
|
-
captureId,
|
|
3064
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
3065
|
-
voiceMode: false,
|
|
3066
|
-
inlineEditMode: false,
|
|
3067
|
-
originalText: null,
|
|
3068
|
-
multiRegion: false,
|
|
3069
|
-
regionScreenshots: [filepath],
|
|
3070
|
-
}, { x: 0, y: 0, width, height });
|
|
3071
|
-
}
|
|
3072
|
-
catch (err) {
|
|
3073
|
-
logger_1.default.error('[FullScreenCapture] Error:', err);
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
|
-
// ── Repeat last capture ──
|
|
3077
|
-
async function doRepeatLastCapture() {
|
|
3078
|
-
const lastRegion = (0, capture_modes_1.getLastCaptureRegion)();
|
|
3079
|
-
if (!lastRegion) {
|
|
3080
|
-
logger_1.default.info('[RepeatCapture] No previous capture region stored');
|
|
3081
|
-
return;
|
|
3082
|
-
}
|
|
3083
|
-
try {
|
|
3084
|
-
await (0, active_window_1.getActiveWindowInfo)().then((info) => {
|
|
3085
|
-
lastActiveWindow = info;
|
|
3086
|
-
});
|
|
3087
|
-
const fullBuffer = await (0, capture_1.captureScreen)();
|
|
3088
|
-
const { filepath, captureId } = await captureAndSaveRegion(fullBuffer, lastRegion);
|
|
3089
|
-
createOverlayWindow({
|
|
3090
|
-
screenshotPath: filepath,
|
|
3091
|
-
captureId,
|
|
3092
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
3093
|
-
voiceMode: false,
|
|
3094
|
-
inlineEditMode: false,
|
|
3095
|
-
originalText: null,
|
|
3096
|
-
multiRegion: false,
|
|
3097
|
-
regionScreenshots: [filepath],
|
|
3098
|
-
}, lastRegion);
|
|
3099
|
-
}
|
|
3100
|
-
catch (err) {
|
|
3101
|
-
logger_1.default.error('[RepeatCapture] Error:', err);
|
|
3102
|
-
}
|
|
3103
|
-
}
|
|
3104
|
-
// Check for CLI recording commands before full app startup
|
|
3105
|
-
// CLI commands communicate via HTTP API and exit immediately
|
|
3106
|
-
Promise.resolve().then(() => __importStar(require('./modules/recording/cli'))).then(({ handleCliArgs }) => {
|
|
3107
|
-
if (handleCliArgs(process.argv)) {
|
|
3108
|
-
// CLI command is being handled — don't start the full app
|
|
3109
|
-
return;
|
|
3110
|
-
}
|
|
3111
|
-
})
|
|
3112
|
-
.catch(() => {
|
|
3113
|
-
// CLI module not available, continue normal startup
|
|
3114
|
-
});
|
|
3115
|
-
// Register protocol handler for auth callback
|
|
3116
|
-
if (process.defaultApp) {
|
|
3117
|
-
if (process.argv.length >= 2) {
|
|
3118
|
-
electron_1.app.setAsDefaultProtocolClient('superbased', process.execPath, [path.resolve(process.argv[1])]);
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
|
-
else {
|
|
3122
|
-
electron_1.app.setAsDefaultProtocolClient('superbased');
|
|
3123
|
-
}
|
|
3124
|
-
// Handle protocol URL on macOS
|
|
3125
|
-
electron_1.app.on('open-url', (_event, url) => {
|
|
3126
|
-
if (url.startsWith('superbased://auth-callback')) {
|
|
3127
|
-
(0, auth_1.handleAuthCallback)(url);
|
|
3128
|
-
// Notify all windows of auth state change
|
|
3129
|
-
for (const win of electron_1.BrowserWindow.getAllWindows()) {
|
|
3130
|
-
if (!win.isDestroyed()) {
|
|
3131
|
-
win.webContents.send('auth:state-changed', {
|
|
3132
|
-
isAuthenticated: (0, auth_1.isAuthenticated)(),
|
|
3133
|
-
...(0, auth_1.getAuthState)(),
|
|
3134
|
-
});
|
|
3135
|
-
}
|
|
3136
|
-
}
|
|
3137
|
-
// Link device to user + validate license (sends machine_id → backend links device)
|
|
3138
|
-
if ((0, auth_1.isAuthenticated)()) {
|
|
3139
|
-
Promise.resolve().then(() => __importStar(require('./modules/license'))).then((lic) => lic.validateLicense()).catch(() => { });
|
|
3140
|
-
// Flush any queued analytics now that we have an auth token, then call
|
|
3141
|
-
// /usage/link-device so prior anonymous events get backfilled to the user.
|
|
3142
|
-
Promise.resolve().then(() => __importStar(require('./modules/telemetry'))).then((tel) => tel.flushNow()).catch(() => { });
|
|
3143
|
-
Promise.resolve().then(() => __importStar(require('./modules/usage-link'))).then((mod) => mod.linkDeviceOnSignIn()).catch(() => { });
|
|
3144
|
-
}
|
|
3145
|
-
}
|
|
3146
|
-
});
|
|
3147
|
-
// Handle protocol URL on Windows (second-instance)
|
|
3148
|
-
const gotSingleLock = electron_1.app.requestSingleInstanceLock();
|
|
3149
|
-
if (!gotSingleLock) {
|
|
3150
|
-
electron_1.app.quit();
|
|
3151
|
-
}
|
|
3152
|
-
else {
|
|
3153
|
-
electron_1.app.on('second-instance', (_event, argv) => {
|
|
3154
|
-
const url = argv.find((arg) => arg.startsWith('superbased://'));
|
|
3155
|
-
if (url && url.startsWith('superbased://auth-callback')) {
|
|
3156
|
-
(0, auth_1.handleAuthCallback)(url);
|
|
3157
|
-
for (const win of electron_1.BrowserWindow.getAllWindows()) {
|
|
3158
|
-
if (!win.isDestroyed()) {
|
|
3159
|
-
win.webContents.send('auth:state-changed', {
|
|
3160
|
-
isAuthenticated: (0, auth_1.isAuthenticated)(),
|
|
3161
|
-
...(0, auth_1.getAuthState)(),
|
|
3162
|
-
});
|
|
3163
|
-
}
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
// Focus main window
|
|
3167
|
-
if (mainPanelWindow && !mainPanelWindow.isDestroyed()) {
|
|
3168
|
-
if (mainPanelWindow.isMinimized())
|
|
3169
|
-
mainPanelWindow.restore();
|
|
3170
|
-
mainPanelWindow.focus();
|
|
3171
|
-
}
|
|
3172
|
-
});
|
|
3173
|
-
}
|
|
3174
|
-
electron_1.app.whenReady().then(() => {
|
|
3175
|
-
// Register sbfile:// protocol — reads files and returns buffers without holding locks.
|
|
3176
|
-
// This prevents Windows file locking when images are displayed in <img> tags.
|
|
3177
|
-
// URL format: sbfile:///C:/path/to/file.webp?v=1 (triple slash, forward slashes)
|
|
3178
|
-
electron_1.protocol.handle('sbfile', async (request) => {
|
|
3179
|
-
// Parse raw URL string — avoid new URL() which mis-parses Windows drive letters
|
|
3180
|
-
let filePath = request.url.replace(/^sbfile:\/\/\//, '').split('?')[0];
|
|
3181
|
-
filePath = decodeURIComponent(filePath);
|
|
3182
|
-
// Normalize forward slashes to platform separators
|
|
3183
|
-
if (process.platform === 'win32') {
|
|
3184
|
-
filePath = filePath.replace(/\//g, '\\');
|
|
3185
|
-
}
|
|
3186
|
-
if (!isPathSafe(filePath)) {
|
|
3187
|
-
return new Response('Forbidden', { status: 403 });
|
|
3188
|
-
}
|
|
3189
|
-
try {
|
|
3190
|
-
const buffer = fs.readFileSync(filePath);
|
|
3191
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
3192
|
-
const mimeTypes = {
|
|
3193
|
-
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
3194
|
-
'.webp': 'image/webp', '.gif': 'image/gif', '.bmp': 'image/bmp',
|
|
3195
|
-
};
|
|
3196
|
-
return new Response(buffer, {
|
|
3197
|
-
headers: { 'Content-Type': mimeTypes[ext] || 'application/octet-stream' },
|
|
3198
|
-
});
|
|
3199
|
-
}
|
|
3200
|
-
catch (err) {
|
|
3201
|
-
logger_1.default.warn('[sbfile] Failed to serve:', filePath, err);
|
|
3202
|
-
return new Response('Not found', { status: 404 });
|
|
3203
|
-
}
|
|
3204
|
-
});
|
|
3205
|
-
(0, auth_1.loadStoredToken)();
|
|
3206
|
-
(0, database_1.initDatabase)();
|
|
3207
|
-
setupIpcHandlers();
|
|
3208
|
-
// Anonymous heartbeat — let the admin console see this install even if the
|
|
3209
|
-
// user never signs in. No-op when authenticated. Throttled to once / 24h.
|
|
3210
|
-
Promise.resolve().then(() => __importStar(require('./modules/license'))).then((lic) => lic.sendAnonymousHeartbeat())
|
|
3211
|
-
.catch(() => { });
|
|
3212
|
-
// Start the analytics forwarder. Periodically flushes the local event queue
|
|
3213
|
-
// to the backend so admin sees per-user usage data. Defaults to enabled —
|
|
3214
|
-
// user can opt out via Settings > Privacy > "Share usage analytics".
|
|
3215
|
-
Promise.resolve().then(() => __importStar(require('./modules/telemetry'))).then((tel) => {
|
|
3216
|
-
tel.startTelemetry();
|
|
3217
|
-
// One-shot historical backfill — uploads existing local SQLite
|
|
3218
|
-
// analytics_events buckets so the admin sees the same lifetime totals
|
|
3219
|
-
// as the user's local Analytics tab. Resumable across restarts.
|
|
3220
|
-
// Delay 5s so the auth state has settled (so the backfill is correctly
|
|
3221
|
-
// attributed to the user instead of going to the anonymous bucket).
|
|
3222
|
-
setTimeout(() => { tel.backfillLocalAnalytics().catch(() => { }); }, 5000);
|
|
3223
|
-
})
|
|
3224
|
-
.catch(() => { });
|
|
3225
|
-
// Backfill any prior anonymous events for this machine to the user account
|
|
3226
|
-
// if we already have an auth token at startup.
|
|
3227
|
-
if ((0, auth_1.isAuthenticated)()) {
|
|
3228
|
-
Promise.resolve().then(() => __importStar(require('./modules/usage-link'))).then((mod) => mod.linkDeviceOnSignIn()).catch(() => { });
|
|
3229
|
-
}
|
|
3230
|
-
// One-time macOS Screen Recording permission check (non-blocking)
|
|
3231
|
-
checkScreenRecordingPermissionOnce();
|
|
3232
|
-
(0, tray_1.setupTray)(() => {
|
|
3233
|
-
if (!tryClaimSelectionUI())
|
|
3234
|
-
return;
|
|
3235
|
-
createSelectionWindow();
|
|
3236
|
-
}, () => openMainPanelSettings(), () => createGalleryWindow(), {
|
|
3237
|
-
onFullScreen: () => doFullScreenCapture(),
|
|
3238
|
-
onRepeatLast: () => doRepeatLastCapture(),
|
|
3239
|
-
onTimedCapture: (delayMs) => {
|
|
3240
|
-
(0, capture_modes_1.startTimedCapture)(delayMs, () => {
|
|
3241
|
-
if (!tryClaimSelectionUI())
|
|
3242
|
-
return;
|
|
3243
|
-
createSelectionWindow();
|
|
3244
|
-
});
|
|
3245
|
-
},
|
|
3246
|
-
onStartRecording: () => {
|
|
3247
|
-
logger_1.default.info('[Tray] Start Recording clicked — opening dialog');
|
|
3248
|
-
createStartRecordingWindow();
|
|
3249
|
-
},
|
|
3250
|
-
onQuickRecord: async () => {
|
|
3251
|
-
try {
|
|
3252
|
-
// Trigger quick-start via IPC (reuses the handler logic)
|
|
3253
|
-
const recordingMod = await Promise.resolve().then(() => __importStar(require('./modules/recording')));
|
|
3254
|
-
const sessionMod = recordingMod.getSessionModule();
|
|
3255
|
-
if (sessionMod) {
|
|
3256
|
-
const recSettings = (0, store_1.getSetting)('recordingSettings');
|
|
3257
|
-
await sessionMod.startSession({
|
|
3258
|
-
name: `Quick Recording ${new Date().toLocaleString()}`,
|
|
3259
|
-
profile: (recSettings?.defaultProfile || 'automated_test'),
|
|
3260
|
-
scope: 'all',
|
|
3261
|
-
showInGallery: recSettings?.showInGallery !== false,
|
|
3262
|
-
});
|
|
3263
|
-
(0, tray_1.updateTrayRecordingState)(true, true);
|
|
3264
|
-
}
|
|
3265
|
-
}
|
|
3266
|
-
catch (err) {
|
|
3267
|
-
logger_1.default.error('[Tray] Quick record failed:', err);
|
|
3268
|
-
}
|
|
3269
|
-
},
|
|
3270
|
-
onPauseRecording: async () => {
|
|
3271
|
-
try {
|
|
3272
|
-
const recordingMod = await Promise.resolve().then(() => __importStar(require('./modules/recording')));
|
|
3273
|
-
const sessionMod = recordingMod.getSessionModule();
|
|
3274
|
-
if (sessionMod) {
|
|
3275
|
-
await sessionMod.pauseCurrentSession();
|
|
3276
|
-
(0, tray_1.updateTrayRecordingState)(true, false, true);
|
|
3277
|
-
}
|
|
3278
|
-
}
|
|
3279
|
-
catch (err) {
|
|
3280
|
-
logger_1.default.error('[Tray] Pause failed:', err);
|
|
3281
|
-
}
|
|
3282
|
-
},
|
|
3283
|
-
onResumeRecording: async () => {
|
|
3284
|
-
try {
|
|
3285
|
-
const recordingMod = await Promise.resolve().then(() => __importStar(require('./modules/recording')));
|
|
3286
|
-
const sessionMod = recordingMod.getSessionModule();
|
|
3287
|
-
if (sessionMod) {
|
|
3288
|
-
await sessionMod.resumeCurrentSession();
|
|
3289
|
-
(0, tray_1.updateTrayRecordingState)(true, true);
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
catch (err) {
|
|
3293
|
-
logger_1.default.error('[Tray] Resume failed:', err);
|
|
3294
|
-
}
|
|
3295
|
-
},
|
|
3296
|
-
onStopRecording: async () => {
|
|
3297
|
-
try {
|
|
3298
|
-
const recordingMod = await Promise.resolve().then(() => __importStar(require('./modules/recording')));
|
|
3299
|
-
const sessionMod = recordingMod.getSessionModule();
|
|
3300
|
-
if (sessionMod) {
|
|
3301
|
-
const cur = sessionMod.getCurrentSession();
|
|
3302
|
-
const sessionId = cur?.id;
|
|
3303
|
-
await sessionMod.stopCurrentSession();
|
|
3304
|
-
(0, tray_1.updateTrayRecordingState)(true, false);
|
|
3305
|
-
closeRecordingBarWindow();
|
|
3306
|
-
if (sessionId) {
|
|
3307
|
-
createTimelineWindow(sessionId);
|
|
3308
|
-
}
|
|
3309
|
-
}
|
|
3310
|
-
}
|
|
3311
|
-
catch (err) {
|
|
3312
|
-
logger_1.default.error('[Tray] Stop failed:', err);
|
|
3313
|
-
}
|
|
3314
|
-
},
|
|
3315
|
-
onManualCapture: () => {
|
|
3316
|
-
try {
|
|
3317
|
-
const recordingMod = require('./modules/recording');
|
|
3318
|
-
const sessionMod = recordingMod.getSessionModule();
|
|
3319
|
-
if (sessionMod)
|
|
3320
|
-
sessionMod.triggerManualCapture();
|
|
3321
|
-
}
|
|
3322
|
-
catch (err) {
|
|
3323
|
-
logger_1.default.error('[Tray] Manual capture failed:', err);
|
|
3324
|
-
}
|
|
3325
|
-
},
|
|
3326
|
-
onSessionGallery: () => {
|
|
3327
|
-
createTimelineWindow();
|
|
3328
|
-
},
|
|
3329
|
-
onOpenMainPanel: () => {
|
|
3330
|
-
createMainPanelWindow();
|
|
3331
|
-
},
|
|
3332
|
-
});
|
|
3333
|
-
(0, hotkeys_1.registerHotkeys)(() => {
|
|
3334
|
-
if (!tryClaimSelectionUI())
|
|
3335
|
-
return;
|
|
3336
|
-
createSelectionWindow();
|
|
3337
|
-
}, () => {
|
|
3338
|
-
if (!tryClaimSelectionUI())
|
|
3339
|
-
return;
|
|
3340
|
-
createSelectionWindow({ mode: 'multi' });
|
|
3341
|
-
});
|
|
3342
|
-
// Register scroll-capture shortcut
|
|
3343
|
-
const scrollSettings = (0, store_1.getSetting)('scrollCapture');
|
|
3344
|
-
const scrollShortcut = scrollSettings?.shortcut || 'CommandOrControl+Shift+A';
|
|
3345
|
-
const scrollSuccess = electron_1.globalShortcut.register(scrollShortcut, () => {
|
|
3346
|
-
if (!tryClaimSelectionUI())
|
|
3347
|
-
return;
|
|
3348
|
-
scrollCaptureMode = true;
|
|
3349
|
-
createSelectionWindow();
|
|
3350
|
-
});
|
|
3351
|
-
if (scrollSuccess)
|
|
3352
|
-
logger_1.default.info(`Scroll-capture shortcut registered: ${scrollShortcut}`);
|
|
3353
|
-
// Register full-screen capture shortcut
|
|
3354
|
-
const fullScreenSuccess = electron_1.globalShortcut.register('CommandOrControl+Shift+F', () => {
|
|
3355
|
-
doFullScreenCapture();
|
|
3356
|
-
});
|
|
3357
|
-
if (fullScreenSuccess)
|
|
3358
|
-
logger_1.default.info('Full-screen capture shortcut registered: Ctrl+Shift+F');
|
|
3359
|
-
// Register repeat-last-capture shortcut
|
|
3360
|
-
const repeatSuccess = electron_1.globalShortcut.register('CommandOrControl+Shift+L', () => {
|
|
3361
|
-
doRepeatLastCapture();
|
|
3362
|
-
});
|
|
3363
|
-
if (repeatSuccess)
|
|
3364
|
-
logger_1.default.info('Repeat-last-capture shortcut registered: Ctrl+Shift+L');
|
|
3365
|
-
// Register window capture shortcut (Ctrl+Shift+W) — opens window picker overlay
|
|
3366
|
-
const windowCaptureSuccess = electron_1.globalShortcut.register('CommandOrControl+Shift+W', async () => {
|
|
3367
|
-
try {
|
|
3368
|
-
const result = await (0, window_picker_1.showWindowPicker)();
|
|
3369
|
-
if (!result)
|
|
3370
|
-
return;
|
|
3371
|
-
await (0, active_window_1.getActiveWindowInfo)().then((info) => {
|
|
3372
|
-
lastActiveWindow = info;
|
|
3373
|
-
});
|
|
3374
|
-
// Capture full screen then crop — the source thumbnail is low-res
|
|
3375
|
-
const fullBuffer = await (0, capture_1.captureScreen)();
|
|
3376
|
-
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
|
|
3377
|
-
const { width, height } = primaryDisplay.size;
|
|
3378
|
-
const region = { x: 0, y: 0, width, height };
|
|
3379
|
-
const { filepath, captureId } = await captureAndSaveRegion(fullBuffer, region);
|
|
3380
|
-
// Store window name as metadata
|
|
3381
|
-
lastActiveWindow = { appName: result.name, windowTitle: result.name };
|
|
3382
|
-
createOverlayWindow({
|
|
3383
|
-
screenshotPath: filepath,
|
|
3384
|
-
captureId,
|
|
3385
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
3386
|
-
voiceMode: false,
|
|
3387
|
-
inlineEditMode: false,
|
|
3388
|
-
originalText: null,
|
|
3389
|
-
multiRegion: false,
|
|
3390
|
-
regionScreenshots: [filepath],
|
|
3391
|
-
}, region);
|
|
3392
|
-
}
|
|
3393
|
-
catch (err) {
|
|
3394
|
-
logger_1.default.error('[WindowCapture] Error:', err);
|
|
3395
|
-
}
|
|
3396
|
-
});
|
|
3397
|
-
if (windowCaptureSuccess)
|
|
3398
|
-
logger_1.default.info('Window capture shortcut registered: Ctrl+Shift+W');
|
|
3399
|
-
// Register color picker shortcut (Ctrl+Shift+C)
|
|
3400
|
-
const colorPickerSuccess = electron_1.globalShortcut.register('CommandOrControl+Shift+C', () => {
|
|
3401
|
-
(0, color_picker_1.startColorPicker)();
|
|
3402
|
-
});
|
|
3403
|
-
if (colorPickerSuccess)
|
|
3404
|
-
logger_1.default.info('Color picker shortcut registered: Ctrl+Shift+C');
|
|
3405
|
-
// Register OCR capture shortcut (Ctrl+Shift+T)
|
|
3406
|
-
const ocrSuccess = electron_1.globalShortcut.register('CommandOrControl+Shift+T', async () => {
|
|
3407
|
-
try {
|
|
3408
|
-
// Capture full screen, then let user select region via selection window
|
|
3409
|
-
// For simplicity, OCR the full screen and show result
|
|
3410
|
-
const buf = await (0, capture_1.captureScreen)();
|
|
3411
|
-
const text = await (0, ocr_1.performOCR)(buf);
|
|
3412
|
-
if (text) {
|
|
3413
|
-
(0, ocr_1.showOCRResult)(text);
|
|
3414
|
-
// Also store in DB if we have a capture
|
|
3415
|
-
}
|
|
3416
|
-
else {
|
|
3417
|
-
(0, ocr_1.showOCRResult)('(No text detected)');
|
|
3418
|
-
}
|
|
3419
|
-
}
|
|
3420
|
-
catch (err) {
|
|
3421
|
-
logger_1.default.error('[OCR] Error:', err);
|
|
3422
|
-
}
|
|
3423
|
-
});
|
|
3424
|
-
if (ocrSuccess)
|
|
3425
|
-
logger_1.default.info('OCR capture shortcut registered: Ctrl+Shift+T');
|
|
3426
|
-
// Register Token Compression shortcut (Ctrl+Shift+E)
|
|
3427
|
-
const tceSuccess = electron_1.globalShortcut.register('CommandOrControl+Shift+E', async () => {
|
|
3428
|
-
try {
|
|
3429
|
-
const autoCopy = (0, store_1.getSetting)('tceAutoCopy') !== false; // default true
|
|
3430
|
-
let text;
|
|
3431
|
-
if (autoCopy) {
|
|
3432
|
-
// Auto-copy: simulate Ctrl+C to grab the current selection.
|
|
3433
|
-
// Wait 500ms first so the user releases Ctrl+Shift+E keys — otherwise
|
|
3434
|
-
// nut.js pressing C while Shift is still held triggers Ctrl+Shift+C (color picker).
|
|
3435
|
-
const { simulateCopy } = await Promise.resolve().then(() => __importStar(require('./modules/keystroke')));
|
|
3436
|
-
const prevClipboard = electron_1.clipboard.readText();
|
|
3437
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
3438
|
-
await simulateCopy();
|
|
3439
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
3440
|
-
text = electron_1.clipboard.readText();
|
|
3441
|
-
if (text !== prevClipboard) {
|
|
3442
|
-
logger_1.default.info('[TCE] Auto-copied selection to clipboard');
|
|
3443
|
-
}
|
|
3444
|
-
}
|
|
3445
|
-
else {
|
|
3446
|
-
text = electron_1.clipboard.readText();
|
|
3447
|
-
}
|
|
3448
|
-
if (!text || text.trim().length < 20) {
|
|
3449
|
-
logger_1.default.info('[TCE] Shortcut: no text available');
|
|
3450
|
-
const { Notification } = require('electron');
|
|
3451
|
-
new Notification({
|
|
3452
|
-
title: 'SuperBased — Compress Text',
|
|
3453
|
-
body: autoCopy
|
|
3454
|
-
? 'Select text first, then press Ctrl+Shift+E.'
|
|
3455
|
-
: 'Copy text to clipboard first, then press Ctrl+Shift+E.',
|
|
3456
|
-
}).show();
|
|
3457
|
-
return;
|
|
3458
|
-
}
|
|
3459
|
-
logger_1.default.info(`[TCE] Shortcut: compressing ${text.length} chars from clipboard`);
|
|
3460
|
-
const { compressToFiles, quickAnalyze } = await Promise.resolve().then(() => __importStar(require('./modules/tce')));
|
|
3461
|
-
// Quick check: is compression actually beneficial?
|
|
3462
|
-
const analysis = quickAnalyze(text);
|
|
3463
|
-
if (analysis.compression.ratio < 1.0) {
|
|
3464
|
-
logger_1.default.info(`[TCE] Compression not beneficial (ratio ${analysis.compression.ratio.toFixed(1)}x). Using auto-preset.`);
|
|
3465
|
-
}
|
|
3466
|
-
if (!analysis.compression.recommend && analysis.compression.ratio < 1.0) {
|
|
3467
|
-
// Still proceed but use auto-preset which picks the smallest size
|
|
3468
|
-
// This maximizes density even if savings are marginal
|
|
3469
|
-
}
|
|
3470
|
-
// Read user TCE settings
|
|
3471
|
-
const tceUserSettings = {};
|
|
3472
|
-
const tcePreset = (0, store_1.getSetting)('tcePreset');
|
|
3473
|
-
tceUserSettings.preset = tcePreset || 'compact';
|
|
3474
|
-
logger_1.default.info(`[TCE] User preset setting: '${tcePreset}' → using '${tceUserSettings.preset}'`);
|
|
3475
|
-
// Schema stores this as a string ('auto' | '1' | '2' | '3'); TCE engine
|
|
3476
|
-
// types it as 'auto' | 1 | 2 | 3. Legacy electron-store values may still
|
|
3477
|
-
// be numbers — accept either.
|
|
3478
|
-
const tceColumnMode = (0, store_1.getSetting)('tceColumnMode');
|
|
3479
|
-
if (tceColumnMode !== undefined) {
|
|
3480
|
-
if (tceColumnMode === 'auto') {
|
|
3481
|
-
tceUserSettings.columnMode = 'auto';
|
|
3482
|
-
}
|
|
3483
|
-
else {
|
|
3484
|
-
const n = Number(tceColumnMode);
|
|
3485
|
-
if (Number.isFinite(n))
|
|
3486
|
-
tceUserSettings.columnMode = n;
|
|
3487
|
-
}
|
|
3488
|
-
}
|
|
3489
|
-
const tceTheme = (0, store_1.getSetting)('tceTheme');
|
|
3490
|
-
if (tceTheme)
|
|
3491
|
-
tceUserSettings.theme = tceTheme;
|
|
3492
|
-
const tceFontSize = (0, store_1.getSetting)('tceFontSize');
|
|
3493
|
-
if (tceFontSize)
|
|
3494
|
-
tceUserSettings.fontSize = tceFontSize;
|
|
3495
|
-
const tceOverlap = (0, store_1.getSetting)('tceOverlapLines');
|
|
3496
|
-
if (tceOverlap !== undefined)
|
|
3497
|
-
tceUserSettings.overlapLines = tceOverlap;
|
|
3498
|
-
const tceWrap = (0, store_1.getSetting)('tceLineWrapping');
|
|
3499
|
-
tceUserSettings.lineWrapping = tceWrap || 'wrap';
|
|
3500
|
-
const { filePaths, metadata } = await compressToFiles(text, tceUserSettings);
|
|
3501
|
-
if (filePaths.length === 0) {
|
|
3502
|
-
logger_1.default.warn('[TCE] No pages generated');
|
|
3503
|
-
return;
|
|
3504
|
-
}
|
|
3505
|
-
// Save first page as a capture record
|
|
3506
|
-
const captureId = (0, database_1.saveCapture)({
|
|
3507
|
-
screenshotPath: filePaths[0],
|
|
3508
|
-
regionX: 0,
|
|
3509
|
-
regionY: 0,
|
|
3510
|
-
regionW: parseInt(metadata.resolution.split('x')[0]) || 800,
|
|
3511
|
-
regionH: parseInt(metadata.resolution.split('x')[1]) || 600,
|
|
3512
|
-
sourceApp: 'Token Compression',
|
|
3513
|
-
windowTitle: `${metadata.totalLines} lines, ${metadata.columnsUsed}-col, ${metadata.presetUsed}`,
|
|
3514
|
-
});
|
|
3515
|
-
// Verify files exist before opening overlay
|
|
3516
|
-
for (const fp of filePaths) {
|
|
3517
|
-
const exists = fs.existsSync(fp);
|
|
3518
|
-
const size = exists ? fs.statSync(fp).size : 0;
|
|
3519
|
-
logger_1.default.info(`[TCE] File check: ${fp} exists=${exists} size=${size}`);
|
|
3520
|
-
}
|
|
3521
|
-
// Open overlay with all compressed pages as screenshots
|
|
3522
|
-
const initData = {
|
|
3523
|
-
screenshotPath: filePaths[0],
|
|
3524
|
-
captureId,
|
|
3525
|
-
hasApiKey: (0, auth_1.isAuthenticated)(),
|
|
3526
|
-
voiceMode: false,
|
|
3527
|
-
inlineEditMode: false,
|
|
3528
|
-
originalText: null,
|
|
3529
|
-
multiRegion: filePaths.length > 1,
|
|
3530
|
-
regionScreenshots: filePaths,
|
|
3531
|
-
};
|
|
3532
|
-
logger_1.default.info(`[TCE] Opening overlay with initData: screenshotPath=${initData.screenshotPath}, regionScreenshots=${initData.regionScreenshots.length} paths`);
|
|
3533
|
-
createOverlayWindow(initData, { x: 0, y: 0, width: parseInt(metadata.resolution.split('x')[0]) || 800, height: parseInt(metadata.resolution.split('x')[1]) || 600 });
|
|
3534
|
-
logger_1.default.info(`[TCE] Opened overlay with ${filePaths.length} compressed pages (${metadata.savingsPercent}% savings)`);
|
|
3535
|
-
// Track TCE capture analytics
|
|
3536
|
-
(0, database_1.trackAnalytics)('capture', 'tce', filePaths.length, 0, 'Token Compression');
|
|
3537
|
-
}
|
|
3538
|
-
catch (err) {
|
|
3539
|
-
logger_1.default.error('[TCE] Shortcut compression failed:', err);
|
|
3540
|
-
}
|
|
3541
|
-
});
|
|
3542
|
-
if (tceSuccess)
|
|
3543
|
-
logger_1.default.info('Token compression shortcut registered: Ctrl+Shift+E');
|
|
3544
|
-
// Show onboarding on first run
|
|
3545
|
-
const onboardingDone = (0, store_1.getSetting)('onboardingComplete');
|
|
3546
|
-
if (!onboardingDone) {
|
|
3547
|
-
createOnboardingWindow();
|
|
3548
|
-
}
|
|
3549
|
-
(0, updater_1.initAutoUpdater)();
|
|
3550
|
-
(0, updater_1.onUpdateStateChanged)((state) => {
|
|
3551
|
-
if (state.status === 'downloaded' && state.version) {
|
|
3552
|
-
(0, tray_2.setTrayUpdateReady)(state.version);
|
|
3553
|
-
}
|
|
3554
|
-
});
|
|
3555
|
-
(0, version_check_1.initVersionCheck)();
|
|
3556
|
-
// Start the always-on HTTP API server for MCP and external tool integration
|
|
3557
|
-
Promise.resolve().then(() => __importStar(require('./modules/api-server'))).then(async (apiMod) => {
|
|
3558
|
-
await apiMod.startApiServer();
|
|
3559
|
-
// Write MCP config file for external tool discovery
|
|
3560
|
-
const { writeMCPConfig } = await Promise.resolve().then(() => __importStar(require('./modules/mcp-config')));
|
|
3561
|
-
writeMCPConfig(apiMod.getApiAuthToken());
|
|
3562
|
-
})
|
|
3563
|
-
.catch((err) => {
|
|
3564
|
-
logger_1.default.error('[API] Failed to start API server:', err);
|
|
3565
|
-
});
|
|
3566
|
-
// Auto-restore recording feature if it was previously enabled
|
|
3567
|
-
const recordingWasEnabled = (0, store_1.getSetting)('recordingFeatureEnabled');
|
|
3568
|
-
logger_1.default.info('[Startup] Recording was previously enabled:', recordingWasEnabled);
|
|
3569
|
-
if (recordingWasEnabled) {
|
|
3570
|
-
Promise.resolve().then(() => __importStar(require('./modules/recording'))).then(async (mod) => {
|
|
3571
|
-
const result = await mod.initialize();
|
|
3572
|
-
if (result.success) {
|
|
3573
|
-
logger_1.default.info(`[Recording] Auto-restored on startup (provider: ${result.providerType})`);
|
|
3574
|
-
// Register recording routes on the API server
|
|
3575
|
-
Promise.resolve().then(() => __importStar(require('./modules/api-server'))).then((apiMod) => apiMod.registerRecordingRoutesOnServer())
|
|
3576
|
-
.catch(() => { });
|
|
3577
|
-
// Store module ref so IPC handlers can use it — simulate enable
|
|
3578
|
-
// The recordingModule var is inside setupIpcHandlers closure, so we use an event
|
|
3579
|
-
electron_1.ipcMain.emit('recording-module-restored', null, mod);
|
|
3580
|
-
}
|
|
3581
|
-
else {
|
|
3582
|
-
logger_1.default.warn('[Recording] Failed to auto-restore:', result.fallbackReason);
|
|
3583
|
-
}
|
|
3584
|
-
})
|
|
3585
|
-
.catch((err) => {
|
|
3586
|
-
logger_1.default.error('[Recording] Failed to auto-restore:', err);
|
|
3587
|
-
});
|
|
3588
|
-
}
|
|
3589
|
-
// Auto-cleanup old screenshots
|
|
3590
|
-
const cleanupDays = (0, store_1.getSetting)('autoCleanupDays') || 0;
|
|
3591
|
-
if (cleanupDays > 0) {
|
|
3592
|
-
try {
|
|
3593
|
-
const capturesDir = getCapturesDir();
|
|
3594
|
-
const cutoff = Date.now() - cleanupDays * 24 * 60 * 60 * 1000;
|
|
3595
|
-
const files = fs.readdirSync(capturesDir);
|
|
3596
|
-
let removed = 0;
|
|
3597
|
-
for (const f of files) {
|
|
3598
|
-
const fp = path.join(capturesDir, f);
|
|
3599
|
-
try {
|
|
3600
|
-
const stat = fs.statSync(fp);
|
|
3601
|
-
if (stat.isFile() && stat.mtimeMs < cutoff && /\.(png|jpg|jpeg|webp)$/i.test(f)) {
|
|
3602
|
-
fs.unlinkSync(fp);
|
|
3603
|
-
removed++;
|
|
3604
|
-
}
|
|
3605
|
-
}
|
|
3606
|
-
catch { }
|
|
3607
|
-
}
|
|
3608
|
-
if (removed > 0)
|
|
3609
|
-
logger_1.default.info(`[AutoCleanup] Removed ${removed} screenshots older than ${cleanupDays} days`);
|
|
3610
|
-
}
|
|
3611
|
-
catch (err) {
|
|
3612
|
-
logger_1.default.error('[AutoCleanup] Error:', err);
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
// Initialize dictation if enabled
|
|
3616
|
-
const dictationEnabled = (0, store_1.getSetting)('dictationEnabled');
|
|
3617
|
-
if (dictationEnabled) {
|
|
3618
|
-
createDictationIndicatorWindow();
|
|
3619
|
-
Promise.resolve().then(() => __importStar(require('./modules/dictation'))).then((mod) => {
|
|
3620
|
-
if (dictationIndicatorWindow && !dictationIndicatorWindow.isDestroyed()) {
|
|
3621
|
-
mod.initializeDictation(dictationIndicatorWindow);
|
|
3622
|
-
}
|
|
3623
|
-
})
|
|
3624
|
-
.catch((err) => logger_1.default.error('[Dictation] Failed to initialize:', err));
|
|
3625
|
-
}
|
|
3626
|
-
logger_1.default.info('SuperBased is running (V3 wiring version). Press Ctrl+Shift+S to start capturing.');
|
|
3627
|
-
logger_1.default.info('[Startup] recordingFeatureEnabled:', (0, store_1.getSetting)('recordingFeatureEnabled'));
|
|
3628
|
-
logger_1.default.info('[Startup] dictationEnabled:', dictationEnabled);
|
|
3629
|
-
});
|
|
3630
|
-
electron_1.app.on('will-quit', () => {
|
|
3631
|
-
(0, hotkeys_1.unregisterHotkeys)();
|
|
3632
|
-
// Flush any queued analytics so we don't lose the last minute of activity.
|
|
3633
|
-
Promise.resolve().then(() => __importStar(require('./modules/telemetry'))).then((tel) => tel.stopTelemetry())
|
|
3634
|
-
.catch(() => { });
|
|
3635
|
-
// Teardown dictation
|
|
3636
|
-
Promise.resolve().then(() => __importStar(require('./modules/dictation'))).then((mod) => mod.teardownDictation())
|
|
3637
|
-
.catch(() => { });
|
|
3638
|
-
closeDictationIndicatorWindow();
|
|
3639
|
-
// Update MCP config to stopped
|
|
3640
|
-
Promise.resolve().then(() => __importStar(require('./modules/mcp-config'))).then((cfgMod) => cfgMod.updateMCPConfigStopped())
|
|
3641
|
-
.catch(() => { });
|
|
3642
|
-
// Stop the API server
|
|
3643
|
-
Promise.resolve().then(() => __importStar(require('./modules/api-server'))).then((apiMod) => apiMod.stopApiServer())
|
|
3644
|
-
.catch(() => { });
|
|
3645
|
-
});
|
|
3646
|
-
electron_1.app.on('window-all-closed', () => {
|
|
3647
|
-
// App stays alive in the system tray
|
|
3648
|
-
});
|
|
3649
|
-
electron_1.app.on('child-process-gone', (_event, details) => {
|
|
3650
|
-
logger_1.default.error(`[Crash] Child process gone: type=${details.type}, reason=${details.reason}`);
|
|
3651
|
-
});
|
|
3652
|
-
//# sourceMappingURL=main.js.map
|