diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index a79b1107..3f3bd3ef 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -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", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 62565165..26e2d590 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -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", diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index adf34a42..47fc92e0 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -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"); } }); } diff --git a/src/preload/index.ts b/src/preload/index.ts index 07b4ec99..5f9bc02c 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -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); diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index d2e50fde..31c99df5 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -211,6 +211,7 @@ declare global { openAuthWindow: (page: AuthPage) => Promise; getSessionHash: () => Promise; onSignIn: (cb: () => void) => () => Electron.IpcRenderer; + onAccountUpdated: (cb: () => void) => () => Electron.IpcRenderer; onSignOut: (cb: () => void) => () => Electron.IpcRenderer; /* User */ diff --git a/src/renderer/src/pages/settings/settings-account.tsx b/src/renderer/src/pages/settings/settings-account.tsx index 4a19819d..3ca7152e 100644 --- a/src/renderer/src/pages/settings/settings-account.tsx +++ b/src/renderer/src/pages/settings/settings-account.tsx @@ -52,11 +52,18 @@ export function SettingsAccount() { }, [userDetails, setValue]); useEffect(() => { - fetchUserDetails().then((response) => { - if (response) { - updateUserDetails(response); - } + const unsubscribe = window.electron.onAccountUpdated(() => { + fetchUserDetails().then((response) => { + if (response) { + updateUserDetails(response); + } + }); + showSuccessToast(t("account_data_updated_successfully")); }); + + return () => { + unsubscribe(); + }; }, [fetchUserDetails, updateUserDetails]); const visibilityOptions = [