-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import axios from "axios"; | ||
import axios, { AxiosInstance } from "axios"; | ||
import { getClashInfo } from "./command"; | ||
|
||
const axiosIns = axios.create({ | ||
baseURL: "http://127.0.0.1:9090", | ||
}); | ||
let axiosIns: AxiosInstance | null = null; | ||
|
||
axiosIns.interceptors.response.use((respone) => { | ||
return respone.data; | ||
}); | ||
export async function getAxios() { | ||
if (axiosIns) return axiosIns; | ||
|
||
export default axiosIns; | ||
let server = "127.0.0.1:9090"; | ||
let secret = ""; | ||
|
||
try { | ||
const info = await getClashInfo(); | ||
const { server: server_, secret: secret_ } = info?.controller ?? {}; | ||
if (server_) server = server_; | ||
if (secret_) secret = secret_; | ||
} catch {} | ||
|
||
axiosIns = axios.create({ | ||
baseURL: `http://${server}`, | ||
headers: secret ? { Authorization: `Bearer ${secret}` } : {}, | ||
}); | ||
axiosIns.interceptors.response.use((r) => r.data); | ||
|
||
return axiosIns; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { invoke } from "@tauri-apps/api/tauri"; | ||
|
||
export async function restartSidecar() { | ||
return invoke<void>("restart_sidebar"); | ||
} | ||
|
||
export interface ClashInfo { | ||
status: string; | ||
controller?: { server?: string; secret?: string }; | ||
message?: string; | ||
} | ||
|
||
export async function getClashInfo() { | ||
return invoke<ClashInfo | null>("get_clash_info"); | ||
} | ||
|
||
export async function importProfile(url: string) { | ||
return invoke<string>("import_profile", { url }); | ||
} | ||
|
||
export interface ProfileItem { | ||
name?: string; | ||
file?: string; | ||
mode?: string; | ||
url?: string; | ||
selected?: { name?: string; now?: string }[]; | ||
extra?: { | ||
upload: number; | ||
download: number; | ||
total: number; | ||
expire: number; | ||
}; | ||
} | ||
|
||
export interface ProfilesConfig { | ||
current?: number; | ||
items?: ProfileItem[]; | ||
} | ||
|
||
export async function getProfiles() { | ||
return (await invoke<ProfilesConfig[] | null>("get_profiles")) ?? []; | ||
} | ||
|
||
export async function setProfiles(current: number, profile: ProfileItem) { | ||
return invoke<void>("set_profiles", { current, profile }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters