diff --git a/src/event.rs b/src/event.rs index 4f320f1e3..30d9bd088 100644 --- a/src/event.rs +++ b/src/event.rs @@ -40,13 +40,13 @@ use std::path::PathBuf; use std::time::Instant; +use crate::push::PushToken; use crate::{ dpi::{PhysicalPosition, PhysicalSize}, keyboard::{self, ModifiersState}, platform_impl, window::{Theme, WindowId}, }; -use crate::push::PushToken; /// Describes a generic event. /// diff --git a/src/event_loop.rs b/src/event_loop.rs index e99a62392..9739831b6 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -13,9 +13,6 @@ //! [create_proxy]: crate::event_loop::EventLoop::create_proxy //! [event_loop_proxy]: crate::event_loop::EventLoopProxy //! [send_event]: crate::event_loop::EventLoopProxy::send_event -use std::time::Instant; -use std::{error, fmt, marker::PhantomData, ops::Deref}; -use windows::Networking::PushNotifications::PushNotificationChannel; use crate::{ dpi::PhysicalPosition, error::ExternalError, @@ -24,6 +21,9 @@ use crate::{ platform_impl, window::{ProgressBarState, Theme}, }; +use std::time::Instant; +use std::{error, fmt, marker::PhantomData, ops::Deref}; +use windows::Networking::PushNotifications::PushNotificationChannel; /// Provides a way to retrieve events from the system and from the windows that were registered to /// the events loop. diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 4931c4199..205044e68 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -19,15 +19,11 @@ use windows::Win32::UI::Input::KeyboardAndMouse::*; #[cfg(feature = "push-notifications")] use windows::Networking::PushNotifications::{ - PushNotificationChannel, - PushNotificationChannelManager, + PushNotificationChannel, PushNotificationChannelManager, }; #[cfg(feature = "push-notifications")] -use { - windows::Foundation::AsyncStatus, - windows::Foundation::IAsyncOperation, -}; +use {windows::Foundation::AsyncStatus, windows::Foundation::IAsyncOperation}; pub type HWND = isize; pub type HMENU = isize; @@ -471,20 +467,18 @@ pub trait PushNotificationsExtWindows { return Err(1); } }; - let push_channel_op = match - mgr.CreatePushNotificationChannelForApplicationAsync() { + let push_channel_op = match mgr.CreatePushNotificationChannelForApplicationAsync() { Ok(channel) => channel, Err(_) => { return Err(2); } }; // Attach callback - attach_callback(push_channel_op, |result| { - match result { - Ok(value) => register_push_channel(value), - Err(e) => println!("Operation failed with error: {:?}", e), - } - }).expect("failed to attach callback for windows push notification token"); + attach_callback(push_channel_op, |result| match result { + Ok(value) => register_push_channel(value), + Err(e) => println!("Operation failed with error: {:?}", e), + }) + .expect("failed to attach callback for windows push notification token"); Ok(()) } @@ -498,30 +492,28 @@ fn register_push_channel(_channel: PushNotificationChannel) { #[cfg(feature = "push-notifications")] fn attach_callback(operation: IAsyncOperation, callback: F) -> windows::core::Result<()> where - T: windows::core::RuntimeType + 'static, - F: FnOnce(windows::core::Result) + Send + Clone + Copy + 'static, + T: windows::core::RuntimeType + 'static, + F: FnOnce(windows::core::Result) + Send + Clone + Copy + 'static, { unsafe { - operation.SetCompleted( - &windows::Foundation::AsyncOperationCompletedHandler::new( - move |op, _| { - let result = match op.unwrap().Status()? { - AsyncStatus::Completed => Ok(op.unwrap().GetResults()), - AsyncStatus::Canceled => Err(windows::core::Error:: new::( - windows::core::HRESULT(0x800704C7u32 as i32), // Operation canceled - "Operation was canceled".into(), - )), - AsyncStatus::Error => Err(windows::core::Error::new::( - op.unwrap().ErrorCode().unwrap(), // Operation failed - "Operation failed".into(), - )), - AsyncStatus::Started => unreachable!(), - _ => unreachable!(), - }; - callback(result.expect("empty waiter")); - Ok(()) - }, - ), - ) + operation.SetCompleted(&windows::Foundation::AsyncOperationCompletedHandler::new( + move |op, _| { + let result = match op.unwrap().Status()? { + AsyncStatus::Completed => Ok(op.unwrap().GetResults()), + AsyncStatus::Canceled => Err(windows::core::Error::new::( + windows::core::HRESULT(0x800704C7u32 as i32), // Operation canceled + "Operation was canceled".into(), + )), + AsyncStatus::Error => Err(windows::core::Error::new::( + op.unwrap().ErrorCode().unwrap(), // Operation failed + "Operation failed".into(), + )), + AsyncStatus::Started => unreachable!(), + _ => unreachable!(), + }; + callback(result.expect("empty waiter")); + Ok(()) + }, + )) } } diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs index 3864a562d..f8826ec51 100644 --- a/src/platform_impl/macos/app_delegate.rs +++ b/src/platform_impl/macos/app_delegate.rs @@ -9,12 +9,11 @@ use cocoa::{ foundation::NSString, }; use objc::{ - msg_send, - sel, - sel_impl, class, declare::ClassDecl, + msg_send, runtime::{Class, Object, Sel, BOOL}, + sel, sel_impl, }; use std::{ cell::{RefCell, RefMut}, @@ -211,14 +210,14 @@ extern "C" fn did_fail_to_register_for_apns(_: &Object, _: Sel, _: id, err: *mut let is_error: bool = msg_send![err, isKindOfClass:class!(NSError)]; if !is_error { trace!("Invalid error object type for push registration failure"); - return + return; } // Get the localizedDescription let description: *mut Object = msg_send![err, localizedDescription]; if description.is_null() { trace!("Error had no description"); - return + return; } // Convert NSString to str @@ -234,7 +233,5 @@ extern "C" fn did_fail_to_register_for_apns(_: &Object, _: Sel, _: id, err: *mut } fn get_shared_application() -> *mut Object { - unsafe { - msg_send![class!(NSApplication), sharedApplication] - } + unsafe { msg_send![class!(NSApplication), sharedApplication] } } diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index 9800bed1f..301449a3c 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -418,7 +418,9 @@ impl AppState { } pub fn did_register_push_token(token_data: Vec) { - HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::PushRegistration(token_data))); + HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::PushRegistration( + token_data, + ))); } pub fn did_fail_to_register_push_token(err: String) { diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 189d0207f..684192d3d 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -6,8 +6,30 @@ mod runner; +use crate::{ + dpi::{PhysicalPosition, PhysicalSize, PixelUnit}, + error::ExternalError, + event::{DeviceEvent, Event, Force, RawKeyEvent, Touch, TouchPhase, WindowEvent}, + event_loop::{ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW}, + keyboard::{KeyCode, ModifiersState}, + monitor::MonitorHandle as RootMonitorHandle, + platform_impl::platform::{ + dark_mode::try_window_theme, + dpi::{become_dpi_aware, dpi_to_scale_factor, enable_non_client_dpi_scaling}, + keyboard::is_msg_keyboard_related, + keyboard_layout::LAYOUT_CACHE, + minimal_ime::is_msg_ime_related, + monitor::{self, MonitorHandle}, + raw_input, util, + window::set_skip_taskbar, + window_state::{CursorFlags, WindowFlags, WindowState}, + wrap_device_id, WindowId, DEVICE_ID, + }, + window::{Fullscreen, Theme, WindowId as RootWindowId}, +}; use crossbeam_channel::{self as channel, Receiver, Sender}; use parking_lot::Mutex; +use runner::{EventLoopRunner, EventLoopRunnerShared}; use std::{ cell::Cell, collections::VecDeque, @@ -42,33 +64,9 @@ use windows::{ }, }, }; -use crate::{ - dpi::{PhysicalPosition, PhysicalSize, PixelUnit}, - error::ExternalError, - event::{DeviceEvent, Event, Force, RawKeyEvent, Touch, TouchPhase, WindowEvent}, - event_loop::{ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW}, - keyboard::{KeyCode, ModifiersState}, - monitor::MonitorHandle as RootMonitorHandle, - platform_impl::platform::{ - dark_mode::try_window_theme, - dpi::{become_dpi_aware, dpi_to_scale_factor, enable_non_client_dpi_scaling}, - keyboard::is_msg_keyboard_related, - keyboard_layout::LAYOUT_CACHE, - minimal_ime::is_msg_ime_related, - monitor::{self, MonitorHandle}, - raw_input, util, - window::set_skip_taskbar, - window_state::{CursorFlags, WindowFlags, WindowState}, - wrap_device_id, WindowId, DEVICE_ID, - }, - window::{Fullscreen, Theme, WindowId as RootWindowId}, -}; -use runner::{EventLoopRunner, EventLoopRunnerShared}; #[cfg(feature = "push-notifications")] -use { - windows::Networking::PushNotifications::PushNotificationChannel, -}; +use windows::Networking::PushNotifications::PushNotificationChannel; type GetPointerFrameInfoHistory = unsafe extern "system" fn( pointerId: u32,