Skip to content

Conversation

@bajrangCoder
Copy link
Member

No description provided.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant performance improvement by offloading file change detection to a background thread. This is achieved by adding compareFileText and compareTexts methods to the native System Cordova plugin. The JavaScript side in editorFile.js is updated to correctly use these new native functions for different file protocols. The Java implementation is solid, though I've suggested a minor refactoring to improve code clarity by removing some unused variables.

// Handle both file:// and content:// URIs
if ("file".equalsIgnoreCase(uri.getScheme())) {
File file = new File(uri.getPath());
if (!file.exists()) {
Copy link
Member

@RohitKushvaha01 RohitKushvaha01 Jan 6, 2026

Choose a reason for hiding this comment

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

Also check file.canRead(). Sometimes invalid URIs get converted to /, which exists but is not what we expect.

Also check file.isFile() for the reasons stated above.

}

// check length first
if (fileContent.length() != currentText.length()) {
Copy link
Member

@RohitKushvaha01 RohitKushvaha01 Jan 6, 2026

Choose a reason for hiding this comment

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

Move this check above the stream-reading code to avoid reading the file. Also, use file.length() instead of the file content length. (Only applicable for java.io.File)

// Read in chunks to handle large files
java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
byte[] chunk = new byte[8192];
while ((bytesRead = inputStream.read(chunk)) != -1) {
Copy link
Member

@RohitKushvaha01 RohitKushvaha01 Jan 6, 2026

Choose a reason for hiding this comment

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

There are better ways to read from a stream/file, this is one of the most error prone method

For java.io.File you can just do file.readText(encoding)

@Acode-Foundation Acode-Foundation deleted a comment from gemini-code-assist bot Jan 6, 2026
@greptile-apps
Copy link

greptile-apps bot commented Jan 6, 2026

Greptile Summary

Offloads file change detection from the JavaScript main thread to Android background threads, improving UI responsiveness during file comparison operations.

  • Added compareFileText() and compareTexts() native methods in Java plugin to handle file reading and text comparison in background threads
  • Refactored EditorFile.isChanged() to use native comparison for file://, content://, and FTP cache files
  • Falls back to JS-based comparison for other protocols after reading file content
  • Maintains existing error handling behavior (returns false on failures)

Confidence Score: 4/5

  • This PR is safe to merge with minor style improvements recommended
  • The implementation properly offloads blocking operations to background threads with correct validation and error handling. The Java code includes proper input validation, charset support checks, and handles both file:// and content:// URIs correctly. One minor style issue with redundant stream closing in the finally block.
  • Pay attention to src/plugins/system/android/com/foxdebug/system/System.java for the redundant stream closing pattern

Important Files Changed

Filename Overview
src/lib/editorFile.js Refactored file change detection to offload I/O and string comparison to native background threads
src/plugins/system/www/plugin.js Added two new Cordova plugin methods with proper Promise-based API and clear documentation
src/plugins/system/android/com/foxdebug/system/System.java Implemented native Android methods for background file/text comparison with proper validation and error handling

Sequence Diagram

sequenceDiagram
    participant Editor as EditorFile.js
    participant Plugin as System Plugin (JS)
    participant Cordova as Cordova Bridge
    participant Java as System.java (Android)
    participant BG as Background Thread
    participant FS as File System

    Note over Editor: User edits file
    Editor->>Editor: isChanged() called
    Editor->>Editor: session.getValue()
    
    alt FTP/SFTP Protocol
        Editor->>Plugin: compareFileText(cacheFileUri, encoding, text)
        Plugin->>Cordova: exec('compare-file-text')
        Cordova->>Java: compareFileText()
        Java->>BG: Run on background thread
        BG->>FS: Read file from cache
        FS-->>BG: File content
        BG->>BG: Compare lengths
        alt Lengths differ
            BG-->>Java: Return 1 (changed)
        else Lengths same
            BG->>BG: String.equals()
            BG-->>Java: Return 0/1
        end
        Java-->>Cordova: Result
        Cordova-->>Plugin: Result
        Plugin-->>Editor: true/false
    else File/Content Protocol
        Editor->>Plugin: compareFileText(uri, encoding, text)
        Plugin->>Cordova: exec('compare-file-text')
        Cordova->>Java: compareFileText()
        Java->>BG: Run on background thread
        BG->>FS: Read file (file:// or content://)
        FS-->>BG: File content
        BG->>BG: Compare and return result
        Java-->>Cordova: Result
        Cordova-->>Plugin: Result
        Plugin-->>Editor: true/false
    else Other Protocols
        Editor->>Editor: fsOperation(uri).readFile()
        Editor->>Plugin: compareTexts(oldText, text)
        Plugin->>Cordova: exec('compare-texts')
        Cordova->>Java: compareTexts()
        Java->>BG: Run on background thread
        BG->>BG: Compare lengths then strings
        Java-->>Cordova: Result
        Cordova-->>Plugin: Result
        Plugin-->>Editor: true/false
    end
    
    Note over Editor: Returns true if changed, false if not
Loading

greptile-apps[bot]

This comment was marked as resolved.

@bajrangCoder
Copy link
Member Author

@greptileai review it

Copy link

@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.

Additional Comments (2)

  1. src/plugins/system/android/com/foxdebug/system/System.java, line 706-711 (link)

    style: redundant stream closing - the try-with-resources at line 696 already closes BufferedReader, which automatically closes the underlying InputStreamReader and inputStream

  2. src/lib/editorFile.js, line 625-628 (link)

    logic: returning false (not changed) on error could lead to data loss - if native comparison fails but file actually changed on disk, editor won't prompt to save. should errors be handled differently (e.g., return true to be safe, or fallback to JS comparison)?

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@bajrangCoder bajrangCoder merged commit eb169fa into Acode-Foundation:main Jan 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants