armcord/src/main.ts

109 lines
4.3 KiB
TypeScript
Raw Normal View History

2021-12-24 21:56:49 +00:00
// Modules to control application life and create native browser window
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 {
Settings,
2022-12-13 13:10:41 +00:00
checkForDataFolder,
checkIfConfigExists,
getConfig,
2022-12-13 13:10:41 +00:00
injectElectronFlags,
installModLoader,
setConfig
2022-12-13 13:10:41 +00:00
} from "./utils";
import "./extensions/mods";
2021-12-26 19:15:18 +00:00
import "./tray";
import {createCustomWindow, createNativeWindow, createTransparentWindow} from "./window";
2022-08-25 14:42:54 +00:00
import path from "path";
export let iconPath: string;
export let settings: any;
export let customTitlebar: boolean;
async function args(): Promise<void> {
let argNum = 2;
2023-04-25 08:57:49 +00:00
if (process.argv[0] == "electron") argNum++;
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("=")) {
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();
}
}
args(); // i want my top level awaits
if (!app.requestSingleInstanceLock()) {
// kill if 2nd instance
app.quit();
} else {
// Your data now belongs to CCP
2022-12-24 18:46:58 +00:00
crashReporter.start({uploadToServer: false});
/* Using appendSwitch properly causes ArmCord to segfault,
So we will leave the responsibility of enabling Wayland
And PipeWire video capture to packagers.
// We use toLowerCase to account for desktops where XDG_SESSION_TYPE might be Wayland and not wayland.
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
// Just using the native Wayland backend doesn't enable PipeWire capture, we need to enable it explicitly.
app.commandLine.appendSwitch("enable-features=WebRTCPipeWireCapturer");
console.log("Wayland detected, using PipeWire for video capture.");
// Some people might want to disable the Wayland backend for one reason or another, such as for Wayland-specific bugs.
if (process.env.USE_WAYLAND === "0") {
console.log("Wayland backend disabled.");
} else {
console.log("Using native Wayland, not Xwayland. Disable with USE_WAYLAND=0 if you find issues.");
app.commandLine.appendSwitch("ozone-platform=auto");
// The Wayland spec doesn't require SSDs, so lets enable self-drawn window decorations.
// If SSDs are supported on the compositor, Electron will let the compositor handle the decorations.
app.commandLine.appendSwitch("enable-features=UseOzonePlatform,WaylandWindowDecorations");
}
2022-07-11 18:19:50 +00:00
}
*/
checkForDataFolder();
checkIfConfigExists();
injectElectronFlags();
app.whenReady().then(async () => {
if ((await getConfig("customIcon")) !== undefined ?? null) {
iconPath = await getConfig("customIcon");
} else {
iconPath = path.join(__dirname, "../", "/assets/ac_icon_transparent.png");
2022-03-04 17:53:18 +00:00
}
async function init(): Promise<void> {
switch (await getConfig("windowStyle")) {
case "default":
createCustomWindow();
customTitlebar = true;
break;
case "native":
createNativeWindow();
break;
case "transparent":
createTransparentWindow();
break;
case "basic":
createNativeWindow();
break;
default:
createCustomWindow();
customTitlebar = true;
break;
}
2022-03-04 17:53:18 +00:00
}
await init();
await installModLoader();
session.fromPartition("some-partition").setPermissionRequestHandler((_webContents, permission, callback) => {
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
}