@native-sdk/cli 0.8.4 → 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 +1178 -74
- package/build.zig +715 -17
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +10 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +435 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +224 -0
- package/packages/core/sdk/core.ts +694 -22
- package/packages/core/sdk/events.d.ts +89 -0
- package/packages/core/sdk/events.ts +128 -0
- package/packages/core/src/checker.ts +936 -15
- package/packages/core/src/cli.ts +156 -3
- package/packages/core/src/contract.ts +28 -5
- package/packages/core/src/devhost.ts +1876 -16
- package/packages/core/src/devhost_journal.mjs +183 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +179 -22
- package/packages/core/src/frontend.ts +210 -34
- package/packages/core/src/infer.ts +24 -0
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/core/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +58 -5
- package/skill-data/ts-core/SKILL.md +123 -41
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +604 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +133 -4
- package/src/app_runner/ts_core_main.zig +254 -8
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +31 -11
- package/src/embed/app_exports.zig +12 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +109 -1
- package/src/embed/root.zig +8 -0
- package/src/embed/tests.zig +241 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +185 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +8 -2
- package/src/platform/linux/gtk_host.c +289 -22
- package/src/platform/linux/gtk_host.h +5 -1
- package/src/platform/linux/root.zig +109 -22
- package/src/platform/macos/appkit_host.h +24 -7
- package/src/platform/macos/appkit_host.m +686 -64
- package/src/platform/macos/cef_host.mm +400 -66
- package/src/platform/macos/root.zig +304 -47
- package/src/platform/null_platform.zig +435 -48
- package/src/platform/null_platform_tests.zig +113 -0
- package/src/platform/root.zig +19 -0
- package/src/platform/types.zig +281 -28
- package/src/platform/windows/root.zig +207 -27
- package/src/platform/windows/webview2_host.cpp +334 -51
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/root.zig +53 -0
- package/src/runtime/api.zig +19 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -20
- package/src/runtime/bridge_permission_tests.zig +58 -3
- package/src/runtime/bridge_responses.zig +4 -2
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/canvas_frame.zig +18 -11
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +145 -7
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +3701 -231
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -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 +35 -10
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +86 -2
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +54 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +158 -5
- package/src/runtime/session_record.zig +215 -0
- package/src/runtime/session_replay.zig +206 -11
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/system_services.zig +170 -38
- package/src/runtime/tests.zig +4 -0
- package/src/runtime/ts_core_host.zig +1067 -95
- package/src/runtime/ts_core_host_tests.zig +325 -11
- package/src/runtime/ts_ui_app.zig +953 -2
- package/src/runtime/ui_app.zig +434 -96
- package/src/runtime/ui_app_tests.zig +287 -11
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +42 -0
- package/src/runtime/view.zig +9 -0
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +214 -2
- package/src/tooling/package.zig +116 -0
- package/src/tooling/raw_manifest.zig +30 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +189 -4
- package/src/tooling/ts_core.zig +366 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +442 -27
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
#import <AppKit/AppKit.h>
|
|
4
4
|
#import <CoreFoundation/CoreFoundation.h>
|
|
5
|
+
#import <dispatch/dispatch.h>
|
|
5
6
|
#import <ImageIO/ImageIO.h>
|
|
6
7
|
#import <Security/Security.h>
|
|
7
8
|
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
|
8
9
|
#include <crt_externs.h>
|
|
10
|
+
#include <dlfcn.h>
|
|
9
11
|
#include <stdint.h>
|
|
10
12
|
#include <stdio.h>
|
|
11
13
|
#include <stdlib.h>
|
|
@@ -44,6 +46,52 @@ static const uint32_t NativeSdkShortcutModifierCommand = 1u << 1;
|
|
|
44
46
|
static const uint32_t NativeSdkShortcutModifierControl = 1u << 2;
|
|
45
47
|
static const uint32_t NativeSdkShortcutModifierOption = 1u << 3;
|
|
46
48
|
static const uint32_t NativeSdkShortcutModifierShift = 1u << 4;
|
|
49
|
+
|
|
50
|
+
// Class lookup alone does not load ServiceManagement. Load the framework
|
|
51
|
+
// explicitly on first use, then keep resolving SMAppService dynamically so
|
|
52
|
+
// hosts on older macOS releases report unsupported.
|
|
53
|
+
static id NativeSdkMainAppService(void) {
|
|
54
|
+
static void *serviceManagementHandle = NULL;
|
|
55
|
+
static dispatch_once_t serviceManagementOnce;
|
|
56
|
+
dispatch_once(&serviceManagementOnce, ^{
|
|
57
|
+
serviceManagementHandle = dlopen(
|
|
58
|
+
"/System/Library/Frameworks/ServiceManagement.framework/ServiceManagement",
|
|
59
|
+
RTLD_LAZY | RTLD_LOCAL);
|
|
60
|
+
});
|
|
61
|
+
if (!serviceManagementHandle) return nil;
|
|
62
|
+
Class serviceClass = NSClassFromString(@"SMAppService");
|
|
63
|
+
SEL selector = NSSelectorFromString(@"mainApp");
|
|
64
|
+
if (!serviceClass || ![serviceClass respondsToSelector:selector]) return nil;
|
|
65
|
+
IMP implementation = [serviceClass methodForSelector:selector];
|
|
66
|
+
return ((id (*)(id, SEL))implementation)(serviceClass, selector);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static int NativeSdkLaunchAtLoginStatus(void) {
|
|
70
|
+
id service = NativeSdkMainAppService();
|
|
71
|
+
SEL selector = NSSelectorFromString(@"status");
|
|
72
|
+
if (!service || ![service respondsToSelector:selector]) return -1;
|
|
73
|
+
IMP implementation = [service methodForSelector:selector];
|
|
74
|
+
return (int)((NSInteger (*)(id, SEL))implementation)(service, selector);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static int NativeSdkSetLaunchAtLogin(BOOL enabled) {
|
|
78
|
+
id service = NativeSdkMainAppService();
|
|
79
|
+
if (!service) return -1;
|
|
80
|
+
int before = NativeSdkLaunchAtLoginStatus();
|
|
81
|
+
// Requires-approval is already registered in the requested enabled
|
|
82
|
+
// direction. Re-registering it returns kSMErrorAlreadyRegistered or
|
|
83
|
+
// kSMErrorLaunchDeniedByUser instead of advancing the user's consent.
|
|
84
|
+
if ((enabled && (before == 1 || before == 2)) || (!enabled && before == 0)) return before;
|
|
85
|
+
SEL selector = NSSelectorFromString(enabled ? @"registerAndReturnError:" : @"unregisterAndReturnError:");
|
|
86
|
+
if (![service respondsToSelector:selector]) return -1;
|
|
87
|
+
NSError *error = nil;
|
|
88
|
+
IMP implementation = [service methodForSelector:selector];
|
|
89
|
+
BOOL succeeded = ((BOOL (*)(id, SEL, NSError **))implementation)(service, selector, &error);
|
|
90
|
+
// -1 is reserved for an unavailable service/API. A supported service
|
|
91
|
+
// refusing the operation is a real failure so the TypeScript effect can
|
|
92
|
+
// distinguish "failed" from "unsupported".
|
|
93
|
+
return succeeded ? NativeSdkLaunchAtLoginStatus() : -2;
|
|
94
|
+
}
|
|
47
95
|
static const char *NativeSdkCefBridgeScript();
|
|
48
96
|
static NSRect NativeSdkConstrainFrame(NSRect frame);
|
|
49
97
|
static NSString *NativeSdkResolvedAssetRoot(NSString *rootPath);
|
|
@@ -84,6 +132,14 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
|
|
|
84
132
|
} mutableCopy];
|
|
85
133
|
}
|
|
86
134
|
|
|
135
|
+
static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
136
|
+
if (status == errSecSuccess) return 1;
|
|
137
|
+
if (status == errSecItemNotFound) return missingCode;
|
|
138
|
+
if (status == errSecInteractionNotAllowed || status == errSecNotAvailable) return -2;
|
|
139
|
+
if (status == errSecAuthFailed || status == errSecUserCanceled || status == errSecMissingEntitlement) return -3;
|
|
140
|
+
return -1;
|
|
141
|
+
}
|
|
142
|
+
|
|
87
143
|
class NativeSdkCefBridgeV8Handler final : public CefV8Handler {
|
|
88
144
|
public:
|
|
89
145
|
bool Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception) override {
|
|
@@ -413,7 +469,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
413
469
|
"});"
|
|
414
470
|
"var os=Object.freeze({"
|
|
415
471
|
"openUrl:function(value){var options=typeof value==='string'?{url:value}:(value||{});return invoke('native-sdk.os.openUrl',{url:ensureString(options.url,'url')});},"
|
|
416
|
-
"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);},"
|
|
417
473
|
"revealPath:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.revealPath',{path:ensureString(options.path,'path')});},"
|
|
418
474
|
"addRecentDocument:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.addRecentDocument',{path:ensureString(options.path,'path')});},"
|
|
419
475
|
"clearRecentDocuments:function(){return invoke('native-sdk.os.clearRecentDocuments',{});}"
|
|
@@ -496,6 +552,21 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
496
552
|
@property(nonatomic, assign) uint32_t modifiers;
|
|
497
553
|
@end
|
|
498
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
|
+
|
|
499
570
|
/* Captures the selected item id of a context-menu popUp (NSMenuItem
|
|
500
571
|
* targets are weak; the presenter block keeps this alive). */
|
|
501
572
|
@interface NativeSdkChromiumContextMenuTarget : NSObject
|
|
@@ -512,7 +583,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
512
583
|
|
|
513
584
|
@end
|
|
514
585
|
|
|
515
|
-
@interface NativeSdkChromiumHost : NSObject
|
|
586
|
+
@interface NativeSdkChromiumHost : NSObject <NSMenuDelegate, NSUserNotificationCenterDelegate>
|
|
516
587
|
@property(nonatomic, strong) NSWindow *window;
|
|
517
588
|
@property(nonatomic, strong) NSView *browserContainer;
|
|
518
589
|
@property(nonatomic, strong) NativeSdkChromiumWindowDelegate *delegate;
|
|
@@ -540,6 +611,10 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
540
611
|
@property(nonatomic, assign) uint64_t nextWebViewGeneration;
|
|
541
612
|
@property(nonatomic, strong) NSTimer *timer;
|
|
542
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;
|
|
543
618
|
@property(nonatomic, strong) NSString *appName;
|
|
544
619
|
/* The human-facing app name (app.zon display_name, empty = appName):
|
|
545
620
|
* drives the application menu title and its About/Hide/Quit labels, the
|
|
@@ -562,7 +637,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
562
637
|
@property(nonatomic, assign) BOOL observesApplicationActivation;
|
|
563
638
|
@property(nonatomic, strong) id shortcutEventMonitor;
|
|
564
639
|
@property(nonatomic, strong) NSArray<NativeSdkChromiumShortcut *> *shortcuts;
|
|
565
|
-
@property(nonatomic, strong)
|
|
640
|
+
@property(nonatomic, strong) NSMutableDictionary<NSNumber *, NativeSdkChromiumStatusItemEntry *> *statusItems;
|
|
566
641
|
@property(nonatomic, assign) native_sdk_appkit_tray_callback_t trayCallback;
|
|
567
642
|
@property(nonatomic, assign) void *trayContext;
|
|
568
643
|
@property(nonatomic) CefRefPtr<NativeSdkCefClient> cefClient;
|
|
@@ -598,6 +673,8 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
598
673
|
- (void)stopApplicationActivationObservers;
|
|
599
674
|
- (void)applicationDidBecomeActive:(NSNotification *)notification;
|
|
600
675
|
- (void)applicationDidResignActive:(NSNotification *)notification;
|
|
676
|
+
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification;
|
|
677
|
+
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification;
|
|
601
678
|
- (void)emitResize;
|
|
602
679
|
- (void)emitResizeForWindowId:(uint64_t)windowId;
|
|
603
680
|
- (void)emitWindowFrameForWindowId:(uint64_t)windowId open:(BOOL)open;
|
|
@@ -637,11 +714,19 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
637
714
|
- (BOOL)handleShortcutEvent:(NSEvent *)event;
|
|
638
715
|
- (void)emitShortcutWithId:(NSString *)identifier key:(NSString *)key modifiers:(uint32_t)modifiers event:(NSEvent *)event;
|
|
639
716
|
- (void)trayMenuItemClicked:(NSMenuItem *)menuItem;
|
|
717
|
+
- (void)menuWillOpen:(NSMenu *)menu;
|
|
718
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForId:(uint32_t)identifier;
|
|
719
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForMenu:(NSMenu *)menu;
|
|
720
|
+
- (void)emitStatusCommand:(NSString *)command statusItemId:(uint32_t)statusItemId;
|
|
721
|
+
- (void)statusItemActivated:(id)sender;
|
|
640
722
|
@end
|
|
641
723
|
|
|
642
724
|
@implementation NativeSdkChromiumShortcut
|
|
643
725
|
@end
|
|
644
726
|
|
|
727
|
+
@implementation NativeSdkChromiumStatusItemEntry
|
|
728
|
+
@end
|
|
729
|
+
|
|
645
730
|
@implementation NativeSdkChromiumWindowDelegate
|
|
646
731
|
|
|
647
732
|
- (void)windowDidResize:(NSNotification *)notification {
|
|
@@ -798,6 +883,9 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
798
883
|
self.webviewGenerations = [[NSMutableDictionary alloc] init];
|
|
799
884
|
self.closingWebViewKeys = [[NSMutableSet alloc] init];
|
|
800
885
|
self.appTimers = [[NSMutableDictionary alloc] init];
|
|
886
|
+
self.notificationActionCommands = [[NSMutableDictionary alloc] init];
|
|
887
|
+
self.notificationActionTokensByIdentifier = [[NSMutableDictionary alloc] init];
|
|
888
|
+
self.statusItems = [[NSMutableDictionary alloc] init];
|
|
801
889
|
self.nextWebViewGeneration = 1;
|
|
802
890
|
self.cefClients = new std::map<uint64_t, CefRefPtr<NativeSdkCefClient>>();
|
|
803
891
|
self.browsers = new std::map<uint64_t, CefRefPtr<CefBrowser>>();
|
|
@@ -913,6 +1001,8 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
913
1001
|
}
|
|
914
1002
|
|
|
915
1003
|
- (void)dealloc {
|
|
1004
|
+
NSUserNotificationCenter *notificationCenter = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
1005
|
+
if (notificationCenter.delegate == self) notificationCenter.delegate = nil;
|
|
916
1006
|
if (self.shortcutEventMonitor) {
|
|
917
1007
|
[NSEvent removeMonitor:self.shortcutEventMonitor];
|
|
918
1008
|
self.shortcutEventMonitor = nil;
|
|
@@ -945,6 +1035,12 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
945
1035
|
if ((windowFlags & (1u << 1)) != 0) window.level = NSFloatingWindowLevel;
|
|
946
1036
|
if ((windowFlags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
|
|
947
1037
|
if ((windowFlags & (1u << 3)) != 0) [self.passiveShowWindows addObject:key];
|
|
1038
|
+
if ((windowFlags & (1u << 4)) != 0) {
|
|
1039
|
+
NSWindowCollectionBehavior behavior = window.collectionBehavior;
|
|
1040
|
+
behavior &= ~(NSWindowCollectionBehaviorFullScreenPrimary | NSWindowCollectionBehaviorFullScreenAuxiliary);
|
|
1041
|
+
window.collectionBehavior = behavior | NSWindowCollectionBehaviorFullScreenNone;
|
|
1042
|
+
[window standardWindowButton:NSWindowZoomButton].enabled = NO;
|
|
1043
|
+
}
|
|
948
1044
|
[window setTitle:title.length > 0 ? title : @"native-sdk"];
|
|
949
1045
|
if (!restoreFrame) {
|
|
950
1046
|
[window center];
|
|
@@ -1006,16 +1102,17 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1006
1102
|
if ([self.passiveShowWindows containsObject:@(windowId)]) {
|
|
1007
1103
|
[window orderFront:nil];
|
|
1008
1104
|
} else {
|
|
1009
|
-
[window makeKeyAndOrderFront:nil];
|
|
1010
1105
|
[NSApp activateIgnoringOtherApps:YES];
|
|
1106
|
+
[window makeKeyAndOrderFront:nil];
|
|
1011
1107
|
}
|
|
1012
1108
|
}
|
|
1013
1109
|
|
|
1014
1110
|
- (void)focusWindowWithId:(uint64_t)windowId {
|
|
1015
1111
|
NSWindow *window = self.windows[@(windowId)];
|
|
1016
1112
|
if (!window) return;
|
|
1017
|
-
[
|
|
1113
|
+
[self.policyHiddenWindows removeObject:@(windowId)];
|
|
1018
1114
|
[NSApp activateIgnoringOtherApps:YES];
|
|
1115
|
+
[window makeKeyAndOrderFront:nil];
|
|
1019
1116
|
[self emitWindowFrameForWindowId:windowId open:YES];
|
|
1020
1117
|
}
|
|
1021
1118
|
|
|
@@ -1138,7 +1235,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1138
1235
|
NSApp.delegate = reopenDelegate;
|
|
1139
1236
|
}
|
|
1140
1237
|
|
|
1141
|
-
[self orderWindowForImplicitShow:1];
|
|
1238
|
+
if (![self.policyHiddenWindows containsObject:@1]) [self orderWindowForImplicitShow:1];
|
|
1142
1239
|
if (!self.shortcutEventMonitor) {
|
|
1143
1240
|
__weak NativeSdkChromiumHost *weakSelf = self;
|
|
1144
1241
|
self.shortcutEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *(NSEvent *event) {
|
|
@@ -1274,6 +1371,38 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1274
1371
|
[self emitEvent:(native_sdk_appkit_event_t){ .kind = NATIVE_SDK_APPKIT_EVENT_APP_DEACTIVATED }];
|
|
1275
1372
|
}
|
|
1276
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
|
+
|
|
1277
1406
|
- (void)emitResize {
|
|
1278
1407
|
[self emitResizeForWindowId:1];
|
|
1279
1408
|
}
|
|
@@ -1914,7 +2043,51 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1914
2043
|
}
|
|
1915
2044
|
|
|
1916
2045
|
- (void)trayMenuItemClicked:(NSMenuItem *)menuItem {
|
|
1917
|
-
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;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
- (void)emitStatusCommand:(NSString *)command statusItemId:(uint32_t)statusItemId {
|
|
2064
|
+
if (command.length == 0) return;
|
|
2065
|
+
const char *bytes = command.UTF8String;
|
|
2066
|
+
[self emitEvent:(native_sdk_appkit_event_t){
|
|
2067
|
+
.kind = NATIVE_SDK_APPKIT_EVENT_TRAY_COMMAND,
|
|
2068
|
+
.window_id = 1,
|
|
2069
|
+
.status_item_id = statusItemId,
|
|
2070
|
+
.command_name = bytes,
|
|
2071
|
+
.command_name_len = [command lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
2072
|
+
}];
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
- (void)menuWillOpen:(NSMenu *)menu {
|
|
2076
|
+
NativeSdkChromiumStatusItemEntry *entry = [self statusEntryForMenu:menu];
|
|
2077
|
+
if (!entry) return;
|
|
2078
|
+
[self emitStatusCommand:entry.openCommand statusItemId:entry.identifier];
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
- (void)statusItemActivated:(id)sender {
|
|
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];
|
|
2087
|
+
return;
|
|
2088
|
+
}
|
|
2089
|
+
[self emitStatusCommand:entry.activationCommand statusItemId:entry.identifier];
|
|
2090
|
+
if (entry.menu) [entry.item popUpStatusItemMenu:entry.menu];
|
|
1918
2091
|
}
|
|
1919
2092
|
|
|
1920
2093
|
@end
|
|
@@ -2147,6 +2320,12 @@ static void NativeSdkApplyOverlayWindowFlags(NativeSdkChromiumHost *host, uint64
|
|
|
2147
2320
|
if ((window_flags & (1u << 1)) != 0) window.level = NSFloatingWindowLevel;
|
|
2148
2321
|
if ((window_flags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
|
|
2149
2322
|
if ((window_flags & (1u << 3)) != 0) [host.passiveShowWindows addObject:@(window_id)];
|
|
2323
|
+
if ((window_flags & (1u << 4)) != 0) {
|
|
2324
|
+
NSWindowCollectionBehavior behavior = window.collectionBehavior;
|
|
2325
|
+
behavior &= ~(NSWindowCollectionBehaviorFullScreenPrimary | NSWindowCollectionBehaviorFullScreenAuxiliary);
|
|
2326
|
+
window.collectionBehavior = behavior | NSWindowCollectionBehaviorFullScreenNone;
|
|
2327
|
+
[window standardWindowButton:NSWindowZoomButton].enabled = NO;
|
|
2328
|
+
}
|
|
2150
2329
|
}
|
|
2151
2330
|
|
|
2152
2331
|
native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t app_name_len, const char *display_name, size_t display_name_len, const char *version, size_t version_len, const char *about_description, size_t about_description_len, int has_web_content, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
@@ -2160,9 +2339,10 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
|
|
|
2160
2339
|
// hosts webviews only (gpu-surface presents are unsupported on
|
|
2161
2340
|
// this engine), so the policy is accepted for ABI parity and
|
|
2162
2341
|
// windows show immediately — the web engine owns first paint.
|
|
2342
|
+
// Policy 2 is different: it is an explicit initially-hidden
|
|
2343
|
+
// lifecycle request and is honored below.
|
|
2163
2344
|
// has_web_content is likewise ABI parity: this host always
|
|
2164
2345
|
// hosts web content, and its menus already assume it.
|
|
2165
|
-
(void)show_policy;
|
|
2166
2346
|
(void)has_web_content;
|
|
2167
2347
|
(void)bundle_id;
|
|
2168
2348
|
(void)bundle_id_len;
|
|
@@ -2184,6 +2364,7 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
|
|
|
2184
2364
|
}
|
|
2185
2365
|
NativeSdkApplyHiddenInsetTitlebar(host.window, titlebar_style, host.delegates[@1]);
|
|
2186
2366
|
NativeSdkApplyOverlayWindowFlags(host, 1, window_flags);
|
|
2367
|
+
if (show_policy == 2) [host.policyHiddenWindows addObject:@1];
|
|
2187
2368
|
return (__bridge_retained native_sdk_appkit_host_t *)host;
|
|
2188
2369
|
}
|
|
2189
2370
|
}
|
|
@@ -2430,8 +2611,6 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
|
|
|
2430
2611
|
}
|
|
2431
2612
|
|
|
2432
2613
|
int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
2433
|
-
// Accepted for ABI parity; see native_sdk_appkit_create.
|
|
2434
|
-
(void)show_policy;
|
|
2435
2614
|
if ((window_flags & (1u << 0)) != 0) return 0;
|
|
2436
2615
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
2437
2616
|
NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"native-sdk";
|
|
@@ -2440,7 +2619,11 @@ int native_sdk_appkit_create_window(native_sdk_appkit_host_t *host, uint64_t win
|
|
|
2440
2619
|
NativeSdkApplyHiddenInsetTitlebar(object.windows[@(window_id)], titlebar_style, object.delegates[@(window_id)]);
|
|
2441
2620
|
// Apply chrome and overlay presentation while still hidden, then
|
|
2442
2621
|
// reveal once so a secondary window cannot flash its default frame.
|
|
2443
|
-
|
|
2622
|
+
if (show_policy == 2) {
|
|
2623
|
+
[object.policyHiddenWindows addObject:@(window_id)];
|
|
2624
|
+
} else {
|
|
2625
|
+
[object orderWindowForImplicitShow:window_id];
|
|
2626
|
+
}
|
|
2444
2627
|
return 1;
|
|
2445
2628
|
}
|
|
2446
2629
|
|
|
@@ -2465,6 +2648,13 @@ int native_sdk_appkit_minimize_window(native_sdk_appkit_host_t *host, uint64_t w
|
|
|
2465
2648
|
return 1;
|
|
2466
2649
|
}
|
|
2467
2650
|
|
|
2651
|
+
int native_sdk_appkit_hide_window(native_sdk_appkit_host_t *host, uint64_t window_id) {
|
|
2652
|
+
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
2653
|
+
if (!object.windows[@(window_id)]) return 0;
|
|
2654
|
+
[object hideWindowWithId:window_id];
|
|
2655
|
+
return 1;
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2468
2658
|
int native_sdk_appkit_show_window(native_sdk_appkit_host_t *host, uint64_t window_id) {
|
|
2469
2659
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
2470
2660
|
if (!object.windows[@(window_id)]) return 0;
|
|
@@ -2476,6 +2666,23 @@ int native_sdk_appkit_show_window(native_sdk_appkit_host_t *host, uint64_t windo
|
|
|
2476
2666
|
return 1;
|
|
2477
2667
|
}
|
|
2478
2668
|
|
|
2669
|
+
int native_sdk_appkit_set_dock_presence(native_sdk_appkit_host_t *host, int visible) {
|
|
2670
|
+
(void)host;
|
|
2671
|
+
NSApplicationActivationPolicy policy = visible ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory;
|
|
2672
|
+
BOOL changed = [NSApp setActivationPolicy:policy];
|
|
2673
|
+
return changed || NSApp.activationPolicy == policy ? 1 : 0;
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
int native_sdk_appkit_launch_at_login_status(native_sdk_appkit_host_t *host) {
|
|
2677
|
+
(void)host;
|
|
2678
|
+
return NativeSdkLaunchAtLoginStatus();
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
int native_sdk_appkit_set_launch_at_login(native_sdk_appkit_host_t *host, int enabled) {
|
|
2682
|
+
(void)host;
|
|
2683
|
+
return NativeSdkSetLaunchAtLogin(enabled != 0);
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2479
2686
|
int native_sdk_appkit_set_window_close_policy(native_sdk_appkit_host_t *host, uint64_t window_id, int close_policy) {
|
|
2480
2687
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
2481
2688
|
if (!object.windows[@(window_id)]) return 0;
|
|
@@ -3028,17 +3235,42 @@ int native_sdk_appkit_clipboard_write_data(native_sdk_appkit_host_t *host, const
|
|
|
3028
3235
|
return [pasteboard setData:data forType:type] ? 1 : 0;
|
|
3029
3236
|
}
|
|
3030
3237
|
|
|
3031
|
-
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) {
|
|
3032
|
-
(
|
|
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;
|
|
3033
3241
|
NSString *titleString = title ? [[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] : @"";
|
|
3034
3242
|
if (titleString.length == 0) return 0;
|
|
3035
3243
|
NSString *subtitleString = subtitle ? [[NSString alloc] initWithBytes:subtitle length:subtitle_len encoding:NSUTF8StringEncoding] : @"";
|
|
3036
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
|
+
}
|
|
3037
3253
|
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
|
3038
3254
|
notification.title = titleString;
|
|
3039
3255
|
if (subtitleString.length > 0) notification.subtitle = subtitleString;
|
|
3040
3256
|
if (bodyString.length > 0) notification.informativeText = bodyString;
|
|
3041
|
-
|
|
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];
|
|
3042
3274
|
return 1;
|
|
3043
3275
|
}
|
|
3044
3276
|
|
|
@@ -3082,7 +3314,7 @@ int native_sdk_appkit_set_credential(native_sdk_appkit_host_t *host, const char
|
|
|
3082
3314
|
@autoreleasepool {
|
|
3083
3315
|
NSString *serviceString = NativeSdkStringFromBytes(service, service_len);
|
|
3084
3316
|
NSString *accountString = NativeSdkStringFromBytes(account, account_len);
|
|
3085
|
-
if (serviceString.length == 0 || accountString.length == 0 || !secret
|
|
3317
|
+
if (serviceString.length == 0 || accountString.length == 0 || (!secret && secret_len > 0)) return 0;
|
|
3086
3318
|
NSData *secretData = [NSData dataWithBytes:secret length:secret_len];
|
|
3087
3319
|
NSMutableDictionary *query = NativeSdkCredentialQuery(serviceString, accountString);
|
|
3088
3320
|
NSDictionary *update = @{ (__bridge id)kSecValueData: secretData };
|
|
@@ -3091,7 +3323,7 @@ int native_sdk_appkit_set_credential(native_sdk_appkit_host_t *host, const char
|
|
|
3091
3323
|
query[(__bridge id)kSecValueData] = secretData;
|
|
3092
3324
|
status = SecItemAdd((__bridge CFDictionaryRef)query, NULL);
|
|
3093
3325
|
}
|
|
3094
|
-
return status
|
|
3326
|
+
return NativeSdkCredentialStatus(status, -1);
|
|
3095
3327
|
}
|
|
3096
3328
|
}
|
|
3097
3329
|
|
|
@@ -3100,13 +3332,16 @@ size_t native_sdk_appkit_get_credential(native_sdk_appkit_host_t *host, const ch
|
|
|
3100
3332
|
@autoreleasepool {
|
|
3101
3333
|
NSString *serviceString = NativeSdkStringFromBytes(service, service_len);
|
|
3102
3334
|
NSString *accountString = NativeSdkStringFromBytes(account, account_len);
|
|
3103
|
-
if (serviceString.length == 0 || accountString.length == 0 || !buffer) return
|
|
3335
|
+
if (serviceString.length == 0 || accountString.length == 0 || (!buffer && buffer_len > 0)) return SIZE_MAX - 1;
|
|
3104
3336
|
NSMutableDictionary *query = NativeSdkCredentialQuery(serviceString, accountString);
|
|
3105
3337
|
query[(__bridge id)kSecReturnData] = @YES;
|
|
3106
3338
|
query[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitOne;
|
|
3107
3339
|
CFTypeRef result = NULL;
|
|
3108
3340
|
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result);
|
|
3109
|
-
if (status
|
|
3341
|
+
if (status == errSecItemNotFound) return SIZE_MAX;
|
|
3342
|
+
if (status == errSecInteractionNotAllowed || status == errSecNotAvailable) return SIZE_MAX - 2;
|
|
3343
|
+
if (status == errSecAuthFailed || status == errSecUserCanceled || status == errSecMissingEntitlement) return SIZE_MAX - 3;
|
|
3344
|
+
if (status != errSecSuccess || !result) return SIZE_MAX - 1;
|
|
3110
3345
|
NSData *data = CFBridgingRelease(result);
|
|
3111
3346
|
if (data.length > buffer_len) return data.length;
|
|
3112
3347
|
memcpy(buffer, data.bytes, data.length);
|
|
@@ -3122,7 +3357,7 @@ int native_sdk_appkit_delete_credential(native_sdk_appkit_host_t *host, const ch
|
|
|
3122
3357
|
if (serviceString.length == 0 || accountString.length == 0) return 0;
|
|
3123
3358
|
NSMutableDictionary *query = NativeSdkCredentialQuery(serviceString, accountString);
|
|
3124
3359
|
OSStatus status = SecItemDelete((__bridge CFDictionaryRef)query);
|
|
3125
|
-
return status
|
|
3360
|
+
return NativeSdkCredentialStatus(status, 0);
|
|
3126
3361
|
}
|
|
3127
3362
|
}
|
|
3128
3363
|
|
|
@@ -3259,43 +3494,121 @@ int native_sdk_appkit_show_message_dialog(native_sdk_appkit_host_t *host, const
|
|
|
3259
3494
|
}
|
|
3260
3495
|
}
|
|
3261
3496
|
|
|
3262
|
-
|
|
3497
|
+
static NSImage *NativeSdkCefTrayImageWithOpacity(NSImage *source, double opacity) {
|
|
3498
|
+
if (!source) return nil;
|
|
3499
|
+
const CGFloat fraction = MAX(0.0, MIN(1.0, opacity));
|
|
3500
|
+
if (fraction >= 1.0) return source;
|
|
3501
|
+
NSImage *image = [[NSImage alloc] initWithSize:source.size];
|
|
3502
|
+
[image lockFocus];
|
|
3503
|
+
[source drawInRect:NSMakeRect(0, 0, source.size.width, source.size.height) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:fraction];
|
|
3504
|
+
[image unlockFocus];
|
|
3505
|
+
image.template = YES;
|
|
3506
|
+
return image;
|
|
3507
|
+
}
|
|
3508
|
+
|
|
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;
|
|
3516
|
+
NSString *title = requestedTitle ?: @"";
|
|
3517
|
+
if (!entry.baseImage && title.length == 0) title = object.appName.length > 0 ? [object.appName substringToIndex:MIN(1, object.appName.length)] : @"Z";
|
|
3518
|
+
NSFont *font = monospaced ? [NSFont monospacedDigitSystemFontOfSize:11 weight:NSFontWeightRegular] : [NSFont systemFontOfSize:11];
|
|
3519
|
+
if (tone == 0) {
|
|
3520
|
+
entry.item.button.title = title;
|
|
3521
|
+
entry.item.button.font = font;
|
|
3522
|
+
entry.item.button.contentTintColor = nil;
|
|
3523
|
+
} else {
|
|
3524
|
+
NSColor *color = tone == 1 ? NSColor.systemOrangeColor : NSColor.systemRedColor;
|
|
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
|
+
}
|
|
3542
|
+
}
|
|
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;
|
|
3553
|
+
}
|
|
3554
|
+
|
|
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) {
|
|
3263
3556
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3264
3557
|
@autoreleasepool {
|
|
3265
|
-
|
|
3266
|
-
|
|
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;
|
|
3267
3566
|
}
|
|
3567
|
+
entry.menu = nil;
|
|
3268
3568
|
// A titled menu-bar extra needs variable width; icon-only status
|
|
3269
3569
|
// items keep the classic square well.
|
|
3270
3570
|
BOOL hasTitle = title != NULL && title_len > 0;
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
3276
|
-
if (image) {
|
|
3277
|
-
[image setTemplate:YES];
|
|
3278
|
-
image.size = NSMakeSize(18, 18);
|
|
3279
|
-
object.statusItem.button.image = image;
|
|
3280
|
-
}
|
|
3281
|
-
}
|
|
3282
|
-
if (hasTitle) {
|
|
3283
|
-
object.statusItem.button.title = [[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
3284
|
-
}
|
|
3285
|
-
if (!object.statusItem.button.image && object.statusItem.button.title.length == 0) {
|
|
3286
|
-
object.statusItem.button.title = object.appName.length > 0 ? [object.appName substringToIndex:MIN(1, object.appName.length)] : @"Z";
|
|
3287
|
-
}
|
|
3288
|
-
if (tooltip && tooltip_len > 0) {
|
|
3289
|
-
object.statusItem.button.toolTip = [[NSString alloc] initWithBytes:tooltip length:tooltip_len encoding:NSUTF8StringEncoding];
|
|
3290
|
-
}
|
|
3571
|
+
entry.item = [[NSStatusBar systemStatusBar] statusItemWithLength:hasTitle ? NSVariableStatusItemLength : NSSquareStatusItemLength];
|
|
3572
|
+
NSString *titleString = hasTitle ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
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);
|
|
3291
3575
|
}
|
|
3292
3576
|
}
|
|
3293
3577
|
|
|
3294
|
-
void
|
|
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) {
|
|
3295
3579
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3296
3580
|
@autoreleasepool {
|
|
3297
|
-
|
|
3298
|
-
|
|
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;
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
static NSEventModifierFlags NativeSdkCefTrayModifiers(uint32_t modifiers) {
|
|
3591
|
+
NSEventModifierFlags flags = 0;
|
|
3592
|
+
if ((modifiers & (1u << 0)) != 0 || (modifiers & (1u << 1)) != 0) flags |= NSEventModifierFlagCommand;
|
|
3593
|
+
if ((modifiers & (1u << 2)) != 0) flags |= NSEventModifierFlagControl;
|
|
3594
|
+
if ((modifiers & (1u << 3)) != 0) flags |= NSEventModifierFlagOption;
|
|
3595
|
+
if ((modifiers & (1u << 4)) != 0) flags |= NSEventModifierFlagShift;
|
|
3596
|
+
return flags;
|
|
3597
|
+
}
|
|
3598
|
+
|
|
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) {
|
|
3600
|
+
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3601
|
+
@autoreleasepool {
|
|
3602
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3603
|
+
if (!entry) return;
|
|
3604
|
+
NSMenu *menu = entry.menu;
|
|
3605
|
+
if (menu == nil) {
|
|
3606
|
+
menu = [[NSMenu alloc] initWithTitle:@""];
|
|
3607
|
+
entry.menu = menu;
|
|
3608
|
+
} else {
|
|
3609
|
+
[menu removeAllItems];
|
|
3610
|
+
}
|
|
3611
|
+
menu.autoenablesItems = NO;
|
|
3299
3612
|
for (size_t i = 0; i < count; i++) {
|
|
3300
3613
|
if (separators[i]) {
|
|
3301
3614
|
[menu addItem:[NSMenuItem separatorItem]];
|
|
@@ -3305,12 +3618,22 @@ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, const ui
|
|
|
3305
3618
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:label ?: @""
|
|
3306
3619
|
action:@selector(trayMenuItemClicked:)
|
|
3307
3620
|
keyEquivalent:@""];
|
|
3308
|
-
item.tag = (NSInteger)item_ids[i];
|
|
3621
|
+
item.tag = (NSInteger)(((uint64_t)status_item_id << 32) | item_ids[i]);
|
|
3309
3622
|
item.target = object;
|
|
3310
|
-
item.enabled = enabled_flags[i] != 0;
|
|
3623
|
+
item.enabled = enabled_flags[i] != 0 && (roles[i] == 0 || roles[i] == 4);
|
|
3624
|
+
if (details[i] && detail_lens[i] > 0) {
|
|
3625
|
+
NSString *detail = [[NSString alloc] initWithBytes:details[i] length:detail_lens[i] encoding:NSUTF8StringEncoding] ?: @"";
|
|
3626
|
+
if (detail.length > 0 && roles[i] != 0) item.title = [NSString stringWithFormat:@"%@ — %@", label ?: @"", detail];
|
|
3627
|
+
}
|
|
3628
|
+
if (keys[i] && key_lens[i] > 0) {
|
|
3629
|
+
NSString *key = [[NSString alloc] initWithBytes:keys[i] length:key_lens[i] encoding:NSUTF8StringEncoding] ?: @"";
|
|
3630
|
+
item.keyEquivalent = key.lowercaseString;
|
|
3631
|
+
item.keyEquivalentModifierMask = NativeSdkCefTrayModifiers(modifiers[i]);
|
|
3632
|
+
}
|
|
3311
3633
|
[menu addItem:item];
|
|
3312
3634
|
}
|
|
3313
|
-
|
|
3635
|
+
menu.delegate = object;
|
|
3636
|
+
if (entry.activationCommand.length == 0 && entry.alternateActivationCommand.length == 0) entry.item.menu = menu;
|
|
3314
3637
|
}
|
|
3315
3638
|
}
|
|
3316
3639
|
|
|
@@ -3327,30 +3650,41 @@ int native_sdk_appkit_set_window_content_min_size(native_sdk_appkit_host_t *host
|
|
|
3327
3650
|
return 1;
|
|
3328
3651
|
}
|
|
3329
3652
|
|
|
3330
|
-
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) {
|
|
3331
3654
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3332
3655
|
@autoreleasepool {
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
NSString *value =
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3656
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3657
|
+
if (!entry) return;
|
|
3658
|
+
NSString *value = title && title_len > 0 ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3659
|
+
NativeSdkCefApplyTrayPresentation(
|
|
3660
|
+
object,
|
|
3661
|
+
entry,
|
|
3662
|
+
value,
|
|
3663
|
+
entry.presentationWidth,
|
|
3664
|
+
entry.presentationTone,
|
|
3665
|
+
entry.presentationIconOpacity,
|
|
3666
|
+
entry.presentationMonospaced
|
|
3667
|
+
);
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
|
|
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) {
|
|
3672
|
+
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3673
|
+
@autoreleasepool {
|
|
3674
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3675
|
+
if (!entry) return;
|
|
3676
|
+
NSString *value = title ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3677
|
+
NativeSdkCefApplyTrayPresentation(object, entry, value, width, tone, icon_opacity, monospaced != 0);
|
|
3345
3678
|
}
|
|
3346
3679
|
}
|
|
3347
3680
|
|
|
3348
|
-
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) {
|
|
3349
3682
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
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];
|
|
3354
3688
|
}
|
|
3355
3689
|
|
|
3356
3690
|
/* Dock icon entry points, CEF engine: the Chromium shell is still a
|