Skip to content

Conversation

@chrismessina
Copy link
Contributor

@chrismessina chrismessina commented Jan 7, 2026

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

  1. Cross-Extension Integration

    • Implemented raycast-cross-extension-conventions.
    • Added raycast-cross-extension as a dependency.
    • Updated package.json with necessary metadata to act as a cross-extension provider.
    • Added a new guide: docs/cross-extension-usage.md to help other developers integrate with ScreenOCR.
  2. Enhanced Type Safety & Readability

    • Introduced dedicated OCRResult and LaunchContext types for robust callback handling.
    • Refactored recognize-text.tsx and detect-barcode.tsx to use early return patterns, significantly cleaning up nested logic.
    • Updated error handling to leverage @raycast/utils while maintaining support for user-defined sound and notification preferences.
  3. Maintenance & Dependency Updates

    • Upgraded @raycast/api to ^1.104.1.
    • Updated dev dependencies including typescript (^5.9.3) and @types packages for React/Node.
    • Refined CHANGELOG.md and README.md to reflect these updates.

Checklist

@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: screenocr Issues related to the screenocr extension platform: macOS labels Jan 7, 2026
@raycastbot
Copy link
Collaborator

raycastbot commented Jan 7, 2026

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 commands
BRANCH="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 dev

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

@neo773
Copy link
Contributor

neo773 commented Jan 7, 2026

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.

@chrismessina
Copy link
Contributor Author

@greptile could you take a look?

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.

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

  1. Proper Cross-Extension Integration

    • Added raycast-cross-extension dependency
    • Implemented callback mechanism in recognize-text.tsx
    • Added comprehensive documentation
  2. Backwards Compatibility

    • Extension still works as before when called directly
    • Only uses callback when launched from another extension
  3. Error Handling

    • Proper error propagation to callback consumers
    • Handles both "no text detected" and general failures
  4. Documentation

    • Good cross-extension usage documentation
    • Clear examples for consumer setup

🔍 Areas for Improvement

  1. 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);
    }
  }
}
  1. Cross-Extension Badge

    • ✅ Added the cross-extension badge to README
    • ✅ Updated metadata correctly
  2. 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! 🎉

…RResult` and `LaunchContext` types with `satisfies` validation
@chrismessina chrismessina changed the title Update screenocr extension Update ScreenOCR extension with cross-extension conventions Jan 7, 2026
@chrismessina chrismessina marked this pull request as ready for review January 7, 2026 06:14
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 7, 2026

Greptile Summary

Implemented cross-extension support for ScreenOCR following the raycast-cross-extension-conventions, enabling other extensions to programmatically trigger OCR and receive structured results via callbacks.

  • Added OCRResult and LaunchContext types with satisfies validation for type-safe callback handling
  • Enhanced recognize-text.tsx to support callback-based cross-extension communication with proper error handling
  • Refactored code with early return patterns across multiple files for improved readability
  • Modernized error handling using @raycast/utils while maintaining user preference support for toast notifications and sounds
  • Added comprehensive documentation in docs/cross-extension-usage.md
  • Updated dependencies to latest versions (@raycast/api ^1.104.1, @raycast/utils ^2.2.2)
  • CHANGELOG follows proper formatting with {PR_MERGE_DATE} placeholder at the top

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The implementation follows Raycast conventions properly, with correct cross-extension setup, excellent type safety using satisfies, proper error handling, and well-structured code refactoring. All changes are clean, focused, and maintain backward compatibility.
  • No files require special attention

Important Files Changed

Filename Overview
extensions/screenocr/src/recognize-text.tsx Implemented cross-extension callback support with proper error handling and early returns for improved readability
extensions/screenocr/src/types.ts Added OCRResult and LaunchContext types for type-safe cross-extension communication
extensions/screenocr/src/utils.ts Refactored toast helpers with early returns and integrated @raycast/utils for better error handling
extensions/screenocr/package.json Added raycast-cross-extension dependency and updated @raycast packages to latest versions
extensions/screenocr/docs/cross-extension-usage.md New documentation file explaining how other extensions can consume ScreenOCR's functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants