mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
parent
bc9dad02e5
commit
4d95bb89ee
2 changed files with 12 additions and 4 deletions
|
@ -3,7 +3,7 @@ import { mkdirp } from "mkdirp";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import log from "./logger";
|
import log from "./logger";
|
||||||
import { getTeaPath } from "./tea-dir";
|
import { getTeaPath } from "./tea-dir";
|
||||||
import { GUIPackage, Packages } from "../../src/libs/types";
|
import { Packages } from "../../src/libs/types";
|
||||||
|
|
||||||
const pkgsFilePath = path.join(getTeaPath(), "tea.xyz/gui/pkgs.json");
|
const pkgsFilePath = path.join(getTeaPath(), "tea.xyz/gui/pkgs.json");
|
||||||
const pkgsFolder = path.join(getTeaPath(), "tea.xyz/gui");
|
const pkgsFolder = path.join(getTeaPath(), "tea.xyz/gui");
|
||||||
|
@ -52,3 +52,8 @@ export const nameToSlug = (name: string) => {
|
||||||
const slug = nameOnly.replace(/[^\w\s]/gi, "_").toLocaleLowerCase();
|
const slug = nameOnly.replace(/[^\w\s]/gi, "_").toLocaleLowerCase();
|
||||||
return slug;
|
return slug;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function isInstalled(fullName: string) {
|
||||||
|
const folderPath = path.join(getTeaPath(), fullName);
|
||||||
|
return fs.existsSync(folderPath);
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { readSessionData } from "./auth";
|
||||||
import { post } from "./v1-client";
|
import { post } from "./v1-client";
|
||||||
import log from "./logger";
|
import log from "./logger";
|
||||||
import { Notification, BrowserWindow } from "electron";
|
import { Notification, BrowserWindow } from "electron";
|
||||||
import { nameToSlug } from "./package";
|
import { isInstalled, nameToSlug } from "./package";
|
||||||
import {
|
import {
|
||||||
getInstalledPackages,
|
getInstalledPackages,
|
||||||
getPackagesInstalledList,
|
getPackagesInstalledList,
|
||||||
|
@ -42,9 +42,10 @@ export default function initialize(mainWindow: BrowserWindow) {
|
||||||
Pushy.setNotificationListener(async (data: any) => {
|
Pushy.setNotificationListener(async (data: any) => {
|
||||||
try {
|
try {
|
||||||
log.info("new notification received", data);
|
log.info("new notification received", data);
|
||||||
|
const pkg = data?.url.replace("tea://packages/", "");
|
||||||
|
const installed = isInstalled(pkg);
|
||||||
const isDup = await wasReceivedBefore(data);
|
const isDup = await wasReceivedBefore(data);
|
||||||
if (!isDup) {
|
if (!isDup && installed) {
|
||||||
new Notification({
|
new Notification({
|
||||||
title: "tea",
|
title: "tea",
|
||||||
body: data?.message as string
|
body: data?.message as string
|
||||||
|
@ -56,6 +57,8 @@ export default function initialize(mainWindow: BrowserWindow) {
|
||||||
} else {
|
} else {
|
||||||
app.dock.setBadge((parseInt(v) + 1).toString());
|
app.dock.setBadge((parseInt(v) + 1).toString());
|
||||||
}
|
}
|
||||||
|
} else if (!installed) {
|
||||||
|
unsubscribeToPackageTopic(pkg);
|
||||||
} else {
|
} else {
|
||||||
log.info("notification was already received before", data);
|
log.info("notification was already received before", data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue