-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Update ScreenOCR extension with cross-extension conventions #24248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ion and updated dependencies.
|
Thank you for your contribution! 🎉 🔔 @neo773 @anwarulislam @xilopaint @pernielsentikaer 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. 📋 Quick checkout commandsBRANCH="ext/screenocr"
FORK_URL="https://github.com/chrismessina/extensions.git"
EXTENSION_NAME="screenocr"
REPO_NAME="extensions"
git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run devDue to our current reduced availability, the initial review may take up to 10-15 business days. |
|
Hi, I just had a quick look at this on my phone and the code looks good. Could you remove the redundant, unnecessary code comment and also use early returns instead of nested if/else? Thanks for the contribution. |
|
@greptile could you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll review the screenocr extension update. Let me look at the changes:
Summary
This PR adds cross-extension support to the ScreenOCR extension, allowing other Raycast extensions to call ScreenOCR programmatically and receive OCR results via callbacks.
Key Changes
✅ Good Implementation
-
Proper Cross-Extension Integration
- Added
raycast-cross-extensiondependency - Implemented callback mechanism in
recognize-text.tsx - Added comprehensive documentation
- Added
-
Backwards Compatibility
- Extension still works as before when called directly
- Only uses callback when launched from another extension
-
Error Handling
- Proper error propagation to callback consumers
- Handles both "no text detected" and general failures
-
Documentation
- Good cross-extension usage documentation
- Clear examples for consumer setup
🔍 Areas for Improvement
- Type Safety in
recognize-text.tsx
The callback data structure could be more strongly typed:
import { Clipboard, closeMainWindow, LaunchProps } from "@raycast/api";
import { LaunchOptions, callbackLaunchCommand } from "raycast-cross-extension";
import { recognizeText, showSuccessToast, showFailureToast } from "./utils";
type OCRResult = {
text: string | null;
error?: string;
};
type LaunchContext = {
callbackLaunchOptions?: LaunchOptions;
};
export default async function command({
launchContext,
}: LaunchProps<{ launchContext?: LaunchContext }>) {
await closeMainWindow();
const callbackOptions = launchContext?.callbackLaunchOptions;
try {
const recognizedText = await recognizeText();
if (!recognizedText) {
await showFailureToast("No text detected");
// If there's a callback, send empty result back
if (callbackOptions) {
await callbackLaunchCommand(callbackOptions, {
text: null,
error: "No text detected",
} as OCRResult);
}
return;
}
// If called from another extension with callback, send result back
if (callbackOptions) {
await callbackLaunchCommand(callbackOptions, { text: recognizedText } as OCRResult);
} else {
// Standard behavior: copy to clipboard
await Clipboard.copy(recognizedText);
await showSuccessToast("Copied text to clipboard");
}
} catch (e) {
console.error(e);
await showFailureToast("Failed detecting text");
// If there's a callback, send error back
if (callbackOptions) {
await callbackLaunchCommand(callbackOptions, {
text: null,
error: e instanceof Error ? e.message : "Failed detecting text",
} as OCRResult);
}
}
}
-
Cross-Extension Badge
- ✅ Added the cross-extension badge to README
- ✅ Updated metadata correctly
-
Documentation Structure
- The cross-extension docs are well-structured
- Example code is clear and practical
Overall Assessment
This is a solid implementation of cross-extension support that:
- Maintains backward compatibility
- Provides clear documentation
- Implements proper error handling
- Uses the cross-extension conventions correctly
The PR successfully transforms ScreenOCR into a provider extension while keeping all existing functionality intact. Great work! 🎉
…code readability through early returns.
…RResult` and `LaunchContext` types with `satisfies` validation
Greptile SummaryImplemented cross-extension support for ScreenOCR following the raycast-cross-extension-conventions, enabling other extensions to programmatically trigger OCR and receive structured results via callbacks.
Confidence Score: 5/5
Important Files Changed
|
Co-authored-by: LitoMore <[email protected]>
Using `undefined` instead of `null` Co-authored-by: LitoMore <[email protected]>
Simplify documentation to align with [SimpleIcons example](https://raw.githubusercontent.com/raycast/extensions/refs/heads/main/extensions/simple-icons/API.md).
Added API section with link to documentation.
Description
This PR implements cross-extension support for ScreenOCR, allowing other Raycast extensions to programmatically call OCR functionality and receive structured data via callbacks. It also includes several code quality improvements and dependency updates.
🌟 Key Changes
Cross-Extension Integration
raycast-cross-extensionas a dependency.package.jsonwith necessary metadata to act as a cross-extension provider.docs/cross-extension-usage.mdto help other developers integrate with ScreenOCR.Enhanced Type Safety & Readability
OCRResultandLaunchContexttypes for robust callback handling.recognize-text.tsxanddetect-barcode.tsxto use early return patterns, significantly cleaning up nested logic.@raycast/utilswhile maintaining support for user-defined sound and notification preferences.Maintenance & Dependency Updates
@raycast/apito^1.104.1.typescript (^5.9.3)and@typespackages for React/Node.CHANGELOG.mdandREADME.mdto reflect these updates.Checklist
npm run buildand tested this distribution build in Raycastassetsfolder are used by the extension itselfREADMEare placed outside of themetadatafolder