-
Notifications
You must be signed in to change notification settings - Fork 0
/
badge.go
37 lines (30 loc) · 848 Bytes
/
badge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Package badge allows you to preserve, set or clear the number displayed
// on your App icon.
package badge
import "fmt"
// Badge number to display on the App icon.
type Badge struct {
number uint
isSet bool
}
// Preserve the current badge (default behavior).
var Preserve = Badge{}
// Clear the badge.
var Clear = Badge{number: 0, isSet: true}
// New badge with a set value.
// A badge set to 0 is the same as badge.Clear.
func New(number uint) Badge {
return Badge{number: number, isSet: true}
}
// Number to display on the App Icon and if should be changed.
// If the badge should not be changed, the number has no effect.
func (b *Badge) Number() (uint, bool) {
return b.number, b.isSet
}
// String prints out a badge
func (b Badge) String() string {
if b.isSet {
return fmt.Sprintf("set %d", b.number)
}
return "preserve"
}