Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Show a red dot, not a second app icon, as the Windows unread overlay

AdityaUmale8cb1b814bb13
diff --git a/electron/color-dot.mjs b/electron/color-dot.mjs
index dac38ff9f7..5c4e571d3a 100644
--- a/electron/color-dot.mjs
+++ b/electron/color-dot.mjs
@@ -44,3 +44,12 @@ export function dotIcons(nativeImage, hexes = BOT_COLOR_HEX) {
return made.get(color) ?? null;
};
}
+
+/** The Windows taskbar's unread overlay: a red dot (16 px, sharp at 2x); null where it cannot be drawn. */
+export function unreadBadgeIcon(nativeImage) {
+ try {
+ const image = nativeImage.createEmpty();
+ for (const scaleFactor of [1, 2]) image.addRepresentation({ scaleFactor, dataURL: colorDotPng(BOT_COLOR_HEX.red, 16 * scaleFactor, 14 * scaleFactor) });
+ return image.isEmpty() ? null : image;
+ } catch { return null; }
+}
diff --git a/electron/main.mjs b/electron/main.mjs
index 711efca3ed..461484b89a 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -97,7 +97,7 @@ import { reviveAfterFailedSwitch, switchLocalEnvironment } from "./environment-s
import { createManagedDesktopClient, createManagedDesktopRelay, createManagedDesktopStore } from "./managed-desktop.mjs";
import { CHECKOUT_SOURCES, cloudMenuSublabel, cloudTarget, createCloudAccountClient as cloudAccountClient, createCloudAccountStore } from "./cloud-account.mjs";
import { installCloudPlanIpc } from "./cloud-plan-ipc.mjs";
-import { cloudLinkOpensSheet, colorDotIcons, createCloudLook, createCloudReadyNotice, installCloudBuy, lookFile } from "./cloud-buy.mjs";
+import { cloudLinkOpensSheet, colorDotIcons, createCloudLook, createCloudReadyNotice, installCloudBuy, lookFile } from "./cloud-buy.mjs"; import { unreadBadgeIcon } from "./color-dot.mjs";
import { createTrialNotices } from "./cloud-trial-notice.mjs";
import { createDesktopText, DESKTOP_PORTS, jsonFile, registerDesktopPrefs, relabelDesktop } from "./desktop-prefs.mjs";
import { createDesktopIncludedX } from "./included-x.mjs"; import { createDesktopIncludedPages } from "./included-pages.mjs"; import { createPhoneLinkFact } from "./phone-link-fact.mjs";
@@ -159,7 +159,7 @@ let organizationEntryReady = false;
let mainWindow = null;
const serverUnavailableWindows = new WeakSet();
let unreadCount = 0;
-let unreadOverlayIcon = null;
+let unreadOverlayIcon;
const windowStateFile = createWindowStateFile({ file: () => path.join(app.getPath("userData"), "window-state.json"), log: message => slog(message) });
@@ -167,9 +167,9 @@ function applyUnreadBadge(win = mainWindow) {
const count = normalizeUnreadCount(unreadCount);
if (process.platform === "win32") {
if (!win || win.isDestroyed()) return;
- unreadOverlayIcon ??= nativeImage.createFromPath(APP_ICON).resize({ width: 16, height: 16 });
+ if (unreadOverlayIcon === undefined) unreadOverlayIcon = unreadBadgeIcon(nativeImage); // a dot: the overlay sits on the app's own icon
win.setOverlayIcon(
- count > 0 && !unreadOverlayIcon.isEmpty() ? unreadOverlayIcon : null,
+ count > 0 ? unreadOverlayIcon : null,
count > 0 ? nativeT(count === 1 ? "native.badge.one" : "native.badge.many", { count }) : nativeT("native.badge.none"),
);
return;
diff --git a/electron/unread-badge.node-test.mjs b/electron/unread-badge.node-test.mjs
new file mode 100644
index 0000000000..0d8f9a4c9b
--- /dev/null
+++ b/electron/unread-badge.node-test.mjs
@@ -0,0 +1,40 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { readFileSync } from "node:fs";
+import { inflateSync } from "node:zlib";
+import { unreadBadgeIcon } from "./color-dot.mjs";
+
+const fakeImages = () => ({ createEmpty: () => ({ reps: [], addRepresentation(options) { this.reps.push(options); }, isEmpty() { return this.reps.length === 0; } }) });
+
+/** The RGBA of pixel (x, y) in a PNG data URL drawn by colorDotPng (8-bit RGBA, filter byte 0 on every row). */
+function pixel(dataURL, x, y) {
+ const png = Buffer.from(dataURL.split(",")[1], "base64");
+ const size = png.readUInt32BE(16);
+ const idat = png.indexOf("IDAT"), length = png.readUInt32BE(idat - 4);
+ const rows = inflateSync(png.subarray(idat + 4, idat + 4 + length));
+ const at = y * (size * 4 + 1) + 1 + x * 4;
+ return { size, rgba: [...rows.subarray(at, at + 4)] };
+}
+
+test("the Windows unread overlay is a red dot at 16 px and 32 px, not the app icon", () => {
+ const image = unreadBadgeIcon(fakeImages());
+ assert.deepEqual(image.reps.map(rep => rep.scaleFactor), [1, 2]);
+ for (const [index, size] of [[0, 16], [1, 32]]) {
+ const middle = pixel(image.reps[index].dataURL, size / 2, size / 2);
+ assert.equal(middle.size, size);
+ assert.deepEqual(middle.rgba, [0xD9, 0x4B, 0x52, 255], "the middle is solid red");
+ assert.equal(pixel(image.reps[index].dataURL, 0, 0).rgba[3], 0, "the corner is clear, so the taskbar icon shows around the dot");
+ }
+});
+
+test("an overlay that cannot be drawn is no overlay", () => {
+ assert.equal(unreadBadgeIcon({ createEmpty: () => { throw new Error("no"); } }), null);
+ assert.equal(unreadBadgeIcon({ createEmpty: () => ({ addRepresentation() {}, isEmpty: () => true }) }), null);
+});
+
+test("main's Windows badge uses the red dot, not a shrunk copy of the app icon (#5885)", () => {
+ const main = readFileSync(new URL("./main.mjs", import.meta.url), "utf8");
+ const badge = main.slice(main.indexOf("function applyUnreadBadge"), main.indexOf("app.setBadgeCount(count)"));
+ assert.match(badge, /unreadBadgeIcon\(nativeImage\)/);
+ assert.doesNotMatch(badge, /APP_ICON/);
+});