-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (74 loc) · 2.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import remote from "@electron/remote/main/index.js";
import { execSync } from "child_process";
import { app, BrowserWindow, globalShortcut, nativeTheme } from "electron";
import { existsSync } from "fs";
import { mkdir, writeFile } from "fs/promises";
import { VERSION } from "./src/env.js";
import dotenv from "dotenv";
const { parsed } = dotenv.config({ debug: true });
remote.initialize();
let window;
app.on("ready", async () => {
await writeCommitHash();
window = new BrowserWindow({
width: 1280,
height: 720,
minWidth: 800,
minHeight: 600,
center: true,
fullscreen: true,
backgroundColor: "#000",
title: `Inepta ${VERSION}`,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
icon: "./inepta.png",
});
remote.enable(window.webContents);
if (parsed.LIVE_MODE == "1" || process.argv.includes("live"))
window.webContents.userAgent += " LIVEMODE";
window.removeMenu();
window.loadFile("src/index.html");
window.on("maximize", () => {
window.unmaximize();
setTimeout(() => {
window.fullScreen = true;
});
});
window.webContents.on("devtools-opened", () => {
toggleNativeTheme();
});
window.webContents.session.webRequest.onHeadersReceived({ urls: ["*://*/*"] }, (d, c) => {
if (d.responseHeaders["X-Frame-Options"]) {
delete d.responseHeaders["X-Frame-Options"];
} else if (d.responseHeaders["x-frame-options"]) {
delete d.responseHeaders["x-frame-options"];
}
c({ cancel: false, responseHeaders: d.responseHeaders });
});
globalShortcut.register("Ctrl+Shift+Alt+I", () => {
if (window.isFocused()) window.toggleDevTools();
});
globalShortcut.register("Alt+Enter", () => {
if (window.isFocused()) window.fullScreen = !window.fullScreen;
});
});
function toggleNativeTheme() {
// First, set the theme to 'light'
nativeTheme.themeSource = "light";
// After a short delay, set it to 'dark'
setTimeout(() => {
nativeTheme.themeSource = "dark";
}, 100); // 100ms delay; adjust if necessary
}
async function writeCommitHash() {
try {
const hash = execSync(`git rev-parse HEAD`);
if (!existsSync("env")) await mkdir("env");
await writeFile("./env/HASH", hash);
} catch (e) {
console.warn("[FAILURE] Couldn't write commit hash. Maybe no Git or no permission.");
}
}