0

execuse my english... I try to write a Cross-Platform Webapp initially just for the Android platfrom. I have to write and read Files to the Filesystem of the mobile. I've already seen that the package rikulo_gap not natively supports the Filesystem API. The Fileystem API used by Rikulo is that one, which of course doesn't work on a mobile platform.

So I've seen that Rikulo's Js-Package should make my Dart-Code interoperable with my Cordova.js-File (v4.0.0), which includes the global function requestFileSystem(persistence,size,success-funct,fail-funct). Now i've tried to make my code work, but i don't get a Filesystem back - i'm getting errors...

Here's my Dart-Code:

import 'package:rikulo_gap/device.dart';
import 'dart:js' as js;

void main() { 
 Device.init().then((device) => onDeviceReady(device)).
 catchError((ex) => print("AN ERROR OCCURED: " + ex.toString()));
}

void onDeviceReady(device) {
 var persistent = js.context['PERSISTENT']; 
 print("Should be Constant PERSISTENT of LFS: " + persistent.toString());
 var fsName = js.context.callMethod('requestFileSystem',[persistent,0,dofs,fail]);
}

void dofs(fs) {
 print("Success");
 var myFs = js.context[fs];
 print("The Return of RequestFileSystem is a: " + myFs.toString());
}

LogCat says:

10-23 18:08:32.589: D/CordovaLog(951): file:///android_asset/www/adam.dart.js: Line 12111 : Should be Constant PERSISTENT of LFS: 1
10-23 18:08:32.624: D/CordovaLog(951): file:///android_asset/www/adam.dart.js: Line 12111 : Success
10-23 18:08:32.649: D/CordovaLog(951): file:///android_asset/www/cordova.js: Line 1060 : processMessage failed: Stack: Error
10-23 18:08:32.649: D/CordovaLog(951):     at dart.wrapException (file:///android_asset/www/adam.dart.js:2520:15)
10-23 18:08:32.649: D/CordovaLog(951):     at JsObject.$index (file:///android_asset/www/adam.dart.js:11549:17)
10-23 18:08:32.649: D/CordovaLog(951):     at dart.J.$index$asx (file:///android_asset/www/adam.dart.js:19278:41)
10-23 18:08:32.649: D/CordovaLog(951):     at dofs (file:///android_asset/www/adam.dart.js:4185:7)
10-23 18:08:32.649: D/CordovaLog(951):     at dart.Primitives_applyFunction (file:///android_asset/www/adam.dart.js:2489:23)
10-23 18:08:32.649: D/CordovaLog(951):     at _callDartFunction (file:///android_asset/www/adam.dart.js:11464:29)
10-23 18:08:32.649: D/CordovaLog(951):     at file:///android_asset/www/adam.dart.js:11671:18
10-23 18:08:32.649: D/CordovaLog(951):     at file:///android_asset/www/plugins/org.apache.cordova.file/www/requestFileSystem.js:52:25
10-23 18:08:32.649: D/CordovaLog(951):     at success (file:///android_asset/www/plugins/org.apache.cordova.file/www/fileSystems-roots.js:40:13)
10-23 18:08:32.649: D/CordovaLog(951):     at Object.cordova.callbackFromNative (file:///android_asset/www/cordova.js:293:54)
10-23 18:08:32.649: D/CordovaLog(951): file:///android_asset/www/cordova.js: Line 1061 : processMessage failed: Message: S01 File1158866550 [{"fullPath":"\/","filesystemName":"temporary","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/Android\/data\/de.htwg.myAndroid\/cache\/","filesystem":0,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"content","isDirectory":true,"nativeURL":"cdvfile:\/\/localhost\/content\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/de.htwg.myAndroid\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files-external","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/Android\/data\/de.htwg.myAndroid\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"documents","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/de.htwg.myAndroid\/files\/Documents\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"sdcard","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/de.htwg.myAndroid\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache-external","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/Android\/data\/de.htwg.myAndroid\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"root","isDirectory":true,"nativeURL":"file:\/\/\/","filesystem":1,"isFile":false,"name":""}]       

What annoys me is, that the first Exception on the Stack is a dart.wrapException, so i guess it's a general Dart<>Js Interop problem.

I followed the official cordova instruction for Building with Android and currently i'm building with the Windows CommandLine with cordova run android. (And yes i've installed the plugins (File, FileUtil, Device via CommandLine and they are added to the project).

So can anybody tell me:

  1. Is it like i think and there is not a common way to use the cordova-Filesystem API with Rikulo/Dart?
  2. If 1. is true, is there a workaround? Anybody a Idea, a loose note oder anything else which could help me?
4

2 回答 2

2
  1. Rikulo 还不支持 Cordova 文件系统 API。您可以贡献一个或尝试改用 window.requestFileSystem。

  2. 返回给 dofs 的对象是一个 JsObject 实例,所以你不需要使用js.context它来转换它。那是,

    var myFs = js.context[fs];
    

    应修改为

    var myFs = fs;
    
于 2014-10-24T04:21:35.107 回答
1

天啊,你在第 2 点上做得很好......我生命中失去了两天:O(第 1 点无法工作,因为使用 dart:html 包函数 window.requestFileSystem 调用 webKitRequestFileSystem,它只在 chrome 浏览器中工作,并且LogCat 告诉我 s.th. 比如“不支持函数 webKitRequestFileSystem)

我很生气,因为 fs.toString 刚刚返回 [Object object],所以我认为它只是一个空对象,并且因为我只使用 dofs(fs)(没有 Type)签署了函数,所以我的 IDE/Dart-API 没有给出我为 JsObject 提出了类似“callMethod()”的建议......现在我改变了它:

void main() {
 Device.init().then((device) => onDeviceReady(device)).catchError((ex) => print("AN ERROR OCCURED: " + ex.toString()));
}
void onDeviceReady(device) {
 var persistent = context['PERSISTENT']; 
 print("Should be Constant PERSISTENT of LFS: " + persistent.toString());
 context.callMethod('requestFileSystem',[persistent,0,dofs,fail]);
}
void dofs(JsObject fs) {
 print("Success");
 var fsroot = fs['root'];
 createFile(fsroot);
}
void createFile(JsObject fsroot) {
 var cNe = new JsObject.jsify({'create': true, 'exclusive': false});
 fsroot.callMethod('getFile', ["DartCreatedFile.txt",cNe,gotFileEntry,fail]);
}
void gotFileEntry(JsObject fileEntry) {
 print(fileEntry['fullPath']);
}

Logcat 成功地告诉我:

10-24 14:17:03.945: D/CordovaLog(6685): file:///android_asset/www/fileSystemApi.js: Line 8 : Device is Ready!!!
10-24 14:17:04.055: D/CordovaLog(6685): file:///android_asset/www/adam.dart.js: Line 12294 : Should be Constant PERSISTENT of LFS: 1
10-24 14:17:04.085: D/CordovaLog(6685): file:///android_asset/www/adam.dart.js: Line 12294 : Success
10-24 14:17:04.105: D/CordovaLog(6685): file:///android_asset/www/adam.dart.js: Line 12294 : //DartCreatedFile.txt
于 2014-10-24T08:55:26.053 回答