Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src-tauri/src/launcher_config/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ pub async fn check_launcher_update(app: AppHandle) -> XMCLResult<VersionMetaInfo
Ok(VersionMetaInfo::default())
}

#[tauri::command]
pub async fn test_proxy_connection(app: AppHandle, test_url: String) -> XMCLResult<bool> {
crate::launcher_config::helpers::proxy::test_proxy_connectivity(&app, test_url).await
}

#[tauri::command]
pub async fn download_launcher_update(app: AppHandle, version: VersionMetaInfo) -> XMCLResult<()> {
if version.version.is_empty() || version.version == "up2date" {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/launcher_config/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod java;
pub mod misc;
pub mod proxy;
pub mod updater;
41 changes: 41 additions & 0 deletions src-tauri/src/launcher_config/helpers/proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::error::{XMCLError, XMCLResult};
use crate::launcher_config::models::{LauncherConfig, ProxyType};
use std::sync::Mutex;
use std::time::Duration;
use tauri::{AppHandle, Manager};
use tauri_plugin_http::reqwest;

pub async fn test_proxy_connectivity(app: &AppHandle, test_url: String) -> XMCLResult<bool> {
let config_binding = app.state::<Mutex<LauncherConfig>>();
let (proxy_enabled, proxy_type, proxy_host, proxy_port) = {
let config = config_binding.lock()?;
(
config.download.proxy.enabled,
config.download.proxy.selected_type.clone(),
config.download.proxy.host.clone(),
config.download.proxy.port,
)
};

if !proxy_enabled || proxy_host.is_empty() || proxy_port == 0 {
return Ok(false);
}

let proxy_url = match proxy_type {
ProxyType::Http => format!("http://{}:{}", proxy_host, proxy_port),
ProxyType::Socks => format!("socks5://{}:{}", proxy_host, proxy_port),
};

let proxy = reqwest::Proxy::all(&proxy_url).map_err(|e| XMCLError::from(e))?;

let client = reqwest::Client::builder()
.proxy(proxy)
.timeout(Duration::from_secs(10))
.build()
.map_err(|e| XMCLError::from(e))?;

match client.get(&test_url).send().await {
Ok(response) => Ok(response.status().is_success()),
Err(_) => Ok(false),
}
}
6 changes: 1 addition & 5 deletions src-tauri/src/launcher_config/helpers/updater.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use crate::error::{XMCLError, XMCLResult};
use crate::error::XMCLResult;
use crate::launcher_config::models::{LauncherConfig, LauncherConfigError};
use crate::tasks::commands::schedule_progressive_task_group;
use crate::tasks::download::DownloadParam;
use crate::tasks::PTaskParam;
use serde_json::Value;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::sync::Mutex;
use tauri::path::BaseDirectory;
use tauri::{AppHandle, Manager};
use tauri_plugin_http::reqwest;

Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub async fn run() {
launcher_config::commands::check_game_directory,
launcher_config::commands::clear_download_cache,
launcher_config::commands::check_launcher_update,
launcher_config::commands::test_proxy_connection,
launcher_config::commands::download_launcher_update,
launcher_config::commands::install_launcher_update,
account::commands::retrieve_player_list,
Expand Down
11 changes: 11 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,18 @@
},
"port": {
"title": "Port"
},
"test": {
"title": "Test Proxy Connection",
"placeholder": "https://www.baidu.com",
"button": "Test",
"success": "Connection successful",
"failed": "Connection failed"
}
},
"test": {
"success": "Proxy connection successful",
"failed": "Proxy connection failed"
}
}
},
Expand Down
11 changes: 11 additions & 0 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,18 @@
},
"port": {
"title": "Port"
},
"test": {
"title": "Tester la connexion du proxy",
"placeholder": "https://www.baidu.com",
"button": "Tester",
"success": "Connexion réussie",
"failed": "Connexion échouée"
}
},
"test": {
"success": "Connexion au proxy réussie",
"failed": "Connexion au proxy échouée"
}
}
},
Expand Down
11 changes: 11 additions & 0 deletions src/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,18 @@
},
"port": {
"title": "ポート"
},
"test": {
"title": "プロキシ接続をテスト",
"placeholder": "https://www.baidu.com",
"button": "テスト",
"success": "接続成功",
"failed": "接続失敗"
}
},
"test": {
"success": "プロキシ接続成功",
"failed": "プロキシ接続失敗"
}
}
},
Expand Down
11 changes: 11 additions & 0 deletions src/locales/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,18 @@
},
"port": {
"title": "端口"
},
"test": {
"title": "测试代理连接",
"placeholder": "https://www.baidu.com",
"button": "测试",
"success": "连接成功",
"failed": "连接失败"
}
},
"test": {
"success": "代理连接成功",
"failed": "代理连接失败"
}
}
},
Expand Down
11 changes: 11 additions & 0 deletions src/locales/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,18 @@
},
"port": {
"title": "埠"
},
"test": {
"title": "測試代理連線",
"placeholder": "https://www.baidu.com",
"button": "測試",
"success": "連線成功",
"failed": "連線失敗"
}
},
"test": {
"success": "代理連線成功",
"failed": "代理連線失敗"
}
}
},
Expand Down
54 changes: 54 additions & 0 deletions src/pages/settings/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const DownloadSettingsPage = () => {
);
const [isClearingDownloadCache, setIsClearingDownloadCache] =
useState<boolean>(false);
const [isTestingProxy, setIsTestingProxy] = useState<boolean>(false);
const [testUrl, setTestUrl] = useState<string>("");

