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
336 stars 59 forks source link

Capacitor Filesystem #91

Open ak1dos opened 3 years ago

ak1dos commented 3 years ago

I added electron to my capacitor project, I'm having problems with the Filesystem plugin. I downloaded some pdf files and saved with the method

let result = await Filesystem.writeFile ({
  path: path,
  data: fileData,
  directory: FilesystemDirectory.Data
})

my problem is being able to show them to electron api. if I try to fetch the uri of the saved file I see it with the Filesystem plugin, but I don't understand where it is saved or how to use it with electron.

let result = await Filesystem.getUri ({
  path: pathFile,
  directory: FilesystemDirectory.Data
});

console.log (result.uri) /DATA/example.pdf

schwenkreis commented 3 years ago

What does it mean, that this has been set to "plugin update needed"? Is there any plan for solving this? Any idea regarding the timeline? My project is blocked by this issue.

digaus commented 3 years ago

Any news here? We cannot expect to use electron without a Filesystem access ...

digaus commented 3 years ago

@IT-MikeS Couldnt we add it from here: https://github.com/ionic-team/capacitor/tree/2.x/electron/src/electron directly to @capacitor-community/electron sources?

Or should I create a @capacitor-community/filesystem plugin which just implements it for electron? What is the best approach here?

IT-MikeS commented 3 years ago

After 4 is released the official file system plug-in for capacitor will need a pr giving it electron support.

At this point you can either create your own plugin or expose your own file api using electrons context bridge system for use in the renderer processes

digaus commented 3 years ago

@IT-MikeS thanks for the reply. I am currently trying to create my own plugin implementing the Filesystem API.

So far I kinda got it working but am running into an issue where the Promises of the plugin are never resolved. I do not know why this is the case as my other plugins do not have this issue (edit: my other plugins now also have this issue ...):

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

The calls are working (folders and files get created when using mkdir or writeFile) but they are never resolved or rejected.

When the Plugin is supposed to reject, I get following error;

Terminal:

args
[ { path: 'files', directory: 'DOCUMENTS', recursive: false } ]
theCall
[Function: mkdir]
isPromise
true
(node:16100) UnhandledPromiseRejectionWarning: Error: EEXIST: file already exists, mkdir 'C:\Users\User\Documents\files'        
(Use `electron --trace-warnings ...` to show where the warning was created)
(node:16100) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:16100) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Dev Tools:

sending sync ipc from renderer of channel: Filesystem-mkdir

TypeError: f.mkdir(...).catch is not a function
    at e.<anonymous> (9289.8eb515d713fc4a521e0b.js:1)
    at Generator.next (<anonymous>)
    at s (9289.8eb515d713fc4a521e0b.js:1)
    at e.invoke (polyfills.4efd05b7e2c2183e44e6.js:1)
    at Object.onInvoke (main.9a92667a6a0c7cd9525e.js:1)
    at e.invoke (polyfills.4efd05b7e2c2183e44e6.js:1)
    at t.run (polyfills.4efd05b7e2c2183e44e6.js:1)
    at polyfills.4efd05b7e2c2183e44e6.js:1
    at e.invokeTask (polyfills.4efd05b7e2c2183e44e6.js:1)
    at Object.onInvokeTask (main.9a92667a6a0c7cd9525e.js:1)

Any idea whats the issue here?

IT-MikeS commented 3 years ago

What version of the platform are you using out of curiosity?

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