From 5d912947c883b162026939a367bfe81cc35d2bbc Mon Sep 17 00:00:00 2001 From: he wei <858544502@qq.com> Date: 星期二, 22 三月 2022 17:13:55 +0800 Subject: [PATCH] UA 整理提交 --- src/main/demo/src/background.js | 52 ++++++++++++++++++++++++++++++++-------------------- 1 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/main/demo/src/background.js b/src/main/demo/src/background.js index 0f06276..21c468e 100644 --- a/src/main/demo/src/background.js +++ b/src/main/demo/src/background.js @@ -3,12 +3,31 @@ import { app, protocol, BrowserWindow, Menu } from 'electron' import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' const isDevelopment = process.env.NODE_ENV !== 'production' +let win = null; + +// 鍗曚緥閿� +const gotTheLock = app.requestSingleInstanceLock() + +if (!gotTheLock) { + app.quit() +} else { + app.on('second-instance', (event, commandLine, workingDirectory) => { + // 褰撹繍琛岀浜屼釜瀹炰緥鏃�,灏嗕細鑱氱劍鍒癿yWindow杩欎釜绐楀彛 + if (win) { + if (win.isMinimized()) win.restore() + win.focus() + } + }) + +} // Scheme must be registered before the app is ready protocol.registerSchemesAsPrivileged([ { scheme: 'app', privileges: { secure: true, standard: true } } ]) + +let appUrl = 'http://localhost:8099/test/hello'; const platform = process.platform let appStarted = false let serverProcess @@ -16,25 +35,19 @@ serverProcess = true } else { if (platform === 'win32') { - let pathArr = app.getPath('exe').split('\\'); - pathArr.length = pathArr.length - 1; - let path = pathArr.join('\\'); - // require('child_process').spawn('cmd.exe', ['/c', 'echo '+path+' > 123.txt']); + // let pathArr = app.getPath('exe').split('\\'); + // pathArr.length = pathArr.length - 1; + // let path = pathArr.join('\\'); + // require('child_process').spawn('cmd.exe', ['/c', 'echo '+app.getAppPath()+ '===========' + __dirname +'===========' + __filename +'===========' + __static + ' >> 123.txt']); // serverProcess = require('child_process').spawn('cmd.exe', ['/c', 'testElectronJ.bat'], { // cwd: path + '/bundled/bin' // }) - serverProcess = require('child_process').spawn('app_x64.exe', { - cwd: path + '/bundled' - }) - } else { - const chmod = require('child_process').spawn('chmod', ['+x', app.getAppPath() + "/bin/testElectronJ"]); - chmod.on('close', (code => { - const chmod2 = require('child_process').spawn('chmod', ['+x', app.getAppPath() + "/runtime/bin/java"]); - chmod2.on('close', () => { - serverProcess = require('child_process').spawn(app.getAppPath() + "/bin/testElectronJ") - }) - })) + serverProcess = require('child_process').execFile(__dirname + '/app_x64.exe'); + // serverProcess = require('child_process').spawn('cmd.exe', ['/c', 'testElectronJ.bat'], { + // cwd: __dirname + '/bin' + // // cwd: app.getAppPath() + '/bin' + // }); } } if (!isDevelopment) { @@ -42,10 +55,10 @@ } async function createWindow() { // Create the browser window. - const win = new BrowserWindow({ - width: 800, - height: 600, - icon: `${__static}/icon/1.png`, + win = new BrowserWindow({ + width: 1200, + height: 800, + icon: `${__static}/icon/icon.png`, webPreferences: { webSecurity: false, // Use pluginOptions.nodeIntegration, leave this alone @@ -107,7 +120,6 @@ // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -let appUrl = 'http://localhost:8099/test/hello'; const startUp = function () { const requestPromise = require('minimal-request-promise') -- Gitblit v1.9.1