Skip to content

Commit f2633b0

Browse files
authored
Merge pull request #64 from TechCat-Team/develop
Develop
2 parents 95d7df6 + 0257a19 commit f2633b0

22 files changed

Lines changed: 152 additions & 354 deletions

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## v0.7.5
4+
5+
### 修复
6+
- 自启动隧道失效的问题
7+
- 在登陆失效后提示用户重新登陆
8+
9+
### 优化
10+
- 调整图表颜色,改进暗色模式下的配色
11+
- 在用户退出的时候清理关闭全部隧道
12+
- 删除遗留的系统托盘自启动代码
13+
- 删除"仅存在IPV6"功能
14+
15+
316
## v0.7.3
417

518
### 新增

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chmlfrplauncher",
33
"private": true,
4-
"version": "0.7.3",
4+
"version": "0.7.5",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ChmlFrpLauncher"
3-
version = "0.7.3"
3+
version = "0.7.5"
44
description = "ChmlFrp的官方启动器"
55
authors = ["南充市轻爪网络科技有限公司 <chaoji@chcat.cn>"]
66
license = "Apache-2.0"

src-tauri/src/commands/autostart.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -91,38 +91,3 @@ pub async fn set_tunnel_auto_start(
9191

9292
Ok(())
9393
}
94-
95-
/// 获取所有自动启动的隧道列表
96-
#[tauri::command]
97-
pub async fn get_auto_start_tunnels(
98-
app: tauri::AppHandle,
99-
) -> Result<Vec<(String, String)>, String> {
100-
let app_data_dir = app
101-
.path()
102-
.app_data_dir()
103-
.map_err(|e| format!("获取应用数据目录失败: {}", e))?;
104-
105-
let config_path = app_data_dir.join("tunnel_auto_start.json");
106-
107-
if !config_path.exists() {
108-
return Ok(vec![]);
109-
}
110-
111-
let content = std::fs::read_to_string(&config_path)
112-
.map_err(|e| format!("读取配置文件失败: {}", e))?;
113-
114-
let config: serde_json::Map<String, serde_json::Value> = serde_json::from_str(&content)
115-
.map_err(|e| format!("解析配置文件失败: {}", e))?;
116-
117-
let mut result = vec![];
118-
for (key, value) in config {
119-
if let Some(true) = value.as_bool() {
120-
// 解析 key 格式: "api_123" or "custom_any_id_with_underscore"
121-
if let Some((tunnel_type, id_str)) = key.split_once('_') {
122-
result.push((tunnel_type.to_string(), id_str.to_string()));
123-
}
124-
}
125-
}
126-
127-
Ok(result)
128-
}

src-tauri/src/lib.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,6 @@ use tauri::{
1010
Emitter, Listener, Manager,
1111
};
1212

