Lewati ke konten

Dock & Taskbar

Wails menyediakan service Dock lintas platform untuk aplikasi desktop. Service ini memungkinkan Anda:

  • Hide and show the application icon in the macOS Dock
  • Display badges on your application tile or dock/taskbar icon (macOS and Windows)

Pertama, inisialisasi service dock:

import "github.com/wailsapp/wails/v3/pkg/application"
import "github.com/wailsapp/wails/v3/pkg/services/dock"
// Create a new Dock service
dockService := dock.New()
// Register the service with the application
app := application.New(application.Options{
Services: []application.Service{
application.NewService(dockService),
},
})

Creating the Service with Custom Badge Options (Windows Only)

Section titled “Creating the Service with Custom Badge Options (Windows Only)”

Di Windows, Anda dapat menyesuaikan tampilan badge dengan berbagai opsi:

import "github.com/wailsapp/wails/v3/pkg/application"
import "github.com/wailsapp/wails/v3/pkg/services/dock"
import "image/color"
// Create a dock service with custom badge options
options := dock.BadgeOptions{
TextColour: color.RGBA{255, 255, 255, 255}, // White text
BackgroundColour: color.RGBA{0, 0, 255, 255}, // Blue background
FontName: "consolab.ttf", // Bold Consolas font
FontSize: 20, // Font size for single character
SmallFontSize: 14, // Font size for multiple characters
}
dockService := dock.NewWithOptions(options)
// Register the service with the application
app := application.New(application.Options{
Services: []application.Service{
application.NewService(dockService),
},
})

Sembunyikan ikon aplikasi dari Dock macOS:

// Hide the app icon
dockService.HideAppIcon()

Tampilkan ikon aplikasi di Dock macOS:

// Show the app icon
dockService.ShowAppIcon()

Set badge pada tile aplikasi/ikon dock:

// Set a default badge
dockService.SetBadge("")
// Set a numeric badge
dockService.SetBadge("3")
// Set a text badge
dockService.SetBadge("New")

Set badge dengan opsi sekali pakai:

options := dock.BadgeOptions{
BackgroundColour: color.RGBA{0, 255, 255, 255},
FontName: "arialb.ttf", // System font
FontSize: 16,
SmallFontSize: 10,
TextColour: color.RGBA{0, 0, 0, 255},
}
// Set a default badge
dockService.SetCustomBadge("", options)
// Set a numeric badge
dockService.SetCustomBadge("3", options)
// Set a text badge
dockService.SetCustomBadge("New", options)

Hapus badge dari ikon aplikasi:

dockService.RemoveBadge()
dockService.GetBadge()

On macOS:

  • The dock icon can be hidden and shown
  • Badges are displayed directly on the dock icon
  • Badge options are not customizable (any options passed to NewWithOptions/SetCustomBadge are ignored)
  • The standard macOS dock badge styling is used and automatically adapts to appearance
  • Label overflow is handled by the system
  • Providing an empty label displays a default badge of ”●”
  1. When hiding the dock icon (macOS):

    • Ensure users can still access your app (e.g., via system tray)
    • Include a “Quit” option in your alternative UI
    • The app won’t appear in Command+Tab switcher
    • Open windows remain visible and functional
    • Closing all windows may not quit the app (macOS behavior varies)
    • Users lose the standard way to quit via Dock right-click
  2. Use badges sparingly:

    • Too many badge updates can distract users
    • Reserve badges for important notifications
  3. Keep badge text short:

    • Numeric badges are most effective
    • On macOS, text badges should be brief
  4. For Windows badge customization:

    • Ensure high contrast between text and background colors
    • Test with different text lengths as font size decreases with length
    • Use common system fonts to ensure availability
MethodDescription
New()Creates a new dock service
NewWithOptions(options BadgeOptions)Creates a new dock service with custom badge options (Windows only; options are ignored on macOS and Linux)
MethodDescription
HideAppIcon()Hides the app icon from the macOS Dock (macOS only)
ShowAppIcon()Shows the app icon in the macOS Dock (macOS only)
MethodDescription
SetBadge(label string) errorSets a badge with the specified label
SetCustomBadge(label string, options BadgeOptions) errorSets a badge with the specified label and custom styling options (Windows only)
RemoveBadge() errorRemoves the badge from the application icon
GetBadge() *stringGets the current badge
// Options for customizing badge appearance (Windows only)
type BadgeOptions struct {
TextColour color.RGBA // Color of the badge text
BackgroundColour color.RGBA // Color of the badge background
FontName string // Font file name (e.g., "segoeuib.ttf")
FontSize int // Font size for single character
SmallFontSize int // Font size for multiple characters
}