Opening files in a Dart Chrome packaged app

438 views
Skip to first unread message

dam...@altern.org

unread,
Apr 12, 2013, 12:06:39 PM4/12/13
to mi...@dartlang.org
I am building an editor with a web interface, but I thought it would be nice to be able to use it as a standalone desktop application.  Since I heard this would be possible with Chrome packaged apps, I tried to make one. However, I am struggling with a seemingly basic thing: showing a file chooser and getting a file's real path on the disk. I need the real path because edited files have links to other files with relative paths, so it's not just a matter of getting the file content (which I could do with a simple HTML input).

First I had the problem with symbolic links to the package files. I avoided this by removing the links and copying the files by hand.
I tried to see if there was a file chooser in the dart chrome api. I didn't find one, so I decided to use the js package. It didn't work until I figured I had to include 'packages/js/dart_interop.js' in the main HTML file.
I was then able to call chrome.fileSystem.chooseEntry and display a file chooser. But I was not able to get the real file path afterwards:
- fileEntry.fullPath does not give the real URL, just a temporary path in the (virtual) fileSystem such as '/myfile.txt'
- chrome.runtime.getURL(fileEntry.fullPath) return a "chrome-extension://" URL
- getDisplayPath returns the real path, but it uses ~ shortcuts, making it useless to get the real URL
- fileEntry.toURL() returns nothing

Here is my code so far :

    js.scoped(() {
      var chrome = js.context.chrome;
      chrome.fileSystem.chooseEntry(js.map({'type': 'openFile'}),
          new js.Callback.once((var fileEntry) {

       }));
    });

Is it even possible to get the real path or file:// URL ?

Devon Carew

unread,
Apr 12, 2013, 2:58:14 PM4/12/13
to General Dart Discussion
I'm not sure if this helps, but those fileEntry object that are returned by chooseEntry are actually instances of 'FileEntry', defined here:


There seem to be a lot of path related methods and properties defined on that page. I myself haven't been successful in getting a full path or url. If you do find out more, please post, as I'm interested in this too. Cheers,

Devon





--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 



--
Devon Carew
Software Engineer
Google, Inc.

dam...@altern.org

unread,
Apr 12, 2013, 3:51:11 PM4/12/13
to mi...@dartlang.org
I am not too hopeful to find a solution with the standard fileSystem API, because it was designed to be used in a sandbox, and the fullPath I get seems to be from a sandboxed file system. But Chrome seems to keep a link between this fileSystem file and the real file system path, otherwise it could not give part of the information I'm looking for in the displayPath. This displayPath also proves it is not a matter of security or permissions: I am already getting information that is not available to normal web applications. So I guess it would require a new feature in the chrome.fileSystem API, which should be easy to add...

Greg Lowe

unread,
Apr 22, 2013, 12:38:59 AM4/22/13
to mi...@dartlang.org
I think there are two ways to solve this:

Option 1) Use javascript interop to:
   choose the file. This returns a Proxy to a javascript FileEntry (which is not a Dart FileEntry - doh)
   create a javascript FileReader object for the javascript FileEntry object, call readAsText()
   read the results back into a Dart string.
   (If you need to use binary, then you'll have to base64 encode).

   I tried to do this here - but I couldn't get it to work either:

Option 2)  Create a patched version of dart:html which adds a choose() method.

Also see:

Ross Smith

unread,
May 18, 2013, 6:10:55 PM5/18/13
to mi...@dartlang.org
> - getDisplayPath returns the real path, but it uses ~ shortcuts, making it useless to get the real URL

This works for me on Windows 7, I get the full path.  I only get the ~/ if the directory is locked (like my windows user directory) - and that seems like a good thing?  For any unlocked directory on my c:\ or d:\ drive this is giving me the full absolute paths.

I put some code up on github here:

Greg Lowe

unread,
May 18, 2013, 10:44:59 PM5/18/13
to mi...@dartlang.org
Cheers ;)


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
 
 

Reply all
Reply to author
Forward
0 new messages