#410 badge count relative to pkgs that needs update (#412)

Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-04-07 11:14:24 +08:00 committed by GitHub
parent d9570e4b13
commit 4192d35268
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 4 deletions

View file

@ -132,4 +132,13 @@ export default function initializeHandlers() {
return error.message;
}
});
ipcMain.handle("set-badge-count", async (_, { count }) => {
console.log("set badge count:", count);
if (count) {
app.dock.setBadge(count.toString());
} else {
app.dock.setBadge("");
}
});
}

View file

@ -11,7 +11,6 @@ import {
} from "./tea-dir";
import { app } from "electron";
let pushCount = 0;
export default function initialize(mainWindow: BrowserWindow) {
Pushy.listen();
// Register device for push notifications
@ -32,8 +31,10 @@ export default function initialize(mainWindow: BrowserWindow) {
log.info("push data:", data);
// TODO: replace this with something
Pushy.alert(mainWindow, data?.message as string);
pushCount++;
if (pushCount) app.dock.setBadge(pushCount.toString());
const v = app.dock.getBadge();
if (!v) {
app.dock.setBadge("1");
}
});
}

View file

@ -219,3 +219,11 @@ export const isPackageInstalled = async (fullName: string, version?: string): Pr
return isInstalled;
};
export const setBadgeCount = async (count: number) => {
try {
await ipcRenderer.invoke("set-badge-count", { count });
} catch (error) {
log.error(error);
}
};

View file

@ -344,3 +344,7 @@ export const submitLogs = async () => {
export const isPackageInstalled = async (_v?: string): Promise<boolean> => {
return true;
};
export const setBadgeCount = async (count: number) => {
console.log("set badge count", count);
};

View file

@ -7,7 +7,8 @@ import {
getDistPackages,
getInstalledPackages,
installPackage,
getPackageBottles
getPackageBottles,
setBadgeCount
} from "@native";
import { getReadme, getContributors, getRepoAsPackage } from "$libs/github";
@ -34,6 +35,7 @@ export default function initPackagesStore() {
...props
};
}
setBadgeCountFromPkgs(pkgs);
return pkgs;
});
};
@ -117,6 +119,8 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
}
syncProgress.set(+((i + 1) / installedPkgs.length).toFixed(2));
}
setBadgeCountFromPkgs(guiPkgs);
} catch (error) {
log.error(error);
}
@ -209,3 +213,12 @@ const withFakeLoader = (pkg: GUIPackage, callback: (progress: number) => void):
return fakeTimer;
};
const setBadgeCountFromPkgs = (pkgs: GUIPackage[]) => {
try {
const needsUpdateCount = pkgs.filter((p) => p.state === PackageStates.NEEDS_UPDATE).length;
setBadgeCount(needsUpdateCount);
} catch (error) {
log.error(error);
}
};