slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 568 forks source link

Use slint inside a devcontainer #3234

Closed BuriKizilkaya closed 1 year ago

BuriKizilkaya commented 1 year ago

Hi

Can I use slint inside your devcontainer. I was able to install dependencies and if execute the command cargo run, then the Window shows up. If I click on the "Show Preview" Button, then I get the following error:

thread 'main' panicked at 'Failed to initialize any backend! Wayland status: XdgRuntimeDirNotSet X11 status: XOpenDisplayFailed', /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.28.6/src/platform_impl/linux/mod.rs:757:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Info  - 8:58:09 PM] Connection to server got closed. Server will restart.
The Slint Language Server crashed. This is a bug.
Please open an issue on https://github.com/slint-ui/slint/issues
[Error - 8:58:09 PM] Request workspace/executeCommand failed.
Error: Connection got disposed.
    at Object.dispose (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/connection.js:1044:27)
    at Object.dispose (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-languageclient/lib/common/client.js:73:35)
    at LanguageClient.handleConnectionClosed (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-languageclient/lib/common/client.js:2424:42)
    at LanguageClient.handleConnectionClosed (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-languageclient/lib/node/main.js:155:15)
    at closeHandler (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-languageclient/lib/common/client.js:2411:18)
    at CallbackList.invoke (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/events.js:55:39)
    at Emitter.fire (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/events.js:117:36)
    at closeHandler (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/connection.js:256:26)
    at CallbackList.invoke (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/events.js:55:39)
    at Emitter.fire (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/events.js:117:36)
    at StreamMessageReader.fireClose (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/messageReader.js:40:27)
    at Socket.<anonymous> (/home/vscode/.vscode-server/extensions/slint.slint-1.1.1/node_modules/vscode-jsonrpc/lib/common/messageReader.js:125:42)
    at Socket.emit (node:events:525:35)
    at Pipe.<anonymous> (node:net:757:14)

The main issue is Failed to initialize any backend!.

tronical commented 1 year ago

Somehow the preview needs to be able to access our X server or wayland compositor, and it appears to be running inside the container. That means you may need to configure your devcontainer to forward for example the DISPLAY environment variable (for x11). How does your devcontainer.json look like? What's your host operating system?

I wonder if perhaps we should try to detect this (lack of availability of connection to display) and disable the "Show Preview" functionality. It's a little tricky to do just with winit, because that just panics (we don't get an error), but we could try to look for the corresponding variables yourselves to detect the lack of display.

tronical commented 1 year ago

(Tagging this as a bug, because either there's a way to make it work or we should try to detect and disable "Show Preview" IMO)

ogoffart commented 1 year ago

Thanks for the bug report.

For this case when the lsp server can't access the display server, there is the "Slint › Preview: Provided By Editor" setting that can be enabled to force it to be rendered with wasm on a tab. image

Ideally we'd detect that we are in a dev container and enable that automatically. (We do that for codespace in our master branch already)

But the problem is that winit panics instead of reporting an error we can catch.

hunger commented 1 year ago

I do all my Linux development in containers, too, and had no trouble with Slint so far. I do have wayland/X11 forwarded from the container to the outside machine for it to render UIs, but most dev container tools do set that up for you.

E.g. toolbox works out of the box.

We should handle the case where no display is found though and forward to the embedded WASM viewer in that case. The user experience you had is horrible, we need to fix that.

hunger commented 1 year ago

The root cause of the preview failing when it can not connect to a display is #204. An oldie but goldie. You can work around the issue nowadays with the WASM previewer.

All this container thing is just a way to produce a situation where no display can be found on Linux. Let's continue with the old issue.

But thank you for taking the time to report your issue, it is aprpeciated!