perf: Windows客户端无法关闭的情况
This commit is contained in:
parent
b695f90ded
commit
32f4446868
1
electron/.gitignore
vendored
1
electron/.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
public/
|
public/
|
||||||
|
package-bak.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
|
||||||
build/
|
build/
|
||||||
|
48
electron/build.js
vendored
48
electron/build.js
vendored
@ -1,4 +1,5 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const fse = require('fs-extra');
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const inquirer = require('inquirer');
|
const inquirer = require('inquirer');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
@ -102,10 +103,15 @@ function rightExists(string, find) {
|
|||||||
const electronDir = path.resolve(__dirname, "public");
|
const electronDir = path.resolve(__dirname, "public");
|
||||||
const nativeCachePath = path.resolve(__dirname, ".native");
|
const nativeCachePath = path.resolve(__dirname, ".native");
|
||||||
const devloadCachePath = path.resolve(__dirname, ".devload");
|
const devloadCachePath = path.resolve(__dirname, ".devload");
|
||||||
|
const packageFile = path.resolve(__dirname, "package.json");
|
||||||
|
const packageBakFile = path.resolve(__dirname, "package-bak.json");
|
||||||
const platform = ["build-mac", "build-mac-arm", "build-win"];
|
const platform = ["build-mac", "build-mac-arm", "build-win"];
|
||||||
|
|
||||||
// 生成配置、编译应用
|
// 生成配置、编译应用
|
||||||
function step1(data, publish) {
|
function start(data, publish) {
|
||||||
|
console.log("Name: " + data.name);
|
||||||
|
console.log("AppId: " + data.id);
|
||||||
|
console.log("Version: " + config.version);
|
||||||
// config.js
|
// config.js
|
||||||
let systemInfo = {
|
let systemInfo = {
|
||||||
title: data.name,
|
title: data.name,
|
||||||
@ -113,7 +119,7 @@ function step1(data, publish) {
|
|||||||
origin: "./",
|
origin: "./",
|
||||||
apiUrl: formatUrl(data.url) + "api/",
|
apiUrl: formatUrl(data.url) + "api/",
|
||||||
}
|
}
|
||||||
fs.writeFileSync(electronDir + "/config.js", "window.systemInformation = " + JSON.stringify(systemInfo), 'utf8');
|
fs.writeFileSync(electronDir + "/config.js", "window.systemInformation = " + JSON.stringify(systemInfo, null, 2), 'utf8');
|
||||||
fs.writeFileSync(nativeCachePath, formatUrl(data.url));
|
fs.writeFileSync(nativeCachePath, formatUrl(data.url));
|
||||||
fs.writeFileSync(devloadCachePath, "", 'utf8');
|
fs.writeFileSync(devloadCachePath, "", 'utf8');
|
||||||
// index.html
|
// index.html
|
||||||
@ -121,26 +127,20 @@ function step1(data, publish) {
|
|||||||
let indexString = fs.readFileSync(indexFile, 'utf8');
|
let indexString = fs.readFileSync(indexFile, 'utf8');
|
||||||
indexString = indexString.replace(`<title></title>`, `<title>${data.name}</title>`);
|
indexString = indexString.replace(`<title></title>`, `<title>${data.name}</title>`);
|
||||||
fs.writeFileSync(indexFile, indexString, 'utf8');
|
fs.writeFileSync(indexFile, indexString, 'utf8');
|
||||||
// package.json
|
// package.json Backup
|
||||||
let packageFile = path.resolve(__dirname, "package.json");
|
fse.copySync(packageFile, packageBakFile)
|
||||||
let packageString = fs.readFileSync(packageFile, 'utf8');
|
// package.json Generated
|
||||||
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${data.name}"`);
|
const econfig = require('./package.json')
|
||||||
packageString = packageString.replace(/"appId":\s*"(.*?)"/, `"appId": "${data.id}"`);
|
econfig.name = data.name;
|
||||||
packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
econfig.version = config.version;
|
||||||
packageString = packageString.replace(/"artifactName":\s*"(.*?)"/g, '"artifactName": "' + getDomain(data.url) + '-v${version}-${os}-${arch}.${ext}"');
|
econfig.build.appId = data.id;
|
||||||
fs.writeFileSync(packageFile, packageString, 'utf8');
|
econfig.build.artifactName = getDomain(data.url) + "-v${version}-${os}-${arch}.${ext}";
|
||||||
//
|
econfig.build.nsis.artifactName = getDomain(data.url) + "-v${version}-${os}-${arch}.${ext}";
|
||||||
|
fs.writeFileSync(packageFile, JSON.stringify(econfig, null, 2), 'utf8');
|
||||||
|
// build
|
||||||
child_process.spawnSync("npm", ["run", data.platform + (publish === true ? "-publish" : "")], {stdio: "inherit", cwd: "electron"});
|
child_process.spawnSync("npm", ["run", data.platform + (publish === true ? "-publish" : "")], {stdio: "inherit", cwd: "electron"});
|
||||||
}
|
// package.json Recovery
|
||||||
|
fse.copySync(packageBakFile, packageFile)
|
||||||
// 还原配置
|
|
||||||
function step2() {
|
|
||||||
let packageFile = path.resolve(__dirname, "package.json");
|
|
||||||
let packageString = fs.readFileSync(packageFile, 'utf8');
|
|
||||||
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`);
|
|
||||||
packageString = packageString.replace(/"appId":\s*"(.*?)"/, `"appId": "${config.app.id}"`);
|
|
||||||
packageString = packageString.replace(/"artifactName":\s*"(.*?)"/g, '"artifactName": "${productName}-v${version}-${os}-${arch}.${ext}"');
|
|
||||||
fs.writeFileSync(packageFile, packageString, 'utf8');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["dev"].includes(argv[2])) {
|
if (["dev"].includes(argv[2])) {
|
||||||
@ -153,10 +153,9 @@ if (["dev"].includes(argv[2])) {
|
|||||||
config.app.sites.forEach((data) => {
|
config.app.sites.forEach((data) => {
|
||||||
if (data.name && data.id && data.url) {
|
if (data.name && data.id && data.url) {
|
||||||
data.platform = argv[2];
|
data.platform = argv[2];
|
||||||
step1(data, true)
|
start(data, true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
step2();
|
|
||||||
} else {
|
} else {
|
||||||
// 自定义编译
|
// 自定义编译
|
||||||
const questions = [
|
const questions = [
|
||||||
@ -198,14 +197,13 @@ if (["dev"].includes(argv[2])) {
|
|||||||
];
|
];
|
||||||
inquirer.prompt(questions).then(answers => {
|
inquirer.prompt(questions).then(answers => {
|
||||||
answers.platform.forEach(platform => {
|
answers.platform.forEach(platform => {
|
||||||
step1({
|
start({
|
||||||
"name": config.name,
|
"name": config.name,
|
||||||
"id": config.app.id,
|
"id": config.app.id,
|
||||||
"url": answers.website,
|
"url": answers.website,
|
||||||
"platform": platform
|
"platform": platform
|
||||||
}, false)
|
}, false)
|
||||||
});
|
});
|
||||||
step2();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
electron/main.js
vendored
16
electron/main.js
vendored
@ -1,7 +1,7 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const XLSX = require('xlsx');
|
const XLSX = require('xlsx');
|
||||||
const {app, BrowserWindow, ipcMain, dialog, screen} = require('electron')
|
const {app, BrowserWindow, ipcMain, dialog} = require('electron')
|
||||||
|
|
||||||
let mainWindow = null,
|
let mainWindow = null,
|
||||||
subWindow = [],
|
subWindow = [],
|
||||||
@ -47,6 +47,7 @@ function createMainWindow() {
|
|||||||
width: 1280,
|
width: 1280,
|
||||||
height: 800,
|
height: 800,
|
||||||
center: true,
|
center: true,
|
||||||
|
autoHideMenuBar: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'preload.js'),
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
@ -71,7 +72,11 @@ function createMainWindow() {
|
|||||||
if (inheritClose) {
|
if (inheritClose) {
|
||||||
mainWindow.webContents.send("windowClose", {})
|
mainWindow.webContents.send("windowClose", {})
|
||||||
} else {
|
} else {
|
||||||
app.hide();
|
if (process.platform === 'darwin') {
|
||||||
|
app.hide();
|
||||||
|
} else {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -103,6 +108,7 @@ function createSubWindow(args) {
|
|||||||
height: 800,
|
height: 800,
|
||||||
center: true,
|
center: true,
|
||||||
parent: mainWindow,
|
parent: mainWindow,
|
||||||
|
autoHideMenuBar: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'preload.js'),
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
devTools: args.devTools !== false,
|
devTools: args.devTools !== false,
|
||||||
@ -162,7 +168,11 @@ ipcMain.on('windowRouter', (event, args) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('windowHidden', (event) => {
|
ipcMain.on('windowHidden', (event) => {
|
||||||
app.hide();
|
if (process.platform === 'darwin') {
|
||||||
|
app.hide();
|
||||||
|
} else {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
event.returnValue = "ok"
|
event.returnValue = "ok"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user