Add tray icon ping icon

This commit is contained in:
smartfridge 2022-08-25 14:57:28 +02:00
parent 934e56bdb0
commit 99417c3d29
10 changed files with 67 additions and 10 deletions

BIN
assets/ping.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

View file

@ -122,7 +122,7 @@
mods: "cumcord",
inviteWebsocket: true,
mobileMode: false,
trayIcon: "ac_plug_colored",
trayIcon: "default",
performanceMode: "none"
});
setTimeout(() => window.armcordinternal.restart(), 5000);
@ -154,7 +154,7 @@
automaticPatches: false,
performanceMode: "none",
alternativePaste: false,
trayIcon: "ac_plug_colored",
trayIcon: "default",
mods: options.mod,
inviteWebsocket: true
});
@ -171,7 +171,7 @@
mods: "none",
alternativePaste: false,
performanceMode: "none",
trayIcon: "ac_plug_colored",
trayIcon: "default",
inviteWebsocket: true
});
setTimeout(() => window.armcordinternal.restart(), 500);

View file

@ -1,5 +1,5 @@
//ipc stuff
import {app, ipcMain, shell, desktopCapturer} from "electron";
import {app, ipcMain, shell, desktopCapturer,nativeImage} from "electron";
import {mainWindow} from "./window";
import {
setConfigBulk,
@ -12,6 +12,8 @@ import {
} from "./utils";
import {customTitlebar} from "./main";
import {createSettingsWindow} from "./settings/main";
import os from "os";
import path from "path";
export function registerIpc() {
ipcMain.on("get-app-path", (event, arg) => {
event.reply("app-path", app.getAppPath());
@ -25,6 +27,21 @@ export function registerIpc() {
ipcMain.on("open-external-link", (event, href: string) => {
shell.openExternal(href);
});
ipcMain.on("setPing", (event, pingCount: number) => {
switch (os.platform()) {
case "linux" ?? "macos":
app.setBadgeCount(pingCount)
break;
case "win32":
if (pingCount > 0) {
var image = nativeImage.createFromPath(path.join(__dirname, "../", `/assets/ping.png`))
mainWindow.setOverlayIcon(image, "badgeCount")
} else {
mainWindow.setOverlayIcon(null, "badgeCount")
}
break;
}
});
ipcMain.on("win-maximize", (event, arg) => {
mainWindow.maximize();
});

View file

@ -59,6 +59,13 @@ export async function setMenu() {
createSettingsWindow();
}
},
{
label: "Reload",
accelerator: "CmdOrCtrl+R",
click: function () {
mainWindow.reload()
}
},
{
label: "Quit",
accelerator: "CmdOrCtrl+Q",

View file

@ -16,6 +16,8 @@ contextBridge.exposeInMainWorld("armcord", {
electron: process.versions.electron,
channel: ipcRenderer.sendSync("channel"),
setLang: (lang: string) => ipcRenderer.send("setLang", lang),
setPingCount: (pingCount: number) => ipcRenderer.send("setPing", pingCount),
setTrayIcon: (favicon: string) => ipcRenderer.send("sendTrayIcon", favicon),
getLang: (toGet: string) =>
ipcRenderer.invoke("getLang", toGet).then((result) => {
return result;

View file

@ -124,7 +124,8 @@
<br />
<div class="switch acTray">
<select name="trayIcon" id="trayIcon" class="left dropdown">
<option value="ac_plug_colored">Default</option>
<option value="default">Default (Dynamic)</option>
<option value="ac_plug_colored">Plug colored</option>
<option value="dsc-tray">Discord Icon</option>
<option value="ac_white_plug">White Icon</option>
<option value="ac_black_plug">Black Icon</option>

View file

@ -159,7 +159,8 @@
<br />
<div class="switch acTray">
<select name="trayIcon" id="trayIcon" class="left dropdown">
<option value="ac_plug_colored">Default</option>
<option value="default">Default (dynamic)</option>
<option value="ac_plug_colored">Plug colored</option>
<option value="dsc-tray">Discord Icon</option>
<option value="ac_white_plug">White Icon</option>
<option value="ac_black_plug">Black Icon</option>

View file

@ -4,12 +4,15 @@ import {mainWindow} from "./window";
import {getConfig, getConfigLocation, setWindowState} from "./utils";
import * as path from "path";
import {createSettingsWindow} from "./settings/main";
let tray: any = null;
export let tray: any = null;
app.whenReady().then(async () => {
let finishedSetup = await getConfig("doneSetup");
var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored";
if (trayIcon = "default") {
trayIcon = "dsc-tray"
}
let trayPath = nativeImage.createFromPath(path.join(__dirname, "../", `/assets/${trayIcon}.png`));
if (process.platform === "darwin" && trayPath.getSize().height > 22) trayPath = trayIcon.resize({height: 22});
if (process.platform === "darwin" && trayPath.getSize().height > 22) trayPath = trayPath.resize({height: 22});
if ((await getConfig("windowStyle")) == "basic") {
var clientName = (await getConfig("clientName")) ?? "ArmCord";
tray = new Tray(trayPath);

View file

@ -45,7 +45,7 @@ export function setup() {
skipSplash: false,
inviteWebsocket: true,
mobileMode: false,
trayIcon: "ac_plug_colored",
trayIcon: "default",
doneSetup: false
};
setConfigBulk({

View file

@ -2,7 +2,7 @@
// I had to add most of the window creation code here to split both into seperete functions
// WHY? Because I can't use the same code for both due to annoying bug with value `frame` not responding to variables
// I'm sorry for this mess but I'm not sure how to fix it.
import {BrowserWindow, shell, app, dialog} from "electron";
import {BrowserWindow, shell, app, dialog, nativeImage} from "electron";
import path from "path";
import {
checkIfConfigIsBroken,
@ -19,6 +19,7 @@ import * as fs from "fs";
import startServer from "./socket";
import contextMenu from "electron-context-menu";
import os from "os";
import {tray} from "./tray";
export var icon: string;
export let mainWindow: BrowserWindow;
export let inviteWindow: BrowserWindow;
@ -86,6 +87,31 @@ async function doAfterDefiningTheWindow() {
if (/api\/v\d\/science$/g.test(details.url)) return callback({cancel: true});
return callback({});
});
if (await getConfig("trayIcon") == "default") {
mainWindow.webContents.on("page-favicon-updated", async (event) => {
var faviconBase64 = await mainWindow.webContents.executeJavaScript(`
var getFavicon = function(){
var favicon = undefined;
var nodeList = document.getElementsByTagName("link");
for (var i = 0; i < nodeList.length; i++)
{
if((nodeList[i].getAttribute("rel") == "icon")||(nodeList[i].getAttribute("rel") == "shortcut icon"))
{
favicon = nodeList[i].getAttribute("href");
}
}
return favicon;
}
getFavicon()
`)
console.log(app.getPath("cache"))
var buf = new Buffer(faviconBase64.replace(/^data:image\/\w+;base64,/, ""), 'base64');
fs.writeFileSync(path.join(app.getPath("cache"), "/", "tray.png"), buf, "utf-8");
let trayPath = nativeImage.createFromPath(path.join(app.getPath("cache"), "/", "tray.png"));
if (process.platform === "darwin" && trayPath.getSize().height > 22) trayPath = trayPath.resize({height: 22});
tray.setImage(trayPath)
})
}
const userDataPath = app.getPath("userData");
const themesFolder = userDataPath + "/themes/";
if (!fs.existsSync(themesFolder)) {