feat: get user static image on notifications

This commit is contained in:
Zamitto
2025-11-12 08:07:51 -03:00
parent 94ebf94abc
commit f84917a00b
2 changed files with 16 additions and 4 deletions

View File

@@ -1,10 +1,14 @@
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
import { PythonRPC } from "@main/services/python-rpc"; import { PythonRPC } from "@main/services/python-rpc";
const processProfileImage = async ( const processProfileImageEvent = async (
_event: Electron.IpcMainInvokeEvent, _event: Electron.IpcMainInvokeEvent,
path: string path: string
) => { ) => {
return processProfileImage(path);
};
export const processProfileImage = async (path: string) => {
return PythonRPC.rpc return PythonRPC.rpc
.post<{ .post<{
imagePath: string; imagePath: string;
@@ -13,4 +17,4 @@ const processProfileImage = async (
.then((response) => response.data); .then((response) => response.data);
}; };
registerEvent("processProfileImage", processProfileImage); registerEvent("processProfileImage", processProfileImageEvent);

View File

@@ -15,6 +15,13 @@ import { db, levelKeys, themesSublevel } from "@main/level";
import { restartAndInstallUpdate } from "@main/events/autoupdater/restart-and-install-update"; import { restartAndInstallUpdate } from "@main/events/autoupdater/restart-and-install-update";
import { SystemPath } from "../system-path"; import { SystemPath } from "../system-path";
import { getThemeSoundPath } from "@main/helpers"; import { getThemeSoundPath } from "@main/helpers";
import { processProfileImage } from "@main/events/profile/process-profile-image";
const getStaticImage = async (path: string) => {
return processProfileImage(path)
.then((response) => response.imagePath)
.catch(() => path);
};
async function downloadImage(url: string | null) { async function downloadImage(url: string | null) {
if (!url) return undefined; if (!url) return undefined;
@@ -31,8 +38,9 @@ async function downloadImage(url: string | null) {
response.data.pipe(writer); response.data.pipe(writer);
return new Promise<string | undefined>((resolve) => { return new Promise<string | undefined>((resolve) => {
writer.on("finish", () => { writer.on("finish", async () => {
resolve(outputPath); const staticImagePath = await getStaticImage(outputPath);
resolve(staticImagePath);
}); });
writer.on("error", () => { writer.on("error", () => {
logger.error("Failed to download image", { url }); logger.error("Failed to download image", { url });