mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-30 07:39:54 +08:00
⚡ 截图功能优化
This commit is contained in:
40
src/core/screen-capture/index.ts
Normal file
40
src/core/screen-capture/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { clipboard, Notification } from 'electron';
|
||||
import { execFile, exec } from 'child_process';
|
||||
import platform from '@/common/utils/commonConst';
|
||||
import path from 'path';
|
||||
|
||||
// 截图方法windows
|
||||
export const screenWindow = (cb) => {
|
||||
const url = path.resolve(__static, 'PrintScr.exe');
|
||||
const screen_window = execFile(url);
|
||||
screen_window.on('exit', (code) => {
|
||||
if (code) {
|
||||
const image = clipboard.readImage();
|
||||
cb && cb(image.isEmpty() ? '' : image.toDataURL());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 截图方法mac
|
||||
export const handleScreenShots = (cb) => {
|
||||
exec('screencapture -i -r -c', () => {
|
||||
const image = clipboard.readImage();
|
||||
cb && cb(image.isEmpty() ? '' : image.toDataURL());
|
||||
});
|
||||
};
|
||||
|
||||
export default (mainWindow, cb) => {
|
||||
// 接收到截图后的执行程序
|
||||
mainWindow.hide();
|
||||
clipboard.writeText('');
|
||||
if (platform.macOS()) {
|
||||
handleScreenShots(cb);
|
||||
} else if (platform.windows()) {
|
||||
screenWindow(cb);
|
||||
} else {
|
||||
new Notification({
|
||||
title: '兼容性支持度不够',
|
||||
body: 'Linux 系统截图暂不支持,我们将会尽快更新!',
|
||||
}).show();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user