Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support tauri v2 #38

Merged
merged 24 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
069350e
feat: support tauri v2
ayangweb Oct 15, 2024
acedd24
refactor: `Windows` type changed to `WebviewWindow`
ayangweb Oct 15, 2024
5d7f987
refactor: renaming of the entry method
ayangweb Oct 15, 2024
5618174
chore: some problems are optimized
ayangweb Oct 15, 2024
9a425a3
update api
lucasfernog-crabnebula Oct 15, 2024
244887f
add change file
lucasfernog-crabnebula Oct 15, 2024
57beb46
prepare v2 release
lucasfernog-crabnebula Oct 15, 2024
7ad9fbf
fix gtk features
lucasfernog-crabnebula Oct 15, 2024
f0136d4
chore(ci): recognizeContributors: true
lucasfernog-crabnebula Oct 15, 2024
a8f3596
migration fixes
lucasfernog-crabnebula Oct 16, 2024
f8467d5
fix: covector
lucasfernog-crabnebula Oct 16, 2024
48fbf1a
remove global-js feature flag
lucasfernog-crabnebula Oct 16, 2024
9f4962f
chore: update tauri version to `2`
ayangweb Oct 16, 2024
eec9979
chore: simplifying tauri permissions
ayangweb Oct 16, 2024
b475f63
install webkit2gtk-4.1
lucasfernog-crabnebula Oct 16, 2024
45bcaec
add windows-core crate
lucasfernog-crabnebula Oct 16, 2024
bb8e921
chore: `windows-rs` downgraded to `v0.52`
ayangweb Oct 16, 2024
e34cd09
fix: fixing linux errors
ayangweb Oct 16, 2024
4f452b4
reintroduce skip_animatation_on_cancel_or_failure logic
lucasfernog-crabnebula Oct 16, 2024
4036724
fix options
lucasfernog-crabnebula Oct 16, 2024
03f9e73
lint
lucasfernog-crabnebula Oct 16, 2024
c10bc99
Revert "lint"
lucasfernog-crabnebula Oct 16, 2024
b4ae578
#[allow(static_mut_refs)]
lucasfernog-crabnebula Oct 16, 2024
3e9deae
remove version req for examples
lucasfernog-crabnebula Oct 17, 2024
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
2 changes: 1 addition & 1 deletion .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"getPublishedVersion": "cargo search ${ pkg.pkg } --limit 1 | sed -nE 's/^[^\"]*\"//; s/\".*//1p' -",
"prepublish": [
"sudo apt-get update",
"sudo apt-get install -y webkit2gtk-4.0"
"sudo apt-get install -y webkit2gtk-4.1"
],
"publish": [
"cargo publish"
Expand Down
9 changes: 9 additions & 0 deletions .changes/v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@crabnebula/tauri-plugin-drag": major
"@crabnebula/tauri-plugin-drag-as-window": major
"drag": major
"tauri-plugin-drag": major
"tauri-plugin-drag-as-window": major
---

Update to tauri v2.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.0
sudo apt-get install -y webkit2gtk-4.1
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --workspace --all-targets --all-features -- -D warnings

Expand All @@ -69,7 +69,7 @@ jobs:
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.0
sudo apt-get install -y webkit2gtk-4.1
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --workspace --lib --bins --tests --benches --all-features --no-fail-fast
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/covector-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
with:
fetch-depth: 0 # required for use of git history
- name: covector status
uses: jbolda/covector/packages/action@covector-v0.10
uses: jbolda/covector/packages/action@covector-v0
id: covector
with:
command: 'status'
3 changes: 2 additions & 1 deletion .github/workflows/covector-version-or-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
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.10
uses: jbolda/covector/packages/action@covector-v0
id: covector
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -38,6 +38,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
command: 'version-or-publish'
createRelease: true
recognizeContributors: true
- name: Create Pull Request With Versions Bumped
id: cpr
uses: peter-evans/create-pull-request@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
/Cargo.lock
gen/
18 changes: 17 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,20 @@ members = ["crates/*", "examples/*"]
[workspace.package]
edition = "2021"
authors = ["CrabNebula Ltd."]
license = "Apache-2.0 OR MIT"
license = "Apache-2.0 OR MIT"

[workspace.dependencies]
tauri = "2"
serde = "1"
serde_json = "1"
thiserror = "1"
base64 = "0.21"
tao = "0.30.3"
winit = "0.30.5"
wry = "0.46.1"
dunce = "1.0.5"
tauri-build = "2.0.1"
tauri-plugin = { version = "2.0.1", features = ["build"] }
drag = { path = "./crates/drag", features = [ "serde" ] }
tauri-plugin-drag = { path = "./crates/tauri-plugin-drag" }
tauri-plugin-drag-as-window = { path = "./crates/tauri-plugin-drag-as-window" }
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ There's two ways to consume this crate API: from Rust code via the `drag` crate
let preview_icon = drag::Image::Raw(include_bytes!("../../icon.png").to_vec());
```

- Use the `drag::start_drag` function. It takes a `&T: raw_window_handle::HasRawWindowHandle` type on macOS and Windows, and a `&gtk::ApplicationWindow` on Linux:
- Use the `drag::start_drag` function. It takes a `&T: raw_window_handle::HasWindowHandle` type on macOS and Windows, and a `&gtk::ApplicationWindow` on Linux:

- tao:
```rust
Expand All @@ -46,18 +46,18 @@ There's two ways to consume this crate API: from Rust code via the `drag` crate

- wry:
```rust
let event_loop = wry::application::event_loop::EventLoop::new();
let window = wry::application::window::WindowBuilder::new().build(&event_loop).unwrap();
let webview = wry::webview::WebViewBuilder::new(window).unwrap().build().unwrap();
let event_loop = tao::event_loop::EventLoop::new();
let window = tao::window::WindowBuilder::new().build(&event_loop).unwrap();
let webview = wry::WebViewBuilder::new().build(&window).unwrap();

drag::start_drag(
#[cfg(target_os = "linux")]
{
use wry::application::platform::unix::WindowExtUnix;
webview.window().gtk_window()
use tao::platform::unix::WindowExtUnix;
window.gtk_window()
},
#[cfg(not(target_os = "linux"))]
&webview.window(),
&window,
item,
preview_icon,
);
Expand Down Expand Up @@ -160,7 +160,7 @@ fn main() {

```javascript
import { dragAsWindow, dragBack } from "@crabnebula/tauri-plugin-drag-as-window";
import { appWindow, WebviewWindow } from "@tauri-apps/api/window";
import { getCurrentWebviewWindow, WebviewWindow } from "@tauri-apps/api/webviewWindow";
// alternatively you can pass a DOM element instead of its selector
dragAsWindow('#my-drag-element', (payload) => {
console.log('dropped!')
Expand All @@ -176,7 +176,7 @@ el.ondragstart = (event) => {
event.preventDefault()

dragBack(event.target, { data: 'some data' }, (payload) => {
appWindow.close()
getCurrentWebviewWindow().close()
})
}
```
Expand Down
50 changes: 17 additions & 33 deletions crates/drag/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,52 +1,36 @@
[package]
name = "drag"
version = "0.4.0"
version = "1.0.0"
description = "Start a drag operation out of a window"
authors = [ "CrabNebula Ltd." ]
edition = { workspace = true }
license = { workspace = true }

[dependencies]
raw-window-handle = "0.5"
thiserror = "1"
serde = { version = "1", optional = true }
raw-window-handle = "0.6.2"
thiserror.workspace = true
serde = { workspace = true, optional = true }

[dev-dependencies]
tao = "0.16"
winit = "0.29"
wry = "0.24"
tauri = "1"
tao.workspace = true
winit.workspace = true
wry.workspace = true
tauri.workspace = true

[target."cfg(target_os = \"macos\")".dependencies]
cocoa = "0.25"
objc = "0.2"
core-graphics = "0.23"
cocoa = "0.26.0"
objc = "0.2.7"
core-graphics = "0.24.0"

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
gtk = { version = "0.15", features = [ "v3_20" ] }
gdk = { version = "0.15", features = [ "v3_20" ] }
gdkx11 = "0.15"
gtk = { version = "0.18.1" }
gdk = { version = "0.18.0" }
gdkx11 = "0.18.0"

[target."cfg(target_os = \"windows\")".dependencies]
dunce = "1"

[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.52"
features = [
"implement",
"Win32_Foundation",
"Win32_Graphics_Gdi",
"Win32_System_Com",
"Win32_System_Com_StructuredStorage",
"Win32_System_Ole",
"Win32_System_Memory",
"Win32_System_SystemServices",
"Win32_UI_Shell",
"Win32_UI_Shell_Common",
"Win32_UI_WindowsAndMessaging",
"Win32_Graphics_Imaging",
"Win32_Graphics_Gdi"
]
dunce.workspace = true
windows-core = "0.58"
windows = { version = "0.52", features = [ "implement", "Win32_Foundation", "Win32_Graphics_Gdi", "Win32_System_Com", "Win32_System_Com_StructuredStorage", "Win32_System_Ole", "Win32_System_Memory", "Win32_System_SystemServices", "Win32_UI_Shell", "Win32_UI_Shell_Common", "Win32_UI_WindowsAndMessaging", "Win32_Graphics_Imaging", "Win32_Graphics_Gdi" ] }

[features]
serde = [ "dep:serde" ]
23 changes: 11 additions & 12 deletions crates/drag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!
//! `$ cargo add drag`
//!
//! - Use the `drag::start_drag` function. It takes a `&T: raw_window_handle::HasRawWindowHandle` type on macOS and Windows, and a `&gtk::ApplicationWindow` on Linux:
//! - Use the `drag::start_drag` function. It takes a `&T: raw_window_handle::HasWindowHandle` type on macOS and Windows, and a `&gtk::ApplicationWindow` on Linux:
//!
//! - tao:
//! ```rust,no_run
Expand Down Expand Up @@ -44,21 +44,21 @@
//!
//! - wry:
//! ```rust,no_run
//! let event_loop = wry::application::event_loop::EventLoop::new();
//! let window = wry::application::window::WindowBuilder::new().build(&event_loop).unwrap();
//! let webview = wry::webview::WebViewBuilder::new(window).unwrap().build().unwrap();
//! let event_loop = tao::event_loop::EventLoop::new();
//! let window = tao::window::WindowBuilder::new().build(&event_loop).unwrap();
//! let webview = wry::WebViewBuilder::new().build(&window).unwrap();
//!
//! let item = drag::DragItem::Files(vec![std::fs::canonicalize("./examples/icon.png").unwrap()]);
//! let preview_icon = drag::Image::File("./examples/icon.png".into());
//!
//! drag::start_drag(
//! #[cfg(target_os = "linux")]
//! {
//! use wry::application::platform::unix::WindowExtUnix;
//! webview.window().gtk_window()
//! use tao::platform::unix::WindowExtUnix;
//! window.gtk_window()
//! },
//! #[cfg(not(target_os = "linux"))]
//! &webview.window(),
//! &window,
//! item,
//! preview_icon,
//! |result, cursor_position| {
Expand All @@ -69,9 +69,8 @@
//! ```
//!
//! - winit:
//! ```rust,no_run
//! let event_loop = winit::event_loop::EventLoop::new().unwrap();
//! let window = winit::window::WindowBuilder::new().build(&event_loop).unwrap();
//! ```rust,ignore
//! let window = ...winit window;
//!
//! let item = drag::DragItem::Files(vec![std::fs::canonicalize("./examples/icon.png").unwrap()]);
//! let preview_icon = drag::Image::File("./examples/icon.png".into());
Expand Down Expand Up @@ -116,7 +115,7 @@ pub enum Error {
FailedToGetCursorPosition,
}

#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum DragResult {
Dropped,
Expand Down Expand Up @@ -160,7 +159,7 @@ pub enum Image {
/// Logical position of the cursor.
///
/// - **Windows**: Currently the win32 API for logical position reports physical position as well, due to the complicated nature of potential multiple monitor with different scaling there's no trivial solution to be incorporated.
#[derive(Debug)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct CursorPosition {
pub x: i32,
Expand Down
13 changes: 9 additions & 4 deletions crates/drag/src/platform_impl/gtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
use crate::{CursorPosition, DragItem, DragResult, Error, Image, Options};
use gdkx11::{
gdk,
glib::{ObjectExt, SignalHandlerId},
glib::{ObjectExt, Propagation, SignalHandlerId},
};
use gtk::{
gdk_pixbuf,
prelude::{DragContextExtManual, PixbufLoaderExt, WidgetExt, WidgetExtManual},
Inhibit,
prelude::{
DeviceExt, DragContextExtManual, PixbufLoaderExt, SeatExt, WidgetExt, WidgetExtManual,
},
};
use std::{
rc::Rc,
Expand Down Expand Up @@ -120,7 +121,11 @@ fn on_drop_failed<F: Fn(DragResult, CursorPosition) + Send + 'static>(
);

cleanup_signal_handlers(&handler_ids_clone, &window_clone);
Inhibit(skip_animatation_on_cancel_or_failure)
if skip_animatation_on_cancel_or_failure {
Propagation::Stop
} else {
Propagation::Proceed
}
}));
}

