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
4 changes: 2 additions & 2 deletions scripts/shots/core/en/status.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"api_version": 36,
"api_version": 37,
"clients": 4,
"config_path": "",
"gateway_addr": null,
Expand All @@ -14,5 +14,5 @@
"reachable": []
},
"uptime_secs": 0,
"version": "0.60.0"
"version": "0.61.0"
}
4 changes: 2 additions & 2 deletions scripts/shots/core/zh/status.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"api_version": 36,
"api_version": 37,
"clients": 4,
"config_path": "",
"gateway_addr": null,
Expand All @@ -14,5 +14,5 @@
"reachable": []
},
"uptime_secs": 0,
"version": "0.60.0"
"version": "0.61.0"
}
2 changes: 2 additions & 0 deletions scripts/shots/mock/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export const CORE: { [N in WebviewEndpoint]: Handler<N> } = {
ConfigHistory: () => [{ version: configVersion(), at_ms: NOW - 2 * DAY, origin: "ui", bytes: 2_714, current: true }],
ConfigAt: () => ({ section: null, name: null }),
ConfigRollback: refuse,
ConfigRepairPlan: () => ({ base_version: configVersion(), fixes: [] }),
RepairConfig: refuse,
SaveListen: refuse,

History: (req) => {
Expand Down
44 changes: 22 additions & 22 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.60.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.60.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.60.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.60.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.60.0" }
tw-link = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.60.0" }
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.61.0" }
tw-types = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.61.0" }
tw-yaml = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.61.0" }
tw-guard = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.61.0" }
tw-watch = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.61.0" }
tw-link = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.61.0" }

[lib]
name = "thinkwatch_lite_lib"
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ webview_endpoints![
ConfigHistory,
ConfigAt,
ConfigRollback,
// 一键修复:修的是磁盘上那一份,界面只交版本号
ConfigRepairPlan,
RepairConfig,
SaveListen,
// 记录。搜索翻的是整个库,界面自己发起、自己翻页
History,
Expand Down
24 changes: 23 additions & 1 deletion src-tauri/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,12 @@ pub(crate) fn describe_state(s: &CoreState) -> String {
CoreState::Starting => "starting".into(),
CoreState::Running { pid } => format!("running:{pid}"),
CoreState::Restarting { attempt, in_ms } => format!("restarting:{attempt}:{in_ms}"),
CoreState::SafeMode { .. } => "safe_mode".into(),
// 控制面答应了就带上 pid:界面见到它才去连(安全模式下也能改配置、一键修复)。
// 还没答应的时候连了也是白连
CoreState::SafeMode { pid: Some(pid) } => format!("safe_mode:{pid}"),
CoreState::SafeMode { pid: None } => "safe_mode".into(),
CoreState::Stopped => "stopped".into(),
CoreState::Exited { reason } => format!("exited:{reason}"),
CoreState::Failed { reason } => format!("failed:{reason}"),
}
}
Expand Down Expand Up @@ -426,6 +430,24 @@ pub(crate) async fn bridge_events(app: tauri::AppHandle) {
if matches!(ev, tw_api::Event::EventsDropped { .. }) {
reconcile_notices(&a);
}
// **安全模式下换进了一份能用的配置**(界面里改好保存、一键修复、回滚、在
// 编辑器里改好):按正常模式重启,网关自己恢复,不用再去点「重新启动」
if matches!(ev, tw_api::Event::ConfigReloaded { .. })
&& let Some(st) = a.try_state::<AppState>()
&& !st.link.is_remote()
&& matches!(
*st.supervisor.watch().borrow(),
CoreState::SafeMode { pid: Some(_) }
)
{
tracing::info!("安全模式下配置已能读进来,按正常模式重启 core");
let app = a.clone();
tauri::async_runtime::spawn(async move {
if let Err(e) = restart_gateway(&app).await {
tracing::warn!("安全模式之后重启 core 没成:{e:?}");
}
});
}
let _ = a.emit("core-event", &ev);
},
);
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/menubar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async fn collect(app: &tauri::AppHandle, state: &AppState, credits: &mut Credits
CoreState::Running { .. } => Gateway::Running,
CoreState::Starting | CoreState::Restarting { .. } => Gateway::Starting,
CoreState::SafeMode { .. } => Gateway::SafeMode,
CoreState::Failed { .. } => Gateway::Failed,
CoreState::Failed { .. } | CoreState::Exited { .. } => Gateway::Failed,
CoreState::Stopped => Gateway::Stopped,
};
let notices = app.try_state::<Arc<notices::Notices>>();
Expand Down
18 changes: 18 additions & 0 deletions src-tauri/src/notices/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,24 @@ pub fn from_core_state(state: &crate::supervisor::CoreState) -> Vec<Signal> {
.now()
.suppressing(suppresses("gateway")),
],
// 程序本身运行不了、或者安全模式里也起不来:不会自己好,转发已经停了
CoreState::Exited { .. } => vec![
Signal::raised(
"gateway",
Level::Critical,
tr!("网关无法启动", "Gateway Cannot Start"),
)
.body(
tr!(
"core 启动后退出,转发已停止。打开窗口可以查看原因并重试。",
"core exited right after starting, so forwarding has stopped. Open the window to see why and try again."
)
.to_string(),
)
.view(SETTINGS)
.now()
.suppressing(suppresses("gateway")),
],
// 程序本身运行不了:不会自己好,转发已经停了
CoreState::Failed { .. } => vec![
Signal::raised(
Expand Down
Loading
Loading