|
@@ -1,5 +1,5 @@
|
|
|
// Modules to control application life and create native browser window
|
|
// Modules to control application life and create native browser window
|
|
|
-const {app, ipcMain, BrowserWindow, session} = require('electron')
|
|
|
|
|
|
|
+const {app, ipcMain, BrowserWindow, session, dialog } = require('electron')
|
|
|
const path = require('path')
|
|
const path = require('path')
|
|
|
const fs = require('fs')
|
|
const fs = require('fs')
|
|
|
const iconv = require('iconv-lite');
|
|
const iconv = require('iconv-lite');
|
|
@@ -892,6 +892,49 @@ ipcMain.on("download", (event, message) => {
|
|
|
event.returnValue = {err: 0}
|
|
event.returnValue = {err: 0}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+// 网页截屏
|
|
|
|
|
+ipcMain.on('capture', async (event, options = {}) => {
|
|
|
|
|
+ console.log('收到截图请求,静默保存');
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const targetWindow = BrowserWindow.getFocusedWindow() || mainWindow;
|
|
|
|
|
+ if (!targetWindow) {
|
|
|
|
|
+ console.error('没有找到可用的窗口');
|
|
|
|
|
+ event.reply('capture-error', '没有找到可用的窗口');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 截取整个页面
|
|
|
|
|
+ const image = await targetWindow.webContents.capturePage();
|
|
|
|
|
+
|
|
|
|
|
+ // 固定保存路径 - 不再弹出对话框
|
|
|
|
|
+ const baseDir = app.isPackaged
|
|
|
|
|
+ ? path.dirname(app.getPath('exe'))
|
|
|
|
|
+ : process.cwd();
|
|
|
|
|
+
|
|
|
|
|
+ const downloadDir = path.join(baseDir, 'screenshots');
|
|
|
|
|
+
|
|
|
|
|
+ // 确保目录存在
|
|
|
|
|
+ if (!fs.existsSync(downloadDir)) {
|
|
|
|
|
+ fs.mkdirSync(downloadDir, { recursive: true });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 生成文件名(带时间戳)
|
|
|
|
|
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
|
|
|
+ const filePath = path.join(downloadDir, `screenshot-${timestamp}.png`);
|
|
|
|
|
+
|
|
|
|
|
+ // 保存文件
|
|
|
|
|
+ fs.writeFileSync(filePath, image.toPNG());
|
|
|
|
|
+
|
|
|
|
|
+ console.log('截图已静默保存到:', filePath);
|
|
|
|
|
+ event.reply('capture-success', filePath);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('截图失败:', error);
|
|
|
|
|
+ event.reply('capture-error', error.message);
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
// 窗口间通信
|
|
// 窗口间通信
|
|
|
ipcMain.on('broadcast-message', (event, message) => {
|
|
ipcMain.on('broadcast-message', (event, message) => {
|
|
|
// 获取发送者
|
|
// 获取发送者
|