Skip to content

Commit

Permalink
handles fallback to clipboard if getSelecteText fails (#12582)
Browse files Browse the repository at this point in the history
  • Loading branch information
blessanm86 committed May 27, 2024
1 parent 43d60d8 commit 3c6e7ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions extensions/bitly-url-shortener/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Bitly Changelog

## [Update] - 2024-05-26
- Fallback to clipboard text when selected text fails with `Unable to get selected text from frontmost application`

## [Update] - 2024-04-13

- Now by default will grab the currently selected URL to shorten
Expand Down
1 change: 1 addition & 0 deletions extensions/bitly-url-shortener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Extension to shorten your url’s with Bitly. Copy the url to shorten and then r
2. Login or create an account on Bitly
3. Generate an access token at https://app.bitly.com/settings/api
4. If you used an oAuth provider like Google to sign in, please use the password reset flow to create a password which you can use to generate the access token.
5. Ensure raycast is enabled in `System Settings > Privacy & Security > Accessibility`

_Note: If this instruction wasn't clear, please let me know in [Slack Community](https://raycast.com/community) or feel free to create a PR with improved steps._
11 changes: 7 additions & 4 deletions extensions/bitly-url-shortener/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export default async function () {
try {
const { accessToken, pasteAfterShortening } = getPreferenceValues();

// Try to get the selected text
const selectedText = await getSelectedText();

// If no text is selected, fall back to the clipboard
const urlToShorten = selectedText ? selectedText : await Clipboard.readText();
let urlToShorten;
try {
urlToShorten = await getSelectedText();
} catch (error: unknown) {
urlToShorten = await Clipboard.readText();
}

if (!urlToShorten) {
return await reportError(new Error("No text selected and clipboard is empty"));
}
Expand Down

0 comments on commit 3c6e7ba

Please sign in to comment.