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
866866 preferredMode = normalizeTranslationType(config.SubOrDub)
867867 }
868868
869 CurdOut(episodeLinkFailureDiagnosis(config, anime, lastErr))
869 diagnosis := episodeLinkFailureDiagnosis(config, anime, lastErr)
870 options := episodeLinkFailureRecoveryOptions(preferredMode, includeAudio)
870871
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 }
872881 if err != nil {
873882 return "back"
874883 }
internal/selection_menu.go +18 −1
@@ -669,13 +669,30 @@ func RofiSelect(options []SelectionOption, isHomeMenu bool) (SelectionOption, er
669669 return RofiSelectWithRefresh(options, isHomeMenu, nil)
670670}
671671
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
672678func 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) {
673683 currentOptions := options
684 if strings.TrimSpace(prompt) == "" {
685 prompt = "Select"
686 }
674687
675688 for {
676689 optionsString := buildRofiOptionsString(currentOptions, isHomeMenu)
677690 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...)
679696 cmd.Stdin = strings.NewReader(optionsString)
680697 var stdout, stderr bytes.Buffer
681698 cmd.Stdout = &stdout
internal/update.go +70 −24
@@ -268,6 +268,51 @@ func pendingUpdateShouldPrompt(config *CurdConfig, currentVersion string, state
268268 return true
269269}
270270
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
271316// HandlePendingUpdatePrompt shows a previously detected update (from idle check).
272317// Returns true if the caller should exit (user updated or chose to quit the session).
273318func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
@@ -279,63 +324,64 @@ func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool {
279324 return false
280325 }
281326
282 CurdOut("")
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{
327 options := []SelectionOption{
296328 {Key: "update", Label: "Update now"},
297329 {Key: "later", Label: "Remind me later"},
298330 {Key: "skip", Label: "Skip this version"},
299331 {Key: "disable", Label: "Turn off automatic update checks"},
300332 {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 }
302347 if err != nil || selected.Key == "-1" || selected.Key == "-2" || selected.Key == "continue" || selected.Key == "" {
303348 return false
304349 }
305350
306351 switch selected.Key {
307352 case "update":
308 CurdOut("Downloading and installing update…")
353 updateUserMessage(config, "Downloading and installing update…")
309354 if err := UpdateCurd(defaultUpdateRepo, "curd"); err != nil {
310 CurdOut(fmt.Sprintf("Update failed: %v", err))
355 updateUserMessage(config, fmt.Sprintf("Update failed: %v", err))
311356 Log(fmt.Sprintf("Update failed: %v", err))
312357 return false
313358 }
314359 state.Available = false
315360 state.RemindAfter = ""
316361 _ = 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))
318363 return true
319364 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)
321367 state.Available = true
322368 _ = 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)))
324370 return false
325371 case "skip":
326372 state.SkippedVersion = state.LatestVersion
327373 state.Available = false
328374 state.RemindAfter = ""
329375 _ = saveUpdatePendingState(config.StoragePath, state)
330 CurdOut(fmt.Sprintf("Skipping version %s.", state.LatestVersion))
376 updateUserMessage(config, fmt.Sprintf("Skipping version %s.", state.LatestVersion))
331377 return false
332378 case "disable":
333379 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))
335381 Log(fmt.Sprintf("disable CheckUpdates: %v", err))
336382 } else {
337383 config.CheckUpdates = false
338 CurdOut("Automatic update checks disabled (CheckUpdates=false).")
384 updateUserMessage(config, "Automatic update checks disabled (CheckUpdates=false).")
339385 }
340386 state.Available = false
341387 _ = saveUpdatePendingState(config.StoragePath, state)
@@ -443,7 +489,7 @@ func replaceExecutable(tmpPath, executablePath string) error {
443489 }
444490
445491 // 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.")
447493 if err := installExecutableWithSudo(tmpPath, executablePath); err != nil {
448494 return err
449495 }
internal/update_test.go +27
@@ -124,3 +124,30 @@ func TestUpdatePendingPath(t *testing.T) {
124124 t.Fatalf("unexpected path %q", path)
125125 }
126126}
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}