提交 652a82c1 编写于 作者: m0_58228130's avatar m0_58228130

Merge remote-tracking branch 'origin/main' into main

...@@ -2580,6 +2580,11 @@ ...@@ -2580,6 +2580,11 @@
} }
} }
}, },
"electron-log": {
"version": "4.4.6",
"resolved": "https://registry.npmmirror.com/electron-log/-/electron-log-4.4.6.tgz",
"integrity": "sha512-nirYgRdY+F+vclr8ijdwy2vW03IzFpDHTaKNWu76dEN21Y76+smcES5knS7cgHUUB0qNLOi8vZO36taakjbSXA=="
},
"electron-notarize": { "electron-notarize": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmmirror.com/electron-notarize/-/electron-notarize-1.1.1.tgz", "resolved": "https://registry.npmmirror.com/electron-notarize/-/electron-notarize-1.1.1.tgz",
...@@ -2636,7 +2641,7 @@ ...@@ -2636,7 +2641,7 @@
"dependencies": { "dependencies": {
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmmirror.com/debug/download/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true, "dev": true,
"requires": { "requires": {
...@@ -3565,7 +3570,7 @@ ...@@ -3565,7 +3570,7 @@
"dependencies": { "dependencies": {
"debug": { "debug": {
"version": "3.2.7", "version": "3.2.7",
"resolved": "https://registry.npmmirror.com/debug/-/debug-3.2.7.tgz", "resolved": "https://registry.npmmirror.com/debug/download/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dev": true, "dev": true,
"requires": { "requires": {
...@@ -3660,7 +3665,7 @@ ...@@ -3660,7 +3665,7 @@
"dependencies": { "dependencies": {
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmmirror.com/debug/download/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true, "dev": true,
"requires": { "requires": {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
"style-loader": "^3.3.1" "style-loader": "^3.3.1"
}, },
"dependencies": { "dependencies": {
"electron-log": "^4.4.6",
"electron-squirrel-startup": "^1.0.0" "electron-squirrel-startup": "^1.0.0"
} }
} }
const logger = require('electron-log');
logger.transports.file.resolvePath = () => require("path").join(require("os").homedir(), 'ztf', 'log', 'electron.log');
export function logInfo(str) {
logger.info(str);
}
export function logErr(str) {
logger.error(str);
}
import {app, BrowserWindow} from 'electron'; import {app, BrowserWindow} from 'electron';
import {getUIServerUrl, startZtfServer, killZtfServer} from './services'; import {getUIServerUrl, startZtfServer, killZtfServer} from './service';
import {logInfo, logErr} from './log';
// Handle creating/removing shortcuts on Windows when installing/uninstalling. // Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
...@@ -24,7 +25,6 @@ const createWindow = (url) => { ...@@ -24,7 +25,6 @@ const createWindow = (url) => {
mainWindow.webContents.openDevTools({mode: 'bottom'}); mainWindow.webContents.openDevTools({mode: 'bottom'});
}; };
let _starting = false; let _starting = false;
async function startApp() { async function startApp() {
...@@ -35,16 +35,16 @@ async function startApp() { ...@@ -35,16 +35,16 @@ async function startApp() {
try { try {
const ztfServerUrl = await startZtfServer(); const ztfServerUrl = await startZtfServer();
console.log(`>> ZTF Server started successfully: ${ztfServerUrl}`); logInfo(`>> ZTF Server started successfully: ${ztfServerUrl}`);
} catch (error) { } catch (error) {
console.error('>> Start ztf server failed: ' + error); logErr('>> Start ztf server failed: ' + error);
process.exit(1); process.exit(1);
return; return;
} }
const url = await getUIServerUrl(); const url = await getUIServerUrl();
console.log('>> UI server url is', url); logInfo(`>> UI server url is ${url}`);
createWindow(url); createWindow(url);
......
...@@ -3,6 +3,7 @@ import {spawn} from 'child_process'; ...@@ -3,6 +3,7 @@ import {spawn} from 'child_process';
import os from 'os'; import os from 'os';
import {app} from 'electron'; import {app} from 'electron';
import express from 'express'; import express from 'express';
import {logInfo, logErr} from './log';
const DEBUG = process.env.NODE_ENV === 'development'; const DEBUG = process.env.NODE_ENV === 'development';
...@@ -10,7 +11,7 @@ let _ztfServerProcess; ...@@ -10,7 +11,7 @@ let _ztfServerProcess;
export function startZtfServer() { export function startZtfServer() {
if (process.env.SKIP_SERVER) { if (process.env.SKIP_SERVER) {
console.log(`>> Skip to start ZTF Server by env "SKIP_SERVER=${process.env.SKIP_SERVER}".`); logInfo(`>> Skip to start ZTF Server by env "SKIP_SERVER=${process.env.SKIP_SERVER}".`);
return Promise.resolve(); return Promise.resolve();
} }
if (_ztfServerProcess) { if (_ztfServerProcess) {
...@@ -29,13 +30,13 @@ export function startZtfServer() { ...@@ -29,13 +30,13 @@ export function startZtfServer() {
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const cwd = process.env.SERVER_CWD_PATH || path.dirname(serverExePath); const cwd = process.env.SERVER_CWD_PATH || path.dirname(serverExePath);
console.log(`>> Starting ZTF Server from exe path with command "${serverExePath} -P 8085" in "${cwd}"...`); logInfo(`>> Starting ZTF Server from exe path with command "${serverExePath} -P 8085" in "${cwd}"...`);
const cmd = spawn(serverExePath, ['-P', '8085'], { const cmd = spawn(serverExePath, ['-P', '8085'], {
cwd, cwd,
shell: true, shell: true,
}); });
cmd.on('close', (code) => { cmd.on('close', (code) => {
console.log(`>> ZTF server closed with code ${code}`); logInfo(`>> ZTF server closed with code ${code}`);
_ztfServerProcess = null; _ztfServerProcess = null;
cmd.kill() cmd.kill()
}); });
...@@ -45,7 +46,7 @@ export function startZtfServer() { ...@@ -45,7 +46,7 @@ export function startZtfServer() {
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
const line = lines[i]; const line = lines[i];
if (DEBUG) { if (DEBUG) {
console.log('\t', line); logInfo('\t' + line);
} }
if (line.includes('Now listening on: http')) { if (line.includes('Now listening on: http')) {
resolve(line.split('Now listening on:')[1].trim()); resolve(line.split('Now listening on:')[1].trim());
...@@ -75,13 +76,13 @@ export function startZtfServer() { ...@@ -75,13 +76,13 @@ export function startZtfServer() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const cwd = process.env.SERVER_CWD_PATH || path.resolve(app.getAppPath(), '../'); const cwd = process.env.SERVER_CWD_PATH || path.resolve(app.getAppPath(), '../');
console.log(`>> Starting ZTF development server from source with command "go run cmd/server/main.go -P 8085" in "${cwd}"`); logInfo(`>> Starting ZTF development server from source with command "go run cmd/server/main.go -P 8085" in "${cwd}"`);
const cmd = spawn('go', ['run', 'main.go', '-P', '8085'], { const cmd = spawn('go', ['run', 'main.go', '-P', '8085'], {
cwd, cwd,
shell: true, shell: true,
}); });
cmd.on('close', (code) => { cmd.on('close', (code) => {
console.log(`>> ZTF server closed with code ${code}`); logInfo(`>> ZTF server closed with code ${code}`);
_ztfServerProcess = null; _ztfServerProcess = null;
}); });
cmd.stdout.on('data', data => { cmd.stdout.on('data', data => {
...@@ -90,7 +91,7 @@ export function startZtfServer() { ...@@ -90,7 +91,7 @@ export function startZtfServer() {
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
const line = lines[i]; const line = lines[i];
if (DEBUG) { if (DEBUG) {
console.log('\t', line); logInfo('\t' + line);
} }
if (line.includes('Now listening on: http')) { if (line.includes('Now listening on: http')) {
resolve(line.split('Now listening on:')[1].trim()); resolve(line.split('Now listening on:')[1].trim());
...@@ -139,7 +140,7 @@ export function getUIServerUrl() { ...@@ -139,7 +140,7 @@ export function getUIServerUrl() {
} }
const port = process.env.UI_SERVER_PORT || 8000; const port = process.env.UI_SERVER_PORT || 8000;
console.log(`>> Starting UI serer at ${uiServerUrl} with port ${port}`); logInfo(`>> Starting UI serer at ${uiServerUrl} with port ${port}`);
const uiServer = express(); const uiServer = express();
uiServer.use(express.static(uiServerUrl)); uiServer.use(express.static(uiServerUrl));
...@@ -149,7 +150,7 @@ export function getUIServerUrl() { ...@@ -149,7 +150,7 @@ export function getUIServerUrl() {
_uiServerApp = null; _uiServerApp = null;
reject(serverError); reject(serverError);
} else { } else {
console.log(`>> UI server started successfully on http://localhost:${port}.`); logInfo(`>> UI server started successfully on http://localhost:${port}.`);
resolve(`http://localhost:${port}`); resolve(`http://localhost:${port}`);
} }
}); });
...@@ -162,7 +163,7 @@ export function getUIServerUrl() { ...@@ -162,7 +163,7 @@ export function getUIServerUrl() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const cwd = path.resolve(app.getAppPath(), '../ui'); const cwd = path.resolve(app.getAppPath(), '../ui');
console.log(`>> Starting UI development server with command "npm run serve" in "${cwd}"...`); logInfo(`>> Starting UI development server with command "npm run serve" in "${cwd}"...`);
let resolved = false; let resolved = false;
const cmd = spawn('npm', ['run', 'serve'], { const cmd = spawn('npm', ['run', 'serve'], {
...@@ -170,7 +171,7 @@ export function getUIServerUrl() { ...@@ -170,7 +171,7 @@ export function getUIServerUrl() {
shell: true, shell: true,
}); });
cmd.on('close', (code) => { cmd.on('close', (code) => {
console.log(`>> ZTF server closed with code ${code}`); logInfo(`>> ZTF server closed with code ${code}`);
_uiServerApp = null; _uiServerApp = null;
}); });
cmd.stdout.on('data', data => { cmd.stdout.on('data', data => {
...@@ -182,15 +183,15 @@ export function getUIServerUrl() { ...@@ -182,15 +183,15 @@ export function getUIServerUrl() {
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
const line = lines[i]; const line = lines[i];
if (DEBUG) { if (DEBUG) {
console.log('\t', line); logInfo('\t' + line);
} }
if (line.includes('App running at:')) { if (line.includes('App running at:')) {
const nextLine = lines[i + 1] || lines[i + 2]; const nextLine = lines[i + 1] || lines[i + 2];
if (DEBUG) { if (DEBUG) {
console.log('\t', nextLine); logInfo('\t' + nextLine);
} }
if (!nextLine) { if (!nextLine) {
console.error('\t', `Cannot grabing running address after line "${line}".`); console.error('\t' + `Cannot grabing running address after line "${line}".`);
throw new Error(`Cannot grabing running address after line "${line}".`); throw new Error(`Cannot grabing running address after line "${line}".`);
} }
const url = nextLine.split('Local: ')[1]; const url = nextLine.split('Local: ')[1];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册