From 99417c3d29cf099c7b144e15532a2974f253c7d5 Mon Sep 17 00:00:00 2001 From: smartfridge <37928912+smartfrigde@users.noreply.github.com> Date: Thu, 25 Aug 2022 14:57:28 +0200 Subject: [PATCH] Add tray icon ping icon --- assets/ping.png | Bin 0 -> 285 bytes src/content/setup.html | 6 +++--- src/ipc.ts | 19 ++++++++++++++++++- src/menu.ts | 7 +++++++ src/preload/bridge.ts | 2 ++ src/settings/hummus.html | 3 ++- src/settings/settings.html | 3 ++- src/tray.ts | 7 +++++-- src/utils.ts | 2 +- src/window.ts | 28 +++++++++++++++++++++++++++- 10 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 assets/ping.png diff --git a/assets/ping.png b/assets/ping.png new file mode 100644 index 0000000000000000000000000000000000000000..1d0762a0b1ffd334adcea3ec03e581ac60199be7 GIT binary patch literal 285 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6XVU3I`u#fXMsm#F#`j) zFbFd;%$g$s6toQR32_C|uUuWoKw)Q+K$?Y1g8YIRm~2-(`OP)?*Z)aprr6spf4t1* z%{1rZKTrO$`WIF0r{Xg8L!!vdNV^tP528|;}<|HZfY}2ut zw5hlF>iS!)WphupIHyez4vcMkvar$igM7-~Bso2n|8ICt8H+^izqj;9;rp8GGiQ(e ZVP~jf-(|V><~^WI44$rjF6*2UngD<@X+8h| literal 0 HcmV?d00001 diff --git a/src/content/setup.html b/src/content/setup.html index 9a00dd0..14e11de 100644 --- a/src/content/setup.html +++ b/src/content/setup.html @@ -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); diff --git a/src/ipc.ts b/src/ipc.ts index 045314e..21ff712 100644 --- a/src/ipc.ts +++ b/src/ipc.ts @@ -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(); }); diff --git a/src/menu.ts b/src/menu.ts index f405455..a76e838 100644 --- a/src/menu.ts +++ b/src/menu.ts @@ -59,6 +59,13 @@ export async function setMenu() { createSettingsWindow(); } }, + { + label: "Reload", + accelerator: "CmdOrCtrl+R", + click: function () { + mainWindow.reload() + } + }, { label: "Quit", accelerator: "CmdOrCtrl+Q", diff --git a/src/preload/bridge.ts b/src/preload/bridge.ts index 3870c4f..1365f1e 100644 --- a/src/preload/bridge.ts +++ b/src/preload/bridge.ts @@ -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; diff --git a/src/settings/hummus.html b/src/settings/hummus.html index ba2cfb9..010ba50 100644 --- a/src/settings/hummus.html +++ b/src/settings/hummus.html @@ -124,7 +124,8 @@
- + + diff --git a/src/tray.ts b/src/tray.ts index 3a0b87f..bf46cdf 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -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); diff --git a/src/utils.ts b/src/utils.ts index e4e3a71..bb802fc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -45,7 +45,7 @@ export function setup() { skipSplash: false, inviteWebsocket: true, mobileMode: false, - trayIcon: "ac_plug_colored", + trayIcon: "default", doneSetup: false }; setConfigBulk({ diff --git a/src/window.ts b/src/window.ts index c0b12ba..a0ae3a7 100644 --- a/src/window.ts +++ b/src/window.ts @@ -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)) {