diff --git a/src-tauri/src/commands/get_version_message.rs b/src-tauri/src/commands/get_version_message.rs index aa7637c..49c4b80 100644 --- a/src-tauri/src/commands/get_version_message.rs +++ b/src-tauri/src/commands/get_version_message.rs @@ -1,7 +1,8 @@ +use crate::commands::requests::ApiResponse; use crate::service::version::VersionService; #[tauri::command] -pub async fn get_version_message(site: String) -> Result { +pub async fn get_version_message(site: String) -> Result { if site.trim().is_empty() { return Err("site is empty".to_string()); } @@ -9,12 +10,5 @@ pub async fn get_version_message(site: String) -> Result { let version_service = VersionService::new(site); let version_message = version_service.get_version_message().await; - if version_message.status == 200 && version_message.success { - Ok(version_message.data) - } else if version_message.status == 404 { - Ok("incompatible".to_string()) - } else { - Ok("".to_string()) - } + Ok(version_message) } - diff --git a/ui/components/SideBar/profile.vue b/ui/components/SideBar/profile.vue index b109154..bb76946 100644 --- a/ui/components/SideBar/profile.vue +++ b/ui/components/SideBar/profile.vue @@ -12,6 +12,12 @@ interface VersionAlertPayload { version?: string; } +interface VersionMessageResponse { + status: number; + data: string; + success: boolean; +} + const props = defineProps<{ collapse: boolean }>(); const recentSiteLimit = 5; @@ -309,17 +315,17 @@ const handleClearInput = () => { recentSitesDismissed.value = false; }; -function normalizeVersionMessage(raw: string) { - if (raw === "incompatible") { +function normalizeVersionMessage(response: VersionMessageResponse) { + if (response.status === 404) { return { status: "incompatible" as const, versions: [] as string[] }; } - if (!raw) { + if (!response.data) { return { status: "list" as const, versions: [] as string[] }; } try { - const parsed = JSON.parse(raw); + const parsed = JSON.parse(response.data); const versions = Array.isArray(parsed) ? parsed.map((item) => (item == null ? "" : String(item))).filter((v) => v.length > 0) : []; @@ -361,13 +367,33 @@ const emitVersionAlertAndCloseModal = (payload: VersionAlertPayload) => { useEventBus().emit("versionAlert", payload); }; +const handleInvalidSiteVersion = () => { + clearLoginBtnUnlockTimer(); + loginBtn.value = false; + hasValidationError.value = true; + errorMessage.value = t("Login.InvalidSiteError"); + + void useTauriCoreInvoke("auth_cancel", {}); + + nextTick(() => { + inputRef.value?.$el?.querySelector("input")?.focus(); + }); +}; + const checkVersionBeforeOAuth = async (site: string) => { - const [rawVersionMessage, appVersion] = await Promise.all([ - useTauriCoreInvoke("get_version_message", { site }).catch(() => ""), + const [versionResponse, appVersion] = await Promise.all([ + useTauriCoreInvoke("get_version_message", { site }).catch((error) => { + return null; + }), useTauriAppGetVersion().catch(() => "") ]); - const { status: versionStatus, versions } = normalizeVersionMessage(rawVersionMessage); + if (!versionResponse || versionResponse.status === 0) { + handleInvalidSiteVersion(); + return false; + } + + const { status: versionStatus, versions } = normalizeVersionMessage(versionResponse); if (versionStatus === "incompatible") { emitVersionAlertAndCloseModal({ type: "incompatible" }); @@ -621,7 +647,7 @@ onMounted(async () => { let description = message || t("Login.LoginFailedErrorPage"); if (reason === "invalid-site") { - description = t("Login.InvalidSiteError"); + description = t(" "); } toast.add({