2021-12-24 21:56:49 +00:00
|
|
|
// Modules to control application life and create native browser window
|
2022-03-04 17:53:18 +00:00
|
|
|
import {app, BrowserWindow, session} from "electron";
|
2021-12-24 21:56:49 +00:00
|
|
|
import * as path from "path";
|
2021-12-26 19:15:18 +00:00
|
|
|
import "v8-compile-cache";
|
|
|
|
import * as storage from "electron-json-storage";
|
2022-03-04 17:53:18 +00:00
|
|
|
import {getConfigUnsafe, setup} from "./utils";
|
2021-12-26 21:41:09 +00:00
|
|
|
import "./extensions/mods";
|
2021-12-26 19:15:18 +00:00
|
|
|
import "./extensions/plugin";
|
|
|
|
import "./tray";
|
2022-03-04 17:53:18 +00:00
|
|
|
import {mainWindow, createCustomWindow, createNativeWindow, createGlasstronWindow, createTabsHost} from "./window";
|
2022-01-15 21:21:51 +00:00
|
|
|
import "./shortcuts";
|
2022-01-30 19:48:32 +00:00
|
|
|
export var contentPath: string;
|
2022-01-15 18:31:51 +00:00
|
|
|
var channel: string;
|
2022-01-30 19:48:32 +00:00
|
|
|
export var settings: any;
|
|
|
|
export var customTitlebar: boolean;
|
2022-02-26 21:26:16 +00:00
|
|
|
export var tabs: boolean;
|
2022-03-04 17:53:18 +00:00
|
|
|
async function appendSwitch() {
|
|
|
|
if ((await getConfigUnsafe("windowStyle")) == "glasstron") {
|
|
|
|
console.log("Enabling transparency visuals.");
|
|
|
|
app.commandLine.appendSwitch("enable-transparent-visuals");
|
|
|
|
}
|
2022-02-26 21:26:16 +00:00
|
|
|
}
|
|
|
|
appendSwitch();
|
2022-03-04 17:53:18 +00:00
|
|
|
storage.has("settings", function (error, hasKey) {
|
2022-02-26 21:26:16 +00:00
|
|
|
if (error) throw error;
|
2021-12-24 21:56:49 +00:00
|
|
|
|
2022-02-26 21:26:16 +00:00
|
|
|
if (!hasKey) {
|
2022-03-04 17:53:18 +00:00
|
|
|
console.log("First run of the ArmCord. Starting setup.");
|
|
|
|
setup();
|
|
|
|
contentPath = path.join(__dirname, "/content/setup.html");
|
|
|
|
if (!contentPath.includes("ts-out")) {
|
|
|
|
contentPath = path.join(__dirname, "/ts-out/content/setup.html");
|
|
|
|
}
|
2022-02-26 21:26:16 +00:00
|
|
|
} else {
|
2022-03-04 17:53:18 +00:00
|
|
|
console.log("ArmCord has been run before. Skipping setup.");
|
|
|
|
contentPath = path.join(__dirname, "/content/splash.html");
|
|
|
|
if (!contentPath.includes("ts-out")) {
|
|
|
|
contentPath = path.join(__dirname, "/ts-out/content/splash.html");
|
|
|
|
}
|
2022-01-30 19:48:32 +00:00
|
|
|
}
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
2021-12-26 19:15:18 +00:00
|
|
|
storage.get("settings", function (error, data: any) {
|
2022-03-04 17:53:18 +00:00
|
|
|
if (error) throw error;
|
|
|
|
console.log(data);
|
|
|
|
channel = data.channel;
|
|
|
|
settings = data;
|
2021-12-26 19:15:18 +00:00
|
|
|
});
|
2022-01-30 19:48:32 +00:00
|
|
|
app.whenReady().then(async () => {
|
2022-03-04 17:53:18 +00:00
|
|
|
switch (await getConfigUnsafe("windowStyle")) {
|
2022-02-26 21:26:16 +00:00
|
|
|
case "default":
|
2022-03-04 17:53:18 +00:00
|
|
|
createCustomWindow();
|
|
|
|
customTitlebar = true;
|
|
|
|
break;
|
2022-02-26 21:26:16 +00:00
|
|
|
case "native":
|
2022-03-04 17:53:18 +00:00
|
|
|
createNativeWindow();
|
|
|
|
break;
|
2022-02-26 21:26:16 +00:00
|
|
|
case "glasstron":
|
2022-03-04 17:53:18 +00:00
|
|
|
setTimeout(
|
|
|
|
createGlasstronWindow,
|
|
|
|
process.platform == "linux" ? 1000 : 0
|
|
|
|
// Electron has a bug on linux where it
|
|
|
|
// won't initialize properly when using
|
|
|
|
// transparency. To work around that, it
|
|
|
|
// is necessary to delay the window
|
|
|
|
// spawn function.
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "tabs":
|
|
|
|
createTabsHost();
|
|
|
|
tabs = true;
|
|
|
|
break;
|
2022-02-26 21:26:16 +00:00
|
|
|
default:
|
2022-03-04 17:53:18 +00:00
|
|
|
createCustomWindow();
|
|
|
|
customTitlebar = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
switch (await getConfigUnsafe("windowStyle")) {
|
|
|
|
case "default":
|
|
|
|
createCustomWindow();
|
|
|
|
break;
|
|
|
|
case "native":
|
|
|
|
createNativeWindow();
|
|
|
|
break;
|
|
|
|
case "glasstron":
|
|
|
|
createGlasstronWindow();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
createCustomWindow();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2021-12-26 19:15:18 +00:00
|
|
|
});
|
2021-12-24 21:56:49 +00:00
|
|
|
|
2021-12-26 19:15:18 +00:00
|
|
|
app.on("window-all-closed", function () {
|
2022-03-04 17:53:18 +00:00
|
|
|
if (process.platform !== "darwin") app.quit();
|
2021-12-26 19:15:18 +00:00
|
|
|
});
|