Where does getExternalFilesDir() point to in an app running in Chrome? - google-chrome-arc

I've successfully got my app running in Chrome using arc welder. And having managed to identify which files hold the sqlite database and shared preferences, I've been able to copy those across to nicely replicate how the app works on my 'phone.
On the 'phone, my app can take photographs, which it stores in the path found using getExternalFilesDir(null) and it would be nice to be able to copy those over so they can be seen when using the app through Chrome. But searching around, I've been unable to work out where this is.
I can save a file (using the app's database exporter and file-chooser) to somewhere which appears as an SD card, but no file or directory under my app's directory in ~/.config/google-chrome/Default/Storage/ext which gets changed when I do the export seems to fit.
I can see the exported file's name in def/File System/primary/p/Paths/000004.log, though as that's a data file it's not giving me any clues.
Anybody know where the virtual SD card (and so externalFilesDir) might be held?

By default ARC stores the external storage files to the Chrome HTML5 filesystem. Each app gets its own instance of the filesystem.
To put files into it, you can either:
(On a PC only) start your app, visit "chrome://inspect/#apps" for your app, and type plugin.shell('adbd') into the javascript console for it. Then you can use the Android ADB command adb push ... to transfer the data.
Or you can also add {"enableExternalDirectory": true} to your application's metadata. Enabling this option means that ARC will prompt you for the directory to use for for the external directory, and you can pick a real directory on your system to use.

Related

Alternative to Windows Alternate Data Streams

I have the following need to implement on Windows: file with files.
Originally I was thinking to use directory with extension. Something like "folderA.myappext", so when user clicks on it in Explorer, my app is launched instead of folder being opened. Unfortunately, I was unable to find a way to do that. Then I tried to use Alternate Data Streams. This works just fine, but several problems with it:
It works only in NTFS, so no way to send it via email or FTP as is;
Only WinRAR can properly archive it, and you still have to do extra clicks in the UI for that;
The real file size (with all streams in it) is not shown in Explorer and does not participate in showing free/used space, which can very quickly lead to big problems for the user.
No, I can't use zip or any other way to combine files into one - this is high-performance app that also requires write streaming (i.e. it changes data all the time).
Any idea how else to achieve my need on Windows? I know on MacOS you can use 'package', but there is nothing like that on Windows. Any idea?
Something like "folderA.myappext", so when user clicks on it in Explorer, my app is launched instead of folder being opened.
You can't do it based on the extension because folders don't have extensions but you can do it with desktop.ini. Windows 7 and later supports custom verbs on folders.
A working example can be found here.

Prevent original files from OS X app's sandbox container to be modified via drag and drop or Share Extensions?

I have a shoebox type (as opposed to document based) OS X app that stores images in the app's sandbox container.
These images can be shared via Share Extensions (in form of a NSURL) or exported via drag and drop.
When an image is shared to an image editor (e.g. Acorn offers a Share Extension), or dropped on an image editor, the image editor opens the file from within my sandbox container and can now alter, rename or delete this file - which can lead to all kinds of inconstancies in my app.
First, I was surprised, because I thought, files in the sandbox can only be accessed by the app itself. But it seems this is not the case, when I intentionally share the NSURL.
So how can I prevent that someone can alter files in my sandbox container while still offering them for drag and drop and to Share Extensions?
I tried not sharing NSURLs but NSImages, but many Share Extensions do not work with NSImages, so this is not a good option.
Is it a possibility to write-protect the files in the sandbox?
Should I always make a copy of an image to a temporary location, before I offer it for sharing or drag and drop (could be slow for big images?)
I am happy to hear your suggestions or learn more about the problem.
Create a bookmark of the NSURL.
So the user can still rename, move and delete the file, but you notice it and know the new location and name and still are able to access the file. Should work even if it's outside your sandbox.
So you can handle this.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/
That's one of the benefits working with NSURL and not with a simple path string.

Display PDF file in LocalState folder in Windows 8 app in Cordova

My application downloads a PDF and stores it in the LocalState folder for my Windows 8 app.
I have a link within the app that I would like to show the PDF when the user clicks it.
I've tried displaying it using ms-appdata:///local/pdfs/filename.pdf in a window.open call and I also tried using the InAppBrowser plugin within cordova with no luck. Additionally, I've tried the following:
var uri = new Windows.Foundation.Uri('ms-appdata:///local/pdfs/filename.pdf');
var file = Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri);
Windows.System.Launcher.launchFileAsync(file).done();
I know the file exists as I'm getting a file result back. Just not sure how to allow the user to view it.
By design, the local appdata folder on Windows is accessible only to that app, or to full-trust desktop applications (and this is probably true of similar sandboxed locations on other platforms). As a result, a Windows Store app that gets launched with Launcher.launchFileAsync won't be able access that location (nor can a webview process, which is also sandboxed). If a desktop application gets launched, on the other hand, it probably can access the file, but you can't tell ahead of time if that's the case. Bottom line is that local appdata isn't a good location for letting other apps get at the file.
You'll need to save the file in another location that is accessible to other apps. There are two approaches here, both of which will require a little user interaction to select a location, so they can place the PDFs anywhere they want:
Have the user select a save folder for your app, which they can do once. You would invoke the FolderPicker for this purpose, and save the selected folder in the FutureAccessList. This way you can have the user select the save folder, which grants you consent to save there, and by saving it in the FutureAccessList you can retrieve it in subsequent sessions without having to ask the user again. Refer to the File Picker Sample and the File Access Sample for more.
Have the user select a save location for each individual file, using the FilePicker (see the same sample), and you can also use the access cache to save permissions to those individual locations if you need them later.
There might be Cordova plugins that work with these APIs too, but I haven't checked. Either way, once the file is in an accessible location, launching the file should work just fine.
As an alternate solution, you could consider rendering the PDFs directly in your app. Windows has an API for this in Windows.Data.Pdf, with an associated sample. There might be a plugin or other JS libraries that could also work for this.

