Restructure the Electron application by separating concerns into new modules (windows, ipc, sentinel), introduce TypeScript types for IPC, and update build configurations and entry points for desktop applications. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 714c0a0f-ae39-4276-a53a-1f68eb5443fa Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/CdxgfN4 Replit-Helium-Checkpoint-Created: true
92 lines
2 KiB
JavaScript
92 lines
2 KiB
JavaScript
import { BrowserWindow } from "electron";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
let mainWindow = null;
|
|
let overlayWindow = null;
|
|
|
|
export function getMainWindow() {
|
|
return mainWindow;
|
|
}
|
|
|
|
export function getOverlayWindow() {
|
|
return overlayWindow;
|
|
}
|
|
|
|
export function getRendererUrl(entryFile = "desktop-main.html") {
|
|
if (process.env.VITE_DEV_SERVER_URL) {
|
|
return `${process.env.VITE_DEV_SERVER_URL}/${entryFile}`;
|
|
}
|
|
return `file://${path.join(__dirname, "../dist/desktop", entryFile)}`;
|
|
}
|
|
|
|
export function createMainWindow() {
|
|
mainWindow = new BrowserWindow({
|
|
width: 1280,
|
|
height: 800,
|
|
minWidth: 800,
|
|
minHeight: 600,
|
|
frame: false,
|
|
titleBarStyle: "hidden",
|
|
backgroundColor: "#030712",
|
|
show: false,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, "preload.js"),
|
|
contextIsolation: true,
|
|
nodeIntegration: false,
|
|
},
|
|
});
|
|
|
|
mainWindow.loadURL(getRendererUrl("desktop-main.html"));
|
|
|
|
mainWindow.once("ready-to-show", () => {
|
|
mainWindow.show();
|
|
});
|
|
|
|
mainWindow.on("closed", () => {
|
|
mainWindow = null;
|
|
});
|
|
|
|
return mainWindow;
|
|
}
|
|
|
|
export function createOverlayWindow() {
|
|
overlayWindow = new BrowserWindow({
|
|
width: 380,
|
|
height: 320,
|
|
transparent: true,
|
|
frame: false,
|
|
alwaysOnTop: true,
|
|
resizable: true,
|
|
focusable: true,
|
|
skipTaskbar: true,
|
|
backgroundColor: "#00000000",
|
|
webPreferences: {
|
|
preload: path.join(__dirname, "preload.js"),
|
|
contextIsolation: true,
|
|
nodeIntegration: false,
|
|
},
|
|
});
|
|
|
|
overlayWindow.setAlwaysOnTop(true, "floating");
|
|
overlayWindow.loadURL(getRendererUrl("desktop-overlay.html"));
|
|
|
|
overlayWindow.on("closed", () => {
|
|
overlayWindow = null;
|
|
});
|
|
|
|
return overlayWindow;
|
|
}
|
|
|
|
export function toggleMainVisibility() {
|
|
if (!mainWindow) return;
|
|
if (mainWindow.isVisible()) {
|
|
mainWindow.hide();
|
|
} else {
|
|
mainWindow.show();
|
|
mainWindow.focus();
|
|
}
|
|
}
|