renaming, spawning forms if it does not exist, simplifying

This commit is contained in:
metacryst
2025-12-28 06:49:04 -06:00
parent 97bd02c59a
commit 263a9795b9
17 changed files with 293 additions and 230 deletions

223
app.js
View File

@@ -1,109 +1,148 @@
import { app, BrowserWindow, globalShortcut } from 'electron';
import paths from 'path'
import Server from "./server/index.js"
import { spawn } from 'child_process'
import fs from 'fs'
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = paths.dirname(__filename);
import util from './flame/util.js'
import Server from "./flame/index.js"
const WINDOW_SHORTCUTS = [
process.platform === "darwin" ? "Command+R" : "Control+R",
"\\"
];
function createWindow({onTop = false}) {
const win = new BrowserWindow({
width: 1200,
height: 800,
frame: false,
show: false,
titleBarStyle: "customButtonsOnHover",
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
webviewTag: true,
}
});
class App {
devToolsOpened = false;
if(onTop) {
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }); // necessary for full screen
win.setAlwaysOnTop(true, 'screen-saver', 1); // necessary so it doesn't bring you back out of full screen when spawned
}
win.loadFile('server/index.html');
win.on("focus", () => {
win.setVibrancy("appearance-based"); // full colors
});
win.on("blur", () => {
win.setVibrancy("selection"); // dims colors
});
win.webContents.on('did-finish-load', () => {
win.show();
});
win.webContents.on('did-fail-load', (e, code, desc) => {
console.log('Webview failed:', desc);
});
win.on('closed', () => {
for (const key of WINDOW_SHORTCUTS) {
globalShortcut.unregister(key);
}
});
}
let devToolsOpened = false;
function toggleDevTools(win) {
if (devToolsOpened) {
win.closeDevTools();
} else {
win.openDevTools();
}
devToolsOpened = !devToolsOpened;
}
app.on("ready", async () => {
// await Forms.init();
// createWindow({onTop: false});
new Server()
globalShortcut.register('CommandOrControl+Shift+Space', () => {
createWindow({onTop: true});
});
// Register global shortcuts
app.on("browser-window-focus", () => {
const focused = BrowserWindow.getFocusedWindow();
if (!focused) return;
// Reload
globalShortcut.register(WINDOW_SHORTCUTS[0], () => {
focused.reload();
createWindow({onTop = false}) {
const win = new BrowserWindow({
width: 1200,
height: 800,
frame: false,
show: false,
titleBarStyle: "customButtonsOnHover",
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
webviewTag: true,
}
});
// Devtools
globalShortcut.register(WINDOW_SHORTCUTS[1], () => {
toggleDevTools(focused);
if(onTop) {
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }); // necessary for full screen
win.setAlwaysOnTop(true, 'screen-saver', 1); // necessary so it doesn't bring you back out of full screen when spawned
}
win.loadFile('flame/index.html');
win.on("focus", () => {
win.setVibrancy("appearance-based"); // full colors
});
});
app.on("browser-window-blur", () => {
for (const key of WINDOW_SHORTCUTS) {
globalShortcut.unregister(key);
}
});
});
win.on("blur", () => {
win.setVibrancy("selection"); // dims colors
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow({onTop: false});
win.webContents.on('did-finish-load', () => {
win.show();
});
win.webContents.on('did-fail-load', (e, code, desc) => {
console.log('Webview failed:', desc);
});
win.on('closed', () => {
for (const key of WINDOW_SHORTCUTS) {
globalShortcut.unregister(key);
}
});
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
spawnFlame(spawnForms) {
new Server(spawnForms)
}
async spawnForms() {
const logPath = paths.join(util.FORMS_PATH, "app.log");
const out = fs.openSync(logPath, "a");
const err = fs.openSync(logPath, "a");
const child = spawn(
process.execPath,
[paths.join(util.FORMS_PATH, "kernel/kernel.js")],
{
detached: true,
stdio: [
"ignore",
out,
err
],
cwd: process.cwd(),
env: process.env
}
);
child.unref();
}
toggleDevTools(win) {
if (this.devToolsOpened) {
win.closeDevTools();
} else {
win.openDevTools();
}
this.devToolsOpened = !this.devToolsOpened;
}
registerShortcuts() {
globalShortcut.register('CommandOrControl+Shift+Space', function CreateWindow() {
this.createWindow({onTop: true});
});
app.on("browser-window-focus", function RegisterWindowOnFocus() {
const focused = BrowserWindow.getFocusedWindow();
if (!focused) return;
let WINDOW_SHORTCUTS = [
process.platform === "darwin" ? "Command+R" : "Control+R",
"\\"
];
// Reload
globalShortcut.register(WINDOW_SHORTCUTS[0], () => {
focused.reload();
});
// Devtools
globalShortcut.register(WINDOW_SHORTCUTS[1], () => {
toggleDevTools(focused);
});
});
app.on("browser-window-blur", function UnregisterWindowOnUnfocus() {
for (const key of WINDOW_SHORTCUTS) {
globalShortcut.unregister(key);
}
});
}
constructor() {
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
this.createWindow({onTop: false});
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
app.on("ready", async () => {
this.createWindow({onTop: false});
this.spawnFlame(this.spawnForms)
this.registerShortcuts()
});
}
}
new App()