Refactor application structure and simplify implementation
This commit is contained in:
+76
-92
@@ -1,4 +1,4 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type {
|
||||
ActivityEntry,
|
||||
ComponentStatus,
|
||||
@@ -9,7 +9,7 @@ import type {
|
||||
SubscriptionServer,
|
||||
Target,
|
||||
TargetInput,
|
||||
} from '../domain/types';
|
||||
} from "../domain/types";
|
||||
|
||||
export interface CommandError {
|
||||
code: string;
|
||||
@@ -20,16 +20,6 @@ export interface CommandError {
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface StatusResponse {
|
||||
routeLine: string;
|
||||
activeProfileCount: number;
|
||||
routedAppCount: number;
|
||||
activeTarget?: Target;
|
||||
components: ComponentStatus[];
|
||||
recentActivity: ActivityEntry[];
|
||||
generatedConfigPath: string;
|
||||
}
|
||||
|
||||
export interface AdminStatusResponse {
|
||||
isWindows: boolean;
|
||||
isElevated: boolean;
|
||||
@@ -67,8 +57,8 @@ export interface ProxiFyreSetupStatus {
|
||||
}
|
||||
|
||||
export interface ProxiFyreSetupProgress {
|
||||
operation: 'idle' | 'install' | 'uninstall' | string;
|
||||
status: 'idle' | 'running' | 'succeeded' | 'failed' | string;
|
||||
operation: "idle" | "install" | "uninstall" | string;
|
||||
status: "idle" | "running" | "succeeded" | "failed" | string;
|
||||
activeStep?: string;
|
||||
percent: number;
|
||||
message: string;
|
||||
@@ -102,6 +92,7 @@ export interface SubscriptionRequestHeader {
|
||||
}
|
||||
|
||||
export interface PingServerResponse {
|
||||
id: string;
|
||||
tag: string;
|
||||
server: string;
|
||||
serverPort: number;
|
||||
@@ -110,6 +101,34 @@ export interface PingServerResponse {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export type ApplyPhaseStatus =
|
||||
"succeeded" | "failed" | "rolledback" | "skipped" | "warning";
|
||||
|
||||
export interface ApplyPhase {
|
||||
id: string;
|
||||
status: ApplyPhaseStatus;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ApplyConfigurationInput {
|
||||
routeMode: "external" | "local-singbox";
|
||||
profile: ProfileInput;
|
||||
externalTarget?: TargetInput;
|
||||
disableOtherProfiles?: boolean;
|
||||
}
|
||||
|
||||
export interface ApplyConfigurationResult {
|
||||
success: boolean;
|
||||
changed: boolean;
|
||||
partialState: boolean;
|
||||
message: string;
|
||||
errorCode?: string;
|
||||
generatedConfigPath: string;
|
||||
singboxGeneratedConfigPath?: string;
|
||||
restartRequired: Array<"control-app" | "proxyfier" | "singbox">;
|
||||
phases: ApplyPhase[];
|
||||
}
|
||||
|
||||
export interface ProxyProbeResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -147,98 +166,60 @@ export interface GenerateSingBoxConfigResponse {
|
||||
activity: ActivityEntry;
|
||||
}
|
||||
|
||||
export interface HelperApplyResult {
|
||||
success: boolean;
|
||||
changed: boolean;
|
||||
action: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ApplyProfilesResponse {
|
||||
success: boolean;
|
||||
changed: boolean;
|
||||
message: string;
|
||||
adapterId: string;
|
||||
generatedConfigPath: string;
|
||||
enabledProfiles: number;
|
||||
routedApps: number;
|
||||
helper: HelperApplyResult;
|
||||
activity: ActivityEntry;
|
||||
}
|
||||
|
||||
export function getStatus(): Promise<StatusResponse> {
|
||||
return invoke<StatusResponse>('get_status');
|
||||
}
|
||||
|
||||
export function getAdminStatus(): Promise<AdminStatusResponse> {
|
||||
return invoke<AdminStatusResponse>('get_admin_status');
|
||||
}
|
||||
|
||||
export function restartAsAdmin(): Promise<void> {
|
||||
return invoke<void>('restart_as_admin');
|
||||
return invoke<void>("restart_as_admin");
|
||||
}
|
||||
|
||||
export function getStartupSnapshot(): Promise<StartupSnapshotResponse> {
|
||||
return invoke<StartupSnapshotResponse>('get_startup_snapshot');
|
||||
return invoke<StartupSnapshotResponse>("get_startup_snapshot");
|
||||
}
|
||||
|
||||
export function getSavedState(): Promise<SavedStateResponse> {
|
||||
return invoke<SavedStateResponse>('get_saved_state');
|
||||
}
|
||||
|
||||
export function getProfiles(): Promise<Profile[]> {
|
||||
return invoke<Profile[]>('get_profiles');
|
||||
}
|
||||
|
||||
export function saveProfile(input: ProfileInput): Promise<Profile> {
|
||||
return invoke<Profile>('save_profile', { input });
|
||||
}
|
||||
|
||||
export function getTargets(): Promise<Target[]> {
|
||||
return invoke<Target[]>('get_targets');
|
||||
}
|
||||
|
||||
export function saveTarget(input: TargetInput): Promise<Target> {
|
||||
return invoke<Target>('save_target', { input });
|
||||
return invoke<SavedStateResponse>("get_saved_state");
|
||||
}
|
||||
|
||||
export function getComponents(): Promise<ComponentStatus[]> {
|
||||
return invoke<ComponentStatus[]>('get_components');
|
||||
return invoke<ComponentStatus[]>("get_components");
|
||||
}
|
||||
|
||||
export function getProxiFyreSetupStatus(): Promise<ProxiFyreSetupStatus> {
|
||||
return invoke<ProxiFyreSetupStatus>('get_proxifyre_setup_status');
|
||||
return invoke<ProxiFyreSetupStatus>("get_proxifyre_setup_status");
|
||||
}
|
||||
|
||||
export function getProxiFyreSetupProgress(): Promise<ProxiFyreSetupProgress> {
|
||||
return invoke<ProxiFyreSetupProgress>('get_proxifyre_setup_progress');
|
||||
return invoke<ProxiFyreSetupProgress>("get_proxifyre_setup_progress");
|
||||
}
|
||||
|
||||
export function getSingBoxStatus(): Promise<LocalSingBoxStatusResponse> {
|
||||
return invoke<LocalSingBoxStatusResponse>('get_singbox_status');
|
||||
return invoke<LocalSingBoxStatusResponse>("get_singbox_status");
|
||||
}
|
||||
|
||||
export function getSingBoxSetupStatus(): Promise<SingBoxSetupStatus> {
|
||||
return invoke<SingBoxSetupStatus>('get_singbox_setup_status');
|
||||
return invoke<SingBoxSetupStatus>("get_singbox_setup_status");
|
||||
}
|
||||
|
||||
export function saveSingBoxSubscription(subscriptionUrl: string): Promise<LocalSingBoxStatusResponse> {
|
||||
return invoke<LocalSingBoxStatusResponse>('save_singbox_subscription', {
|
||||
export function saveSingBoxSubscription(
|
||||
subscriptionUrl: string,
|
||||
): Promise<LocalSingBoxStatusResponse> {
|
||||
return invoke<LocalSingBoxStatusResponse>("save_singbox_subscription", {
|
||||
input: { subscriptionUrl },
|
||||
});
|
||||
}
|
||||
|
||||
export function fetchSingBoxSubscription(): Promise<LocalSingBoxStatusResponse> {
|
||||
return invoke<LocalSingBoxStatusResponse>('fetch_singbox_subscription');
|
||||
return invoke<LocalSingBoxStatusResponse>("fetch_singbox_subscription");
|
||||
}
|
||||
|
||||
export function forgetSingBoxSubscription(): Promise<LocalSingBoxStatusResponse> {
|
||||
return invoke<LocalSingBoxStatusResponse>('forget_singbox_subscription');
|
||||
return invoke<LocalSingBoxStatusResponse>("forget_singbox_subscription");
|
||||
}
|
||||
|
||||
export function selectSingBoxServer(server: SubscriptionServer): Promise<LocalSingBoxStatusResponse> {
|
||||
return invoke<LocalSingBoxStatusResponse>('select_singbox_server', {
|
||||
export function selectSingBoxServer(
|
||||
server: SubscriptionServer,
|
||||
): Promise<LocalSingBoxStatusResponse> {
|
||||
return invoke<LocalSingBoxStatusResponse>("select_singbox_server", {
|
||||
input: {
|
||||
id: server.id,
|
||||
tag: server.tag,
|
||||
server: server.server,
|
||||
serverPort: server.serverPort,
|
||||
@@ -246,62 +227,65 @@ export function selectSingBoxServer(server: SubscriptionServer): Promise<LocalSi
|
||||
});
|
||||
}
|
||||
|
||||
export function pingSingBoxServer(tag: string): Promise<PingServerResponse> {
|
||||
return invoke<PingServerResponse>('ping_singbox_server', {
|
||||
input: { tag },
|
||||
export function pingSingBoxServer(
|
||||
server: SubscriptionServer,
|
||||
): Promise<PingServerResponse> {
|
||||
return invoke<PingServerResponse>("ping_singbox_server", {
|
||||
input: { id: server.id, tag: server.tag },
|
||||
});
|
||||
}
|
||||
|
||||
export function pingAllSingBoxServers(): Promise<PingServerResponse[]> {
|
||||
return invoke<PingServerResponse[]>('ping_all_singbox_servers');
|
||||
return invoke<PingServerResponse[]>("ping_all_singbox_servers");
|
||||
}
|
||||
|
||||
export function pingProxyTarget(host: string, port: number): Promise<ProxyTargetCheckResponse> {
|
||||
return invoke<ProxyTargetCheckResponse>('ping_proxy_target', {
|
||||
export function pingProxyTarget(
|
||||
host: string,
|
||||
port: number,
|
||||
): Promise<ProxyTargetCheckResponse> {
|
||||
return invoke<ProxyTargetCheckResponse>("ping_proxy_target", {
|
||||
input: { host, port },
|
||||
});
|
||||
}
|
||||
|
||||
export function generateSingBoxConfig(): Promise<GenerateSingBoxConfigResponse> {
|
||||
return invoke<GenerateSingBoxConfigResponse>('generate_singbox_config');
|
||||
return invoke<GenerateSingBoxConfigResponse>("generate_singbox_config");
|
||||
}
|
||||
|
||||
export function applyProfiles(): Promise<ApplyProfilesResponse> {
|
||||
return invoke<ApplyProfilesResponse>('apply_profiles');
|
||||
}
|
||||
|
||||
export function openConfigLocation(): Promise<string> {
|
||||
return invoke<string>('open_config_location');
|
||||
export function applyConfiguration(
|
||||
input: ApplyConfigurationInput,
|
||||
): Promise<ApplyConfigurationResult> {
|
||||
return invoke<ApplyConfigurationResult>("apply_configuration", { input });
|
||||
}
|
||||
|
||||
export function startProxiFyreService(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('start_proxifyre_service');
|
||||
return invoke<ComponentStatus>("start_proxifyre_service");
|
||||
}
|
||||
|
||||
export function stopProxiFyreService(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('stop_proxifyre_service');
|
||||
return invoke<ComponentStatus>("stop_proxifyre_service");
|
||||
}
|
||||
|
||||
export function installProxiFyre(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('install_proxifyre');
|
||||
return invoke<ComponentStatus>("install_proxifyre");
|
||||
}
|
||||
|
||||
export function uninstallProxiFyre(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('uninstall_proxifyre');
|
||||
return invoke<ComponentStatus>("uninstall_proxifyre");
|
||||
}
|
||||
|
||||
export function startSingBoxService(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('start_singbox_service');
|
||||
return invoke<ComponentStatus>("start_singbox_service");
|
||||
}
|
||||
|
||||
export function stopSingBoxService(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('stop_singbox_service');
|
||||
return invoke<ComponentStatus>("stop_singbox_service");
|
||||
}
|
||||
|
||||
export function installSingBox(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('install_singbox');
|
||||
return invoke<ComponentStatus>("install_singbox");
|
||||
}
|
||||
|
||||
export function uninstallSingBox(): Promise<ComponentStatus> {
|
||||
return invoke<ComponentStatus>('uninstall_singbox');
|
||||
return invoke<ComponentStatus>("uninstall_singbox");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user