Skip to content

Commit

Permalink
refactor(core): add support to multiple webviews on a Tauri window (#…
Browse files Browse the repository at this point in the history
…8280)

* feat: update to latest wry

* wry dev branch [skip ci]

* fix linux [skip ci]

* refactor(runtime): split webview and window types

* split dispatch

* implement create_webview

* move webview message

* wip webview mod

* create webview manager, finish webview struct and builder

* fix tests and docs

* rename WindowUrl to WebviewUrl

* update examples

* event refactor

* update JS API

* fix events

* update example

* add WebviewWindow class on JS

* fix macos build

* allow creating window+webview on the same runtime call

* rename tauri://window-created to tauri://webview-created

* Window::add_child

* use inner_size from webview on macOS

* add multiwebview example

* automatically resize webviews on window resize

* fix tests

* set_position, set_size

* position, size getters

* set_focus

* add close fn

* update mock runtime

* lint [skip ci]

* fix inner_size getter [skip ci]

* import hwnd [skip ci]

* update webview bound ratios on set_size/set_position

* add auto_resize option

* fix android

* fix build on windows

* typo

* with_webview isnt desktop only

* add WebviewWindow rust struct (and builder)

* fix build on android

* license header

* fix macos/windows

* fix macos build

* resolve todo

* handle window not found

* hide unstable features

* document unstable feature [skip ci]

* webview plugin permissions

* hide more stuff

* fix doctests

* typos

* add change files

* fix examples

* rename hook
  • Loading branch information
lucasfernog authored Jan 24, 2024
1 parent 74a2a60 commit c77b403
Show file tree
Hide file tree
Showing 98 changed files with 14,583 additions and 4,217 deletions.
5 changes: 5 additions & 0 deletions .changes/api-event-resource-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:breaking
---

Removed event callback's `windowLabel` field and added a `windowSource` object instead.
5 changes: 5 additions & 0 deletions .changes/event-target-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:breaking
---

The event target is now an object so you can target either a window or a webview.
5 changes: 5 additions & 0 deletions .changes/hooks-webview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:breaking
---

The `invoke_system`, `on_page_load` hooks now gives you a `Webview` argument instead of a `Window`.
5 changes: 5 additions & 0 deletions .changes/move-window-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:breaking
---

Moved webview-specific APIs from the `Window` class to the `Webview` class.
5 changes: 5 additions & 0 deletions .changes/multiwebview-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:feat
---

Added support to multiwebview via the new `window` and `webview` modules.
7 changes: 7 additions & 0 deletions .changes/multiwebview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch:feat
"tauri-runtime": patch:feat
"tauri-runtime-wry": patch:feat
---

Add multiwebview support behind the `unstable` feature flag. See `WindowBuilder` and `WebviewBuilder` for more information.
5 changes: 5 additions & 0 deletions .changes/remove-window-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-utils": patch:breaking
---

Renamed `config::WindowUrl` to `config::WebviewUrl`.
5 changes: 5 additions & 0 deletions .changes/tauri-event-enum-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:breaking
---

Renamed `TauriEvent.WINDOW_FILE_DROP` to `TauriEvent.WEBVIEW_FILE_DROP`, `TauriEvent.WINDOW_FILE_DROP_HOVER` to `TauriEvent.WEBVIEW_FILE_DROP_HOVER` and `TauriEvent.WINDOW_FILE_DROP_CANCELLED` to `TauriEvent.WEBVIEW_FILE_DROP_CANCELLED`.
5 changes: 5 additions & 0 deletions .changes/webview-window-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:breaking
---

Added back the `WebviewWindow` API that exposes functionality of a window that hosts a single webview. The dedicated `Window` and `Webview` types are exposed for multiwebview features.
5 changes: 5 additions & 0 deletions .changes/webview-window-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:breaking
---

Renamed `Window` to `WebviewWindow`, `WindowBuilder` to `WebviewWindowBuilder`, `Manager::windows` to `Manager::webview_windows` and `Manager::get_window` to `Manager::get_webview_window`.
5 changes: 5 additions & 0 deletions .changes/window-data-url-rename.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:breaking
---

Renamed the `window-data-url` feature flag to `webview-data-url`.
4 changes: 2 additions & 2 deletions core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
path::PathBuf,
};
use tauri_codegen::{context_codegen, ContextData};
use tauri_utils::config::{AppUrl, WindowUrl};
use tauri_utils::config::{AppUrl, WebviewUrl};

// TODO docs
/// A builder for generating a Tauri application context during compile time.
Expand Down Expand Up @@ -88,7 +88,7 @@ impl CodegenContext {
&config.build.dist_dir
};
match app_url {
AppUrl::Url(WindowUrl::App(p)) => {
AppUrl::Url(WebviewUrl::App(p)) => {
println!("cargo:rerun-if-changed={}", config_parent.join(p).display());
}
AppUrl::Files(files) => {
Expand Down
6 changes: 3 additions & 3 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tauri_utils::acl::capability::Capability;
use tauri_utils::acl::plugin::Manifest;
use tauri_utils::acl::resolved::Resolved;
use tauri_utils::assets::AssetKey;
use tauri_utils::config::{AppUrl, Config, PatternKind, WindowUrl};
use tauri_utils::config::{AppUrl, Config, PatternKind, WebviewUrl};
use tauri_utils::html::{
inject_nonce_token, parse as parse_html, serialize_node as serialize_html_node,
};
Expand Down Expand Up @@ -165,8 +165,8 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE

let assets = match app_url {
AppUrl::Url(url) => match url {
WindowUrl::External(_) => Default::default(),
WindowUrl::App(path) => {
WebviewUrl::External(_) => Default::default(),
WebviewUrl::App(path) => {
if path.components().count() == 0 {
panic!(
"The `{}` configuration cannot be empty",
Expand Down
8 changes: 4 additions & 4 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
"default": "index.html",
"allOf": [
{
"$ref": "#/definitions/WindowUrl"
"$ref": "#/definitions/WebviewUrl"
}
]
},
Expand Down Expand Up @@ -571,7 +571,7 @@
},
"additionalProperties": false
},
"WindowUrl": {
"WebviewUrl": {
"description": "An URL to open on a Tauri webview window.",
"anyOf": [
{
Expand Down Expand Up @@ -1451,7 +1451,7 @@
"additionalProperties": false
},
"DmgConfig": {
"description": "Configuration for Apple Disk Image (.dmg) bundles.\n\nSee more: https://tauri.app/v1/api/config#dmgconfig",
"description": "Configuration for Apple Disk Image (.dmg) bundles.\n\nSee more: <https://tauri.app/v1/api/config#dmgconfig>",
"type": "object",
"properties": {
"background": {
Expand Down Expand Up @@ -2482,7 +2482,7 @@
"description": "The app's external URL, or the path to the directory containing the app assets.",
"allOf": [
{
"$ref": "#/definitions/WindowUrl"
"$ref": "#/definitions/WebviewUrl"
}
]
},
Expand Down
Loading

0 comments on commit c77b403

Please sign in to comment.