2022-01-30 19:48:32 +00:00
|
|
|
//ipc stuff
|
2022-09-25 18:30:09 +00:00
|
|
|
import {app, ipcMain, shell, desktopCapturer, nativeImage} from "electron";
|
2022-06-14 15:02:37 +00:00
|
|
|
import {mainWindow} from "./window";
|
2022-08-24 15:25:12 +00:00
|
|
|
import {
|
|
|
|
setConfigBulk,
|
|
|
|
getVersion,
|
|
|
|
getConfig,
|
|
|
|
setLang,
|
|
|
|
getLang,
|
|
|
|
getWindowState,
|
2022-09-25 18:30:09 +00:00
|
|
|
packageVersion,
|
|
|
|
getDisplayVersion
|
2022-08-24 15:25:12 +00:00
|
|
|
} from "./utils";
|
2022-06-14 15:02:37 +00:00
|
|
|
import {customTitlebar} from "./main";
|
2022-03-04 17:53:18 +00:00
|
|
|
import {createSettingsWindow} from "./settings/main";
|
2022-08-25 12:57:28 +00:00
|
|
|
import os from "os";
|
|
|
|
import path from "path";
|
2022-01-30 19:48:32 +00:00
|
|
|
export function registerIpc() {
|
2022-03-04 17:53:18 +00:00
|
|
|
ipcMain.on("get-app-path", (event, arg) => {
|
|
|
|
event.reply("app-path", app.getAppPath());
|
|
|
|
});
|
2022-06-11 20:14:16 +00:00
|
|
|
ipcMain.on("setLang", (event, lang: string) => {
|
|
|
|
setLang(lang);
|
|
|
|
});
|
2022-06-14 12:54:34 +00:00
|
|
|
ipcMain.handle("getLang", (event, toGet: string) => {
|
|
|
|
return getLang(toGet);
|
|
|
|
});
|
2022-03-04 17:53:18 +00:00
|
|
|
ipcMain.on("open-external-link", (event, href: string) => {
|
|
|
|
shell.openExternal(href);
|
|
|
|
});
|
2022-08-25 12:57:28 +00:00
|
|
|
ipcMain.on("setPing", (event, pingCount: number) => {
|
|
|
|
switch (os.platform()) {
|
|
|
|
case "linux" ?? "macos":
|
2022-09-25 18:30:09 +00:00
|
|
|
app.setBadgeCount(pingCount);
|
2022-08-25 12:57:28 +00:00
|
|
|
break;
|
|
|
|
case "win32":
|
|
|
|
if (pingCount > 0) {
|
2022-09-25 18:30:09 +00:00
|
|
|
var image = nativeImage.createFromPath(path.join(__dirname, "../", `/assets/ping.png`));
|
|
|
|
mainWindow.setOverlayIcon(image, "badgeCount");
|
2022-08-25 12:57:28 +00:00
|
|
|
} else {
|
2022-09-25 18:30:09 +00:00
|
|
|
mainWindow.setOverlayIcon(null, "badgeCount");
|
2022-08-25 12:57:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2022-03-04 17:53:18 +00:00
|
|
|
ipcMain.on("win-maximize", (event, arg) => {
|
|
|
|
mainWindow.maximize();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-isMaximized", (event, arg) => {
|
|
|
|
event.returnValue = mainWindow.isMaximized();
|
|
|
|
});
|
2022-07-04 14:39:22 +00:00
|
|
|
ipcMain.on("win-isNormal", (event, arg) => {
|
|
|
|
event.returnValue = mainWindow.isNormal();
|
|
|
|
});
|
2022-03-04 17:53:18 +00:00
|
|
|
ipcMain.on("win-minimize", (event, arg) => {
|
|
|
|
mainWindow.minimize();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-unmaximize", (event, arg) => {
|
|
|
|
mainWindow.unmaximize();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-show", (event, arg) => {
|
|
|
|
mainWindow.show();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-hide", (event, arg) => {
|
|
|
|
mainWindow.hide();
|
|
|
|
});
|
|
|
|
ipcMain.on("win-quit", (event, arg) => {
|
|
|
|
app.exit();
|
|
|
|
});
|
|
|
|
ipcMain.on("get-app-version", (event) => {
|
|
|
|
event.returnValue = getVersion();
|
|
|
|
});
|
2022-08-24 15:25:12 +00:00
|
|
|
ipcMain.on("displayVersion", (event) => {
|
|
|
|
event.returnValue = getDisplayVersion();
|
|
|
|
});
|
2022-08-22 09:24:55 +00:00
|
|
|
ipcMain.on("get-package-version", (event) => {
|
|
|
|
event.returnValue = packageVersion;
|
|
|
|
});
|
2022-08-24 15:25:12 +00:00
|
|
|
ipcMain.on("splashEnd", async () => {
|
2022-06-16 15:24:37 +00:00
|
|
|
try {
|
2022-08-22 09:24:55 +00:00
|
|
|
var width = (await getWindowState("width")) ?? 800;
|
|
|
|
var height = (await getWindowState("height")) ?? 600;
|
|
|
|
var isMaximized = (await getWindowState("isMaximized")) ?? false;
|
2022-06-16 15:24:37 +00:00
|
|
|
} catch (e) {
|
2022-08-22 09:24:55 +00:00
|
|
|
console.log("[Window state manager] No window state file found. Fallbacking to default values.");
|
2022-06-16 15:24:37 +00:00
|
|
|
mainWindow.setSize(800, 600);
|
|
|
|
}
|
|
|
|
if (isMaximized) {
|
2022-08-22 09:24:55 +00:00
|
|
|
mainWindow.setSize(800, 600); //just so the whole thing doesn't cover whole screen
|
|
|
|
mainWindow.maximize();
|
2022-06-16 15:24:37 +00:00
|
|
|
} else {
|
|
|
|
mainWindow.setSize(width, height);
|
2022-08-22 09:24:55 +00:00
|
|
|
console.log("[Window state manager] Not maximized.");
|
2022-06-16 15:24:37 +00:00
|
|
|
}
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
|
|
|
ipcMain.on("restart", (event, arg) => {
|
|
|
|
app.relaunch();
|
|
|
|
app.exit();
|
|
|
|
});
|
|
|
|
ipcMain.on("saveSettings", (event, args) => {
|
2022-04-18 10:25:10 +00:00
|
|
|
setConfigBulk(args);
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
2022-04-18 11:03:26 +00:00
|
|
|
ipcMain.on("minimizeToTray", async (event) => {
|
|
|
|
event.returnValue = await getConfig("minimizeToTray");
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
2022-04-18 11:03:26 +00:00
|
|
|
ipcMain.on("channel", async (event) => {
|
|
|
|
event.returnValue = await getConfig("channel");
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
2022-04-18 11:03:26 +00:00
|
|
|
ipcMain.on("clientmod", async (event, arg) => {
|
|
|
|
event.returnValue = await getConfig("mods");
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
2022-07-04 14:39:22 +00:00
|
|
|
ipcMain.on("trayIcon", async (event, arg) => {
|
|
|
|
event.returnValue = await getConfig("trayIcon");
|
|
|
|
});
|
2022-03-04 17:53:18 +00:00
|
|
|
ipcMain.on("titlebar", (event, arg) => {
|
|
|
|
event.returnValue = customTitlebar;
|
|
|
|
});
|
2022-07-11 17:13:52 +00:00
|
|
|
ipcMain.on("mobileMode", async (event, arg) => {
|
|
|
|
event.returnValue = await getConfig("mobileMode");
|
|
|
|
});
|
2022-04-18 11:03:26 +00:00
|
|
|
ipcMain.on("shouldPatch", async (event, arg) => {
|
|
|
|
event.returnValue = await getConfig("automaticPatches");
|
2022-03-04 17:53:18 +00:00
|
|
|
});
|
|
|
|
ipcMain.on("openSettingsWindow", (event, arg) => {
|
|
|
|
createSettingsWindow();
|
|
|
|
});
|
2022-04-18 11:03:26 +00:00
|
|
|
ipcMain.on("setting-armcordCSP", async (event) => {
|
|
|
|
if (await getConfig("armcordCSP")) {
|
2022-03-04 17:53:18 +00:00
|
|
|
event.returnValue = true;
|
|
|
|
} else {
|
|
|
|
event.returnValue = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ipcMain.handle("DESKTOP_CAPTURER_GET_SOURCES", (event, opts) => desktopCapturer.getSources(opts));
|
2022-01-30 19:48:32 +00:00
|
|
|
}
|