:spark: 支持系统截屏功能

This commit is contained in:
muwoo
2023-04-04 11:13:38 +08:00
parent 9ee8d78b1b
commit 2cd70bd386
12 changed files with 197 additions and 66 deletions

View File

@@ -15,6 +15,7 @@ import { LocalDb } 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'));
@@ -33,6 +34,14 @@ 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) => {
@@ -313,6 +322,10 @@ class API {
shell.beep();
return true;
}
public screenCapture() {
screenshots.startCapture();
}
}
export default new API();

View File

@@ -5,8 +5,9 @@ import {
BrowserView,
screen,
ipcMain,
app
} from "electron";
app,
} from 'electron';
import { screenshots } from './registerScreenshots';
const registerHotKey = (mainWindow: BrowserWindow): void => {
// 设置开机启动
@@ -14,7 +15,7 @@ const registerHotKey = (mainWindow: BrowserWindow): void => {
const config = global.OP_CONFIG.get();
app.setLoginItemSettings({
openAtLogin: config.perf.common.start,
openAsHidden: true
openAsHidden: true,
});
};
// 设置暗黑模式
@@ -22,7 +23,7 @@ const registerHotKey = (mainWindow: BrowserWindow): void => {
const config = global.OP_CONFIG.get();
const isDark = config.perf.common.darkMode;
if (isDark) {
nativeTheme.themeSource = "dark";
nativeTheme.themeSource = 'dark';
mainWindow.webContents.executeJavaScript(
`document.body.classList.add("dark");window.rubick.theme="dark"`
);
@@ -32,7 +33,7 @@ const registerHotKey = (mainWindow: BrowserWindow): void => {
);
});
} else {
nativeTheme.themeSource = "light";
nativeTheme.themeSource = 'light';
mainWindow.webContents.executeJavaScript(
`document.body.classList.remove("dark");window.rubick.theme="light"`
);
@@ -71,12 +72,16 @@ const registerHotKey = (mainWindow: BrowserWindow): void => {
mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
mainWindow.focus();
mainWindow.setVisibleOnAllWorkspaces(false, {
visibleOnFullScreen: true
visibleOnFullScreen: true,
});
mainWindow.setPosition(wx, wy);
mainWindow.show();
});
globalShortcut.register(config.perf.shortCut.capture, () => {
screenshots.startCapture();
});
// globalShortcut.register(config.perf.shortCut.separate, () => {
//
// });
@@ -87,15 +92,15 @@ const registerHotKey = (mainWindow: BrowserWindow): void => {
});
// 注册自定义全局快捷键
config.global.forEach(sc => {
config.global.forEach((sc) => {
if (!sc.key || !sc.value) return;
globalShortcut.register(sc.key, () => {
mainWindow.webContents.send("global-short-key", sc.value);
mainWindow.webContents.send('global-short-key', sc.value);
});
});
};
init();
ipcMain.on("re-register", () => {
ipcMain.on('re-register', () => {
init();
});
};

View File

@@ -0,0 +1,8 @@
import Screenshots from 'electron-screenshots';
let screenshots;
const initScreenShots = () => {
screenshots = new Screenshots();
};
export { initScreenShots, screenshots };