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
6 changes: 4 additions & 2 deletions scripts/shots/core/en/status.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"api_version": 51,
"api_version": 52,
"clients": 4,
"config_path": "",
"draining": 0,
"gateway_addr": null,
"gateway_reachable": [],
"handover": "idle",
"in_flight": 0,
"pid": 0,
"providers": 7,
Expand All @@ -14,5 +16,5 @@
"reachable": []
},
"uptime_secs": 0,
"version": "0.79.0"
"version": "0.82.0"
}
1 change: 1 addition & 0 deletions scripts/shots/core/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async fn dump() {
price_updater: Default::default(),
chatgpt: Default::default(),
zai: Default::default(),
handover: Default::default(),
});

let write = |name: &str, v: &serde_json::Value| {
Expand Down
6 changes: 4 additions & 2 deletions scripts/shots/core/zh/status.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"api_version": 51,
"api_version": 52,
"clients": 4,
"config_path": "",
"draining": 0,
"gateway_addr": null,
"gateway_reachable": [],
"handover": "idle",
"in_flight": 0,
"pid": 0,
"providers": 7,
Expand All @@ -14,5 +16,5 @@
"reachable": []
},
"uptime_secs": 0,
"version": "0.79.0"
"version": "0.82.0"
}
28 changes: 14 additions & 14 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ license = "MIT"
# twcore 二进制必须和这里编译进去的协议镜像来自同一个 core 版本 —— 打包脚本正是
# 从 tw-api 锁到的 tag 去取二进制的(见 scripts/fetch-core.sh)。
[workspace.dependencies]
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.81.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.81.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.81.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.81.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.81.0" }
tw-link = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.81.0" }
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.82.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.82.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.82.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.82.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.82.0" }
tw-link = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.82.0" }

[lib]
name = "thinkwatch_lite_lib"
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ mod tests {
"Diagnostics",
"Fixture",
"Status",
// 请 core 等接替者:只在更新、重启网关时由 Rust 这边发(`handover`)
"HandoverArm",
"StartChatgptLogin",
"CancelChatgptLogin",
"StartZaiLogin",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/connection/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ mod tests {
serde_json::json!({
"api_version": tw_api::CONTROL_API_VERSION, "version": "x", "pid": 1,
"gateway_addr": gateway, "config_path": "/x", "clients": 0, "providers": 0,
"uptime_secs": 0, "in_flight": 0,
"uptime_secs": 0, "in_flight": 0, "handover": "idle", "draining": 0,
"remote_control": { "enabled": true, "addr": null, "allow_from": [], "reachable": [] },
"gateway_reachable": reachable,
})
Expand Down
29 changes: 28 additions & 1 deletion src-tauri/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ pub(crate) fn bundled_core(product: &str) -> Option<PathBuf> {
/// 让环境变量替换掉网关本体,在开发机上是便利,在用户机器上是一个口子。
pub fn locate_core(app: &tauri::AppHandle) -> anyhow::Result<PathBuf> {
if let Some(inside) = bundled_core(&app.package_info().name) {
// **Linux AppImage 从数据目录里的按版本缓存运行**:挂载点随这个进程退出而卸载,
// 交接时旧 core 还要接着跑(见 `handover::core_cache`)
#[cfg(target_os = "linux")]
if inside.exists()
&& tauri::utils::platform::bundle_type()
== Some(tauri::utils::config::BundleType::AppImage)
{
return Ok(crate::handover::core_cache::from_cache(
inside,
&app.package_info().version.to_string(),
));
}
if inside.exists() {
return Ok(inside);
}
Expand Down Expand Up @@ -238,12 +250,27 @@ pub(crate) async fn restart_gateway(app: &tauri::AppHandle) -> Out<()> {
return Err(why.clone().into());
}
if state.supervising.swap(true, Ordering::SeqCst) {
return state.supervisor.request_restart().await.map_err(text);
return restart_running(&state).await;
}
spawn_supervise(app, state.supervisor.clone(), state.supervising.clone());
Ok(())
}

/// 守护在跑时的「重新启动」:**同版本交接**(方案 R5)。请正在跑的 core 等接替者,守护起一个
/// 新的接过监听,旧的做完手上的请求再走 —— 和换版本时一样,网关不断、在跑的流不被截断。
///
/// arm 不上(安全模式里的、还在启动的、登录进行中、core 太旧)就照以前停了再起。安全模式之后
/// 配置修好了的那次自动重启也走这里:安全模式的 core 不交接,照旧停了再起
async fn restart_running(state: &AppState) -> Out<()> {
if matches!(state.supervisor.state(), CoreState::Running { .. }) {
match crate::handover::arm(state.supervisor.control(), None).await {
Ok(_) => return state.supervisor.hand_over().await.map_err(text),
Err(e) => tracing::info!("重新启动网关:core 没能等接替者,停了再起({e})"),
}
}
state.supervisor.request_restart().await.map_err(text)
}

/// 守护没在跑就接回来;在跑就什么都不做。切回本机时用:远程模式下它停了
pub(crate) fn ensure_supervising(app: &tauri::AppHandle) {
use std::sync::atomic::Ordering;
Expand Down
Loading
Loading