|
| 1 | +--- |
| 2 | +title: Badges |
| 3 | +--- |
| 4 | + |
| 5 | +import { Tabs, TabItem } from "@astrojs/starlight/components"; |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +Wails provides a cross-platform badge service for desktop applications. This service allows you to display badges on your application tile or dock icon, which is useful for indicating unread messages, notifications, or other status information. |
| 10 | + |
| 11 | +## Basic Usage |
| 12 | + |
| 13 | +### Creating the Service |
| 14 | + |
| 15 | +First, initialize the badge service: |
| 16 | + |
| 17 | +```go |
| 18 | +import "github.com/wailsapp/wails/v3/pkg/application" |
| 19 | +import "github.com/wailsapp/wails/v3/services/badge" |
| 20 | + |
| 21 | +// Create a new badge service |
| 22 | +badgeService := badge.New() |
| 23 | + |
| 24 | +// Register the service with the application |
| 25 | +app := application.New(application.Options{ |
| 26 | + Services: []application.Service{ |
| 27 | + application.NewService(badgeService), |
| 28 | + }, |
| 29 | +}) |
| 30 | +``` |
| 31 | + |
| 32 | +## Badge Operations |
| 33 | + |
| 34 | +### Setting a Badge |
| 35 | + |
| 36 | +Set a badge on the application tile/dock icon: |
| 37 | + |
| 38 | +```go |
| 39 | +// Set a numeric badge |
| 40 | +badgeService.SetBadge("3") |
| 41 | + |
| 42 | +// Set a text badge |
| 43 | +badgeService.SetBadge("New") |
| 44 | + |
| 45 | +// Set a symbol badge |
| 46 | +badgeService.SetBadge("●") |
| 47 | +``` |
| 48 | + |
| 49 | +### Removing a Badge |
| 50 | + |
| 51 | +Remove the badge from the application icon: |
| 52 | + |
| 53 | +```go |
| 54 | +badgeService.RemoveBadge() |
| 55 | + |
| 56 | +// or |
| 57 | + |
| 58 | +// Set an empty string |
| 59 | +badgeService.SetBadge("") |
| 60 | +``` |
| 61 | + |
| 62 | +## Platform Considerations |
| 63 | + |
| 64 | +<Tabs> |
| 65 | + <TabItem label="macOS" icon="fa-brands:apple"> |
| 66 | + |
| 67 | + On macOS, badges: |
| 68 | + |
| 69 | + - Are displayed directly on the dock icon |
| 70 | + - Support both text and numeric values |
| 71 | + - Automatically handle dark/light mode appearance |
| 72 | + - Use the standard macOS dock badge styling |
| 73 | + |
| 74 | + </TabItem> |
| 75 | + |
| 76 | + <TabItem label="Windows" icon="fa-brands:windows"> |
| 77 | + |
| 78 | + On Windows, badges: |
| 79 | + |
| 80 | + - Are displayed as an overlay icon in the taskbar |
| 81 | + - Currently implemented as a red circle with a white center |
| 82 | + - Do not currently support displaying text or numbers |
| 83 | + - Adapt to Windows theme settings |
| 84 | + - Require the application to have a window |
| 85 | + |
| 86 | + </TabItem> |
| 87 | + |
| 88 | + <TabItem label="Linux" icon="fa-brands:linux"> |
| 89 | + |
| 90 | + On Linux: |
| 91 | + |
| 92 | + - Badge functionality is not available |
| 93 | + |
| 94 | + </TabItem> |
| 95 | +</Tabs> |
| 96 | + |
| 97 | +## Best Practices |
| 98 | + |
| 99 | +1. Use badges sparingly: |
| 100 | + - Too many badge updates can distract users |
| 101 | + - Reserve badges for important notifications |
| 102 | + |
| 103 | +2. Keep badge text short: |
| 104 | + - Numeric badges are most effective |
| 105 | + - On macOS, text badges should be brief |
| 106 | + |
| 107 | +## API Reference |
| 108 | + |
| 109 | +### Service Management |
| 110 | +| Method | Description | |
| 111 | +|--------------------------------------------|-------------------------------------------------------| |
| 112 | +| `New()` | Creates a new badge service | |
| 113 | + |
| 114 | +### Badge Operations |
| 115 | +| Method | Description | |
| 116 | +|----------------------------------------------|------------------------------------------------------------| |
| 117 | +| `SetBadge(label string) error` | Sets a badge with the specified label | |
| 118 | +| `RemoveBadge() error` | Removes the badge from the application icon | |
| 119 | + |
| 120 | +### Structs and Types |
| 121 | + |
| 122 | +This service doesn't define any specific structs or types beyond the standard error return types. |
0 commit comments