@native-sdk/cli 0.9.0 → 0.9.2
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 +357 -33
- package/build.zig +234 -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 +170 -13
- 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 +18 -12
- package/skill-data/ts-core/SKILL.md +54 -21
- 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 +122 -6
- package/src/app_runner/ts_core_main.zig +9 -4
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/app_runner/window_placement.zig +63 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +3 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +2 -0
- package/src/embed/tests.zig +41 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +94 -4
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +17 -3
- package/src/platform/linux/gtk_host.c +243 -15
- package/src/platform/linux/gtk_host.h +5 -4
- package/src/platform/linux/root.zig +91 -11
- package/src/platform/macos/appkit_host.h +18 -11
- package/src/platform/macos/appkit_host.m +402 -128
- package/src/platform/macos/cef_host.mm +342 -122
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +231 -39
- package/src/platform/null_platform.zig +251 -54
- package/src/platform/null_platform_tests.zig +97 -4
- package/src/platform/root.zig +12 -0
- package/src/platform/types.zig +174 -35
- package/src/platform/windows/root.zig +42 -13
- package/src/platform/windows/webview2_host.cpp +72 -11
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +50 -0
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +13 -2
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +10 -0
- package/src/runtime/api.zig +14 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +16 -3
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +31 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/core.zig +28 -6
- package/src/runtime/effects.zig +1337 -49
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_image_tests.zig +91 -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/gpu_surface_events.zig +25 -2
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +7 -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 +110 -15
- package/src/runtime/session_tests.zig +192 -4
- package/src/runtime/shell_layout_tests.zig +12 -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 +142 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +330 -112
- package/src/runtime/ui_app_tests.zig +251 -25
- package/src/runtime/ui_app_window_tests.zig +74 -8
- package/src/runtime/validation.zig +20 -0
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +156 -18
- package/src/tooling/ts_core.zig +83 -0
- package/src/tooling/web_engine.zig +1 -1
- 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
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
#include <stdlib.h>
|
|
14
14
|
#include <string.h>
|
|
15
15
|
|
|
16
|
+
#include "../ios/apple_image_fit.h"
|
|
17
|
+
|
|
16
18
|
#include "include/cef_app.h"
|
|
17
19
|
#include "include/cef_browser.h"
|
|
18
20
|
#include "include/cef_client.h"
|
|
@@ -32,6 +34,7 @@
|
|
|
32
34
|
#endif
|
|
33
35
|
|
|
34
36
|
@class NativeSdkChromiumHost;
|
|
37
|
+
@class NativeSdkChromiumWindowDelegate;
|
|
35
38
|
|
|
36
39
|
@interface NativeSdkChromiumApplication : NSApplication <CefAppProtocol>
|
|
37
40
|
@property(nonatomic, assign) BOOL handlingSendEvent;
|
|
@@ -93,7 +96,12 @@ static int NativeSdkSetLaunchAtLogin(BOOL enabled) {
|
|
|
93
96
|
return succeeded ? NativeSdkLaunchAtLoginStatus() : -2;
|
|
94
97
|
}
|
|
95
98
|
static const char *NativeSdkCefBridgeScript();
|
|
99
|
+
static NSScreen *NativeSdkPrimaryScreen(void);
|
|
100
|
+
static NSScreen *NativeSdkScreenForFrame(NSRect frame);
|
|
101
|
+
static NSRect NativeSdkConstrainFrameToScreen(NSRect frame, NSScreen *screen);
|
|
96
102
|
static NSRect NativeSdkConstrainFrame(NSRect frame);
|
|
103
|
+
static NSRect NativeSdkCenterFrameOnScreen(NSRect frame, NSScreen *screen);
|
|
104
|
+
static void NativeSdkApplyHiddenInsetTitlebar(NSWindow *window, int titlebar_style, NativeSdkChromiumWindowDelegate *delegate);
|
|
97
105
|
static NSString *NativeSdkResolvedAssetRoot(NSString *rootPath);
|
|
98
106
|
static NSURL *NativeSdkAssetEntryFileURL(NSString *rootPath, NSString *entryPath);
|
|
99
107
|
static NSString *NativeSdkSafeAssetPath(NSURL *url, NSString *entryPath);
|
|
@@ -378,8 +386,42 @@ static NSString *NativeSdkCefFrameworkPath(void) {
|
|
|
378
386
|
return [devRoot stringByAppendingPathComponent:@"Release/Chromium Embedded Framework.framework"];
|
|
379
387
|
}
|
|
380
388
|
|
|
381
|
-
static
|
|
382
|
-
NSScreen
|
|
389
|
+
static NSScreen *NativeSdkPrimaryScreen(void) {
|
|
390
|
+
return [NSScreen screens].firstObject ?: [NSScreen mainScreen];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
static NSScreen *NativeSdkScreenForFrame(NSRect frame) {
|
|
394
|
+
NSArray<NSScreen *> *screens = [NSScreen screens];
|
|
395
|
+
NSScreen *bestScreen = nil;
|
|
396
|
+
CGFloat bestArea = 0;
|
|
397
|
+
for (NSScreen *screen in screens) {
|
|
398
|
+
NSRect intersection = NSIntersectionRect(frame, screen.visibleFrame);
|
|
399
|
+
CGFloat area = NSWidth(intersection) * NSHeight(intersection);
|
|
400
|
+
if (area > bestArea) {
|
|
401
|
+
bestArea = area;
|
|
402
|
+
bestScreen = screen;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (bestScreen) return bestScreen;
|
|
406
|
+
|
|
407
|
+
NSPoint center = NSMakePoint(NSMidX(frame), NSMidY(frame));
|
|
408
|
+
CGFloat bestDistance = CGFLOAT_MAX;
|
|
409
|
+
for (NSScreen *screen in screens) {
|
|
410
|
+
NSRect visible = screen.visibleFrame;
|
|
411
|
+
CGFloat nearestX = MIN(MAX(center.x, NSMinX(visible)), NSMaxX(visible));
|
|
412
|
+
CGFloat nearestY = MIN(MAX(center.y, NSMinY(visible)), NSMaxY(visible));
|
|
413
|
+
CGFloat dx = center.x - nearestX;
|
|
414
|
+
CGFloat dy = center.y - nearestY;
|
|
415
|
+
CGFloat distance = dx * dx + dy * dy;
|
|
416
|
+
if (distance < bestDistance) {
|
|
417
|
+
bestDistance = distance;
|
|
418
|
+
bestScreen = screen;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return bestScreen ?: [NSScreen mainScreen];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
static NSRect NativeSdkConstrainFrameToScreen(NSRect frame, NSScreen *screen) {
|
|
383
425
|
if (!screen) return frame;
|
|
384
426
|
NSRect visible = screen.visibleFrame;
|
|
385
427
|
if (frame.size.width > visible.size.width) frame.size.width = visible.size.width;
|
|
@@ -391,6 +433,19 @@ static NSRect NativeSdkConstrainFrame(NSRect frame) {
|
|
|
391
433
|
return frame;
|
|
392
434
|
}
|
|
393
435
|
|
|
436
|
+
static NSRect NativeSdkConstrainFrame(NSRect frame) {
|
|
437
|
+
return NativeSdkConstrainFrameToScreen(frame, NativeSdkScreenForFrame(frame));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
static NSRect NativeSdkCenterFrameOnScreen(NSRect frame, NSScreen *screen) {
|
|
441
|
+
frame = NativeSdkConstrainFrameToScreen(frame, screen);
|
|
442
|
+
if (!screen) return frame;
|
|
443
|
+
NSRect visible = screen.visibleFrame;
|
|
444
|
+
frame.origin.x = NSMidX(visible) - NSWidth(frame) / 2.0;
|
|
445
|
+
frame.origin.y = NSMidY(visible) - NSHeight(frame) / 2.0;
|
|
446
|
+
return NativeSdkConstrainFrameToScreen(frame, screen);
|
|
447
|
+
}
|
|
448
|
+
|
|
394
449
|
static const char *NativeSdkCefBridgeScript() {
|
|
395
450
|
return "(function(){"
|
|
396
451
|
"if(window.zero&&window.zero.invoke){return;}"
|
|
@@ -469,7 +524,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
469
524
|
"});"
|
|
470
525
|
"var os=Object.freeze({"
|
|
471
526
|
"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);},"
|
|
527
|
+
"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
528
|
"revealPath:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.revealPath',{path:ensureString(options.path,'path')});},"
|
|
474
529
|
"addRecentDocument:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.addRecentDocument',{path:ensureString(options.path,'path')});},"
|
|
475
530
|
"clearRecentDocuments:function(){return invoke('native-sdk.os.clearRecentDocuments',{});}"
|
|
@@ -552,6 +607,21 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
552
607
|
@property(nonatomic, assign) uint32_t modifiers;
|
|
553
608
|
@end
|
|
554
609
|
|
|
610
|
+
@interface NativeSdkChromiumStatusItemEntry : NSObject
|
|
611
|
+
@property(nonatomic, assign) uint32_t identifier;
|
|
612
|
+
@property(nonatomic, strong) NSStatusItem *item;
|
|
613
|
+
@property(nonatomic, strong) NSImage *baseImage;
|
|
614
|
+
@property(nonatomic, strong) NSMenu *menu;
|
|
615
|
+
@property(nonatomic, strong) NSString *presentationTitle;
|
|
616
|
+
@property(nonatomic, assign) double presentationWidth;
|
|
617
|
+
@property(nonatomic, assign) int presentationTone;
|
|
618
|
+
@property(nonatomic, assign) double presentationIconOpacity;
|
|
619
|
+
@property(nonatomic, assign) BOOL presentationMonospaced;
|
|
620
|
+
@property(nonatomic, strong) NSString *activationCommand;
|
|
621
|
+
@property(nonatomic, strong) NSString *alternateActivationCommand;
|
|
622
|
+
@property(nonatomic, strong) NSString *openCommand;
|
|
623
|
+
@end
|
|
624
|
+
|
|
555
625
|
/* Captures the selected item id of a context-menu popUp (NSMenuItem
|
|
556
626
|
* targets are weak; the presenter block keeps this alive). */
|
|
557
627
|
@interface NativeSdkChromiumContextMenuTarget : NSObject
|
|
@@ -568,7 +638,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
568
638
|
|
|
569
639
|
@end
|
|
570
640
|
|
|
571
|
-
@interface NativeSdkChromiumHost : NSObject <NSMenuDelegate>
|
|
641
|
+
@interface NativeSdkChromiumHost : NSObject <NSMenuDelegate, NSUserNotificationCenterDelegate>
|
|
572
642
|
@property(nonatomic, strong) NSWindow *window;
|
|
573
643
|
@property(nonatomic, strong) NSView *browserContainer;
|
|
574
644
|
@property(nonatomic, strong) NativeSdkChromiumWindowDelegate *delegate;
|
|
@@ -596,6 +666,10 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
596
666
|
@property(nonatomic, assign) uint64_t nextWebViewGeneration;
|
|
597
667
|
@property(nonatomic, strong) NSTimer *timer;
|
|
598
668
|
@property(nonatomic, strong) NSMutableDictionary<NSNumber *, NSTimer *> *appTimers;
|
|
669
|
+
/* Delivered notifications outlive this object, so userInfo carries only
|
|
670
|
+
* a per-process token; the command remains in these live-host maps. */
|
|
671
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *notificationActionCommands;
|
|
672
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *notificationActionTokensByIdentifier;
|
|
599
673
|
@property(nonatomic, strong) NSString *appName;
|
|
600
674
|
/* The human-facing app name (app.zon display_name, empty = appName):
|
|
601
675
|
* drives the application menu title and its About/Hide/Quit labels, the
|
|
@@ -618,16 +692,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
618
692
|
@property(nonatomic, assign) BOOL observesApplicationActivation;
|
|
619
693
|
@property(nonatomic, strong) id shortcutEventMonitor;
|
|
620
694
|
@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;
|
|
695
|
+
@property(nonatomic, strong) NSMutableDictionary<NSNumber *, NativeSdkChromiumStatusItemEntry *> *statusItems;
|
|
631
696
|
@property(nonatomic, assign) native_sdk_appkit_tray_callback_t trayCallback;
|
|
632
697
|
@property(nonatomic, assign) void *trayContext;
|
|
633
698
|
@property(nonatomic) CefRefPtr<NativeSdkCefClient> cefClient;
|
|
@@ -639,11 +704,11 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
639
704
|
@property(nonatomic, strong) NSArray<NSString *> *allowedNavigationOrigins;
|
|
640
705
|
@property(nonatomic, strong) NSArray<NSString *> *allowedExternalURLs;
|
|
641
706
|
@property(nonatomic, assign) NSInteger externalLinkAction;
|
|
642
|
-
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription title:(NSString *)title width:(double)width height:(double)height;
|
|
707
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription dockVisible:(BOOL)dockVisible title:(NSString *)title x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy titlebarStyle:(int)titlebarStyle;
|
|
643
708
|
- (void)configureApplication;
|
|
644
709
|
- (void)buildMenuBar;
|
|
645
710
|
- (NSMenuItem *)menuItem:(NSString *)title action:(SEL)action key:(NSString *)key modifiers:(NSEventModifierFlags)modifiers;
|
|
646
|
-
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
|
|
711
|
+
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain;
|
|
647
712
|
- (void)orderWindowForImplicitShow:(uint64_t)windowId;
|
|
648
713
|
- (void)focusWindowWithId:(uint64_t)windowId;
|
|
649
714
|
- (void)closeWindowWithId:(uint64_t)windowId;
|
|
@@ -663,6 +728,8 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
663
728
|
- (void)stopApplicationActivationObservers;
|
|
664
729
|
- (void)applicationDidBecomeActive:(NSNotification *)notification;
|
|
665
730
|
- (void)applicationDidResignActive:(NSNotification *)notification;
|
|
731
|
+
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification;
|
|
732
|
+
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification;
|
|
666
733
|
- (void)emitResize;
|
|
667
734
|
- (void)emitResizeForWindowId:(uint64_t)windowId;
|
|
668
735
|
- (void)emitWindowFrameForWindowId:(uint64_t)windowId open:(BOOL)open;
|
|
@@ -703,13 +770,18 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
703
770
|
- (void)emitShortcutWithId:(NSString *)identifier key:(NSString *)key modifiers:(uint32_t)modifiers event:(NSEvent *)event;
|
|
704
771
|
- (void)trayMenuItemClicked:(NSMenuItem *)menuItem;
|
|
705
772
|
- (void)menuWillOpen:(NSMenu *)menu;
|
|
706
|
-
- (
|
|
773
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForId:(uint32_t)identifier;
|
|
774
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForMenu:(NSMenu *)menu;
|
|
775
|
+
- (void)emitStatusCommand:(NSString *)command statusItemId:(uint32_t)statusItemId;
|
|
707
776
|
- (void)statusItemActivated:(id)sender;
|
|
708
777
|
@end
|
|
709
778
|
|
|
710
779
|
@implementation NativeSdkChromiumShortcut
|
|
711
780
|
@end
|
|
712
781
|
|
|
782
|
+
@implementation NativeSdkChromiumStatusItemEntry
|
|
783
|
+
@end
|
|
784
|
+
|
|
713
785
|
@implementation NativeSdkChromiumWindowDelegate
|
|
714
786
|
|
|
715
787
|
- (void)windowDidResize:(NSNotification *)notification {
|
|
@@ -835,13 +907,14 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
835
907
|
|
|
836
908
|
@implementation NativeSdkChromiumHost
|
|
837
909
|
|
|
838
|
-
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription title:(NSString *)title width:(double)width height:(double)height {
|
|
910
|
+
- (instancetype)initWithAppName:(NSString *)appName displayName:(NSString *)displayName version:(NSString *)version aboutDescription:(NSString *)aboutDescription dockVisible:(BOOL)dockVisible title:(NSString *)title x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy titlebarStyle:(int)titlebarStyle {
|
|
839
911
|
self = [super init];
|
|
840
912
|
if (!self) return nil;
|
|
841
913
|
|
|
842
914
|
[NativeSdkChromiumApplication sharedApplication];
|
|
915
|
+
NSApplicationActivationPolicy policy = dockVisible ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory;
|
|
916
|
+
[NSApp setActivationPolicy:policy];
|
|
843
917
|
ensureCefInitialized();
|
|
844
|
-
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
845
918
|
self.appName = appName.length > 0 ? appName : @"native-sdk";
|
|
846
919
|
self.displayName = displayName.length > 0 ? displayName : self.appName;
|
|
847
920
|
self.appVersion = version ?: @"";
|
|
@@ -866,6 +939,9 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
866
939
|
self.webviewGenerations = [[NSMutableDictionary alloc] init];
|
|
867
940
|
self.closingWebViewKeys = [[NSMutableSet alloc] init];
|
|
868
941
|
self.appTimers = [[NSMutableDictionary alloc] init];
|
|
942
|
+
self.notificationActionCommands = [[NSMutableDictionary alloc] init];
|
|
943
|
+
self.notificationActionTokensByIdentifier = [[NSMutableDictionary alloc] init];
|
|
944
|
+
self.statusItems = [[NSMutableDictionary alloc] init];
|
|
869
945
|
self.nextWebViewGeneration = 1;
|
|
870
946
|
self.cefClients = new std::map<uint64_t, CefRefPtr<NativeSdkCefClient>>();
|
|
871
947
|
self.browsers = new std::map<uint64_t, CefRefPtr<CefBrowser>>();
|
|
@@ -876,7 +952,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
876
952
|
self.externalLinkAction = 0;
|
|
877
953
|
self.shortcuts = @[];
|
|
878
954
|
|
|
879
|
-
[self createWindowWithId:1 title:(title.length > 0 ? title : self.appName) label:@"main" x:
|
|
955
|
+
[self createWindowWithId:1 title:(title.length > 0 ? title : self.appName) label:@"main" x:x y:y width:width height:height restoreFrame:restoreFrame initialPlacement:initialPlacement restorePolicy:restorePolicy resizable:YES titlebarStyle:titlebarStyle windowFlags:0 makeMain:YES];
|
|
880
956
|
self.didShutdown = NO;
|
|
881
957
|
self.pendingPreRunStop = NO;
|
|
882
958
|
self.observesApplicationActivation = NO;
|
|
@@ -981,6 +1057,8 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
981
1057
|
}
|
|
982
1058
|
|
|
983
1059
|
- (void)dealloc {
|
|
1060
|
+
NSUserNotificationCenter *notificationCenter = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
1061
|
+
if (notificationCenter.delegate == self) notificationCenter.delegate = nil;
|
|
984
1062
|
if (self.shortcutEventMonitor) {
|
|
985
1063
|
[NSEvent removeMonitor:self.shortcutEventMonitor];
|
|
986
1064
|
self.shortcutEventMonitor = nil;
|
|
@@ -991,11 +1069,17 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
991
1069
|
delete self.browsers;
|
|
992
1070
|
}
|
|
993
1071
|
|
|
994
|
-
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame resizable:(BOOL)resizable windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
|
|
1072
|
+
- (BOOL)createWindowWithId:(uint64_t)windowId title:(NSString *)title label:(NSString *)label x:(double)x y:(double)y width:(double)width height:(double)height restoreFrame:(BOOL)restoreFrame initialPlacement:(int)initialPlacement restorePolicy:(int)restorePolicy resizable:(BOOL)resizable titlebarStyle:(int)titlebarStyle windowFlags:(uint32_t)windowFlags makeMain:(BOOL)makeMain {
|
|
995
1073
|
NSNumber *key = @(windowId);
|
|
996
1074
|
if (self.windows[key]) return NO;
|
|
997
1075
|
|
|
998
|
-
|
|
1076
|
+
(void)restoreFrame; // Persistence opt-in; initialPlacement says whether a frame was found.
|
|
1077
|
+
const BOOL restoredPlacement = initialPlacement == 0;
|
|
1078
|
+
const BOOL centerOnPrimary = initialPlacement == 2 || (restoredPlacement && restorePolicy == 1);
|
|
1079
|
+
NSScreen *primaryScreen = NativeSdkPrimaryScreen();
|
|
1080
|
+
NSRect rect = centerOnPrimary
|
|
1081
|
+
? NativeSdkConstrainFrameToScreen(NSMakeRect(0, 0, width, height), primaryScreen)
|
|
1082
|
+
: NativeSdkConstrainFrame(NSMakeRect(x, y, width, height));
|
|
999
1083
|
NSWindowStyleMask styleMask = NSWindowStyleMaskTitled |
|
|
1000
1084
|
NSWindowStyleMaskClosable |
|
|
1001
1085
|
NSWindowStyleMaskMiniaturizable;
|
|
@@ -1020,13 +1104,33 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1020
1104
|
[window standardWindowButton:NSWindowZoomButton].enabled = NO;
|
|
1021
1105
|
}
|
|
1022
1106
|
[window setTitle:title.length > 0 ? title : @"native-sdk"];
|
|
1023
|
-
|
|
1024
|
-
|
|
1107
|
+
NativeSdkChromiumWindowDelegate *delegate = [[NativeSdkChromiumWindowDelegate alloc] init];
|
|
1108
|
+
delegate.host = self;
|
|
1109
|
+
delegate.windowId = windowId;
|
|
1110
|
+
window.delegate = delegate;
|
|
1111
|
+
// Install the final titlebar before converting persisted content
|
|
1112
|
+
// geometry back to an outer frame; the conversion must include the
|
|
1113
|
+
// actual chrome the window will keep.
|
|
1114
|
+
NativeSdkApplyHiddenInsetTitlebar(window, titlebarStyle, delegate);
|
|
1115
|
+
if (restoredPlacement) {
|
|
1116
|
+
NSRect restoredContentFrame = NSMakeRect(x, y, width, height);
|
|
1117
|
+
NSRect restoredWindowFrame = [window frameRectForContentRect:restoredContentFrame];
|
|
1118
|
+
restoredWindowFrame = restorePolicy == 1
|
|
1119
|
+
? NativeSdkCenterFrameOnScreen(restoredWindowFrame, primaryScreen)
|
|
1120
|
+
: NativeSdkConstrainFrame(restoredWindowFrame);
|
|
1121
|
+
[window setFrame:restoredWindowFrame display:NO];
|
|
1122
|
+
} else if (initialPlacement == 1) {
|
|
1123
|
+
// AppKit adds titlebar chrome to the authored content rectangle;
|
|
1124
|
+
// constrain the completed OUTER frame so no chrome escapes the
|
|
1125
|
+
// matching or nearest display's visible bounds.
|
|
1126
|
+
[window setFrame:NativeSdkConstrainFrame(window.frame) display:NO];
|
|
1127
|
+
} else if (centerOnPrimary) {
|
|
1128
|
+
[window setFrame:NativeSdkCenterFrameOnScreen(window.frame, primaryScreen) display:NO];
|
|
1025
1129
|
// Match the system-WebView host and Win32's default placement:
|
|
1026
1130
|
// secondary windows should reveal the window that opened them,
|
|
1027
1131
|
// not land directly on top of it.
|
|
1028
1132
|
NSWindow *referenceWindow = NSApp.keyWindow ?: self.window;
|
|
1029
|
-
if (!makeMain && referenceWindow) {
|
|
1133
|
+
if (initialPlacement == 2 && restorePolicy == 0 && !makeMain && referenceWindow) {
|
|
1030
1134
|
NSRect referenceFrame = referenceWindow.frame;
|
|
1031
1135
|
NSRect cascadedFrame = window.frame;
|
|
1032
1136
|
cascadedFrame.origin.x = NSMinX(referenceFrame) + 24.0;
|
|
@@ -1044,7 +1148,7 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1044
1148
|
}
|
|
1045
1149
|
}
|
|
1046
1150
|
|
|
1047
|
-
NSView *stackRoot = [[NSView alloc] initWithFrame:
|
|
1151
|
+
NSView *stackRoot = [[NSView alloc] initWithFrame:window.contentView.bounds];
|
|
1048
1152
|
stackRoot.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
1049
1153
|
window.contentView = stackRoot;
|
|
1050
1154
|
|
|
@@ -1054,10 +1158,6 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1054
1158
|
browserContainer.layer.zPosition = 0;
|
|
1055
1159
|
[stackRoot addSubview:browserContainer positioned:NSWindowAbove relativeTo:nil];
|
|
1056
1160
|
|
|
1057
|
-
NativeSdkChromiumWindowDelegate *delegate = [[NativeSdkChromiumWindowDelegate alloc] init];
|
|
1058
|
-
delegate.host = self;
|
|
1059
|
-
delegate.windowId = windowId;
|
|
1060
|
-
window.delegate = delegate;
|
|
1061
1161
|
CefRefPtr<NativeSdkCefClient> client = new NativeSdkCefClient(self, windowId);
|
|
1062
1162
|
|
|
1063
1163
|
self.windows[key] = window;
|
|
@@ -1349,6 +1449,38 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1349
1449
|
[self emitEvent:(native_sdk_appkit_event_t){ .kind = NATIVE_SDK_APPKIT_EVENT_APP_DEACTIVATED }];
|
|
1350
1450
|
}
|
|
1351
1451
|
|
|
1452
|
+
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
|
|
1453
|
+
(void)center;
|
|
1454
|
+
(void)notification;
|
|
1455
|
+
return YES;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
|
|
1459
|
+
NSInteger activation = notification.activationType;
|
|
1460
|
+
if (activation != NSUserNotificationActivationTypeActionButtonClicked) return;
|
|
1461
|
+
NSString *token = [notification.userInfo[@"native-sdk-action-token"] isKindOfClass:[NSString class]]
|
|
1462
|
+
? notification.userInfo[@"native-sdk-action-token"] : @"";
|
|
1463
|
+
NSString *command = token.length > 0 ? self.notificationActionCommands[token] : @"";
|
|
1464
|
+
if (command.length == 0) {
|
|
1465
|
+
[center removeDeliveredNotification:notification];
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
NSString *identifier = notification.identifier ?: @"";
|
|
1469
|
+
if (identifier.length > 0 &&
|
|
1470
|
+
[self.notificationActionTokensByIdentifier[identifier] isEqualToString:token]) {
|
|
1471
|
+
[self.notificationActionTokensByIdentifier removeObjectForKey:identifier];
|
|
1472
|
+
}
|
|
1473
|
+
[self.notificationActionCommands removeObjectForKey:token];
|
|
1474
|
+
const char *commandBytes = command.UTF8String ?: "";
|
|
1475
|
+
[self emitEvent:(native_sdk_appkit_event_t){
|
|
1476
|
+
.kind = NATIVE_SDK_APPKIT_EVENT_NOTIFICATION_COMMAND,
|
|
1477
|
+
.window_id = 1,
|
|
1478
|
+
.command_name = commandBytes,
|
|
1479
|
+
.command_name_len = [command lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
1480
|
+
}];
|
|
1481
|
+
[center removeDeliveredNotification:notification];
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1352
1484
|
- (void)emitResize {
|
|
1353
1485
|
[self emitResizeForWindowId:1];
|
|
1354
1486
|
}
|
|
@@ -1374,7 +1506,12 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1374
1506
|
- (void)emitWindowFrameForWindowId:(uint64_t)windowId open:(BOOL)open {
|
|
1375
1507
|
NSWindow *window = self.windows[@(windowId)] ?: self.window;
|
|
1376
1508
|
NSString *label = self.windowLabels[@(windowId)] ?: @"";
|
|
1377
|
-
|
|
1509
|
+
// The frame event's rect is the CONTENT rect in screen coordinates,
|
|
1510
|
+
// never window.frame: consumers treat these numbers as content
|
|
1511
|
+
// geometry (shell layout, the resize channel, window-state
|
|
1512
|
+
// persistence, and the initWithContentRect: round-trip) — see the
|
|
1513
|
+
// AppKit host's emitWindowFrameForWindowId:.
|
|
1514
|
+
NSRect frame = [window contentRectForFrameRect:window.frame];
|
|
1378
1515
|
[self emitEvent:(native_sdk_appkit_event_t){
|
|
1379
1516
|
.kind = NATIVE_SDK_APPKIT_EVENT_WINDOW_FRAME,
|
|
1380
1517
|
.window_id = windowId,
|
|
@@ -1989,33 +2126,51 @@ static const char *NativeSdkCefBridgeScript() {
|
|
|
1989
2126
|
}
|
|
1990
2127
|
|
|
1991
2128
|
- (void)trayMenuItemClicked:(NSMenuItem *)menuItem {
|
|
1992
|
-
if (self.trayCallback)
|
|
2129
|
+
if (self.trayCallback) {
|
|
2130
|
+
uint64_t packed = (uint64_t)(NSUInteger)menuItem.tag;
|
|
2131
|
+
self.trayCallback(self.trayContext, (uint32_t)(packed >> 32), (uint32_t)packed);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForId:(uint32_t)identifier {
|
|
2136
|
+
return self.statusItems[@(identifier)];
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
- (NativeSdkChromiumStatusItemEntry *)statusEntryForMenu:(NSMenu *)menu {
|
|
2140
|
+
for (NativeSdkChromiumStatusItemEntry *entry in self.statusItems.allValues) {
|
|
2141
|
+
if (entry.menu == menu) return entry;
|
|
2142
|
+
}
|
|
2143
|
+
return nil;
|
|
1993
2144
|
}
|
|
1994
2145
|
|
|
1995
|
-
- (void)emitStatusCommand:(NSString *)command {
|
|
2146
|
+
- (void)emitStatusCommand:(NSString *)command statusItemId:(uint32_t)statusItemId {
|
|
1996
2147
|
if (command.length == 0) return;
|
|
1997
2148
|
const char *bytes = command.UTF8String;
|
|
1998
2149
|
[self emitEvent:(native_sdk_appkit_event_t){
|
|
1999
2150
|
.kind = NATIVE_SDK_APPKIT_EVENT_TRAY_COMMAND,
|
|
2000
2151
|
.window_id = 1,
|
|
2152
|
+
.status_item_id = statusItemId,
|
|
2001
2153
|
.command_name = bytes,
|
|
2002
2154
|
.command_name_len = [command lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
2003
2155
|
}];
|
|
2004
2156
|
}
|
|
2005
2157
|
|
|
2006
2158
|
- (void)menuWillOpen:(NSMenu *)menu {
|
|
2007
|
-
|
|
2008
|
-
|
|
2159
|
+
NativeSdkChromiumStatusItemEntry *entry = [self statusEntryForMenu:menu];
|
|
2160
|
+
if (!entry) return;
|
|
2161
|
+
[self emitStatusCommand:entry.openCommand statusItemId:entry.identifier];
|
|
2009
2162
|
}
|
|
2010
2163
|
|
|
2011
2164
|
- (void)statusItemActivated:(id)sender {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2165
|
+
NSStatusBarButton *button = [sender isKindOfClass:[NSStatusBarButton class]] ? sender : nil;
|
|
2166
|
+
NativeSdkChromiumStatusItemEntry *entry = button ? [self statusEntryForId:(uint32_t)button.tag] : nil;
|
|
2167
|
+
if (!entry) return;
|
|
2168
|
+
if ((NSEvent.modifierFlags & NSEventModifierFlagOption) != 0 && entry.alternateActivationCommand.length > 0) {
|
|
2169
|
+
[self emitStatusCommand:entry.alternateActivationCommand statusItemId:entry.identifier];
|
|
2015
2170
|
return;
|
|
2016
2171
|
}
|
|
2017
|
-
[self emitStatusCommand:
|
|
2018
|
-
if (
|
|
2172
|
+
[self emitStatusCommand:entry.activationCommand statusItemId:entry.identifier];
|
|
2173
|
+
if (entry.menu) [entry.item popUpStatusItemMenu:entry.menu];
|
|
2019
2174
|
}
|
|
2020
2175
|
|
|
2021
2176
|
@end
|
|
@@ -2256,7 +2411,7 @@ static void NativeSdkApplyOverlayWindowFlags(NativeSdkChromiumHost *host, uint64
|
|
|
2256
2411
|
}
|
|
2257
2412
|
}
|
|
2258
2413
|
|
|
2259
|
-
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) {
|
|
2414
|
+
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, int dock_visible, 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 initial_placement, int restore_policy, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
2260
2415
|
@autoreleasepool {
|
|
2261
2416
|
// A windowed CEF child cannot paint transparent pixels into its
|
|
2262
2417
|
// parent NSWindow. Refuse instead of accepting a flag that leaves
|
|
@@ -2283,14 +2438,10 @@ native_sdk_appkit_host_t *native_sdk_appkit_create(const char *app_name, size_t
|
|
|
2283
2438
|
NSString *versionString = [[NSString alloc] initWithBytes:version length:version_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
2284
2439
|
NSString *aboutDescriptionString = [[NSString alloc] initWithBytes:about_description length:about_description_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
2285
2440
|
NSString *titleString = [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] ?: appNameString;
|
|
2286
|
-
NativeSdkChromiumHost *host = [[NativeSdkChromiumHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString title:titleString width:width height:height];
|
|
2287
|
-
if (restore_frame) {
|
|
2288
|
-
[host.window setFrame:NativeSdkConstrainFrame(NSMakeRect(x, y, width, height)) display:NO];
|
|
2289
|
-
}
|
|
2441
|
+
NativeSdkChromiumHost *host = [[NativeSdkChromiumHost alloc] initWithAppName:appNameString displayName:displayNameString version:versionString aboutDescription:aboutDescriptionString dockVisible:(dock_visible != 0) title:titleString x:x y:y width:width height:height restoreFrame:(restore_frame != 0) initialPlacement:initial_placement restorePolicy:restore_policy titlebarStyle:titlebar_style];
|
|
2290
2442
|
if (!resizable) {
|
|
2291
2443
|
host.window.styleMask &= ~NSWindowStyleMaskResizable;
|
|
2292
2444
|
}
|
|
2293
|
-
NativeSdkApplyHiddenInsetTitlebar(host.window, titlebar_style, host.delegates[@1]);
|
|
2294
2445
|
NativeSdkApplyOverlayWindowFlags(host, 1, window_flags);
|
|
2295
2446
|
if (show_policy == 2) [host.policyHiddenWindows addObject:@1];
|
|
2296
2447
|
return (__bridge_retained native_sdk_appkit_host_t *)host;
|
|
@@ -2538,13 +2689,12 @@ void native_sdk_appkit_set_shortcuts(native_sdk_appkit_host_t *host, const char
|
|
|
2538
2689
|
[object setShortcutsWithIds:ids idLengths:id_lens keys:keys keyLengths:key_lens modifiers:modifiers count:count];
|
|
2539
2690
|
}
|
|
2540
2691
|
|
|
2541
|
-
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) {
|
|
2692
|
+
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 initial_placement, int restore_policy, int resizable, int titlebar_style, int show_policy, uint32_t window_flags) {
|
|
2542
2693
|
if ((window_flags & (1u << 0)) != 0) return 0;
|
|
2543
2694
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
2544
2695
|
NSString *titleString = window_title ? [[NSString alloc] initWithBytes:window_title length:window_title_len encoding:NSUTF8StringEncoding] : @"native-sdk";
|
|
2545
2696
|
NSString *labelString = window_label ? [[NSString alloc] initWithBytes:window_label length:window_label_len encoding:NSUTF8StringEncoding] : @"";
|
|
2546
|
-
if (![object createWindowWithId:window_id title:titleString ?: @"native-sdk" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) resizable:(resizable != 0) windowFlags:window_flags makeMain:NO]) return 0;
|
|
2547
|
-
NativeSdkApplyHiddenInsetTitlebar(object.windows[@(window_id)], titlebar_style, object.delegates[@(window_id)]);
|
|
2697
|
+
if (![object createWindowWithId:window_id title:titleString ?: @"native-sdk" label:labelString ?: @"" x:x y:y width:width height:height restoreFrame:(restore_frame != 0) initialPlacement:initial_placement restorePolicy:restore_policy resizable:(resizable != 0) titlebarStyle:titlebar_style windowFlags:window_flags makeMain:NO]) return 0;
|
|
2548
2698
|
// Apply chrome and overlay presentation while still hidden, then
|
|
2549
2699
|
// reveal once so a secondary window cannot flash its default frame.
|
|
2550
2700
|
if (show_policy == 2) {
|
|
@@ -3048,25 +3198,45 @@ int native_sdk_appkit_measure_text_advances(uint64_t font_id, double size, const
|
|
|
3048
3198
|
* system SVG rasterizer, with no host state, so both engines decode
|
|
3049
3199
|
* identically. See appkit_host.h for the pixel-format and return-value
|
|
3050
3200
|
* contract. */
|
|
3051
|
-
int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8_t *pixels, size_t pixels_len, size_t *out_width, size_t *out_height) {
|
|
3201
|
+
int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8_t *pixels, size_t pixels_len, size_t max_pixels, size_t *out_width, size_t *out_height) {
|
|
3052
3202
|
if (out_width) *out_width = 0;
|
|
3053
3203
|
if (out_height) *out_height = 0;
|
|
3054
|
-
if (!bytes || bytes_len == 0 || !pixels) return 0;
|
|
3204
|
+
if (!bytes || bytes_len == 0 || !pixels || max_pixels == 0) return 0;
|
|
3055
3205
|
@autoreleasepool {
|
|
3056
3206
|
NSData *data = [NSData dataWithBytesNoCopy:(void *)bytes length:bytes_len freeWhenDone:NO];
|
|
3057
3207
|
CGImageRef image = NULL;
|
|
3058
3208
|
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
|
|
3059
3209
|
if (source) {
|
|
3060
|
-
|
|
3210
|
+
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
|
|
3211
|
+
int64_t source_width_value = 0;
|
|
3212
|
+
int64_t source_height_value = 0;
|
|
3213
|
+
if (properties) {
|
|
3214
|
+
CFNumberRef width_value = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
|
|
3215
|
+
CFNumberRef height_value = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
|
|
3216
|
+
if (width_value) CFNumberGetValue(width_value, kCFNumberSInt64Type, &source_width_value);
|
|
3217
|
+
if (height_value) CFNumberGetValue(height_value, kCFNumberSInt64Type, &source_height_value);
|
|
3218
|
+
CFRelease(properties);
|
|
3219
|
+
}
|
|
3220
|
+
size_t source_width = source_width_value > 0 ? (size_t)source_width_value : 0;
|
|
3221
|
+
size_t source_height = source_height_value > 0 ? (size_t)source_height_value : 0;
|
|
3222
|
+
if (source_width > 0 && source_height > 0) {
|
|
3223
|
+
const size_t max_dimension = native_sdk_apple_image_thumbnail_max_dimension(source_width, source_height, max_pixels);
|
|
3224
|
+
NSDictionary *thumbnail_options = @{
|
|
3225
|
+
(NSString *)kCGImageSourceCreateThumbnailFromImageAlways: @YES,
|
|
3226
|
+
(NSString *)kCGImageSourceThumbnailMaxPixelSize: @(max_dimension),
|
|
3227
|
+
(NSString *)kCGImageSourceCreateThumbnailWithTransform: @YES,
|
|
3228
|
+
};
|
|
3229
|
+
image = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef)thumbnail_options);
|
|
3230
|
+
}
|
|
3061
3231
|
CFRelease(source);
|
|
3062
3232
|
}
|
|
3063
3233
|
if (!image) {
|
|
3064
3234
|
NSImage *system_image = [[NSImage alloc] initWithData:data];
|
|
3065
3235
|
NSSize size = system_image ? system_image.size : NSZeroSize;
|
|
3066
|
-
if (size.width > 0 && size.height > 0 && size.width
|
|
3236
|
+
if (size.width > 0 && size.height > 0 && isfinite(size.width) && isfinite(size.height)) {
|
|
3067
3237
|
// Bound SVG rasterization before NSImage materializes the
|
|
3068
3238
|
// screen-scale representation; see the AppKit mirror.
|
|
3069
|
-
const CGFloat max_raster_points =
|
|
3239
|
+
const CGFloat max_raster_points = sqrt((CGFloat)max_pixels) / 2.0;
|
|
3070
3240
|
const CGFloat raster_scale = MIN(1.0, MIN(max_raster_points / size.width, max_raster_points / size.height));
|
|
3071
3241
|
NSRect proposed = NSMakeRect(0, 0, size.width * raster_scale, size.height * raster_scale);
|
|
3072
3242
|
CGImageRef rendered = [system_image CGImageForProposedRect:&proposed context:nil hints:nil];
|
|
@@ -3077,14 +3247,14 @@ int native_sdk_appkit_decode_image(const uint8_t *bytes, size_t bytes_len, uint8
|
|
|
3077
3247
|
|
|
3078
3248
|
size_t width = CGImageGetWidth(image);
|
|
3079
3249
|
size_t height = CGImageGetHeight(image);
|
|
3080
|
-
if (width == 0 || height == 0 || width >
|
|
3250
|
+
if (width == 0 || height == 0 || width > NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION || height > NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION) {
|
|
3081
3251
|
CGImageRelease(image);
|
|
3082
3252
|
return 0;
|
|
3083
3253
|
}
|
|
3084
3254
|
if (out_width) *out_width = width;
|
|
3085
3255
|
if (out_height) *out_height = height;
|
|
3086
3256
|
size_t byte_len = width * height * 4;
|
|
3087
|
-
if (byte_len / 4 / height != width || pixels_len < byte_len) {
|
|
3257
|
+
if (width > max_pixels / height || byte_len / 4 / height != width || pixels_len < byte_len) {
|
|
3088
3258
|
CGImageRelease(image);
|
|
3089
3259
|
return -1;
|
|
3090
3260
|
}
|
|
@@ -3163,17 +3333,42 @@ int native_sdk_appkit_clipboard_write_data(native_sdk_appkit_host_t *host, const
|
|
|
3163
3333
|
return [pasteboard setData:data forType:type] ? 1 : 0;
|
|
3164
3334
|
}
|
|
3165
3335
|
|
|
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
|
-
(
|
|
3336
|
+
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) {
|
|
3337
|
+
if (!host || ((action_label_len == 0) != (action_command_len == 0))) return 0;
|
|
3338
|
+
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3168
3339
|
NSString *titleString = title ? [[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] : @"";
|
|
3169
3340
|
if (titleString.length == 0) return 0;
|
|
3170
3341
|
NSString *subtitleString = subtitle ? [[NSString alloc] initWithBytes:subtitle length:subtitle_len encoding:NSUTF8StringEncoding] : @"";
|
|
3171
3342
|
NSString *bodyString = body ? [[NSString alloc] initWithBytes:body length:body_len encoding:NSUTF8StringEncoding] : @"";
|
|
3343
|
+
NSString *identifier = notification_id ? [[NSString alloc] initWithBytes:notification_id length:notification_id_len encoding:NSUTF8StringEncoding] : @"";
|
|
3344
|
+
NSString *actionLabel = action_label ? [[NSString alloc] initWithBytes:action_label length:action_label_len encoding:NSUTF8StringEncoding] : @"";
|
|
3345
|
+
NSString *actionCommand = action_command ? [[NSString alloc] initWithBytes:action_command length:action_command_len encoding:NSUTF8StringEncoding] : @"";
|
|
3346
|
+
if (identifier.length > 0) {
|
|
3347
|
+
NSString *oldToken = object.notificationActionTokensByIdentifier[identifier];
|
|
3348
|
+
if (oldToken.length > 0) [object.notificationActionCommands removeObjectForKey:oldToken];
|
|
3349
|
+
[object.notificationActionTokensByIdentifier removeObjectForKey:identifier];
|
|
3350
|
+
}
|
|
3172
3351
|
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
|
3173
3352
|
notification.title = titleString;
|
|
3174
3353
|
if (subtitleString.length > 0) notification.subtitle = subtitleString;
|
|
3175
3354
|
if (bodyString.length > 0) notification.informativeText = bodyString;
|
|
3176
|
-
|
|
3355
|
+
if (identifier.length > 0) notification.identifier = identifier;
|
|
3356
|
+
if (actionCommand.length > 0) {
|
|
3357
|
+
NSString *actionToken = [NSUUID UUID].UUIDString;
|
|
3358
|
+
object.notificationActionCommands[actionToken] = actionCommand;
|
|
3359
|
+
if (identifier.length > 0) object.notificationActionTokensByIdentifier[identifier] = actionToken;
|
|
3360
|
+
notification.hasActionButton = YES;
|
|
3361
|
+
notification.actionButtonTitle = actionLabel;
|
|
3362
|
+
notification.userInfo = @{ @"native-sdk-action-token": actionToken };
|
|
3363
|
+
}
|
|
3364
|
+
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
3365
|
+
center.delegate = object;
|
|
3366
|
+
if (identifier.length > 0) {
|
|
3367
|
+
for (NSUserNotification *delivered in center.deliveredNotifications) {
|
|
3368
|
+
if ([delivered.identifier isEqualToString:identifier]) [center removeDeliveredNotification:delivered];
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
[center deliverNotification:notification];
|
|
3177
3372
|
return 1;
|
|
3178
3373
|
}
|
|
3179
3374
|
|
|
@@ -3409,63 +3604,84 @@ static NSImage *NativeSdkCefTrayImageWithOpacity(NSImage *source, double opacity
|
|
|
3409
3604
|
return image;
|
|
3410
3605
|
}
|
|
3411
3606
|
|
|
3412
|
-
static void NativeSdkCefApplyTrayPresentation(NativeSdkChromiumHost *object, NSString *requestedTitle, double width, int tone, double iconOpacity, BOOL monospaced) {
|
|
3413
|
-
if (!
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3607
|
+
static void NativeSdkCefApplyTrayPresentation(NativeSdkChromiumHost *object, NativeSdkChromiumStatusItemEntry *entry, NSString *requestedTitle, double width, int tone, double iconOpacity, BOOL monospaced) {
|
|
3608
|
+
if (!entry.item) return;
|
|
3609
|
+
entry.presentationTitle = requestedTitle ?: @"";
|
|
3610
|
+
entry.presentationWidth = width;
|
|
3611
|
+
entry.presentationTone = tone;
|
|
3612
|
+
entry.presentationIconOpacity = iconOpacity;
|
|
3613
|
+
entry.presentationMonospaced = monospaced;
|
|
3418
3614
|
NSString *title = requestedTitle ?: @"";
|
|
3419
|
-
if (!
|
|
3615
|
+
if (!entry.baseImage && title.length == 0) title = object.appName.length > 0 ? [object.appName substringToIndex:MIN(1, object.appName.length)] : @"Z";
|
|
3420
3616
|
NSFont *font = monospaced ? [NSFont monospacedDigitSystemFontOfSize:11 weight:NSFontWeightRegular] : [NSFont systemFontOfSize:11];
|
|
3421
3617
|
if (tone == 0) {
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3618
|
+
entry.item.button.title = title;
|
|
3619
|
+
entry.item.button.font = font;
|
|
3620
|
+
entry.item.button.contentTintColor = nil;
|
|
3425
3621
|
} else {
|
|
3426
3622
|
NSColor *color = tone == 1 ? NSColor.systemOrangeColor : NSColor.systemRedColor;
|
|
3427
|
-
|
|
3428
|
-
|
|
3623
|
+
entry.item.button.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:@{ NSForegroundColorAttributeName: color, NSFontAttributeName: font }];
|
|
3624
|
+
entry.item.button.contentTintColor = color;
|
|
3625
|
+
}
|
|
3626
|
+
entry.item.button.image = NativeSdkCefTrayImageWithOpacity(entry.baseImage, iconOpacity);
|
|
3627
|
+
entry.item.length = width > 0 ? width : (requestedTitle.length > 0 ? NSVariableStatusItemLength : NSSquareStatusItemLength);
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3630
|
+
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) {
|
|
3631
|
+
entry.baseImage = nil;
|
|
3632
|
+
if (icon_path && icon_path_len > 0) {
|
|
3633
|
+
NSString *path = [[NSString alloc] initWithBytes:icon_path length:icon_path_len encoding:NSUTF8StringEncoding];
|
|
3634
|
+
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
3635
|
+
if (image) {
|
|
3636
|
+
image.template = YES;
|
|
3637
|
+
image.size = NSMakeSize(18, 18);
|
|
3638
|
+
entry.baseImage = image;
|
|
3639
|
+
}
|
|
3429
3640
|
}
|
|
3430
|
-
|
|
3431
|
-
|
|
3641
|
+
entry.item.button.toolTip = tooltip && tooltip_len > 0 ? ([[NSString alloc] initWithBytes:tooltip length:tooltip_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3642
|
+
entry.activationCommand = activation_command ? ([[NSString alloc] initWithBytes:activation_command length:activation_command_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3643
|
+
entry.alternateActivationCommand = alternate_activation_command ? ([[NSString alloc] initWithBytes:alternate_activation_command length:alternate_activation_command_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3644
|
+
entry.openCommand = open_command ? ([[NSString alloc] initWithBytes:open_command length:open_command_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3645
|
+
NSStatusBarButton *button = entry.item.button;
|
|
3646
|
+
button.tag = (NSInteger)entry.identifier;
|
|
3647
|
+
button.target = object;
|
|
3648
|
+
button.action = (entry.activationCommand.length > 0 || entry.alternateActivationCommand.length > 0) ? @selector(statusItemActivated:) : NULL;
|
|
3649
|
+
if (button.action) [button sendActionOn:NSEventMaskLeftMouseUp];
|
|
3650
|
+
entry.item.visible = visible != 0;
|
|
3432
3651
|
}
|
|
3433
3652
|
|
|
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) {
|
|
3653
|
+
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
3654
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3436
3655
|
@autoreleasepool {
|
|
3437
|
-
|
|
3438
|
-
|
|
3656
|
+
NSNumber *key = @(status_item_id);
|
|
3657
|
+
NativeSdkChromiumStatusItemEntry *entry = object.statusItems[key];
|
|
3658
|
+
if (entry) {
|
|
3659
|
+
[[NSStatusBar systemStatusBar] removeStatusItem:entry.item];
|
|
3660
|
+
} else {
|
|
3661
|
+
entry = [[NativeSdkChromiumStatusItemEntry alloc] init];
|
|
3662
|
+
entry.identifier = status_item_id;
|
|
3663
|
+
object.statusItems[key] = entry;
|
|
3439
3664
|
}
|
|
3440
|
-
|
|
3665
|
+
entry.menu = nil;
|
|
3441
3666
|
// A titled menu-bar extra needs variable width; icon-only status
|
|
3442
3667
|
// items keep the classic square well.
|
|
3443
3668
|
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
|
-
}
|
|
3669
|
+
entry.item = [[NSStatusBar systemStatusBar] statusItemWithLength:hasTitle ? NSVariableStatusItemLength : NSSquareStatusItemLength];
|
|
3456
3670
|
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,
|
|
3671
|
+
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);
|
|
3672
|
+
NativeSdkCefApplyTrayPresentation(object, entry, titleString, width, tone, icon_opacity, monospaced != 0);
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
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) {
|
|
3677
|
+
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3678
|
+
@autoreleasepool {
|
|
3679
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3680
|
+
if (!entry) return;
|
|
3681
|
+
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);
|
|
3682
|
+
NativeSdkCefApplyTrayPresentation(object, entry, entry.presentationTitle, entry.presentationWidth, entry.presentationTone, entry.presentationIconOpacity, entry.presentationMonospaced);
|
|
3683
|
+
if (entry.activationCommand.length == 0 && entry.alternateActivationCommand.length == 0) entry.item.menu = entry.menu;
|
|
3684
|
+
else entry.item.menu = nil;
|
|
3469
3685
|
}
|
|
3470
3686
|
}
|
|
3471
3687
|
|
|
@@ -3478,14 +3694,15 @@ static NSEventModifierFlags NativeSdkCefTrayModifiers(uint32_t modifiers) {
|
|
|
3478
3694
|
return flags;
|
|
3479
3695
|
}
|
|
3480
3696
|
|
|
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) {
|
|
3697
|
+
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
3698
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3483
3699
|
@autoreleasepool {
|
|
3484
|
-
|
|
3485
|
-
|
|
3700
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3701
|
+
if (!entry) return;
|
|
3702
|
+
NSMenu *menu = entry.menu;
|
|
3486
3703
|
if (menu == nil) {
|
|
3487
3704
|
menu = [[NSMenu alloc] initWithTitle:@""];
|
|
3488
|
-
|
|
3705
|
+
entry.menu = menu;
|
|
3489
3706
|
} else {
|
|
3490
3707
|
[menu removeAllItems];
|
|
3491
3708
|
}
|
|
@@ -3499,7 +3716,7 @@ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, const ui
|
|
|
3499
3716
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:label ?: @""
|
|
3500
3717
|
action:@selector(trayMenuItemClicked:)
|
|
3501
3718
|
keyEquivalent:@""];
|
|
3502
|
-
item.tag = (NSInteger)item_ids[i];
|
|
3719
|
+
item.tag = (NSInteger)(((uint64_t)status_item_id << 32) | item_ids[i]);
|
|
3503
3720
|
item.target = object;
|
|
3504
3721
|
item.enabled = enabled_flags[i] != 0 && (roles[i] == 0 || roles[i] == 4);
|
|
3505
3722
|
if (details[i] && detail_lens[i] > 0) {
|
|
@@ -3514,7 +3731,7 @@ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, const ui
|
|
|
3514
3731
|
[menu addItem:item];
|
|
3515
3732
|
}
|
|
3516
3733
|
menu.delegate = object;
|
|
3517
|
-
if (
|
|
3734
|
+
if (entry.activationCommand.length == 0 && entry.alternateActivationCommand.length == 0) entry.item.menu = menu;
|
|
3518
3735
|
}
|
|
3519
3736
|
}
|
|
3520
3737
|
|
|
@@ -3531,38 +3748,41 @@ int native_sdk_appkit_set_window_content_min_size(native_sdk_appkit_host_t *host
|
|
|
3531
3748
|
return 1;
|
|
3532
3749
|
}
|
|
3533
3750
|
|
|
3534
|
-
void native_sdk_appkit_update_tray_title(native_sdk_appkit_host_t *host, const char *title, size_t title_len) {
|
|
3751
|
+
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
3752
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3536
3753
|
@autoreleasepool {
|
|
3537
|
-
|
|
3754
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3755
|
+
if (!entry) return;
|
|
3538
3756
|
NSString *value = title && title_len > 0 ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3539
3757
|
NativeSdkCefApplyTrayPresentation(
|
|
3540
3758
|
object,
|
|
3759
|
+
entry,
|
|
3541
3760
|
value,
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3761
|
+
entry.presentationWidth,
|
|
3762
|
+
entry.presentationTone,
|
|
3763
|
+
entry.presentationIconOpacity,
|
|
3764
|
+
entry.presentationMonospaced
|
|
3546
3765
|
);
|
|
3547
3766
|
}
|
|
3548
3767
|
}
|
|
3549
3768
|
|
|
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) {
|
|
3769
|
+
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
3770
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3552
3771
|
@autoreleasepool {
|
|
3772
|
+
NativeSdkChromiumStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
3773
|
+
if (!entry) return;
|
|
3553
3774
|
NSString *value = title ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
3554
|
-
NativeSdkCefApplyTrayPresentation(object, value, width, tone, icon_opacity, monospaced != 0);
|
|
3775
|
+
NativeSdkCefApplyTrayPresentation(object, entry, value, width, tone, icon_opacity, monospaced != 0);
|
|
3555
3776
|
}
|
|
3556
3777
|
}
|
|
3557
3778
|
|
|
3558
|
-
void native_sdk_appkit_remove_tray(native_sdk_appkit_host_t *host) {
|
|
3779
|
+
void native_sdk_appkit_remove_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id) {
|
|
3559
3780
|
NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
}
|
|
3781
|
+
NSNumber *key = @(status_item_id);
|
|
3782
|
+
NativeSdkChromiumStatusItemEntry *entry = object.statusItems[key];
|
|
3783
|
+
if (!entry) return;
|
|
3784
|
+
[[NSStatusBar systemStatusBar] removeStatusItem:entry.item];
|
|
3785
|
+
[object.statusItems removeObjectForKey:key];
|
|
3566
3786
|
}
|
|
3567
3787
|
|
|
3568
3788
|
/* Dock icon entry points, CEF engine: the Chromium shell is still a
|