Giter Site home page Giter Site logo

Comments (8)

ihadeed avatar ihadeed commented on May 12, 2024

The code you have looks right to me ..
Do you have the plugin cordova-plugin-file installed?

from awesome-cordova-plugins.

Fenkiou avatar Fenkiou commented on May 12, 2024

Yes, the plugin is installed. Maybe the plugin is missing the equivalent of $cordovaFileError and $window ?

from awesome-cordova-plugins.

ihadeed avatar ihadeed commented on May 12, 2024

Hey @Fenkiou ..

I was looking at the plugin's source code. The function getFreeDiskSpace() is not exposed in the plugin's JavaScript file. It is a function defined in the Java and Objective-C files only. Which explains why you aren't able to access it through the ionic-native wrapper you wrote.
Ref: https://github.com/apache/cordova-plugin-file/search?utf8=%E2%9C%93&q=getFreeDiskSpace

The ionic-native wrappers route your call to the plugin's methods that are defined in their JavaScript files (which is usually the methods they have documented).

You probably saw the method implemented in ngCordova and thought it's one of the plugin's methods. If you look at their code, they are actually executing the method using cordova.exec() which speaks to the Java/Object-C files directly without passing by the JS file.
Ref: https://github.com/driftyco/ng-cordova/blob/master/src/plugins/file.js#L27-L35

We might be looking to implement a similar approach to that method when we add the file plugin.

from awesome-cordova-plugins.

Fenkiou avatar Fenkiou commented on May 12, 2024

Ok, I thought that ionic-native plugin wrap ngCordova plugin but it's the cordova plugin that is wrapped.

cordova.execis only used in getFreeDiskSpace(), and when I saw it, I tried to implement checkDir() method instead, like this :

@Cordova()
static checkDir(path: string, dir: string):Promise<any> {
  let resolveFn, rejectFn;
  let promise = new Promise((resolve, reject) => {resolveFn = resolve; rejectFn = reject; })

  var directory = path + dir;

  if ((/^\//.test(dir))) {
    rejectFn('directory cannot start with \/');
  }

  try {
    var directory = path + dir;

    window.resolveLocalFileSystemURL(directory, function (fileSystem) {
      if (fileSystem.isDirectory === true) {
        resolveFn(fileSystem);
      } else {
        rejectFn({code: 13, message: 'input is not a directory'});
      }
    }, function (error) {
      error.message = error.code;
      rejectFn(error);
    });
  } catch (err) {
    err.message = err.code;
    rejectFn(err);
  }

  return promise;
}

But it's not working anyway. Even with just something like this :

@Cordova()
static checkDir(path: string, dir: string): string {
  return "some string";
}

It's still raising an error on https://github.com/driftyco/ionic-native/blob/master/src/plugins/plugin.ts#L100 without tell me the error but it's this call that fails.

from awesome-cordova-plugins.

ihadeed avatar ihadeed commented on May 12, 2024

Adding the @Cordova() decorator overrides anything that's defined in your function.

from awesome-cordova-plugins.

ihadeed avatar ihadeed commented on May 12, 2024

This should work.

static checkDir(path: string, dir: string):Promise<any> {
  return new Promise((resolve, reject) => {
    var directory = path + dir;

  if ((/^\//.test(dir))) {
    reject('directory cannot start with \/');
  }

  try {
    var directory = path + dir;

    window.resolveLocalFileSystemURL(directory, function (fileSystem) {
      if (fileSystem.isDirectory === true) {
        resolve(fileSystem);
      } else {
        reject({code: 13, message: 'input is not a directory'});
      }
    }, function (error) {
      error.message = error.code;
      reject(error);
    });
  } catch (err) {
    err.message = err.code;
    reject(err);
  }

  });
}

from awesome-cordova-plugins.

Fenkiou avatar Fenkiou commented on May 12, 2024

That's it, thank you ! I'll try to implement methods I need to see if it works and I hope get back with a PR.

UDPATE:
Your way to return promise causes a memory consumption issue, I used my way with @cordova() removed and it works.

from awesome-cordova-plugins.

ihadeed avatar ihadeed commented on May 12, 2024

@Fenkiou Thanks for feedback. Glad you got it working.

from awesome-cordova-plugins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.