MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 208 forks source link

loading files #22

Open dorkalev opened 12 years ago

dorkalev commented 12 years ago

so it seems safari doesn't support loading files yet (chrome does) for example:

works on chrome: http://stackoverflow.com/questions/3146483/html5-file-api-read-as-text-and-binary fails on safari

and so it doesn't work in macgap :\

anyway around this?

it would have been great if there was :<

maccman commented 12 years ago

Yes, we could definitely emulate the API. Pull requests are always welcome :)

Sent with Hermes

liamks commented 12 years ago

WebKit nightly has support for FileReader. @dorkalev you might want to start with WebKit nightly and see if you can use the WebKit.framework that it uses (assuming that's how you get FileReader to work). If you have any luck, let us know, that could be a much easier solution that emulating the API.

dorkalev commented 12 years ago

Hi, I downloaded the nightly build and changed the import webkit line to

import </Applications/WebKit.app/Contents/Frameworks/10.7/WebKit.framework/Versions/A/Headers/WebKit.h>

it compiles but still FileReader doesn't seem to work.

Anything else to try here?

liamks commented 12 years ago

I've posted the question on Stackoverflow:

http://stackoverflow.com/questions/9007825/using-webkit-framework-from-webkit-nightly-in-cocoa-app

If we can't find an easy solution then we'll have to emulate the API!

maccman commented 12 years ago

Have a look at the console, it's not as easy as just importing the framework.

Sent with Hermes

dorkalev commented 12 years ago

Ok, so we've got an answer there and I tried it just to realize that the nightly build doesn't handle FileReader that well actually :O :O :O emulating the API then?

liamks commented 12 years ago

@dorkalev Implementing the entire API might end up being a lot of work. I wonder if we could get away with initially implementing a subset of it? It looks like WebKit already has File and Blob objects. Something like the following might work:

macgap.filereader.readAsArrayBuffer(...)
macgap.filereader.readAsBinaryString(...)
macgap.filereader.readAsDataURL(...)
macgap.filereader.readAsText(...)
macgap.filereader.abort()

with the following events: onabort, onerror, onload, onloadend, onloadstart, onprogress. If you're comfortable with objective-c you can use the existing classes and events (see bottom of MacGap documentation) as a template.

@maccman Any thoughts on above proposal for the macgap.filereader api?

dorkalev commented 12 years ago

Thank @liamks! I have some objective-c guys in my team which I am trying to recruit to this blessed mission.

What I am really up to is building a slim IDE, textmate-like in HTML5 project with macgap I really find browser based IDEs annoying but love browser based office tools (google's that means)

I believe this environment can fit great to this mission.

liamks commented 12 years ago

@dorkalev I was wondering if your colleagues have started on this issue? If not I was thinking of tackling it this weekend. If I have something/or do not, I'll post here.

dorkalev commented 12 years ago

@liamks go for it but all means! I have ruby on serverside to emulate my FileReader needs for now... so we combine it later to something beautiful.

What I would really love (hope that's what you really plan on bringing) is ability to list all files in directory (so I can build a file tree) and ability to load, save files.

I am really glad you're on it, it is going to be awesome!

liamks commented 12 years ago

@dorkalev see https://github.com/maccman/macgap/pull/25

Please test it out first!

dorkalev commented 12 years ago

:O not workin' for me with the example from http://stackoverflow.com/questions/3146483/html5-file-api-read-as-text-and-binary

have you tried it?

liamks commented 12 years ago

@dorkalev the File API has not been implemented. I have added some additional methods that allow you to access files and get either their text, or a base64 encoding of them. See the readme on my master branch for how to access files (e.g. macgap.file.).