@native-sdk/cli 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +331 -24
- package/build.zig +179 -11
- package/native-sdk.d.ts +8 -0
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +70 -1
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
- package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
- package/packages/core/scripts/stage_external_services.mjs +1 -1
- package/packages/core/sdk/core.d.ts +75 -0
- package/packages/core/sdk/core.ts +167 -12
- package/packages/core/sdk/events.d.ts +53 -0
- package/packages/core/sdk/events.ts +78 -7
- package/packages/core/src/checker.ts +470 -2
- package/packages/core/src/cli.ts +13 -0
- package/packages/core/src/contract.ts +3 -1
- package/packages/core/src/devhost.ts +30 -1
- package/packages/core/src/devhost_journal.mjs +10 -8
- package/packages/core/src/diagnostics.ts +99 -8
- package/packages/core/src/frontend.ts +6 -0
- package/packages/core/src/infer.ts +24 -0
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/native-ui/SKILL.md +11 -5
- package/skill-data/ts-core/SKILL.md +53 -20
- package/skill-data/ts-services/SKILL.md +4 -4
- package/skill-data/ts-services/references/service-surface.md +2 -1
- package/skill-data/zig/SKILL.md +1 -1
- package/src/app_runner/root.zig +29 -0
- package/src/app_runner/ts_core_main.zig +5 -0
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +1 -0
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +28 -0
- package/src/embed/ui_host.zig +68 -2
- package/src/platform/linux/cef_host.cpp +7 -1
- package/src/platform/linux/gtk_host.c +200 -5
- package/src/platform/linux/gtk_host.h +2 -1
- package/src/platform/linux/root.zig +69 -4
- package/src/platform/macos/appkit_host.h +11 -7
- package/src/platform/macos/appkit_host.m +210 -88
- package/src/platform/macos/cef_host.mm +210 -88
- package/src/platform/macos/root.zig +77 -30
- package/src/platform/null_platform.zig +234 -51
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +10 -0
- package/src/platform/types.zig +105 -16
- package/src/platform/windows/root.zig +20 -6
- package/src/platform/windows/webview2_host.cpp +41 -5
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +8 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/core.zig +12 -6
- package/src/runtime/effects.zig +1323 -35
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +21 -9
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +5 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +56 -5
- package/src/runtime/session_record.zig +38 -0
- package/src/runtime/session_replay.zig +97 -7
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/state.zig +10 -0
- package/src/runtime/system_services.zig +129 -36
- package/src/runtime/ts_core_host.zig +281 -11
- package/src/runtime/ts_core_host_tests.zig +95 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +321 -109
- package/src/runtime/ui_app_tests.zig +132 -6
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +20 -0
- package/src/tooling/templates.zig +28 -0
- package/src/tooling/ts_core.zig +83 -0
- package/tools/corewire/emit.zig +3 -3
- package/tools/corewire/emit_facade.zig +65 -5
- package/tools/corewire/emit_profile.zig +2 -2
- package/tools/corewire/emit_service.zig +2 -2
- package/tools/corewire/service_contract.zig +4 -4
- package/tools/corewire/sidecar.zig +4 -4
|
@@ -469,7 +469,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
469
469
|
"});"
|
|
470
470
|
"var os=Object.freeze({"
|
|
471
471
|
"openUrl:function(value){var options=typeof value==='string'?{url:value}:(value||{});return invoke('native-sdk.os.openUrl',{url:ensureString(options.url,'url')});},"
|
|
472
|
-
"showNotification:function(value){var options=typeof value==='string'?{title:value}:(value||{});var payload={title:ensureString(options.title,'title')};if(options.subtitle!=null){payload.subtitle=ensureString(options.subtitle,'subtitle');}if(options.body!=null){payload.body=ensureString(options.body,'body');}return invoke('native-sdk.os.showNotification',payload);},"
|
|
472
|
+
"showNotification:function(value){var options=typeof value==='string'?{title:value}:(value||{});var payload={title:ensureString(options.title,'title')};if(options.id!=null){payload.id=ensureString(options.id,'id');}if(options.subtitle!=null){payload.subtitle=ensureString(options.subtitle,'subtitle');}if(options.body!=null){payload.body=ensureString(options.body,'body');}if(options.actionLabel!=null){payload.actionLabel=ensureString(options.actionLabel,'actionLabel');}if(options.actionCommand!=null){payload.actionCommand=ensureString(options.actionCommand,'actionCommand');}return invoke('native-sdk.os.showNotification',payload);},"
|
|
473
473
|
"revealPath:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.revealPath',{path:ensureString(options.path,'path')});},"
|
|
474
474
|
"addRecentDocument:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.addRecentDocument',{path:ensureString(options.path,'path')});},"
|
|
475
475
|
"clearRecentDocuments:function(){return invoke('native-sdk.os.clearRecentDocuments',{});}"
|
|
@@ -552,6 +552,21 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
552
552
|
@property(nonatomic, assign) uint32_t modifiers;
|
|
553
553
|
@end
|
|
554
554
|
|
|
555
|
+
@interface NativeSdkChromiumStatusItemEntry : NSObject
|
|
556
|
+
@property(nonatomic, assign) uint32_t identifier;
|
|
557
|
+
@property(nonatomic, strong) NSStatusItem *item;
|
|
558
|
+
@property(nonatomic, strong) NSImage *baseImage;
|
|
559
|
+
@property(nonatomic, strong) NSMenu *menu;
|
|
560
|
+
@property(nonatomic, strong) NSString *presentationTitle;
|
|
561
|
+
@property(nonatomic, assign) double presentationWidth;
|
|
562
|
+
@property(nonatomic, assign) int presentationTone;
|
|
563
|
+
@property(nonatomic, assign) double presentationIconOpacity;
|
|
564
|
+
@property(nonatomic, assign) BOOL presentationMonospaced;
|
|
565
|
+
@property(nonatomic, strong) NSString *activationCommand;
|
|
566
|
+
@property(nonatomic, strong) NSString *alternateActivationCommand;
|
|
567
|
+
@property(nonatomic, strong) NSString *openCommand;
|
|
568
|
+
@end
|
|
569
|
+
|
|
555
570
|
/* Captures the selected item id of a context-menu popUp (NSMenuItem
|
|
556
571
|
* targets are weak; the presenter block keeps this alive). */
|
|
557
572
|
@interface NativeSdkChromiumContextMenuTarget : NSObject
|
|
@@ -568,7 +583,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
568
583
|
|
|
569
584
|
@end
|
|
570
585
|
|
|
571
|
-
@interface NativeSdkChromiumHost : NSObject <NSMenuDelegate>
|
|
586
|
+
@interface NativeSdkChromiumHost : NSObject <NSMenuDelegate, NSUserNotificationCenterDelegate>
|
|
572
587
|
@property(nonatomic, strong) NSWindow *window;
|
|
573
588
|
@property(nonatomic, strong) NSView *browserContainer;
|
|
574
589
|
@property(nonatomic, strong) NativeSdkChromiumWindowDelegate *delegate;
|
|
@@ -596,6 +611,10 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
596
611
|
@property(nonatomic, assign) uint64_t nextWebViewGeneration;
|
|
597
612
|
@property(nonatomic, strong) NSTimer *timer;
|
|
598
613
|
@property(nonatomic, strong) NSMutableDictionary<NSNumber *, NSTimer *> *appTimers;
|
|
614
|
+
/* Delivered notifications outlive this object, so userInfo carries only
|
|
615
|
+
* a per-process token; the command remains in these live-host maps. */
|
|
616
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *notificationActionCommands;
|
|
617
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *notificationActionTokensByIdentifier;
|
|
599
618
|
@property(nonatomic, strong) NSString *appName;
|
|
600
619
|
/* The human-facing app name (app.zon display_name, empty = appName):
|
|
601
620
|
* drives the application menu title and its About/Hide/Quit labels, the
|
|
@@ -618,16 +637,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
618
637
|
@property(nonatomic, assign) BOOL observesApplicationActivation;
|
|
619
638
|
@property(nonatomic, strong) id shortcutEventMonitor;
|
|
620
639
|
@property(nonatomic, strong) NSArray<NativeSdkChromiumShortcut *> *shortcuts;
|
|
621
|
-
@property(nonatomic, strong)
|
|
622
|
-
@property(nonatomic, strong) NSImage *statusItemBaseImage;
|
|
623
|
-
@property(nonatomic, strong) NSMenu *statusMenu;
|
|
624
|
-
@property(nonatomic, assign) double statusPresentationWidth;
|
|
625
|
-
@property(nonatomic, assign) int statusPresentationTone;
|
|
626
|
-
@property(nonatomic, assign) double statusPresentationIconOpacity;
|
|
627
|
-
@property(nonatomic, assign) BOOL statusPresentationMonospaced;
|
|
628
|
-
@property(nonatomic, strong) NSString *statusActivationCommand;
|
|
629
|
-
@property(nonatomic, strong) NSString *statusAlternateActivationCommand;
|
|
630
|
-
@property(nonatomic, strong) NSString *statusOpenCommand;
|
|
640
|
+
@property(nonatomic, strong) NSMutableDictionary<NSNumber *, NativeSdkChromiumStatusItemEntry *> *statusItems;
|
|
631
641
|
@property(nonatomic, assign) native_sdk_appkit_tray_callback_t trayCallback;
|
|
632
642
|
@property(nonatomic, assign) void *trayContext;
|
|
633
643
|
@property(nonatomic) CefRefPtr<NativeSdkCefClient> cefClient;
|
|
@@ -663,6 +673,8 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
663
673
|
- (void)stopApplicationActivationObservers;
|
|
664
674
|
- (void)applicationDidBecomeActive:(NSNotification *)notification;
|
|
665
675
|
- (void)applicationDidResignActive:(NSNotification *)notification;
|
|
676
|
+
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification;
|
|
677
|
+
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification;
|
|
666
678
|
- (void)emitResize;
|
|
667
679
|
- (void)emitResizeForWindowId:(uint64_t)windowId;
|
|
668
680
|
- (void)emitWindowFrameForWindowId:(uint64_t)windowId open:(BOOL)open;
|
|
@@ -703,13 +715,18 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
703
715
|
- (void)emitShortcutWithId:(NSString *)identifier key:(NSString *)key modifiers:(uint32_t)modifiers event:(NSEvent *)event;
|
|
704
716
|
- (void)trayMenuItemClicked:(NSMenuItem *)menuItem;
|
|
705
717
|
- (void)menuWillOpen:(NSMenu *)menu;
|
|
706
|
-
- (
|
|
718
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForId:(uint32_t)identifier;
|
|
719
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForMenu:(NSMenu *)menu;
|
|
720
|
+
- (void)emitStatusCommand:(NSString *)command statusItemId:(uint32_t)statusItemId;
|
|
707
721
|
- (void)statusItemActivated:(id)sender;
|
|
708
722
|
@end
|
|
709
723
|
|
|
710
724
|
@implementation NativeSdkChromiumShortcut
|
|
711
725
|
@end
|
|
712
726
|
|
|
727
|
+
@implementation NativeSdkChromiumStatusItemEntry
|
|
728
|
+
@end
|
|
729
|
+
|
|
713
730
|
@implementation NativeSdkChromiumWindowDelegate
|
|
714
731
|
|
|
715
732
|
- (void)windowDidResize:(NSNotification *)notification {
|
|
@@ -866,6 +883,9 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
866
883
|
self.webviewGenerations = [[NSMutableDictionary alloc] init];
|
|
867
884
|
self.closingWebViewKeys = [[NSMutableSet alloc] init];
|
|
868
885
|
self.appTimers = [[NSMutableDictionary alloc] init];
|
|
886
|
+
self.notificationActionCommands = [[NSMutableDictionary alloc] init];
|
|
887
|
+
self.notificationActionTokensByIdentifier = [[NSMutableDictionary alloc] init];
|
|
888
|
+
self.statusItems = [[NSMutableDictionary alloc] init];
|
|
869
889
|
self.nextWebViewGeneration = 1;
|
|
870
890
|
self.cefClients = new std::map<uint64_t, CefRefPtr<NativeSdkCefClient>>();
|
|
871
891
|
self.browsers = new std::map<uint64_t, CefRefPtr<CefBrowser>>();
|
|
@@ -981,6 +1001,8 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
981
1001
|
}
|
|
982
1002
|
|
|
983
1003
|
- (void)dealloc {
|
|
1004
|
+
NSUserNotificationCenter *notificationCenter = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
1005
|
+
if (notificationCenter.delegate == self) notificationCenter.delegate = nil;
|
|
984
1006
|
if (self.shortcutEventMonitor) {
|
|
985
1007
|
[NSEvent removeMonitor:self.shortcutEventMonitor];
|
|
986
1008
|
self.shortcutEventMonitor = nil;
|
|
@@ -1349,6 +1371,38 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1349
1371
|
[self emitEvent:(native_sdk_appkit_event_t){ .kind = NATIVE_SDK_APPKIT_EVENT_APP_DEACTIVATED }];
|
|
1350
1372
|
}
|
|
1351
1373
|
|
|
1374
|
+
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
|
|
1375
|
+
(void)center;
|
|
1376
|
+
(void)notification;
|
|
1377
|
+
return YES;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
|
|
1381
|
+
NSInteger activation = notification.activationType;
|
|
1382
|
+
if (activation != NSUserNotificationActivationTypeActionButtonClicked) return;
|
|
1383
|
+
NSString *token = [notification.userInfo[@"native-sdk-action-token"] isKindOfClass:[NSString class]]
|
|
1384
|
+
? notification.userInfo[@"native-sdk-action-token"] : @"";
|
|
1385
|
+
NSString *command = token.length > 0 ? self.notificationActionCommands[token] : @"";
|
|
1386
|
+
if (command.length == 0) {
|
|
1387
|
+
[center removeDeliveredNotification:notification];
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
NSString *identifier = notification.identifier ?: @"";
|
|
1391
|
+
if (identifier.length > 0 &&
|
|
1392
|
+
[self.notificationActionTokensByIdentifier[identifier] isEqualToString:token]) {
|
|
1393
|
+
[self.notificationActionTokensByIdentifier removeObjectForKey:identifier];
|
|
1394
|
+
}
|
|
1395
|
+
[self.notificationActionCommands removeObjectForKey:token];
|
|
1396
|
+
const char *commandBytes = command.UTF8String ?: "";
|
|
1397
|
+
[self emitEvent:(native_sdk_appkit_event_t){
|
|
1398
|
+
.kind = NATIVE_SDK_APPKIT_EVENT_NOTIFICATION_COMMAND,
|
|
1399
|
+
.window_id = 1,
|
|
1400
|
+
.command_name = commandBytes,
|
|
1401
|
+
.command_name_len = [command lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
1402
|
+
}];
|
|
1403
|
+
[center removeDeliveredNotification:notification];
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1352
1406
|
- (void)emitResize {
|
|
1353
1407
|
[self emitResizeForWindowId:1];
|
|
1354
1408
|
}
|
|
@@ -1989,33 +2043,51 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1989
2043
|
}
|
|
1990
2044
|
|
|
1991
2045
|
- (void)trayMenuItemClicked:(NSMenuItem *)menuItem {
|
|
1992
|
-
if (self.trayCallback)
|
|
2046
|
+
if (self.trayCallback) {
|
|
2047
|
+
uint64_t packed = (uint64_t)(NSUInteger)menuItem.tag;
|
|
2048
|
+
self.trayCallback(self.trayContext, (uint32_t)(packed >> 32), (uint32_t)packed);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForId:(uint32_t)identifier {
|
|
2053
|
+
return self.statusItems[@(identifier)];
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForMenu:(NSMenu *)menu {
|
|
2057
|
+
for (NativeSdkChromiumStatusItemEntry *entry in self.statusItems.allValues) {
|
|
2058
|
+
if (entry.menu == menu) return entry;
|
|
2059
|
+
}
|
|
2060
|
+
return nil;
|
|
1993
2061
|
}
|
|
1994
2062
|
|
|
1995
|
-
- (void)emitStatusCommand:(NSString *)command {
|
|
2063
|
+
- (void)emitStatusCommand:(NSString *)command statusItemId:(uint32_t)statusItemId {
|
|
1996
2064
|
if (command.length == 0) return;
|
|
1997
2065
|
const char *bytes = command.UTF8String;
|
|
1998
2066
|
[self emitEvent:(native_sdk_appkit_event_t){
|
|
1999
2067
|
.kind = NATIVE_SDK_APPKIT_EVENT_TRAY_COMMAND,
|
|
2000
2068
|
.window_id = 1,
|
|
2069
|
+
.status_item_id = statusItemId,
|
|
2001
2070
|
.command_name = bytes,
|
|
2002
2071
|
.command_name_len = [command lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
2003
2072
|
}];
|
|
2004
2073
|
}
|
|
2005
2074
|
|
|
2006
2075
|
- (void)menuWillOpen:(NSMenu *)menu {
|
|
2007
|
-
|
|
2008
|
-
|
|
2076
|
+
NativeSdkChromiumStatusItemEntry *entry = [self statusEntryForMenu:menu];
|
|
2077
|
+
if (!entry) return;
|
|
2078
|
+
[self emitStatusCommand:entry.openCommand statusItemId:entry.identifier];
|
|
2009
2079
|
}
|
|
2010
2080
|
|
|
2011
2081
|
- (void)statusItemActivated:(id)sender {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2082
|
+
NSStatusBarButton *button = [sender isKindOfClass:[NSStatusBarButton class]] ? sender : nil;
|
|
2083
|
+
NativeSdkChromiumStatusItemEntry *entry = button ? [self statusEntryForId:(uint32_t)button.tag] : nil;
|
|
2084
|
+
if (!entry) return;
|
|
2085
|
+
if ((NSEvent.modifierFlags & NSEventModifierFlagOption) != 0 && entry.alternateActivationCommand.length > 0) {
|
|
2086
|
+
[self emitStatusCommand:entry.alternateActivationCommand statusItemId:entry.identifier];
|
|
2015
2087
|
return;
|
|
2016
2088
|
}
|
|
2017
|
-
[self emitStatusCommand:
|
|
2018
|
-
if (
|
|
2089
|
+
[self emitStatusCommand:entry.activationCommand statusItemId:entry.identifier];
|
|
2090
|
+
if (entry.menu) [entry.item popUpStatusItemMenu:entry.menu];
|
|
2019
2091
|
}
|
|
2020
2092
|
|
|
2021
2093
|
@end
|
|
@@ -3163,17 +3235,42 @@ int native_sdk_appkit_clipboard_write_data(native_sdk_appkit_host_t *host, const
|
|
|
3163
3235
|
return [pasteboard setData:data forType:type] ? 1 : 0;
|
|
3164
3236
|
}
|
|
3165
3237
|
|
|
3166
|
-
int native_sdk_appkit_show_notification(native_sdk_appkit_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len) {
|
|
3167
|
-
(
|
|
3238
|
+
int native_sdk_appkit_show_notification(native_sdk_appkit_host_t *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len, const char *notification_id, size_t notification_id_len, const char *action_label, size_t action_label_len, const char *action_command, size_t action_command_len) {
|
|
3239
|
+
if (!host || ((action_label_len == 0) != (action_command_len == 0))) return 0;
|
|
3240
|
+
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3168
3241
|
NSString *titleString = title ? [[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] : @"";
|
|
3169
3242
|
if (titleString.length == 0) return 0;
|
|
3170
3243
|
NSString *subtitleString = subtitle ? [[NSString alloc] initWithBytes:subtitle length:subtitle_len encoding:NSUTF8StringEncoding] : @"";
|
|
3171
3244
|
NSString *bodyString = body ? [[NSString alloc] initWithBytes:body length:body_len encoding:NSUTF8StringEncoding] : @"";
|
|
3245
|
+
NSString *identifier = notification_id ? [[NSString alloc] initWithBytes:notification_id length:notification_id_len encoding:NSUTF8StringEncoding] : @"";
|
|
3246
|
+
NSString *actionLabel = action_label ? [[NSString alloc] initWithBytes:action_label length:action_label_len encoding:NSUTF8StringEncoding] : @"";
|
|
3247
|
+
NSString *actionCommand = action_command ? [[NSString alloc] initWithBytes:action_command length:action_command_len encoding:NSUTF8StringEncoding] : @"";
|
|
3248
|
+
if (identifier.length > 0) {
|
|
3249
|
+
NSString *oldToken = object.notificationActionTokensByIdentifier[identifier];
|
|
3250
|
+
if (oldToken.length > 0) [object.notificationActionCommands removeObjectForKey:oldToken];
|
|
3251
|
+
[object.notificationActionTokensByIdentifier removeObjectForKey:identifier];
|
|
3252
|
+
}
|
|
3172
3253
|
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
|
3173
3254
|
notification.title = titleString;
|
|
3174
3255
|
if (subtitleString.length > 0) notification.subtitle = subtitleString;
|
|
3175
3256
|
if (bodyString.length > 0) notification.informativeText = bodyString;
|
|
3176
|
-
|
|
3257
|
+
if (identifier.length > 0) notification.identifier = identifier;
|
|
3258
|
+
if (actionCommand.length > 0) {
|
|
3259
|
+
NSString *actionToken = [NSUUID UUID].UUIDString;
|
|
3260
|
+
object.notificationActionCommands[actionToken] = actionCommand;
|
|
3261
|
+
if (identifier.length > 0) object.notificationActionTokensByIdentifier[identifier] = actionToken;
|
|
3262
|
+
notification.hasActionButton = YES;
|
|
3263
|
+
notification.actionButtonTitle = actionLabel;
|
|
3264
|
+
notification.userInfo = @{ @"native-sdk-action-token": actionToken };
|
|
3265
|
+
}
|
|
3266
|
+
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
3267
|
+
center.delegate = object;
|
|
3268
|
+
if (identifier.length > 0) {
|
|
3269
|
+
for (NSUserNotification *delivered in center.deliveredNotifications) {
|
|
3270
|
+
if ([delivered.identifier isEqualToString:identifier]) [center removeDeliveredNotification:delivered];
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
[center deliverNotification:notification];
|
|
3177
3274
|
return 1;
|
|
3178
3275
|
}
|
|
3179
3276
|
|
|
@@ -3409,63 +3506,84 @@ static NSImage *NativeSdkCefTrayImageWithOpacity(NSImage *source, double opacity
|
|
|
3409
3506
|
return image;
|
|
3410
3507
|
}
|
|
3411
3508
|
|
|
3412
|
-
static void NativeSdkCefApplyTrayPresentation(NativeSdkChromiumHost *object, NSString *requestedTitle, double width, int tone, double iconOpacity, BOOL monospaced) {
|
|
3413
|
-
if (!
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3509
|
+
static void NativeSdkCefApplyTrayPresentation(NativeSdkChromiumHost *object, NativeSdkChromiumStatusItemEntry *entry, NSString *requestedTitle, double width, int tone, double iconOpacity, BOOL monospaced) {
|
|
3510
|
+
if (!entry.item) return;
|
|
3511
|
+
entry.presentationTitle = requestedTitle ?: @"";
|
|
3512
|
+
entry.presentationWidth = width;
|
|
3513
|
+
entry.presentationTone = tone;
|
|
3514
|
+
entry.presentationIconOpacity = iconOpacity;
|
|
3515
|
+
entry.presentationMonospaced = monospaced;
|
|
3418
3516
|
NSString *title = requestedTitle ?: @"";
|
|
3419
|
-
if (!
|
|
3517
|
+
if (!entry.baseImage && title.length == 0) title = object.appName.length > 0 ? [object.appName substringToIndex:MIN(1, object.appName.length)] : @"Z";
|
|
3420
3518
|
NSFont *font = monospaced ? [NSFont monospacedDigitSystemFontOfSize:11 weight:NSFontWeightRegular] : [NSFont systemFontOfSize:11];
|
|
3421
3519
|
if (tone == 0) {
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3520
|
+
entry.item.button.title = title;
|
|
3521
|
+
entry.item.button.font = font;
|
|
3522
|
+
entry.item.button.contentTintColor = nil;
|
|
3425
3523
|
} else {
|
|
3426
3524
|
NSColor *color = tone == 1 ? NSColor.systemOrangeColor : NSColor.systemRedColor;
|
|
3427
|
-
|
|
3428
|
-
|
|
3525
|
+
entry.item.button.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:@{ NSForegroundColorAttributeName: color, NSFontAttributeName: font }];
|
|
3526
|
+
entry.item.button.contentTintColor = color;
|
|
3527
|
+
}
|
|
3528
|
+
entry.item.button.image = NativeSdkCefTrayImageWithOpacity(entry.baseImage, iconOpacity);
|
|
3529
|
+
entry.item.length = width > 0 ? width : (requestedTitle.length > 0 ? NSVariableStatusItemLength : NSSquareStatusItemLength);
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
static void NativeSdkCefApplyTrayShell(NativeSdkChromiumHost *object, NativeSdkChromiumStatusItemEntry *entry, const char *icon_path, size_t icon_path_len, const char *tooltip, size_t tooltip_len, int visible, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len) {
|
|
3533
|
+
entry.baseImage = nil;
|
|
3534
|
+
if (icon_path && icon_path_len > 0) {
|
|
3535
|
+
NSString *path = [[NSString alloc] initWithBytes:icon_path length:icon_path_len encoding:NSUTF8StringEncoding];
|
|
3536
|
+
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
3537
|
+
if (image) {
|
|
3538
|
+
image.template = YES;
|
|
3539
|
+
image.size = NSMakeSize(18, 18);
|
|
3540
|
+
entry.baseImage = image;
|
|
3541
|
+
}
|
|
3429
3542
|
}
|
|
3430
|
-
|
|
3431
|
-
|
|
3543
|
+
entry.item.button.toolTip = tooltip && tooltip_len > 0 ? ([[NSString alloc] initWithBytes:tooltip length:tooltip_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3544
|
+
entry.activationCommand = activation_command ? ([[NSString alloc] initWithBytes:activation_command length:activation_command_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3545
|
+
entry.alternateActivationCommand = alternate_activation_command ? ([[NSString alloc] initWithBytes:alternate_activation_command length:alternate_activation_command_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3546
|
+
entry.openCommand = open_command ? ([[NSString alloc] initWithBytes:open_command length:open_command_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3547
|
+
NSStatusBarButton *button = entry.item.button;
|
|
3548
|
+
button.tag = (NSInteger)entry.identifier;
|
|
3549
|
+
button.target = object;
|
|
3550
|
+
button.action = (entry.activationCommand.length > 0 || entry.alternateActivationCommand.length > 0) ? @selector(statusItemActivated:) : NULL;
|
|
3551
|
+
if (button.action) [button sendActionOn:NSEventMaskLeftMouseUp];
|
|
3552
|
+
entry.item.visible = visible != 0;
|
|
3432
3553
|
}
|
|
3433
3554
|
|
|
3434
|
-
void native_sdk_appkit_create_tray(native_sdk_appkit_host_t *host, const char *icon_path, size_t icon_path_len, const char *title, size_t title_len, const char *tooltip, size_t tooltip_len, double width, int tone, double icon_opacity, int monospaced, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len) {
|
|
3555
|
+
void native_sdk_appkit_create_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *icon_path, size_t icon_path_len, const char *title, size_t title_len, const char *tooltip, size_t tooltip_len, int visible, double width, int tone, double icon_opacity, int monospaced, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len) {
|
|
3435
3556
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3436
3557
|
@autoreleasepool {
|
|
3437
|
-
|
|
3438
|
-
|
|
3558
|
+
NSNumber *key = @(status_item_id);
|
|
3559
|
+
NativeSdkChromiumStatusItemEntry *entry = object.statusItems[key];
|
|
3560
|
+
if (entry) {
|
|
3561
|
+
[[NSStatusBar systemStatusBar] removeStatusItem:entry.item];
|
|
3562
|
+
} else {
|
|
3563
|
+
entry = [[NativeSdkChromiumStatusItemEntry alloc] init];
|
|
3564
|
+
entry.identifier = status_item_id;
|
|
3565
|
+
object.statusItems[key] = entry;
|
|
3439
3566
|
}
|
|
3440
|
-
|
|
3567
|
+
entry.menu = nil;
|
|
3441
3568
|
// A titled menu-bar extra needs variable width; icon-only status
|
|
3442
3569
|
// items keep the classic square well.
|
|
3443
3570
|
BOOL hasTitle = title != NULL && title_len > 0;
|
|
3444
|
-
|
|
3445
|
-
object.statusItemBaseImage = nil;
|
|
3446
|
-
|
|
3447
|
-
if (icon_path && icon_path_len > 0) {
|
|
3448
|
-
NSString *path = [[NSString alloc] initWithBytes:icon_path length:icon_path_len encoding:NSUTF8StringEncoding];
|
|
3449
|
-
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
3450
|
-
if (image) {
|
|
3451
|
-
[image setTemplate:YES];
|
|
3452
|
-
image.size = NSMakeSize(18, 18);
|
|
3453
|
-
object.statusItemBaseImage = image;
|
|
3454
|
-
}
|
|
3455
|
-
}
|
|
3571
|
+
entry.item = [[NSStatusBar systemStatusBar] statusItemWithLength:hasTitle ? NSVariableStatusItemLength : NSSquareStatusItemLength];
|
|
3456
3572
|
NSString *titleString = hasTitle ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
NativeSdkCefApplyTrayPresentation(object,
|
|
3573
|
+
NativeSdkCefApplyTrayShell(object, entry, icon_path, icon_path_len, tooltip, tooltip_len, visible, activation_command, activation_command_len, alternate_activation_command, alternate_activation_command_len, open_command, open_command_len);
|
|
3574
|
+
NativeSdkCefApplyTrayPresentation(object, entry, titleString, width, tone, icon_opacity, monospaced != 0);
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
|
|
3578
|
+
void native_sdk_appkit_update_tray_shell(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *icon_path, size_t icon_path_len, const char *tooltip, size_t tooltip_len, int visible, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len) {
|
|
3579
|
+
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3580
|
+
@autoreleasepool {
|
|
3581
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3582
|
+
if (!entry) return;
|
|
3583
|
+
NativeSdkCefApplyTrayShell(object, entry, icon_path, icon_path_len, tooltip, tooltip_len, visible, activation_command, activation_command_len, alternate_activation_command, alternate_activation_command_len, open_command, open_command_len);
|
|
3584
|
+
NativeSdkCefApplyTrayPresentation(object, entry, entry.presentationTitle, entry.presentationWidth, entry.presentationTone, entry.presentationIconOpacity, entry.presentationMonospaced);
|
|
3585
|
+
if (entry.activationCommand.length == 0 && entry.alternateActivationCommand.length == 0) entry.item.menu = entry.menu;
|
|
3586
|
+
else entry.item.menu = nil;
|
|
3469
3587
|
}
|
|
3470
3588
|
}
|
|
3471
3589
|
|
|
@@ -3478,14 +3596,15 @@ static NSEventModifierFlags NativeSdkCefTrayModifiers(uint32_t modifiers) {
|
|
|
3478
3596
|
return flags;
|
|
3479
3597
|
}
|
|
3480
3598
|
|
|
3481
|
-
void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, const uint32_t *item_ids, const char *const *labels, const size_t *label_lens, const int *separators, const int *enabled_flags, const char *const *details, const size_t *detail_lens, const int *roles, const char *const *keys, const size_t *key_lens, const uint32_t *modifiers, size_t count) {
|
|
3599
|
+
void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, uint32_t status_item_id, const uint32_t *item_ids, const char *const *labels, const size_t *label_lens, const int *separators, const int *enabled_flags, const char *const *details, const size_t *detail_lens, const int *roles, const char *const *keys, const size_t *key_lens, const uint32_t *modifiers, size_t count) {
|
|
3482
3600
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3483
3601
|
@autoreleasepool {
|
|
3484
|
-
|
|
3485
|
-
|
|
3602
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3603
|
+
if (!entry) return;
|
|
3604
|
+
NSMenu *menu = entry.menu;
|
|
3486
3605
|
if (menu == nil) {
|
|
3487
3606
|
menu = [[NSMenu alloc] initWithTitle:@""];
|
|
3488
|
-
|
|
3607
|
+
entry.menu = menu;
|
|
3489
3608
|
} else {
|
|
3490
3609
|
[menu removeAllItems];
|
|
3491
3610
|
}
|
|
@@ -3499,7 +3618,7 @@ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, const ui
|
|
|
3499
3618
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:label ?: @""
|
|
3500
3619
|
action:@selector(trayMenuItemClicked:)
|
|
3501
3620
|
keyEquivalent:@""];
|
|
3502
|
-
item.tag = (NSInteger)item_ids[i];
|
|
3621
|
+
item.tag = (NSInteger)(((uint64_t)status_item_id << 32) | item_ids[i]);
|
|
3503
3622
|
item.target = object;
|
|
3504
3623
|
item.enabled = enabled_flags[i] != 0 && (roles[i] == 0 || roles[i] == 4);
|
|
3505
3624
|
if (details[i] && detail_lens[i] > 0) {
|
|
@@ -3514,7 +3633,7 @@ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, const ui
|
|
|
3514
3633
|
[menu addItem:item];
|
|
3515
3634
|
}
|
|
3516
3635
|
menu.delegate = object;
|
|
3517
|
-
if (
|
|
3636
|
+
if (entry.activationCommand.length == 0 && entry.alternateActivationCommand.length == 0) entry.item.menu = menu;
|
|
3518
3637
|
}
|
|
3519
3638
|
}
|
|
3520
3639
|
|
|
@@ -3531,38 +3650,41 @@ int native_sdk_appkit_set_window_content_min_size(native_sdk_appkit_host_t *host
|
|
|
3531
3650
|
return 1;
|
|
3532
3651
|
}
|
|
3533
3652
|
|
|
3534
|
-
void native_sdk_appkit_update_tray_title(native_sdk_appkit_host_t *host, const char *title, size_t title_len) {
|
|
3653
|
+
void native_sdk_appkit_update_tray_title(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *title, size_t title_len) {
|
|
3535
3654
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3536
3655
|
@autoreleasepool {
|
|
3537
|
-
|
|
3656
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3657
|
+
if (!entry) return;
|
|
3538
3658
|
NSString *value = title && title_len > 0 ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3539
3659
|
NativeSdkCefApplyTrayPresentation(
|
|
3540
3660
|
object,
|
|
3661
|
+
entry,
|
|
3541
3662
|
value,
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3663
|
+
entry.presentationWidth,
|
|
3664
|
+
entry.presentationTone,
|
|
3665
|
+
entry.presentationIconOpacity,
|
|
3666
|
+
entry.presentationMonospaced
|
|
3546
3667
|
);
|
|
3547
3668
|
}
|
|
3548
3669
|
}
|
|
3549
3670
|
|
|
3550
|
-
void native_sdk_appkit_update_tray_presentation(native_sdk_appkit_host_t *host, const char *title, size_t title_len, double width, int tone, double icon_opacity, int monospaced) {
|
|
3671
|
+
void native_sdk_appkit_update_tray_presentation(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *title, size_t title_len, double width, int tone, double icon_opacity, int monospaced) {
|
|
3551
3672
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3552
3673
|
@autoreleasepool {
|
|
3674
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3675
|
+
if (!entry) return;
|
|
3553
3676
|
NSString *value = title ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3554
|
-
NativeSdkCefApplyTrayPresentation(object, value, width, tone, icon_opacity, monospaced != 0);
|
|
3677
|
+
NativeSdkCefApplyTrayPresentation(object, entry, value, width, tone, icon_opacity, monospaced != 0);
|
|
3555
3678
|
}
|
|
3556
3679
|
}
|
|
3557
3680
|
|
|
3558
|
-
void native_sdk_appkit_remove_tray(native_sdk_appkit_host_t *host) {
|
|
3681
|
+
void native_sdk_appkit_remove_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id) {
|
|
3559
3682
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
}
|
|
3683
|
+
NSNumber *key = @(status_item_id);
|
|
3684
|
+
NativeSdkChromiumStatusItemEntry *entry = object.statusItems[key];
|
|
3685
|
+
if (!entry) return;
|
|
3686
|
+
[[NSStatusBar systemStatusBar] removeStatusItem:entry.item];
|
|
3687
|
+
[object.statusItems removeObjectForKey:key];
|
|
3566
3688
|
}
|
|
3567
3689
|
|
|
3568
3690
|
/* Dock icon entry points, CEF engine: the Chromium shell is still a
|