Skip to content

[coffee] show caffeinate duration in menu bar item#17493

Merged
raycastbot merged 2 commits intoraycast:mainfrom
kargeor:gk/coffeeshowtime
Mar 3, 2025
Merged

[coffee] show caffeinate duration in menu bar item#17493
raycastbot merged 2 commits intoraycast:mainfrom
kargeor:gk/coffeeshowtime

Conversation

@kargeor
Copy link
Contributor

@kargeor kargeor commented Mar 2, 2025

Description

Screencast

image

Checklist

@raycastbot
Copy link
Collaborator

raycastbot commented Mar 2, 2025

Thank you for your first contribution! 🎉

🔔 @mooxl @bibixx @GastroGeek @pernielsentikaer @xilopaint @ridemountainpig @zakj @Visual-Studio-Coder you might want to have a look.

You can use this guide to learn how to check out the Pull Request locally in order to test it.

Due to our current reduced availability, the initial review may take up to 10-15 business days

@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: coffee Issues related to the coffee extension labels Mar 2, 2025
@kargeor kargeor force-pushed the gk/coffeeshowtime branch 2 times, most recently from 6cab0dd to af80b2c Compare March 2, 2025 17:59
@kargeor kargeor force-pushed the gk/coffeeshowtime branch from af80b2c to 860af48 Compare March 2, 2025 18:03
@pernielsentikaer
Copy link
Collaborator

Could we make the time prettier instead of showing 3600s it should be nice to show 1h and string like 5h 30m instead

@pernielsentikaer pernielsentikaer self-assigned this Mar 2, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds functionality to display the caffeinate duration in the menu bar item, enhancing user visibility of the remaining time when using time-limited caffeination.

  • Added new useExtraInfoStr hook in extensions/coffee/src/index.tsx that extracts duration information from caffeinate process arguments
  • Implemented display of duration as "For Xs" in the menu bar when Mac is caffeinated with a time limit
  • Added a new section in the menu bar UI to show the duration information when available
  • Added changelog entry in extensions/coffee/CHANGELOG.md but it's missing the required {PR_MERGE_DATE} template string
  • The implementation cleanly integrates with existing code to provide useful context to users

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@kargeor
Copy link
Contributor Author

kargeor commented Mar 2, 2025

Could we make the time prettier instead of showing 3600s it should be nice to show 1h and string like 5h 30m instead

Is there a pre-existing function somewhere that does this that I can import?

@pernielsentikaer
Copy link
Collaborator

You can maybe do something like

function formatDuration(seconds: number): string {
  const units = [
    { label: 'd', value: 86400 },
    { label: 'h', value: 3600 },
    { label: 'm', value: 60 },
    { label: 's', value: 1 }
  ];

  const result: string[] = [];

  for (const unit of units) {
    const amount = Math.floor(seconds / unit.value);
    seconds %= unit.value;
    if (amount > 0) {
      result.push(`${amount}${unit.label}`);
    }
  }

  return result.join(' ');
}

// Example usage:
console.log(formatDuration(1337000)); // Output: "15d 11h 23m 20s"
console.log(formatDuration(3600));    // Output: "1h"
console.log(formatDuration(65));      // Output: "1m 5s"
console.log(formatDuration(86400));   // Output: "1d"

@zakj
Copy link
Contributor

zakj commented Mar 2, 2025

Won't this be a bit confusing after some time progresses? For example, if I caffeinate for 2 hours, when there's one minute left to go it will still display "For 7200s".

@kargeor
Copy link
Contributor Author

kargeor commented Mar 3, 2025

Won't this be a bit confusing after some time progresses? For example, if I caffeinate for 2 hours, when there's one minute left to go it will still display "For 7200s".

I updated it to show the remaining time. Any advice on wording/format would be appreciated. (see updated screenshot)

@zakj
Copy link
Contributor

zakj commented Mar 3, 2025

Thank you, that's so much better! I think "remain" is fine. Other alternatives would be "left", or nothing at all—the time on its own is pretty clear in this context.

Copy link
Collaborator

@pernielsentikaer pernielsentikaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋

Looks good to me, approved 🔥

@raycastbot raycastbot merged commit 8bc3c5c into raycast:main Mar 3, 2025
9 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2025

Published to the Raycast Store:
https://raycast.com/mooxl/coffee

@raycastbot
Copy link
Collaborator

🎉 🎉 🎉

Such a great contribution deserves a reward, but unfortunately we couldn't find your Raycast account based on your GitHub username (@kargeor).
Please link your GitHub account to your Raycast account to receive your credits and soon be able to exchange them for some swag.

@kargeor kargeor deleted the gk/coffeeshowtime branch March 3, 2025 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extension: coffee Issues related to the coffee extension extension fix / improvement Label for PRs with extension's fix improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants