-
Notifications
You must be signed in to change notification settings - Fork 426
API Spec for Badge Notifications in WindowsAppSdk #4823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SatwikKrSharma
merged 10 commits into
main
from
user/satwiksharma/badgeNotificationApiSpec
Dec 12, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5f3aab9
API Spec for Badge Notifications in WindowsAppSdk
7d85404
fixed typo
69a86ec
resolved PR comments
21a90fd
Pretty-print markdown
jonwis 73f49aa
resolved PR comments and added compatibility section in the spec
60c88f5
resolved API spec review comments
b49bb05
resolved nit comment
19abc54
Added clarification for None Glyph Type
dd48346
Formatting pass, packaging note
jonwis 02da576
Update BadgeNotifications-spec.md
SatwikKrSharma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| # Badge Notifications in Windows App SDK | ||
|
|
||
| This is the spec for proposal: [Issue #138](https://github.com/microsoft/WindowsAppSDK/issues/138) | ||
|
|
||
| # Background | ||
|
|
||
| A notification badge conveys summary or status information specific to your app. They can be numeric | ||
| (1-99) or one of a set of system-provided glyphs. Examples of information best conveyed through a | ||
| badge include network connection status in an online game, user status in a messaging app, number of | ||
| unread mails in a mail app, and number of new posts in a social media app. | ||
|
|
||
| Example of a numeric badge in Taskbar (One new message in Whatsapp): | ||
|
|
||
|  | ||
|
|
||
| Example of a system-provided glyph in taskbar (New message in Outlook): | ||
|
|
||
|  | ||
|
|
||
| This Badge notification functionality is missing in WinAppSDK, which not only blocks apps like | ||
| WhatsApp to move to WinAppSDK but also stops them from availing new features and goodness that we | ||
| are building in WinAppSDK. The scope of this document is to fill that gap and provide badge | ||
| notification capability in WinAppSDK as well. | ||
|
|
||
| > Note: This provids a subset of functionality present in WindowsSdk, but all that is necessary to | ||
| > post and clear a badge notification | ||
|
|
||
| # Description | ||
|
|
||
| Badge notifications provide users with a visual indicator of new or important content in your | ||
| application. This feature enhances user engagement by allowing them to quickly see updates without | ||
| needing to open the app. Badge notifications are already supported for UWP apps. This initiative is | ||
| to make badge notifications work in WindowsAppSdk. | ||
|
|
||
| For more details see: | ||
|
|
||
| - [Badge Notification WinRT APIs](https://learn.microsoft.com/windows/apps/design/shell/tiles-and-notifications/badges) | ||
| Defines all the API constructs that we have for Badge Notifications in WinRT today. | ||
|
|
||
SatwikKrSharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Compatibility | ||
|
|
||
| ## Supported Apps | ||
|
|
||
| This API requires package identity to match notifications to applications. See | ||
| [an overview of package identity](https://learn.microsoft.com/windows/apps/desktop/modernize/package-identity-overview) | ||
| for how to deploy your application as a package, or assign identity to your existing application | ||
| during its install time. | ||
|
|
||
| ## Notification Type | ||
|
|
||
| The badge notifications are local to the device. No remote server interaction is required or | ||
| supported for updating the badge count. | ||
|
|
||
| # Examples | ||
|
|
||
| ## Create a numeric badge (c++) | ||
|
|
||
| ```c++ | ||
| private void setBadgeNumber(uint32_t num) | ||
| { | ||
| winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current(); | ||
| manager.SetBadgeAsCount(num); | ||
| } | ||
| ``` | ||
|
|
||
| ## Create a Glyph badge (c++) | ||
|
|
||
| ```c++ | ||
| private void updateBadgeGlyph() | ||
| { | ||
| winrt::BadgeNotificationGlyph badgeNotificationGlyph = winrt::BadgeNotificationGlyph::Alert; | ||
| winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current(); | ||
| manager.SetBadgeAsGlyph(badgeNotificationGlyph); | ||
| } | ||
| ``` | ||
|
|
||
| ## Clear a badge | ||
|
|
||
| ```c++ | ||
| private void clearBadge() | ||
| { | ||
| winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current(); | ||
| manager.ClearBadge(); | ||
| } | ||
| ``` | ||
|
|
||
| ## To set an expiration time in a badge (c++) | ||
|
|
||
| ```c++ | ||
| private void updateBadgeGlyph() | ||
| { | ||
| winrt::BadgeNotificationGlyph badgeNotificationGlyph = winrt::BadgeNotificationGlyph::Alert | ||
|
|
||
| DateTime expirationTime = clock::now() + std::chrono::hours(24); | ||
|
|
||
| winrt::BadgeNotificationManager manager = winrt::BadgeNotificationManager::Current(); | ||
| manager.SetBadgeAsGlyph(badgeNotificationGlyph, expirationTime); | ||
| } | ||
| ``` | ||
|
|
||
| # API Description | ||
|
|
||
| ## BadgeNotificationManager class | ||
|
|
||
| The `BadgeNotificationManager` class is the central point for managing badge notifications for an | ||
| application. It provides the functionality to update or clear the badge displayed on the app's tile. | ||
| This class allows developers to modify the badge's appearance by setting a numeric value or a glyph | ||
| and also to remove the badge when it is no longer needed. | ||
|
|
||
| ## BadgeNotificationManager Properties | ||
|
|
||
| | Name | Description | Type | | ||
| | ------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------ | | ||
| | Current | Provides a default instance of the `BadgeNotificationManager` for use in updating or clearing badge notifications. | BadgeNotificationManager | | ||
|
|
||
| ## BadgeNotificationManager Methods | ||
|
|
||
| | Name | Description | Parameters | Returns | | ||
| | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------- | | ||
| | SetBadgeAsCount | Updates the badge on the app's tile to display a numeric value. This method is used to reflect a new status or count. | UInt32 `notificationCount` | void | | ||
| | SetBadgeAsCount | Updates the badge on the app's tile to display a numeric value, with an expiration time after which the badge should be cleared. | UInt32 `notificationCount`, Windows.Foundation.DateTime `expiration` | void | | ||
| | SetBadgeAsGlyph | Updates the badge on the app's tile to display a glyph. This method is used to reflect a new status represented by a glyph. | BadgeNotificationGlyph `glyphValue` | void | | ||
| | SetBadgeAsGlyph | Updates the badge on the app's tile to display a glyph, with an expiration time after which the badge should be cleared. | BadgeNotificationGlyph `glyphValue`, Windows.Foundation.DateTime `expiration` | void | | ||
| | ClearBadge | Removes the badge notifications for the app from the action center. This method is useful for clearing any badge notifications when they are no longer relevant or when the app wants to reset its badge status. | | void | | ||
|
|
||
| > Note: For Numeric badge if the count is greater then 99 it will be reported as "99+" | ||
|
|
||
| ## BadgeNotificationGlyph enum | ||
|
|
||
| The `BadgeNotificationGlyph` enum defines a set of predefined glyphs that can be used to represent | ||
| various statuses or notifications on an application's badge. These glyphs provide a visual cue on | ||
| the app's tile, allowing users to quickly understand the app's status or to be alerted to new | ||
| information without opening the app. | ||
|
|
||
| | Name | Description | Glyph | | ||
| | ----------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------ | | ||
| | None | No glyph is displayed. The badge will not be shown at all. It is equivalent to ClearBadge. | (No Badge Shown) | | ||
| | Activity | A glyph indicating some form of activity is taking place within the app. |  | | ||
| | Alarm | A glyph that represents an alarm, possibly indicating a set reminder or a timed event. |  | | ||
| | Alert | A glyph that suggests an alert or an important notification that may require immediate attention. |  | | ||
| | Attention | A glyph that signifies the need for attention, often used for notifications or new information. |  | | ||
| | Available | A glyph that indicates the user or a service is available, often used in communication apps. |  | | ||
| | Away | A glyph that shows the user is away or inactive, commonly used in status indicators for communication apps. |  | | ||
| | Busy | A glyph that represents the user being busy or engaged in an activity, preventing interruptions. |  | | ||
| | Error | A glyph that denotes an error has occurred, which may require user action to resolve. |  | | ||
| | NewMessage | A glyph that indicates the arrival of a new message, often used in messaging and email applications. |  | | ||
| | Paused | A glyph that signifies a pause in activity or content, such as media playback being paused. |  | | ||
| | Playing | A glyph that indicates media or content is currently playing. |  | | ||
| | Unavailable | A glyph that shows the user or a service is not currently available or offline. |  | | ||
|
|
||
| These glyphs are system-provided and standardized, ensuring a consistent look and feel across | ||
| different applications that use them. By using these glyphs, developers can convey specific states | ||
| or notifications to users in a visually intuitive manner. | ||
|
|
||
| > Note: Only system-provided badge images can be used. | ||
|
|
||
SatwikKrSharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # API Details | ||
|
|
||
| > Note: all of this new WinAppSDK API is to support Badge Notifications in WindowsAppSdk | ||
|
|
||
| ```c++ (but really MIDL3) | ||
| namespace Microsoft.Windows.BadgeNotifications | ||
SatwikKrSharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // Set of predefined glyphs that can be used to represent various statuses or notifications on an application's badge | ||
| enum BadgeNotificationGlyph | ||
| { | ||
| None, // No glyph. A blank tile appears in the badge. | ||
| Activity, // A glyph representing an activity | ||
| Alarm, // A glyph representing an alarm | ||
| Alert, // A glyph representing an alert | ||
| Attention, // A glyph representing attention | ||
| Available, // A glyph representing availability | ||
| Away, // A glyph representing being away | ||
| Busy, // A glyph representing being busy | ||
| Error, // A glyph representing an error | ||
| NewMessage, // A glyph representing a new message | ||
| Paused, // A glyph representing being paused | ||
| Playing, // A glyph representing playing | ||
| Unavailable, // A glyph representing being unavailable | ||
| }; | ||
|
|
||
| // The manager class which encompasses all Badge Notification API Functionality | ||
| runtimeclass BadgeNotificationManager | ||
SatwikKrSharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // Gets a Default instance of a BadgeNotificationManager | ||
| static BadgeNotificationManager Current{ get; }; | ||
|
|
||
| // Updates the badge on the app's icon on taskbar to display a numeric value. | ||
| void SetBadgeAsCount(UInt32 notificationCount); | ||
|
|
||
| // Updates the badge on the app's icon on taskbar to display a numeric value with an expiration time. | ||
| void SetBadgeAsCount(UInt32 notificationCount, Windows.Foundation.DateTime expiration); | ||
|
|
||
| // Updates the badge on the app's icon on taskbar to display a glyph. | ||
| void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue); | ||
|
|
||
| // Updates the badge on the app's icon on taskbar to display a glyph with an expiration time. | ||
| void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue, Windows.Foundation.DateTime expiration); | ||
|
|
||
| // Removes the Badge Notifications for the App from Action Center | ||
| void ClearBadge(); | ||
| } | ||
| } | ||
| ``` | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.