Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Gammon <[email protected]>
  • Loading branch information
sgammon committed Nov 16, 2024
1 parent f167515 commit 7ca11ae
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
6 changes: 3 additions & 3 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
66 changes: 29 additions & 37 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}
Expand All @@ -498,30 +492,28 @@ fn register_push_channel(_channel: PushNotificationChannel) {
#[cfg(feature = "push-notifications")]
fn attach_callback<T, F>(operation: IAsyncOperation<T>, callback: F) -> windows::core::Result<()>
where
T: windows::core::RuntimeType + 'static,
F: FnOnce(windows::core::Result<T>) + Send + Clone + Copy + 'static,
T: windows::core::RuntimeType + 'static,
F: FnOnce(windows::core::Result<T>) + 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::<String>(
windows::core::HRESULT(0x800704C7u32 as i32), // Operation canceled
"Operation was canceled".into(),
)),
AsyncStatus::Error => Err(windows::core::Error::new::<String>(
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::<String>(
windows::core::HRESULT(0x800704C7u32 as i32), // Operation canceled
"Operation was canceled".into(),
)),
AsyncStatus::Error => Err(windows::core::Error::new::<String>(
op.unwrap().ErrorCode().unwrap(), // Operation failed
"Operation failed".into(),
)),
AsyncStatus::Started => unreachable!(),
_ => unreachable!(),
};
callback(result.expect("empty waiter"));
Ok(())
},
))
}
}
13 changes: 5 additions & 8 deletions src/platform_impl/macos/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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] }
}
4 changes: 3 additions & 1 deletion src/platform_impl/macos/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ impl AppState {
}

pub fn did_register_push_token(token_data: Vec<u8>) {
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) {
Expand Down
48 changes: 23 additions & 25 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7ca11ae

Please sign in to comment.