Skip to content
Open
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
27 changes: 11 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
[package]
name = "tauri-runtime-cef"
version = "0.1.0"
description = "CEF runtime for Tauri, ported from tauri feat/cef branch onto published crates."
authors = ["Tauri Programme within The Commons Conservancy", "byeongsu-hong"]
homepage = "https://github.com/SableClient/tauri-runtime-cef"
repository = "https://github.com/SableClient/tauri-runtime-cef"
categories = ["gui"]
license = "Apache-2.0 OR MIT"
edition = "2024"
rust-version = "1.88"
authors.workspace = true
homepage.workspace = true
repository.workspace = true
categories.workspace = true
license.workspace = true
edition.workspace = true
rust-version.workspace = true

[dependencies]
base64 = "0.22"
cef = { version = "=150.0.0", features = ["build-util", "linux-x11"] }
# Not actually used directly, just locking it.
cef = { version = "=150.2.1", features = ["build-util", "linux-x11"] }
# Not actually used directly, just locking it.
cef-dll-sys = { version = "=150.2.1", default-features = false }
cef-dll-sys = { version = "=150.0.0", default-features = false }
dirs = "6"
dioxus-debug-cell = "0.1"
http = "1"
Expand All @@ -26,8 +24,8 @@ raw-window-handle = "0.6"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10"
tauri-runtime = "2.11.2"
tauri-utils = { version = "2.9.2", features = [
tauri-runtime = { version = "2.11.2", path = "../tauri-runtime" }
tauri-utils = { version = "2.9.2", path = "../tauri-utils", features = [
"html-manipulation",
] }
url = "2"
Expand Down Expand Up @@ -98,6 +96,3 @@ default = ["sandbox"]
devtools = []
macos-private-api = ["tauri-runtime/macos-private-api"]
sandbox = ["cef/sandbox"]

[dev-dependencies]
tauri = { version = "2", default-features = false, features = ["test"] }
4 changes: 2 additions & 2 deletions src/cef_impl/client/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::webview::INITIAL_LOAD_URL;

wrap_display_handler! {
pub struct TauriCefDisplayHandler {
document_title_changed_handler: Option<Arc<crate::compat::DocumentTitleChangedHandler>>,
address_changed_handler: Option<Arc<crate::compat::AddressChangedHandler>>,
document_title_changed_handler: Option<Arc<tauri_runtime::webview::DocumentTitleChangedHandler>>,
address_changed_handler: Option<Arc<tauri_runtime::webview::AddressChangedHandler>>,
}

impl DisplayHandler {
Expand Down
2 changes: 1 addition & 1 deletion src/cef_impl/client/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cef::*;

wrap_download_handler! {
pub struct TauriCefDownloadHandler {
download_handler: Arc<crate::compat::DownloadHandler>,
download_handler: Arc<tauri_runtime::webview::DownloadHandler>,
}

impl DownloadHandler {
Expand Down
142 changes: 71 additions & 71 deletions src/cef_impl/client/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
// SPDX-License-Identifier: MIT

use std::{
path::PathBuf,
sync::{Arc, Mutex},
path::PathBuf,
sync::{Arc, Mutex},
};

use cef::*;
use tauri_runtime::{
UserEvent,
dpi::PhysicalPosition,
webview::InitializationScript,
window::{DragDropEvent, WindowId},
UserEvent,
dpi::PhysicalPosition,
webview::InitializationScript,
window::{DragDropEvent, WindowId},
};
use url::Url;

Expand Down Expand Up @@ -89,53 +89,53 @@ const DRAG_DROP_INIT_SCRIPT: &str = r#"
"#;

pub(crate) fn drag_drop_initialization_script() -> InitializationScript {
InitializationScript {
script: DRAG_DROP_INIT_SCRIPT.to_string(),
for_main_frame_only: false,
}
InitializationScript {
script: DRAG_DROP_INIT_SCRIPT.to_string(),
for_main_frame_only: false,
}
}

#[derive(Default)]
pub(crate) struct DragDropState {
pub(crate) paths: Option<Vec<PathBuf>>,
pub(crate) native_entered: bool,
pub(crate) entered: bool,
pub(crate) paths: Option<Vec<PathBuf>>,
pub(crate) native_entered: bool,
pub(crate) entered: bool,
}

#[derive(Clone, Copy, PartialEq, Eq)]
pub(crate) enum DragDropEventTarget {
Window,
Webview,
Window,
Webview,
}

#[derive(Clone, serde::Deserialize)]
pub(crate) struct DragDropScriptEvent {
#[serde(rename = "type")]
pub(crate) kind: String,
pub(crate) x: f64,
pub(crate) y: f64,
#[serde(rename = "type")]
pub(crate) kind: String,
pub(crate) x: f64,
pub(crate) y: f64,
}

fn collect_drag_data_paths(drag_data: &mut DragData) -> Vec<PathBuf> {
let mut paths = CefStringList::new();
if drag_data.file_paths(Some(&mut paths)) != 0 {
let paths = paths
.into_iter()
.filter(|path| !path.is_empty())
.map(PathBuf::from)
.collect::<Vec<_>>();

if !paths.is_empty() {
return paths;
}
let mut paths = CefStringList::new();
if drag_data.file_paths(Some(&mut paths)) != 0 {
let paths = paths
.into_iter()
.filter(|path| !path.is_empty())
.map(PathBuf::from)
.collect::<Vec<_>>();

if !paths.is_empty() {
return paths;
}
}

let file_name = CefStringUtf16::from(&drag_data.file_name()).to_string();
if file_name.is_empty() {
Vec::new()
} else {
vec![PathBuf::from(file_name)]
}
let file_name = CefStringUtf16::from(&drag_data.file_name()).to_string();
if file_name.is_empty() {
Vec::new()
} else {
vec![PathBuf::from(file_name)]
}
}

wrap_drag_handler! {
Expand Down Expand Up @@ -165,45 +165,45 @@ wrap_drag_handler! {
}

pub(crate) fn event_from_script_event(
drag_drop_state: &Arc<Mutex<DragDropState>>,
script_event: DragDropScriptEvent,
drag_drop_state: &Arc<Mutex<DragDropState>>,
script_event: DragDropScriptEvent,
) -> Option<DragDropEvent> {
let position = PhysicalPosition::new(script_event.x, script_event.y);
let mut state = drag_drop_state.lock().unwrap();
if !state.native_entered {
return None;
}
let position = PhysicalPosition::new(script_event.x, script_event.y);
let mut state = drag_drop_state.lock().unwrap();
if !state.native_entered {
return None;
}

match script_event.kind.as_str() {
"enter" => {
if state.entered {
return None;
}
match script_event.kind.as_str() {
"enter" => {
if state.entered {
return None;
}

let paths = state.paths.clone()?;
state.entered = true;
Some(DragDropEvent::Enter { paths, position })
}
"over" => state.entered.then_some(DragDropEvent::Over { position }),
"drop" => {
let paths = state.entered.then(|| state.paths.take()).flatten();
state.entered = false;
state.native_entered = false;
paths.map(|paths| DragDropEvent::Drop { paths, position })
}
"leave" => {
state.native_entered = false;
state.paths = None;

if state.entered {
state.entered = false;
Some(DragDropEvent::Leave)
} else {
None
}
}
_ => None,
let paths = state.paths.clone()?;
state.entered = true;
Some(DragDropEvent::Enter { paths, position })
}
"over" => state.entered.then_some(DragDropEvent::Over { position }),
"drop" => {
let paths = state.entered.then(|| state.paths.take()).flatten();
state.entered = false;
state.native_entered = false;
paths.map(|paths| DragDropEvent::Drop { paths, position })
}
"leave" => {
state.native_entered = false;
state.paths = None;

if state.entered {
state.entered = false;
Some(DragDropEvent::Leave)
} else {
None
}
}
_ => None,
}
}

wrap_resource_request_handler! {
Expand Down
Loading