Skip to content

Commit

Permalink
fixed a bug where the server child-process would not terminate when G…
Browse files Browse the repository at this point in the history
…LIMPSE is closed on MacOS
  • Loading branch information
[email protected] committed Feb 17, 2025
1 parent 8913afc commit d53cc83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Binary file added glimpse/assets/GLIMPSE_color_icon.ico
Binary file not shown.
9 changes: 7 additions & 2 deletions glimpse/electron-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ win:
arch:
- x64
mac:
icon: ./assets/GLIMPSE_color_icon.ico
target:
- target: pkg
arch:
- arm64

linux:
target:
- deb
- tar.gz
- target: deb
arch:
- x64
- target: tar.gz
arch:
- x64
maintainer: "[email protected]"
vendor: "pnnl"
synopsis: "GLIMPSE is a graph-based web application to visualize and update distribution power grid models."
Expand Down
34 changes: 20 additions & 14 deletions glimpse/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
nativeImage,
Notification,
} = require("electron");
const { execFile, spawn } = require("child_process");
const { spawn } = require("child_process");
const path = require("path");
const { io } = require("socket.io-client");
const fs = require("fs");
Expand All @@ -25,6 +25,7 @@ if (!app.isPackaged) {

const jsonUploadSchema = require("./schemas/json_upload.schema.json");
const themeUploadSchema = require("./schemas/theme_upload.schema.json");
const { kill } = require("process");
const socket = io("http://127.0.0.1:5051");
const isMac = process.platform === "darwin";
let mainWindow = null;
Expand Down Expand Up @@ -419,32 +420,37 @@ const makeSplashWindow = () => {
};

const initiateServer = () => {
let serverProcess = null;
const serverExecutableName =
process.platform === "linux" || process.platform === "darwin" ? "server" : "server.exe";

const serverExecutablePath = path.join(rootDir, "local-server", "server", serverExecutableName);

if (fs.existsSync(serverExecutablePath)) {
try {
execFile(serverExecutablePath, (error, stdout, stderr) => {
if (error) throw error;
if (stderr) throw stderr;
console.log(stdout);
});
} catch (error) {
console.log(error);
return;
}
serverProcess = spawn(serverExecutablePath);
serverProcess.stdout.on("data", (data) => {
console.log(data.toString("utf8"));
});
serverProcess.stderr.on("data", (data) => {
console.error(`Server error: ${data}`);
});
} else {
const python = spawn("python", [path.join(__dirname, "local-server", "server.py")]);
python.stdout.on("data", (data) => {
serverProcess = spawn("python", [path.join(__dirname, "local-server", "server.py")]);
serverProcess.stdout.on("data", (data) => {
console.log("data: ", data.toString("utf8"));
// console.log("data: ", data);
});
python.stderr.on("data", (data) => {
serverProcess.stderr.on("data", (data) => {
console.log(`log: ${data}`); // when error
});
}

app.on("before-quit", () => {
if (serverProcess) {
serverProcess.kill("SIGTERM");
serverProcess = null;
}
});
};

app.whenReady()
Expand Down

0 comments on commit d53cc83

Please sign in to comment.