capacitor-community / electron

Deploy your Capacitor apps to Linux, Mac, and Windows desktops, with the Electron platform! 🖥️
https://capacitor-community.github.io/electron/
MIT License
341 stars 59 forks source link

Accessing the filesystem #141

Open moltenice opened 3 years ago

moltenice commented 3 years ago

What's the recommended approach for an Ionic+Capacitor app to access the filesystem via Electron?

There's a couple of options:

  1. Ionic's File plugin: https://ionicframework.com/docs/native/file
  2. Capacitor's Filesystem plugin: https://capacitorjs.com/docs/apis/filesystem

But none of them allow me to access for example my home directory ~.

With pure Electron I can just use fs but that's not an option here as I'd like it to work with Android as well.

A recommended approach and perhaps a code example would be really appreciated as the current docs are only focused on iOS and Android for these plugins.

digaus commented 3 years ago

https://github.com/digaus/capacitor-community-filesystem

I made a dirty workaround. Works for my project so far. Better would be if we could somehow register the electron part to the original Filesystem Plugin.

Any idea if this would be doable somehow @IT-MikeS? Just pulling the definitions from @capacitor/filesystem and then register the electron part from @capacitor-community/filesystem to it?

That way would could implement @capacitor-community electron versions for the capacitor maintained plugins.

tachibana-shin commented 3 years ago

I have a plugin like node:fs for capacitor hope it helps you!

https://npmjs.org/package/capacitor-fs

moltenice commented 3 years ago

https://github.com/digaus/capacitor-community-filesystem

I made a dirty workaround. Works for my project so far. Better would be if we could somehow register the electron part to the original Filesystem Plugin.

Any idea if this would be doable somehow @IT-MikeS? Just pulling the definitions from @capacitor/filesystem and then register the electron part from @capacitor-community/filesystem to it?

That way would could implement @capacitor-community electron versions for the capacitor maintained plugins.

Thanks for sharing this, I will take a look.

So in general most Ionic/Capacitor plugins will not work with "@capacitor-community/electron" by default? It seems so strange that accessing the filesystem is highly unsupported cross platform here. Especially when a Cordova plugin exists and would work: https://cordova.apache.org/docs/en/10.x/reference/cordova-plugin-file/

For some reason the Ionic wrapper doesn't work for Electron.

moltenice commented 3 years ago

I have a plugin like node:fs for capacitor hope it helps you!

https://npmjs.org/package/capacitor-fs

Would this work on Android as well?

tachibana-shin commented 3 years ago

Tôi có một plugin như node:fscho tụ điện hy vọng nó sẽ giúp bạn! https://npmjs.org/package/capacitor-fs

Điều này cũng sẽ hoạt động trên Android?

Yes, this plugin working on all platform.

moltenice commented 3 years ago

Thank you very much @digaus and @tachibana-shin for your solutions! They will help me solve this issue :)

Hopefully an official Filesystem solution shows up for capacitor-community/electron at some point.

itsMapleLeaf commented 3 years ago

My requirement is similar to that of the OP: I want to target Android and Desktop, but I don't need arbitrary access to the whole filesystem. I only want files saved on disk, and it doesn't matter where.

This is the dummy code I'm using:

      await Filesystem.writeFile({
        path: 'test.json',
        data: JSON.stringify("hello world"),
        directory: Directory.Documents,
        encoding: Encoding.UTF8,
      })

If they are saved to disk, I can't find where. Could that be documented?

If they aren't, what would it take to be able to use the @capacitor/filesystem module and save files to disk? I've looked at the capacitor-fs plugin that was previous posted here, but I much prefer the API of the core FS module.

tachibana-shin commented 3 years ago

My requirement is similar to that of the OP: I want to target Android and Desktop, but I don't need arbitrary access to the whole filesystem. I only want files saved on disk, and it doesn't matter where.

This is the dummy code I'm using:

      await Filesystem.writeFile({
        path: 'test.json',
        data: JSON.stringify("hello world"),
        directory: Directory.Documents,
        encoding: Encoding.UTF8,
      })

If they are saved to disk, I can't find where. Could that be documented?

If they aren't, what would it take to be able to use the @capacitor/filesystem module and save files to disk? I've looked at the capacitor-fs plugin that was previous posted here, but I much prefer the API of the core FS module.

Oh I'll tell you where they'll be saved on Android:

Directory.Documents: /sdcard/Documents/ -- you will see dir Documents as soon as you enter the file manager Directory.Cache: /data/cache -- required root permission

BaxAndrei commented 3 years ago

If you use Directory.Documents as a path on a desktop (Windows 10 and Chrome). Where are the files saved? I notice that it is updated with data but I can't find it on the disk.

NeluQi commented 2 years ago

If you use Directory.Documents as a path on a desktop (Windows 10 and Chrome). Where are the files saved? I notice that it is updated with data but I can't find it on the disk.

I also join the question

I found out that the files saved with

await Filesystem.writeFile ({ path: 'AAAAtext222.txt', data: 'This is a test', directory: Directory.Documents, encoding: Encoding.UTF8, });

in the electron assembly for winodws 10

Save to IndexedDB image

I would like to save the files in the root of the program, so where exe. Who knows how?

jdgjsag67251 commented 2 years ago

I added a pull-request to the default Capacitor plugins repo that adds support for Electron to the Filesystem plugin: https://github.com/ionic-team/capacitor-plugins/pull/792

Estevete commented 1 year ago

If you use Directory.Documents as a path on a desktop (Windows 10 and Chrome). Where are the files saved? I notice that it is updated with data but I can't find it on the disk.

I also join the question

I found out that the files saved with

await Filesystem.writeFile ({ path: 'AAAAtext222.txt', data: 'This is a test', directory: Directory.Documents, encoding: Encoding.UTF8, });

in the electron assembly for winodws 10

Save to IndexedDB image

I would like to save the files in the root of the program, so where exe. Who knows how?

Hi mate @NeluQi! Did you find where the files are stored finally?