Skip to content

Commit

Permalink
Refactor new method entry point to rwh (#1041)
Browse files Browse the repository at this point in the history
* Refactor new method entry point to rwh

* Update doc and add change file

* Fix mac and ios compile error

* Add new_as_child

* Add rhw_04, 05 06 flags

* Update android port

* Remove winit CI

* Fix android bindings

* windows implementation

* Update Cargo.toml

* Fix macOS and iOS

* Fix Android

* fix is_child on WkWebView

* x11 impl

* expose `new_gtk`

* fix winit-gtk version

* remove undecorated resizing handling

* implement set_position and set_size for child gtk in x11

* fix macos

* more fixes

* one more time

* unreachable

* update actions

* fix windows

* some clippy

* Add documentation and fix clippy

* Fix windows clippy error

* Fix android biuld

* Fix documentation test

* Fix android again

* Reduce clippy noise

* use rc?

* refine some documentation, add set_visible

* fix set_visible

* impl set_visible on Windows

* fix doctests

* more set_visible fixes

* fix windows

* unsafe

* fix set size for child webviews

* fix initial visibility with new_gtk

* refine examples

* fix wpgu example

* fix examples on windows and macos

* use a better workaround

* make set_size work on x11

* Fix size in multiwebview example

* Add visible method on macOS and iOS

* remvoe `tao` from android backend and update documentation

* fix winit example

* Add new_as_content_view on macOS

* allow using raw-window-handle v0.5 [skip ci]

* change trait name [skip ci]

* fix linux impl [skip ci]

* fix android build [skip ci]

* fix windows build

* fix(macos): do not autoresize on child webview [skip ci]

* fix macos coordinates [skip ci]

* fix example [skip ci]

* fixed child on macos [skip ci]

* fix docs typos [skip ci]

* fix webview position when it's not a child [skip ci]

* replace new_as_content_view with new_as_subview

* with_as_subview instead of constructor [skip ci]

* fix position/size when as_subview is true

* lint & fmt

* Fix ios build

* Fix cargo test

* Fix mac build

* Update macOS contrusctors

* cargo fmt

* impl drop on Windows

* fix child transparency on Windows (still needs PRs in tao and winit)

* fix winit usage in the examples, use rwh_05 only for now

* fix tests

* add webview.focus

* fix dropping on Linux

* chore clean examples

* implement focus on Linux

* macos focus

---------

Co-authored-by: amrbashir <[email protected]>
Co-authored-by: Lucas Nogueira <[email protected]>
Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
4 people committed Nov 7, 2023
1 parent 81cfa37 commit 783b142
Show file tree
Hide file tree
Showing 71 changed files with 3,426 additions and 3,449 deletions.
17 changes: 17 additions & 0 deletions .changes/rwh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"wry": minor
---

Refactor new method to take raw window handle instead. Following are APIs got affected:
- `application` module is removed, and `webivew` module is moved to root module.
- `WebviewBuilder::new`, `Webview::new` now take `RawWindowHandle` instead.
- Attributes `ipc_handler`, `file_drop_handler`, `document_change_handler` don't have window parameter anymore.
Users should use closure to capture the types they want to use.
- Position field in `FileDrop` event is now `Position` instead of `PhysicalPosition`. Users need to handle scale factor
depend on the situation they have.
- `Webview::inner_size` is removed.

This also means that we removed `tao` as a dependency completely which required some changes to the Android backend:
- We exposed the `android_setup` function that needs to be called once to setup necessary logic.
- Previously the `android_binding!` had internal call to `tao::android_binding` but now that `tao` has been removed,sa
the macro signature has changed and you now need to call `tao::android_binding` yourself, checkout the crate documentation for more information.
29 changes: 21 additions & 8 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
name: Audit
# Copyright 2022-2022 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

name: audit

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
push:
branches:
- dev
paths:
- 'Cargo.lock'
- 'Cargo.toml'
pull_request:
paths:
- "Cargo.lock"
- "Cargo.toml"
- 'Cargo.lock'
- 'Cargo.toml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
audit-rust:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: rust audit
uses: actions-rs/audit-check@v1
- uses: actions/checkout@v4
- uses: rustsec/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
17 changes: 3 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jobs:
strategy:
fail-fast: false
matrix:
rust_version: [stable]
platform:
- { target: x86_64-pc-windows-msvc, os: windows-latest }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
Expand All @@ -28,7 +27,7 @@ jobs:
if: contains(matrix.platform.target, 'gnu')
run: |
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.1 libgtksourceview-3.0-dev libayatana-appindicator3-dev
sudo apt-get install -y libwebkit2gtk-4.1-dev
- name: install webview2 (windows only)
if: contains(matrix.platform.target, 'windows')
Expand All @@ -44,20 +43,10 @@ jobs:

- name: build tests and examples
shell: bash
if: (
!contains(matrix.platform.target, 'android') &&
!contains(matrix.platform.target, 'ios'))
if: (!contains(matrix.platform.target, 'android') && !contains(matrix.platform.target, 'ios'))
run: cargo test --no-run --verbose --target ${{ matrix.platform.target }}

- name: run tests
if: (
!contains(matrix.platform.target, 'android') &&
!contains(matrix.platform.target, 'ios'))
if: (!contains(matrix.platform.target, 'android') && !contains(matrix.platform.target, 'ios'))
run: cargo test --verbose --target ${{ matrix.platform.target }} --features linux-body

- name: build wry with winit
if: (
contains(matrix.platform.target, 'gnu') ||
contains(matrix.platform.target, 'windows') ||
contains(matrix.platform.target, 'apple'))
run: cargo build --no-default-features --features winit --target ${{ matrix.platform.target }}
48 changes: 48 additions & 0 deletions .github/workflows/clippy-fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2022-2022 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

name: clippy & fmt

on:
push:
branches:
- dev
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
clippy:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
- name: install system deps
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- run: cargo clippy --all-targets

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- run: cargo fmt --all -- --check
4 changes: 1 addition & 3 deletions .github/workflows/covector-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/checkout@v4
- name: covector status
uses: jbolda/covector/packages/action@covector-v0
id: covector
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/covector-version-or-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: version or publish
name: covector version or publish

on:
push:
Expand All @@ -15,15 +15,16 @@ jobs:
successfulPublish: ${{ steps.covector.outputs.successfulPublish }}

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/checkout@v4

- name: cargo login
run: cargo login ${{ secrets.ORG_CRATES_IO_TOKEN }}

- name: git config
run: |
git config --global user.name "${{ github.event.pusher.name }}"
git config --global user.email "${{ github.event.pusher.email }}"
- name: covector version or publish (publish when no change files present)
uses: jbolda/covector/packages/action@covector-v0
id: covector
Expand All @@ -34,14 +35,15 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
command: 'version-or-publish'
createRelease: true

- name: Create Pull Request With Versions Bumped
id: cpr
uses: tauri-apps/create-pull-request@v3
if: steps.covector.outputs.commandRan == 'version'
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Publish New Versions"
commit-message: "publish new versions"
labels: "version updates"
branch: "release"
title: Apply Version Updates From Current Changes
commit-message: 'apply version updates'
labels: 'version updates'
branch: 'release'
body: ${{ steps.covector.outputs.change }}
31 changes: 0 additions & 31 deletions .github/workflows/fmt.yml

This file was deleted.

71 changes: 39 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,71 +1,67 @@
workspace = { }
workspace = {}

[package]
name = "wry"
version = "0.34.2"
authors = [ "Tauri Programme within The Commons Conservancy" ]
authors = ["Tauri Programme within The Commons Conservancy"]
edition = "2021"
license = "Apache-2.0 OR MIT"
description = "Cross-platform WebView rendering library"
readme = "README.md"
repository = "https://github.com/tauri-apps/wry"
documentation = "https://docs.rs/wry"
categories = [ "gui" ]
categories = ["gui"]

[package.metadata.docs.rs]
no-default-features = true
features = [ "tao", "file-drop", "protocol" ]
features = ["file-drop", "protocol"]
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
"x86_64-apple-darwin"
"x86_64-apple-darwin",
]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = [ "file-drop", "objc-exception", "protocol", "tao" ]
objc-exception = [ "objc/exception" ]
file-drop = [ ]
protocol = [ ]
devtools = [ ]
transparent = [ ]
fullscreen = [ ]
linux-body = [ "webkit2gtk/v2_40" ]
mac-proxy = [ ]
default = ["file-drop", "objc-exception", "protocol"]
objc-exception = ["objc/exception"]
file-drop = []
protocol = []
devtools = []
transparent = []
fullscreen = []
linux-body = ["webkit2gtk/v2_40"]
mac-proxy = []

