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
9 changes: 9 additions & 0 deletions desktop/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ fn main() {

// 为应用自定义命令生成 ACL 权限(allow-<command>):
// capability 中引用的每个自定义命令都必须在此登记。
//
// 新增一条命令要同时动三处:main.rs 的 invoke_handler、这里、以及
// tauri.conf.json 里**用得到它的每个** capability。两个方向的失手代价
// 不对称:capability 里名字写错是编译期硬错(UnknownPermission),而漏加
// capability 只在运行期被 ACL 拒掉——UI 侧若把 invoke 的报错 catch 掉,
// 症状就是"按钮点了没反应",编译与测试全绿。桌宠页与主窗口是两个
// capability,只给一边放行同样是这个症状。
tauri_build::try_build(
tauri_build::Attributes::new().app_manifest(
tauri_build::AppManifest::new().commands(&[
Expand All @@ -22,6 +29,8 @@ fn main() {
"host_info",
"show_main",
"pet_native_render",
"sound_enabled",
"set_sound_enabled",
"update_check",
"update_install",
"open_extension_dir",
Expand Down
5 changes: 4 additions & 1 deletion desktop/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"allow-save-config",
"allow-take-ui-intent",
"allow-host-info",
"allow-sound-enabled",
"allow-set-sound-enabled",
"allow-update-check",
"allow-update-install",
"allow-open-extension-dir",
Expand Down Expand Up @@ -123,7 +125,8 @@
"core:window:allow-outer-position",
"allow-sessions-list",
"allow-show-main",
"allow-pet-native-render"
"allow-pet-native-render",
"allow-sound-enabled"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion desktop/ui/public/pet.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
// 每次启动仍要挨一声。取不到(命令异常)按默认"开"继续,不拖住状态渲染。
invoke('sound_enabled')
.then((on) => { soundEnabled = on !== false; })
.catch(() => {})
.catch((e) => console.warn('[pet] 读取提示音开关失败,按开处理', e))
.then(snapshot);

// ---- 交互:拖动(位移阈值)与点击(唤回主窗口) ----
Expand Down
12 changes: 9 additions & 3 deletions desktop/ui/src/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,22 @@ export function SettingsView({
let alive = true;
void getSoundEnabled().then((on) => {
if (alive) setSoundOn(on);
}).catch(() => {});
}).catch((e) => console.warn("[settings] 读取提示音开关失败", e));
const off = onHostEvent<boolean>("sound-enabled", (on) => setSoundOn(on !== false));
return () => {
alive = false;
off();
};
}, []);
const pickSound = (next: boolean) => {
setSoundOn(next); // 乐观置位:壳广播会回来盖一次,失败则由它纠回
void setSoundEnabled(next).catch(() => void getSoundEnabled().then(setSoundOn).catch(() => {}));
setSoundOn(next); // 乐观置位:壳广播会回来盖一次,失败则回滚并报错
setErr("");
void setSoundEnabled(next).catch((e) => {
// 静默回滚会让按钮看着像坏了(命令没在 ACL 里放行就是这个症状):
// 把壳的原话摆出来,下次同类故障一眼可诊
setSoundOn(!next);
setErr("提示音开关切换失败: " + (e instanceof Error ? e.message : String(e)));
});
};

// 登录态由 Shell 持有:账号页 BaizhiCard 与模型/MCP 页的引导条共用
Expand Down
Loading