mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Add tray icon ping icon
This commit is contained in:
parent
934e56bdb0
commit
99417c3d29
10 changed files with 67 additions and 10 deletions
BIN
assets/ping.png
Normal file
BIN
assets/ping.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 285 B |
|
@ -122,7 +122,7 @@
|
||||||
mods: "cumcord",
|
mods: "cumcord",
|
||||||
inviteWebsocket: true,
|
inviteWebsocket: true,
|
||||||
mobileMode: false,
|
mobileMode: false,
|
||||||
trayIcon: "ac_plug_colored",
|
trayIcon: "default",
|
||||||
performanceMode: "none"
|
performanceMode: "none"
|
||||||
});
|
});
|
||||||
setTimeout(() => window.armcordinternal.restart(), 5000);
|
setTimeout(() => window.armcordinternal.restart(), 5000);
|
||||||
|
@ -154,7 +154,7 @@
|
||||||
automaticPatches: false,
|
automaticPatches: false,
|
||||||
performanceMode: "none",
|
performanceMode: "none",
|
||||||
alternativePaste: false,
|
alternativePaste: false,
|
||||||
trayIcon: "ac_plug_colored",
|
trayIcon: "default",
|
||||||
mods: options.mod,
|
mods: options.mod,
|
||||||
inviteWebsocket: true
|
inviteWebsocket: true
|
||||||
});
|
});
|
||||||
|
@ -171,7 +171,7 @@
|
||||||
mods: "none",
|
mods: "none",
|
||||||
alternativePaste: false,
|
alternativePaste: false,
|
||||||
performanceMode: "none",
|
performanceMode: "none",
|
||||||
trayIcon: "ac_plug_colored",
|
trayIcon: "default",
|
||||||
inviteWebsocket: true
|
inviteWebsocket: true
|
||||||
});
|
});
|
||||||
setTimeout(() => window.armcordinternal.restart(), 500);
|
setTimeout(() => window.armcordinternal.restart(), 500);
|
||||||
|
|
19
src/ipc.ts
19
src/ipc.ts
|
@ -1,5 +1,5 @@
|
||||||
//ipc stuff
|
//ipc stuff
|
||||||
import {app, ipcMain, shell, desktopCapturer} from "electron";
|
import {app, ipcMain, shell, desktopCapturer,nativeImage} from "electron";
|
||||||
import {mainWindow} from "./window";
|
import {mainWindow} from "./window";
|
||||||
import {
|
import {
|
||||||
setConfigBulk,
|
setConfigBulk,
|
||||||
|
@ -12,6 +12,8 @@ import {
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import {customTitlebar} from "./main";
|
import {customTitlebar} from "./main";
|
||||||
import {createSettingsWindow} from "./settings/main";
|
import {createSettingsWindow} from "./settings/main";
|
||||||
|
import os from "os";
|
||||||
|
import path from "path";
|
||||||
export function registerIpc() {
|
export function registerIpc() {
|
||||||
ipcMain.on("get-app-path", (event, arg) => {
|
ipcMain.on("get-app-path", (event, arg) => {
|
||||||
event.reply("app-path", app.getAppPath());
|
event.reply("app-path", app.getAppPath());
|
||||||
|
@ -25,6 +27,21 @@ export function registerIpc() {
|
||||||
ipcMain.on("open-external-link", (event, href: string) => {
|
ipcMain.on("open-external-link", (event, href: string) => {
|
||||||
shell.openExternal(href);
|
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) => {
|
ipcMain.on("win-maximize", (event, arg) => {
|
||||||
mainWindow.maximize();
|
mainWindow.maximize();
|
||||||
});
|
});
|
||||||
|
|
|
@ -59,6 +59,13 @@ export async function setMenu() {
|
||||||
createSettingsWindow();
|
createSettingsWindow();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Reload",
|
||||||
|
accelerator: "CmdOrCtrl+R",
|
||||||
|
click: function () {
|
||||||
|
mainWindow.reload()
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "Quit",
|
label: "Quit",
|
||||||
accelerator: "CmdOrCtrl+Q",
|
accelerator: "CmdOrCtrl+Q",
|
||||||
|
|
|
@ -16,6 +16,8 @@ contextBridge.exposeInMainWorld("armcord", {
|
||||||
electron: process.versions.electron,
|
electron: process.versions.electron,
|
||||||
channel: ipcRenderer.sendSync("channel"),
|
channel: ipcRenderer.sendSync("channel"),
|
||||||
setLang: (lang: string) => ipcRenderer.send("setLang", lang),
|
setLang: (lang: string) => ipcRenderer.send("setLang", lang),
|
||||||
|
setPingCount: (pingCount: number) => ipcRenderer.send("setPing", pingCount),
|
||||||
|
setTrayIcon: (favicon: string) => ipcRenderer.send("sendTrayIcon", favicon),
|
||||||
getLang: (toGet: string) =>
|
getLang: (toGet: string) =>
|
||||||
ipcRenderer.invoke("getLang", toGet).then((result) => {
|
ipcRenderer.invoke("getLang", toGet).then((result) => {
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -124,7 +124,8 @@
|
||||||
<br />
|
<br />
|
||||||
<div class="switch acTray">
|
<div class="switch acTray">
|
||||||
<select name="trayIcon" id="trayIcon" class="left dropdown">
|
<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="dsc-tray">Discord Icon</option>
|
||||||
<option value="ac_white_plug">White Icon</option>
|
<option value="ac_white_plug">White Icon</option>
|
||||||
<option value="ac_black_plug">Black Icon</option>
|
<option value="ac_black_plug">Black Icon</option>
|
||||||
|
|
|
@ -159,7 +159,8 @@
|
||||||
<br />
|
<br />
|
||||||
<div class="switch acTray">
|
<div class="switch acTray">
|
||||||
<select name="trayIcon" id="trayIcon" class="left dropdown">
|
<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="dsc-tray">Discord Icon</option>
|
||||||
<option value="ac_white_plug">White Icon</option>
|
<option value="ac_white_plug">White Icon</option>
|
||||||
<option value="ac_black_plug">Black Icon</option>
|
<option value="ac_black_plug">Black Icon</option>
|
||||||
|
|
|
@ -4,12 +4,15 @@ import {mainWindow} from "./window";
|
||||||
import {getConfig, getConfigLocation, setWindowState} from "./utils";
|
import {getConfig, getConfigLocation, setWindowState} from "./utils";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import {createSettingsWindow} from "./settings/main";
|
import {createSettingsWindow} from "./settings/main";
|
||||||
let tray: any = null;
|
export let tray: any = null;
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
let finishedSetup = await getConfig("doneSetup");
|
let finishedSetup = await getConfig("doneSetup");
|
||||||
var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored";
|
var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored";
|
||||||
|
if (trayIcon = "default") {
|
||||||
|
trayIcon = "dsc-tray"
|
||||||
|
}
|
||||||
let trayPath = nativeImage.createFromPath(path.join(__dirname, "../", `/assets/${trayIcon}.png`));
|
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") {
|
if ((await getConfig("windowStyle")) == "basic") {
|
||||||
var clientName = (await getConfig("clientName")) ?? "ArmCord";
|
var clientName = (await getConfig("clientName")) ?? "ArmCord";
|
||||||
tray = new Tray(trayPath);
|
tray = new Tray(trayPath);
|
||||||
|
|
|
@ -45,7 +45,7 @@ export function setup() {
|
||||||
skipSplash: false,
|
skipSplash: false,
|
||||||
inviteWebsocket: true,
|
inviteWebsocket: true,
|
||||||
mobileMode: false,
|
mobileMode: false,
|
||||||
trayIcon: "ac_plug_colored",
|
trayIcon: "default",
|
||||||
doneSetup: false
|
doneSetup: false
|
||||||
};
|
};
|
||||||
setConfigBulk({
|
setConfigBulk({
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// I had to add most of the window creation code here to split both into seperete functions
|
// 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
|
// 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.
|
// 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 path from "path";
|
||||||
import {
|
import {
|
||||||
checkIfConfigIsBroken,
|
checkIfConfigIsBroken,
|
||||||
|
@ -19,6 +19,7 @@ import * as fs from "fs";
|
||||||
import startServer from "./socket";
|
import startServer from "./socket";
|
||||||
import contextMenu from "electron-context-menu";
|
import contextMenu from "electron-context-menu";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
|
import {tray} from "./tray";
|
||||||
export var icon: string;
|
export var icon: string;
|
||||||
export let mainWindow: BrowserWindow;
|
export let mainWindow: BrowserWindow;
|
||||||
export let inviteWindow: 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});
|
if (/api\/v\d\/science$/g.test(details.url)) return callback({cancel: true});
|
||||||
return callback({});
|
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 userDataPath = app.getPath("userData");
|
||||||
const themesFolder = userDataPath + "/themes/";
|
const themesFolder = userDataPath + "/themes/";
|
||||||
if (!fs.existsSync(themesFolder)) {
|
if (!fs.existsSync(themesFolder)) {
|
||||||
|
|
Loading…
Reference in a new issue