FGA icon indicating copy to clipboard operation
FGA copied to clipboard

feat: tesseract improvements

Open ArthurKun21 opened this issue 7 months ago • 3 comments

Pull Request Type

  • [ ] Chore
  • [ ] Bugfix
  • [X] Feature Implementation
  • [ ] Documentation
  • [ ] Other

Related issue

Description

  • Make the Tesseract load once per service
  • ensure tesseract proper closing of resources
  • Implement SHA-256 validation to verify file integrity during asset copying, while streamlining the copying process.

Screenshots

Testing

Additional context

This pull request refactors the TesseractOcrService and its integration into the project, improving resource management, error handling, and modularity. The changes also update the dependency injection setup and ensure proper cleanup of OCR-related resources.

Dependency Injection Updates:

  • Removed the binding of TesseractOcrService as OcrService from ScriptsModule and added it to ServiceModule to scope it appropriately to services. (ScriptsModule.kt: [1] [2] [3]; ServiceModule.kt: [4] [5]

TesseractOcrService Enhancements:

  • Changed the scope of TesseractOcrService from ScriptScope to ServiceScoped and implemented the AutoCloseable interface for better resource management. (TesseractOcrService.kt: app/src/main/java/io/github/fate_grand_automata/imaging/TesseractOcrService.ktL4-R22)
  • Added hash-based validation for Tesseract training data files to ensure data integrity and avoid unnecessary file overwrites. (TesseractOcrService.kt: [1] [2]
  • Replaced finalize with an explicit close method for predictable cleanup of the Tesseract API and improved logging using Timber. (TesseractOcrService.kt: app/src/main/java/io/github/fate_grand_automata/imaging/TesseractOcrService.ktL71-R149)

Integration with ScriptRunnerServiceController:

  • Injected OcrService into ScriptRunnerServiceController and ensured it is properly closed during cleanup to release resources. (ScriptRunnerServiceController.kt: [1] [2] [3]

OcrService Interface Update:

  • Added a close method to the OcrService interface to standardize resource cleanup across implementations. (OcrService.kt: libautomata/src/main/java/io/github/lib_automata/OcrService.ktR5-R13)

ArthurKun21 avatar May 05 '25 23:05 ArthurKun21

Build 176

Download the latest APK for testing here

[!NOTE] You need a GitHub account to download the APK.

This URL is valid as long as the artifact has not expired yet.

github-actions[bot] avatar May 05 '25 23:05 github-actions[bot]

Forgot to ask, is this ready to merge?

reconman avatar May 10 '25 19:05 reconman

currently not

ArthurKun21 avatar May 10 '25 19:05 ArthurKun21