Add base HTTP server that responds to IO pings.

This commit is contained in:
Patrick Fic
2025-03-25 20:47:56 -07:00
parent d9300f6bc8
commit 791c518920
6 changed files with 928 additions and 54 deletions

View File

@@ -9,10 +9,14 @@ import ipcTypes from "../util/ipcTypes.json";
import client from "./graphql/graphql-client";
import store from "./store/store";
import appIcon from "../../resources/diamond.png?asset";
import LocalServer from "./http-server/http-server";
import errorTypeCheck from "../util/errorTypeCheck";
log.initialize();
const isMac = process.platform === "darwin";
var isAppQuitting = false; //Needed on Mac as an override to allow us to fully quit the app.
let isAppQuitting = false; //Needed on Mac as an override to allow us to fully quit the app.
// Initialize the server
const localServer = new LocalServer();
function createWindow(): void {
// Create the browser window.
const { width, height, x, y } = store.get("app.windowBounds") as {
@@ -257,8 +261,17 @@ app.whenReady().then(async () => {
...ErrorTypeCheck(error),
});
}
//Create Tray
//Start the HTTP server.
// Start the local HTTP server
try {
localServer.start();
log.info("HTTP server initialized on port 1337");
} catch (error) {
log.error("Failed to start HTTP server:", errorTypeCheck(error));
}
//Create Tray
const trayicon = nativeImage.createFromPath(appIcon);
const tray = new Tray(trayicon.resize({ width: 16 }));
const contextMenu = Menu.buildFromTemplate([
@@ -279,18 +292,17 @@ app.whenReady().then(async () => {
tray.setContextMenu(contextMenu);
//Check for app updates.
autoUpdater.logger = log;
if (import.meta.env.DEV) {
// Useful for some dev/debugging tasks, but download can
// not be validated becuase dev app is not signed
autoUpdater.updateConfigPath = path.join(
__dirname,
"../../dev-app-update.yml",
);
autoUpdater.forceDevUpdateConfig = true;
autoUpdater.autoDownload = false;
}
// if (import.meta.env.DEV) {
// // Useful for some dev/debugging tasks, but download can
// // not be validated becuase dev app is not signed
// autoUpdater.updateConfigPath = path.join(
// __dirname,
// "../../dev-app-update.yml",
// );
// autoUpdater.forceDevUpdateConfig = true;
// autoUpdater.autoDownload = false;
// }
autoUpdater.on("checking-for-update", () => {
log.info("Checking for update...");
const mainWindow = BrowserWindow.getAllWindows()[0];
@@ -336,6 +348,7 @@ app.on("window-all-closed", () => {
});
app.on("before-quit", () => {
localServer.stop();
isAppQuitting = true;
});