refactor(tauri): remove private params trait methods (#1484)

* refactor(tauri): remove private params trait methods

* add changes file

* remove newly unused trait in WindowManager unit test
This commit is contained in:
chip 2021-04-14 11:03:20 -07:00 committed by GitHub
parent f2d24ef2fb
commit ec27ca81fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 149 additions and 258 deletions

View File

@ -0,0 +1,10 @@
---
"tauri": patch
---
internal refactoring of `Params` to allow for easier usage without a private trait with only 1 implementor.
`ParamsPrivate` -> `ParamsBase`
`ManagerPrivate` -> `ManagerBase`
(new) `Args`, crate only. Now implements `Params`/`ParamsBase`.
`App` and `Window` use `WindowManager` directly

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use crate::{endpoints::InvokeResponse, sealed::ManagerPrivate, Manager, Params, Window};
use crate::{endpoints::InvokeResponse, sealed::ManagerBase, Manager, Params, Window};
use serde::Deserialize;
/// The API descriptor.

View File

@ -111,7 +111,7 @@ pub struct Context<A: Assets> {
}
/// Types associated with the running Tauri application.
pub trait Params: sealed::ParamsPrivate<Self> {
pub trait Params: sealed::ParamsBase {
/// The event type used to create and listen to events.
type Event: Tag;
@ -126,7 +126,9 @@ pub trait Params: sealed::ParamsPrivate<Self> {
}
/// Manages a running application.
pub trait Manager<M: Params>: sealed::ManagerPrivate<M> {
///
/// TODO: expand these docs
pub trait Manager<M: Params>: sealed::ManagerBase<M> {
/// The [`Config`] the manager was created with.
fn config(&self) -> &Config {
self.manager().config()
@ -202,126 +204,27 @@ pub trait Manager<M: Params>: sealed::ManagerPrivate<M> {
/// Prevent implementation details from leaking out of the [`Manager`] and [`Params`] traits.
pub(crate) mod sealed {
use super::Params;
use crate::runtime::Runtime;
use crate::{
api::{config::Config, PackageInfo},
event::{Event, EventHandler},
hooks::{InvokeMessage, PageLoadPayload},
runtime::window::{DetachedWindow, PendingWindow},
Window,
};
use serde::Serialize;
use std::collections::{HashMap, HashSet};
use uuid::Uuid;
use crate::runtime::{manager::WindowManager, Runtime};
/// private manager api
pub trait ParamsPrivate<M: Params>: Clone + Send + Sized + 'static {
/// Pass messages not handled by modules or plugins to the running application
fn run_invoke_handler(&self, message: InvokeMessage<M>);
/// No downstream implementations of [`Params`].
pub trait ParamsBase: 'static {}
/// Ran once for every window when the page is loaded.
fn run_on_page_load(&self, window: Window<M>, payload: PageLoadPayload);
/// Pass a message to be handled by a plugin that expects the command.
fn extend_api(&self, command: String, message: InvokeMessage<M>);
/// Initialize all the plugins attached to the [`Manager`].
fn initialize_plugins(&self) -> crate::Result<()>;
/// Prepare a [`PendingWindow`] to be created by the [`Runtime`].
///
/// The passed labels should represent either all the windows in the manager. If the application
/// has not yet been started, the passed labels should represent all windows that will be
/// created before starting.
fn prepare_window(
&self,
pending: PendingWindow<M>,
labels: &[M::Label],
) -> crate::Result<PendingWindow<M>>;
/// Attach a detached window to the manager.
fn attach_window(&self, window: DetachedWindow<M>) -> Window<M>;
/// Emit an event to javascript windows that pass the predicate.
fn emit_filter_internal<S: Serialize + Clone, F: Fn(&Window<Self>) -> bool>(
&self,
event: String,
payload: Option<S>,
filter: F,
) -> crate::Result<()>;
/// Emit an event to javascript windows that pass the predicate.
fn emit_filter<S: Serialize + Clone, F: Fn(&Window<M>) -> bool>(
&self,
event: M::Event,
payload: Option<S>,
predicate: F,
) -> crate::Result<()>;
/// All current window labels existing.
fn labels(&self) -> HashSet<M::Label>;
/// The configuration the [`Manager`] was built with.
fn config(&self) -> &Config;
/// App package information.
fn package_info(&self) -> &PackageInfo;
/// Remove the specified event handler.
fn unlisten(&self, handler_id: EventHandler);
/// Trigger an event.
fn trigger(&self, event: M::Event, window: Option<M::Label>, data: Option<String>);
/// Set up a listener to an event.
fn listen<F: Fn(Event) + Send + 'static>(
&self,
event: M::Event,
window: Option<M::Label>,
handler: F,
) -> EventHandler;
/// Set up a listener to and event that is automatically removed after called once.
fn once<F: Fn(Event) + Send + 'static>(
&self,
event: M::Event,
window: Option<M::Label>,
handler: F,
);
fn event_listeners_object_name(&self) -> String;
fn event_queue_object_name(&self) -> String;
fn event_emit_function_name(&self) -> String;
/// Generate a random salt and store it in the manager
fn generate_salt(&self) -> Uuid;
/// Verify that the passed salt is a valid salt in the manager.
fn verify_salt(&self, salt: String) -> bool;
/// Get a single managed window.
fn get_window(&self, label: &M::Label) -> Option<Window<M>>;
/// Get all managed windows.
fn windows(&self) -> HashMap<M::Label, Window<M>>;
}
/// Represents either a running [`Runtime`] or a dispatcher to it.
pub enum RuntimeOrDispatch<'m, M: Params> {
/// A running [`Runtime`] or a dispatcher to it.
pub enum RuntimeOrDispatch<'r, P: Params> {
/// Mutable reference to the running [`Runtime`].
Runtime(&'m mut M::Runtime),
Runtime(&'r mut P::Runtime),
/// A dispatcher to the running [`Runtime`].
Dispatch(<M::Runtime as Runtime>::Dispatcher),
Dispatch(<P::Runtime as Runtime>::Dispatcher),
}
/// Represents a managed handle to the application runner.
pub trait ManagerPrivate<M: Params> {
/// Managed handle to the application runtime.
pub trait ManagerBase<P: Params> {
/// The manager behind the [`Managed`] item.
fn manager(&self) -> &M;
fn manager(&self) -> &WindowManager<P>;
/// The runtime or runtime dispatcher of the [`Managed`] item.
fn runtime(&mut self) -> RuntimeOrDispatch<'_, M>;
fn runtime(&mut self) -> RuntimeOrDispatch<'_, P>;
}
}

View File

@ -10,10 +10,11 @@ use crate::{
flavors::wry::Wry, manager::WindowManager, tag::Tag, webview::Attributes,
window::PendingWindow, Dispatch, Runtime,
},
sealed::{ManagerPrivate, ParamsPrivate, RuntimeOrDispatch},
sealed::{ManagerBase, RuntimeOrDispatch},
Context, Manager, Params, Window,
};
use crate::runtime::manager::Args;
#[cfg(feature = "updater")]
use crate::updater;
@ -22,12 +23,12 @@ use crate::updater;
/// This type implements [`Manager`] which allows for manipulation of global application items.
pub struct App<P: Params> {
runtime: P::Runtime,
manager: P,
manager: WindowManager<P>,
}
impl<P: Params> Manager<P> for App<P> {}
impl<P: Params> ManagerPrivate<P> for App<P> {
fn manager(&self) -> &P {
impl<P: Params> ManagerBase<P> for App<P> {
fn manager(&self) -> &WindowManager<P> {
&self.manager
}
@ -104,19 +105,19 @@ where
R: Runtime,
{
/// The JS message handler.
invoke_handler: Box<InvokeHandler<WindowManager<E, L, A, R>>>,
invoke_handler: Box<InvokeHandler<Args<E, L, A, R>>>,
/// The setup hook.
setup: SetupHook<WindowManager<E, L, A, R>>,
setup: SetupHook<Args<E, L, A, R>>,
/// Page load hook.
on_page_load: Box<OnPageLoad<WindowManager<E, L, A, R>>>,
on_page_load: Box<OnPageLoad<Args<E, L, A, R>>>,
/// windows to create when starting up.
pending_windows: Vec<PendingWindow<WindowManager<E, L, A, R>>>,
pending_windows: Vec<PendingWindow<Args<E, L, A, R>>>,
/// All passed plugins
plugins: PluginStore<WindowManager<E, L, A, R>>,
plugins: PluginStore<Args<E, L, A, R>>,
}
impl<E, L, A, R> Builder<E, L, A, R>
@ -140,7 +141,7 @@ where
/// Defines the JS message handler callback.
pub fn invoke_handler<F>(mut self, invoke_handler: F) -> Self
where
F: Fn(InvokeMessage<WindowManager<E, L, A, R>>) + Send + Sync + 'static,
F: Fn(InvokeMessage<Args<E, L, A, R>>) + Send + Sync + 'static,
{
self.invoke_handler = Box::new(invoke_handler);
self
@ -149,9 +150,7 @@ where
/// Defines the setup hook.
pub fn setup<F>(mut self, setup: F) -> Self
where
F: Fn(&mut App<WindowManager<E, L, A, R>>) -> Result<(), Box<dyn std::error::Error>>
+ Send
+ 'static,
F: Fn(&mut App<Args<E, L, A, R>>) -> Result<(), Box<dyn std::error::Error>> + Send + 'static,
{
self.setup = Box::new(setup);
self
@ -160,14 +159,14 @@ where
/// Defines the page load hook.
pub fn on_page_load<F>(mut self, on_page_load: F) -> Self
where
F: Fn(Window<WindowManager<E, L, A, R>>, PageLoadPayload) + Send + Sync + 'static,
F: Fn(Window<Args<E, L, A, R>>, PageLoadPayload) + Send + Sync + 'static,
{
self.on_page_load = Box::new(on_page_load);
self
}
/// Adds a plugin to the runtime.
pub fn plugin<P: Plugin<WindowManager<E, L, A, R>> + 'static>(mut self, plugin: P) -> Self {
pub fn plugin<P: Plugin<Args<E, L, A, R>> + 'static>(mut self, plugin: P) -> Self {
self.plugins.register(plugin);
self
}

View File

@ -17,11 +17,12 @@ use crate::{
window::{DetachedWindow, PendingWindow},
Dispatch, Icon, Runtime,
},
sealed::ParamsPrivate,
sealed::ParamsBase,
Context, Params, Window,
};
use serde::Serialize;
use serde_json::Value as JsonValue;
use std::marker::PhantomData;
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
@ -50,42 +51,55 @@ pub struct InnerWindowManager<M: Params> {
package_info: PackageInfo,
}
pub struct WindowManager<E, L, A, R>
where
E: Tag,
L: Tag,
A: Assets + 'static,
R: Runtime,
{
pub(crate) inner: Arc<InnerWindowManager<Self>>,
/// A [Zero Sized Type] marker representing a full [`Params`].
///
/// [Zero Sized Type]: https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts
pub struct Args<E: Tag, L: Tag, A: Assets, R: Runtime> {
_event: PhantomData<fn() -> E>,
_label: PhantomData<fn() -> L>,
_assets: PhantomData<fn() -> A>,
_runtime: PhantomData<fn() -> R>,
}
impl<E, L, A, R> Clone for WindowManager<E, L, A, R>
where
E: Tag,
L: Tag,
A: Assets + 'static,
R: Runtime,
{
fn clone(&self) -> Self {
impl<E: Tag, L: Tag, A: Assets, R: Runtime> Default for Args<E, L, A, R> {
fn default() -> Self {
Self {
inner: self.inner.clone(),
_event: PhantomData,
_label: PhantomData,
_assets: PhantomData,
_runtime: PhantomData,
}
}
}
impl<E, L, A, R> WindowManager<E, L, A, R>
where
E: Tag,
L: Tag,
A: Assets,
R: Runtime,
{
impl<E: Tag, L: Tag, A: Assets, R: Runtime> ParamsBase for Args<E, L, A, R> {}
impl<E: Tag, L: Tag, A: Assets, R: Runtime> Params for Args<E, L, A, R> {
type Event = E;
type Label = L;
type Assets = A;
type Runtime = R;
}
pub struct WindowManager<P: Params> {
pub inner: Arc<InnerWindowManager<P>>,
_marker: Args<P::Event, P::Label, P::Assets, P::Runtime>,
}
impl<P: Params> Clone for WindowManager<P> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
_marker: Args::default(),
}
}
}
impl<P: Params> WindowManager<P> {
pub(crate) fn with_handlers(
context: Context<A>,
plugins: PluginStore<Self>,
invoke_handler: Box<InvokeHandler<Self>>,
on_page_load: Box<OnPageLoad<Self>>,
context: Context<P::Assets>,
plugins: PluginStore<P>,
invoke_handler: Box<InvokeHandler<P>>,
on_page_load: Box<OnPageLoad<P>>,
) -> Self {
Self {
inner: Arc::new(InnerWindowManager {
@ -100,11 +114,12 @@ where
salts: Mutex::default(),
package_info: context.package_info,
}),
_marker: Args::default(),
}
}
/// Get a locked handle to the windows.
pub(crate) fn windows_lock(&self) -> MutexGuard<'_, HashMap<L, Window<Self>>> {
pub(crate) fn windows_lock(&self) -> MutexGuard<'_, HashMap<P::Label, Window<P>>> {
self.inner.windows.lock().expect("poisoned window manager")
}
@ -125,11 +140,11 @@ where
fn prepare_attributes(
&self,
attrs: <R::Dispatcher as Dispatch>::Attributes,
attrs: <<P::Runtime as Runtime>::Dispatcher as Dispatch>::Attributes,
url: String,
label: L,
pending_labels: &[L],
) -> crate::Result<<R::Dispatcher as Dispatch>::Attributes> {
label: P::Label,
pending_labels: &[P::Label],
) -> crate::Result<<<P::Runtime as Runtime>::Dispatcher as Dispatch>::Attributes> {
let is_init_global = self.inner.config.build.with_global_tauri;
let plugin_init = self
.inner
@ -179,7 +194,7 @@ where
Ok(attributes)
}
fn prepare_rpc_handler(&self) -> WebviewRpcHandler<Self> {
fn prepare_rpc_handler(&self) -> WebviewRpcHandler<P> {
let manager = self.clone();
Box::new(move |window, request| {
let window = manager.attach_window(window);
@ -248,7 +263,7 @@ where
}
}
fn prepare_file_drop(&self) -> FileDropHandler<Self> {
fn prepare_file_drop(&self) -> FileDropHandler<P> {
let manager = self.clone();
Box::new(move |event, window| {
let manager = manager.clone();
@ -341,13 +356,13 @@ where
#[cfg(test)]
mod test {
use super::WindowManager;
use super::{Args, WindowManager};
use crate::{generate_context, plugin::PluginStore, runtime::flavors::wry::Wry};
#[test]
fn check_get_url() {
let context = generate_context!("test/fixture/src-tauri/tauri.conf.json", crate);
let manager: WindowManager<String, String, _, Wry> = WindowManager::with_handlers(
let manager: WindowManager<Args<String, String, _, Wry>> = WindowManager::with_handlers(
context,
PluginStore::default(),
Box::new(|_| ()),
@ -358,25 +373,15 @@ mod test {
assert_eq!(manager.get_url(), "tauri://studio.tauri.example");
#[cfg(dev)]
{
use crate::sealed::ParamsPrivate;
assert_eq!(manager.get_url(), manager.config().build.dev_path);
}
assert_eq!(manager.get_url(), manager.config().build.dev_path);
}
}
impl<E, L, A, R> ParamsPrivate<Self> for WindowManager<E, L, A, R>
where
E: Tag,
L: Tag,
A: Assets + 'static,
R: Runtime,
{
fn run_invoke_handler(&self, message: InvokeMessage<Self>) {
impl<P: Params> WindowManager<P> {
pub fn run_invoke_handler(&self, message: InvokeMessage<P>) {
(self.inner.invoke_handler)(message);
}
fn run_on_page_load(&self, window: Window<Self>, payload: PageLoadPayload) {
pub fn run_on_page_load(&self, window: Window<P>, payload: PageLoadPayload) {
(self.inner.on_page_load)(window.clone(), payload.clone());
self
.inner
@ -385,8 +390,7 @@ where
.expect("poisoned plugin store")
.on_page_load(window, payload);
}
fn extend_api(&self, command: String, message: InvokeMessage<Self>) {
pub fn extend_api(&self, command: String, message: InvokeMessage<P>) {
self
.inner
.plugins
@ -394,8 +398,7 @@ where
.expect("poisoned plugin store")
.extend_api(command, message);
}
fn initialize_plugins(&self) -> crate::Result<()> {
pub fn initialize_plugins(&self) -> crate::Result<()> {
self
.inner
.plugins
@ -404,11 +407,11 @@ where
.initialize(&self.inner.config.plugins)
}
fn prepare_window(
pub fn prepare_window(
&self,
mut pending: PendingWindow<Self>,
pending_labels: &[L],
) -> crate::Result<PendingWindow<Self>> {
mut pending: PendingWindow<P>,
pending_labels: &[P::Label],
) -> crate::Result<PendingWindow<P>> {
let (is_local, url) = match &pending.url {
WindowUrl::App(path) => {
let url = self.get_url();
@ -439,8 +442,7 @@ where
Ok(pending)
}
fn attach_window(&self, window: DetachedWindow<Self>) -> Window<Self> {
pub fn attach_window(&self, window: DetachedWindow<P>) -> Window<P> {
let window = Window::new(self.clone(), window);
// insert the window into our manager
@ -462,8 +464,7 @@ where
window
}
fn emit_filter_internal<S: Serialize + Clone, F: Fn(&Window<Self>) -> bool>(
pub fn emit_filter_internal<S: Serialize + Clone, F: Fn(&Window<P>) -> bool>(
&self,
event: String,
payload: Option<S>,
@ -475,10 +476,9 @@ where
.filter(|&w| filter(w))
.try_for_each(|window| window.emit_internal(event.clone(), payload.clone()))
}
fn emit_filter<S: Serialize + Clone, F: Fn(&Window<Self>) -> bool>(
pub fn emit_filter<S: Serialize + Clone, F: Fn(&Window<P>) -> bool>(
&self,
event: E,
event: P::Event,
payload: Option<S>,
filter: F,
) -> crate::Result<()> {
@ -488,53 +488,47 @@ where
.filter(|&w| filter(w))
.try_for_each(|window| window.emit(&event, payload.clone()))
}
fn labels(&self) -> HashSet<L> {
pub fn labels(&self) -> HashSet<P::Label> {
self.windows_lock().keys().cloned().collect()
}
fn config(&self) -> &Config {
pub fn config(&self) -> &Config {
&self.inner.config
}
fn package_info(&self) -> &PackageInfo {
pub fn package_info(&self) -> &PackageInfo {
&self.inner.package_info
}
fn unlisten(&self, handler_id: EventHandler) {
pub fn unlisten(&self, handler_id: EventHandler) {
self.inner.listeners.unlisten(handler_id)
}
fn trigger(&self, event: E, window: Option<L>, data: Option<String>) {
pub fn trigger(&self, event: P::Event, window: Option<P::Label>, data: Option<String>) {
self.inner.listeners.trigger(event, window, data)
}
fn listen<F: Fn(Event) + Send + 'static>(
pub fn listen<F: Fn(Event) + Send + 'static>(
&self,
event: E,
window: Option<L>,
event: P::Event,
window: Option<P::Label>,
handler: F,
) -> EventHandler {
self.inner.listeners.listen(event, window, handler)
}
fn once<F: Fn(Event) + Send + 'static>(&self, event: E, window: Option<L>, handler: F) {
pub fn once<F: Fn(Event) + Send + 'static>(
&self,
event: P::Event,
window: Option<P::Label>,
handler: F,
) {
self.inner.listeners.once(event, window, handler)
}
fn event_listeners_object_name(&self) -> String {
pub fn event_listeners_object_name(&self) -> String {
self.inner.listeners.listeners_object_name()
}
fn event_queue_object_name(&self) -> String {
pub fn event_queue_object_name(&self) -> String {
self.inner.listeners.queue_object_name()
}
fn event_emit_function_name(&self) -> String {
pub fn event_emit_function_name(&self) -> String {
self.inner.listeners.function_name()
}
fn generate_salt(&self) -> Uuid {
pub fn generate_salt(&self) -> Uuid {
let salt = Uuid::new_v4();
self
.inner
@ -544,8 +538,7 @@ where
.insert(salt);
salt
}
fn verify_salt(&self, salt: String) -> bool {
pub fn verify_salt(&self, salt: String) -> bool {
// flat out ignore any invalid uuids
let uuid: Uuid = match salt.parse() {
Ok(uuid) => uuid,
@ -560,25 +553,10 @@ where
.expect("poisoned salt mutex")
.remove(&uuid)
}
fn get_window(&self, label: &L) -> Option<Window<Self>> {
pub fn get_window(&self, label: &P::Label) -> Option<Window<P>> {
self.windows_lock().get(label).cloned()
}
fn windows(&self) -> HashMap<L, Window<Self>> {
pub fn windows(&self) -> HashMap<P::Label, Window<P>> {
self.windows_lock().clone()
}
}
impl<E, L, A, R> Params for WindowManager<E, L, A, R>
where
E: Tag,
L: Tag,
A: Assets,
R: Runtime,
{
type Event = E;
type Label = L;
type Assets = A;
type Runtime = R;
}

View File

@ -14,7 +14,7 @@ use crate::{
webview::{CustomProtocol, FileDropHandler, WebviewRpcHandler},
Dispatch, Runtime,
},
sealed::{ManagerPrivate, RuntimeOrDispatch},
sealed::{ManagerBase, RuntimeOrDispatch},
Attributes, Icon, Manager, Params,
};
use serde::Serialize;
@ -113,6 +113,7 @@ impl<M: Params> PartialEq for DetachedWindow<M> {
/// We want to export the runtime related window at the crate root, but not look like a re-export.
pub(crate) mod export {
use super::*;
use crate::runtime::manager::WindowManager;
/// A webview window managed by Tauri.
///
@ -120,12 +121,12 @@ pub(crate) mod export {
/// the same application.
///
/// TODO: expand these docs since this is a pretty important type
pub struct Window<M: Params> {
pub struct Window<P: Params> {
/// The webview window created by the runtime.
window: DetachedWindow<M>,
window: DetachedWindow<P>,
/// The manager to associate this webview window with.
manager: M,
manager: WindowManager<P>,
}
impl<M: Params> Clone for Window<M> {
@ -137,40 +138,40 @@ pub(crate) mod export {
}
}
impl<M: Params> Hash for Window<M> {
impl<P: Params> Hash for Window<P> {
/// Only use the [`Window`]'s label to represent its hash.
fn hash<H: Hasher>(&self, state: &mut H) {
self.window.label.hash(state)
}
}
impl<M: Params> Eq for Window<M> {}
impl<M: Params> PartialEq for Window<M> {
impl<P: Params> Eq for Window<P> {}
impl<P: Params> PartialEq for Window<P> {
/// Only use the [`Window`]'s label to compare equality.
fn eq(&self, other: &Self) -> bool {
self.window.label.eq(&other.window.label)
}
}
impl<M: Params> Manager<M> for Window<M> {}
impl<M: Params> ManagerPrivate<M> for Window<M> {
fn manager(&self) -> &M {
impl<P: Params> Manager<P> for Window<P> {}
impl<P: Params> ManagerBase<P> for Window<P> {
fn manager(&self) -> &WindowManager<P> {
&self.manager
}
fn runtime(&mut self) -> RuntimeOrDispatch<'_, M> {
fn runtime(&mut self) -> RuntimeOrDispatch<'_, P> {
RuntimeOrDispatch::Dispatch(self.dispatcher())
}
}
impl<M: Params> Window<M> {
impl<P: Params> Window<P> {
/// Create a new window that is attached to the manager.
pub(crate) fn new(manager: M, window: DetachedWindow<M>) -> Self {
pub(crate) fn new(manager: WindowManager<P>, window: DetachedWindow<P>) -> Self {
Self { manager, window }
}
/// The current window's dispatcher.
pub(crate) fn dispatcher(&self) -> <M::Runtime as Runtime>::Dispatcher {
pub(crate) fn dispatcher(&self) -> <P::Runtime as Runtime>::Dispatcher {
self.window.dispatcher.clone()
}
@ -196,7 +197,7 @@ pub(crate) mod export {
}
/// The label of this window.
pub fn label(&self) -> &M::Label {
pub fn label(&self) -> &P::Label {
&self.window.label
}
@ -222,7 +223,7 @@ pub(crate) mod export {
}
/// Emits an event to the current window.
pub fn emit<S: Serialize>(&self, event: &M::Event, payload: Option<S>) -> crate::Result<()> {
pub fn emit<S: Serialize>(&self, event: &P::Event, payload: Option<S>) -> crate::Result<()> {
self.emit_internal(event.clone(), payload)
}
@ -239,14 +240,14 @@ pub(crate) mod export {
/// Emits an event on all windows except this one.
pub fn emit_others<S: Serialize + Clone>(
&self,
event: M::Event,
event: P::Event,
payload: Option<S>,
) -> crate::Result<()> {
self.manager.emit_filter(event, payload, |w| w != self)
}
/// Listen to an event on this window.
pub fn listen<F>(&self, event: M::Event, handler: F) -> EventHandler
pub fn listen<F>(&self, event: P::Event, handler: F) -> EventHandler
where
F: Fn(Event) + Send + 'static,
{
@ -255,7 +256,7 @@ pub(crate) mod export {
}
/// Listen to a an event on this window a single time.
pub fn once<F>(&self, event: M::Event, handler: F)
pub fn once<F>(&self, event: P::Event, handler: F)
where
F: Fn(Event) + Send + 'static,
{
@ -264,7 +265,7 @@ pub(crate) mod export {
}
/// Triggers an event on this window.
pub(crate) fn trigger(&self, event: M::Event, data: Option<String>) {
pub(crate) fn trigger(&self, event: P::Event, data: Option<String>) {
let label = self.window.label.clone();
self.manager.trigger(event, Some(label), data)
}