Skip to content

Commit

Permalink
refactor(runtime): remove clipboard APIs
Browse files Browse the repository at this point in the history
Finishes the clipboard refactor started on PR #6728.
  • Loading branch information
lucasfernog committed Apr 18, 2023
1 parent 8e46695 commit 28380e9
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 233 deletions.
2 changes: 2 additions & 0 deletions .changes/remove-clipboard.md
@@ -1,5 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
"api": patch
---

Expand Down
1 change: 0 additions & 1 deletion core/tauri-runtime-wry/Cargo.toml
Expand Up @@ -49,5 +49,4 @@ macos-private-api = [
]
objc-exception = [ "wry/objc-exception" ]
global-shortcut = [ "tauri-runtime/global-shortcut" ]
clipboard = [ "tauri-runtime/clipboard" ]
linux-headers = [ "wry/linux-headers", "webkit2gtk/v2_36" ]
62 changes: 0 additions & 62 deletions core/tauri-runtime-wry/src/clipboard.rs

This file was deleted.

70 changes: 0 additions & 70 deletions core/tauri-runtime-wry/src/lib.rs
Expand Up @@ -121,11 +121,6 @@ mod global_shortcut;
#[cfg(all(desktop, feature = "global-shortcut"))]
use global_shortcut::*;

#[cfg(feature = "clipboard")]
mod clipboard;
#[cfg(feature = "clipboard")]
use clipboard::*;

pub type WebContextStore = Arc<Mutex<HashMap<Option<PathBuf>, WebContext>>>;
// window
pub type WindowEventHandler = Box<dyn Fn(&WindowEvent) + Send>;
Expand Down Expand Up @@ -176,8 +171,6 @@ pub(crate) fn send_user_message<T: UserEvent>(
webview_id_map: context.webview_id_map.clone(),
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager: context.main_thread.global_shortcut_manager.clone(),
#[cfg(feature = "clipboard")]
clipboard_manager: context.main_thread.clipboard_manager.clone(),
windows: context.main_thread.windows.clone(),
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: context.main_thread.system_tray_manager.clone(),
Expand Down Expand Up @@ -252,8 +245,6 @@ pub struct DispatcherMainThreadContext<T: UserEvent> {
pub web_context: WebContextStore,
#[cfg(all(desktop, feature = "global-shortcut"))]
pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
#[cfg(feature = "clipboard")]
pub clipboard_manager: Arc<Mutex<Clipboard>>,
pub windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: SystemTrayManager,
Expand Down Expand Up @@ -1177,8 +1168,6 @@ pub enum Message<T: 'static> {
),
#[cfg(all(desktop, feature = "global-shortcut"))]
GlobalShortcut(GlobalShortcutMessage),
#[cfg(feature = "clipboard")]
Clipboard(ClipboardMessage),
UserEvent(T),
}

Expand All @@ -1190,8 +1179,6 @@ impl<T: UserEvent> Clone for Message<T> {
Self::Tray(i, m) => Self::Tray(*i, m.clone()),
#[cfg(all(desktop, feature = "global-shortcut"))]
Self::GlobalShortcut(m) => Self::GlobalShortcut(m.clone()),
#[cfg(feature = "clipboard")]
Self::Clipboard(m) => Self::Clipboard(m.clone()),
Self::UserEvent(t) => Self::UserEvent(t.clone()),
_ => unimplemented!(),
}
Expand Down Expand Up @@ -1742,9 +1729,6 @@ pub struct Wry<T: UserEvent> {
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager_handle: GlobalShortcutManagerHandle<T>,

#[cfg(feature = "clipboard")]
clipboard_manager_handle: ClipboardManagerWrapper<T>,

event_loop: EventLoop<Message<T>>,
}

Expand Down Expand Up @@ -1773,13 +1757,6 @@ impl<T: UserEvent> fmt::Debug for Wry<T> {
&self.global_shortcut_manager_handle,
);

#[cfg(feature = "clipboard")]
d.field(
"clipboard_manager",
&self.context.main_thread.clipboard_manager,
)
.field("clipboard_manager_handle", &self.clipboard_manager_handle);

