Merge branch 'master' of https://gitea.23544.com/marking/WGShare.Client.Electron
This commit is contained in:
commit
7b61a073bd
22
main.js
22
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue