Skip to content

Commit

Permalink
Tray: use more "stable" image format.
Browse files Browse the repository at this point in the history
The `toBitmap` method is actually quite "unstable": it's behavior varies
from platform and produce different results. It's not reliable for hash
verifications, therefore a better format of an image should be used.

This commit changes the format to PNG and regenrates checksums for it.
This should produce much more reliable results than it was before.
  • Loading branch information
SpacingBat3 committed Aug 28, 2022
1 parent 170767e commit 7141c90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sources/code/common/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function isJsonSyntaxCorrect(string: string) {
/** SHA1 hashes of Discord favicons (in RAW bitmap format). */
export const discordFavicons = {
/** Default favicon (without *blue dot* indicator). */
default: "25522cef7e234ab001bbbc85c7a3f477b996e20b",
unread: "e6cba81a4e4189bb44df2c7ae63c79d8e80a3660"
default: "a971976200e0abf8d8a9fad46b7309363ef3cd01",
unread: "3133ab8ef98ea83f1573f6c3902c027015c005bf"
};

/**
Expand Down
7 changes: 4 additions & 3 deletions sources/code/main/windows/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,14 @@ export default function createMainWindow(flags:MainWindowFlags): BrowserWindow {
win.webContents.on("page-favicon-updated", (_event, favicons) => {
let icon: NativeImage, flash = false;
// Convert from DataURL to RAW.
const faviconRaw = nativeImage.createFromDataURL(favicons[0]??"").toBitmap();
const faviconBuffer = nativeImage.createFromDataURL(favicons[0]??"").toPNG();
// Hash discord favicon.
const faviconHash = createHash("sha1").update(faviconRaw).digest("hex");
const faviconHash = createHash("sha1").update(faviconBuffer).digest("hex");
// Stop execution when icon is same as the one set.
if (faviconHash === setFavicon) return;
// Stop code execution on Fosscord instances.
const currentInstance = knownInstancesList.find((value) => value[1].origin === new URL(win.webContents.getURL()).origin);
const currentInstance = knownInstancesList
.find((value) => value[1].origin === new URL(win.webContents.getURL()).origin);
if (currentInstance?.[2] !== true) {
setFavicon = faviconHash;
icon = appInfo.icons.tray.default;
Expand Down

0 comments on commit 7141c90

Please sign in to comment.