stuff
This commit is contained in:
43
index.js
43
index.js
@@ -1,4 +1,9 @@
|
||||
import { app, BrowserWindow, globalShortcut } from 'electron';
|
||||
import { app, BrowserWindow, globalShortcut, ipcMain, protocol, net } from 'electron';
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { fileURLToPath } from "url";
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const WINDOW_SHORTCUTS = [
|
||||
process.platform === "darwin" ? "Command+R" : "Control+R",
|
||||
@@ -9,6 +14,7 @@ class App {
|
||||
devToolsOpened = false;
|
||||
|
||||
createWindow({onTop = false}) {
|
||||
|
||||
const win = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
@@ -16,6 +22,7 @@ class App {
|
||||
show: false,
|
||||
titleBarStyle: "customButtonsOnHover",
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
webviewTag: true,
|
||||
@@ -27,7 +34,22 @@ class App {
|
||||
win.setAlwaysOnTop(true, 'screen-saver', 1); // necessary so it doesn't bring you back out of full screen when spawned
|
||||
}
|
||||
|
||||
win.loadFile('index.html');
|
||||
protocol.handle('app', (request) => {
|
||||
const url = new URL(request.url);
|
||||
let filePath = path.join(__dirname, url.pathname);
|
||||
|
||||
// if file doesn't exist, fall back to index.html
|
||||
if(filePath.includes("desktoputil")) {
|
||||
filePath = path.join(__dirname, 'desktoputil.js');
|
||||
}
|
||||
else if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
|
||||
filePath = path.join(__dirname, 'index.html');
|
||||
}
|
||||
|
||||
return net.fetch(`file://${filePath}`);
|
||||
});
|
||||
|
||||
win.loadURL('app://local/');
|
||||
|
||||
win.on("focus", () => {
|
||||
win.setVibrancy("appearance-based"); // full colors
|
||||
@@ -92,10 +114,9 @@ class App {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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});
|
||||
@@ -110,6 +131,20 @@ class App {
|
||||
this.createWindow({onTop: false});
|
||||
this.registerShortcuts()
|
||||
});
|
||||
|
||||
ipcMain.on('focus-window', () => {
|
||||
const win = BrowserWindow.getAllWindows()[0];
|
||||
win?.show();
|
||||
win?.focus();
|
||||
});
|
||||
|
||||
ipcMain.on('set-badge', (e, count) => {
|
||||
app.setBadgeCount(count);
|
||||
});
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{ scheme: 'app', privileges: { standard: true, secure: true, supportFetchAPI: true, corsEnabled: true } }
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user