package action import "context" // ruleNotifyKey 是规则级"是否显示通知"开关在 context 中的键。 // // 规则引擎在派发动作前把当前规则的 notify 写入 context:动作实现不 // 直接依赖 config.Rule,异步路径(音量媒体键读回、亮度合并队列)也能 // 在启动 goroutine 前捕获该值,避免 context 取消后读不到。 type ruleNotifyKey struct{} // WithRuleNotify 把规则级通知开关写入 context。 func WithRuleNotify(ctx context.Context, notify bool) context.Context { return context.WithValue(ctx, ruleNotifyKey{}, notify) } // RuleNotify 读取规则级通知开关;未设置时默认允许通知。 func RuleNotify(ctx context.Context) bool { if ctx == nil { return true } if v, ok := ctx.Value(ruleNotifyKey{}).(bool); ok { return v } return true } // NotificationsAllowed 返回当前动作是否允许弹桌面通知: // 全局总开关(global.notify)与规则级开关同时开启才允许。 // // 调节提示条(internal/osd)不经过这里,始终显示;这里只控制右下角 // 系统 Toast,包括自动调节通知和显式的 show_notification 动作。 func NotificationsAllowed(ctx context.Context) bool { return toastEnabled.Load() && RuleNotify(ctx) }