2021-12-24 21:56:49 +00:00
|
|
|
// Modules to control application life and create native browser window
|
2022-01-16 18:07:00 +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-01-30 19:48:32 +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-01-30 19:48:32 +00:00
|
|
|
import { mainWindow, createCustomWindow, createNativeWindow } 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;
|
2021-12-26 21:41:09 +00:00
|
|
|
storage.has("settings", function (error, hasKey) {
|
2021-12-24 21:56:49 +00:00
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
if (!hasKey) {
|
2021-12-26 19:15:18 +00:00
|
|
|
console.log("First run of the ArmCord. Starting setup.");
|
2022-01-15 21:21:51 +00:00
|
|
|
setup();
|
2022-01-17 14:35:12 +00:00
|
|
|
contentPath = path.join(__dirname, "/content/setup.html");
|
2022-01-30 19:48:32 +00:00
|
|
|
if (!contentPath.includes("ts-out")) {
|
|
|
|
contentPath = path.join(__dirname, "/ts-out/content/setup.html");
|
|
|
|
}
|
2021-12-24 21:56:49 +00:00
|
|
|
} else {
|
2021-12-26 19:15:18 +00:00
|
|
|
console.log("ArmCord has been run before. Skipping setup.");
|
2022-01-30 19:48:32 +00:00
|
|
|
contentPath = path.join(__dirname, "/content/splash.html");
|
|
|
|
if (!contentPath.includes("ts-out")) {
|
|
|
|
contentPath = path.join(__dirname, "/ts-out/content/splash.html");
|
|
|
|
}
|
2021-12-24 21:56:49 +00:00
|
|
|
}
|
2022-01-30 19:48:32 +00:00
|
|
|
});
|
2021-12-26 19:15:18 +00:00
|
|
|
storage.get("settings", function (error, data: any) {
|
|
|
|
if (error) throw error;
|
|
|
|
console.log(data);
|
2022-01-15 18:31:51 +00:00
|
|
|
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 () => {
|
|
|
|
if (await getConfigUnsafe("customTitlebar") == true) {
|
|
|
|
console.log("Creating custom titlebar window.");
|
|
|
|
customTitlebar = true;
|
|
|
|
createCustomWindow();
|
|
|
|
} else if (await getConfigUnsafe("customTitlebar") == "setup") {
|
|
|
|
//rare case of setup window
|
|
|
|
console.log("Creating setup window.");
|
|
|
|
customTitlebar = true;
|
|
|
|
createCustomWindow();
|
|
|
|
} else {
|
|
|
|
console.log("Creating native titlebar window.");
|
|
|
|
customTitlebar = false;
|
|
|
|
createNativeWindow();
|
2022-01-16 20:31:03 +00:00
|
|
|
}
|
2022-01-16 18:07:00 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2022-01-30 19:48:32 +00:00
|
|
|
mainWindow.webContents.session.webRequest.onBeforeRequest(
|
|
|
|
(details, callback) => {
|
|
|
|
if (/api\/v\d\/science$/g.test(details.url))
|
|
|
|
return callback({ cancel: true });
|
|
|
|
return callback({});
|
|
|
|
}
|
|
|
|
);
|
2021-12-26 19:15:18 +00:00
|
|
|
app.on("activate", function () {
|
2022-01-30 19:48:32 +00:00
|
|
|
if (BrowserWindow.getAllWindows().length === 0)
|
|
|
|
if (!settings.customTitlebar) {
|
|
|
|
createNativeWindow();
|
|
|
|
} else {
|
|
|
|
createCustomWindow();
|
|
|
|
}
|
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 () {
|
|
|
|
if (process.platform !== "darwin") app.quit();
|
|
|
|
});
|