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_password": "Update password",
"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": {
"download_complete": "Download complete",

View File

@ -279,7 +279,8 @@
"update_email": "Atualizar email",
"update_password": "Atualizar senha",
"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": {
"download_complete": "Download concluído",

View File

@ -178,6 +178,13 @@ export class WindowManager {
authWindow.close();
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);
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) => {
const listener = (_event: Electron.IpcRendererEvent) => cb();
ipcRenderer.on("on-signout", listener);

View File

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

View File

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