mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-06-16 13:34:04 +08:00
8e4a0a1bbb
Rename `AppType` to `AppId` across the entire frontend codebase to better reflect its purpose as an application identifier rather than a type category. This aligns frontend naming with backend command parameter conventions. Changes: - Rename type `AppType` to `AppId` in src/lib/api/types.ts - Remove `AppType` export from src/lib/api/index.ts - Update all component props from `appType` to `appId` (43 files) - Update all variable names from `appType` to `appId` - Synchronize documentation (CHANGELOG, refactoring plans) - Update test files and MSW mocks BREAKING CHANGE: `AppType` type is no longer exported. Use `AppId` instead. All component props have been renamed from `appType` to `appId`.
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
|
import type { Provider } from "@/types";
|
|
import type { AppId } from "./types";
|
|
|
|
export interface ProviderSortUpdate {
|
|
id: string;
|
|
sortIndex: number;
|
|
}
|
|
|
|
export interface ProviderSwitchEvent {
|
|
appType: AppId;
|
|
providerId: string;
|
|
}
|
|
|
|
export const providersApi = {
|
|
async getAll(appId: AppId): Promise<Record<string, Provider>> {
|
|
return await invoke("get_providers", { app: appId });
|
|
},
|
|
|
|
async getCurrent(appId: AppId): Promise<string> {
|
|
return await invoke("get_current_provider", { app: appId });
|
|
},
|
|
|
|
async add(provider: Provider, appId: AppId): Promise<boolean> {
|
|
return await invoke("add_provider", { provider, app: appId });
|
|
},
|
|
|
|
async update(provider: Provider, appId: AppId): Promise<boolean> {
|
|
return await invoke("update_provider", { provider, app: appId });
|
|
},
|
|
|
|
async delete(id: string, appId: AppId): Promise<boolean> {
|
|
return await invoke("delete_provider", { id, app: appId });
|
|
},
|
|
|
|
async switch(id: string, appId: AppId): Promise<boolean> {
|
|
return await invoke("switch_provider", { id, app: appId });
|
|
},
|
|
|
|
async importDefault(appId: AppId): Promise<boolean> {
|
|
return await invoke("import_default_config", { app: appId });
|
|
},
|
|
|
|
async updateTrayMenu(): Promise<boolean> {
|
|
return await invoke("update_tray_menu");
|
|
},
|
|
|
|
async updateSortOrder(
|
|
updates: ProviderSortUpdate[],
|
|
appId: AppId,
|
|
): Promise<boolean> {
|
|
return await invoke("update_providers_sort_order", { updates, app: appId });
|
|
},
|
|
|
|
async onSwitched(
|
|
handler: (event: ProviderSwitchEvent) => void,
|
|
): Promise<UnlistenFn> {
|
|
return await listen("provider-switched", (event) => {
|
|
const payload = event.payload as ProviderSwitchEvent;
|
|
handler(payload);
|
|
});
|
|
},
|
|
};
|