Skip to content

Commit

Permalink
Merge pull request unoplatform#325 from unoplatform/dev/spouliot/maco…
Browse files Browse the repository at this point in the history
…s-skia-badge

feat(macos/skia): add badge support
  • Loading branch information
spouliot authored Feb 21, 2024
2 parents fd55996 + 28b7210 commit b37b744
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/MacOSBadgeUpdaterExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Globalization;
using Uno.Foundation.Extensibility;
using Uno.UI.Notifications;

namespace Uno.UI.Runtime.Skia.MacOS;

internal class MacOSBadgeUpdaterExtension : IBadgeUpdaterExtension
{
private static readonly MacOSBadgeUpdaterExtension _instance = new();

private MacOSBadgeUpdaterExtension()
{
}

public static void Register() => ApiExtensibility.Register(typeof(IBadgeUpdaterExtension), _ => _instance);

public void SetBadge(int? value)
{
var s = string.Empty;
if (value is not null)
{
s = value.Value.ToString(CultureInfo.CurrentUICulture.NumberFormat);
}
// NativeUno.uno_application_set_badge(s);
}
}
1 change: 1 addition & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/MacSkiaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static MacSkiaHost()

MacOSAnalyticsInfoExtension.Register();
MacOSApplicationViewExtension.Register();
MacOSBadgeUpdaterExtension.Register();
MacOSClipboardExtension.Register(); // work in progress
MacOSCoreApplicationExtension.Register();
MacOSDisplayInformationExtension.Register();
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.UI.Runtime.Skia.MacOS/NativeUno.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ internal static partial class NativeUno
[LibraryImport("libUnoNativeMac.dylib")]
internal static partial nint uno_app_get_main_window();

[LibraryImport("libUnoNativeMac.dylib", StringMarshalling = StringMarshalling.Utf8)]
internal static partial void uno_application_set_badge(string badge);

[LibraryImport("libUnoNativeMac.dylib", StringMarshalling = StringMarshalling.Utf8)]
internal static partial void uno_application_set_icon(string iconPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bool uno_app_initialize(bool *supportsMetal);
NSWindow* uno_app_get_main_window(void);

id<MTLDevice> uno_application_get_metal_device(void);
void uno_application_set_badge(const char *badge);
void uno_application_set_icon(const char *path);
bool uno_application_open_url(const char *url);
bool uno_application_query_url_support(const char *url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ bool uno_app_initialize(bool *metal)
return device;
}

void uno_application_set_badge(const char *badge)
{
NSApplication *app = [NSApplication sharedApplication];
NSDockTile *dockTile = [app dockTile];
[dockTile setBadgeLabel:[NSString stringWithUTF8String:badge]];
}

void uno_application_set_icon(const char *path)
{
NSApplication *app = [NSApplication sharedApplication];
Expand Down

0 comments on commit b37b744

Please sign in to comment.