const sourceStrategyTypes = ["auto", "official", "mirror"];
const proxyTypeOptions = [
Expand Down Expand Up @@ -123,6 +125,33 @@ const DownloadSettingsPage = () => {
closeSharedModal("generic-confirm");
};

const handleTestProxy = async () => {
if (isTestingProxy) return;

const url = testUrl.trim() || "https://www.baidu.com";
setIsTestingProxy(true);

try {
const response = await ConfigService.testProxyConnection(url);
if (response.status === "success") {
toast({
title: response.data
? t("DownloadSettingPage.proxy.test.success")
: t("DownloadSettingPage.proxy.test.failed"),
status: response.data ? "success" : "error",
});
} else {
toast({
title: t("DownloadSettingPage.proxy.test.failed"),
description: response.message,
status: "error",
});
}
} finally {
setIsTestingProxy(false);
}
};

const downloadSettingGroups: OptionItemGroupProps[] = [
{
items: [
Expand Down Expand Up @@ -446,6 +475,31 @@ const DownloadSettingsPage = () => {
</NumberInput>
),
},
{
title: t("DownloadSettingPage.proxy.settings.test.title"),
children: (
<HStack>
<Input
size="xs"
w="240px"
focusBorderColor={`${primaryColor}.500`}
placeholder={t(
"DownloadSettingPage.proxy.settings.test.placeholder"
)}
value={testUrl}
onChange={(event) => setTestUrl(event.target.value)}
/>
<Button
variant="subtle"
size="xs"
isLoading={isTestingProxy}
onClick={handleTestProxy}
>
{t("DownloadSettingPage.proxy.settings.test.button")}
</Button>
</HStack>
),
},
]
: []),
],
Expand Down
14 changes: 12 additions & 2 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,18 @@ export class ConfigService {
return await invoke("download_launcher_update", { version });
}

/**
* INSTALL the launcher update.
/** * TEST the proxy connection.
* @param {string} testUrl URL to test the proxy connection.
* @returns {Promise<InvokeResponse<boolean>>} Returns true if the connection is successful.
*/
@responseHandler("config")
static async testProxyConnection(
testUrl: string
): Promise<InvokeResponse<boolean>> {
return await invoke("test_proxy_connection", { testUrl });
}

/** * INSTALL the launcher update.
* @param {string} downloadedFilename The name of the downloaded new version file.
* @param {boolean} restart Whether to restart the launcher now.
* @returns {Promise<InvokeResponse<void>>} Returns void if the update process is started successfully.
Expand Down
Loading