chore: rename M: Params to P: Params (#1771)

This commit is contained in:
Lucas Fernandes Nogueira
2021-05-10 22:26:18 -03:00
committed by GitHub
parent 46ea873311
commit 21ce355c48
12 changed files with 63 additions and 63 deletions

View File

@@ -539,10 +539,10 @@ impl Dispatch for WryDispatcher {
.map_err(|_| Error::FailedToSendMessage)
}
fn create_window<M: Params<Runtime = Self::Runtime>>(
fn create_window<P: Params<Runtime = Self::Runtime>>(
&mut self,
pending: PendingWindow<M>,
) -> Result<DetachedWindow<M>> {
pending: PendingWindow<P>,
) -> Result<DetachedWindow<P>> {
let (tx, rx) = channel();
let label = pending.label.clone();
let context = self.context.clone();
@@ -782,10 +782,10 @@ impl Runtime for Wry {
})
}
fn create_window<M: Params<Runtime = Self>>(
fn create_window<P: Params<Runtime = Self>>(
&self,
pending: PendingWindow<M>,
) -> Result<DetachedWindow<M>> {
pending: PendingWindow<P>,
) -> Result<DetachedWindow<P>> {
let label = pending.label.clone();
let proxy = self.event_loop.create_proxy();
let webview = create_webview(
@@ -1052,10 +1052,10 @@ impl Runtime for Wry {
}
}
fn create_webview<M: Params<Runtime = Wry>>(
fn create_webview<P: Params<Runtime = Wry>>(
event_loop: &EventLoopWindowTarget<Message>,
context: DispatcherContext,
pending: PendingWindow<M>,
pending: PendingWindow<P>,
) -> Result<WebView> {
let PendingWindow {
webview_attributes,
@@ -1098,10 +1098,10 @@ fn create_webview<M: Params<Runtime = Wry>>(
}
/// Create a wry rpc handler from a tauri rpc handler.
fn create_rpc_handler<M: Params<Runtime = Wry>>(
fn create_rpc_handler<P: Params<Runtime = Wry>>(
context: DispatcherContext,
label: M::Label,
handler: WebviewRpcHandler<M>,
label: P::Label,
handler: WebviewRpcHandler<P>,
) -> Box<dyn Fn(&Window, WryRpcRequest) -> Option<RpcResponse> + 'static> {
Box::new(move |window, request| {
handler(
@@ -1119,10 +1119,10 @@ fn create_rpc_handler<M: Params<Runtime = Wry>>(
}
/// Create a wry file drop handler from a tauri file drop handler.
fn create_file_drop_handler<M: Params<Runtime = Wry>>(
fn create_file_drop_handler<P: Params<Runtime = Wry>>(
context: DispatcherContext,
label: M::Label,
handler: FileDropHandler<M>,
label: P::Label,
handler: FileDropHandler<P>,
) -> Box<dyn Fn(&Window, WryFileDropEvent) -> bool + 'static> {
Box::new(move |window, event| {
handler(

View File

@@ -177,11 +177,11 @@ pub enum FileDropEvent {
}
/// Rpc handler.
pub type WebviewRpcHandler<M> = Box<dyn Fn(DetachedWindow<M>, RpcRequest) + Send>;
pub type WebviewRpcHandler<P> = Box<dyn Fn(DetachedWindow<P>, RpcRequest) + Send>;
/// File drop handler callback
/// Return `true` in the callback to block the OS' default behavior of handling a file drop.
pub type FileDropHandler<M> = Box<dyn Fn(FileDropEvent, DetachedWindow<M>) -> bool + Send>;
pub type FileDropHandler<P> = Box<dyn Fn(FileDropEvent, DetachedWindow<P>) -> bool + Send>;
#[derive(Deserialize)]
pub struct InvokePayload {

View File

@@ -55,32 +55,32 @@ pub struct MenuEvent {
}
/// A webview window that has yet to be built.
pub struct PendingWindow<M: Params> {
pub struct PendingWindow<P: Params> {
/// The label that the window will be named.
pub label: M::Label,
pub label: P::Label,
/// The [`WindowBuilder`] that the window will be created with.
pub window_builder: <<M::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder,
pub window_builder: <<P::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder,
/// The [`WebviewAttributes`] that the webview will be created with.
pub webview_attributes: WebviewAttributes,
/// How to handle RPC calls on the webview window.
pub rpc_handler: Option<WebviewRpcHandler<M>>,
pub rpc_handler: Option<WebviewRpcHandler<P>>,
/// How to handle a file dropping onto the webview window.
pub file_drop_handler: Option<FileDropHandler<M>>,
pub file_drop_handler: Option<FileDropHandler<P>>,
/// The resolved URL to load on the webview.
pub url: String,
}
impl<M: Params> PendingWindow<M> {
impl<P: Params> PendingWindow<P> {
/// Create a new [`PendingWindow`] with a label and starting url.
pub fn new(
window_builder: <<M::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder,
window_builder: <<P::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder,
webview_attributes: WebviewAttributes,
label: M::Label,
label: P::Label,
) -> Self {
Self {
window_builder,
@@ -96,11 +96,11 @@ impl<M: Params> PendingWindow<M> {
pub fn with_config(
window_config: WindowConfig,
webview_attributes: WebviewAttributes,
label: M::Label,
label: P::Label,
) -> Self {
Self {
window_builder:
<<<M::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder>::with_config(
<<<P::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder>::with_config(
window_config,
),
webview_attributes,
@@ -113,15 +113,15 @@ impl<M: Params> PendingWindow<M> {
}
/// A webview window that is not yet managed by Tauri.
pub struct DetachedWindow<M: Params> {
pub struct DetachedWindow<P: Params> {
/// Name of the window
pub label: M::Label,
pub label: P::Label,
/// The [`Dispatch`](crate::Dispatch) associated with the window.
pub dispatcher: <M::Runtime as Runtime>::Dispatcher,
pub dispatcher: <P::Runtime as Runtime>::Dispatcher,
}
impl<M: Params> Clone for DetachedWindow<M> {
impl<P: Params> Clone for DetachedWindow<P> {
fn clone(&self) -> Self {
Self {
label: self.label.clone(),
@@ -130,15 +130,15 @@ impl<M: Params> Clone for DetachedWindow<M> {
}
}
impl<M: Params> Hash for DetachedWindow<M> {
impl<P: Params> Hash for DetachedWindow<P> {
/// Only use the [`DetachedWindow`]'s label to represent its hash.
fn hash<H: Hasher>(&self, state: &mut H) {
self.label.hash(state)
}
}
impl<M: Params> Eq for DetachedWindow<M> {}
impl<M: Params> PartialEq for DetachedWindow<M> {
impl<P: Params> Eq for DetachedWindow<P> {}
impl<P: Params> PartialEq for DetachedWindow<P> {
/// Only use the [`DetachedWindow`]'s label to compare equality.
fn eq(&self, other: &Self) -> bool {
self.label.eq(&other.label)

View File

@@ -141,9 +141,9 @@ impl<P: Params> App<P> {
}
#[cfg(feature = "updater")]
impl<M: Params> App<M> {
impl<P: Params> App<P> {
/// Runs the updater hook with built-in dialog.
fn run_updater_dialog(&self, window: Window<M>) {
fn run_updater_dialog(&self, window: Window<P>) {
let updater_config = self.manager.config().tauri.updater.clone();
let package_info = self.manager.package_info().clone();
crate::async_runtime::spawn(async move {
@@ -152,12 +152,12 @@ impl<M: Params> App<M> {
}
/// Listen updater events when dialog are disabled.
fn listen_updater_events(&self, window: Window<M>) {
fn listen_updater_events(&self, window: Window<P>) {
let updater_config = self.manager.config().tauri.updater.clone();
updater::listener(updater_config, self.manager.package_info().clone(), &window);
}
fn run_updater(&self, main_window: Option<Window<M>>) {
fn run_updater(&self, main_window: Option<Window<P>>) {
if let Some(main_window) = main_window {
let event_window = main_window.clone();
let updater_config = self.manager.config().tauri.updater.clone();
@@ -172,7 +172,7 @@ impl<M: Params> App<M> {
// invoke the Event `tauri://update` from JS or rust side.
main_window.listen(
updater::EVENT_CHECK_UPDATE
.parse::<M::Event>()
.parse::<P::Event>()
.unwrap_or_else(|_| panic!("bad label")),
move |_msg| {
let window = event_window.clone();

View File

@@ -57,10 +57,10 @@ enum Module {
}
impl Module {
fn run<M: Params>(
fn run<P: Params>(
self,
window: Window<M>,
resolver: InvokeResolver<M>,
window: Window<P>,
resolver: InvokeResolver<P>,
config: Arc<Config>,
package_info: PackageInfo,
) {

View File

@@ -25,7 +25,7 @@ pub enum Cmd {
}
impl Cmd {
pub fn run<M: Params>(self, window: Window<M>) -> crate::Result<InvokeResponse> {
pub fn run<P: Params>(self, window: Window<P>) -> crate::Result<InvokeResponse> {
match self {
Self::Listen { event, handler } => {
let event_id = rand::random();
@@ -42,11 +42,11 @@ impl Cmd {
payload,
} => {
// Panic if the user's `Tag` type decided to return an error while parsing.
let e: M::Event = event
let e: P::Event = event
.parse()
.unwrap_or_else(|_| panic!("Event module received unhandled event: {}", event));
let window_label: Option<M::Label> = window_label.map(|l| {
let window_label: Option<P::Label> = window_label.map(|l| {
l.parse()
.unwrap_or_else(|_| panic!("Event module recieved unhandled window: {}", l))
});
@@ -65,7 +65,7 @@ impl Cmd {
}
}
pub fn unlisten_js<M: Params>(window: &Window<M>, event_id: u64) -> String {
pub fn unlisten_js<P: Params>(window: &Window<P>, event_id: u64) -> String {
format!(
"
for (var event in (window['{listeners}'] || {{}})) {{
@@ -80,8 +80,8 @@ pub fn unlisten_js<M: Params>(window: &Window<M>, event_id: u64) -> String {
)
}
pub fn listen_js<M: Params>(
window: &Window<M>,
pub fn listen_js<P: Params>(
window: &Window<P>,
event: String,
event_id: u64,
handler: String,

View File

@@ -55,7 +55,7 @@ fn register_shortcut<D: Dispatch>(
#[cfg(not(global_shortcut_all))]
impl Cmd {
pub fn run<M: Params>(self, _window: Window<M>) -> crate::Result<InvokeResponse> {
pub fn run<P: Params>(self, _window: Window<P>) -> crate::Result<InvokeResponse> {
Err(crate::Error::ApiNotAllowlisted(
"globalShortcut > all".to_string(),
))
@@ -64,7 +64,7 @@ impl Cmd {
#[cfg(global_shortcut_all)]
impl Cmd {
pub fn run<M: Params>(self, window: Window<M>) -> crate::Result<InvokeResponse> {
pub fn run<P: Params>(self, window: Window<P>) -> crate::Result<InvokeResponse> {
match self {
Self::Register { shortcut, handler } => {
let dispatcher = window.dispatcher();

View File

@@ -73,7 +73,7 @@ pub enum Cmd {
impl Cmd {
#[allow(unused_variables)]
pub fn run<M: Params>(self, window: Window<M>) -> crate::Result<InvokeResponse> {
pub fn run<P: Params>(self, window: Window<P>) -> crate::Result<InvokeResponse> {
match self {
Self::Execute {
program,

View File

@@ -229,9 +229,9 @@ impl<P: Params> InvokeResolver<P> {
}
/// An invoke message.
pub struct InvokeMessage<M: Params> {
pub struct InvokeMessage<P: Params> {
/// The window that received the invoke message.
pub(crate) window: Window<M>,
pub(crate) window: Window<P>,
/// Application managed state.
pub(crate) state: Arc<StateManager>,
/// The RPC command.

View File

@@ -383,10 +383,10 @@ struct UpdateManifest {
}
/// Check if there is any new update with builtin dialog.
pub(crate) async fn check_update_with_dialog<M: Params>(
pub(crate) async fn check_update_with_dialog<P: Params>(
updater_config: UpdaterConfig,
package_info: crate::api::PackageInfo,
window: Window<M>,
window: Window<P>,
) {
if let Some(endpoints) = updater_config.endpoints.clone() {
// check updates
@@ -425,17 +425,17 @@ pub(crate) async fn check_update_with_dialog<M: Params>(
/// Experimental listener
/// This function should be run on the main thread once.
pub(crate) fn listener<M: Params>(
pub(crate) fn listener<P: Params>(
updater_config: UpdaterConfig,
package_info: crate::api::PackageInfo,
window: &Window<M>,
window: &Window<P>,
) {
let isolated_window = window.clone();
// Wait to receive the event `"tauri://update"`
window.listen(
EVENT_CHECK_UPDATE
.parse::<M::Event>()
.parse::<P::Event>()
.unwrap_or_else(|_| panic!("bad label")),
move |_msg| {
let window = isolated_window.clone();
@@ -469,7 +469,7 @@ pub(crate) fn listener<M: Params>(
// Emit `tauri://update-available`
let _ = window.emit(
&tauri_event::<M::Event>(EVENT_UPDATE_AVAILABLE),
&tauri_event::<P::Event>(EVENT_UPDATE_AVAILABLE),
Some(UpdateManifest {
body,
date: updater.date.clone(),
@@ -480,7 +480,7 @@ pub(crate) fn listener<M: Params>(
// Listen for `tauri://update-install`
window.once(
EVENT_INSTALL_UPDATE
.parse::<M::Event>()
.parse::<P::Event>()
.unwrap_or_else(|_| panic!("bad label")),
move |_msg| {
let window = window_isolation.clone();
@@ -522,9 +522,9 @@ pub(crate) fn listener<M: Params>(
}
// Send a status update via `tauri://update-status` event.
fn send_status_update<M: Params>(window: Window<M>, status: &str, error: Option<String>) {
fn send_status_update<P: Params>(window: Window<P>, status: &str, error: Option<String>) {
let _ = window.emit(
&tauri_event::<M::Event>(EVENT_STATUS_UPDATE),
&tauri_event::<P::Event>(EVENT_STATUS_UPDATE),
Some(StatusEvent {
error,
status: String::from(status),

View File

@@ -105,7 +105,7 @@ pub struct Window<P: Params> {
manager: WindowManager<P>,
}
impl<M: Params> Clone for Window<M> {
impl<P: Params> Clone for Window<P> {
fn clone(&self) -> Self {
Self {
window: self.window.clone(),

View File

@@ -1,5 +1,5 @@
#[tauri::command(with_window)]
fn exit<M: tauri::Params>(window: tauri::Window<M>) {
fn exit<M: tauri::Params>(window: tauri::Window<P>) {
window.close().unwrap();
}