Thinktecture.Blazor.Badging 2.0.0

Suggested Alternatives

PatrickJahr.Blazor.Badging

dotnet add package Thinktecture.Blazor.Badging --version 2.0.0                
NuGet\Install-Package Thinktecture.Blazor.Badging -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Thinktecture.Blazor.Badging" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Thinktecture.Blazor.Badging --version 2.0.0                
#r "nuget: Thinktecture.Blazor.Badging, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Thinktecture.Blazor.Badging as a Cake Addin
#addin nuget:?package=Thinktecture.Blazor.Badging&version=2.0.0

// Install Thinktecture.Blazor.Badging as a Cake Tool
#tool nuget:?package=Thinktecture.Blazor.Badging&version=2.0.0                

Thinktecture.Blazor.Badging

NuGet Downloads (official NuGet)

Introduction

A Blazor wrapper for the Badging API.

The Badging API allows you to display a badge on the installed application’s icon.

Getting started

Prerequisites

You need .NET 7.0 or newer to use this library.

Download .NET 7

Platform support

Platform support for Badging API

Installation

You can install the package via NuGet with the Package Manager in your IDE or alternatively using the command line:

dotnet add package Thinktecture.Blazor.Badging

Usage

The package can be used in Blazor WebAssembly projects.

Add to service collection

To make the BadgingService available on all pages, register it at the IServiceCollection in Program.cs before the host is built:

builder.Services.AddBadgingService();

Checking for browser support

Before using the Badging API, you should first test if the API is supported on the target platform by calling the IsSupportedAsync() method. This method returns a boolean to indicate whether the Badging API is supported or not.

var isSupported = await badgingService.IsSupportedAsync();
if (isSupported)
{
    // enable badging feature
}
else
{
    // use fallback mechanism or hide/disable feature
}

Internally, this method tests for the presence of the setAppBadge() and clearAppBadge() methods on the navigator object of the target browser.

Set app badge

The SetAppBadgeAsync() method sets a badge on the current app's icon. If a value is passed to this method, it will be set as the value of the badge:

await badgingService.SetAppBadgeAsync(3);

When omitting the contents parameter, a generic badge will be shown, as defined by the platform.

await badgingService.SetAppBadgeAsync();

Clear app badge

The ClearAppBadgeAsync() method clears the badge on the current app's icon:

await badgingService.ClearAppBadgeAsync();

Acknowledgements

Thanks to Kristoffer Strube who provides a Blazor wrapper for the File System Access API. This library is inspired by Kristoffer's implementation and project setup.

License and Note

BSD-3-Clause.

This is a technical showcase, not an official Thinktecture product.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 368 2/10/2023 2.0.0 is deprecated because it is no longer maintained.
1.0.0 277 11/30/2022