mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Rewrite splash
This commit is contained in:
parent
451c96d57c
commit
89e4c3570d
9 changed files with 107 additions and 115 deletions
Binary file not shown.
Before Width: | Height: | Size: 24 KiB |
27
src/ipc.ts
27
src/ipc.ts
|
@ -17,6 +17,7 @@ import {createSettingsWindow} from "./settings/main";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {createTManagerWindow} from "./themeManager/main";
|
import {createTManagerWindow} from "./themeManager/main";
|
||||||
|
import {splashWindow} from "./splash/main";
|
||||||
export function registerIpc(): void {
|
export function registerIpc(): void {
|
||||||
ipcMain.on("get-app-path", (event) => {
|
ipcMain.on("get-app-path", (event) => {
|
||||||
event.reply("app-path", app.getAppPath());
|
event.reply("app-path", app.getAppPath());
|
||||||
|
@ -82,31 +83,11 @@ export function registerIpc(): void {
|
||||||
event.returnValue = packageVersion;
|
event.returnValue = packageVersion;
|
||||||
});
|
});
|
||||||
ipcMain.on("splashEnd", async () => {
|
ipcMain.on("splashEnd", async () => {
|
||||||
let width = 835,
|
splashWindow.close();
|
||||||
height = 600,
|
|
||||||
isMaximized = true,
|
|
||||||
xValue = 0,
|
|
||||||
yValue = 0;
|
|
||||||
try {
|
|
||||||
width = (await getWindowState("width")) ?? 835;
|
|
||||||
height = (await getWindowState("height")) ?? 600;
|
|
||||||
isMaximized = (await getWindowState("isMaximized")) ?? false;
|
|
||||||
xValue = await getWindowState("x");
|
|
||||||
yValue = await getWindowState("y");
|
|
||||||
} catch (_e) {
|
|
||||||
console.log("[Window state manager] No window state file found. Falling back to default values.");
|
|
||||||
mainWindow.setSize(835, 600);
|
|
||||||
}
|
|
||||||
if (isMaximized) {
|
|
||||||
mainWindow.setSize(835, 600); //just so the whole thing doesn't cover whole screen
|
|
||||||
mainWindow.maximize();
|
|
||||||
} else {
|
|
||||||
mainWindow.setSize(width, height);
|
|
||||||
mainWindow.setPosition(xValue, yValue);
|
|
||||||
console.log("[Window state manager] Not maximized.");
|
|
||||||
}
|
|
||||||
if (await getConfig("startMinimized")) {
|
if (await getConfig("startMinimized")) {
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
|
} else {
|
||||||
|
mainWindow.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on("restart", () => {
|
ipcMain.on("restart", () => {
|
||||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -8,13 +8,16 @@ import {
|
||||||
getConfig,
|
getConfig,
|
||||||
injectElectronFlags,
|
injectElectronFlags,
|
||||||
installModLoader,
|
installModLoader,
|
||||||
setConfig
|
modInstallState,
|
||||||
|
setConfig,
|
||||||
|
sleep
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import "./extensions/mods";
|
import "./extensions/mods";
|
||||||
import "./tray";
|
import "./tray";
|
||||||
import {createCustomWindow, createNativeWindow, createTransparentWindow} from "./window";
|
import {createCustomWindow, createNativeWindow, createTransparentWindow, mainWindow} from "./window";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {createTManagerWindow} from "./themeManager/main";
|
import {createTManagerWindow} from "./themeManager/main";
|
||||||
|
import {createSplashWindow} from "./splash/main";
|
||||||
export let iconPath: string;
|
export let iconPath: string;
|
||||||
export let settings: any;
|
export let settings: any;
|
||||||
export let customTitlebar: boolean;
|
export let customTitlebar: boolean;
|
||||||
|
@ -82,6 +85,9 @@ if (!app.requestSingleInstanceLock()) {
|
||||||
iconPath = path.join(__dirname, "../", "/assets/desktop.png");
|
iconPath = path.join(__dirname, "../", "/assets/desktop.png");
|
||||||
}
|
}
|
||||||
async function init(): Promise<void> {
|
async function init(): Promise<void> {
|
||||||
|
if ((await getConfig("skipSplash")) == false) {
|
||||||
|
createSplashWindow();
|
||||||
|
}
|
||||||
switch (await getConfig("windowStyle")) {
|
switch (await getConfig("windowStyle")) {
|
||||||
case "default":
|
case "default":
|
||||||
createCustomWindow();
|
createCustomWindow();
|
||||||
|
|
|
@ -58,7 +58,6 @@ contextBridge.exposeInMainWorld("armcord", {
|
||||||
version: ipcRenderer.sendSync("get-app-version", "app-version"),
|
version: ipcRenderer.sendSync("get-app-version", "app-version"),
|
||||||
mods: ipcRenderer.sendSync("clientmod"),
|
mods: ipcRenderer.sendSync("clientmod"),
|
||||||
packageVersion: ipcRenderer.sendSync("get-package-version", "app-version"),
|
packageVersion: ipcRenderer.sendSync("get-package-version", "app-version"),
|
||||||
splashEnd: () => ipcRenderer.send("splashEnd"),
|
|
||||||
openSettingsWindow: () => ipcRenderer.send("openSettingsWindow")
|
openSettingsWindow: () => ipcRenderer.send("openSettingsWindow")
|
||||||
});
|
});
|
||||||
let windowCallback: (arg0: object) => void;
|
let windowCallback: (arg0: object) => void;
|
||||||
|
@ -70,10 +69,3 @@ contextBridge.exposeInMainWorld("ArmCordRPC", {
|
||||||
ipcRenderer.on("rpc", (_event, data: object) => {
|
ipcRenderer.on("rpc", (_event, data: object) => {
|
||||||
windowCallback(data);
|
windowCallback(data);
|
||||||
});
|
});
|
||||||
//to be only used inside armcord internal setup/splash etc
|
|
||||||
if (window.location.href.indexOf("splash.html") > -1 || window.location.href.indexOf("setup.html") > -1) {
|
|
||||||
contextBridge.exposeInMainWorld("armcordinternal", {
|
|
||||||
restart: () => ipcRenderer.send("restart"),
|
|
||||||
installState: ipcRenderer.sendSync("modInstallState")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,18 +32,16 @@ console.log(`ArmCord ${version}`);
|
||||||
ipcRenderer.on("themeLoader", (_event, message) => {
|
ipcRenderer.on("themeLoader", (_event, message) => {
|
||||||
addStyle(message);
|
addStyle(message);
|
||||||
});
|
});
|
||||||
if (window.location.href.indexOf("splash.html") > -1) {
|
|
||||||
console.log("Skipping titlebar injection and client mod injection.");
|
if (ipcRenderer.sendSync("titlebar")) {
|
||||||
} else {
|
injectTitlebar();
|
||||||
if (ipcRenderer.sendSync("titlebar")) {
|
}
|
||||||
injectTitlebar();
|
if (ipcRenderer.sendSync("mobileMode")) {
|
||||||
}
|
injectMobileStuff();
|
||||||
if (ipcRenderer.sendSync("mobileMode")) {
|
}
|
||||||
injectMobileStuff();
|
sleep(5000).then(async () => {
|
||||||
}
|
// dirty hack to make clicking notifications focus ArmCord
|
||||||
sleep(5000).then(async () => {
|
addScript(`
|
||||||
// dirty hack to make clicking notifications focus ArmCord
|
|
||||||
addScript(`
|
|
||||||
(() => {
|
(() => {
|
||||||
const originalSetter = Object.getOwnPropertyDescriptor(Notification.prototype, "onclick").set;
|
const originalSetter = Object.getOwnPropertyDescriptor(Notification.prototype, "onclick").set;
|
||||||
Object.defineProperty(Notification.prototype, "onclick", {
|
Object.defineProperty(Notification.prototype, "onclick", {
|
||||||
|
@ -57,21 +55,20 @@ if (window.location.href.indexOf("splash.html") > -1) {
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
`);
|
`);
|
||||||
if (ipcRenderer.sendSync("disableAutogain")) {
|
if (ipcRenderer.sendSync("disableAutogain")) {
|
||||||
addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/disableAutogain.js"), "utf8"));
|
addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/disableAutogain.js"), "utf8"));
|
||||||
|
}
|
||||||
|
addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/rpc.js"), "utf8"));
|
||||||
|
const cssPath = path.join(__dirname, "../", "/content/css/discord.css");
|
||||||
|
addStyle(fs.readFileSync(cssPath, "utf8"));
|
||||||
|
if (document.getElementById("window-controls-container") == null) {
|
||||||
|
console.warn("Titlebar didn't inject, retrying...");
|
||||||
|
if (ipcRenderer.sendSync("titlebar")) {
|
||||||
|
fixTitlebar();
|
||||||
}
|
}
|
||||||
addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/rpc.js"), "utf8"));
|
}
|
||||||
const cssPath = path.join(__dirname, "../", "/content/css/discord.css");
|
await updateLang();
|
||||||
addStyle(fs.readFileSync(cssPath, "utf8"));
|
});
|
||||||
if (document.getElementById("window-controls-container") == null) {
|
|
||||||
console.warn("Titlebar didn't inject, retrying...");
|
|
||||||
if (ipcRenderer.sendSync("titlebar")) {
|
|
||||||
fixTitlebar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await updateLang();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Settings info version injection
|
// Settings info version injection
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
|
23
src/splash/main.ts
Normal file
23
src/splash/main.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import {BrowserWindow} from "electron";
|
||||||
|
import {iconPath} from "../main";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
export let splashWindow: BrowserWindow;
|
||||||
|
export async function createSplashWindow(): Promise<void> {
|
||||||
|
splashWindow = new BrowserWindow({
|
||||||
|
width: 300,
|
||||||
|
height: 350,
|
||||||
|
title: "ArmCord",
|
||||||
|
show: true,
|
||||||
|
darkTheme: true,
|
||||||
|
icon: iconPath,
|
||||||
|
frame: false,
|
||||||
|
backgroundColor: "#202225",
|
||||||
|
autoHideMenuBar: true,
|
||||||
|
webPreferences: {
|
||||||
|
sandbox: false,
|
||||||
|
preload: path.join(__dirname, "preload.js")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
splashWindow.loadURL(`file://${__dirname}/splash.html`);
|
||||||
|
}
|
12
src/splash/preload.ts
Normal file
12
src/splash/preload.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import {contextBridge, ipcRenderer} from "electron";
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld("internal", {
|
||||||
|
restart: () => ipcRenderer.send("restart"),
|
||||||
|
installState: ipcRenderer.sendSync("modInstallState"),
|
||||||
|
version: ipcRenderer.sendSync("get-app-version", "app-version"),
|
||||||
|
getLang: (toGet: string) =>
|
||||||
|
ipcRenderer.invoke("getLang", toGet).then((result) => {
|
||||||
|
return result;
|
||||||
|
}),
|
||||||
|
splashEnd: () => ipcRenderer.send("splashEnd")
|
||||||
|
});
|
|
@ -2,10 +2,9 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/ico" href="./favicon.ico" />
|
|
||||||
<title>ArmCord</title>
|
<title>ArmCord</title>
|
||||||
<style>
|
<style>
|
||||||
@import url("css/splash.css");
|
@import url("../content/css/splash.css");
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
window.onbeforeunload = function () {
|
window.onbeforeunload = function () {
|
||||||
|
@ -28,34 +27,34 @@
|
||||||
async function loadLang() {
|
async function loadLang() {
|
||||||
const text = document.getElementById("text-splashscreen");
|
const text = document.getElementById("text-splashscreen");
|
||||||
if (window.navigator.onLine === false) {
|
if (window.navigator.onLine === false) {
|
||||||
text.innerHTML = await armcord.getLang("loading_screen_offline");
|
text.innerHTML = await internal.getLang("loading_screen_offline");
|
||||||
} else {
|
} else {
|
||||||
text.innerHTML = await armcord.getLang("loading_screen_start");
|
text.innerHTML = await internal.getLang("loading_screen_start");
|
||||||
if (window.armcord.version === "3.2.0") {
|
if (window.internal.version === "3.2.1") {
|
||||||
console.log("Running a development build of ArmCord. Skipping updater.");
|
console.log("Running a development build of ArmCord. Skipping updater.");
|
||||||
} else {
|
} else {
|
||||||
const response = await fetch("https://armcord.xyz/latest.json");
|
const response = await fetch("https://armcord.xyz/latest.json");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.version !== window.armcord.version) {
|
if (data.version !== window.internal.version) {
|
||||||
var elem = document.createElement("img");
|
var elem = document.createElement("img");
|
||||||
elem.classList.add("logo");
|
elem.classList.add("logo");
|
||||||
elem.src = "https://armcord.xyz/update.webp";
|
elem.src = "https://armcord.xyz/update.webp";
|
||||||
document.body.prepend(elem);
|
document.body.prepend(elem);
|
||||||
document.getElementById("splashscreen-armcord").remove();
|
document.getElementById("splashscreen-armcord").remove();
|
||||||
text.innerHTML = await armcord.getLang("loading_screen_update");
|
text.innerHTML = await internal.getLang("loading_screen_update");
|
||||||
} else {
|
} else {
|
||||||
console.log("ArmCord is up to date.");
|
console.log("ArmCord is up to date.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
if (armcordinternal.installState === "installing") {
|
if (internal.installState === "installing") {
|
||||||
text.innerHTML = "Installing mods";
|
text.innerHTML = "Installing mods";
|
||||||
} else if (armcordinternal.installState === "done") {
|
} else if (internal.installState === "done") {
|
||||||
return true;
|
return true;
|
||||||
} else if (armcordinternal.installState === "modDownload") {
|
} else if (internal.installState === "modDownload") {
|
||||||
text.innerHTML = "Updating " + armcord.mods;
|
text.innerHTML = "Updating " + armcord.mods;
|
||||||
} else if (armcordinternal.installState === "none") {
|
} else if (internal.installState === "none") {
|
||||||
text.innerHTML = "Nothing to install.";
|
text.innerHTML = "Nothing to install.";
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,23 +64,7 @@
|
||||||
|
|
||||||
while (check() === false) await new Promise((r) => setTimeout(r, 10));
|
while (check() === false) await new Promise((r) => setTimeout(r, 10));
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.armcord.splashEnd();
|
window.internal.splashEnd();
|
||||||
switch (window.armcord.channel) {
|
|
||||||
case "stable":
|
|
||||||
window.location.replace("https://discord.com/app");
|
|
||||||
break;
|
|
||||||
case "canary":
|
|
||||||
window.location.replace("https://canary.discord.com/app");
|
|
||||||
break;
|
|
||||||
case "ptb":
|
|
||||||
window.location.replace("https://ptb.discord.com/app");
|
|
||||||
break;
|
|
||||||
case undefined:
|
|
||||||
window.location.replace("https://discord.com/app");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
window.location.replace("https://discord.com/app");
|
|
||||||
}
|
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ import {
|
||||||
contentPath,
|
contentPath,
|
||||||
firstRun,
|
firstRun,
|
||||||
getConfig,
|
getConfig,
|
||||||
|
getWindowState,
|
||||||
modInstallState,
|
modInstallState,
|
||||||
setConfig,
|
setConfig,
|
||||||
setLang,
|
setLang,
|
||||||
|
@ -26,7 +27,6 @@ import {iconPath} from "./main";
|
||||||
import {createSetupWindow} from "./setup/main";
|
import {createSetupWindow} from "./setup/main";
|
||||||
export let mainWindow: BrowserWindow;
|
export let mainWindow: BrowserWindow;
|
||||||
export let inviteWindow: BrowserWindow;
|
export let inviteWindow: BrowserWindow;
|
||||||
|
|
||||||
let osType = os.type();
|
let osType = os.type();
|
||||||
contextMenu({
|
contextMenu({
|
||||||
showSaveImageAs: true,
|
showSaveImageAs: true,
|
||||||
|
@ -53,10 +53,11 @@ contextMenu({
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
async function doAfterDefiningTheWindow(): Promise<void> {
|
async function doAfterDefiningTheWindow(): Promise<void> {
|
||||||
if (await getConfig("startMinimized")) {
|
if ((await getWindowState("isMaximized")) ?? false) {
|
||||||
mainWindow.hide();
|
mainWindow.setSize(835, 600); //just so the whole thing doesn't cover whole screen
|
||||||
} else {
|
mainWindow.maximize();
|
||||||
mainWindow.show();
|
mainWindow.webContents.executeJavaScript(`document.body.setAttribute("isMaximized", "");`);
|
||||||
|
mainWindow.hide(); // please don't flashbang the user
|
||||||
}
|
}
|
||||||
if (transparency && process.platform === "win32") {
|
if (transparency && process.platform === "win32") {
|
||||||
import("@pyke/vibe").then(async (vibe) => {
|
import("@pyke/vibe").then(async (vibe) => {
|
||||||
|
@ -167,8 +168,10 @@ async function doAfterDefiningTheWindow(): Promise<void> {
|
||||||
trayPath = trayPath.resize({height: 22});
|
trayPath = trayPath.resize({height: 22});
|
||||||
if (process.platform === "win32" && trayPath.getSize().height > 32)
|
if (process.platform === "win32" && trayPath.getSize().height > 32)
|
||||||
trayPath = trayPath.resize({height: 32});
|
trayPath = trayPath.resize({height: 32});
|
||||||
if ((await getConfig("trayIcon")) == "default") {
|
if (await getConfig("tray")) {
|
||||||
tray.setImage(trayPath);
|
if ((await getConfig("trayIcon")) == "default") {
|
||||||
|
tray.setImage(trayPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (await getConfig("dynamicIcon")) {
|
if (await getConfig("dynamicIcon")) {
|
||||||
mainWindow.setIcon(trayPath);
|
mainWindow.setIcon(trayPath);
|
||||||
|
@ -259,15 +262,9 @@ async function doAfterDefiningTheWindow(): Promise<void> {
|
||||||
await setLang(new Intl.DateTimeFormat().resolvedOptions().locale);
|
await setLang(new Intl.DateTimeFormat().resolvedOptions().locale);
|
||||||
createSetupWindow();
|
createSetupWindow();
|
||||||
mainWindow.close();
|
mainWindow.close();
|
||||||
} else if ((await getConfig("skipSplash")) == true) {
|
}
|
||||||
// It's modified elsewhere.
|
mainWindow.loadURL("data:text/html,%3Ch1%3ELoading%21%3C%2Fh1%3E");
|
||||||
// eslint-disable-next-line no-unmodified-loop-condition
|
mainWindow.webContents.executeJavaScript(`
|
||||||
while (modInstallState == "installing") {
|
|
||||||
await sleep(1000);
|
|
||||||
}
|
|
||||||
mainWindow.loadURL("data:text/html,%3Ch1%3ELoading%21%3C%2Fh1%3E");
|
|
||||||
mainWindow.webContents.executeJavaScript(`
|
|
||||||
window.armcord.splashEnd();
|
|
||||||
switch (window.armcord.channel) {
|
switch (window.armcord.channel) {
|
||||||
case "stable":
|
case "stable":
|
||||||
window.location.replace("https://discord.com/app");
|
window.location.replace("https://discord.com/app");
|
||||||
|
@ -285,19 +282,16 @@ async function doAfterDefiningTheWindow(): Promise<void> {
|
||||||
window.location.replace("https://discord.com/app");
|
window.location.replace("https://discord.com/app");
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
} else {
|
if (await getConfig("skipSplash")) {
|
||||||
await mainWindow.loadFile(path.join(__dirname, "/content/splash.html"));
|
|
||||||
}
|
|
||||||
if (await getConfig("startMinimized")) {
|
|
||||||
mainWindow.hide();
|
|
||||||
} else {
|
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export async function createCustomWindow(): Promise<void> {
|
export async function createCustomWindow(): Promise<void> {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 300,
|
width: (await getWindowState("width")) ?? 835,
|
||||||
height: 350,
|
height: (await getWindowState("height")) ?? 600,
|
||||||
|
x: await getWindowState("x"),
|
||||||
|
y: await getWindowState("y"),
|
||||||
title: "ArmCord",
|
title: "ArmCord",
|
||||||
show: false,
|
show: false,
|
||||||
darkTheme: true,
|
darkTheme: true,
|
||||||
|
@ -315,8 +309,10 @@ export async function createCustomWindow(): Promise<void> {
|
||||||
}
|
}
|
||||||
export async function createNativeWindow(): Promise<void> {
|
export async function createNativeWindow(): Promise<void> {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 300,
|
width: (await getWindowState("width")) ?? 835,
|
||||||
height: 350,
|
height: (await getWindowState("height")) ?? 600,
|
||||||
|
x: await getWindowState("x"),
|
||||||
|
y: await getWindowState("y"),
|
||||||
title: "ArmCord",
|
title: "ArmCord",
|
||||||
darkTheme: true,
|
darkTheme: true,
|
||||||
icon: iconPath,
|
icon: iconPath,
|
||||||
|
@ -334,8 +330,10 @@ export async function createNativeWindow(): Promise<void> {
|
||||||
}
|
}
|
||||||
export async function createTransparentWindow(): Promise<void> {
|
export async function createTransparentWindow(): Promise<void> {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 300,
|
width: (await getWindowState("width")) ?? 835,
|
||||||
height: 350,
|
height: (await getWindowState("height")) ?? 600,
|
||||||
|
x: await getWindowState("x"),
|
||||||
|
y: await getWindowState("y"),
|
||||||
title: "ArmCord",
|
title: "ArmCord",
|
||||||
darkTheme: true,
|
darkTheme: true,
|
||||||
icon: iconPath,
|
icon: iconPath,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue