提交
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
import { app, shell, BrowserWindow, ipcMain, globalShortcut } from 'electron'
|
||||
import { app, shell, BrowserWindow, ipcMain, globalShortcut, dialog } from 'electron'
|
||||
import path, { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/earth.png?asset'
|
||||
import fs from 'fs'
|
||||
import { exec } from 'child_process'
|
||||
|
||||
const { exec } = require('child_process');
|
||||
|
||||
// 开发环境路径处理 - 确保添加正确的file协议
|
||||
const devSplashPath = path.resolve(
|
||||
@ -53,6 +53,11 @@ if (prodSplashPath) {
|
||||
|
||||
// 最终的启动页URL
|
||||
const splashURL = process.env.NODE_ENV === 'development' ? devSplashURL : prodSplashURL
|
||||
let startBatPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'java', 'start.bat')
|
||||
startBatPath = process.platform === 'win32' ? startBatPath.replace(/^(\w:)/, '/$1') : startBatPath
|
||||
let stopBatPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'java', 'stop.bat')
|
||||
stopBatPath = process.platform === 'win32' ? stopBatPath.replace(/^(\w:)/, '/$1') : stopBatPath
|
||||
|
||||
// const splashURL =
|
||||
// process.env.NODE_ENV === 'development'
|
||||
// ? `${join(app.getAppPath(), 'src/renderer/public/startUp/startUp.html')}`
|
||||
@ -126,6 +131,23 @@ function createWindow(): void {
|
||||
}, 200)
|
||||
})
|
||||
})
|
||||
ipcMain.on("open-directory-dialog", (event, option) => {
|
||||
// @ts-ignore
|
||||
dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
||||
properties: option.properties,
|
||||
filters: option.filters,
|
||||
})
|
||||
.then((files) => {
|
||||
let arr = [];
|
||||
if (!files.canceled) {
|
||||
files.filePaths.forEach((url) => {
|
||||
// @ts-ignore
|
||||
arr.push(url.replace(/\\/g, "/"));
|
||||
});
|
||||
}
|
||||
event.sender.send("selectedItem", arr);
|
||||
});
|
||||
});
|
||||
// 设置窗口标题和图标
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
@ -156,6 +178,26 @@ function createWindow(): void {
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
// alert(devSplashURL)
|
||||
// alert(prodSplashURL)
|
||||
// dialog.showMessageBox({
|
||||
// type: 'info',
|
||||
// title: '信息1',
|
||||
// message: devSplashURL,
|
||||
// buttons: ['确定']
|
||||
// })
|
||||
// 执行批处理文件
|
||||
exec(startBatPath.substring(1, 200), (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`执行错误: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(`错误输出: ${stderr}`);
|
||||
return;
|
||||
}
|
||||
console.log(`批处理输出: ${stdout}`);
|
||||
});
|
||||
// Set app user model id for windows
|
||||
electronApp.setAppUserModelId('com.electron')
|
||||
|
||||
@ -189,6 +231,18 @@ app.on('window-all-closed', () => {
|
||||
// 退出时注销所有快捷键
|
||||
app.on('will-quit', () => {
|
||||
globalShortcut.unregisterAll()
|
||||
// 关闭后台服务
|
||||
exec(stopBatPath.substring(1, 200), (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`执行错误: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(`错误输出: ${stderr}`);
|
||||
return;
|
||||
}
|
||||
console.log(`批处理输出: ${stdout}`);
|
||||
});
|
||||
})
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
|
||||
Reference in New Issue
Block a user