Merge pull request #7 from ghillb/feat/configure-notification-messages

feat(cli): add notification messages to configure wizard
This commit is contained in:
Leonardo Trapani
2026-01-02 22:49:01 +01:00
committed by GitHub
+146 -5
View File
@@ -355,6 +355,105 @@ func runInteractiveConfig() error {
break
}
// Ask if user wants to customize notification messages
fmt.Print("Customize notification messages? [y/n] (default: n): ")
if scanner.Scan() {
input := strings.TrimSpace(strings.ToLower(scanner.Text()))
if input == "y" || input == "yes" {
fmt.Println()
// Get current/default values for display
recTitle, recBody := cfg.GetRecordingStarted()
transTitle, transBody := cfg.GetTranscribing()
reloadTitle, reloadBody := cfg.GetConfigReloaded()
cancelTitle, cancelBody := cfg.GetOperationCancelled()
abortRecBody := cfg.GetRecordingAborted()
abortInjBody := cfg.GetInjectionAborted()
// Recording Started
fmt.Println(" Recording Started notification:")
fmt.Printf(" Title (current: %s): ", recTitle)
if scanner.Scan() {
if t := strings.TrimSpace(scanner.Text()); t != "" {
cfg.Notifications.Messages.RecordingStarted.Title = t
}
}
fmt.Printf(" Body (current: %s): ", recBody)
if scanner.Scan() {
if b := strings.TrimSpace(scanner.Text()); b != "" {
cfg.Notifications.Messages.RecordingStarted.Body = b
}
}
fmt.Println()
// Transcribing
fmt.Println(" Transcribing notification:")
fmt.Printf(" Title (current: %s): ", transTitle)
if scanner.Scan() {
if t := strings.TrimSpace(scanner.Text()); t != "" {
cfg.Notifications.Messages.Transcribing.Title = t
}
}
fmt.Printf(" Body (current: %s): ", transBody)
if scanner.Scan() {
if b := strings.TrimSpace(scanner.Text()); b != "" {
cfg.Notifications.Messages.Transcribing.Body = b
}
}
fmt.Println()
// Config Reloaded
fmt.Println(" Config Reloaded notification:")
fmt.Printf(" Title (current: %s): ", reloadTitle)
if scanner.Scan() {
if t := strings.TrimSpace(scanner.Text()); t != "" {
cfg.Notifications.Messages.ConfigReloaded.Title = t
}
}
fmt.Printf(" Body (current: %s): ", reloadBody)
if scanner.Scan() {
if b := strings.TrimSpace(scanner.Text()); b != "" {
cfg.Notifications.Messages.ConfigReloaded.Body = b
}
}
fmt.Println()
// Operation Cancelled
fmt.Println(" Operation Cancelled notification:")
fmt.Printf(" Title (current: %s): ", cancelTitle)
if scanner.Scan() {
if t := strings.TrimSpace(scanner.Text()); t != "" {
cfg.Notifications.Messages.OperationCancelled.Title = t
}
}
fmt.Printf(" Body (current: %s): ", cancelBody)
if scanner.Scan() {
if b := strings.TrimSpace(scanner.Text()); b != "" {
cfg.Notifications.Messages.OperationCancelled.Body = b
}
}
fmt.Println()
// Recording Aborted (body only)
fmt.Println(" Recording Aborted notification:")
fmt.Printf(" Body (current: %s): ", abortRecBody)
if scanner.Scan() {
if b := strings.TrimSpace(scanner.Text()); b != "" {
cfg.Notifications.Messages.RecordingAborted.Body = b
}
}
fmt.Println()
// Injection Aborted (body only)
fmt.Println(" Injection Aborted notification:")
fmt.Printf(" Body (current: %s): ", abortInjBody)
if scanner.Scan() {
if b := strings.TrimSpace(scanner.Text()); b != "" {
cfg.Notifications.Messages.InjectionAborted.Body = b
}
}
}
}
fmt.Println()
// Configure recording timeout
@@ -492,11 +591,6 @@ func saveConfig(cfg *config.Config) error {
wtype_timeout = "%s" # Timeout for wtype commands
clipboard_timeout = "%s" # Timeout for clipboard operations
# Desktop Notification Configuration
[notifications]
enabled = %v # Enable desktop notifications
type = "%s" # Notification type ("desktop", "log", "none")
# Backend explanations:
# - "ydotool": Uses ydotool (requires ydotoold daemon running). Most compatible with Chromium/Electron apps.
# - "wtype": Uses wtype for Wayland. May have issues with some Chromium-based apps.
@@ -514,6 +608,11 @@ func saveConfig(cfg *config.Config) error {
# Language codes: Use empty string ("") for automatic detection, or specific codes like:
# "en" (English), "it" (Italian), "es" (Spanish), "fr" (French), "de" (German), etc.
# For groq-translation, the language field hints at the source audio language for better accuracy.
# Desktop Notification Configuration
[notifications]
enabled = %v # Enable desktop notifications
type = "%s" # Notification type ("desktop", "log", "none")
`,
cfg.Recording.SampleRate,
cfg.Recording.Channels,
@@ -538,5 +637,47 @@ func saveConfig(cfg *config.Config) error {
return fmt.Errorf("failed to write config content: %w", err)
}
// Write notification messages if any are configured
msgs := cfg.Notifications.Messages
if hasCustomMessages(msgs) {
messagesContent := "\n [notifications.messages]\n"
if msgs.RecordingStarted.Title != "" || msgs.RecordingStarted.Body != "" {
messagesContent += fmt.Sprintf(" [notifications.messages.recording_started]\n title = %q\n body = %q\n",
msgs.RecordingStarted.Title, msgs.RecordingStarted.Body)
}
if msgs.Transcribing.Title != "" || msgs.Transcribing.Body != "" {
messagesContent += fmt.Sprintf(" [notifications.messages.transcribing]\n title = %q\n body = %q\n",
msgs.Transcribing.Title, msgs.Transcribing.Body)
}
if msgs.ConfigReloaded.Title != "" || msgs.ConfigReloaded.Body != "" {
messagesContent += fmt.Sprintf(" [notifications.messages.config_reloaded]\n title = %q\n body = %q\n",
msgs.ConfigReloaded.Title, msgs.ConfigReloaded.Body)
}
if msgs.OperationCancelled.Title != "" || msgs.OperationCancelled.Body != "" {
messagesContent += fmt.Sprintf(" [notifications.messages.operation_cancelled]\n title = %q\n body = %q\n",
msgs.OperationCancelled.Title, msgs.OperationCancelled.Body)
}
if msgs.RecordingAborted.Body != "" {
messagesContent += fmt.Sprintf(" [notifications.messages.recording_aborted]\n body = %q\n",
msgs.RecordingAborted.Body)
}
if msgs.InjectionAborted.Body != "" {
messagesContent += fmt.Sprintf(" [notifications.messages.injection_aborted]\n body = %q\n",
msgs.InjectionAborted.Body)
}
if _, err := file.WriteString(messagesContent); err != nil {
return fmt.Errorf("failed to write messages config: %w", err)
}
}
return nil
}
func hasCustomMessages(msgs config.MessagesConfig) bool {
return msgs.RecordingStarted.Title != "" || msgs.RecordingStarted.Body != "" ||
msgs.Transcribing.Title != "" || msgs.Transcribing.Body != "" ||
msgs.ConfigReloaded.Title != "" || msgs.ConfigReloaded.Body != "" ||
msgs.OperationCancelled.Title != "" || msgs.OperationCancelled.Body != "" ||
msgs.RecordingAborted.Body != "" ||
msgs.InjectionAborted.Body != ""
}