vscode-drawio icon indicating copy to clipboard operation
vscode-drawio copied to clipboard

Neither .drawio.png nor .drawio.svg files are shown via liveshare

Open jinjamator opened this issue 4 years ago • 6 comments

First of all thanks for this great extension. I tried liveshare editing and it works for .drawio files like a charm. If we use .drawio.png or .drawio.svg files nothing of the content is visible on the participants screen. Also if a participant adds a node the node is not visible on the master. We assume, that only text document sharing is supported by liveshare.

jinjamator avatar Jan 25 '21 10:01 jinjamator

Thank you!

That is interesting - .drawio.svg files should work with liveshare in theory! I guess conflicts are much more likely to happen though, as small changes update the entire drawio encoding in SVG files. Conflicts are problematic if many users edit the same diagram concurrently. Conflicts should not happen if at a given time only one participant edits the file.

I didn't really test .drawio.png in liveshare yet, but it does not use text documents. Binary files always conflict. It uses the workspace API though, so in theory it should work too.

But yes, .drawio files work best (they also yield the best gif diffs for the same reason). Sadly, I doubt there is an easy way to combine the advantages of .drawio and .drawio.svg files.

hediet avatar Jan 25 '21 10:01 hediet

I see. We played around a little today and SVG files do work, but, as we can reproduce, not always reliable (needs more testing, but it seems, closing and opening the file fixes the problems). PNG files never work, at least we had not a single successful attempt. For PNG (produced by your extension), I know that the XML is urlencoded text in the tEXt section of the file. In the SVG it's deflated and urlencoded in the content attribute of the svg tag. I neither know liveshare nor vscode nor your codebase so I don't know if this problem is even fixable, but is there a way of sending the plain xml changes via liveshare (which works very good for plain drawio files) and keep svg and/or png?

jinjamator avatar Jan 25 '21 20:01 jinjamator

Thanks for the tests!

but is there a way of sending the plain xml changes via liveshare

Not directly.

The architecture is as following: For *.drawio and *.drawio.svg files, this extensions implements a custom text editor. Custom text editors get a text document by vscode that they can write to and read from (+ listen to change events). Liveshare synchronizes text documents transparently, so for plain content synchronization, the drawio extension does not need to know liveshare (cursor/selection synchronization uses liveshare apis though). I think it is not really possible to override that: liveshare synchronizes what will get saved on disk.

For *.drawio.png files, this extension implements a custom binary editor - they need to manage their own documents. Hence they are not synced by liveshare automatically. However, they write to the workspace on save (I forgot that) and the workspace should be synchronized by liveshare. So yeah, without saving, they don't work with liveshare. I guess smooth live share support could be added for custom binary editors, as liveshare does not get in the way. It will be way harder for custom text editors though, as liveshare will sync text documents automatically.

It is very interesting that liveshare works so much better for *.drawio files than for *.drawio.svg files.

hediet avatar Jan 25 '21 20:01 hediet

Ok. I see. Perhaps, as a workaround, some sort of auto export on save would fix this for me. EG.: Editing .drawio together. On save, save the .drawio and export to .drawio.png. If I find time, i'll dig in your code. Thanks for clarifying things.

jinjamator avatar Jan 26 '21 11:01 jinjamator

auto export on save would fix this for me.

This is not entirely trivial. I don't know if a text document has an event for saves. Also, VS Code has optional auto save! Also, you only want the host to export the diagram in liveshare scenarios to avoid conflicts, even if a guest saves the file.

hediet avatar Jan 26 '21 11:01 hediet