d.finish()
}
}
Expand Down Expand Up @@ -1931,9 +1908,6 @@ impl<T: UserEvent> Wry<T> {
#[cfg(all(desktop, feature = "global-shortcut"))]
let global_shortcut_manager = Arc::new(Mutex::new(WryShortcutManager::new(&event_loop)));

#[cfg(feature = "clipboard")]
let clipboard_manager = Arc::new(Mutex::new(Clipboard::new()));

let windows = Arc::new(RefCell::new(HashMap::default()));
let webview_id_map = WebviewIdStore::default();

Expand All @@ -1949,8 +1923,6 @@ impl<T: UserEvent> Wry<T> {
web_context,
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager,
#[cfg(feature = "clipboard")]
clipboard_manager,
windows,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager,
Expand All @@ -1965,21 +1937,12 @@ impl<T: UserEvent> Wry<T> {
listeners: Default::default(),
};

#[cfg(feature = "clipboard")]
#[allow(clippy::redundant_clone)]
let clipboard_manager_handle = ClipboardManagerWrapper {
context: context.clone(),
};

Ok(Self {
context,

#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager_handle,

#[cfg(feature = "clipboard")]
clipboard_manager_handle,

event_loop,
})
}
Expand All @@ -1992,9 +1955,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
#[cfg(all(desktop, feature = "global-shortcut"))]
type GlobalShortcutManager = GlobalShortcutManagerHandle<T>;

#[cfg(feature = "clipboard")]
type ClipboardManager = ClipboardManagerWrapper<T>;

#[cfg(all(desktop, feature = "system-tray"))]
type TrayHandler = SystemTrayHandle<T>;

Expand Down Expand Up @@ -2030,11 +1990,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
self.global_shortcut_manager_handle.clone()
}

#[cfg(feature = "clipboard")]
fn clipboard_manager(&self) -> Self::ClipboardManager {
self.clipboard_manager_handle.clone()
}

fn create_window(&self, pending: PendingWindow<T, Self>) -> Result<DetachedWindow<T, Self>> {
let label = pending.label.clone();
let menu_ids = pending.menu_ids.clone();
Expand Down Expand Up @@ -2155,8 +2110,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
#[cfg(all(desktop, feature = "global-shortcut"))]
let global_shortcut_manager_handle = self.global_shortcut_manager_handle.clone();

#[cfg(feature = "clipboard")]
let clipboard_manager = self.context.main_thread.clipboard_manager.clone();
let mut iteration = RunIteration::default();

let proxy = self.event_loop.create_proxy();
Expand All @@ -2183,8 +2136,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
global_shortcut_manager: global_shortcut_manager.clone(),
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager_handle: &global_shortcut_manager_handle,
#[cfg(feature = "clipboard")]
clipboard_manager: clipboard_manager.clone(),
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: system_tray_manager.clone(),
},
Expand All @@ -2207,8 +2158,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
global_shortcut_manager: global_shortcut_manager.clone(),
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager_handle: &global_shortcut_manager_handle,
#[cfg(feature = "clipboard")]
clipboard_manager: clipboard_manager.clone(),
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: system_tray_manager.clone(),
},
Expand All @@ -2233,9 +2182,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
#[cfg(all(desktop, feature = "global-shortcut"))]
let global_shortcut_manager_handle = self.global_shortcut_manager_handle.clone();

#[cfg(feature = "clipboard")]
let clipboard_manager = self.context.main_thread.clipboard_manager.clone();

let proxy = self.event_loop.create_proxy();

