mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-31 08:20:07 +08:00
⚡ 截图功能优化
This commit is contained in:
@@ -11,11 +11,10 @@ import {
|
||||
} from 'electron';
|
||||
import { runner, detach } from '../browsers';
|
||||
import fs from 'fs';
|
||||
import { LocalDb } from '@/core';
|
||||
import { LocalDb, screenCapture } from '@/core';
|
||||
import plist from 'plist';
|
||||
import { DECODE_KEY } from '@/common/constans/main';
|
||||
import mainInstance from '../index';
|
||||
import { screenshots } from './registerScreenshots';
|
||||
const runnerInstance = runner();
|
||||
const detachInstance = detach();
|
||||
const dbInstance = new LocalDb(app.getPath('userData'));
|
||||
@@ -34,14 +33,6 @@ class API {
|
||||
event.returnValue = data;
|
||||
// event.sender.send(`msg-back-${arg.type}`, data);
|
||||
});
|
||||
|
||||
// 注册截屏成功回调事件
|
||||
screenshots.on('ok', (e, buffer) => {
|
||||
const image = nativeImage.createFromBuffer(buffer);
|
||||
runnerInstance.executeHooks('ScreenCapture', {
|
||||
data: image.toDataURL(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public getCurrentWindow = (window, e) => {
|
||||
@@ -323,8 +314,12 @@ class API {
|
||||
return true;
|
||||
}
|
||||
|
||||
public screenCapture() {
|
||||
screenshots.startCapture();
|
||||
public screenCapture(arg, window) {
|
||||
screenCapture(window, (img) => {
|
||||
runnerInstance.executeHooks('ScreenCapture', {
|
||||
data: img,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@ import {
|
||||
screen,
|
||||
ipcMain,
|
||||
app,
|
||||
Notification,
|
||||
} from 'electron';
|
||||
import { screenshots } from './registerScreenshots';
|
||||
import screenCapture from '@/core/screen-capture';
|
||||
|
||||
const registerHotKey = (mainWindow: BrowserWindow): void => {
|
||||
// 设置开机启动
|
||||
@@ -79,7 +80,13 @@ const registerHotKey = (mainWindow: BrowserWindow): void => {
|
||||
});
|
||||
|
||||
globalShortcut.register(config.perf.shortCut.capture, () => {
|
||||
screenshots.startCapture();
|
||||
screenCapture(mainWindow, (data) => {
|
||||
data &&
|
||||
new Notification({
|
||||
title: '截图完成',
|
||||
body: '截图以存储到系统剪贴板中',
|
||||
}).show();
|
||||
});
|
||||
});
|
||||
|
||||
// globalShortcut.register(config.perf.shortCut.separate, () => {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import Screenshots from 'electron-screenshots';
|
||||
let screenshots;
|
||||
|
||||
const initScreenShots = () => {
|
||||
screenshots = new Screenshots();
|
||||
};
|
||||
|
||||
export { initScreenShots, screenshots };
|
||||
@@ -17,7 +17,6 @@ import '../common/utils/localPlugin';
|
||||
import '../common/utils/localConfig';
|
||||
|
||||
import registerySystemPlugin from './common/registerySystemPlugin';
|
||||
import { initScreenShots } from './common/registerScreenshots';
|
||||
|
||||
class App {
|
||||
public windowCreator: { init: () => void; getWindow: () => BrowserWindow };
|
||||
@@ -59,7 +58,6 @@ class App {
|
||||
const readyFunction = () => {
|
||||
this.createWindow();
|
||||
const mainWindow = this.windowCreator.getWindow();
|
||||
initScreenShots();
|
||||
API.init(mainWindow);
|
||||
createTray(this.windowCreator.getWindow());
|
||||
registerHotKey(this.windowCreator.getWindow());
|
||||
|
||||
Reference in New Issue
Block a user