[dependencies]
libc = "0.2"
log = "0.4"
once_cell = "1"
serde = { version = "1.0", features = [ "derive" ] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
url = "2.4"
tao = { version = "0.23", default-features = false, features = [ "serde" ], optional = true }
http = "0.2.9"

[dev-dependencies]
http-range = "0.1.5"
base64 = "0.21"
http = "0.2"
raw-window-handle = { version = "0.5", features = ["std"] }

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
javascriptcore-rs = { version = "=1.1", features = [ "v2_28" ] }
webkit2gtk = { version = "=2.0", features = [ "v2_38" ] }
javascriptcore-rs = { version = "=1.1", features = ["v2_28"] }
webkit2gtk = { version = "=2.0", features = ["v2_38"] }
webkit2gtk-sys = "=2.0"
gtk = "0.18"
soup3 = "0.5"
winit = { version = "0.29", package = "winit-gtk", features = [ "serde" ], optional = true }
x11-dl = "2.9"
gdkx11 = "0.18"

[target."cfg(target_os = \"windows\")".dependencies]
webview2-com = "0.27"
windows-implement = "0.51"
dunce = "1"
winit = { version = "0.28", features = [ "serde" ], optional = true }

[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.51"
features = [
[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.51"
features = [
"implement",
"Win32_Foundation",
"Win32_Graphics_Gdi",
Expand All @@ -80,7 +76,7 @@ winit = { version = "0.28", features = [ "serde" ], optional = true }
"Win32_Globalization",
"Win32_UI_HiDpi",
"Win32_UI_Input",
"Win32_UI_Input_KeyboardAndMouse"
"Win32_UI_Input_KeyboardAndMouse",
]

[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
Expand All @@ -89,11 +85,22 @@ cocoa = "0.25"
core-graphics = "0.23"
objc = "0.2"
objc_id = "0.1"
winit = { version = "0.28", features = [ "serde" ], optional = true }

[target."cfg(target_os = \"android\")".dependencies]
crossbeam-channel = "0.5"
html5ever = "0.26"
kuchiki = { package = "kuchikiki", version = "0.8" }
sha2 = "0.10"
base64 = "0.21"
jni = "0.21"
ndk = "0.7"
ndk-sys = "0.4"
ndk-context = "0.1"
tao-macros = { version = "0.1.0" }

[dev-dependencies]
http-range = "0.1.5"
pollster = "0.3.0"
tao = { git = "https://github.com/tauri-apps/tao", default-features = false, features = ["rwh_05"] }
wgpu = "0.18.0"
winit = { version = "0.29", features = ["rwh_05"] }
Loading

0 comments on commit 783b142

Please sign in to comment.