Skip to content

Commit 0a8f2b6

Browse files
authored
fix webview implementation in linux (#26)
1 parent c30d315 commit 0a8f2b6

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ crate-type = ["cdylib"]
1212
[dependencies]
1313
napi = { version = "3.8.2", default-features = true, features = ["napi9"] }
1414
napi-derive = "3.5.1"
15-
tao = "0.34.5"
15+
tao = { version = "0.34.5", features = ["rwh_06"] }
1616
wry = { version = "0.53.5", features = ["devtools", "fullscreen"] }
1717

18+
[target.'cfg(target_os = "linux")'.dependencies]
19+
gtk = "0.18"
20+
glib = "0.18"
21+
1822
[build-dependencies]
1923
napi-build = "2"
2024

src/webview.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use napi_derive::*;
99
use tao::dpi::{LogicalPosition, LogicalSize};
1010
use wry::{http::Request, Rect, WebViewBuilder};
1111

12+
#[cfg(target_os = "linux")]
13+
use tao::platform::unix::WindowExtUnix;
14+
#[cfg(target_os = "linux")]
15+
use wry::WebViewBuilderExtUnix;
16+
1217
use crate::{HeaderData, IpcMessage};
1318

1419
/// Represents the theme of the window.
@@ -215,25 +220,20 @@ impl JsWebview {
215220
)
216221
};
217222

218-
#[cfg(not(target_os = "linux"))]
219223
let webview = {
220-
if options.child.unwrap_or(false) {
221-
webview.build_as_child(&window).map_err(handle_build_error)
222-
} else {
223-
webview.build(&window).map_err(handle_build_error)
224+
#[cfg(target_os = "linux")]
225+
{
226+
webview.build_gtk(window.default_vbox().unwrap()).map_err(handle_build_error)
224227
}
225-
}?;
226-
227-
#[cfg(target_os = "linux")]
228-
let webview = {
229-
if options.child.unwrap_or(false) {
230-
webview
231-
.build_as_child(&window)
232-
.map_err(handle_build_error)?
233-
} else {
234-
webview.build(&window).map_err(handle_build_error)?
228+
#[cfg(not(target_os = "linux"))]
229+
{
230+
if options.child.unwrap_or(false) {
231+
webview.build_as_child(window).map_err(handle_build_error)
232+
} else {
233+
webview.build(window).map_err(handle_build_error)
234+
}
235235
}
236-
};
236+
}?;
237237

238238
Ok(Self {
239239
webview_inner: webview,

0 commit comments

Comments
 (0)