mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
patching user displayName and profileImageUrl
This commit is contained in:
parent
af69509c61
commit
59b2096d06
6 changed files with 33 additions and 10 deletions
|
@ -24,6 +24,7 @@ import "./library/remove-game";
|
||||||
import "./library/remove-game-from-library";
|
import "./library/remove-game-from-library";
|
||||||
import "./misc/open-external";
|
import "./misc/open-external";
|
||||||
import "./misc/show-open-dialog";
|
import "./misc/show-open-dialog";
|
||||||
|
import "./misc/image-path-to-base-64";
|
||||||
import "./torrenting/cancel-game-download";
|
import "./torrenting/cancel-game-download";
|
||||||
import "./torrenting/pause-game-download";
|
import "./torrenting/pause-game-download";
|
||||||
import "./torrenting/resume-game-download";
|
import "./torrenting/resume-game-download";
|
||||||
|
|
14
src/main/events/misc/image-path-to-base-64.ts
Normal file
14
src/main/events/misc/image-path-to-base-64.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import mime from "mime";
|
||||||
|
import { registerEvent } from "../register-event";
|
||||||
|
import fs from "node:fs";
|
||||||
|
|
||||||
|
const imagePathToBase64 = async (
|
||||||
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
filePath: string
|
||||||
|
) => {
|
||||||
|
const buffer = fs.readFileSync(filePath);
|
||||||
|
const mimeType = mime.getType(filePath);
|
||||||
|
return `data:${mimeType};base64,${buffer.toString("base64")}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
registerEvent("imagePathToBase64", imagePathToBase64);
|
|
@ -4,12 +4,11 @@ import axios from "axios";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import mime from "mime";
|
import mime from "mime";
|
||||||
|
|
||||||
const patchUserProfile = (displayName: string, imageUrl?: string) => {
|
const patchUserProfile = (displayName: string, profileImageUrl?: string) => {
|
||||||
return;
|
if (profileImageUrl) {
|
||||||
if (imageUrl) {
|
|
||||||
return HydraApi.patch("/profile", {
|
return HydraApi.patch("/profile", {
|
||||||
displayName,
|
displayName,
|
||||||
imageUrl,
|
profileImageUrl,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return HydraApi.patch("/profile", {
|
return HydraApi.patch("/profile", {
|
||||||
|
|
|
@ -106,6 +106,8 @@ contextBridge.exposeInMainWorld("electron", {
|
||||||
getVersion: () => ipcRenderer.invoke("getVersion"),
|
getVersion: () => ipcRenderer.invoke("getVersion"),
|
||||||
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
||||||
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
||||||
|
imagePathToBase64: (filePath: string) =>
|
||||||
|
ipcRenderer.invoke("imagePathToBase64", filePath),
|
||||||
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
||||||
ipcRenderer.invoke("showOpenDialog", options),
|
ipcRenderer.invoke("showOpenDialog", options),
|
||||||
platform: process.platform,
|
platform: process.platform,
|
||||||
|
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
|
@ -96,6 +96,7 @@ declare global {
|
||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
openExternal: (src: string) => Promise<void>;
|
openExternal: (src: string) => Promise<void>;
|
||||||
|
imagePathToBase64: (filePath: string) => Promise<string>;
|
||||||
getVersion: () => Promise<string>;
|
getVersion: () => Promise<string>;
|
||||||
ping: () => string;
|
ping: () => string;
|
||||||
getDefaultDownloadsPath: () => Promise<string>;
|
getDefaultDownloadsPath: () => Promise<string>;
|
||||||
|
|
|
@ -18,22 +18,28 @@ export const UserEditProfileModal = ({
|
||||||
}: UserEditProfileModalProps) => {
|
}: UserEditProfileModalProps) => {
|
||||||
const [displayName, setDisplayName] = useState(userProfile.displayName);
|
const [displayName, setDisplayName] = useState(userProfile.displayName);
|
||||||
const [newImagePath, setNewImagePath] = useState<string | null>(null);
|
const [newImagePath, setNewImagePath] = useState<string | null>(null);
|
||||||
|
const [newImageBase64, setNewImageBase64] = useState<string | null>(null);
|
||||||
|
|
||||||
const handleChangeProfileAvatar = async () => {
|
const handleChangeProfileAvatar = async () => {
|
||||||
const { filePaths } = await window.electron.showOpenDialog({
|
const { filePaths } = await window.electron.showOpenDialog({
|
||||||
properties: ["openFile"],
|
properties: ["openFile"],
|
||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
name: "Profile avatar",
|
name: "Profile image",
|
||||||
extensions: ["jpg", "png", "gif"],
|
extensions: ["jpg", "png", "gif", "webp", "jpeg"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const path = filePaths[0];
|
if (filePaths && filePaths.length > 0) {
|
||||||
console.log(path);
|
const path = filePaths[0];
|
||||||
|
|
||||||
setNewImagePath(path);
|
window.electron.imagePathToBase64(path).then((base64) => {
|
||||||
|
setNewImageBase64(base64);
|
||||||
|
});
|
||||||
|
|
||||||
|
setNewImagePath(path);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveProfile = async () => {
|
const handleSaveProfile = async () => {
|
||||||
|
@ -67,7 +73,7 @@ export const UserEditProfileModal = ({
|
||||||
<img
|
<img
|
||||||
className={styles.profileAvatar}
|
className={styles.profileAvatar}
|
||||||
alt={userProfile.displayName}
|
alt={userProfile.displayName}
|
||||||
src={newImagePath ?? userProfile.profileImageUrl}
|
src={newImageBase64 ?? userProfile.profileImageUrl}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<PersonIcon size={72} />
|
<PersonIcon size={72} />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue