From 12bb2701888b8f47b3557dfd28d0218165d55885 Mon Sep 17 00:00:00 2001 From: metacryst Date: Wed, 15 Apr 2026 14:38:16 -0500 Subject: [PATCH] init --- .gitignore | 5 +++ index.html | 41 ++++++++++++++++++ index.js | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 20 +++++++++ 4 files changed, 182 insertions(+) create mode 100644 .gitignore create mode 100644 index.html create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec2f9e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +package-lock.json +master.forms +forms/app.log +.DS_Store \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..a176ae7 --- /dev/null +++ b/index.html @@ -0,0 +1,41 @@ + + + + + Parchment + + + + + +
+ + diff --git a/index.js b/index.js new file mode 100644 index 0000000..635906e --- /dev/null +++ b/index.js @@ -0,0 +1,116 @@ +import { app, BrowserWindow, globalShortcut } from 'electron'; + +const WINDOW_SHORTCUTS = [ + process.platform === "darwin" ? "Command+R" : "Control+R", + "\\" +]; + +class App { + devToolsOpened = false; + + createWindow({onTop = false}) { + const win = new BrowserWindow({ + width: 1200, + height: 800, + frame: false, + show: false, + titleBarStyle: "customButtonsOnHover", + webPreferences: { + contextIsolation: true, + nodeIntegration: false, + webviewTag: true, + } + }); + + 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('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); + } + }); + } + + 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() { + console.log("command line: ", app.commandLine.getSwitchValue('disable-gpu')); // or check flags + + 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.registerShortcuts() + }); + } +} + +new App() \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4d5e41d --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "Forum", + "version": "1.0.0", + "type": "module", + "main": "index.js", + "scripts": { + "start": "electron ." + }, + "devDependencies": { + "electron": "^30.0.0" + }, + "dependencies": { + "chalk": "^5.6.2", + "cors": "^2.8.5", + "express": "^4.18.2", + "moment": "^2.30.1", + "ws": "^8.18.3", + "zod": "^4.2.1" + } +}