self.event_loop.run(move |event, event_loop, control_flow| {
Expand All @@ -2253,8 +2199,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
global_shortcut_manager: global_shortcut_manager.clone(),
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager_handle: &global_shortcut_manager_handle,
#[cfg(feature = "clipboard")]
clipboard_manager: clipboard_manager.clone(),
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: system_tray_manager.clone(),
},
Expand All @@ -2276,8 +2220,6 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
global_shortcut_manager: global_shortcut_manager.clone(),
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager_handle: &global_shortcut_manager_handle,
#[cfg(feature = "clipboard")]
clipboard_manager: clipboard_manager.clone(),
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: system_tray_manager.clone(),
},
Expand All @@ -2295,8 +2237,6 @@ pub struct EventLoopIterationContext<'a, T: UserEvent> {
pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
#[cfg(all(desktop, feature = "global-shortcut"))]
pub global_shortcut_manager_handle: &'a GlobalShortcutManagerHandle<T>,
#[cfg(feature = "clipboard")]
pub clipboard_manager: Arc<Mutex<Clipboard>>,
#[cfg(all(desktop, feature = "system-tray"))]
pub system_tray_manager: SystemTrayManager,
}
Expand All @@ -2306,8 +2246,6 @@ struct UserMessageContext {
webview_id_map: WebviewIdStore,
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
#[cfg(feature = "clipboard")]
clipboard_manager: Arc<Mutex<Clipboard>>,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: SystemTrayManager,
}
Expand All @@ -2322,8 +2260,6 @@ fn handle_user_message<T: UserEvent>(
webview_id_map,
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager,
#[cfg(feature = "clipboard")]
clipboard_manager,
windows,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager,
Expand Down Expand Up @@ -2724,8 +2660,6 @@ fn handle_user_message<T: UserEvent>(
Message::GlobalShortcut(message) => {
handle_global_shortcut_message(message, &global_shortcut_manager)
}
#[cfg(feature = "clipboard")]
Message::Clipboard(message) => handle_clipboard_message(message, &clipboard_manager),
Message::UserEvent(_) => (),
}

Expand All @@ -2750,8 +2684,6 @@ fn handle_event_loop<T: UserEvent>(
global_shortcut_manager,
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager_handle,
#[cfg(feature = "clipboard")]
clipboard_manager,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager,
} = context;
Expand Down Expand Up @@ -2991,8 +2923,6 @@ fn handle_event_loop<T: UserEvent>(
webview_id_map,
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager,
#[cfg(feature = "clipboard")]
clipboard_manager,
windows,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager,
Expand Down
1 change: 0 additions & 1 deletion core/tauri-runtime/Cargo.toml
Expand Up @@ -52,4 +52,3 @@ devtools = [ ]
system-tray = [ ]
macos-private-api = [ ]
global-shortcut = [ ]
clipboard = [ ]
16 changes: 0 additions & 16 deletions core/tauri-runtime/src/lib.rs
Expand Up @@ -431,15 +431,6 @@ pub trait GlobalShortcutManager: Debug + Clone + Send + Sync {
fn unregister(&mut self, accelerator: &str) -> Result<()>;
}

/// Clipboard manager.
#[cfg(feature = "clipboard")]
pub trait ClipboardManager: Debug + Clone + Send + Sync {
/// Writes the text into the clipboard as plain text.
fn write_text<T: Into<String>>(&mut self, text: T) -> Result<()>;
/// Read the content in the clipboard as plain text.
fn read_text(&self) -> Result<Option<String>>;
}

pub trait EventLoopProxy<T: UserEvent>: Debug + Clone + Send + Sync {
fn send_event(&self, event: T) -> Result<()>;
}
Expand All @@ -453,9 +444,6 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
/// The global shortcut manager type.
#[cfg(all(desktop, feature = "global-shortcut"))]
type GlobalShortcutManager: GlobalShortcutManager;
/// The clipboard manager type.
#[cfg(feature = "clipboard")]
type ClipboardManager: ClipboardManager;
/// The tray handler type.
#[cfg(all(desktop, feature = "system-tray"))]
type TrayHandler: menu::TrayHandle;
Expand All @@ -480,10 +468,6 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
#[cfg(all(desktop, feature = "global-shortcut"))]
fn global_shortcut_manager(&self) -> Self::GlobalShortcutManager;

/// Gets the clipboard manager.
#[cfg(feature = "clipboard")]
fn clipboard_manager(&self) -> Self::ClipboardManager;

/// Create a new webview window.
fn create_window(&self, pending: PendingWindow<T, Self>) -> Result<DetachedWindow<T, Self>>;

Expand Down
5 changes: 2 additions & 3 deletions core/tauri/Cargo.toml
Expand Up @@ -161,7 +161,6 @@ global-shortcut = [
"tauri-runtime/global-shortcut",
"tauri-runtime-wry/global-shortcut"
]
clipboard = [ "tauri-runtime/clipboard", "tauri-runtime-wry/clipboard" ]
dialog = [ "rfd" ]
notification = [ "notify-rust" ]
system-tray = [ "tauri-runtime/system-tray", "tauri-runtime-wry/system-tray" ]
Expand Down Expand Up @@ -189,8 +188,8 @@ api-all = [
"app-all"
]
clipboard-all = [ "clipboard-write-text", "clipboard-read-text" ]
clipboard-read-text = [ "clipboard" ]
clipboard-write-text = [ "clipboard" ]
clipboard-read-text = [ ]
clipboard-write-text = [ ]
dialog-all = [ "dialog-open", "dialog-save", "dialog-message", "dialog-ask" ]
dialog-ask = [ "dialog" ]
dialog-confirm = [ "dialog" ]
Expand Down

0 comments on commit 28380e9

Please sign in to comment.