Expand Down
10 changes: 5 additions & 5 deletions crates/drag/src/platform_impl/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use objc::{
declare::ClassDecl,
runtime::{Class, Object, Protocol, Sel, BOOL, NO, YES},
};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::{HasWindowHandle, RawWindowHandle};

use crate::{CursorPosition, DragItem, DragResult, Image, Options};

Expand Down Expand Up @@ -50,16 +50,16 @@ impl NSString {
}
}

pub fn start_drag<W: HasRawWindowHandle, F: Fn(DragResult, CursorPosition) + Send + 'static>(
pub fn start_drag<W: HasWindowHandle, F: Fn(DragResult, CursorPosition) + Send + 'static>(
handle: &W,
item: DragItem,
image: Image,
on_drop_callback: F,
options: Options,
) -> crate::Result<()> {
if let RawWindowHandle::AppKit(w) = handle.raw_window_handle() {
if let Ok(RawWindowHandle::AppKit(w)) = handle.window_handle().map(|h| h.as_raw()) {
unsafe {
let window = w.ns_window as id;
let window: id = msg_send![w.ns_view.as_ptr() as id, window];
// wry replaces the ns_view so we don't really use AppKitWindowHandle::ns_view
let ns_view: id = msg_send![window, contentView];

Expand Down Expand Up @@ -238,7 +238,7 @@ pub fn start_drag<W: HasRawWindowHandle, F: Fn(DragResult, CursorPosition) + Sen
1
} else {
// NSDragOperationEvery
NSUInteger::max_value()
NSUInteger::MAX
}
}

Expand Down
8 changes: 5 additions & 3 deletions crates/drag/src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::{HasWindowHandle, RawWindowHandle};

use crate::{CursorPosition, DragItem, DragResult, Image, Options};

Expand Down Expand Up @@ -210,18 +210,19 @@ impl IDataObject_Impl for DataObject {
}
}

pub fn start_drag<W: HasRawWindowHandle, F: Fn(DragResult, CursorPosition) + Send + 'static>(
pub fn start_drag<W: HasWindowHandle, F: Fn(DragResult, CursorPosition) + Send + 'static>(
handle: &W,
item: DragItem,
image: Image,
on_drop_callback: F,
_options: Options,
) -> crate::Result<()> {
if let RawWindowHandle::Win32(_w) = handle.raw_window_handle() {
if let Ok(RawWindowHandle::Win32(_w)) = handle.window_handle().map(|h| h.as_raw()) {
match item {
DragItem::Files(files) => {
init_ole();
unsafe {
#[allow(static_mut_refs)]
if let Err(e) = &OLE_RESULT {
return Err(e.clone().into());
}
Expand Down Expand Up @@ -264,6 +265,7 @@ pub fn start_drag<W: HasRawWindowHandle, F: Fn(DragResult, CursorPosition) + Sen
DragItem::Data { .. } => {
init_ole();
unsafe {
#[allow(static_mut_refs)]
if let Err(e) = &OLE_RESULT {
return Err(e.clone().into());
}
Expand Down
Loading
Loading