enyo.kind({ name: 'service.Whatever', kind: enyo.Component, url: 'http://example.com/path/to/the/files/', path: 'localfolder/', xmlFile: 'foobar.xml', previewFile: 'preview.jpg', fetch: function() { var that = this, fileTransfer = new FileTransfer(); window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, that.fetchFailed); function gotFS(fileSystem) { fileSystem.root.getDirectory(that.path, {create: true}, gotLocalDir, that.fetchFailed); } function gotLocalDir(dirEntry) { // fetch xml file fileTransfer.download( that.url + that.xmlFile, dirEntry.fullPath + '/' + that.xmlFile, gotXml, that.fetchFailed ); // fetch preview image fileTransfer.download( that.url + that.previewFile, dirEntry.fullPath + '/' + that.previewFile, null, that.fetchFailed ); } function gotXml(file) { var reader = new FileReader(); reader.onloadend = function(evt) { that.setupData(evt.target.result); }; reader.readAsText(file); } }, setupData: function(xml) { // parse xml var if its a string if (typeof xml === 'string') { var parser = new DOMParser(); xml = parser.parseFromString(xml, 'text/xml'); } // save data as javascript object this.owner.setData('somekey', Xml.getObject(xml)); }, fetchFailed: function(error) { enyo.warn(error); } });I thought the calls to the file system will be async and should not block anything. My first suggestion was the huge amount of files, but it's also blocking if i just fetch a few.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
My second thought, is how are you calling these functions? Another idea would be to make this a enyo.Service kind, as Service is designed to wrap async functions.
I tried both, nextTick and asyncMethod, but that does not change anything. The setupData ist only called once as soon as the XML file is loaded, but the surface gets locked as long as files are fetched, not while the setupData runs.
Most of the files are preview images used for something similar to a gallery.
You'll probably find better solutions for this over on the PhoneGap mailing list at http://groups.google.com/group/phonegap.
As a quick solution i will split loading and place a scrim in front of it, then i'll see what the PhoneGap folks has in mind about this.
No, unfortunately i did not. I could not find a forum or contact email, only those ugly Google Group (sorry i don't like it). The bugtracker is deactivated on github, maybe it's a bit of confusion because of the move to apache. Feel free to contact them, i'm also still interested and would appreciate a solution, it's just low priority for me now.