Skip to content

Commit ff84b4c

Browse files
committed
fix: Fix the issue with the timing of the unavailable site prompt message
1 parent ee7ef91 commit ff84b4c

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1+
use crate::commands::requests::ApiResponse;
12
use crate::service::version::VersionService;
23

34
#[tauri::command]
4-
pub async fn get_version_message(site: String) -> Result<String, String> {
5+
pub async fn get_version_message(site: String) -> Result<ApiResponse, String> {
56
if site.trim().is_empty() {
67
return Err("site is empty".to_string());
78
}
89

910
let version_service = VersionService::new(site);
1011
let version_message = version_service.get_version_message().await;
1112

12-
if version_message.status == 200 && version_message.success {
13-
Ok(version_message.data)
14-
} else if version_message.status == 404 {
15-
Ok("incompatible".to_string())
16-
} else {
17-
Ok("".to_string())
18-
}
13+
Ok(version_message)
1914
}
20-

ui/components/SideBar/profile.vue

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ interface VersionAlertPayload {
1212
version?: string;
1313
}
1414
15+
interface VersionMessageResponse {
16+
status: number;
17+
data: string;
18+
success: boolean;
19+
}
20+
1521
const props = defineProps<{ collapse: boolean }>();
1622
1723
const recentSiteLimit = 5;
@@ -309,17 +315,17 @@ const handleClearInput = () => {
309315
recentSitesDismissed.value = false;
310316
};
311317
312-
function normalizeVersionMessage(raw: string) {
313-
if (raw === "incompatible") {
318+
function normalizeVersionMessage(response: VersionMessageResponse) {
319+
if (response.status === 404) {
314320
return { status: "incompatible" as const, versions: [] as string[] };
315321
}
316322
317-
if (!raw) {
323+
if (!response.data) {
318324
return { status: "list" as const, versions: [] as string[] };
319325
}
320326
321327
try {
322-
const parsed = JSON.parse(raw);
328+
const parsed = JSON.parse(response.data);
323329
const versions = Array.isArray(parsed)
324330
? parsed.map((item) => (item == null ? "" : String(item))).filter((v) => v.length > 0)
325331
: [];
@@ -361,13 +367,33 @@ const emitVersionAlertAndCloseModal = (payload: VersionAlertPayload) => {
361367
useEventBus().emit("versionAlert", payload);
362368
};
363369
370+
const handleInvalidSiteVersion = () => {
371+
clearLoginBtnUnlockTimer();
372+
loginBtn.value = false;
373+
hasValidationError.value = true;
374+
errorMessage.value = t("Login.InvalidSiteError");
375+
376+
void useTauriCoreInvoke("auth_cancel", {});
377+
378+
nextTick(() => {
379+
inputRef.value?.$el?.querySelector("input")?.focus();
380+
});
381+
};
382+
364383
const checkVersionBeforeOAuth = async (site: string) => {
365-
const [rawVersionMessage, appVersion] = await Promise.all([
366-
useTauriCoreInvoke<string>("get_version_message", { site }).catch(() => ""),
384+
const [versionResponse, appVersion] = await Promise.all([
385+
useTauriCoreInvoke<VersionMessageResponse>("get_version_message", { site }).catch((error) => {
386+
return null;
387+
}),
367388
useTauriAppGetVersion().catch(() => "")
368389
]);
369390
370-
const { status: versionStatus, versions } = normalizeVersionMessage(rawVersionMessage);
391+
if (!versionResponse || versionResponse.status === 0) {
392+
handleInvalidSiteVersion();
393+
return false;
394+
}
395+
396+
const { status: versionStatus, versions } = normalizeVersionMessage(versionResponse);
371397
372398
if (versionStatus === "incompatible") {
373399
emitVersionAlertAndCloseModal({ type: "incompatible" });
@@ -621,7 +647,7 @@ onMounted(async () => {
621647
let description = message || t("Login.LoginFailedErrorPage");
622648
623649
if (reason === "invalid-site") {
624-
description = t("Login.InvalidSiteError");
650+
description = t(" ");
625651
}
626652
627653
toast.add({

0 commit comments

Comments
 (0)