diff --git a/internal/ui/dialog/actions.go b/internal/ui/dialog/actions.go index 79e11a64bec50937b36a198b6096f83273041142..8fea38fb75d8e2eca73e4b6693f6469fc1e743d6 100644 --- a/internal/ui/dialog/actions.go +++ b/internal/ui/dialog/actions.go @@ -44,13 +44,14 @@ type ActionSelectModel struct { // Messages for commands type ( - ActionNewSession struct{} - ActionToggleHelp struct{} - ActionToggleCompactMode struct{} - ActionToggleThinking struct{} - ActionTogglePills struct{} - ActionExternalEditor struct{} - ActionToggleYoloMode struct{} + ActionNewSession struct{} + ActionToggleHelp struct{} + ActionToggleCompactMode struct{} + ActionToggleThinking struct{} + ActionTogglePills struct{} + ActionExternalEditor struct{} + ActionToggleYoloMode struct{} + ActionToggleNotifications struct{} // ActionInitializeProject is a message to initialize a project. ActionInitializeProject struct{} ActionSummarize struct { diff --git a/internal/ui/dialog/commands.go b/internal/ui/dialog/commands.go index e74d92775de24ee2672b251005e1e6d501e35aab..14ffaf3aedc11d9fefb1b4932664c5d95d34e413 100644 --- a/internal/ui/dialog/commands.go +++ b/internal/ui/dialog/commands.go @@ -437,8 +437,11 @@ func (c *Commands) defaultCommands() []*CommandItem { } } - // Add external editor command if $EDITOR is available - // TODO: Use [tea.EnvMsg] to get environment variable instead of os.Getenv + // Add external editor command if $EDITOR is available. + // + // TODO: Use [tea.EnvMsg] to get environment variable instead of os.Getenv; + // because os.Getenv does IO is breaks the TEA paradigm and is generally an + // antipattern. if os.Getenv("EDITOR") != "" { commands = append(commands, NewCommandItem(c.com.Styles, "open_external_editor", "Open External Editor", "ctrl+o", ActionExternalEditor{})) } @@ -456,6 +459,15 @@ func (c *Commands) defaultCommands() []*CommandItem { commands = append(commands, NewCommandItem(c.com.Styles, "toggle_pills", label, "ctrl+t", ActionTogglePills{})) } + // Add a command for toggling notifications. + cfg = c.com.Config() + notificationsDisabled := cfg != nil && cfg.Options != nil && cfg.Options.DisableNotifications + notificationLabel := "Disable Notifications" + if notificationsDisabled { + notificationLabel = "Enable Notifications" + } + commands = append(commands, NewCommandItem(c.com.Styles, "toggle_notifications", notificationLabel, "", ActionToggleNotifications{})) + commands = append(commands, NewCommandItem(c.com.Styles, "toggle_yolo", "Toggle Yolo Mode", "", ActionToggleYoloMode{}), NewCommandItem(c.com.Styles, "toggle_help", "Toggle Help", "ctrl+g", ActionToggleHelp{}), diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 66d57321824833e91b78539357d55013e4322e87..8bb398f387929dd30b1df1e6e27d2c72097797b8 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -1229,24 +1229,40 @@ func (m *UI) handleDialogMsg(msg tea.Msg) tea.Cmd { cmds = append(cmds, msg.Cmd) } - // Session dialog messages + // Session dialog messages. case dialog.ActionSelectSession: m.dialog.CloseDialog(dialog.SessionsID) cmds = append(cmds, m.loadSession(msg.Session.ID)) - // Open dialog message + // Open dialog message. case dialog.ActionOpenDialog: m.dialog.CloseDialog(dialog.CommandsID) if cmd := m.openDialog(msg.DialogID); cmd != nil { cmds = append(cmds, cmd) } - // Command dialog messages + // Command dialog messages. case dialog.ActionToggleYoloMode: yolo := !m.com.App.Permissions.SkipRequests() m.com.App.Permissions.SetSkipRequests(yolo) m.setEditorPrompt(yolo) m.dialog.CloseDialog(dialog.CommandsID) + case dialog.ActionToggleNotifications: + cfg := m.com.Config() + if cfg != nil && cfg.Options != nil { + disabled := !cfg.Options.DisableNotifications + cfg.Options.DisableNotifications = disabled + if err := m.com.Store().SetConfigField(config.ScopeGlobal, "options.disable_notifications", disabled); err != nil { + cmds = append(cmds, util.ReportError(err)) + } else { + status := "enabled" + if disabled { + status = "disabled" + } + cmds = append(cmds, util.CmdHandler(util.NewInfoMsg("Notifications "+status))) + } + } + m.dialog.CloseDialog(dialog.CommandsID) case dialog.ActionNewSession: if m.isAgentBusy() { cmds = append(cmds, util.ReportWarn("Agent is busy, please wait before starting a new session..."))