| @@ -268,6 +268,51 @@ func pendingUpdateShouldPrompt(config *CurdConfig, currentVersion string, state |
| 268 | 268 | return true |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | func formatLocalTime(t time.Time) string { |
| 272 | return t.In(time.Local).Format("Mon Jan 2 2006, 3:04 PM MST") |
| 273 | } |
| 274 | |
| 275 | func 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. |
| 300 | func 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 | 316 | // HandlePendingUpdatePrompt shows a previously detected update (from idle check). |
| 272 | 317 | // Returns true if the caller should exit (user updated or chose to quit the session). |
| 273 | 318 | func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool { |
| @@ -279,63 +324,64 @@ func HandlePendingUpdatePrompt(config *CurdConfig, currentVersion string) bool { |
| 279 | 324 | return false |
| 280 | 325 | } |
| 281 | 326 | |
| 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{ |
| 296 | 328 | {Key: "update", Label: "Update now"}, |
| 297 | 329 | {Key: "later", Label: "Remind me later"}, |
| 298 | 330 | {Key: "skip", Label: "Skip this version"}, |
| 299 | 331 | {Key: "disable", Label: "Turn off automatic update checks"}, |
| 300 | 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 | 347 | if err != nil || selected.Key == "-1" || selected.Key == "-2" || selected.Key == "continue" || selected.Key == "" { |
| 303 | 348 | return false |
| 304 | 349 | } |
| 305 | 350 | |
| 306 | 351 | switch selected.Key { |
| 307 | 352 | case "update": |
| 308 | | CurdOut("Downloading and installing update…") |
| 353 | updateUserMessage(config, "Downloading and installing update…") |
| 309 | 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 | 356 | Log(fmt.Sprintf("Update failed: %v", err)) |
| 312 | 357 | return false |
| 313 | 358 | } |
| 314 | 359 | state.Available = false |
| 315 | 360 | state.RemindAfter = "" |
| 316 | 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 | 363 | return true |
| 319 | 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 | 367 | state.Available = true |
| 322 | 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 | 370 | return false |
| 325 | 371 | case "skip": |
| 326 | 372 | state.SkippedVersion = state.LatestVersion |
| 327 | 373 | state.Available = false |
| 328 | 374 | state.RemindAfter = "" |
| 329 | 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 | 377 | return false |
| 332 | 378 | case "disable": |
| 333 | 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 | 381 | Log(fmt.Sprintf("disable CheckUpdates: %v", err)) |
| 336 | 382 | } else { |
| 337 | 383 | config.CheckUpdates = false |
| 338 | | CurdOut("Automatic update checks disabled (CheckUpdates=false).") |
| 384 | updateUserMessage(config, "Automatic update checks disabled (CheckUpdates=false).") |
| 339 | 385 | } |
| 340 | 386 | state.Available = false |
| 341 | 387 | _ = saveUpdatePendingState(config.StoragePath, state) |
| @@ -443,7 +489,7 @@ func replaceExecutable(tmpPath, executablePath string) error { |
| 443 | 489 | } |
| 444 | 490 | |
| 445 | 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 | 493 | if err := installExecutableWithSudo(tmpPath, executablePath); err != nil { |
| 448 | 494 | return err |
| 449 | 495 | } |