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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ step-by-step instructions.

The menu bar shows today's cost and the output rate; for a subscription account
it shows the quota used and the time until it resets instead. System
notifications report when the gateway stops forwarding, an upstream becomes
unreachable, a subscription quota runs out or a credential stops working; each
kind can be set to a system notification, in-app only, or off.
notifications report when the gateway stops forwarding, a subscription quota
runs out or a credential stops working; an unreachable upstream, which a
fallback usually covers, is only listed in the app. Notices as a whole can be
set to system notifications, in-app only, or off.

<p>
<picture>
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ Cursor、Continue 与 Gemini CLI 提供逐步的手动配置说明。
### 菜单栏与系统通知

菜单栏常驻显示今日费用与输出速率;使用订阅账号时改为显示额度用量与重置倒计时。
网关停止转发、上游无法连接、订阅额度用完、凭据失效等情况会发送系统通知,每一类
都可以设为系统通知、仅在应用内显示或关闭。
网关停止转发、订阅额度用完、凭据失效等情况会发送系统通知;上游无法连接多半有回退
接住,只记录在应用内。提醒可以整体设为系统通知、仅在应用内显示或关闭。

<p>
<picture>
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tauri-plugin-deep-link = "2"
# 编出来的东西不一样;而更要紧的是,打进 `.app` 的那个 twcore 二进制
# 必须和这里编译进去的协议镜像来自同一个 core 版本 —— 打包脚本正是从
# 这个 tag 去取二进制的(见 scripts/fetch-core.sh)。
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.15.0" }
tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.16.0" }

anyhow = "1"
libc = "0.2"
Expand Down
48 changes: 17 additions & 31 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,8 +1467,8 @@ pub fn run() {
upstreams::test_proxy,
notices_list,
dismiss_notice,
notice_prefs,
set_notice_pref,
notice_mode,
set_notice_mode,
take_pending_view,
keys::list_keys,
keys::create_key,
Expand Down Expand Up @@ -1575,6 +1575,7 @@ pub fn run() {
system,
],
Some(data_dir()),
saved.notices,
);
app.manage(notices.clone());
app.manage(AppState {
Expand Down Expand Up @@ -1886,44 +1887,29 @@ fn take_pending_view() -> Option<String> {
notices::take_pending_view()
}

/// 设置页上的一行:一类提醒,和它现在怎么对待
#[derive(serde::Serialize)]
struct NoticePref {
category: notices::Category,
label: &'static str,
mode: notices::Mode,
}

fn notice_prefs_view(n: &notices::Notices) -> Vec<NoticePref> {
n.modes()
.into_iter()
.map(|(category, mode)| NoticePref {
category,
label: category.label(),
mode,
})
.collect()
}

/// 提醒现在是哪一档
#[tauri::command]
fn notice_prefs(notices: tauri::State<'_, Arc<notices::Notices>>) -> Vec<NoticePref> {
notice_prefs_view(&notices)
fn notice_mode(notices: tauri::State<'_, Arc<notices::Notices>>) -> notices::Mode {
notices.mode()
}

/// 改一类提醒的对待方式。**返回改完之后的全部**,界面以它为准
/// 换一档。**先存盘再生效**:存不进去的话,界面弹回去,总线也还是原来那一档。
/// 工具栏的铃铛听 `notice-mode-changed` —— 关掉之后它不该还在那儿
#[tauri::command]
fn set_notice_pref(
fn set_notice_mode(
app: tauri::AppHandle,
notices: tauri::State<'_, Arc<notices::Notices>>,
category: notices::Category,
mode: notices::Mode,
) -> Result<Vec<NoticePref>, String> {
notices.set_mode(category, mode).map_err(|e| {
) -> Result<notices::Mode, String> {
prefs::update(&data_dir(), |p| p.notices = mode).map_err(|e| {
tr!(
format!("无法保存设置:{e}"),
format!("The setting could not be saved: {e}")
format!("无法保存设置:{e:#}"),
format!("The setting could not be saved: {e:#}")
)
})?;
Ok(notice_prefs_view(&notices))
notices.set_mode(mode);
let _ = app.emit("notice-mode-changed", mode);
Ok(mode)
}

/// 第一次开机自启之后提示一次「我在菜单栏这儿」,之后永不再弹。
Expand Down
13 changes: 5 additions & 8 deletions src-tauri/src/notices/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Sink for NativeSink {
notice.key.clone(),
notice.title.clone(),
notice.body.clone(),
thread_of(notice),
thread_of(&notice.key),
false,
);
}
Expand All @@ -58,7 +58,7 @@ impl Sink for NativeSink {
notice.key.clone(),
title,
notice.body.clone(),
thread_of(notice),
thread_of(&notice.key),
true,
);
}
Expand All @@ -68,10 +68,7 @@ impl Sink for NativeSink {
}
}

/// 同一类的归在一起:用类别的标识做 thread
fn thread_of(notice: &Notice) -> String {
serde_json::to_value(notice.category)
.ok()
.and_then(|v| v.as_str().map(str::to_string))
.unwrap_or_default()
/// 同一种的归在一起:用键的种类(冒号前那段)做 thread
fn thread_of(key: &str) -> String {
key.split(':').next().unwrap_or(key).to_string()
}
Loading
Loading