Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/migrate-to-objc2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Tsai committed Oct 7, 2024
2 parents d0f6990 + 4a5b6e8 commit 50c681f
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"dryRunCommand": true
},
{
"command": "cargo generate-lockfile",
"command": "echo '<details>\n<summary><em><h4>Cargo Audit</h4></em></summary>\n\n```'",
"dryRunCommand": true,
"runFromRoot": true,
"pipe": true
},
{
"command": "echo '<details>\n<summary><em><h4>Cargo Audit</h4></em></summary>\n\n```'",
"command": "cargo generate-lockfile",
"dryRunCommand": true,
"runFromRoot": true,
"pipe": true
},
{
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## \[0.45.0]

- [`0fd1229`](https://github.com/tauri-apps/wry/commit/0fd12297997f598e4893e8f5b6e235b09cedec09) ([#1369](https://github.com/tauri-apps/wry/pull/1369) by [@lloydzhou](https://github.com/tauri-apps/wry/../../lloydzhou)) On Linux, fixed incorrect path for indexeddb database directory which made apps using `[email protected]` and `tauri@1` migrating to `wry@>=0.38` and `tauri@2` lose their indexeddb data.
- [`e332eff`](https://github.com/tauri-apps/wry/commit/e332eff6ac41ff0f4ed6cf5196c3a78c776912d3) ([#1368](https://github.com/tauri-apps/wry/pull/1368) by [@zephraph](https://github.com/tauri-apps/wry/../../zephraph)) Add `Webview::load_html`.

## \[0.44.1]

- [`5111eb0`](https://github.com/tauri-apps/wry/commit/5111eb013e1b049d12aad38b96b2017a4fc54c72) ([#1362](https://github.com/tauri-apps/wry/pull/1362) by [@lucasfernog](https://github.com/tauri-apps/wry/../../lucasfernog)) Fixes `WebView::clear_all_browsing_data` crashing with a segfault on macOS.

## \[0.44.0]

- [`b863d38`](https://github.com/tauri-apps/wry/commit/b863d38ff705e037b297c1651e17775d3dbe473c) ([#1356](https://github.com/tauri-apps/wry/pull/1356) by [@SpikeHD](https://github.com/tauri-apps/wry/../../SpikeHD)) Expose ability to enable browser extensions in WebView2
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = {}

[package]
name = "wry"
version = "0.44.0"
version = "0.45.0"
authors = [ "Tauri Programme within The Commons Conservancy" ]
edition = "2021"
license = "Apache-2.0 OR MIT"
Expand Down
9 changes: 3 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ fn main() {

fn env_var(var: &str) -> String {
std::env::var(var).unwrap_or_else(|_| {
panic!(
"`{}` is not set, which is needed to generate the kotlin files for android.",
var
)
panic!("`{var}` is not set, which is needed to generate the kotlin files for android.")
})
}

Expand Down Expand Up @@ -61,8 +58,8 @@ fn main() {
.to_uppercase()
);

println!("cargo:rerun-if-env-changed={}", class_extension_env);
println!("cargo:rerun-if-env-changed={}", class_init_env);
println!("cargo:rerun-if-env-changed={class_extension_env}");
println!("cargo:rerun-if-env-changed={class_init_env}");

let content = fs::read_to_string(file.path())
.expect("failed to read kotlin file as string")
Expand Down
6 changes: 3 additions & 3 deletions examples/gtk_multiwebview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ fn main() -> wry::Result<()> {
})
.with_url("https://tauri.app")
.build()?;
let webview2 = WebViewBuilder::new_as_child(&window)
let webview2 = create_webview_builder()
.with_bounds(Rect {
position: LogicalPosition::new(size.width / 2, 0).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://github.com/tauri-apps/wry")
.build()?;
let webview3 = WebViewBuilder::new_as_child(&window)
let webview3 = create_webview_builder()
.with_bounds(Rect {
position: LogicalPosition::new(0, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://twitter.com/TauriApps")
.build()?;
let webview4 = WebViewBuilder::new_as_child(&window)
let webview4 = create_webview_builder()
.with_bounds(Rect {
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
Expand Down
7 changes: 7 additions & 0 deletions src/android/main_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ impl<'a> MainPipe<'a> {
.call_method(webview, "clearAllBrowsingData", "()V", &[])?;
}
}
WebViewMessage::LoadHtml(html) => {
if let Some(webview) = &self.webview {
let html = self.env.new_string(html)?;
load_html(&mut self.env, webview.as_obj(), &html)?;
}
}
}
}
Ok(())
Expand Down Expand Up @@ -369,6 +375,7 @@ pub(crate) enum WebViewMessage {
GetUrl(Sender<String>),
Jni(Box<dyn FnOnce(&mut JNIEnv, &JObject, &JObject) + Send>),
LoadUrl(String, Option<http::HeaderMap>),
LoadHtml(String),
ClearAllBrowsingData,
}

Expand Down
5 changes: 5 additions & 0 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ impl InnerWebView {
Ok(())
}

pub fn load_html(&self, html: &str) -> Result<()> {
MainPipe::send(WebViewMessage::LoadHtml(html.to_string()));
Ok(())
}

pub fn clear_all_browsing_data(&self) -> Result<()> {
MainPipe::send(WebViewMessage::ClearAllBrowsingData);
Ok(())
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,11 @@ impl WebView {
self.webview.load_url_with_headers(url, headers)
}

/// Load html content into the webview
pub fn load_html(&self, html: &str) -> Result<()> {
self.webview.load_html(html)
}

/// Clear all browsing data
pub fn clear_all_browsing_data(&self) -> Result<()> {
self.webview.clear_all_browsing_data()
Expand Down
7 changes: 6 additions & 1 deletion src/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,11 @@ impl InnerWebView {
Ok(())
}

pub fn load_html(&self, html: &str) -> Result<()> {
self.webview.load_html(html, None);
Ok(())
}

pub fn clear_all_browsing_data(&self) -> Result<()> {
if let Some(context) = self.webview.context() {
if let Some(data_manger) = context.website_data_manager() {
Expand Down Expand Up @@ -820,7 +825,7 @@ pub fn platform_webview_version() -> Result<String> {
webkit_get_micro_version(),
)
};
Ok(format!("{}.{}.{}", major, minor, patch))
Ok(format!("{major}.{minor}.{patch}"))
}

// SAFETY: only use this when you are sure the span will be dropped on the same thread it was entered
Expand Down
9 changes: 2 additions & 7 deletions src/webkitgtk/web_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use soup::{MessageHeaders, MessageHeadersType};
use std::{
borrow::Cow,
cell::RefCell,
collections::{HashSet, VecDeque},
collections::VecDeque,
path::PathBuf,
rc::Rc,
sync::{
Expand Down Expand Up @@ -40,12 +40,7 @@ impl WebContextImpl {
let mut context_builder = WebContext::builder();
if let Some(data_directory) = data.data_directory() {
let data_manager = WebsiteDataManager::builder()
.base_data_directory(
data_directory
.join("databases")
.join("indexeddb")
.to_string_lossy(),
)
.base_data_directory(data_directory.to_string_lossy())
.build();
if let Some(cookie_manager) = data_manager.cookie_manager() {
cookie_manager.set_persistent_storage(
Expand Down
5 changes: 5 additions & 0 deletions src/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,11 @@ impl InnerWebView {
load_url_with_headers(&self.webview, &self.env, url, headers)
}

pub fn load_html(&self, html: &str) -> Result<()> {
let html = HSTRING::from(html);
unsafe { self.webview.NavigateToString(&html) }.map_err(Into::into)
}

pub fn bounds(&self) -> Result<Rect> {
let mut bounds = Rect::default();
let mut rect = RECT::default();
Expand Down
7 changes: 6 additions & 1 deletion src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,18 @@ r#"Object.defineProperty(window, 'ipc', {
self.navigate_to_url(url, Some(headers))
}

pub fn load_html(&self, html: &str) -> crate::Result<()> {
self.navigate_to_string(html);
Ok(())
}

pub fn clear_all_browsing_data(&self) -> Result<()> {
unsafe {
let config = self.webview.configuration();
let store = config.websiteDataStore();
let all_data_types = WKWebsiteDataStore::allWebsiteDataTypes();
let date = NSDate::dateWithTimeIntervalSince1970(0.0);
let handler = block2::RcBlock::new(|| {});
let handler = block2::RcBlock::new(|| {}).copy();
store.removeDataOfTypes_modifiedSince_completionHandler(&all_data_types, &date, &handler);
}
Ok(())
Expand Down

0 comments on commit 50c681f

Please sign in to comment.