From 5454d5cebaa9400174ea78b8d8e91d30a37956e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=85=E8=88=AA?= <602869941@qq.com> Date: Tue, 13 Aug 2024 15:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 4e8968f..0d0fc20 100644 --- a/main.js +++ b/main.js @@ -11,7 +11,8 @@ const { desktopCapturer, } = require('electron'); const path = require('node:path') -const { autoUpdater, CancellationToken } = require('electron-updater'); +const fs = require('fs'); +const {autoUpdater, CancellationToken} = require('electron-updater'); const cancellationToken = new CancellationToken() app.allowRendererProcessReuse = false; let mainWindow = null; @@ -33,7 +34,7 @@ class AppWindow extends BrowserWindow { backgroundColor: '#00000000', transparent: true, }; - const finalConfig = { ...basicConfig, ...config }; + const finalConfig = {...basicConfig, ...config}; super(finalConfig); const env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1]; if (env === 'development') { @@ -64,9 +65,11 @@ function showWindow() { createWindow(); } } + function quit() { app.quit() } + function createTray() { const iconPath = `${__dirname}/src/assets/icon.png`; const trayIcon = nativeImage.createFromPath(iconPath); @@ -132,6 +135,15 @@ app.on('ready', () => { createWindow() updateHandle() // 检查更新 createTray() + // 获取当前脚本所在目录的绝对路径 + const currentDirectory = __dirname; + // 获取安装父目录 + const parentDirectory = path.resolve(currentDirectory, '../..'); + const customFolderPath = path.join(parentDirectory, 'Downloads'); + if (!fs.existsSync(customFolderPath)) { + // 如果不存在,则创建文件夹 + fs.mkdirSync(customFolderPath); + } // 监听f12打开控制台 mainWindow.webContents.on('before-input-event', (event, input) => { if (input.key === 'F12') { @@ -235,7 +247,7 @@ app.on('ready', () => { mainWindow.setMinimumSize(config.width, config.height); // 设置最大尺寸 const primaryDisplay = screen.getPrimaryDisplay() - const { width, height } = primaryDisplay.workAreaSize + const {width, height} = primaryDisplay.workAreaSize if (config.key === 'login') { mainWindow.setMaximumSize(config.width, config.height); } else { @@ -244,7 +256,7 @@ app.on('ready', () => { // 设置窗口尺寸 mainWindow.setSize(config.width, config.height) // 设置窗口位置使其居中于当前屏幕 - const display = screen.getDisplayMatching({ ...mainWindow.getBounds() }); + const display = screen.getDisplayMatching({...mainWindow.getBounds()}); const x = Math.round((display.workArea.width - mainWindow.getSize()[0]) / 2); const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2); mainWindow.setPosition(x, y); @@ -271,7 +283,7 @@ function updateHandle() { sendUpdateMessage(message.checking) }) autoUpdater.on('update-available', function (info) { - let messageStr = JSON.stringify({ type: '0' }) + let messageStr = JSON.stringify({type: '0'}) setTimeout(() => { sendUpdateMessage(messageStr) }, 5000)