mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Avoid window creation/init if 2nd instance (#297)
* fix first instance not showing when opening 2nd * Avoid window creation/init if 2nd instance * fix white flash on startup, add en-us transparent entry for future use * fix white flash for settings window too Co-authored-by: octopushugger <octopushugger@github.com>
This commit is contained in:
parent
8a9a62aa57
commit
63db76cd7e
4 changed files with 77 additions and 73 deletions
|
@ -19,6 +19,7 @@
|
|||
"settings-theme-desc3": "uses native titlebar of OS you're currently running (e.g Windows 7/10). Functions more\n similar to actual Discord app on Linux.",
|
||||
"settings-theme-default": "Default",
|
||||
"settings-theme-native": "Native",
|
||||
"settings-theme-transparent": "Transparent (Experimental)",
|
||||
"settings-csp-desc": "ArmCord CSP is our system that manages loading custom content loading into the Discord app. Stuff like\n client mods and themes depend on it. Disable if you want to get rid of mods and custom styles.",
|
||||
"settings-tray": "Minimize to tray",
|
||||
"settings-tray-desc": "When disabled, ArmCord will close like any other window when closed, otherwise it'll sit back and relax\n in your system tray for later.",
|
||||
|
|
120
src/main.ts
120
src/main.ts
|
@ -19,65 +19,71 @@ export var settings: any;
|
|||
export var customTitlebar: boolean;
|
||||
export var clientName: "ArmCord";
|
||||
|
||||
// Your data now belongs to CCP
|
||||
let settingsFile = fs.readFileSync(getConfigLocation(), "utf-8");
|
||||
crashReporter.start({uploadToServer: false, extra: {settingsFile}});
|
||||
|
||||
if (process.platform == "linux") {
|
||||
if (process.env.$XDG_SESSION_TYPE == "wayland") {
|
||||
console.log("Wayland specific patches applied.");
|
||||
app.commandLine.appendSwitch("ozone-platform=wayland");
|
||||
if (process.env.$XDG_CURRENT_DESKTOP == "GNOME") {
|
||||
app.commandLine.appendSwitch("enable-features=UseOzonePlatform,WaylandWindowDecorations");
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
// kill if 2nd instance
|
||||
app.quit();
|
||||
} else {
|
||||
// Your data now belongs to CCP
|
||||
let settingsFile = fs.readFileSync(getConfigLocation(), "utf-8");
|
||||
crashReporter.start({uploadToServer: false, extra: {settingsFile}});
|
||||
|
||||
if (process.platform == "linux") {
|
||||
if (process.env.$XDG_SESSION_TYPE == "wayland") {
|
||||
console.log("Wayland specific patches applied.");
|
||||
app.commandLine.appendSwitch("ozone-platform=wayland");
|
||||
if (process.env.$XDG_CURRENT_DESKTOP == "GNOME") {
|
||||
app.commandLine.appendSwitch("enable-features=UseOzonePlatform,WaylandWindowDecorations");
|
||||
} else {
|
||||
app.commandLine.appendSwitch("enable-features=UseOzonePlatform");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkForDataFolder();
|
||||
checkIfConfigExists();
|
||||
injectElectronFlags();
|
||||
app.whenReady().then(async () => {
|
||||
if ((await getConfig("customIcon")) !== undefined ?? null) {
|
||||
iconPath = await getConfig("customIcon");
|
||||
} else {
|
||||
app.commandLine.appendSwitch("enable-features=UseOzonePlatform");
|
||||
iconPath = path.join(__dirname, "../", "/assets/ac_icon_transparent.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkForDataFolder();
|
||||
checkIfConfigExists();
|
||||
injectElectronFlags();
|
||||
app.whenReady().then(async () => {
|
||||
if ((await getConfig("customIcon")) !== undefined ?? null) {
|
||||
iconPath = await getConfig("customIcon");
|
||||
} else {
|
||||
iconPath = path.join(__dirname, "../", "/assets/ac_icon_transparent.png");
|
||||
}
|
||||
async function init() {
|
||||
switch (await getConfig("windowStyle")) {
|
||||
case "default":
|
||||
createCustomWindow();
|
||||
customTitlebar = true;
|
||||
break;
|
||||
case "native":
|
||||
createNativeWindow();
|
||||
break;
|
||||
case "transparent":
|
||||
createTransparentWindow();
|
||||
break;
|
||||
case "basic":
|
||||
createNativeWindow();
|
||||
break;
|
||||
default:
|
||||
createCustomWindow();
|
||||
customTitlebar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await init();
|
||||
await installModLoader();
|
||||
session.fromPartition("some-partition").setPermissionRequestHandler((webContents, permission, callback) => {
|
||||
if (permission === "notifications") {
|
||||
// Approves the permissions request
|
||||
callback(true);
|
||||
}
|
||||
if (permission === "media") {
|
||||
// Approves the permissions request
|
||||
callback(true);
|
||||
async function init() {
|
||||
switch (await getConfig("windowStyle")) {
|
||||
case "default":
|
||||
createCustomWindow();
|
||||
customTitlebar = true;
|
||||
break;
|
||||
case "native":
|
||||
createNativeWindow();
|
||||
break;
|
||||
case "transparent":
|
||||
createTransparentWindow();
|
||||
break;
|
||||
case "basic":
|
||||
createNativeWindow();
|
||||
break;
|
||||
default:
|
||||
createCustomWindow();
|
||||
customTitlebar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await init();
|
||||
await installModLoader();
|
||||
session.fromPartition("some-partition").setPermissionRequestHandler((webContents, permission, callback) => {
|
||||
if (permission === "notifications") {
|
||||
// Approves the permissions request
|
||||
callback(true);
|
||||
}
|
||||
if (permission === "media") {
|
||||
// Approves the permissions request
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
app.on("activate", async function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) await init();
|
||||
});
|
||||
});
|
||||
app.on("activate", async function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) await init();
|
||||
});
|
||||
});
|
||||
}
|
|
@ -38,6 +38,7 @@ export function createSettingsWindow() {
|
|||
title: `ArmCord Settings | Version: ${getDisplayVersion()}`,
|
||||
darkTheme: true,
|
||||
frame: true,
|
||||
backgroundColor: "#2f3136",
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
sandbox: false,
|
||||
|
|
|
@ -78,23 +78,17 @@ async function doAfterDefiningTheWindow() {
|
|||
}
|
||||
mainWindow.webContents.userAgent = `Mozilla/5.0 (X11; ${osType} ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36`; //fake useragent for screenshare to work
|
||||
}
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
app.on("second-instance", (event, commandLine, workingDirectory, additionalData) => {
|
||||
// Print out data received from the second instance.
|
||||
console.log(additionalData);
|
||||
|
||||
if (!gotTheLock) {
|
||||
app.quit();
|
||||
} else {
|
||||
app.on("second-instance", (event, commandLine, workingDirectory, additionalData) => {
|
||||
// Print out data received from the second instance.
|
||||
console.log(additionalData);
|
||||
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
mainWindow.webContents.setWindowOpenHandler(({url}) => {
|
||||
// Allow about:blank (used by Vencord QuickCss popup)
|
||||
if (url === "about:blank") return {action: "allow"};
|
||||
|
@ -273,6 +267,7 @@ export function createCustomWindow() {
|
|||
darkTheme: true,
|
||||
icon: iconPath,
|
||||
frame: false,
|
||||
backgroundColor: "#202225",
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
sandbox: false,
|
||||
|
@ -291,6 +286,7 @@ export function createNativeWindow() {
|
|||
icon: iconPath,
|
||||
show: false,
|
||||
frame: true,
|
||||
backgroundColor: "#202225",
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
sandbox: false,
|
||||
|
|
Loading…
Reference in a new issue