forked from fyne-io/fyne
/
app_darwin.m
55 lines (41 loc) · 1.78 KB
/
app_darwin.m
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// +build !ci
// +build !ios
extern void themeChanged();
#import <Foundation/Foundation.h>
@interface FyneUserNotificationCenterDelegate : NSObject<NSUserNotificationCenterDelegate>
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
shouldPresentNotification:(NSUserNotification*)notification;
@end
@implementation FyneUserNotificationCenterDelegate
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
shouldPresentNotification:(NSUserNotification*)notification
{
return YES;
}
@end
void sendNSUserNotification(const char *, const char *);
bool isBundled() {
return [[NSBundle mainBundle] bundleIdentifier] != nil;
}
bool isDarkMode() {
NSString *style = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
return [@"Dark" isEqualToString:style];
}
void sendNotification(const char *title, const char *body) {
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
if (center.delegate == nil) {
center.delegate = [[FyneUserNotificationCenterDelegate new] autorelease];
}
NSString *uuid = [[NSUUID UUID] UUIDString];
NSUserNotification *notification = [[NSUserNotification new] autorelease];
notification.title = [NSString stringWithUTF8String:title];
notification.informativeText = [NSString stringWithUTF8String:body];
notification.identifier = [NSString stringWithFormat:@"%@-fyne-notify-%@", [[NSBundle mainBundle] bundleIdentifier], uuid];
[center scheduleNotification:notification];
}
void watchTheme() {
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"AppleInterfaceThemeChangedNotification" object:nil queue:nil
usingBlock:^(NSNotification *note) {
themeChanged(); // calls back into Go
}];
}