Skip to content

Commit

Permalink
Add flags to support all other unix systems. (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngo Iok Ui (Wu Yu Wei) authored Jul 21, 2021
1 parent 134af02 commit c0d0a78
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changes/unix-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"wry": patch
---

Add flags to support all other possible unix systems.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
thiserror = "1.0"
url = "2.2"
tao = { version = "0.4", default-features = false, features = [ "serde" ] }
#tao = { version = "0.4", default-features = false, features = [ "serde" ] }
tao = { git = "https://github.com/tauri-apps/tao", branch = "dev", default-features = false, features = [ "serde" ] }

[dev-dependencies]
anyhow = "1.0.42"
chrono = "0.4.19"
tempfile = "3.2.0"

[target."cfg(target_os = \"linux\")".dependencies]
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
webkit2gtk = { version = "0.11", features = [ "v2_18" ] }
webkit2gtk-sys = "0.13.0"
gio = "0.9"
Expand Down
5 changes: 1 addition & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

#[cfg(target_os = "linux")]
#[cfg(not(target_os = "macos"))]
fn main() {}

#[cfg(target_os = "macos")]
fn main() {
println!("cargo:rustc-link-lib=framework=WebKit");
}

#[cfg(target_os = "windows")]
fn main() {}
26 changes: 21 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ extern crate objc;

use std::sync::mpsc::{RecvError, SendError};

#[cfg(not(target_os = "linux"))]
use crate::application::window::BadIcon;
pub use serde_json::Value;
use url::ParseError;
Expand All @@ -108,13 +107,31 @@ pub type Result<T> = std::result::Result<T, Error>;
#[non_exhaustive]
#[derive(Error, Debug)]
pub enum Error {
#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
#[error(transparent)]
GlibError(#[from] glib::Error),
#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
#[error(transparent)]
GlibBoolError(#[from] glib::BoolError),
#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
#[error("Fail to fetch security manager")]
MissingManager,
#[error("Failed to initialize the script")]
Expand All @@ -137,7 +154,6 @@ pub enum Error {
UrlError(#[from] ParseError),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[cfg(not(target_os = "linux"))]
#[error("Icon error: {0}")]
Icon(#[from] BadIcon),
#[cfg(target_os = "windows")]
Expand Down
24 changes: 21 additions & 3 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ mod web_context;

pub use web_context::WebContext;

#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
mod webkitgtk;
#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
use webkitgtk::*;
#[cfg(any(target_os = "macos", target_os = "ios"))]
mod wkwebview;
Expand Down Expand Up @@ -284,7 +296,13 @@ pub struct WebView {
// blocks and raw pointer properly.
impl Drop for WebView {
fn drop(&mut self) {
#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
unsafe {
use crate::application::platform::unix::WindowExtUnix;
use gtk::prelude::WidgetExtManual;
Expand Down
33 changes: 28 additions & 5 deletions src/webview/web_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,22 @@ impl WebContextData {
}
}

#[cfg(not(target_os = "linux"))]
#[cfg(not(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
)))]
struct WebContextImpl;

#[cfg(not(target_os = "linux"))]
#[cfg(not(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
)))]
impl WebContextImpl {
fn new(_data: &WebContextData) -> Self {
Self
Expand All @@ -71,11 +83,22 @@ impl WebContextImpl {
fn set_allows_automation(&mut self, _flag: bool) {}
}

#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
use self::unix::WebContextImpl;

#[cfg(target_os = "linux")]
#[cfg_attr(doc_cfg, doc(cfg(target_os = "linux")))]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
pub mod unix {
//! Unix platform extensions for [`WebContext`](super::WebContext).
Expand Down

0 comments on commit c0d0a78

Please sign in to comment.