123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- const { app, BrowserWindow, BrowserView, Tray, Menu, nativeImage, screen } = require('electron')
- const child_process = require('child_process');
- const { exec } = child_process
- const { error } = require('console');
- const { stdout, stderr, argv0 } = require('process');
- const path = require('path')
- const { createPort, getRunPort } = require('./server/index')
- app.disableHardwareAcceleration();
- app.commandLine.appendSwitch('use-angle', 'd3d9');
- function createWindow (port) {
- const { width, height } = screen.getPrimaryDisplay().workAreaSize;
- const mainWindow = new BrowserWindow({
- width: width,
- height: height,
-
-
- focusable: true,
- useContentSize: true,
- menuBarVisible : false,
- enableLargerThanScreen: true,
- autoHideMenuBar: true,
- icon: 'logo.png',
- webPreferences: {
- contextIsolation: false,
-
-
- nodeIntegration: true,
-
-
-
- }
- });
- const { setTimeout } = require('timers')
- createPort((port) => {
- setTimeout(() => {
- var view = new BrowserView()
- mainWindow.setBrowserView(view)
- view.setBounds({x: 0,y: 0, width: width , height: height})
- view.setAutoResize({width: true, height: true})
- view.useContentSize = true
- view.webContents.loadURL('http://localhost:' + port + '/html')
- }, 1000)
-
- mainWindow.on('closed', () => {
- console.log('mainWindow ---closed', );
- closePort(port)
- });
- })
-
- }
- app.on('ready', () => {
- createWindow()
- })
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit()
- }
- console.log('window-all-closed active');
- })
- app.on('activate', () => {
- app.setName('中德智慧思维芯资源库')
- if (BrowserWindow.getAllWindows().length === 0) {
- }
- })
- function closePort(port) {
-
- exec(`netstat -ano | findstr :${port}`, (error, stdout, stderr) => {
- if (error) {
- console.error(`exec error: ${error}`);
- return;
- }
- if (!stdout) {
- console.log(`prop ${port} not has`);
- return;
- }
-
- const lines = stdout.trim().split('\n');
- lines.forEach(line => {
- const parts = line.trim().split(/\s+/);
- const pid = parts[parts.length - 1];
- console.log(`port ${port} PID is ${pid} progress has`);
-
- exec(`taskkill /F /PID ${pid}`, (error, stdout, stderr) => {
- if (error) {
- console.error(`unstop PID: ${pid} - ${error}`);
- return;
- }
- console.log(`success stop PID: ${pid}`);
- });
- });
- });
- }
|