Commit 92f9c5fad6

92f9c5fad6335e1b72d8820e800ec948904e285a

parent: 402025f4eb

Unsigned

Wraient <wraient.911@gmail.com> · 2026-07-22 20:29 UTC

Fix: show update prompt in Rofi, local remind times, no notify spam

Rofi mode was turning every CurdOut into notify-send (dozens of toasts).
Update and episode-recovery prompts now use Rofi -mesg for details.
Remind-later times display in the local timezone.

Layout: unified · split

internal/provider_mapping.go +11 −2
@@ -866,9 +866,18 @@ func promptEpisodeLinkFailureRecovery(config *CurdConfig, anime *Anime, lastErr
866 preferredMode = normalizeTranslationType(config.SubOrDub) 866 preferredMode = normalizeTranslationType(config.SubOrDub)
867 } 867 }
868 868
869 CurdOut(episodeLinkFailureDiagnosis(config, anime, lastErr)) 869 diagnosis := episodeLinkFailureDiagnosis(config, anime, lastErr)
870 options := episodeLinkFailureRecoveryOptions(preferredMode, includeAudio)
870 871
871 selected, err := promptSelect(episodeLinkFailureRecoveryOptions(preferredMode, includeAudio)) 872 var selected SelectionOption
873 var err error
874 if config != nil && config.RofiSelection {
875 // Put diagnosis in Rofi -mesg — avoid one notify-send per CurdOut line.
876 selected, err = RofiSelectWithMessage(options, false, "Playback recovery", diagnosis)
877 } else {
878 fmt.Println(diagnosis)
879 selected, err = promptSelect(options)
880 }
872 if err != nil { 881 if err != nil {
873 return "back" 882 return "back"
874 } 883 }
internal/selection_menu.go +18 −1
@@ -669,13 +669,30 @@ func RofiSelect(options []SelectionOption, isHomeMenu bool) (SelectionOption, er
669 return RofiSelectWithRefresh(options, isHomeMenu, nil) 669 return RofiSelectWithRefresh(options, isHomeMenu, nil)
670} 670}
671 671
672// RofiSelectWithMessage shows a Rofi dmenu with an optional -mesg banner (for
673// release notes, error diagnosis, etc.) so callers do not need notify-send spam.
674func RofiSelectWithMessage(options []SelectionOption, isHomeMenu bool, prompt, message string) (SelectionOption, error) {
675 return rofiSelectInternal(options, isHomeMenu, nil, prompt, message)
676}
677
672func RofiSelectWithRefresh(options []SelectionOption, isHomeMenu bool, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) { 678func RofiSelectWithRefresh(options []SelectionOption, isHomeMenu bool, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) {
679 return rofiSelectInternal(options, isHomeMenu, refreshConfig, "Select", "")
680}
681
682func rofiSelectInternal(options []SelectionOption, isHomeMenu bool, refreshConfig *SelectionRefreshConfig, prompt, message string) (SelectionOption, error) {
673 currentOptions := options 683 currentOptions := options
684 if strings.TrimSpace(prompt) == "" {
685 prompt = "Select"
686 }
674 687
675 for { 688 for {
676 optionsString := buildRofiOptionsString(currentOptions, isHomeMenu) 689 optionsString := buildRofiOptionsString(currentOptions, isHomeMenu)
677 configPath := filepath.Join(GetStoragePath(), "selectanime.rasi") 690 configPath := filepath.Join(GetStoragePath(), "selectanime.rasi")
678 cmd := exec.Command("rofi", "-dmenu", "-theme", configPath, "-i", "-p", "Select") 691 args := []string{"-dmenu", "-theme", configPath, "-i", "-p", prompt}
692 if msg := strings.TrimSpace(message); msg != "" {
693 args = append(args, "-mesg", msg)
694 }
695 cmd := exec.Command("rofi", args...)
679 cmd.Stdin = strings.NewReader(optionsString) 696 cmd.Stdin = strings.NewReader(optionsString)
680 var stdout, stderr bytes.Buffer 697 var stdout, stderr bytes.Buffer
681 cmd.Stdout = &stdout 698 cmd.Stdout = &stdout
internal/update.go +70 −24
@@ -268,6 +268,51 @@ func pendingUpdateShouldPrompt(config *CurdConfig, currentVersion string, state
268 return true 268 return true
269} 269}
270 270
271func formatLocalTime(t time.Time) string {
272 return t.In(time.Local).Format("Mon Jan 2 2006, 3:04 PM MST")
273}
274
275func buildUpdatePromptMessage(currentVersion string, state updatePendingState) (prompt, message string) {
276 from := normalizeReleaseVersion(currentVersion)
277 to := normalizeReleaseVersion(state.LatestVersion)
278 prompt = fmt.Sprintf("Update %s → %s", from, to)
279
280 var b strings.Builder
281 if state.ReleaseName != "" {
282 fmt.Fprintf(&b, "%s\n", state.ReleaseName)
283 }
284 fmt.Fprintf(&b, "Current: %s Latest: %s\n", from, to)
285 if state.HTMLURL != "" {
286 fmt.Fprintf(&b, "%s\n", state.HTMLURL)
287 }
288 b.WriteString("\n")
289 b.WriteString(state.ReleaseNotes)
290 message = strings.TrimSpace(b.String())
291 // Rofi -mesg stays readable; keep a hard cap.
292 if runes := []rune(message); len(runes) > maxReleaseNotesRunes {
293 message = string(runes[:maxReleaseNotesRunes]) + "\n… (truncated)"
294 }
295 return prompt, message
296}
297
298// updateUserMessage prints a single status line. With Rofi mode, CurdOut becomes
299// notify-send — so we only send one short notification (or log) for status.
300func updateUserMessage(config *CurdConfig, msg string) {
301 msg = strings.TrimSpace(msg)
302 if msg == "" {
303 return
304 }
305 Log(msg)
306 if config != nil && config.RofiSelection {
307 // One short desktop notification, not a barrage of CurdOut lines.
308 _ = exec.Command("notify-send", "-a", "Curd",
309 "-h", "string:x-canonical-private-synchronous:curd-update",
310 "Curd", msg).Run()
311 return
312 }
313 fmt.Println(msg)
314}
315
271// HandlePendingUpdatePrompt shows a previously detected update (from idle check). 316// HandlePendingUpdatePrompt shows a previously detected update (from idle check).
272// Returns true if the caller should exit (user updated or chose to quit the session). 317// Returns true if the caller should exit (user updated or chose to quit the session).
273func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool { 318func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
@@ -279,63 +324,64 @@ func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
279 return false 324 return false
280 } 325 }
281 326
282 CurdOut("") 327 options := []SelectionOption{
283 CurdOut(fmt.Sprintf("Update available: %s → %s", normalizeReleaseVersion(currentVersion), state.LatestVersion))
284 if state.ReleaseName != "" {
285 CurdOut(state.ReleaseName)
286 }
287 if state.HTMLURL != "" {
288 CurdOut(state.HTMLURL)
289 }
290 CurdOut("")
291 CurdOut("Release notes:")
292 CurdOut(state.ReleaseNotes)
293 CurdOut("")
294
295 selected, err := promptSelect([]SelectionOption{
296 {Key: "update", Label: "Update now"}, 328 {Key: "update", Label: "Update now"},
297 {Key: "later", Label: "Remind me later"}, 329 {Key: "later", Label: "Remind me later"},
298 {Key: "skip", Label: "Skip this version"}, 330 {Key: "skip", Label: "Skip this version"},
299 {Key: "disable", Label: "Turn off automatic update checks"}, 331 {Key: "disable", Label: "Turn off automatic update checks"},
300 {Key: "continue", Label: "Continue without updating"}, 332 {Key: "continue", Label: "Continue without updating"},
301 }) 333 }
334 prompt, message := buildUpdatePromptMessage(currentVersion, state)
335
336 var selected SelectionOption
337 var err error
338 if config.RofiSelection {
339 // All details go in Rofi -mesg; zero notify-send spam for notes.
340 selected, err = RofiSelectWithMessage(options, false, prompt, message)
341 } else {
342 fmt.Println(prompt)
343 fmt.Println(message)
344 fmt.Println()
345 selected, err = promptSelect(options)
346 }
302 if err != nil || selected.Key == "-1" || selected.Key == "-2" || selected.Key == "continue" || selected.Key == "" { 347 if err != nil || selected.Key == "-1" || selected.Key == "-2" || selected.Key == "continue" || selected.Key == "" {
303 return false 348 return false
304 } 349 }
305 350
306 switch selected.Key { 351 switch selected.Key {
307 case "update": 352 case "update":
308 CurdOut("Downloading and installing update…") 353 updateUserMessage(config, "Downloading and installing update…")
309 if err := UpdateCurd(defaultUpdateRepo, "curd"); err != nil { 354 if err := UpdateCurd(defaultUpdateRepo, "curd"); err != nil {
310 CurdOut(fmt.Sprintf("Update failed: %v", err)) 355 updateUserMessage(config, fmt.Sprintf("Update failed: %v", err))
311 Log(fmt.Sprintf("Update failed: %v", err)) 356 Log(fmt.Sprintf("Update failed: %v", err))
312 return false 357 return false
313 } 358 }
314 state.Available = false 359 state.Available = false
315 state.RemindAfter = "" 360 state.RemindAfter = ""
316 _ = saveUpdatePendingState(config.StoragePath, state) 361 _ = saveUpdatePendingState(config.StoragePath, state)
317 CurdOut(fmt.Sprintf("Updated to %s. Please restart curd.", state.LatestVersion)) 362 updateUserMessage(config, fmt.Sprintf("Updated to %s. Please restart curd.", state.LatestVersion))
318 return true 363 return true
319 case "later": 364 case "later":
320 state.RemindAfter = time.Now().Add(defaultRemindLaterDuration).UTC().Format(time.RFC3339) 365 until := time.Now().Add(defaultRemindLaterDuration)
366 state.RemindAfter = until.UTC().Format(time.RFC3339)
321 state.Available = true 367 state.Available = true
322 _ = saveUpdatePendingState(config.StoragePath, state) 368 _ = saveUpdatePendingState(config.StoragePath, state)
323 CurdOut(fmt.Sprintf("Will remind again after %s.", state.RemindAfter)) 369 updateUserMessage(config, fmt.Sprintf("Will remind again after %s.", formatLocalTime(until)))
324 return false 370 return false
325 case "skip": 371 case "skip":
326 state.SkippedVersion = state.LatestVersion 372 state.SkippedVersion = state.LatestVersion
327 state.Available = false 373 state.Available = false
328 state.RemindAfter = "" 374 state.RemindAfter = ""
329 _ = saveUpdatePendingState(config.StoragePath, state) 375 _ = saveUpdatePendingState(config.StoragePath, state)
330 CurdOut(fmt.Sprintf("Skipping version %s.", state.LatestVersion)) 376 updateUserMessage(config, fmt.Sprintf("Skipping version %s.", state.LatestVersion))
331 return false 377 return false
332 case "disable": 378 case "disable":
333 if err := setConfigBoolOption(GlobalConfigPath, "CheckUpdates", false); err != nil { 379 if err := setConfigBoolOption(GlobalConfigPath, "CheckUpdates", false); err != nil {
334 CurdOut(fmt.Sprintf("Could not write config: %v", err)) 380 updateUserMessage(config, fmt.Sprintf("Could not write config: %v", err))
335 Log(fmt.Sprintf("disable CheckUpdates: %v", err)) 381 Log(fmt.Sprintf("disable CheckUpdates: %v", err))
336 } else { 382 } else {
337 config.CheckUpdates = false 383 config.CheckUpdates = false
338 CurdOut("Automatic update checks disabled (CheckUpdates=false).") 384 updateUserMessage(config, "Automatic update checks disabled (CheckUpdates=false).")
339 } 385 }
340 state.Available = false 386 state.Available = false
341 _ = saveUpdatePendingState(config.StoragePath, state) 387 _ = saveUpdatePendingState(config.StoragePath, state)
@@ -443,7 +489,7 @@ func replaceExecutable(tmpPath, executablePath string) error {
443 } 489 }
444 490
445 // Permission denied — e.g. installed to /usr/local/bin. Ask for sudo. 491 // Permission denied — e.g. installed to /usr/local/bin. Ask for sudo.
446 CurdOut("Update needs elevated permissions to replace the installed binary.") 492 updateUserMessage(GetGlobalConfig(), "Update needs elevated permissions to replace the installed binary.")
447 if err := installExecutableWithSudo(tmpPath, executablePath); err != nil { 493 if err := installExecutableWithSudo(tmpPath, executablePath); err != nil {
448 return err 494 return err
449 } 495 }
internal/update_test.go +27
@@ -124,3 +124,30 @@ func TestUpdatePendingPath(t *testing.T) {
124 t.Fatalf("unexpected path %q", path) 124 t.Fatalf("unexpected path %q", path)
125 } 125 }
126} 126}
127
128func TestFormatLocalTimeUsesLocalZone(t *testing.T) {
129 // Fixed instant: 2026-07-23T20:24:06Z
130 utc := time.Date(2026, 7, 23, 20, 24, 6, 0, time.UTC)
131 got := formatLocalTime(utc)
132 if strings.Contains(got, "2026-07-23T20:24:06Z") {
133 t.Fatalf("expected local display, not RFC3339 Z form: %q", got)
134 }
135 if !strings.Contains(got, "2026") || !strings.Contains(got, ":") {
136 t.Fatalf("unexpected local format %q", got)
137 }
138}
139
140func TestBuildUpdatePromptMessage(t *testing.T) {
141 prompt, msg := buildUpdatePromptMessage("2.0.1", updatePendingState{
142 LatestVersion: "2.0.2",
143 ReleaseName: "Curd v2.0.2",
144 HTMLURL: "https://example.com",
145 ReleaseNotes: "fixed stuff",
146 })
147 if !strings.Contains(prompt, "2.0.1") || !strings.Contains(prompt, "2.0.2") {
148 t.Fatalf("prompt=%q", prompt)
149 }
150 if !strings.Contains(msg, "fixed stuff") || !strings.Contains(msg, "https://example.com") {
151 t.Fatalf("message=%q", msg)
152 }
153}