Skip to content

Commit 928df59

Browse files
favicon notification added
1 parent 03e026b commit 928df59

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

electron/main/index.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ let win: BrowserWindow | null = null;
4848
const preload = path.join(__dirname, '../preload/index.js');
4949
const tinyUrl = process.env.VITE_DEV_SERVER_URL;
5050
const indexHtml = path.join(process.env.DIST, 'index.html');
51-
const icon = path.join(process.env.VITE_PUBLIC, './img/png/cinny.png');
51+
const iconPath = path.join(process.env.VITE_PUBLIC, './img/png');
52+
const icon = path.join(iconPath, './cinny.png');
5253

5354
const appShow = {
5455
change: (value: boolean) => {
@@ -104,6 +105,24 @@ async function createWindow() {
104105
},
105106
});
106107

108+
if (process.platform === 'win32') {
109+
win.setAppDetails({
110+
appId: 'pony-house-matrix',
111+
appIconPath: icon,
112+
relaunchDisplayName: title,
113+
});
114+
}
115+
116+
ipcMain.on('change-app-icon', (event, img) => {
117+
try {
118+
if (typeof img === 'string' && img.length > 0) {
119+
if (win) win.setIcon(path.join(iconPath, `./${img}`));
120+
}
121+
} catch (err) {
122+
console.error(err);
123+
}
124+
});
125+
107126
// Start modules
108127
startResizeEvents(ipcMain, win);
109128
startEvents(ipcMain, win);
@@ -238,6 +257,16 @@ if (!gotTheLock) {
238257
}
239258
}
240259
});
260+
261+
ipcMain.on('change-tray-icon', (event, img) => {
262+
try {
263+
if (typeof img === 'string' && img.length > 0) {
264+
tray.setImage(path.join(iconPath, `./${img}`));
265+
}
266+
} catch (err) {
267+
console.error(err);
268+
}
269+
});
241270
}
242271
});
243272
}

electron/preload/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ contextBridge.exposeInMainWorld('setElectronResize', (callback: Function) => {
125125
electronResize = callback;
126126
});
127127

128+
contextBridge.exposeInMainWorld('changeTrayIcon', (img: string) => {
129+
if (
130+
img === 'cinny.png' ||
131+
img === 'cinny-highlight.png' ||
132+
img === 'cinny-unread-red.png' ||
133+
img === 'cinny-unread.png'
134+
) {
135+
ipcRenderer.send('change-tray-icon', img);
136+
}
137+
});
138+
139+
contextBridge.exposeInMainWorld('changeAppIcon', (img: string) => {
140+
if (
141+
img === 'cinny.png' ||
142+
img === 'cinny-highlight.png' ||
143+
img === 'cinny-unread-red.png' ||
144+
img === 'cinny-unread.png'
145+
) {
146+
ipcRenderer.send('change-app-icon', img);
147+
}
148+
});
149+
128150
setTimeout(removeLoading, 4999);
129151

130152
// App Status

info/dev/preparing-changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Join buttons delay added to protect ratelimit.
2-
- Room selector anim fix
2+
- Room selector anim fix.
3+
- favicon notification added.

src/util/libs/favicon.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,41 @@ export function favIconValue() {
2525
};
2626

2727
export function checkerFavIcon() {
28+
setTimeout(() => {
2829

30+
// Number of messages from rooms which has "All Messages" notifications enabled or when mentionned in a room with "Mentions & Keyword" notifications level.
31+
let directCount = 0;
32+
// Number of messages for rooms which has "Mentions & Keyword" notifications level set which does not directly mention you.
33+
let indirectCount = 0;
34+
35+
// Retrieves notification badges
36+
const badges = $('.sidebar .notification-badge');
37+
for (const badge of badges) {
38+
39+
indirectCount++;
40+
const nb = Number($(badges[badge]).text());
41+
42+
if (!Number.isNaN(nb) && Number.isFinite(nb)) {
43+
directCount += nb;
44+
}
45+
46+
}
47+
48+
// Change Icon
49+
const finalNumber = directCount || indirectCount;
50+
if (finalNumber > 0) {
51+
changeFavIcon('cinny-unread-red.png');
52+
if (__ENV_APP__.electron_mode) {
53+
global.changeTrayIcon('cinny-unread-red.png');
54+
global.changeAppIcon('cinny-unread-red.png');
55+
}
56+
} else {
57+
changeFavIcon('cinny.png');
58+
if (__ENV_APP__.electron_mode) {
59+
global.changeTrayIcon('cinny.png');
60+
global.changeAppIcon('cinny.png');
61+
}
62+
}
63+
64+
}, 100);
2965
};

0 commit comments

Comments
 (0)