on main help sign in
chore(ui): add command palette entry for toggling notifications (#2402)
ca32607Christian Rocha
internal/ui/dialog/actions.go+8−7
@@ -44,13 +44,14 @@ type ActionSelectModel struct {
44
44
45// Messages for commands
45// Messages for commands
46type (
46type (
47− ActionNewSession struct{}
47+ ActionNewSession struct{}
48− ActionToggleHelp struct{}
48+ ActionToggleHelp struct{}
49− ActionToggleCompactMode struct{}
49+ ActionToggleCompactMode struct{}
50− ActionToggleThinking struct{}
50+ ActionToggleThinking struct{}
51− ActionTogglePills struct{}
51+ ActionTogglePills struct{}
52− ActionExternalEditor struct{}
52+ ActionExternalEditor struct{}
53− ActionToggleYoloMode struct{}
53+ ActionToggleYoloMode struct{}
54+ ActionToggleNotifications struct{}
54 // ActionInitializeProject is a message to initialize a project.
55 // ActionInitializeProject is a message to initialize a project.
55 ActionInitializeProject struct{}
56 ActionInitializeProject struct{}
56 ActionSummarize struct {
57 ActionSummarize struct {
internal/ui/dialog/commands.go+14−2
@@ -437,8 +437,11 @@ func (c *Commands) defaultCommands() []*CommandItem {
437 }
437 }
438 }
438 }
439
439
440− // Add external editor command if $EDITOR is available
440+ // Add external editor command if $EDITOR is available.
441+ //
441− // TODO: Use [tea.EnvMsg] to get environment variable instead of os.Getenv
442+ // TODO: Use [tea.EnvMsg] to get environment variable instead of os.Getenv;
443+ // because os.Getenv does IO is breaks the TEA paradigm and is generally an
444+ // antipattern.
442 if os.Getenv("EDITOR") != "" {
445 if os.Getenv("EDITOR") != "" {
443 commands = append(commands, NewCommandItem(c.com.Styles, "open_external_editor", "Open External Editor", "ctrl+o", ActionExternalEditor{}))
446 commands = append(commands, NewCommandItem(c.com.Styles, "open_external_editor", "Open External Editor", "ctrl+o", ActionExternalEditor{}))
444 }
447 }
@@ -456,6 +459,15 @@ func (c *Commands) defaultCommands() []*CommandItem {
456 commands = append(commands, NewCommandItem(c.com.Styles, "toggle_pills", label, "ctrl+t", ActionTogglePills{}))
459 commands = append(commands, NewCommandItem(c.com.Styles, "toggle_pills", label, "ctrl+t", ActionTogglePills{}))
457 }
460 }
458
461
462+ // Add a command for toggling notifications.
463+ cfg = c.com.Config()
464+ notificationsDisabled := cfg != nil && cfg.Options != nil && cfg.Options.DisableNotifications
465+ notificationLabel := "Disable Notifications"
466+ if notificationsDisabled {
467+ notificationLabel = "Enable Notifications"
468+ }
469+ commands = append(commands, NewCommandItem(c.com.Styles, "toggle_notifications", notificationLabel, "", ActionToggleNotifications{}))
470+
459 commands = append(commands,
471 commands = append(commands,
460 NewCommandItem(c.com.Styles, "toggle_yolo", "Toggle Yolo Mode", "", ActionToggleYoloMode{}),
472 NewCommandItem(c.com.Styles, "toggle_yolo", "Toggle Yolo Mode", "", ActionToggleYoloMode{}),
461 NewCommandItem(c.com.Styles, "toggle_help", "Toggle Help", "ctrl+g", ActionToggleHelp{}),
473 NewCommandItem(c.com.Styles, "toggle_help", "Toggle Help", "ctrl+g", ActionToggleHelp{}),
internal/ui/model/ui.go+19−3
@@ -1229,24 +1229,40 @@ func (m *UI) handleDialogMsg(msg tea.Msg) tea.Cmd {
1229 cmds = append(cmds, msg.Cmd)
1229 cmds = append(cmds, msg.Cmd)
1230 }
1230 }
1231
1231
1232− // Session dialog messages
1232+ // Session dialog messages.
1233 case dialog.ActionSelectSession:
1233 case dialog.ActionSelectSession:
1234 m.dialog.CloseDialog(dialog.SessionsID)
1234 m.dialog.CloseDialog(dialog.SessionsID)
1235 cmds = append(cmds, m.loadSession(msg.Session.ID))
1235 cmds = append(cmds, m.loadSession(msg.Session.ID))
1236
1236
1237− // Open dialog message
1237+ // Open dialog message.
1238 case dialog.ActionOpenDialog:
1238 case dialog.ActionOpenDialog:
1239 m.dialog.CloseDialog(dialog.CommandsID)
1239 m.dialog.CloseDialog(dialog.CommandsID)
1240 if cmd := m.openDialog(msg.DialogID); cmd != nil {
1240 if cmd := m.openDialog(msg.DialogID); cmd != nil {
1241 cmds = append(cmds, cmd)
1241 cmds = append(cmds, cmd)
1242 }
1242 }
1243
1243
1244− // Command dialog messages
1244+ // Command dialog messages.
1245 case dialog.ActionToggleYoloMode:
1245 case dialog.ActionToggleYoloMode:
1246 yolo := !m.com.App.Permissions.SkipRequests()
1246 yolo := !m.com.App.Permissions.SkipRequests()
1247 m.com.App.Permissions.SetSkipRequests(yolo)
1247 m.com.App.Permissions.SetSkipRequests(yolo)
1248 m.setEditorPrompt(yolo)
1248 m.setEditorPrompt(yolo)
1249 m.dialog.CloseDialog(dialog.CommandsID)
1249 m.dialog.CloseDialog(dialog.CommandsID)
1250+ case dialog.ActionToggleNotifications:
1251+ cfg := m.com.Config()
1252+ if cfg != nil && cfg.Options != nil {
1253+ disabled := !cfg.Options.DisableNotifications
1254+ cfg.Options.DisableNotifications = disabled
1255+ if err := m.com.Store().SetConfigField(config.ScopeGlobal, "options.disable_notifications", disabled); err != nil {
1256+ cmds = append(cmds, util.ReportError(err))
1257+ } else {
1258+ status := "enabled"
1259+ if disabled {
1260+ status = "disabled"
1261+ }
1262+ cmds = append(cmds, util.CmdHandler(util.NewInfoMsg("Notifications "+status)))
1263+ }
1264+ }
1265+ m.dialog.CloseDialog(dialog.CommandsID)
1250 case dialog.ActionNewSession:
1266 case dialog.ActionNewSession:
1251 if m.isAgentBusy() {
1267 if m.isAgentBusy() {
1252 cmds = append(cmds, util.ReportWarn("Agent is busy, please wait before starting a new session..."))
1268 cmds = append(cmds, util.ReportWarn("Agent is busy, please wait before starting a new session..."))