How can I associate a file with my app?

I have a Cocoa app "PDFHistory" on Mac OS X that uses the NSDocument architecture to save and load PDF files that are internally formatted specially for my app. I want to make it so whenever I save a file (e.g., "mydoc.pdf") from PDFHistory, then subsequently double-clicking on mydoc.pdf will automatically open it in PDFHistory.app. However, I don't want to make it so all .pdf files are automatically opened in PDFHistory, but rather use the system default (probably Preview.app). The .pdf suffix is a requirement, though, since I need the user to be able to e-mail the files to other users who can view the file in their default PDF viewer.
The problem is that if I set the LSHandlerRank to "Owner", then all .pdf files will be opened with PDFHistory, which is bad (since I only understand the internals of the .pdf file that PDFHistory wrote out). But if I set LSHandlerRank to "Alternate", then all .pdf files will be opened to the system default app (Preview.app), which is confusing for the user who had just created the file using my app.
Once upon a time, "creator codes" could be used to implement this sort of capability, but launch services started ignoring them back in Snow Leopard (see http://tidbits.com/article/10537). UTIs are not a substitute that provide this capability (see http://boredzo.org/blog/archives/2009-09-22/how-not-to-use-utis).
Using Finder to get info on the file allows the user to specify a specific app to use to open the specific file. This supposedly works by setting a "usro" property in a the file's resource. There is some open-source code to mimic this behavior (https://github.com/AlanQuatermain/SetAppAffinity), but is uses deprecated functions, and so would cause Apple to reject the app from the App Store. Similarly, people have posted AppleScript to set this property (https://discussions.apple.com/thread/2597365), but sandboxing would prevent me from invoking it.
Although the .pdf suffix is a requirement in order to be able to send the files to users on other systems/platforms, I considered trying to have the suffix registered with two extensions as ".phistory.pdf", which would allow "file.phistory.pdf" to be opened in PDFHistory, but "file.pdf" would be opened in the default PDF viewer. However, this simply didn't work: it appears that the final suffix is the only one used by launch services, and everything before that is ignored.
So is there any way to have my app be the default app for opening files that it created itself?

Is it possible to check in/out files from a webserver with a FF-plugin or Chrome extension?

I am creating a CMS and want to know if its possible to download a folder, edit things and upload it back to the server without much user interaction.
For example just press a checkout button and the files are stored on your computer. after you are finished editing these files you press the checkin button. no selecting files again and such things.
Is it possible to access the filesystem and up/download files after a user gives you the permission?
In Firefox - yes, add-ons have full access to the hard drive and can download/upload files. See for example FireFTP, also code snippets.
In Chrome - no, extensions are not allowed to access the hard drive, other than limited access via File System API (which is a virtual file system actually). Best you can do is including a binary NPAPI plugin into your extension and making it write to disk. Users will see lots of scary warnings when installing this extension.

Resources