修复所有lint警告和错误

This commit is contained in:
xintaofei
2026-03-26 21:47:13 +08:00
parent 5e5c48338b
commit f61f9fb025
20 changed files with 138 additions and 93 deletions

View File

@@ -1,10 +1,7 @@
export type TransportEnvironment = "tauri" | "web"
export function detectEnvironment(): TransportEnvironment {
if (
typeof window !== "undefined" &&
"__TAURI_INTERNALS__" in window
) {
if (typeof window !== "undefined" && "__TAURI_INTERNALS__" in window) {
return "tauri"
}
return "web"

View File

@@ -10,17 +10,16 @@ export function getTransport(): Transport {
const env = detectEnvironment()
if (env === "tauri") {
// Use dynamic require to avoid bundling tauri deps in web mode.
// TauriTransport uses dynamic imports internally.
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { TauriTransport } = require("./tauri-transport") as {
TauriTransport: new () => Transport
}
_transport = new TauriTransport()
} else {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { WebTransport } = require("./web-transport") as {
WebTransport: new (baseUrl: string) => Transport
}
// In web mode, the API is served from the same origin.
// Token is read from localStorage on each request.
const baseUrl = window.location.origin
_transport = new WebTransport(baseUrl)
}

View File

@@ -1,10 +1,7 @@
import type { Transport, UnsubscribeFn } from "./types"
export class TauriTransport implements Transport {
async call<T>(
command: string,
args?: Record<string, unknown>
): Promise<T> {
async call<T>(command: string, args?: Record<string, unknown>): Promise<T> {
const { invoke } = await import("@tauri-apps/api/core")
return invoke(command, args)
}

View File

@@ -20,10 +20,7 @@ export class WebTransport implements Transport {
this.baseUrl = baseUrl
}
async call<T>(
command: string,
args?: Record<string, unknown>
): Promise<T> {
async call<T>(command: string, args?: Record<string, unknown>): Promise<T> {
const token = getToken()
const res = await fetch(`${this.baseUrl}/api/${command}`, {
method: "POST",