fix: stabilize download source switching

- serialize app and core version checks to prevent state races
- keep the source selector responsive during background checks
- prevent stale fallback results from overriding recent selections
- style the custom source action and restore the compact selector width
This commit is contained in:
lzt404 committed 2026-08-26 01:56:46 +08:00
1 parent 6d7da20e4e
commit 1df1f7808f
5 files changed
+15 -15

No files matched your search

+1
View File
@@ -130,6 +130,7 @@ pub(crate) async fn check_app_update(
state: tauri::State<'_, AppUpdateState>,
gui_config_state: tauri::State<'_, GuiConfigState>,
) -> Result<AppUpdateInfo, String> {
let _detection_guard = VERSION_SOURCE_DETECTION_LOCK.lock().await;
let config = gui_config_state.snapshot()?;
let proxy_url = config.proxy_url.clone();
let client = build_http_client_with_proxy(
+1
View File
@@ -5,6 +5,7 @@ pub(crate) async fn check_latest_core(
app: tauri::AppHandle,
gui_config_state: tauri::State<'_, GuiConfigState>,
) -> Result<CoreLatest, String> {
let _detection_guard = VERSION_SOURCE_DETECTION_LOCK.lock().await;
let platform = current_core_platform()?;
let config = gui_config_state.snapshot()?;
let proxy_url = config.proxy_url.clone();
+1
View File
@@ -111,6 +111,7 @@ const CORE_INSTALL_PROGRESS_EVENT: &str = "core-install-progress";
const CORE_STATUS_EVENT: &str = "core-status-changed";
const CONFIG_FILES_CHANGED_EVENT: &str = "config-files-changed";
const VERSION_DOWNLOAD_SOURCE_CHANGED_EVENT: &str = "version-download-source-changed";
static VERSION_SOURCE_DETECTION_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
#[cfg(target_os = "windows")]
const WINDOWS_CLOSE_REQUEST_EVENT: &str = "windows-close-requested";
const CORE_METADATA_FILE: &str = "cpa-gui-meta.json";
+10 -4
View File
@@ -245,7 +245,9 @@ export function VersionManagementPage() {
cachedLatestError = '';
setLatest(null);
showToast(t('kernel.versions.gitcodeSwitchSuccess'), 'success');
await Promise.allSettled([checkAppUpdate(), checkLatest(true)]);
setVersionSourceSaving(false);
await checkAppUpdate();
await checkLatest(true);
} catch (error) {
await loadVersionSourceSettings();
setVersionSourceError(t('kernel.versions.gitcodeSaveFailed', { error: String(error) }));
@@ -269,7 +271,9 @@ export function VersionManagementPage() {
cachedLatestError = '';
setLatest(null);
showToast(t('kernel.versions.customMirrorAdded'), 'success');
await Promise.allSettled([checkAppUpdate(), checkLatest(true)]);
setVersionSourceSaving(false);
await checkAppUpdate();
await checkLatest(true);
} catch (error) {
const message = t('kernel.versions.customMirrorAddFailed', { error: String(error) });
setVersionSourceError(message);
@@ -289,8 +293,10 @@ export function VersionManagementPage() {
});
setVersionSource(settings);
showToast(t('kernel.versions.customMirrorRemoved'), 'success');
setVersionSourceSaving(false);
if (wasSelected) {
await Promise.allSettled([checkAppUpdate(), checkLatest(true)]);
await checkAppUpdate();
await checkLatest(true);
}
} catch (error) {
const message = t('kernel.versions.customMirrorRemoveFailed', { error: String(error) });
@@ -618,7 +624,7 @@ export function VersionManagementPage() {
</label>
<button
type="button"
className="version-source-add-button"
className="primary-button version-source-add-button"
disabled={versionSourceSaving || appUpdateTask.running || installing}
onClick={() => {
setVersionSourceError('');
+2 -11
View File
@@ -1079,14 +1079,14 @@ textarea:focus-visible {
.version-source-control {
display: grid;
grid-template-columns: minmax(0, 250px) auto;
grid-template-columns: minmax(0, 220px) auto;
width: max-content;
max-width: 100%;
gap: 8px;
}
.version-source-control select {
width: 250px;
width: 220px;
max-width: 100%;
height: 42px;
padding: 0 36px 0 12px;
@@ -1114,15 +1114,6 @@ textarea:focus-visible {
justify-content: center;
gap: 6px;
padding: 0 12px;
border: 1px solid var(--theme-d5d2cb);
border-radius: 8px;
background: var(--theme-fffdf8);
color: var(--theme-4b4742);
}
.version-source-add-button:hover:not(:disabled) {
border-color: var(--theme-9b958c);
background: var(--theme-faf8f2);
}
.version-source-add-button:disabled {