lunapaint / vscode-luna-paint

A raster image editor extension for VS Code
https://marketplace.visualstudio.com/items?itemName=Tyriar.luna-paint
279 stars 25 forks source link

Unable to save files edited via Luna Paint to backend #192

Closed tyaginidhi closed 11 months ago

tyaginidhi commented 1 year ago

Our extension Power Platform Tools loads images associated with a website (Power pages - part of Power platform) from backend (Dataverse). I tried installing Luna paint and I am able to edit these images - but on save, the call to backend for saving these files in our database did not happen.

In Power platform tools extension - we have our own FileSystemProvider implementation - and leverage the writeFile() call to save the file content edited by user to our backend as well.

What is the delta we need to address to make sure our users are able to use Luna paint to edit files without our extension natively building this support? Or, is there a bug which is not allowing this to automatically happen for images loaded via our extension?

Tyriar commented 1 year ago

I tested this in github.dev which also uses a FIleSystemProvider and it worked fine:

image

Do you get some error when trying to save, either as a notification or in the devtools console?

tyaginidhi commented 1 year ago

Thats the tricky part - there are no errors in console on Save action. There is just this on console on file edit and save:

image

File appears to be saved initially - but on vscode.dev tab reload this is the message for the image file open in editor: (this error though is not consistent in occurence) 9247.js:1 Uncaught (in promise) Error: Not enough bytes in file for png signature (0) at g (9247.js:1:7657) at Module._ (9247.js:1:9667) at s (vscode.main.js:1:71773) at async Se.openFile (vscode.main.js:1:204643) at async gn (vscode.main.js:1:310191) at async vscode.main.js:1:313536

This notification below is consistent - which seems reasonable since the changes to image file are not saved on the backend database.

image
Tyriar commented 1 year ago

This is what I'm seeing for vscode.dev/github/...:

Recording 2023-08-23 at 04 54 24

Since it's working for that I suspect there's something going wrong on the power platform end. Can you verify the writeFile call is getting the data and saving correctly?

tyaginidhi commented 1 year ago

Confirmed that there is no call coming to writeFile implementation. This is the writeFile code we have, for reference. And this is where we are registering the FSProvider.

Tyriar commented 1 year ago

Weird... If it was Luna Paint's fault I would expect some error showing up in devtools.

Could you enable trace logging via the Set Log Level command, try save and then grab the log from extension host channel in the output panel?

tyaginidhi commented 1 year ago

Here are the logs from Image file load to edit and save. LunaPaintImageEditSaveLogVerbose.txt

Tyriar commented 1 year ago

Oh looks like that's from devtools, I meant from here:

image

tyaginidhi commented 1 year ago

aha - i got it wrong - here are the logs from output channel for file open, edit and save action - though i noticed that there is not much in logs apart from diagnostics and this command: 2023-08-25 13:02:18.863 [trace] ExtHostCommands#executeCommand _update.state

Here is the file for reference: LunaPaintImageEditSaveLogVerbose_OutputChannel.txt

I am using npx to serve the extension files on localhost and consume in vscode.dev insiders URL: npx serve --cors -l 5000 --ssl-cert $HOME/certs/localhost.pem --ssl-key $HOME/certs/localhost-key.pem

tyaginidhi commented 1 year ago

Also - after edit-save scenario I tried opening the file from "File explorer", and I see the file is rendered with the last saved changes - so I think the changes are getting written to Virtual File System(VFS), but not to our database. Most likely since the call is possibly going to vscode.fs.writeFile() function??? and not to the provider implementation of writeFile? Just a theory - so not totally sure - but attaching the logs - maybe something amiss will show-up here.

LunaPaintImageEditSaveLogVerbose_OutputChannel_fileOpensceanrio.txt

Tyriar commented 1 year ago

Do you have the same problem with any other custom webview editors, like tldraw or draw.io integration?

tyaginidhi commented 1 year ago

Haven't tried these before but seems both of these extension support their own specific file formats unlike Luna paint - will have to get back on this.

Tyriar commented 1 year ago

The fact that they work on special file extensions shouldn't matter, the custom editors API which is what they all use replace the default editor and should work the same (in the image case it's the image preview).

tyaginidhi commented 11 months ago

@Tyriar I am now getting call to the writeFIle call in our FS implementation - so have closed the issue raised on Vscode-dev. I am checking the reload file sceanrio after the save file is successful to our backend. Seeing some issue there on correct file read on reload. Will debug this and raise a seprate issue as needed. Closing this issue down since it is now an action on our extension. On, why the initial writeFile call was not happening? I do not have a root-cause, but possibly worth trying on other similar issues. Seems like if there was any issue its not reproing any more.

For reference: https://github.com/microsoft/vscode-dev/issues/988

tyaginidhi commented 10 months ago

@Tyriar Good news. I have the PR ready to make use of Luna paint to help enable image edits for files loaded by our extension. Here is the PR: https://github.com/microsoft/powerplatform-vscode/pull/733

DO you mind reviewing it for accuracy?

Thank you for all the time spent in making this possible! We will be releasing it sometime next week, or after!