Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/change-pr-1736.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": minor
---

Remove Send, Sync bounds from NewWindowOpener.
3 changes: 1 addition & 2 deletions examples/gtk_opengl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use std::cell::RefCell;
use std::rc::Rc;
use std::{cell::RefCell, rc::Rc};
use tao::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
Expand Down
12 changes: 8 additions & 4 deletions src/android/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,19 @@ fn handle_request(

#[allow(non_snake_case)]
pub unsafe fn wryCreate(env: JNIEnv, _: JClass) {
let mut main_pipe = MainPipe { env };
let mut main_pipe = MainPipe {
env,
package: super::PACKAGE.get().unwrap(),
};

let looper = ThreadLooper::for_thread().unwrap();

looper
.add_fd_with_callback(MAIN_PIPE[0].as_fd(), FdEvent::INPUT, move |fd, _event| {
let size = std::mem::size_of::<bool>();
let mut wake = false;
if libc::read(fd.as_raw_fd(), &mut wake as *mut _ as *mut _, size) == size as libc::ssize_t {
let mut buf = [0u8];
if libc::read(fd.as_raw_fd(), buf.as_mut_ptr() as *mut _, buf.len())
== buf.len() as libc::ssize_t
{
// unregister itself on errors
main_pipe.recv().is_ok()
} else {
Expand Down
21 changes: 9 additions & 12 deletions src/android/main_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
sync::{Arc, Mutex},
};

use super::{find_class, EvalCallback, WebviewId, EVAL_CALLBACKS, EVAL_ID_GENERATOR, PACKAGE};
use super::{find_class, EvalCallback, WebviewId, EVAL_CALLBACKS, EVAL_ID_GENERATOR};

pub type ActivityId = i32;

Expand Down Expand Up @@ -126,17 +126,18 @@ pub fn get_webview(activity_id: ActivityId) -> Option<GlobalRef> {

pub struct MainPipe<'a> {
pub env: JNIEnv<'a>,
pub package: &'static str,
}

impl<'a> MainPipe<'a> {
pub(crate) fn send(activity_id: ActivityId, message: WebViewMessage) {
let size = std::mem::size_of::<bool>();
const BYTE: [u8; 1] = [0];
if CHANNEL.0.send((activity_id, message)).is_ok() {
unsafe {
libc::write(
MAIN_PIPE[1].as_raw_fd(),
&true as *const _ as *const _,
size,
BYTE.as_ptr() as *const _,
BYTE.len(),
)
};
}
Expand Down Expand Up @@ -188,7 +189,7 @@ impl<'a> MainPipe<'a> {
let rust_webview_class = find_class(
&mut self.env,
&activity,
format!("{}/RustWebView", PACKAGE.get().unwrap()),
format!("{}/RustWebView", self.package),
)?;
let webview = self.env.new_object(
&rust_webview_class,
Expand Down Expand Up @@ -237,7 +238,7 @@ impl<'a> MainPipe<'a> {
)?;
}

let webview_class_name = format!("{}/RustWebView", PACKAGE.get().unwrap());
let webview_class_name = format!("{}/RustWebView", self.package);
self.env.call_method(
&activity,
"setWebView",
Expand Down Expand Up @@ -268,7 +269,7 @@ impl<'a> MainPipe<'a> {
set_background_color(&mut self.env, &webview, color)?;
}
// Create and set webview client
let client_class_name = format!("{}/RustWebViewClient", PACKAGE.get().unwrap());
let client_class_name = format!("{}/RustWebViewClient", self.package);
let rust_webview_client_class =
find_class(&mut self.env, &activity, client_class_name.clone())?;
let webview_client = self.env.new_object(
Expand All @@ -291,11 +292,7 @@ impl<'a> MainPipe<'a> {
)?;

// Add javascript interface (IPC)
let ipc_class = find_class(
&mut self.env,
&activity,
format!("{}/Ipc", PACKAGE.get().unwrap()),
)?;
let ipc_class = find_class(&mut self.env, &activity, format!("{}/Ipc", self.package))?;
let ipc = self.env.new_object(
ipc_class,
format!("(L{webview_class_name};L{client_class_name};)V"),
Expand Down
16 changes: 8 additions & 8 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ macro_rules! define_static_handlers {
($($var:ident = $type_name:ident { $($fields:ident:$types:ty),+ $(,)? });+ $(;)?) => {
$(
static $var: Lazy<Mutex<HashMap<WebviewId, $type_name>>> = Lazy::new(||Mutex::new(HashMap::new()));
pub struct $type_name {
struct $type_name {
$($fields: $types,)*
}
impl $type_name {
pub fn new($($fields: $types,)*) -> Self {
fn new($($fields: $types,)*) -> Self {
Self {
$($fields,)*
}
Expand All @@ -81,12 +81,12 @@ define_static_handlers! {
ActivityId, WEBVIEW_ATTRIBUTES = CreateWebViewAttributes;
}

pub(crate) static PACKAGE: OnceCell<String> = OnceCell::new();
static PACKAGE: OnceCell<String> = OnceCell::new();

type EvalCallback = Box<dyn Fn(String) + Send + 'static>;

pub static EVAL_ID_GENERATOR: Counter = Counter::new();
pub static EVAL_CALLBACKS: OnceCell<Mutex<HashMap<i32, EvalCallback>>> = OnceCell::new();
static EVAL_ID_GENERATOR: Counter = Counter::new();
static EVAL_CALLBACKS: OnceCell<Mutex<HashMap<i32, EvalCallback>>> = OnceCell::new();

pub fn destroy_webview(activity_id: ActivityId, webview_id: &WebviewId) {
WEBVIEW_ATTRIBUTES.lock().unwrap().remove(&activity_id);
Expand All @@ -109,7 +109,7 @@ pub unsafe fn android_setup(
_looper: &ThreadLooper,
activity: GlobalRef,
) {
PACKAGE.get_or_init(move || package.to_string());
let package = PACKAGE.get_or_init(|| package.to_string());

let vm = env.get_java_vm().unwrap();

Expand All @@ -136,13 +136,13 @@ pub unsafe fn android_setup(
let rust_webchrome_client_class = find_class(
&mut env,
activity.as_obj(),
format!("{}/RustWebChromeClient", PACKAGE.get().unwrap()),
format!("{package}/RustWebChromeClient"),
)
.unwrap();
let webchrome_client = env
.new_object(
&rust_webchrome_client_class,
format!("(L{}/WryActivity;)V", PACKAGE.get().unwrap()),
format!("(L{package}/WryActivity;)V"),
&[activity.as_obj().into()],
)
.unwrap();
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,6 @@ pub struct NewWindowOpener {
pub target_configuration: Retained<objc2_web_kit::WKWebViewConfiguration>,
}

unsafe impl Send for NewWindowOpener {}
Comment thread
sftse marked this conversation as resolved.
unsafe impl Sync for NewWindowOpener {}

/// Window features of a window requested to open.
#[non_exhaustive]
#[derive(Debug)]
Expand Down
Loading