|
|
@@ -5,6 +5,34 @@ let win; let
|
|
|
loadingWin
|
|
|
Menu.setApplicationMenu(null) // 去掉菜单栏
|
|
|
app.commandLine.appendSwitch('wm-window-animations-disabled') // 拖动闪屏
|
|
|
+
|
|
|
+
|
|
|
+// 截图
|
|
|
+function screenShot() {
|
|
|
+ return new Promise((res, rej) => {
|
|
|
+ const file = execFile(`${path.resolve(__dirname, 'screen/PrintScr.exe')}`)
|
|
|
+ file.on('exit', (e) => {
|
|
|
+ if (e === 1) {
|
|
|
+ // 剪切板读buffer图片
|
|
|
+ const clip = clipboard.readImage()
|
|
|
+ if (clip.isEmpty()) {
|
|
|
+ // eslint-disable-next-line prefer-promise-reject-errors
|
|
|
+ rej(null)
|
|
|
+ } else {
|
|
|
+ // 转成buffer base64
|
|
|
+ const png = clipboard.readImage().toPNG()
|
|
|
+ const img = 'data:image/png;base64,' + png.toString('base64')
|
|
|
+ res(img)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // eslint-disable-next-line prefer-promise-reject-errors
|
|
|
+ rej(null)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// 创建loading 窗口
|
|
|
const showLoading = () => {
|
|
|
loadingWin = new BrowserWindow({
|
|
|
@@ -55,6 +83,14 @@ app.on('ready', async () => {
|
|
|
loadingWin.close()
|
|
|
win.show()
|
|
|
})
|
|
|
+ // 监听截图
|
|
|
+ ipcMain.once('screen', () => {
|
|
|
+ screenShot().then(res => {
|
|
|
+ if (!res) return
|
|
|
+ // 发送到子进程
|
|
|
+ win.webContents.send('screenData', res)
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
app.on('window-all-closed', () => {
|