Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3] App icon badge #4040

Open
popaprozac opened this issue Jan 30, 2025 · 1 comment
Open

[V3] App icon badge #4040

popaprozac opened this issue Jan 30, 2025 · 1 comment
Labels
Enhancement New feature or request

Comments

@popaprozac
Copy link

Is your feature request related to a problem? Please describe.

Tauri and Electron allow setting a badge on the app icon.

Tauri
https://tauri.app/reference/javascript/api/namespacewindow/#setbadgecount
https://tauri.app/reference/javascript/api/namespacewindow/#setbadgelabel

Electron
https://www.electronjs.org/docs/latest/api/dock#docksetbadgetext-macos

Describe the solution you'd like

Expose an app.SetBadge(value string) method or similar to set an app badge on the dock icon.

Describe alternatives you've considered

Import and use DarwinKit

Example of my current usage (badgeservice_darwin.go):

package main

import "github.com/progrium/darwinkit/macos/appkit"

type BadgeService struct{}

func (g *BadgeService) SetBadge(value string) {
	app := appkit.Application_SharedApplication()
	dockTile := app.DockTile()

	if value == "" {
		dockTile.SetBadgeLabel("")
	} else {
		dockTile.SetBadgeLabel(value)
	}
}

Additional context

I am currently focused on macOS development so I haven't looked at Windows/Linux solutions yet (researching).
Relying on DarwinKit for this increases the app size to >35MB build and >25MB app.

@popaprozac popaprozac added the Enhancement New feature or request label Jan 30, 2025
@popaprozac
Copy link
Author

Playing around on macOS this seems to work
application_darwin.go

// Set the application dock tile badge label
static void setBadgeLabel(const char *label) {
    NSString *nsLabel = nil;
	if (label != NULL) {
		nsLabel = [NSString stringWithUTF8String:label];
	}
	[[NSApp dockTile] setBadgeLabel:nsLabel];
	[[NSApp dockTile] display];
}
...
...
...
func (m *macosApp) setBadge(label string) {
	var cLabel *C.char
	if label != "" {
		cLabel = C.CString(label)
		defer C.free(unsafe.Pointer(cLabel))
	}
	C.setBadgeLabel(cLabel)
}

application.go

func (a *App) SetBadge(label string) {
	if a.impl != nil {
		if macApp, ok := a.impl.(*macosApp); ok {
			macApp.setBadge(label)
		}
	}
}

I will try to look at Windows and if it seems valuable I can open a PR.

@popaprozac popaprozac changed the title App icon badge [V3] App icon badge Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant