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,
|
|
|
|
ipcMain,
|
|
|
|
shell,
|
|
|
|
desktopCapturer,
|
|
|
|
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-16 18:07:00 +00:00
|
|
|
import { saveSettings, getVersion, setup, getConfigUnsafe } 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-15 21:21:51 +00:00
|
|
|
import "./shortcuts";
|
2021-12-26 19:15:18 +00:00
|
|
|
var contentPath: string = "null";
|
|
|
|
var frame: boolean;
|
2022-01-15 18:31:51 +00:00
|
|
|
var channel: string;
|
2021-12-26 18:58:05 +00:00
|
|
|
export var mainWindow: BrowserWindow;
|
2022-01-15 21:21:51 +00:00
|
|
|
var settings: any;
|
2021-12-26 19:15:18 +00:00
|
|
|
|
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();
|
2021-12-26 19:15:18 +00:00
|
|
|
contentPath = __dirname + "/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.");
|
2021-12-26 21:41:09 +00:00
|
|
|
contentPath = __dirname + "/content/splash.html";
|
2021-12-24 21:56:49 +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;
|
2022-01-16 18:07:00 +00:00
|
|
|
|
2021-12-26 19:15:18 +00:00
|
|
|
});
|
2022-01-16 18:07:00 +00:00
|
|
|
var titlebar:any = getConfigUnsafe("customTitlebar")
|
|
|
|
console.log(!titlebar)
|
2021-12-26 19:15:18 +00:00
|
|
|
function createWindow() {
|
|
|
|
mainWindow = new BrowserWindow({
|
2021-12-24 21:56:49 +00:00
|
|
|
width: 300,
|
2021-12-26 18:58:05 +00:00
|
|
|
height: 350,
|
2021-12-24 21:56:49 +00:00
|
|
|
title: "ArmCord",
|
2022-01-16 18:07:00 +00:00
|
|
|
darkTheme: true,
|
|
|
|
icon: path.join(__dirname, "/assets/icon_transparent.png"),
|
|
|
|
frame: !titlebar,
|
|
|
|
autoHideMenuBar: true,
|
2021-12-24 21:56:49 +00:00
|
|
|
webPreferences: {
|
2021-12-26 19:15:18 +00:00
|
|
|
preload: path.join(__dirname, "preload/preload.js"),
|
|
|
|
},
|
|
|
|
});
|
2021-12-24 21:56:49 +00:00
|
|
|
ipcMain.on("get-app-path", (event, arg) => {
|
|
|
|
event.reply("app-path", app.getAppPath());
|
|
|
|
});
|
|
|
|
ipcMain.on("open-external-link", (event, href: string) => {
|
|
|
|
shell.openExternal(href);
|
|
|
|
});
|
|
|
|
ipcMain.on("win-maximize", (event, arg) => {
|
|
|
|
mainWindow.maximize();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-isMaximized", (event, arg) => {
|
|
|
|
event.returnValue = mainWindow.isMaximized();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-minimize", (event, arg) => {
|
|
|
|
mainWindow.minimize();
|
|
|
|
});
|
2021-12-26 18:58:05 +00:00
|
|
|
ipcMain.on("win-unmaximize", (event, arg) => {
|
|
|
|
mainWindow.unmaximize();
|
|
|
|
});
|
2021-12-24 21:56:49 +00:00
|
|
|
ipcMain.on("win-show", (event, arg) => {
|
|
|
|
mainWindow.show();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-hide", (event, arg) => {
|
|
|
|
mainWindow.hide();
|
|
|
|
});
|
|
|
|
ipcMain.on("get-app-version", (event) => {
|
2022-01-15 21:21:51 +00:00
|
|
|
event.returnValue = getVersion();
|
2021-12-26 19:15:18 +00:00
|
|
|
});
|
2021-12-24 21:56:49 +00:00
|
|
|
ipcMain.on("splashEnd", (event, arg) => {
|
|
|
|
mainWindow.setSize(800, 600);
|
|
|
|
});
|
2022-01-15 21:21:51 +00:00
|
|
|
ipcMain.on("restart", (event, arg) => {
|
2022-01-16 18:07:00 +00:00
|
|
|
app.relaunch();
|
|
|
|
app.exit();
|
2022-01-15 21:21:51 +00:00
|
|
|
});
|
|
|
|
|
2021-12-26 21:41:09 +00:00
|
|
|
ipcMain.on("saveSettings", (event, ...args) => {
|
|
|
|
//@ts-ignore
|
|
|
|
saveSettings(...args);
|
|
|
|
});
|
2022-01-15 18:31:51 +00:00
|
|
|
ipcMain.on("channel", (event) => {
|
|
|
|
event.returnValue = channel;
|
|
|
|
});
|
|
|
|
ipcMain.on("clientmod", (event, arg) => {
|
|
|
|
event.returnValue = settings.mods;
|
|
|
|
});
|
|
|
|
|
2021-12-26 21:41:09 +00:00
|
|
|
ipcMain.on("setting-armcordCSP", (event) => {
|
|
|
|
storage.get("settings", function (error, data: any) {
|
|
|
|
if (error) throw error;
|
|
|
|
if (data.armcordCSP) {
|
|
|
|
event.returnValue = true;
|
|
|
|
} else {
|
|
|
|
event.returnValue = false;
|
|
|
|
}
|
|
|
|
});
|
2021-12-26 19:15:18 +00:00
|
|
|
});
|
|
|
|
ipcMain.handle("DESKTOP_CAPTURER_GET_SOURCES", (event, opts) =>
|
|
|
|
desktopCapturer.getSources(opts)
|
|
|
|
);
|
2021-12-26 18:58:05 +00:00
|
|
|
mainWindow.webContents.userAgent =
|
|
|
|
"Mozilla/5.0 (X11; Linux x86) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; //fake useragent
|
2022-01-15 18:31:51 +00:00
|
|
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
2021-12-26 19:15:18 +00:00
|
|
|
shell.openExternal(url);
|
2022-01-15 18:31:51 +00:00
|
|
|
return { action: "deny" };
|
2021-12-26 19:15:18 +00:00
|
|
|
});
|
2022-01-15 18:31:51 +00:00
|
|
|
|
2021-12-26 19:15:18 +00:00
|
|
|
mainWindow.loadFile(contentPath);
|
2021-12-24 21:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
2021-12-26 19:15:18 +00:00
|
|
|
createWindow();
|
2022-01-16 18:07:00 +00:00
|
|
|
session
|
|
|
|
.fromPartition("some-partition")
|
|
|
|
.setPermissionRequestHandler((webContents, permission, callback) => {
|
|
|
|
const url = webContents.getURL(); //unused?
|
2021-12-24 21:56:49 +00:00
|
|
|
|
2022-01-16 18:07:00 +00:00
|
|
|
if (permission === "notifications") {
|
|
|
|
// Approves the permissions request
|
|
|
|
callback(true);
|
|
|
|
}
|
|
|
|
if (permission === "media") {
|
|
|
|
// Approves the permissions request
|
|
|
|
callback(true);
|
|
|
|
}
|
|
|
|
if (url.startsWith("discord://")) {
|
|
|
|
// Denies the permissions request
|
|
|
|
return callback(false);
|
|
|
|
}
|
|
|
|
if (url.startsWith("discord.com/science")) {
|
|
|
|
// Denies the permissions request
|
|
|
|
return callback(false);
|
|
|
|
}
|
|
|
|
if (url.startsWith("discord.com/tracing")) {
|
|
|
|
// Denies the permissions request
|
|
|
|
return callback(false);
|
|
|
|
}
|
|
|
|
});
|
2021-12-26 19:15:18 +00:00
|
|
|
app.on("activate", function () {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
|
|
});
|
|
|
|
});
|
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();
|
|
|
|
});
|