armcord/src/main.ts

115 lines
3.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
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";
import "./extensions/mods";
2021-12-26 19:15:18 +00:00
import "./extensions/plugin";
import "./tray";
2022-02-26 21:26:16 +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;
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;
async function appendSwitch(){
if (await getConfigUnsafe("windowStyle") == "glasstron") {
console.log("Enabling transparency visuals.");
app.commandLine.appendSwitch("enable-transparent-visuals");
}
}
appendSwitch();
storage.has("settings", function (error, hasKey) {
if (error) throw error;
2021-12-24 21:56:49 +00:00
2022-02-26 21:26:16 +00:00
if (!hasKey) {
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");
}
} else {
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-02-26 21:26:16 +00:00
});
2021-12-26 19:15:18 +00:00
storage.get("settings", function (error, data: any) {
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-02-26 21:26:16 +00:00
switch (await getConfigUnsafe("windowStyle")) {
case "default":
createCustomWindow();
customTitlebar = true;
break;
case "native":
createNativeWindow();
break;
case "glasstron":
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;
default:
createCustomWindow();
customTitlebar = true;
break;
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-02-26 21:26:16 +00:00
app.on("activate", async function () {
2022-01-30 19:48:32 +00:00
if (BrowserWindow.getAllWindows().length === 0)
2022-02-26 21:26:16 +00:00
switch (await getConfigUnsafe("windowStyle")) {
case "default":
createCustomWindow();
break;
case "native":
createNativeWindow();
break;
case "glasstron":
createGlasstronWindow();
break;
default:
createCustomWindow();
break;
2022-01-30 19:48:32 +00:00
}
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();
});