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,
|
desktopCapturer,
|
||||||
} = require('electron');
|
} = require('electron');
|
||||||
const path = require('node:path')
|
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()
|
const cancellationToken = new CancellationToken()
|
||||||
app.allowRendererProcessReuse = false;
|
app.allowRendererProcessReuse = false;
|
||||||
let mainWindow = null;
|
let mainWindow = null;
|
||||||
|
|
@ -33,7 +34,7 @@ class AppWindow extends BrowserWindow {
|
||||||
backgroundColor: '#00000000',
|
backgroundColor: '#00000000',
|
||||||
transparent: true,
|
transparent: true,
|
||||||
};
|
};
|
||||||
const finalConfig = { ...basicConfig, ...config };
|
const finalConfig = {...basicConfig, ...config};
|
||||||
super(finalConfig);
|
super(finalConfig);
|
||||||
const env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1];
|
const env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1];
|
||||||
if (env === 'development') {
|
if (env === 'development') {
|
||||||
|
|
@ -64,9 +65,11 @@ function showWindow() {
|
||||||
createWindow();
|
createWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function quit() {
|
function quit() {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTray() {
|
function createTray() {
|
||||||
const iconPath = `${__dirname}/src/assets/icon.png`;
|
const iconPath = `${__dirname}/src/assets/icon.png`;
|
||||||
const trayIcon = nativeImage.createFromPath(iconPath);
|
const trayIcon = nativeImage.createFromPath(iconPath);
|
||||||
|
|
@ -132,6 +135,15 @@ app.on('ready', () => {
|
||||||
createWindow()
|
createWindow()
|
||||||
updateHandle() // 检查更新
|
updateHandle() // 检查更新
|
||||||
createTray()
|
createTray()
|
||||||
|
// 获取当前脚本所在目录的绝对路径
|
||||||
|
const currentDirectory = __dirname;
|
||||||
|
// 获取安装父目录
|
||||||
|
const parentDirectory = path.resolve(currentDirectory, '../..');
|
||||||
|
const customFolderPath = path.join(parentDirectory, 'Downloads');
|
||||||
|
if (!fs.existsSync(customFolderPath)) {
|
||||||
|
// 如果不存在,则创建文件夹
|
||||||
|
fs.mkdirSync(customFolderPath);
|
||||||
|
}
|
||||||
// 监听f12打开控制台
|
// 监听f12打开控制台
|
||||||
mainWindow.webContents.on('before-input-event', (event, input) => {
|
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||||
if (input.key === 'F12') {
|
if (input.key === 'F12') {
|
||||||
|
|
@ -235,7 +247,7 @@ app.on('ready', () => {
|
||||||
mainWindow.setMinimumSize(config.width, config.height);
|
mainWindow.setMinimumSize(config.width, config.height);
|
||||||
// 设置最大尺寸
|
// 设置最大尺寸
|
||||||
const primaryDisplay = screen.getPrimaryDisplay()
|
const primaryDisplay = screen.getPrimaryDisplay()
|
||||||
const { width, height } = primaryDisplay.workAreaSize
|
const {width, height} = primaryDisplay.workAreaSize
|
||||||
if (config.key === 'login') {
|
if (config.key === 'login') {
|
||||||
mainWindow.setMaximumSize(config.width, config.height);
|
mainWindow.setMaximumSize(config.width, config.height);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -244,7 +256,7 @@ app.on('ready', () => {
|
||||||
// 设置窗口尺寸
|
// 设置窗口尺寸
|
||||||
mainWindow.setSize(config.width, config.height)
|
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 x = Math.round((display.workArea.width - mainWindow.getSize()[0]) / 2);
|
||||||
const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2);
|
const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2);
|
||||||
mainWindow.setPosition(x, y);
|
mainWindow.setPosition(x, y);
|
||||||
|
|
@ -271,7 +283,7 @@ function updateHandle() {
|
||||||
sendUpdateMessage(message.checking)
|
sendUpdateMessage(message.checking)
|
||||||
})
|
})
|
||||||
autoUpdater.on('update-available', function (info) {
|
autoUpdater.on('update-available', function (info) {
|
||||||
let messageStr = JSON.stringify({ type: '0' })
|
let messageStr = JSON.stringify({type: '0'})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
sendUpdateMessage(messageStr)
|
sendUpdateMessage(messageStr)
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue