mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Update Window state manager (#291)
* Update Window state * Add x/y state saving
This commit is contained in:
parent
e2fc0c6401
commit
254ba93433
11 changed files with 267 additions and 147 deletions
|
@ -56,7 +56,7 @@
|
|||
} else if (armcordinternal.installState === "modDownload") {
|
||||
text.innerHTML = "Updating " + armcord.mods;
|
||||
} else if (armcordinternal.installState === "none") {
|
||||
text.innerHTML = "Nothing to install. Starting ArmCord";
|
||||
text.innerHTML = "Nothing to install.";
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//ipc stuff
|
||||
import {app, ipcMain, shell, desktopCapturer, nativeImage} from "electron";
|
||||
import {app, ipcMain, shell, desktopCapturer, nativeImage, screen} from "electron";
|
||||
import {mainWindow} from "./window";
|
||||
import {
|
||||
setConfigBulk,
|
||||
|
@ -87,6 +87,8 @@ export function registerIpc() {
|
|||
var width = (await getWindowState("width")) ?? 800;
|
||||
var height = (await getWindowState("height")) ?? 600;
|
||||
var isMaximized = (await getWindowState("isMaximized")) ?? false;
|
||||
var xValue = await getWindowState("x");
|
||||
var yValue = await getWindowState("y");
|
||||
} catch (e) {
|
||||
console.log("[Window state manager] No window state file found. Fallbacking to default values.");
|
||||
mainWindow.setSize(800, 600);
|
||||
|
@ -96,6 +98,7 @@ export function registerIpc() {
|
|||
mainWindow.maximize();
|
||||
} else {
|
||||
mainWindow.setSize(width, height);
|
||||
mainWindow.setPosition(xValue, yValue);
|
||||
console.log("[Window state manager] Not maximized.");
|
||||
}
|
||||
});
|
||||
|
|
111
src/preload/alt.ts
Normal file
111
src/preload/alt.ts
Normal file
|
@ -0,0 +1,111 @@
|
|||
import {ipcRenderer} from "electron";
|
||||
import "./bridge";
|
||||
import "./capturer";
|
||||
import "./patch";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import {fixTitlebar, injectHummusTitlebar, injectTitlebar} from "./titlebar";
|
||||
import {sleep, addStyle, addScript} from "../utils";
|
||||
import {injectMobileStuff} from "./mobile";
|
||||
var version = ipcRenderer.sendSync("displayVersion");
|
||||
var channel = ipcRenderer.sendSync("channel");
|
||||
async function updateLang() {
|
||||
if (window.location.href.indexOf("setup.html") > -1) {
|
||||
console.log("Setup, skipping lang update");
|
||||
} else {
|
||||
const value = `; ${document.cookie}`;
|
||||
const parts: any = value.split(`; locale=`);
|
||||
if (parts.length === 2) ipcRenderer.send("setLang", parts.pop().split(";").shift());
|
||||
}
|
||||
}
|
||||
declare global {
|
||||
interface Window {
|
||||
armcord: any;
|
||||
}
|
||||
}
|
||||
|
||||
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")) {
|
||||
if (channel == "hummus") {
|
||||
injectHummusTitlebar();
|
||||
} else {
|
||||
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", {
|
||||
set(onClick) {
|
||||
originalSetter.call(this, function() {
|
||||
onClick.apply(this, arguments);
|
||||
armcord.window.show();
|
||||
})
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
})();
|
||||
`);
|
||||
|
||||
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")) {
|
||||
if (channel == "hummus") {
|
||||
injectHummusTitlebar();
|
||||
} else {
|
||||
fixTitlebar();
|
||||
}
|
||||
}
|
||||
}
|
||||
await updateLang();
|
||||
});
|
||||
}
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 GooseNest
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
// Settings info version injection
|
||||
setInterval(() => {
|
||||
const host = document.getElementsByClassName("info-3pQQBb")[0];
|
||||
if (!host || document.querySelector("#ac-ver")) return;
|
||||
const el = document.createElement("span");
|
||||
el.id = "ac-ver";
|
||||
el.classList.add("text-xs-normal-3SiVjE", "line-18uChy");
|
||||
|
||||
el.textContent = `\nArmCord Version: ${version}`;
|
||||
el.onclick = () => ipcRenderer.send("openSettingsWindow");
|
||||
host.append(el);
|
||||
}, 2000);
|
|
@ -102,3 +102,45 @@ export function injectHummusTitlebar() {
|
|||
});
|
||||
});
|
||||
}
|
||||
export function fixTitlebar() {
|
||||
var elem = document.createElement("div");
|
||||
elem.innerHTML = `<nav class="titlebar">
|
||||
<div class="window-title" id="window-title"></div>
|
||||
<div id="window-controls-container">
|
||||
<div id="spacer"></div>
|
||||
<div id="minimize"><div id="minimize-icon"></div></div>
|
||||
<div id="maximize"><div id="maximize-icon"></div></div>
|
||||
<div id="quit"><div id="quit-icon"></div></div>
|
||||
</div>
|
||||
</nav>`;
|
||||
elem.classList.add("withFrame-haYltI");
|
||||
if (document.getElementById("app-mount") == null) {
|
||||
document.body.appendChild(elem);
|
||||
} else {
|
||||
document.getElementById("app-mount")!.prepend(elem);
|
||||
}
|
||||
var minimize = document.getElementById("minimize");
|
||||
var maximize = document.getElementById("maximize");
|
||||
var quit = document.getElementById("quit");
|
||||
|
||||
minimize!.addEventListener("click", () => {
|
||||
ipcRenderer.send("win-minimize");
|
||||
});
|
||||
|
||||
maximize!.addEventListener("click", () => {
|
||||
if (ipcRenderer.sendSync("win-isMaximized") == true) {
|
||||
ipcRenderer.send("win-unmaximize");
|
||||
document.body.removeAttribute("isMaximized");
|
||||
} else if (ipcRenderer.sendSync("win-isNormal") == true) {
|
||||
ipcRenderer.send("win-maximize");
|
||||
}
|
||||
});
|
||||
|
||||
quit!.addEventListener("click", () => {
|
||||
if (ipcRenderer.sendSync("minimizeToTray") === true) {
|
||||
ipcRenderer.send("win-hide");
|
||||
} else if (ipcRenderer.sendSync("minimizeToTray") === false) {
|
||||
ipcRenderer.send("win-quit");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import fs from "fs";
|
|||
import {mainWindow} from "../window";
|
||||
var settingsWindow: BrowserWindow;
|
||||
var instance: number = 0;
|
||||
checkForDataFolder();
|
||||
//checkForDataFolder();
|
||||
const userDataPath = app.getPath("userData");
|
||||
const storagePath = path.join(userDataPath, "/storage/");
|
||||
const themesPath = path.join(userDataPath, "/themes/");
|
||||
|
|
|
@ -56,7 +56,13 @@ app.whenReady().then(async () => {
|
|||
label: `Quit ${clientName}`,
|
||||
click: function () {
|
||||
let [width, height] = mainWindow.getSize();
|
||||
setWindowState({width: width, height: height, isMaximized: mainWindow.isMaximized()});
|
||||
setWindowState({
|
||||
width: width,
|
||||
height: height,
|
||||
isMaximized: mainWindow.isMaximized(),
|
||||
x: mainWindow.getPosition()[0],
|
||||
y: mainWindow.getPosition()[1]
|
||||
});
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as fs from "fs";
|
||||
import {app, dialog, session} from "electron";
|
||||
import {app, dialog, Rectangle} from "electron";
|
||||
import path from "path";
|
||||
import fetch from "cross-fetch";
|
||||
import extract from "extract-zip";
|
||||
|
@ -199,6 +199,8 @@ export async function getLangName() {
|
|||
export interface WindowState {
|
||||
width: number;
|
||||
height: number;
|
||||
x: number;
|
||||
y: number;
|
||||
isMaximized: boolean;
|
||||
}
|
||||
export async function setWindowState(object: WindowState) {
|
||||
|
@ -217,7 +219,8 @@ export async function getWindowState(object: string) {
|
|||
const settingsFile = storagePath + "window.json";
|
||||
let rawdata = fs.readFileSync(settingsFile, "utf-8");
|
||||
let returndata = JSON.parse(rawdata);
|
||||
console.log("[Window state manager] " + object + ": " + returndata[object]);
|
||||
console.log(returndata);
|
||||
console.log("[Window state manager] " + returndata);
|
||||
return returndata[object];
|
||||
}
|
||||
//ArmCord Settings/Storage manager
|
||||
|
|
|
@ -178,7 +178,9 @@ async function doAfterDefiningTheWindow() {
|
|||
await setWindowState({
|
||||
width: width,
|
||||
height: height,
|
||||
isMaximized: mainWindow.isMaximized()
|
||||
isMaximized: mainWindow.isMaximized(),
|
||||
x: mainWindow.getPosition()[0],
|
||||
y: mainWindow.getPosition()[1]
|
||||
});
|
||||
if (await getConfig("minimizeToTray")) {
|
||||
e.preventDefault();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue