feat: add account updated listener

This commit is contained in:
Zamitto 2025-01-16 00:21:44 -03:00
parent 44fd971c95
commit d866face54
6 changed files with 28 additions and 6 deletions

View File

@ -291,7 +291,8 @@
"update_email": "Update email", "update_email": "Update email",
"update_password": "Update password", "update_password": "Update password",
"current_email": "Current email:", "current_email": "Current email:",
"no_email_account": "You have not set an email yet" "no_email_account": "You have not set an email yet",
"account_data_updated_successfully": "Account data updated successfully"
}, },
"notifications": { "notifications": {
"download_complete": "Download complete", "download_complete": "Download complete",

View File

@ -279,7 +279,8 @@
"update_email": "Atualizar email", "update_email": "Atualizar email",
"update_password": "Atualizar senha", "update_password": "Atualizar senha",
"current_email": "Email atual:", "current_email": "Email atual:",
"no_email_account": "Você ainda não adicionou um email a sua conta" "no_email_account": "Você ainda não adicionou um email a sua conta",
"account_data_updated_successfully": "Dados da conta atualizados com sucesso"
}, },
"notifications": { "notifications": {
"download_complete": "Download concluído", "download_complete": "Download concluído",

View File

@ -178,6 +178,13 @@ export class WindowManager {
authWindow.close(); authWindow.close();
HydraApi.handleExternalAuth(url); HydraApi.handleExternalAuth(url);
return;
}
if (url.startsWith("hydralauncher://update-account")) {
authWindow.close();
WindowManager.mainWindow?.webContents.send("on-account-updated");
} }
}); });
} }

View File

@ -299,6 +299,11 @@ contextBridge.exposeInMainWorld("electron", {
ipcRenderer.on("on-signin", listener); ipcRenderer.on("on-signin", listener);
return () => ipcRenderer.removeListener("on-signin", listener); return () => ipcRenderer.removeListener("on-signin", listener);
}, },
onAccountUpdated: (cb: () => void) => {
const listener = (_event: Electron.IpcRendererEvent) => cb();
ipcRenderer.on("on-account-updated", listener);
return () => ipcRenderer.removeListener("on-account-updated", listener);
},
onSignOut: (cb: () => void) => { onSignOut: (cb: () => void) => {
const listener = (_event: Electron.IpcRendererEvent) => cb(); const listener = (_event: Electron.IpcRendererEvent) => cb();
ipcRenderer.on("on-signout", listener); ipcRenderer.on("on-signout", listener);

View File

@ -211,6 +211,7 @@ declare global {
openAuthWindow: (page: AuthPage) => Promise<void>; openAuthWindow: (page: AuthPage) => Promise<void>;
getSessionHash: () => Promise<string | null>; getSessionHash: () => Promise<string | null>;
onSignIn: (cb: () => void) => () => Electron.IpcRenderer; onSignIn: (cb: () => void) => () => Electron.IpcRenderer;
onAccountUpdated: (cb: () => void) => () => Electron.IpcRenderer;
onSignOut: (cb: () => void) => () => Electron.IpcRenderer; onSignOut: (cb: () => void) => () => Electron.IpcRenderer;
/* User */ /* User */

View File

@ -52,11 +52,18 @@ export function SettingsAccount() {
}, [userDetails, setValue]); }, [userDetails, setValue]);
useEffect(() => { useEffect(() => {
const unsubscribe = window.electron.onAccountUpdated(() => {
fetchUserDetails().then((response) => { fetchUserDetails().then((response) => {
if (response) { if (response) {
updateUserDetails(response); updateUserDetails(response);
} }
}); });
showSuccessToast(t("account_data_updated_successfully"));
});
return () => {
unsubscribe();
};
}, [fetchUserDetails, updateUserDetails]); }, [fetchUserDetails, updateUserDetails]);
const visibilityOptions = [ const visibilityOptions = [