2021-12-24 21:56:49 +00:00
|
|
|
// Modules to control application life and create native browser window
|
2023-05-08 19:24:30 +00:00
|
|
|
import {BrowserWindow, app, crashReporter, session} from "electron";
|
2021-12-26 19:15:18 +00:00
|
|
|
import "v8-compile-cache";
|
2022-12-13 13:10:41 +00:00
|
|
|
import {
|
2023-05-08 19:24:30 +00:00
|
|
|
Settings,
|
2022-12-13 13:10:41 +00:00
|
|
|
checkForDataFolder,
|
|
|
|
checkIfConfigExists,
|
2023-07-03 11:25:26 +00:00
|
|
|
firstRun,
|
2023-09-25 11:15:49 +00:00
|
|
|
checkIfConfigIsBroken,
|
2023-05-08 19:24:30 +00:00
|
|
|
getConfig,
|
2023-08-20 19:14:26 +00:00
|
|
|
getConfigSync,
|
2022-12-13 13:10:41 +00:00
|
|
|
injectElectronFlags,
|
|
|
|
installModLoader,
|
2023-06-11 16:50:07 +00:00
|
|
|
modInstallState,
|
|
|
|
setConfig,
|
2023-07-03 11:25:26 +00:00
|
|
|
setLang,
|
|
|
|
setWindowState,
|
2023-06-11 16:50:07 +00:00
|
|
|
sleep
|
2022-12-13 13:10:41 +00:00
|
|
|
} from "./utils";
|
2021-12-26 21:41:09 +00:00
|
|
|
import "./extensions/mods";
|
2021-12-26 19:15:18 +00:00
|
|
|
import "./tray";
|
2023-06-11 16:50:07 +00:00
|
|
|
import {createCustomWindow, createNativeWindow, createTransparentWindow, mainWindow} from "./window";
|
2022-08-25 14:42:54 +00:00
|
|
|
import path from "path";
|
2023-05-14 11:42:15 +00:00
|
|
|
import {createTManagerWindow} from "./themeManager/main";
|
2023-06-11 16:50:07 +00:00
|
|
|
import {createSplashWindow} from "./splash/main";
|
2023-07-03 11:25:26 +00:00
|
|
|
import {createSetupWindow} from "./setup/main";
|
2023-07-24 19:51:08 +00:00
|
|
|
import {createKeybindWindow} from "./keybindMaker/main";
|
2023-05-08 19:24:30 +00:00
|
|
|
export let iconPath: string;
|
|
|
|
export let settings: any;
|
|
|
|
export let customTitlebar: boolean;
|
2024-04-05 10:04:00 +00:00
|
|
|
|
2023-06-17 16:33:07 +00:00
|
|
|
app.on("render-process-gone", (event, webContents, details) => {
|
|
|
|
if (details.reason == "crashed") {
|
|
|
|
app.relaunch();
|
|
|
|
}
|
|
|
|
});
|
2023-05-08 19:24:30 +00:00
|
|
|
async function args(): Promise<void> {
|
|
|
|
let argNum = 2;
|
2023-04-25 08:57:49 +00:00
|
|
|
if (process.argv[0] == "electron") argNum++;
|
2023-05-08 19:24:30 +00:00
|
|
|
let args = process.argv[argNum];
|
2023-04-25 08:57:49 +00:00
|
|
|
if (args == undefined) return;
|
|
|
|
if (args.startsWith("--")) return; //electron flag
|
|
|
|
if (args.includes("=")) {
|
2023-05-08 19:24:30 +00:00
|
|
|
let e = args.split("=");
|
|
|
|
await setConfig(e[0] as keyof Settings, e[1]);
|
|
|
|
console.log(`Setting ${e[0]} to ${e[1]}`);
|
2023-04-25 08:57:49 +00:00
|
|
|
app.relaunch();
|
|
|
|
app.exit();
|
2023-05-14 11:42:15 +00:00
|
|
|
} else if (args == "themes") {
|
|
|
|
app.whenReady().then(async () => {
|
|
|
|
createTManagerWindow();
|
|
|
|
});
|
2023-07-24 19:51:08 +00:00
|
|
|
} else if (args == "keybinds") {
|
|
|
|
app.whenReady().then(async () => {
|
|
|
|
createKeybindWindow();
|
|
|
|
});
|
2023-04-25 08:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
args(); // i want my top level awaits
|
2023-08-20 19:14:26 +00:00
|
|
|
if (!app.requestSingleInstanceLock() && getConfigSync("multiInstance") == (false ?? undefined)) {
|
|
|
|
// if value isn't set after 3.2.4
|
2022-12-13 18:45:21 +00:00
|
|
|
// kill if 2nd instance
|
|
|
|
app.quit();
|
|
|
|
} else {
|
2023-08-20 19:14:26 +00:00
|
|
|
app.commandLine.appendSwitch("disable-features", "WidgetLayering"); // fix dev tools layers
|
2022-12-13 18:45:21 +00:00
|
|
|
// Your data now belongs to CCP
|
2022-12-24 18:46:58 +00:00
|
|
|
crashReporter.start({uploadToServer: false});
|
2023-08-05 12:07:42 +00:00
|
|
|
// enable webrtc capturer for wayland
|
2023-03-09 15:50:17 +00:00
|
|
|
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
|
2023-08-05 12:07:42 +00:00
|
|
|
app.commandLine.appendSwitch("enable-features=WebRTCPipeWireCapturer");
|
|
|
|
console.log("Wayland detected, using PipeWire for video capture.");
|
|
|
|
}
|
2023-06-10 17:43:59 +00:00
|
|
|
// work around chrome 66 disabling autoplay by default
|
|
|
|
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");
|
|
|
|
// WinRetrieveSuggestionsOnlyOnDemand: Work around electron 13 bug w/ async spellchecking on Windows.
|
|
|
|
// HardwareMediaKeyHandling,MediaSessionService: Prevent Discord from registering as a media service.
|
|
|
|
app.commandLine.appendSwitch(
|
|
|
|
"disable-features",
|
|
|
|
"WinRetrieveSuggestionsOnlyOnDemand,HardwareMediaKeyHandling,MediaSessionService"
|
|
|
|
);
|
2022-12-13 18:45:21 +00:00
|
|
|
checkForDataFolder();
|
|
|
|
checkIfConfigExists();
|
2024-04-05 10:04:00 +00:00
|
|
|
checkIfConfigIsBroken();
|
2022-12-13 18:45:21 +00:00
|
|
|
injectElectronFlags();
|
|
|
|
app.whenReady().then(async () => {
|
|
|
|
if ((await getConfig("customIcon")) !== undefined ?? null) {
|
|
|
|
iconPath = await getConfig("customIcon");
|
|
|
|
} else {
|
2023-05-13 20:53:48 +00:00
|
|
|
iconPath = path.join(__dirname, "../", "/assets/desktop.png");
|
2022-03-04 17:53:18 +00:00
|
|
|
}
|
2023-05-08 19:24:30 +00:00
|
|
|
async function init(): Promise<void> {
|
2023-06-11 16:50:07 +00:00
|
|
|
if ((await getConfig("skipSplash")) == false) {
|
|
|
|
createSplashWindow();
|
|
|
|
}
|
2023-07-03 11:25:26 +00:00
|
|
|
if (firstRun == true) {
|
|
|
|
await setLang(new Intl.DateTimeFormat().resolvedOptions().locale);
|
|
|
|
createSetupWindow();
|
|
|
|
}
|
2022-12-13 18:45:21 +00:00
|
|
|
switch (await getConfig("windowStyle")) {
|
|
|
|
case "default":
|
|
|
|
createCustomWindow();
|
|
|
|
customTitlebar = true;
|
|
|
|
break;
|
|
|
|
case "native":
|
|
|
|
createNativeWindow();
|
|
|
|
break;
|
|
|
|
case "transparent":
|
|
|
|
createTransparentWindow();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
createCustomWindow();
|
|
|
|
customTitlebar = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-03-04 17:53:18 +00:00
|
|
|
}
|
2022-12-13 18:45:21 +00:00
|
|
|
await init();
|
|
|
|
await installModLoader();
|
2023-05-08 19:24:30 +00:00
|
|
|
session.fromPartition("some-partition").setPermissionRequestHandler((_webContents, permission, callback) => {
|
2022-12-13 18:45:21 +00:00
|
|
|
if (permission === "notifications") {
|
|
|
|
// Approves the permissions request
|
|
|
|
callback(true);
|
|
|
|
}
|
|
|
|
if (permission === "media") {
|
|
|
|
// Approves the permissions request
|
|
|
|
callback(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
app.on("activate", async function () {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) await init();
|
|
|
|
});
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
2022-12-13 19:23:17 +00:00
|
|
|
}
|