|
@@ -5,6 +5,7 @@ import { BrowserWindow, Menu, app, dialog, ipcMain, shell } from 'electron'
|
|
|
import { electronApp, is, optimizer } from '@electron-toolkit/utils'
|
|
|
import icon from '../../resources/icon.png?asset'
|
|
|
|
|
|
+let mainWindow
|
|
|
//菜单设置
|
|
|
const menu = Menu.buildFromTemplate([
|
|
|
{
|
|
@@ -41,7 +42,7 @@ const menu = Menu.buildFromTemplate([
|
|
|
Menu.setApplicationMenu(menu)
|
|
|
|
|
|
function createWindow() {
|
|
|
- const mainWindow = new BrowserWindow({
|
|
|
+ mainWindow = new BrowserWindow({
|
|
|
width: 900,
|
|
|
height: 670,
|
|
|
center: true,
|
|
@@ -80,42 +81,14 @@ app.whenReady().then(() => {
|
|
|
|
|
|
// Open file
|
|
|
app.on('open-file', (event, url) => {
|
|
|
- //event.preventDefault()
|
|
|
- /*if (process.platform === 'win32') {
|
|
|
- process.argv.push(url)
|
|
|
- const argv = process.argv
|
|
|
- const filePath = argv[argv.length - 1]
|
|
|
+ event.preventDefault()
|
|
|
+ if (process.platform === 'darwin') {
|
|
|
BrowserWindow.getFocusedWindow().webContents.send('open-file-vue', {
|
|
|
- data: 'win',
|
|
|
- argv: argv,
|
|
|
- file: filePath,
|
|
|
+ data: url,
|
|
|
})
|
|
|
- }*/
|
|
|
- BrowserWindow.getFocusedWindow().webContents.send('open-file-vue', {
|
|
|
- data: url,
|
|
|
- })
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
- //禁止多开 点击打开原来应用
|
|
|
- if (!app.requestSingleInstanceLock()) {
|
|
|
- app.quit()
|
|
|
- } else {
|
|
|
- // 有人试图运行第二个实例,我们应该关注我们的窗口
|
|
|
- app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
|
|
|
- BrowserWindow.getFocusedWindow().webContents.send('open-file-second', {
|
|
|
- commandLine: commandLine,
|
|
|
- workingDirectory: workingDirectory,
|
|
|
- additionalData: additionalData,
|
|
|
- })
|
|
|
- /*const win = BrowserWindow.getFocusedWindow().webContents
|
|
|
- if (win) {
|
|
|
- if (win.isMaximized()) win.restore()
|
|
|
- if (!win.isVisible()) win.show()
|
|
|
- win.focus()
|
|
|
- }*/
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
// IPC showOpenDialog
|
|
|
ipcMain.handle('showOpenDialog', async (event, options) => {
|
|
|
return new Promise((resolve) => {
|
|
@@ -162,13 +135,39 @@ app.whenReady().then(() => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- createWindow()
|
|
|
+ //禁止多开 点击打开原来应用
|
|
|
+ if (!app.requestSingleInstanceLock()) {
|
|
|
+ app.quit()
|
|
|
+ } else {
|
|
|
+ createWindow()
|
|
|
+ // 有人试图运行第二个实例,我们应该关注我们的窗口
|
|
|
+ app.on('second-instance', (event, argv) => {
|
|
|
+ if (process.platform !== 'darwin') {
|
|
|
+ const url = argv[argv.length - 1]
|
|
|
+ if (!mainWindow) {
|
|
|
+ createWindow()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (mainWindow?.isMinimized()) {
|
|
|
+ mainWindow?.restore()
|
|
|
+ }
|
|
|
+ if (mainWindow?.isVisible()) {
|
|
|
+ mainWindow?.show()
|
|
|
+ }
|
|
|
+ mainWindow.focus()
|
|
|
+ mainWindow.webContents.send('open-file-vue', { data: url })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
app.on('activate', function () {
|
|
|
- if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
|
+ if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
+ createWindow()
|
|
|
+ }
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+
|
|
|
app.on('will-quit', () => {
|
|
|
if (process.platform !== 'darwin') {
|
|
|
app.quit()
|