Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,23 +489,39 @@ class ScreenCapture {

/**
* 启动区域截图
* @param {Function} callback - 截图完成时的回调函数
* - 参数: { success: boolean, width?: number, height?: number }
* @param {Object|Function} [options] - 截图选项;直接传函数时按旧签名 start(callback) 处理
* @param {boolean} [options.autoConfirm=true] - 选区确定后直接出图,跳过编辑态(工具栏/标注)
* @param {Function} [callback] - 截图完成时的回调函数
* - 参数: { success: boolean, width?: number, height?: number, base64?: string }
* - success: 是否成功截图
* - width: 截图宽度(成功时)
* - height: 截图高度(成功时)
* - base64: 截图 PNG 的 base64(成功时)
*
* @example
* // 默认:框选/点选完成即出图,不再二次编辑
* ScreenCapture.start((result) => { ... });
*
* // 进入编辑态:选区确定后停留在工具栏,可标注/调整
* ScreenCapture.start({ autoConfirm: false }, (result) => { ... });
*/
static start(callback) {
static start(options, callback) {
if (platform === 'darwin') {
// macOS 暂不支持
throw new Error('ScreenCapture is not yet supported on macOS');
}

// 兼容旧签名 start(callback)
if (typeof options === 'function') {
callback = options;
options = undefined;
}

if (typeof callback !== 'function') {
throw new TypeError('Callback must be a function');
}

addon.startRegionCaptureWithPrimedFrame((result) => {
addon.startRegionCaptureWithPrimedFrame(options || {}, (result) => {
callback(result);
});
}
Expand Down
Loading
Loading