Rewrite splash

This commit is contained in:
smartfrigde 2023-06-11 18:50:07 +02:00
parent 451c96d57c
commit 89e4c3570d
9 changed files with 107 additions and 115 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View file

@ -17,6 +17,7 @@ import {createSettingsWindow} from "./settings/main";
import os from "os";
import path from "path";
import {createTManagerWindow} from "./themeManager/main";
import {splashWindow} from "./splash/main";
export function registerIpc(): void {
ipcMain.on("get-app-path", (event) => {
event.reply("app-path", app.getAppPath());
@ -82,31 +83,11 @@ export function registerIpc(): void {
event.returnValue = packageVersion;
});
ipcMain.on("splashEnd", async () => {
let width = 835,
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.");
}
splashWindow.close();
if (await getConfig("startMinimized")) {
mainWindow.hide();
} else {
mainWindow.show();
}
});
ipcMain.on("restart", () => {

View file

@ -8,13 +8,16 @@ import {
getConfig,
injectElectronFlags,
installModLoader,
setConfig
modInstallState,
setConfig,
sleep
} from "./utils";
import "./extensions/mods";
import "./tray";
import {createCustomWindow, createNativeWindow, createTransparentWindow} from "./window";
import {createCustomWindow, createNativeWindow, createTransparentWindow, mainWindow} from "./window";
import path from "path";
import {createTManagerWindow} from "./themeManager/main";
import {createSplashWindow} from "./splash/main";
export let iconPath: string;
export let settings: any;
export let customTitlebar: boolean;
@ -82,6 +85,9 @@ if (!app.requestSingleInstanceLock()) {
iconPath = path.join(__dirname, "../", "/assets/desktop.png");
}
async function init(): Promise<void> {
if ((await getConfig("skipSplash")) == false) {
createSplashWindow();
}
switch (await getConfig("windowStyle")) {
case "default":
createCustomWindow();

View file

@ -58,7 +58,6 @@ contextBridge.exposeInMainWorld("armcord", {
version: ipcRenderer.sendSync("get-app-version", "app-version"),
mods: ipcRenderer.sendSync("clientmod"),
packageVersion: ipcRenderer.sendSync("get-package-version", "app-version"),
splashEnd: () => ipcRenderer.send("splashEnd"),
openSettingsWindow: () => ipcRenderer.send("openSettingsWindow")
});
let windowCallback: (arg0: object) => void;
@ -70,10 +69,3 @@ contextBridge.exposeInMainWorld("ArmCordRPC", {
ipcRenderer.on("rpc", (_event, data: object) => {
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")
});
}

View file

@ -32,18 +32,16 @@ console.log(`ArmCord ${version}`);
ipcRenderer.on("themeLoader", (_event, message) => {
addStyle(message);
});
if (window.location.href.indexOf("splash.html") > -1) {
console.log("Skipping titlebar injection and client mod injection.");
} else {
if (ipcRenderer.sendSync("titlebar")) {
injectTitlebar();
}
if (ipcRenderer.sendSync("mobileMode")) {
injectMobileStuff();
}
sleep(5000).then(async () => {
// dirty hack to make clicking notifications focus ArmCord
addScript(`
if (ipcRenderer.sendSync("titlebar")) {
injectTitlebar();
}
if (ipcRenderer.sendSync("mobileMode")) {
injectMobileStuff();
}
sleep(5000).then(async () => {
// dirty hack to make clicking notifications focus ArmCord
addScript(`
(() => {
const originalSetter = Object.getOwnPropertyDescriptor(Notification.prototype, "onclick").set;
Object.defineProperty(Notification.prototype, "onclick", {
@ -57,21 +55,20 @@ if (window.location.href.indexOf("splash.html") > -1) {
});
})();
`);
if (ipcRenderer.sendSync("disableAutogain")) {
addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/disableAutogain.js"), "utf8"));
if (ipcRenderer.sendSync("disableAutogain")) {
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");
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();
});
}
}
await updateLang();
});
// Settings info version injection
setInterval(() => {

23
src/splash/main.ts Normal file
View 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
View 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")
});

View file

@ -2,10 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/ico" href="./favicon.ico" />
<title>ArmCord</title>
<style>
@import url("css/splash.css");
@import url("../content/css/splash.css");
</style>
<script>
window.onbeforeunload = function () {
@ -28,34 +27,34 @@
async function loadLang() {
const text = document.getElementById("text-splashscreen");
if (window.navigator.onLine === false) {
text.innerHTML = await armcord.getLang("loading_screen_offline");
text.innerHTML = await internal.getLang("loading_screen_offline");
} else {
text.innerHTML = await armcord.getLang("loading_screen_start");
if (window.armcord.version === "3.2.0") {
text.innerHTML = await internal.getLang("loading_screen_start");
if (window.internal.version === "3.2.1") {
console.log("Running a development build of ArmCord. Skipping updater.");
} else {
const response = await fetch("https://armcord.xyz/latest.json");
const data = await response.json();
if (data.version !== window.armcord.version) {
if (data.version !== window.internal.version) {
var elem = document.createElement("img");
elem.classList.add("logo");
elem.src = "https://armcord.xyz/update.webp";
document.body.prepend(elem);
document.getElementById("splashscreen-armcord").remove();
text.innerHTML = await armcord.getLang("loading_screen_update");
text.innerHTML = await internal.getLang("loading_screen_update");
} else {
console.log("ArmCord is up to date.");
}
}
function check() {
if (armcordinternal.installState === "installing") {
if (internal.installState === "installing") {
text.innerHTML = "Installing mods";
} else if (armcordinternal.installState === "done") {
} else if (internal.installState === "done") {
return true;
} else if (armcordinternal.installState === "modDownload") {
} else if (internal.installState === "modDownload") {
text.innerHTML = "Updating " + armcord.mods;
} else if (armcordinternal.installState === "none") {
} else if (internal.installState === "none") {
text.innerHTML = "Nothing to install.";
return true;
} else {
@ -65,23 +64,7 @@
while (check() === false) await new Promise((r) => setTimeout(r, 10));
setTimeout(() => {
window.armcord.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");
}
window.internal.splashEnd();
}, 3000);
}
}

View file

@ -9,6 +9,7 @@ import {
contentPath,
firstRun,
getConfig,
getWindowState,
modInstallState,
setConfig,
setLang,
@ -26,7 +27,6 @@ import {iconPath} from "./main";
import {createSetupWindow} from "./setup/main";
export let mainWindow: BrowserWindow;
export let inviteWindow: BrowserWindow;
let osType = os.type();
contextMenu({
showSaveImageAs: true,
@ -53,10 +53,11 @@ contextMenu({
]
});
async function doAfterDefiningTheWindow(): Promise<void> {
if (await getConfig("startMinimized")) {
mainWindow.hide();
} else {
mainWindow.show();
if ((await getWindowState("isMaximized")) ?? false) {
mainWindow.setSize(835, 600); //just so the whole thing doesn't cover whole screen
mainWindow.maximize();
mainWindow.webContents.executeJavaScript(`document.body.setAttribute("isMaximized", "");`);
mainWindow.hide(); // please don't flashbang the user
}
if (transparency && process.platform === "win32") {
import("@pyke/vibe").then(async (vibe) => {
@ -167,8 +168,10 @@ async function doAfterDefiningTheWindow(): Promise<void> {
trayPath = trayPath.resize({height: 22});
if (process.platform === "win32" && trayPath.getSize().height > 32)
trayPath = trayPath.resize({height: 32});
if ((await getConfig("trayIcon")) == "default") {
tray.setImage(trayPath);
if (await getConfig("tray")) {
if ((await getConfig("trayIcon")) == "default") {
tray.setImage(trayPath);
}
}
if (await getConfig("dynamicIcon")) {
mainWindow.setIcon(trayPath);
@ -259,15 +262,9 @@ async function doAfterDefiningTheWindow(): Promise<void> {
await setLang(new Intl.DateTimeFormat().resolvedOptions().locale);
createSetupWindow();
mainWindow.close();
} else if ((await getConfig("skipSplash")) == true) {
// It's modified elsewhere.
// eslint-disable-next-line no-unmodified-loop-condition
while (modInstallState == "installing") {
await sleep(1000);
}
mainWindow.loadURL("data:text/html,%3Ch1%3ELoading%21%3C%2Fh1%3E");
mainWindow.webContents.executeJavaScript(`
window.armcord.splashEnd();
}
mainWindow.loadURL("data:text/html,%3Ch1%3ELoading%21%3C%2Fh1%3E");
mainWindow.webContents.executeJavaScript(`
switch (window.armcord.channel) {
case "stable":
window.location.replace("https://discord.com/app");
@ -285,19 +282,16 @@ async function doAfterDefiningTheWindow(): Promise<void> {
window.location.replace("https://discord.com/app");
}
`);
} else {
await mainWindow.loadFile(path.join(__dirname, "/content/splash.html"));
}
if (await getConfig("startMinimized")) {
mainWindow.hide();
} else {
if (await getConfig("skipSplash")) {
mainWindow.show();
}
}
export async function createCustomWindow(): Promise<void> {
mainWindow = new BrowserWindow({
width: 300,
height: 350,
width: (await getWindowState("width")) ?? 835,
height: (await getWindowState("height")) ?? 600,
x: await getWindowState("x"),
y: await getWindowState("y"),
title: "ArmCord",
show: false,
darkTheme: true,
@ -315,8 +309,10 @@ export async function createCustomWindow(): Promise<void> {
}
export async function createNativeWindow(): Promise<void> {
mainWindow = new BrowserWindow({
width: 300,
height: 350,
width: (await getWindowState("width")) ?? 835,
height: (await getWindowState("height")) ?? 600,
x: await getWindowState("x"),
y: await getWindowState("y"),
title: "ArmCord",
darkTheme: true,
icon: iconPath,
@ -334,8 +330,10 @@ export async function createNativeWindow(): Promise<void> {
}
export async function createTransparentWindow(): Promise<void> {
mainWindow = new BrowserWindow({
width: 300,
height: 350,
width: (await getWindowState("width")) ?? 835,
height: (await getWindowState("height")) ?? 600,
x: await getWindowState("x"),
y: await getWindowState("y"),
title: "ArmCord",
darkTheme: true,
icon: iconPath,