mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-10 21:36:17 +00:00
feat: get user static image on notifications
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { registerEvent } from "../register-event";
|
||||
import { PythonRPC } from "@main/services/python-rpc";
|
||||
|
||||
const processProfileImage = async (
|
||||
const processProfileImageEvent = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
path: string
|
||||
) => {
|
||||
return processProfileImage(path);
|
||||
};
|
||||
|
||||
export const processProfileImage = async (path: string) => {
|
||||
return PythonRPC.rpc
|
||||
.post<{
|
||||
imagePath: string;
|
||||
@@ -13,4 +17,4 @@ const processProfileImage = async (
|
||||
.then((response) => response.data);
|
||||
};
|
||||
|
||||
registerEvent("processProfileImage", processProfileImage);
|
||||
registerEvent("processProfileImage", processProfileImageEvent);
|
||||
|
||||
@@ -15,6 +15,13 @@ import { db, levelKeys, themesSublevel } from "@main/level";
|
||||
import { restartAndInstallUpdate } from "@main/events/autoupdater/restart-and-install-update";
|
||||
import { SystemPath } from "../system-path";
|
||||
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) {
|
||||
if (!url) return undefined;
|
||||
@@ -31,8 +38,9 @@ async function downloadImage(url: string | null) {
|
||||
response.data.pipe(writer);
|
||||
|
||||
return new Promise<string | undefined>((resolve) => {
|
||||
writer.on("finish", () => {
|
||||
resolve(outputPath);
|
||||
writer.on("finish", async () => {
|
||||
const staticImagePath = await getStaticImage(outputPath);
|
||||
resolve(staticImagePath);
|
||||
});
|
||||
writer.on("error", () => {
|
||||
logger.error("Failed to download image", { url });
|
||||
|
||||
Reference in New Issue
Block a user