wails/v3/pkg/services/dock/dock.go
Zach Botterman ff6a333621
[v3] macOS Dock Service (#4451)
* dock service

* add docs and update comments

* remove unneeded doc imports

* update comment

* update comment

* update comment

* update changelog

* consolidate to dock service

* update examples + thread safety

* fix linux

* update docs

* thread safety

* Update v3/pkg/services/dock/dock_darwin.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-09-24 07:30:02 +00:00

77 lines
1.9 KiB
Go

package dock
import (
"context"
"image/color"
"github.com/wailsapp/wails/v3/pkg/application"
)
type platformDock interface {
// Lifecycle methods
Startup(ctx context.Context, options application.ServiceOptions) error
Shutdown() error
// Dock icon visibility methods
HideAppIcon()
ShowAppIcon()
// Badge methods
SetBadge(label string) error
SetCustomBadge(label string, options BadgeOptions) error
RemoveBadge() error
}
// Service represents the dock service
type DockService struct {
impl platformDock
}
// BadgeOptions represents options for customizing badge appearance
type BadgeOptions struct {
TextColour color.RGBA
BackgroundColour color.RGBA
FontName string
FontSize int
SmallFontSize int
}
// ServiceName returns the name of the service.
func (d *DockService) ServiceName() string {
return "github.com/wailsapp/wails/v3/pkg/services/dock"
}
// ServiceStartup is called when the service is loaded.
func (d *DockService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
return d.impl.Startup(ctx, options)
}
// ServiceShutdown is called when the service is unloaded.
func (d *DockService) ServiceShutdown() error {
return d.impl.Shutdown()
}
// HideAppIcon hides the app icon in the dock/taskbar.
func (d *DockService) HideAppIcon() {
d.impl.HideAppIcon()
}
// ShowAppIcon shows the app icon in the dock/taskbar.
func (d *DockService) ShowAppIcon() {
d.impl.ShowAppIcon()
}
// SetBadge sets the badge label on the application icon.
func (d *DockService) SetBadge(label string) error {
return d.impl.SetBadge(label)
}
// SetCustomBadge sets the badge label on the application icon with custom options.
func (d *DockService) SetCustomBadge(label string, options BadgeOptions) error {
return d.impl.SetCustomBadge(label, options)
}
// RemoveBadge removes the badge label from the application icon.
func (d *DockService) RemoveBadge() error {
return d.impl.RemoveBadge()
}