fix: 修复桌面版残留服务和卸载清理

This commit is contained in:
2026-05-20 12:28:53 +08:00
parent 07ae90c1b5
commit 2cdc0a0c81
6 changed files with 88 additions and 5 deletions
+18 -1
View File
@@ -1,7 +1,8 @@
import type { ApiError, ApiErrorDetail } from '../types';
const TOKEN_KEY = 'capacity_report_token';
const API_BASE = (import.meta.env.VITE_API_BASE || '').replace(/\/$/, '');
const DESKTOP_API_BASE = 'http://127.0.0.1:19082';
const API_BASE = resolveApiBase();
const API_FETCH_RETRIES = 8;
const API_FETCH_RETRY_DELAY_MS = 500;
let onUnauthorized: (() => void) | null = null;
@@ -255,6 +256,22 @@ function apiUrl(url: string): string {
return `${API_BASE}${url.startsWith('/') ? url : `/${url}`}`;
}
function resolveApiBase(): string {
const configured = (import.meta.env.VITE_API_BASE || '').replace(/\/$/, '');
if (configured) {
return configured;
}
return isTauriRuntime() ? DESKTOP_API_BASE : '';
}
function isTauriRuntime(): boolean {
const win = window as Window & {
__TAURI__?: unknown;
__TAURI_INTERNALS__?: unknown;
};
return Boolean(win.__TAURI__ || win.__TAURI_INTERNALS__ || navigator.userAgent.includes('Tauri'));
}
function isLoginRequest(url: string): boolean {
try {
const parsed = new URL(url, window.location.origin);