You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/07/06 10:09:04 UTC

[GitHub] [cordova-plugin-file] ZhennanWu commented on issue #312: Electron platform does not support

ZhennanWu commented on issue #312: Electron platform does not support
URL: https://github.com/apache/cordova-plugin-file/issues/312#issuecomment-508914128
 
 
   You should really remove the "Test Pending" status on [Cordova platform support page](https://cordova.apache.org/docs/en/latest/guide/support/index.html). Because this plugin is really, really broken on Electron. Pissed me off for a day.
   
   I have confirm it on two seperate development environments. When invoking any api, it will throw
   ```javascript
   FileErrorĀ {code: "Missing Command Error", message: undefined}
   ```
   with
   ```javascript
   Error: exec proxy not found for :: File :: $TheAPIYouInvoked
   ```
   
   
   # Suspected Cause
   Tracing the error output, I suspect this is caused by inconsistencies in platform detection strategy? 
   
   Eg: In [src/browser/FileProxy.js](https://github.com/apache/cordova-plugin-file/tree/master/src/browser) and [www/resolveLocalFileSystemURI.js](https://github.com/apache/cordova-plugin-file/blob/master/www/resolveLocalFileSystemURI.js)
   ```javascript
   //In src/browser/FileProxy.js
   
       // For chrome we don't need to implement proxy methods
       // All functionality can be accessed natively.
       if (require('./isChrome')()) {
           var pathsPrefix = {
               // Read-only directory where the application is installed.
               applicationDirectory: location.origin + '/', // eslint-disable-line no-undef
               // Where to put app-specific data files.
               dataDirectory: 'filesystem:file:///persistent/',
               // Cached files that should survive app restarts.
               // Apps should not rely on the OS to delete files in here.
               cacheDirectory: 'filesystem:file:///temporary/'
           };
   
           exports.requestAllPaths = function (successCallback) {
               successCallback(pathsPrefix);
           };
   
           require('cordova/exec/proxy').add('File', module.exports);
           return;
       }
   ```
   ```javascript
   //In www/resolveLocalFileSystemURI.js
   
       // For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
       function checkBrowser () {
           if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
               module.exports.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
               return true;
           }
           return false;
       }
       if (checkBrowser()) {
           return;
       }
   ```
   In src/browser/FileProxy.js, it assumes Electron have all the native APIs. So it choose to register nothing in the execProxy of Cordova. Meanwhile, other modules consider Electron not qualified (`cordova.platformId !== 'browser'`) and overrides its methods.
   
   
   # Fixing Attempt
   I've hacked src/browser/FileProxy.js to ensure it uses a consistent platform detection logic
   ```javascript
   //In src/browser/FileProxy.js
   
       // For chrome we don't need to implement proxy methods
       // All functionality can be accessed natively.
       if (cordova.platformId === 'browser' && require('./isChrome')()) { // FIX HERE
   
           //..........
   
           require('cordova/exec/proxy').add('File', module.exports);
           return;
       }
   ```
   And at least the API call is OK. No more `Error: exec proxy not found for :: File :: `
   
   Is there anyone who can confirm this issue? I'm new to Cordova platform.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org