13-
const AUTO_START_CONFIG_FILE: &str = "auto_start_tunnels.json";
14-
15-
fn get_auto_start_tunnels_setting(app_handle: &tauri::AppHandle) -> bool {
16-
let Some(app_data_dir) = app_handle.path().app_data_dir().ok() else {
17-
return false;
18-
};
19-
let config_path = app_data_dir.join(AUTO_START_CONFIG_FILE);
20-
if !config_path.exists() {
21-
return false;
22-
}
23-
let Ok(content) = std::fs::read_to_string(&config_path) else {
24-
return false;
25-
};
26-
serde_json::from_str::<serde_json::Value>(&content)
27-
.ok()
28-
.and_then(|config| config.get("enabled").and_then(|v| v.as_bool()))
29-
.unwrap_or(false)
30-
}
31-
32-
fn save_auto_start_tunnels_setting(app_handle: &tauri::AppHandle, enabled: bool) -> bool {
33-
let Some(app_data_dir) = app_handle.path().app_data_dir().ok() else {
34-
return false;
35-
};
36-
if std::fs::create_dir_all(&app_data_dir).is_err() {
37-
return false;
38-
}
39-
let config_path = app_data_dir.join(AUTO_START_CONFIG_FILE);
40-
let config = serde_json::json!({ "enabled": enabled });
41-
std::fs::write(&config_path, serde_json::to_string_pretty(&config).unwrap()).is_ok()
42-
}
43-
4413
fn cleanup_official_tunnel_configs(app_handle: &tauri::AppHandle) {
4514
let Ok(app_data_dir) = app_handle.path().app_data_dir() else {
4615
return;
@@ -58,22 +27,12 @@ fn cleanup_official_tunnel_configs(app_handle: &tauri::AppHandle) {
5827
}
5928

6029
fn build_tray_menu(app: &tauri::App) -> Result<tauri::menu::Menu<tauri::Wry>, Box<dyn std::error::Error>> {
61-
let auto_start_tunnels = get_auto_start_tunnels_setting(&app.handle());
62-
let auto_start_label = if auto_start_tunnels {
63-
"✓ 启动软件时自动启动隧道"
64-
} else {
65-
"启动软件时自动启动隧道"
66-
};
67-
6830
let show_item = MenuItemBuilder::with_id("show", "显示窗口").build(app)?;
69-
let auto_start_item = MenuItemBuilder::with_id("auto_start_tunnels", auto_start_label).build(app)?;
7031
let quit_item = MenuItemBuilder::with_id("quit", "退出").build(app)?;
7132

7233
MenuBuilder::new(app)
7334
.item(&show_item)
7435
.separator()
75-
.item(&auto_start_item)
76-
.separator()
7736
.item(&quit_item)
7837
.build()
7938
.map_err(Into::into)
@@ -135,15 +94,6 @@ pub fn run() {
13594
let _ = window.set_focus();
13695
}
13796
}
138-
"auto_start_tunnels" => {
139-
let app_handle = app.clone();
140-
let current_setting = get_auto_start_tunnels_setting(&app_handle);
141-
let new_setting = !current_setting;
142-
143-
if save_auto_start_tunnels_setting(&app_handle, new_setting) {
144-
let _ = app_handle.emit("auto-start-tunnels-changed", new_setting);
145-
}
146-
}
14797
"quit" => {
14898
app.exit(0);
14999
}
@@ -258,7 +208,6 @@ pub fn run() {
258208
commands::get_running_tunnels,
259209
commands::is_autostart_enabled,
260210
commands::set_autostart,
261-
commands::get_auto_start_tunnels,
262211
commands::get_tunnel_auto_start,
263212
commands::set_tunnel_auto_start,
264213
commands::http_request,

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "ChmlFrpLauncher",
4-
"version": "0.7.3",
4+
"version": "0.7.5",
55
"identifier": "net.chmlfrp.launcher",
66
"build": {
77
"frontendDist": "../dist",

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useBackground } from "@/components/App/hooks/useBackground";
1818
import { useDeepLink } from "@/components/App/hooks/useDeepLink";
1919
import { useFrpcDownload } from "@/components/App/hooks/useFrpcDownload";
2020
import { useUpdateCheck } from "@/components/App/hooks/useUpdateCheck";
21-
import { useStartupAutoStartTunnels } from "@/components/App/hooks/useStartupAutoStartTunnels";
21+
import { useAutoStartTunnels } from "@/components/App/hooks/useAutoStartTunnels";
2222
import { updateService } from "@/services/updateService";
2323
import { toast } from "sonner";
2424
import { BackgroundLayer } from "@/components/App/components/BackgroundLayer";
@@ -46,8 +46,8 @@ function App() {
4646
// 其他功能 Hooks
4747
useAppTheme();
4848
useAppInitialization();
49+
useAutoStartTunnels(user);
4950
useDeepLink(user, setUser);
50-
useStartupAutoStartTunnels(user);
5151
useTunnelNotifications(activeTab);
5252
const { showCloseConfirmDialog, setShowCloseConfirmDialog } = useWindowEvents();
5353
const { showTitleBar } = useTitleBar();

src/components/App/hooks/useAppInitialization.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,7 @@ export function useAppInitialization() {
2020
}
2121
};
2222

23-
const initIpv6OnlyNetwork = async () => {
24-
if (typeof window === "undefined") return;
25-
if (localStorage.getItem("ipv6OnlyNetwork") !== null) return;
26-
if (!("__TAURI__" in window)) {
27-
localStorage.setItem("ipv6OnlyNetwork", "false");
28-
window.dispatchEvent(new Event("ipv6OnlyNetworkChanged"));
29-
return;
30-
}
31-
32-
try {
33-
const { invoke } = await import("@tauri-apps/api/core");
34-
const ipv4Result = await invoke<{ success: boolean }>("ping_host", {
35-
host: "1.1.1.1",
36-
});
37-
const ipv6Result = await invoke<{ success: boolean }>("ping_host", {
38-
host: "2606:4700:4700::1111",
39-
});
40-
const ipv6Only = ipv6Result.success && !ipv4Result.success;
41-
localStorage.setItem("ipv6OnlyNetwork", ipv6Only ? "true" : "false");
42-
window.dispatchEvent(new Event("ipv6OnlyNetworkChanged"));
43-
} catch {
44-
localStorage.setItem("ipv6OnlyNetwork", "false");
45-
window.dispatchEvent(new Event("ipv6OnlyNetworkChanged"));
46-
}
47-
};
48-
4923
initProcessGuard();
50-
initIpv6OnlyNetwork();
5124
}, []);
5225

5326
useEffect(() => {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { useEffect, useRef } from "react";
2+
import { fetchTunnels, type StoredUser, type Tunnel } from "@/services/api";
3+
import { frpcManager } from "@/services/frpcManager";
4+
import { customTunnelService } from "@/services/customTunnelService";
5+
import { autoStartTunnelsService } from "@/services/autoStartTunnelsService";
6+
7+
export function useAutoStartTunnels(user: StoredUser | null) {
8+
const hasRunRef = useRef(false);
9+
10+
useEffect(() => {
11+
if (hasRunRef.current) return;
12+
if (!user?.usertoken) return;
13+
14+
hasRunRef.current = true;
15+
16+
const run = async () => {
17+
try {
18+
const [apiTunnels, customTunnels] = await Promise.all([
19+
fetchTunnels().catch(() => [] as Tunnel[]),
20+
customTunnelService.getCustomTunnels().catch(() => []),
21+
]);
22+
23+
await Promise.all(
24+
apiTunnels.map(async (t) => {
25+
try {
26+
const enabled = await autoStartTunnelsService.isTunnelEnabled(
27+
"api",
28+
t.id,
29+
);
30+
if (!enabled) return;
31+
if (t.nodestate && t.nodestate !== "online") return;
32+
const running = await frpcManager
33+
.isTunnelRunning(t.id)
34+
.catch(() => false);
35+
if (running) return;
36+
await frpcManager.startTunnel(t, user.usertoken!);
37+
} catch (error) {
38+
console.error(`自动启动隧道失败 (api ${t.id}):`, error);
39+
}
40+
}),
41+
);
42+
43+
await Promise.all(
44+
customTunnels.map(async (t) => {
45+
try {
46+
const enabled = await autoStartTunnelsService.isTunnelEnabled(
47+
"custom",
48+
t.id,
49+
);
50+
if (!enabled) return;
51+
const running = await customTunnelService
52+
.isCustomTunnelRunning(t.id)
53+
.catch(() => false);
54+
if (running) return;
55+
await customTunnelService.startCustomTunnel(t.id);
56+
} catch (error) {
57+
console.error(`自动启动自定义隧道失败 (${t.id}):`, error);
58+
}
59+
}),
60+
);
61+
} catch (error) {
62+
console.error("自动启动隧道失败:", error);
63+
}
64+
};
65+
66+
void run();
67+
}, [user?.usertoken]);
68+
}

0 commit comments

Comments
 (0)