Skip to content

Commit

Permalink
add: implement ios
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Nov 4, 2024
1 parent f54fcee commit 348acf6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .changes/badge_count.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"tao": patch
---

Add **set_badge_count** for Linux; **set_badge_label** for Macos; **set_overlay_icon** for Windows
Add **set_badge_count** for Linux, iOS; **set_badge_label** for Macos; **set_overlay_icon** for Windows
10 changes: 10 additions & 0 deletions src/platform_impl/ios/badge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use objc::runtime::{Class, Object};
use objc::{msg_send, sel, sel_impl};

pub fn set_badge_count(count: i32) {
unsafe {
let ui_application = Class::get("UIApplication").expect("Failed to get UIApplication class");
let app: *mut Object = msg_send![ui_application, sharedApplication];
let _: () = msg_send![app, setApplicationIconBadgeNumber:count];
}
}
6 changes: 6 additions & 0 deletions src/platform_impl/ios/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
};

use crate::platform_impl::platform::{
set_badge_count,
app_state,
ffi::{
id, kCFRunLoopAfterWaiting, kCFRunLoopBeforeWaiting, kCFRunLoopCommonModes,
Expand Down Expand Up @@ -94,6 +95,11 @@ impl<T: 'static> EventLoopWindowTarget<T> {
debug!("`EventLoopWindowTarget::cursor_position` is ignored on iOS");
Ok((0, 0).into())
}

/// Sets badge count on iOS launcher. 0 hides the count
pub fn set_badge_count(&self, count: i32) {
set_badge_count(count);
}
}

#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
Expand Down
3 changes: 2 additions & 1 deletion src/platform_impl/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ mod keycode;
mod monitor;
mod view;
mod window;
mod badge;

use std::fmt;

Expand All @@ -90,7 +91,7 @@ pub use self::{
monitor::{MonitorHandle, VideoMode},
window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId},
};

pub(crate) use badge::set_badge_count;
pub(crate) use crate::icon::NoIcon as PlatformIcon;

// todo: implement iOS keyboard event
Expand Down
6 changes: 6 additions & 0 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
monitor::MonitorHandle as RootMonitorHandle,
platform::ios::{MonitorHandleExtIOS, ScreenEdge, ValidOrientations},
platform_impl::platform::{
set_badge_count,
app_state,
event_loop::{self, EventProxy, EventWrapper},
ffi::{
Expand Down Expand Up @@ -440,6 +441,11 @@ impl Inner {
pub fn theme(&self) -> Theme {
Theme::Light
}

/// Sets badge count on iOS launcher. 0 hides the count
pub fn set_badge_count(&self, count: i32) {
set_badge_count(count);
}
}

pub struct Window {
Expand Down

0 comments on commit 348acf6

Please sign in to comment.