@native-sdk/cli 0.9.4 → 0.10.0
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/README.md +3 -3
- package/build/app.zig +75 -57
- package/build/ts_run.mjs +1 -1
- package/build.zig +20 -2
- package/package.json +11 -10
- package/packages/core/package-lock.json +12 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_command.mjs +1 -1
- package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/events.d.ts +33 -4
- package/packages/core/sdk/events.ts +45 -6
- package/packages/core/src/checker.ts +103 -8
- package/packages/core/src/modules.ts +6 -2
- package/packages/core/src/sqlite_cli.ts +22 -2
- package/packages/core/src/typed_ast.ts +4 -2
- package/packages/core/src/types.ts +8 -8
- package/schemas/app.schema.json +446 -0
- package/skill-data/core/SKILL.md +53 -15
- package/skill-data/core/references/project-anatomy.md +6 -6
- package/skill-data/native-ui/SKILL.md +26 -5
- package/skill-data/ts-core/SKILL.md +6 -6
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/skills/native-sdk/SKILL.md +2 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/snapshot.zig +91 -3
- package/src/platform/macos/appkit_host.h +66 -2
- package/src/platform/macos/appkit_host.m +735 -24
- package/src/platform/macos/cef_host.mm +208 -9
- package/src/platform/macos/root.zig +205 -3
- package/src/platform/null_platform.zig +50 -1
- package/src/platform/null_platform_tests.zig +53 -0
- package/src/platform/root.zig +12 -0
- package/src/platform/types.zig +73 -0
- package/src/platform/windows/root.zig +88 -15
- package/src/primitives/app_manifest/tests.zig +19 -0
- package/src/primitives/app_manifest/validation.zig +14 -2
- package/src/primitives/canvas/font_ttf.zig +24 -0
- package/src/primitives/canvas/gpu.zig +5 -0
- package/src/primitives/canvas/reference.zig +41 -16
- package/src/primitives/canvas/reference_tests.zig +63 -0
- package/src/primitives/canvas/render_tests.zig +1 -1
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/serialization.zig +1 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_layout.zig +84 -15
- package/src/primitives/canvas/text_layout_hash.zig +3 -1
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_metrics.zig +28 -1
- package/src/primitives/canvas/text_tests.zig +61 -6
- package/src/primitives/canvas/ui.zig +9 -0
- package/src/primitives/canvas/ui_markup.zig +29 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
- package/src/primitives/canvas/ui_markup_contract.zig +7 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
- package/src/primitives/canvas/ui_markup_tests.zig +6 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
- package/src/primitives/canvas/ui_schema.zig +9 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +4 -2
- package/src/primitives/canvas/widget_render.zig +13 -2
- package/src/primitives/canvas/widget_render_controls.zig +1 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
- package/src/root.zig +6 -0
- package/src/runtime/automation_snapshot.zig +3 -0
- package/src/runtime/canvas_fonts.zig +87 -0
- package/src/runtime/core.zig +1 -0
- package/src/runtime/flow.zig +8 -1
- package/src/runtime/native_command_event_tests.zig +58 -0
- package/src/runtime/state.zig +14 -0
- package/src/runtime/system_services.zig +62 -0
- package/src/runtime/ts_ui_app.zig +161 -33
- package/src/runtime/ui_app.zig +33 -1
- package/src/runtime/ui_app_tests.zig +63 -0
- package/src/runtime/validation.zig +87 -1
- package/src/tooling/android.zig +5 -4
- package/src/tooling/buildgraph.zig +24 -8
- package/src/tooling/db.zig +1 -1
- package/src/tooling/doctor.zig +1 -1
- package/src/tooling/ios.zig +5 -4
- package/src/tooling/json_to_zon.zig +136 -0
- package/src/tooling/manifest.zig +199 -35
- package/src/tooling/package.zig +33 -0
- package/src/tooling/raw_manifest.zig +11 -0
- package/src/tooling/root.zig +2 -0
- package/src/tooling/templates.zig +210 -116
- package/src/tooling/ts_core.zig +11 -7
- package/src/tooling/update.zig +576 -0
- package/src/tooling/verbs.zig +7 -6
- package/src/tooling/web_engine.zig +17 -1
- package/src/updater/c_api.zig +123 -0
- package/src/updater/feed.zig +215 -0
- package/src/updater/root.zig +10 -0
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
#include <stdlib.h>
|
|
26
26
|
#include <string.h>
|
|
27
27
|
#include <time.h>
|
|
28
|
+
#include <unistd.h>
|
|
28
29
|
|
|
29
30
|
#include "../ios/apple_image_fit.h"
|
|
30
31
|
|
|
@@ -158,6 +159,17 @@ static NSString *NativeSdkStringFromTextInput(id value) {
|
|
|
158
159
|
return [value description] ?: @"";
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
/* The authored runner identity is the right fallback for unbundled dev
|
|
163
|
+
* executables. Once the process is inside a packaged .app, Info.plist is the
|
|
164
|
+
* installed identity and must win: Finder/package tooling can legitimately
|
|
165
|
+
* produce a bundle whose identifier differs from stale generated runner
|
|
166
|
+
* source, and update feeds are bound to the bundle actually being replaced. */
|
|
167
|
+
static NSString *NativeSdkPackagedBundleIdentifier(void) {
|
|
168
|
+
NSBundle *bundle = NSBundle.mainBundle;
|
|
169
|
+
if (![[bundle.bundlePath pathExtension].lowercaseString isEqualToString:@"app"]) return nil;
|
|
170
|
+
return bundle.bundleIdentifier.length > 0 ? bundle.bundleIdentifier : nil;
|
|
171
|
+
}
|
|
172
|
+
|
|
161
173
|
static int NativeSdkAppKitColorSchemeForAppearance(NSAppearance *appearance) {
|
|
162
174
|
NSAppearance *effective = appearance ?: NSApp.effectiveAppearance;
|
|
163
175
|
NSString *bestMatch = [effective bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
|
|
@@ -774,6 +786,10 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
774
786
|
@property(nonatomic, assign) uint32_t modifiers;
|
|
775
787
|
@end
|
|
776
788
|
|
|
789
|
+
@interface NativeSdkTraySegmentedControl : NSSegmentedControl
|
|
790
|
+
@property(nonatomic, assign) NSInteger sourceSelectedSegment;
|
|
791
|
+
@end
|
|
792
|
+
|
|
777
793
|
@interface NativeSdkStatusItemEntry : NSObject
|
|
778
794
|
@property(nonatomic, assign) uint32_t identifier;
|
|
779
795
|
@property(nonatomic, strong) NSStatusItem *item;
|
|
@@ -784,6 +800,8 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
784
800
|
@property(nonatomic, assign) int presentationTone;
|
|
785
801
|
@property(nonatomic, assign) double presentationIconOpacity;
|
|
786
802
|
@property(nonatomic, assign) BOOL presentationMonospaced;
|
|
803
|
+
@property(nonatomic, assign) double presentationFontSize;
|
|
804
|
+
@property(nonatomic, assign) int presentationFontWeight;
|
|
787
805
|
@property(nonatomic, strong) NSString *activationCommand;
|
|
788
806
|
@property(nonatomic, strong) NSString *alternateActivationCommand;
|
|
789
807
|
@property(nonatomic, strong) NSString *openCommand;
|
|
@@ -999,6 +1017,19 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
999
1017
|
@property(nonatomic, strong) NSImage *appIcon;
|
|
1000
1018
|
@property(nonatomic, strong) NSString *bundleIdentifier;
|
|
1001
1019
|
@property(nonatomic, strong) NSString *iconPath;
|
|
1020
|
+
@property(nonatomic, strong) NSString *updateFeedURL;
|
|
1021
|
+
@property(nonatomic, strong) NSString *updatePublicKey;
|
|
1022
|
+
@property(nonatomic, strong) NSString *updateTarget;
|
|
1023
|
+
@property(nonatomic, assign) BOOL updateCheckOnStart;
|
|
1024
|
+
@property(nonatomic, assign) BOOL updateCheckRunning;
|
|
1025
|
+
@property(nonatomic, strong) NSURLSessionDownloadTask *updateFeedTask;
|
|
1026
|
+
@property(nonatomic, strong) NSURLSessionDownloadTask *updateDownloadTask;
|
|
1027
|
+
@property(nonatomic, strong) NSTimer *updateFeedLimitTimer;
|
|
1028
|
+
@property(nonatomic, strong) NSTimer *updateDownloadLimitTimer;
|
|
1029
|
+
@property(nonatomic, assign) uint64_t updateExpectedArchiveBytes;
|
|
1030
|
+
@property(nonatomic, assign) BOOL updateDownloadCancelledByUser;
|
|
1031
|
+
@property(nonatomic, assign) BOOL updateDownloadAlertIsAppModal;
|
|
1032
|
+
@property(nonatomic, strong) NSAlert *updateDownloadAlert;
|
|
1002
1033
|
@property(nonatomic, strong) NSString *windowLabel;
|
|
1003
1034
|
@property(nonatomic, assign) native_sdk_appkit_event_callback_t callback;
|
|
1004
1035
|
@property(nonatomic, assign) native_sdk_appkit_bridge_callback_t bridgeCallback;
|
|
@@ -1087,6 +1118,15 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
1087
1118
|
- (void)configureApplication;
|
|
1088
1119
|
- (void)buildMenuBar;
|
|
1089
1120
|
- (void)addApplicationMenuToMenu:(NSMenu *)mainMenu;
|
|
1121
|
+
- (void)checkForUpdatesMenuItem:(id)sender;
|
|
1122
|
+
- (void)checkForUpdatesUserInitiated:(BOOL)userInitiated;
|
|
1123
|
+
- (NSWindow *)updatePresentationWindow;
|
|
1124
|
+
- (void)presentUpdateAlert:(NSAlert *)alert completionHandler:(void (^)(NSModalResponse responseCode))completionHandler;
|
|
1125
|
+
- (void)downloadUpdateVersion:(NSString *)version archiveURL:(NSString *)archiveURL archiveBytes:(uint64_t)archiveBytes sha256:(NSString *)sha256 releaseNotes:(NSString *)releaseNotes;
|
|
1126
|
+
- (void)installDownloadedUpdate:(NSURL *)downloadURL version:(NSString *)version archiveBytes:(uint64_t)archiveBytes sha256:(NSString *)sha256;
|
|
1127
|
+
- (void)showUpdateError:(NSString *)message userInitiated:(BOOL)userInitiated;
|
|
1128
|
+
- (void)updateFeedLimitTimerFired:(NSTimer *)timer;
|
|
1129
|
+
- (void)updateDownloadLimitTimerFired:(NSTimer *)timer;
|
|
1090
1130
|
- (NSMenuItem *)menuItem:(NSString *)title action:(SEL)action key:(NSString *)key modifiers:(NSEventModifierFlags)modifiers;
|
|
1091
1131
|
- (NSMenuItem *)commandMenuItem:(NSString *)title command:(NSString *)command key:(NSString *)key modifiers:(uint32_t)modifiers enabled:(BOOL)enabled checked:(BOOL)checked;
|
|
1092
1132
|
- (void)menuCommandItemClicked:(NSMenuItem *)menuItem;
|
|
@@ -1095,6 +1135,7 @@ static int NativeSdkCredentialStatus(OSStatus status, int missingCode) {
|
|
|
1095
1135
|
- (NativeSdkStatusItemEntry *)statusEntryForMenu:(NSMenu *)menu;
|
|
1096
1136
|
- (void)emitStatusCommand:(NSString *)command statusItemId:(uint32_t)statusItemId;
|
|
1097
1137
|
- (void)statusItemActivated:(id)sender;
|
|
1138
|
+
- (void)traySegmentChanged:(NSSegmentedControl *)control;
|
|
1098
1139
|
- (uint64_t)activeCommandWindowId;
|
|
1099
1140
|
- (void)setMenusWithTitles:(const char *const *)menuTitles titleLengths:(const size_t *)menuTitleLengths count:(size_t)menuCount itemMenuIndices:(const uint32_t *)itemMenuIndices itemLabels:(const char *const *)itemLabels itemLabelLengths:(const size_t *)itemLabelLengths itemCommands:(const char *const *)itemCommands itemCommandLengths:(const size_t *)itemCommandLengths itemKeys:(const char *const *)itemKeys itemKeyLengths:(const size_t *)itemKeyLengths itemModifiers:(const uint32_t *)itemModifiers itemSeparators:(const int *)itemSeparators itemEnabled:(const int *)itemEnabled itemChecked:(const int *)itemChecked itemCount:(size_t)itemCount;
|
|
1100
1141
|
- (void)runWithCallback:(native_sdk_appkit_event_callback_t)callback context:(void *)context;
|
|
@@ -2038,6 +2079,34 @@ static NSTextAlignment NativeSdkPacketTextAlignment(NSString *align) {
|
|
|
2038
2079
|
return NSTextAlignmentNatural;
|
|
2039
2080
|
}
|
|
2040
2081
|
|
|
2082
|
+
static BOOL NativeSdkPacketDrawAttributedText(
|
|
2083
|
+
NSString *value,
|
|
2084
|
+
NSDictionary *attributes,
|
|
2085
|
+
CGFloat x,
|
|
2086
|
+
CGFloat baseline,
|
|
2087
|
+
CGFloat width,
|
|
2088
|
+
CGFloat height
|
|
2089
|
+
) {
|
|
2090
|
+
if (value.length == 0) return YES;
|
|
2091
|
+
|
|
2092
|
+
NSTextStorage *storage = [[NSTextStorage alloc] initWithString:value attributes:attributes];
|
|
2093
|
+
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
|
|
2094
|
+
NSTextContainer *container = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(
|
|
2095
|
+
width > 0 ? width : CGFLOAT_MAX,
|
|
2096
|
+
height > 0 ? height : CGFLOAT_MAX
|
|
2097
|
+
)];
|
|
2098
|
+
container.lineFragmentPadding = 0;
|
|
2099
|
+
[layoutManager addTextContainer:container];
|
|
2100
|
+
[storage addLayoutManager:layoutManager];
|
|
2101
|
+
[layoutManager ensureLayoutForTextContainer:container];
|
|
2102
|
+
|
|
2103
|
+
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:container];
|
|
2104
|
+
if (glyphRange.length == 0) return YES;
|
|
2105
|
+
CGFloat firstLineOffset = [layoutManager locationForGlyphAtIndex:glyphRange.location].y;
|
|
2106
|
+
[layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:NSMakePoint(x, baseline - firstLineOffset)];
|
|
2107
|
+
return YES;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2041
2110
|
// Italicizes a resolved sans face for the reserved italic span font ids
|
|
2042
2111
|
// (5 and 6). Prefers a real italic face from the same family via
|
|
2043
2112
|
// NSFontManager (SF has one; Geist does not ship a sans italic), and falls
|
|
@@ -2178,6 +2247,16 @@ static NSCache<NSString *, NSNumber *> *NativeSdkMeasuredWidthCache(void) {
|
|
|
2178
2247
|
return cache;
|
|
2179
2248
|
}
|
|
2180
2249
|
|
|
2250
|
+
static NSCache<NSString *, NSValue *> *NativeSdkMeasuredInkCache(void) {
|
|
2251
|
+
static NSCache<NSString *, NSValue *> *cache = nil;
|
|
2252
|
+
static dispatch_once_t onceToken;
|
|
2253
|
+
dispatch_once(&onceToken, ^{
|
|
2254
|
+
cache = [[NSCache alloc] init];
|
|
2255
|
+
cache.countLimit = 16384;
|
|
2256
|
+
});
|
|
2257
|
+
return cache;
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2181
2260
|
// The id's current registration token AND the registered face that
|
|
2182
2261
|
// token resolves to, snapshotted under ONE acquisition of the
|
|
2183
2262
|
// descriptor table's @synchronized guard. The pair must be atomic
|
|
@@ -2262,6 +2341,7 @@ int native_sdk_appkit_register_font(uint64_t font_id, const uint8_t *bytes, size
|
|
|
2262
2341
|
for (NSString *cachedKey in cachedKeys) {
|
|
2263
2342
|
if ([cachedKey hasPrefix:stalePrefix]) [sizeCache removeObjectForKey:cachedKey];
|
|
2264
2343
|
}
|
|
2344
|
+
[NativeSdkMeasuredInkCache() removeAllObjects];
|
|
2265
2345
|
// The measured-width cache holds the same stale state but
|
|
2266
2346
|
// cannot be enumerated for eviction, so stamp the id with a
|
|
2267
2347
|
// fresh process-global token instead: width-cache keys
|
|
@@ -2339,6 +2419,7 @@ int native_sdk_appkit_unregister_font(uint64_t font_id, uint64_t token) {
|
|
|
2339
2419
|
// id's token under this same guard before caching, and this
|
|
2340
2420
|
// removal already retired the token it snapshotted.
|
|
2341
2421
|
[NativeSdkMeasuredWidthCache() removeAllObjects];
|
|
2422
|
+
[NativeSdkMeasuredInkCache() removeAllObjects];
|
|
2342
2423
|
}
|
|
2343
2424
|
return 1;
|
|
2344
2425
|
}
|
|
@@ -2485,6 +2566,47 @@ double native_sdk_appkit_measure_text(uint64_t font_id, double size, const char
|
|
|
2485
2566
|
}
|
|
2486
2567
|
}
|
|
2487
2568
|
|
|
2569
|
+
int native_sdk_appkit_measure_text_ink(uint64_t font_id, double size, const char *text, size_t text_len, double *min_x, double *max_x, double *min_y, double *max_y) {
|
|
2570
|
+
if (!text || text_len == 0 || !min_x || !max_x || !min_y || !max_y) return 0;
|
|
2571
|
+
CGFloat clamped = MAX(1, size);
|
|
2572
|
+
@autoreleasepool {
|
|
2573
|
+
NSString *value = [[NSString alloc] initWithBytes:text length:text_len encoding:NSUTF8StringEncoding];
|
|
2574
|
+
if (!value) return 0;
|
|
2575
|
+
|
|
2576
|
+
unsigned long long token = 0;
|
|
2577
|
+
NSFont *registered = NativeSdkRegisteredFontSnapshot((unsigned long long)font_id, clamped, &token);
|
|
2578
|
+
NSFont *font = registered ?: NativeSdkBuiltInFontForFontId(font_id, clamped);
|
|
2579
|
+
if (!font) return 0;
|
|
2580
|
+
|
|
2581
|
+
NSString *key = [NSString stringWithFormat:@"%llu/%llu/%.3f/%@", (unsigned long long)font_id, token, (double)clamped, value];
|
|
2582
|
+
NSValue *cached = [NativeSdkMeasuredInkCache() objectForKey:key];
|
|
2583
|
+
if (cached) {
|
|
2584
|
+
CGRect bounds = cached.rectValue;
|
|
2585
|
+
*min_x = CGRectGetMinX(bounds);
|
|
2586
|
+
*max_x = CGRectGetMaxX(bounds);
|
|
2587
|
+
*min_y = CGRectGetMinY(bounds);
|
|
2588
|
+
*max_y = CGRectGetMaxY(bounds);
|
|
2589
|
+
return 1;
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:value
|
|
2593
|
+
attributes:@{ NSFontAttributeName : font }];
|
|
2594
|
+
CTLineRef line = CTLineCreateWithAttributedString((__bridge CFAttributedStringRef)attributed);
|
|
2595
|
+
if (!line) return 0;
|
|
2596
|
+
CGRect bounds = CTLineGetBoundsWithOptions(line, kCTLineBoundsUseGlyphPathBounds);
|
|
2597
|
+
CFRelease(line);
|
|
2598
|
+
if (!isfinite(CGRectGetMinX(bounds)) || !isfinite(CGRectGetMaxX(bounds)) ||
|
|
2599
|
+
!isfinite(CGRectGetMinY(bounds)) || !isfinite(CGRectGetMaxY(bounds))) return 0;
|
|
2600
|
+
|
|
2601
|
+
[NativeSdkMeasuredInkCache() setObject:[NSValue valueWithRect:bounds] forKey:key];
|
|
2602
|
+
*min_x = CGRectGetMinX(bounds);
|
|
2603
|
+
*max_x = CGRectGetMaxX(bounds);
|
|
2604
|
+
*min_y = CGRectGetMinY(bounds);
|
|
2605
|
+
*max_y = CGRectGetMaxY(bounds);
|
|
2606
|
+
return 1;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2488
2610
|
// Batched per-cluster advances for a single-line run: one CTLine over
|
|
2489
2611
|
// the whole run (the same attributed-string shaping the width above
|
|
2490
2612
|
// summarizes), glyph advances accumulated onto the UTF-16 character
|
|
@@ -2697,8 +2819,7 @@ static BOOL NativeSdkPacketDrawText(NSDictionary *text, CGFloat opacity) {
|
|
|
2697
2819
|
};
|
|
2698
2820
|
NSDictionary *layout = NativeSdkPacketDictionary(text[@"layout"]);
|
|
2699
2821
|
if (!layout) {
|
|
2700
|
-
|
|
2701
|
-
return YES;
|
|
2822
|
+
return NativeSdkPacketDrawAttributedText(value, baseAttributes, origin.x, origin.y, CGFLOAT_MAX, CGFLOAT_MAX);
|
|
2702
2823
|
}
|
|
2703
2824
|
|
|
2704
2825
|
// Engine-measured line breaks: the packet carries the exact lines the
|
|
@@ -2717,7 +2838,7 @@ static BOOL NativeSdkPacketDrawText(NSDictionary *text, CGFloat opacity) {
|
|
|
2717
2838
|
if (lineText.length == 0) continue;
|
|
2718
2839
|
CGFloat lineX = NativeSdkPacketNumber(line[@"x"], origin.x);
|
|
2719
2840
|
CGFloat baseline = NativeSdkPacketNumber(line[@"baseline"], origin.y);
|
|
2720
|
-
|
|
2841
|
+
if (!NativeSdkPacketDrawAttributedText(lineText, baseAttributes, lineX, baseline, CGFLOAT_MAX, CGFLOAT_MAX)) return NO;
|
|
2721
2842
|
}
|
|
2722
2843
|
return YES;
|
|
2723
2844
|
}
|
|
@@ -2736,17 +2857,8 @@ static BOOL NativeSdkPacketDrawText(NSDictionary *text, CGFloat opacity) {
|
|
|
2736
2857
|
NSMutableDictionary *attributes = [baseAttributes mutableCopy];
|
|
2737
2858
|
attributes[NSParagraphStyleAttributeName] = paragraph;
|
|
2738
2859
|
CGFloat maxWidth = NativeSdkPacketNumber(layout[@"maxWidth"], 0);
|
|
2739
|
-
CGFloat
|
|
2740
|
-
|
|
2741
|
-
CGFloat textHeight = MAX(lineHeight > 0 ? lineHeight : size * 1.25, size * 1.25);
|
|
2742
|
-
NSRect measuredRect = [value boundingRectWithSize:NSMakeSize(textWidth, CGFLOAT_MAX)
|
|
2743
|
-
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
|
|
2744
|
-
attributes:attributes];
|
|
2745
|
-
textHeight = MAX(textHeight, ceil(measuredRect.size.height + 1));
|
|
2746
|
-
[value drawWithRect:NSMakeRect(origin.x, origin.y - size, textWidth, textHeight)
|
|
2747
|
-
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
|
|
2748
|
-
attributes:attributes];
|
|
2749
|
-
return YES;
|
|
2860
|
+
CGFloat textWidth = maxWidth > 0 ? maxWidth : CGFLOAT_MAX;
|
|
2861
|
+
return NativeSdkPacketDrawAttributedText(value, attributes, origin.x, origin.y, textWidth, CGFLOAT_MAX);
|
|
2750
2862
|
}
|
|
2751
2863
|
|
|
2752
2864
|
static BOOL NativeSdkPacketDrawEffect(NSDictionary *effect, CGFloat opacity, CGContextRef context, CGFloat scale, id transformValue, BOOL hasClip, NSRect clipRect) {
|
|
@@ -7480,6 +7592,9 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
|
|
|
7480
7592
|
@implementation NativeSdkShortcut
|
|
7481
7593
|
@end
|
|
7482
7594
|
|
|
7595
|
+
@implementation NativeSdkTraySegmentedControl
|
|
7596
|
+
@end
|
|
7597
|
+
|
|
7483
7598
|
@implementation NativeSdkStatusItemEntry
|
|
7484
7599
|
@end
|
|
7485
7600
|
|
|
@@ -7830,9 +7945,17 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
7830
7945
|
self.appVersion = version ?: @"";
|
|
7831
7946
|
self.aboutDescription = aboutDescription ?: @"";
|
|
7832
7947
|
self.hasWebContent = hasWebContent;
|
|
7833
|
-
|
|
7948
|
+
NSString *configuredBundleIdentifier = bundleIdentifier.length > 0 ? bundleIdentifier : @"dev.native_sdk.app";
|
|
7949
|
+
self.bundleIdentifier = NativeSdkPackagedBundleIdentifier() ?: configuredBundleIdentifier;
|
|
7834
7950
|
self.iconPath = iconPath ?: @"";
|
|
7835
7951
|
self.windowLabel = windowLabel.length > 0 ? windowLabel : @"main";
|
|
7952
|
+
self.updateFeedURL = @"";
|
|
7953
|
+
self.updatePublicKey = @"";
|
|
7954
|
+
self.updateTarget = @"";
|
|
7955
|
+
self.updateCheckOnStart = NO;
|
|
7956
|
+
self.updateCheckRunning = NO;
|
|
7957
|
+
self.updateDownloadCancelledByUser = NO;
|
|
7958
|
+
self.updateDownloadAlertIsAppModal = NO;
|
|
7836
7959
|
self.windows = [[NSMutableDictionary alloc] init];
|
|
7837
7960
|
self.webViews = [[NSMutableDictionary alloc] init];
|
|
7838
7961
|
self.delegates = [[NSMutableDictionary alloc] init];
|
|
@@ -8121,6 +8244,10 @@ static float NativeSdkCaptureReadRemixedSample(const AudioBufferList *buffers, c
|
|
|
8121
8244
|
NSUserNotificationCenter *notificationCenter = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
8122
8245
|
if (notificationCenter.delegate == self) notificationCenter.delegate = nil;
|
|
8123
8246
|
[self invalidateAppTimers];
|
|
8247
|
+
[self.updateFeedLimitTimer invalidate];
|
|
8248
|
+
[self.updateDownloadLimitTimer invalidate];
|
|
8249
|
+
[self.updateFeedTask cancel];
|
|
8250
|
+
[self.updateDownloadTask cancel];
|
|
8124
8251
|
[self audioCaptureStopSource:0];
|
|
8125
8252
|
[self audioCaptureStopSource:1];
|
|
8126
8253
|
[self audioStop];
|
|
@@ -9788,6 +9915,9 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
|
|
|
9788
9915
|
NSMenu *appMenu = [[NSMenu alloc] initWithTitle:self.displayName];
|
|
9789
9916
|
[appMenuItem setSubmenu:appMenu];
|
|
9790
9917
|
[appMenu addItem:[self menuItem:[NSString stringWithFormat:@"About %@", self.displayName] action:@selector(showAboutPanel:) key:@"" modifiers:0]];
|
|
9918
|
+
if (self.updateFeedURL.length > 0 && self.updatePublicKey.length > 0) {
|
|
9919
|
+
[appMenu addItem:[self menuItem:@"Check for Updates…" action:@selector(checkForUpdatesMenuItem:) key:@"" modifiers:0]];
|
|
9920
|
+
}
|
|
9791
9921
|
[appMenu addItem:[NSMenuItem separatorItem]];
|
|
9792
9922
|
[appMenu addItem:[self menuItem:[NSString stringWithFormat:@"Hide %@", self.displayName] action:@selector(hide:) key:@"h" modifiers:NSEventModifierFlagCommand]];
|
|
9793
9923
|
[appMenu addItem:[self menuItem:@"Hide Others" action:@selector(hideOtherApplications:) key:@"h" modifiers:(NSEventModifierFlagCommand | NSEventModifierFlagOption)]];
|
|
@@ -9796,6 +9926,381 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
|
|
|
9796
9926
|
[appMenu addItem:[self menuItem:[NSString stringWithFormat:@"Quit %@", self.displayName] action:@selector(terminate:) key:@"q" modifiers:NSEventModifierFlagCommand]];
|
|
9797
9927
|
}
|
|
9798
9928
|
|
|
9929
|
+
- (void)checkForUpdatesMenuItem:(id)sender {
|
|
9930
|
+
(void)sender;
|
|
9931
|
+
[self checkForUpdatesUserInitiated:YES];
|
|
9932
|
+
}
|
|
9933
|
+
|
|
9934
|
+
- (NSWindow *)updatePresentationWindow {
|
|
9935
|
+
NSWindow *keyWindow = NSApp.keyWindow;
|
|
9936
|
+
if (keyWindow.isVisible && !keyWindow.miniaturized) return keyWindow;
|
|
9937
|
+
for (NSWindow *window in NSApp.orderedWindows) {
|
|
9938
|
+
if (window.isVisible && !window.miniaturized) return window;
|
|
9939
|
+
}
|
|
9940
|
+
for (NSWindow *window in self.windows.allValues) {
|
|
9941
|
+
if (window.isVisible && !window.miniaturized) return window;
|
|
9942
|
+
}
|
|
9943
|
+
return nil;
|
|
9944
|
+
}
|
|
9945
|
+
|
|
9946
|
+
- (void)presentUpdateAlert:(NSAlert *)alert completionHandler:(void (^)(NSModalResponse responseCode))completionHandler {
|
|
9947
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
9948
|
+
NSWindow *window = [self updatePresentationWindow];
|
|
9949
|
+
if (window) {
|
|
9950
|
+
[alert beginSheetModalForWindow:window completionHandler:completionHandler];
|
|
9951
|
+
return;
|
|
9952
|
+
}
|
|
9953
|
+
const NSModalResponse response = [alert runModal];
|
|
9954
|
+
if (completionHandler) completionHandler(response);
|
|
9955
|
+
}
|
|
9956
|
+
|
|
9957
|
+
- (void)showUpdateError:(NSString *)message userInitiated:(BOOL)userInitiated {
|
|
9958
|
+
self.updateCheckRunning = NO;
|
|
9959
|
+
if (!userInitiated) {
|
|
9960
|
+
NSLog(@"Native SDK update check failed: %@", message ?: @"unknown error");
|
|
9961
|
+
return;
|
|
9962
|
+
}
|
|
9963
|
+
NSAlert *alert = [[NSAlert alloc] init];
|
|
9964
|
+
alert.alertStyle = NSAlertStyleWarning;
|
|
9965
|
+
alert.messageText = @"Unable to Check for Updates";
|
|
9966
|
+
alert.informativeText = message ?: @"The update could not be checked.";
|
|
9967
|
+
[alert addButtonWithTitle:@"OK"];
|
|
9968
|
+
[self presentUpdateAlert:alert completionHandler:nil];
|
|
9969
|
+
}
|
|
9970
|
+
|
|
9971
|
+
- (void)checkForUpdatesUserInitiated:(BOOL)userInitiated {
|
|
9972
|
+
if (self.updateFeedURL.length == 0 || self.updatePublicKey.length == 0 || self.updateCheckRunning) return;
|
|
9973
|
+
NSString *bundlePath = NSBundle.mainBundle.bundlePath;
|
|
9974
|
+
if (![[bundlePath pathExtension].lowercaseString isEqualToString:@"app"]) {
|
|
9975
|
+
[self showUpdateError:@"Update checks run only from a packaged .app bundle." userInitiated:userInitiated];
|
|
9976
|
+
return;
|
|
9977
|
+
}
|
|
9978
|
+
NSURL *feedURL = [NSURL URLWithString:self.updateFeedURL];
|
|
9979
|
+
if (!feedURL || ![feedURL.scheme.lowercaseString isEqualToString:@"https"]) {
|
|
9980
|
+
[self showUpdateError:@"The update feed URL is invalid." userInitiated:userInitiated];
|
|
9981
|
+
return;
|
|
9982
|
+
}
|
|
9983
|
+
self.updateCheckRunning = YES;
|
|
9984
|
+
__weak NativeSdkAppKitHost *weakSelf = self;
|
|
9985
|
+
NSMutableURLRequest *feedRequest = [NSMutableURLRequest requestWithURL:feedURL];
|
|
9986
|
+
[feedRequest setValue:@"bytes=0-65536" forHTTPHeaderField:@"Range"];
|
|
9987
|
+
self.updateFeedTask = [[NSURLSession sharedSession] downloadTaskWithRequest:feedRequest completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
|
|
9988
|
+
NativeSdkAppKitHost *strongSelf = weakSelf;
|
|
9989
|
+
if (!strongSelf) return;
|
|
9990
|
+
NSDictionary *attributes = location ? [[NSFileManager defaultManager] attributesOfItemAtPath:location.path error:nil] : nil;
|
|
9991
|
+
unsigned long long feedBytes = attributes.fileSize;
|
|
9992
|
+
NSData *data = feedBytes > 0 && feedBytes <= 64 * 1024 ? [NSData dataWithContentsOfURL:location options:NSDataReadingMappedIfSafe error:nil] : nil;
|
|
9993
|
+
if (error || data.length == 0 || ![response.URL.scheme.lowercaseString isEqualToString:@"https"] || ![response isKindOfClass:[NSHTTPURLResponse class]] || ((NSHTTPURLResponse *)response).statusCode < 200 || ((NSHTTPURLResponse *)response).statusCode >= 300) {
|
|
9994
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
9995
|
+
[strongSelf.updateFeedLimitTimer invalidate];
|
|
9996
|
+
strongSelf.updateFeedLimitTimer = nil;
|
|
9997
|
+
strongSelf.updateCheckRunning = NO;
|
|
9998
|
+
strongSelf.updateFeedTask = nil;
|
|
9999
|
+
[strongSelf showUpdateError:error.localizedDescription ?: @"The update feed could not be downloaded." userInitiated:userInitiated];
|
|
10000
|
+
});
|
|
10001
|
+
return;
|
|
10002
|
+
}
|
|
10003
|
+
NSMutableData *versionData = [NSMutableData dataWithLength:64];
|
|
10004
|
+
NSMutableData *archiveURLData = [NSMutableData dataWithLength:4096];
|
|
10005
|
+
NSMutableData *releaseNotesData = [NSMutableData dataWithLength:16 * 1024];
|
|
10006
|
+
native_sdk_update_verify_result_t verified = native_sdk_update_verify_feed(
|
|
10007
|
+
data.bytes, data.length,
|
|
10008
|
+
strongSelf.updatePublicKey.UTF8String, [strongSelf.updatePublicKey lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
10009
|
+
strongSelf.bundleIdentifier.UTF8String, [strongSelf.bundleIdentifier lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
10010
|
+
strongSelf.appVersion.UTF8String, [strongSelf.appVersion lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
10011
|
+
strongSelf.updateTarget.UTF8String, [strongSelf.updateTarget lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
10012
|
+
versionData.mutableBytes, versionData.length,
|
|
10013
|
+
archiveURLData.mutableBytes, archiveURLData.length,
|
|
10014
|
+
releaseNotesData.mutableBytes, releaseNotesData.length);
|
|
10015
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
10016
|
+
[strongSelf.updateFeedLimitTimer invalidate];
|
|
10017
|
+
strongSelf.updateFeedLimitTimer = nil;
|
|
10018
|
+
strongSelf.updateFeedTask = nil;
|
|
10019
|
+
if (verified.ok == 2) {
|
|
10020
|
+
strongSelf.updateCheckRunning = NO;
|
|
10021
|
+
if (userInitiated) {
|
|
10022
|
+
NSAlert *alert = [[NSAlert alloc] init];
|
|
10023
|
+
alert.messageText = [NSString stringWithFormat:@"%@ is up to date", strongSelf.displayName];
|
|
10024
|
+
alert.informativeText = [NSString stringWithFormat:@"You’re running version %@.", strongSelf.appVersion];
|
|
10025
|
+
[alert addButtonWithTitle:@"OK"];
|
|
10026
|
+
[strongSelf presentUpdateAlert:alert completionHandler:nil];
|
|
10027
|
+
}
|
|
10028
|
+
return;
|
|
10029
|
+
}
|
|
10030
|
+
if (verified.ok != 1) {
|
|
10031
|
+
NSString *message = verified.error_code == 3 ? @"The update feed signature is invalid."
|
|
10032
|
+
: verified.error_code == 5 ? @"The update feed belongs to another app."
|
|
10033
|
+
: verified.error_code == 6 ? @"The update feed does not contain a release for this Mac."
|
|
10034
|
+
: @"The update feed is malformed or cannot be verified.";
|
|
10035
|
+
[strongSelf showUpdateError:message userInitiated:userInitiated];
|
|
10036
|
+
return;
|
|
10037
|
+
}
|
|
10038
|
+
NSString *version = [[NSString alloc] initWithBytes:versionData.bytes length:verified.version_len encoding:NSUTF8StringEncoding];
|
|
10039
|
+
NSString *archiveURL = [[NSString alloc] initWithBytes:archiveURLData.bytes length:verified.archive_url_len encoding:NSUTF8StringEncoding];
|
|
10040
|
+
NSString *releaseNotes = [[NSString alloc] initWithBytes:releaseNotesData.bytes length:verified.release_notes_len encoding:NSUTF8StringEncoding] ?: @"";
|
|
10041
|
+
NSString *sha256 = [[NSString alloc] initWithBytes:verified.sha256 length:sizeof(verified.sha256) encoding:NSASCIIStringEncoding];
|
|
10042
|
+
if (!version || !archiveURL || !sha256) {
|
|
10043
|
+
[strongSelf showUpdateError:@"The verified update metadata could not be decoded." userInitiated:userInitiated];
|
|
10044
|
+
return;
|
|
10045
|
+
}
|
|
10046
|
+
NSAlert *alert = [[NSAlert alloc] init];
|
|
10047
|
+
alert.messageText = [NSString stringWithFormat:@"A new version of %@ is available", strongSelf.displayName];
|
|
10048
|
+
alert.informativeText = releaseNotes.length > 0
|
|
10049
|
+
? [NSString stringWithFormat:@"Version %@\n\n%@", version, releaseNotes]
|
|
10050
|
+
: [NSString stringWithFormat:@"Version %@ is ready to install.", version];
|
|
10051
|
+
[alert addButtonWithTitle:@"Install Update"];
|
|
10052
|
+
[alert addButtonWithTitle:@"Later"];
|
|
10053
|
+
[strongSelf presentUpdateAlert:alert completionHandler:^(NSModalResponse responseCode) {
|
|
10054
|
+
if (responseCode == NSAlertFirstButtonReturn) {
|
|
10055
|
+
[strongSelf downloadUpdateVersion:version archiveURL:archiveURL archiveBytes:verified.archive_bytes sha256:sha256 releaseNotes:releaseNotes];
|
|
10056
|
+
} else {
|
|
10057
|
+
strongSelf.updateCheckRunning = NO;
|
|
10058
|
+
}
|
|
10059
|
+
}];
|
|
10060
|
+
});
|
|
10061
|
+
}];
|
|
10062
|
+
[self.updateFeedTask resume];
|
|
10063
|
+
self.updateFeedLimitTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateFeedLimitTimerFired:) userInfo:nil repeats:YES];
|
|
10064
|
+
}
|
|
10065
|
+
|
|
10066
|
+
- (void)updateFeedLimitTimerFired:(NSTimer *)timer {
|
|
10067
|
+
(void)timer;
|
|
10068
|
+
if (!self.updateFeedTask) {
|
|
10069
|
+
[self.updateFeedLimitTimer invalidate];
|
|
10070
|
+
self.updateFeedLimitTimer = nil;
|
|
10071
|
+
return;
|
|
10072
|
+
}
|
|
10073
|
+
if (self.updateFeedTask.countOfBytesReceived > 64 * 1024) [self.updateFeedTask cancel];
|
|
10074
|
+
}
|
|
10075
|
+
|
|
10076
|
+
- (void)downloadUpdateVersion:(NSString *)version archiveURL:(NSString *)archiveURL archiveBytes:(uint64_t)archiveBytes sha256:(NSString *)sha256 releaseNotes:(NSString *)releaseNotes {
|
|
10077
|
+
(void)releaseNotes;
|
|
10078
|
+
NSURL *url = [NSURL URLWithString:archiveURL];
|
|
10079
|
+
if (!url || ![url.scheme.lowercaseString isEqualToString:@"https"]) {
|
|
10080
|
+
[self showUpdateError:@"The update archive URL is invalid." userInitiated:YES];
|
|
10081
|
+
return;
|
|
10082
|
+
}
|
|
10083
|
+
NSAlert *progress = [[NSAlert alloc] init];
|
|
10084
|
+
progress.messageText = [NSString stringWithFormat:@"Downloading %@ %@…", self.displayName, version];
|
|
10085
|
+
progress.informativeText = @"The update will be verified before it is installed.";
|
|
10086
|
+
NSProgressIndicator *indicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 320, 20)];
|
|
10087
|
+
indicator.indeterminate = YES;
|
|
10088
|
+
indicator.style = NSProgressIndicatorStyleBar;
|
|
10089
|
+
[indicator startAnimation:nil];
|
|
10090
|
+
progress.accessoryView = indicator;
|
|
10091
|
+
[progress addButtonWithTitle:@"Cancel"];
|
|
10092
|
+
self.updateDownloadAlert = progress;
|
|
10093
|
+
self.updateExpectedArchiveBytes = archiveBytes;
|
|
10094
|
+
self.updateDownloadCancelledByUser = NO;
|
|
10095
|
+
self.updateDownloadAlertIsAppModal = NO;
|
|
10096
|
+
__weak NativeSdkAppKitHost *weakSelf = self;
|
|
10097
|
+
self.updateDownloadTask = [[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
|
|
10098
|
+
NativeSdkAppKitHost *strongSelf = weakSelf;
|
|
10099
|
+
if (!strongSelf) return;
|
|
10100
|
+
NSURL *copied = nil;
|
|
10101
|
+
NSError *copyError = error;
|
|
10102
|
+
if (!copyError && location && [response.URL.scheme.lowercaseString isEqualToString:@"https"] && [response isKindOfClass:[NSHTTPURLResponse class]] && ((NSHTTPURLResponse *)response).statusCode >= 200 && ((NSHTTPURLResponse *)response).statusCode < 300) {
|
|
10103
|
+
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"native-update-%@.zip", NSUUID.UUID.UUIDString]];
|
|
10104
|
+
copied = [NSURL fileURLWithPath:path];
|
|
10105
|
+
if (![[NSFileManager defaultManager] copyItemAtURL:location toURL:copied error:©Error]) copied = nil;
|
|
10106
|
+
}
|
|
10107
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
10108
|
+
const BOOL cancelledByUser = strongSelf.updateDownloadCancelledByUser;
|
|
10109
|
+
strongSelf.updateDownloadCancelledByUser = NO;
|
|
10110
|
+
[strongSelf.updateDownloadLimitTimer invalidate];
|
|
10111
|
+
strongSelf.updateDownloadLimitTimer = nil;
|
|
10112
|
+
strongSelf.updateDownloadTask = nil;
|
|
10113
|
+
NSAlert *downloadAlert = strongSelf.updateDownloadAlert;
|
|
10114
|
+
if (downloadAlert.window.sheetParent) {
|
|
10115
|
+
[downloadAlert.window.sheetParent endSheet:downloadAlert.window returnCode:NSModalResponseOK];
|
|
10116
|
+
} else if (strongSelf.updateDownloadAlertIsAppModal && NSApp.modalWindow == downloadAlert.window) {
|
|
10117
|
+
[NSApp abortModal];
|
|
10118
|
+
[downloadAlert.window orderOut:nil];
|
|
10119
|
+
}
|
|
10120
|
+
strongSelf.updateDownloadAlertIsAppModal = NO;
|
|
10121
|
+
strongSelf.updateDownloadAlert = nil;
|
|
10122
|
+
if (cancelledByUser) {
|
|
10123
|
+
if (copied) [[NSFileManager defaultManager] removeItemAtURL:copied error:nil];
|
|
10124
|
+
strongSelf.updateCheckRunning = NO;
|
|
10125
|
+
return;
|
|
10126
|
+
}
|
|
10127
|
+
if (!copied || copyError) {
|
|
10128
|
+
[strongSelf showUpdateError:copyError.localizedDescription ?: @"The update archive could not be downloaded." userInitiated:YES];
|
|
10129
|
+
return;
|
|
10130
|
+
}
|
|
10131
|
+
[strongSelf installDownloadedUpdate:copied version:version archiveBytes:archiveBytes sha256:sha256];
|
|
10132
|
+
});
|
|
10133
|
+
}];
|
|
10134
|
+
self.updateDownloadLimitTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateDownloadLimitTimerFired:) userInfo:nil repeats:YES];
|
|
10135
|
+
NSWindow *presentationWindow = [self updatePresentationWindow];
|
|
10136
|
+
if (presentationWindow) {
|
|
10137
|
+
[progress beginSheetModalForWindow:presentationWindow completionHandler:^(NSModalResponse responseCode) {
|
|
10138
|
+
NativeSdkAppKitHost *strongSelf = weakSelf;
|
|
10139
|
+
if (responseCode == NSAlertFirstButtonReturn && strongSelf.updateDownloadTask) {
|
|
10140
|
+
strongSelf.updateDownloadCancelledByUser = YES;
|
|
10141
|
+
[strongSelf.updateDownloadTask cancel];
|
|
10142
|
+
}
|
|
10143
|
+
}];
|
|
10144
|
+
[self.updateDownloadTask resume];
|
|
10145
|
+
} else {
|
|
10146
|
+
self.updateDownloadAlertIsAppModal = YES;
|
|
10147
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
10148
|
+
[self.updateDownloadTask resume];
|
|
10149
|
+
const NSModalResponse responseCode = [progress runModal];
|
|
10150
|
+
const BOOL completedByDownload = !self.updateDownloadAlertIsAppModal;
|
|
10151
|
+
self.updateDownloadAlertIsAppModal = NO;
|
|
10152
|
+
if (!completedByDownload && responseCode == NSAlertFirstButtonReturn && self.updateDownloadTask) {
|
|
10153
|
+
self.updateDownloadCancelledByUser = YES;
|
|
10154
|
+
[self.updateDownloadTask cancel];
|
|
10155
|
+
}
|
|
10156
|
+
}
|
|
10157
|
+
}
|
|
10158
|
+
|
|
10159
|
+
- (void)updateDownloadLimitTimerFired:(NSTimer *)timer {
|
|
10160
|
+
(void)timer;
|
|
10161
|
+
if (!self.updateDownloadTask) {
|
|
10162
|
+
[self.updateDownloadLimitTimer invalidate];
|
|
10163
|
+
self.updateDownloadLimitTimer = nil;
|
|
10164
|
+
return;
|
|
10165
|
+
}
|
|
10166
|
+
if ((uint64_t)self.updateDownloadTask.countOfBytesReceived > self.updateExpectedArchiveBytes) [self.updateDownloadTask cancel];
|
|
10167
|
+
}
|
|
10168
|
+
|
|
10169
|
+
static BOOL NativeSdkRunTask(NSString *launchPath, NSArray<NSString *> *arguments, NSString **output) {
|
|
10170
|
+
NSTask *task = [[NSTask alloc] init];
|
|
10171
|
+
task.executableURL = [NSURL fileURLWithPath:launchPath];
|
|
10172
|
+
task.arguments = arguments;
|
|
10173
|
+
NSPipe *pipe = [NSPipe pipe];
|
|
10174
|
+
task.standardOutput = pipe;
|
|
10175
|
+
task.standardError = pipe;
|
|
10176
|
+
NSError *error = nil;
|
|
10177
|
+
if (![task launchAndReturnError:&error]) {
|
|
10178
|
+
if (output) *output = error.localizedDescription;
|
|
10179
|
+
return NO;
|
|
10180
|
+
}
|
|
10181
|
+
NSData *data = [pipe.fileHandleForReading readDataToEndOfFile];
|
|
10182
|
+
[task waitUntilExit];
|
|
10183
|
+
if (output) *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ?: @"";
|
|
10184
|
+
return task.terminationStatus == 0;
|
|
10185
|
+
}
|
|
10186
|
+
|
|
10187
|
+
static NSString *NativeSdkSigningTeamIdentifier(NSString *bundlePath) {
|
|
10188
|
+
SecStaticCodeRef code = NULL;
|
|
10189
|
+
CFDictionaryRef information = NULL;
|
|
10190
|
+
OSStatus status = SecStaticCodeCreateWithPath((__bridge CFURLRef)[NSURL fileURLWithPath:bundlePath], kSecCSDefaultFlags, &code);
|
|
10191
|
+
if (status == errSecSuccess) status = SecCodeCopySigningInformation(code, kSecCSSigningInformation, &information);
|
|
10192
|
+
NSString *result = nil;
|
|
10193
|
+
if (status == errSecSuccess && information) {
|
|
10194
|
+
CFTypeRef value = CFDictionaryGetValue(information, kSecCodeInfoTeamIdentifier);
|
|
10195
|
+
if (value && CFGetTypeID(value) == CFStringGetTypeID()) result = [(__bridge NSString *)value copy];
|
|
10196
|
+
}
|
|
10197
|
+
if (information) CFRelease(information);
|
|
10198
|
+
if (code) CFRelease(code);
|
|
10199
|
+
return result;
|
|
10200
|
+
}
|
|
10201
|
+
|
|
10202
|
+
- (void)installDownloadedUpdate:(NSURL *)downloadURL version:(NSString *)version archiveBytes:(uint64_t)archiveBytes sha256:(NSString *)sha256 {
|
|
10203
|
+
NSString *bundlePath = NSBundle.mainBundle.bundlePath.stringByStandardizingPath;
|
|
10204
|
+
NSString *parentPath = bundlePath.stringByDeletingLastPathComponent;
|
|
10205
|
+
__weak NativeSdkAppKitHost *weakSelf = self;
|
|
10206
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
|
10207
|
+
NativeSdkAppKitHost *strongSelf = weakSelf;
|
|
10208
|
+
if (!strongSelf) return;
|
|
10209
|
+
NSFileManager *manager = [NSFileManager defaultManager];
|
|
10210
|
+
if (![manager isWritableFileAtPath:parentPath]) {
|
|
10211
|
+
[manager removeItemAtURL:downloadURL error:nil];
|
|
10212
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
10213
|
+
[strongSelf showUpdateError:@"The app’s containing folder is not writable. Move the app to a user-writable Applications folder or install the update manually." userInitiated:YES];
|
|
10214
|
+
});
|
|
10215
|
+
return;
|
|
10216
|
+
}
|
|
10217
|
+
if (!native_sdk_update_verify_archive(downloadURL.path.UTF8String, [downloadURL.path lengthOfBytesUsingEncoding:NSUTF8StringEncoding], archiveBytes, sha256.UTF8String, [sha256 lengthOfBytesUsingEncoding:NSUTF8StringEncoding])) {
|
|
10218
|
+
[manager removeItemAtURL:downloadURL error:nil];
|
|
10219
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
10220
|
+
[strongSelf showUpdateError:@"The downloaded update did not match its signed size and SHA-256 digest." userInitiated:YES];
|
|
10221
|
+
});
|
|
10222
|
+
return;
|
|
10223
|
+
}
|
|
10224
|
+
NSString *stagePath = [parentPath stringByAppendingPathComponent:[NSString stringWithFormat:@".%@.native-update-%@", bundlePath.lastPathComponent, NSUUID.UUID.UUIDString]];
|
|
10225
|
+
NSString *extractPath = [stagePath stringByAppendingPathComponent:@"extracted"];
|
|
10226
|
+
NSError *stageError = nil;
|
|
10227
|
+
if (![manager createDirectoryAtPath:extractPath withIntermediateDirectories:YES attributes:nil error:&stageError]) {
|
|
10228
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10229
|
+
[manager removeItemAtURL:downloadURL error:nil];
|
|
10230
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:stageError.localizedDescription userInitiated:YES]; });
|
|
10231
|
+
return;
|
|
10232
|
+
}
|
|
10233
|
+
NSString *taskOutput = nil;
|
|
10234
|
+
if (!NativeSdkRunTask(@"/usr/bin/ditto", @[ @"-x", @"-k", downloadURL.path, extractPath ], &taskOutput)) {
|
|
10235
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10236
|
+
[manager removeItemAtURL:downloadURL error:nil];
|
|
10237
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:taskOutput.length > 0 ? taskOutput : @"The update archive could not be extracted." userInitiated:YES]; });
|
|
10238
|
+
return;
|
|
10239
|
+
}
|
|
10240
|
+
[manager removeItemAtURL:downloadURL error:nil];
|
|
10241
|
+
NSError *listingError = nil;
|
|
10242
|
+
NSArray<NSString *> *entries = [manager contentsOfDirectoryAtPath:extractPath error:&listingError];
|
|
10243
|
+
NSMutableArray<NSString *> *appEntries = [NSMutableArray array];
|
|
10244
|
+
for (NSString *entry in entries ?: @[]) {
|
|
10245
|
+
if ([[entry pathExtension].lowercaseString isEqualToString:@"app"]) [appEntries addObject:entry];
|
|
10246
|
+
}
|
|
10247
|
+
if (listingError || entries.count != 1 || appEntries.count != 1) {
|
|
10248
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10249
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:@"The update archive must contain exactly one top-level .app bundle." userInitiated:YES]; });
|
|
10250
|
+
return;
|
|
10251
|
+
}
|
|
10252
|
+
NSString *candidatePath = [extractPath stringByAppendingPathComponent:appEntries.firstObject];
|
|
10253
|
+
NSNumber *candidateIsDirectory = nil;
|
|
10254
|
+
NSNumber *candidateIsSymlink = nil;
|
|
10255
|
+
[[NSURL fileURLWithPath:candidatePath] getResourceValue:&candidateIsDirectory forKey:NSURLIsDirectoryKey error:nil];
|
|
10256
|
+
[[NSURL fileURLWithPath:candidatePath] getResourceValue:&candidateIsSymlink forKey:NSURLIsSymbolicLinkKey error:nil];
|
|
10257
|
+
NSBundle *candidateBundle = [NSBundle bundleWithPath:candidatePath];
|
|
10258
|
+
if (!candidateIsDirectory.boolValue || candidateIsSymlink.boolValue || !candidateBundle || ![candidateBundle.bundleIdentifier isEqualToString:strongSelf.bundleIdentifier] || ![[candidateBundle objectForInfoDictionaryKey:@"CFBundleVersion"] isEqualToString:version]) {
|
|
10259
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10260
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:@"The update archive does not contain the expected app bundle and version." userInitiated:YES]; });
|
|
10261
|
+
return;
|
|
10262
|
+
}
|
|
10263
|
+
NSString *teamIdentifier = NativeSdkSigningTeamIdentifier(bundlePath);
|
|
10264
|
+
if (teamIdentifier.length > 0) {
|
|
10265
|
+
if ([teamIdentifier rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound ||
|
|
10266
|
+
[strongSelf.bundleIdentifier rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"\\\""]].location != NSNotFound) {
|
|
10267
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10268
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:@"The installed app’s signing identity cannot be represented safely." userInitiated:YES]; });
|
|
10269
|
+
return;
|
|
10270
|
+
}
|
|
10271
|
+
NSString *requirement = [NSString stringWithFormat:@"anchor apple generic and certificate leaf[subject.OU] = \"%@\" and identifier \"%@\"", teamIdentifier, strongSelf.bundleIdentifier];
|
|
10272
|
+
NSMutableArray<NSString *> *codesignArguments = [NSMutableArray arrayWithArray:@[ @"--verify", @"--deep", @"--strict" ]];
|
|
10273
|
+
if (requirement.length > 0) [codesignArguments addObject:[@"-R=" stringByAppendingString:requirement]];
|
|
10274
|
+
[codesignArguments addObject:candidatePath];
|
|
10275
|
+
if (!NativeSdkRunTask(@"/usr/bin/codesign", codesignArguments, &taskOutput)) {
|
|
10276
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10277
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:taskOutput.length > 0 ? taskOutput : @"The update’s Apple code signature does not match the installed app." userInitiated:YES]; });
|
|
10278
|
+
return;
|
|
10279
|
+
}
|
|
10280
|
+
}
|
|
10281
|
+
NSString *scriptPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"native-update-install-%@.sh", NSUUID.UUID.UUIDString]];
|
|
10282
|
+
NSString *backupPath = [parentPath stringByAppendingPathComponent:[NSString stringWithFormat:@".%@.native-update-backup-%@", bundlePath.lastPathComponent, NSUUID.UUID.UUIDString]];
|
|
10283
|
+
NSString *script = @"#!/bin/sh\nset -u\npid=\"$1\"\ncurrent=\"$2\"\ncandidate=\"$3\"\nbackup=\"$4\"\nstage=\"$5\"\ncount=0\nwhile /bin/kill -0 \"$pid\" 2>/dev/null; do\n count=$((count + 1))\n if [ \"$count\" -ge 600 ]; then /bin/rm -rf \"$stage\"; /bin/rm -f \"$0\"; exit 1; fi\n /bin/sleep 0.1\ndone\nif /bin/mv \"$current\" \"$backup\" && /bin/mv \"$candidate\" \"$current\"; then\n if /usr/bin/open \"$current\"; then\n /bin/rm -rf \"$backup\" \"$stage\"\n /bin/rm -f \"$0\"\n exit 0\n fi\n /bin/rm -rf \"$current\"\n /bin/mv \"$backup\" \"$current\"\nfi\nif [ -e \"$backup\" ] && [ ! -e \"$current\" ]; then /bin/mv \"$backup\" \"$current\"; fi\n/usr/bin/open \"$current\" >/dev/null 2>&1 || true\n/bin/rm -rf \"$stage\"\n/bin/rm -f \"$0\"\nexit 1\n";
|
|
10284
|
+
NSError *scriptError = nil;
|
|
10285
|
+
if (![script writeToFile:scriptPath atomically:YES encoding:NSUTF8StringEncoding error:&scriptError] || ![manager setAttributes:@{ NSFilePosixPermissions: @0700 } ofItemAtPath:scriptPath error:&scriptError]) {
|
|
10286
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10287
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:scriptError.localizedDescription userInitiated:YES]; });
|
|
10288
|
+
return;
|
|
10289
|
+
}
|
|
10290
|
+
NSTask *installer = [[NSTask alloc] init];
|
|
10291
|
+
installer.executableURL = [NSURL fileURLWithPath:@"/bin/sh"];
|
|
10292
|
+
installer.arguments = @[ scriptPath, [NSString stringWithFormat:@"%d", getpid()], bundlePath, candidatePath, backupPath, stagePath ];
|
|
10293
|
+
NSError *launchError = nil;
|
|
10294
|
+
if (![installer launchAndReturnError:&launchError]) {
|
|
10295
|
+
[manager removeItemAtPath:stagePath error:nil];
|
|
10296
|
+
[manager removeItemAtPath:scriptPath error:nil];
|
|
10297
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [strongSelf showUpdateError:launchError.localizedDescription userInitiated:YES]; });
|
|
10298
|
+
return;
|
|
10299
|
+
}
|
|
10300
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [NSApp terminate:nil]; });
|
|
10301
|
+
});
|
|
10302
|
+
}
|
|
10303
|
+
|
|
9799
10304
|
- (NSMenuItem *)menuItem:(NSString *)title action:(SEL)action key:(NSString *)key modifiers:(NSEventModifierFlags)modifiers {
|
|
9800
10305
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:action keyEquivalent:key ?: @""];
|
|
9801
10306
|
item.keyEquivalentModifierMask = modifiers;
|
|
@@ -9999,6 +10504,13 @@ static void NativeSdkApplyProcessDisplayName(NSString *displayName) {
|
|
|
9999
10504
|
dispatch_activate(sigterm_source);
|
|
10000
10505
|
self.sigtermSource = sigterm_source;
|
|
10001
10506
|
|
|
10507
|
+
if (self.updateCheckOnStart && self.updateFeedURL.length > 0 && self.updatePublicKey.length > 0) {
|
|
10508
|
+
__weak NativeSdkAppKitHost *weakUpdateSelf = self;
|
|
10509
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
10510
|
+
[weakUpdateSelf checkForUpdatesUserInitiated:NO];
|
|
10511
|
+
});
|
|
10512
|
+
}
|
|
10513
|
+
|
|
10002
10514
|
[self scheduleFrame];
|
|
10003
10515
|
[NSApp run];
|
|
10004
10516
|
}
|
|
@@ -12197,6 +12709,22 @@ static void NativeSdkVideoFittedSize(double naturalWidth, double naturalHeight,
|
|
|
12197
12709
|
}
|
|
12198
12710
|
}
|
|
12199
12711
|
|
|
12712
|
+
- (void)traySegmentChanged:(NSSegmentedControl *)control {
|
|
12713
|
+
NSInteger selected = control.selectedSegment;
|
|
12714
|
+
if (selected < 0 || !self.trayCallback) return;
|
|
12715
|
+
NSInteger itemId = [control tagForSegment:selected];
|
|
12716
|
+
if (itemId <= 0) return;
|
|
12717
|
+
// Selection is model-owned. AppKit applies its optimistic selection
|
|
12718
|
+
// before sending the action; restore the declared state before dispatch
|
|
12719
|
+
// so an ignored or failed command cannot leave native chrome ahead of
|
|
12720
|
+
// the model. A successful dispatch rebuilds the row from the new state.
|
|
12721
|
+
NSInteger sourceSelected = [(NativeSdkTraySegmentedControl *)control sourceSelectedSegment];
|
|
12722
|
+
for (NSInteger index = 0; index < control.segmentCount; index++) {
|
|
12723
|
+
[control setSelected:index == sourceSelected forSegment:index];
|
|
12724
|
+
}
|
|
12725
|
+
self.trayCallback(self.trayContext, (uint32_t)control.tag, (uint32_t)itemId);
|
|
12726
|
+
}
|
|
12727
|
+
|
|
12200
12728
|
- (NativeSdkStatusItemEntry *)statusEntryForId:(uint32_t)identifier {
|
|
12201
12729
|
return self.statusItems[@(identifier)];
|
|
12202
12730
|
}
|
|
@@ -12496,6 +13024,26 @@ void native_sdk_appkit_set_dock_icon_file(native_sdk_appkit_host_t *host, const
|
|
|
12496
13024
|
}
|
|
12497
13025
|
}
|
|
12498
13026
|
|
|
13027
|
+
void native_sdk_appkit_configure_updates(native_sdk_appkit_host_t *host, const char *feed_url, size_t feed_url_len, const char *public_key, size_t public_key_len, int check_on_start, const char *target, size_t target_len) {
|
|
13028
|
+
if (!host) return;
|
|
13029
|
+
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
13030
|
+
@autoreleasepool {
|
|
13031
|
+
object.updateFeedURL = feed_url && feed_url_len > 0 ? ([[NSString alloc] initWithBytes:feed_url length:feed_url_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
13032
|
+
object.updatePublicKey = public_key && public_key_len > 0 ? ([[NSString alloc] initWithBytes:public_key length:public_key_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
13033
|
+
object.updateTarget = target && target_len > 0 ? ([[NSString alloc] initWithBytes:target length:target_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
13034
|
+
object.updateCheckOnStart = check_on_start != 0;
|
|
13035
|
+
[object buildMenuBar];
|
|
13036
|
+
}
|
|
13037
|
+
}
|
|
13038
|
+
|
|
13039
|
+
int native_sdk_appkit_check_for_updates(native_sdk_appkit_host_t *host, int user_initiated) {
|
|
13040
|
+
if (!host) return 0;
|
|
13041
|
+
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
13042
|
+
if (object.updateFeedURL.length == 0 || object.updatePublicKey.length == 0) return 0;
|
|
13043
|
+
[object checkForUpdatesUserInitiated:(user_initiated != 0)];
|
|
13044
|
+
return 1;
|
|
13045
|
+
}
|
|
13046
|
+
|
|
12499
13047
|
void native_sdk_appkit_run(native_sdk_appkit_host_t *host, native_sdk_appkit_event_callback_t callback, void *context) {
|
|
12500
13048
|
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
12501
13049
|
[object runWithCallback:callback context:context];
|
|
@@ -13344,20 +13892,33 @@ static NSImage *NativeSdkTrayImageWithOpacity(NSImage *source, double opacity) {
|
|
|
13344
13892
|
return image;
|
|
13345
13893
|
}
|
|
13346
13894
|
|
|
13347
|
-
static
|
|
13895
|
+
static NSFontWeight NativeSdkTrayFontWeight(int weight) {
|
|
13896
|
+
switch (weight) {
|
|
13897
|
+
case 1: return NSFontWeightMedium;
|
|
13898
|
+
case 2: return NSFontWeightSemibold;
|
|
13899
|
+
case 3: return NSFontWeightBold;
|
|
13900
|
+
default: return NSFontWeightRegular;
|
|
13901
|
+
}
|
|
13902
|
+
}
|
|
13903
|
+
|
|
13904
|
+
static void NativeSdkApplyTrayPresentation(NativeSdkAppKitHost *object, NativeSdkStatusItemEntry *entry, NSString *requestedTitle, double width, int tone, double iconOpacity, BOOL monospaced, double fontSize, int fontWeight) {
|
|
13348
13905
|
if (!entry.item) return;
|
|
13349
13906
|
entry.presentationTitle = requestedTitle ?: @"";
|
|
13350
13907
|
entry.presentationWidth = width;
|
|
13351
13908
|
entry.presentationTone = tone;
|
|
13352
13909
|
entry.presentationIconOpacity = iconOpacity;
|
|
13353
13910
|
entry.presentationMonospaced = monospaced;
|
|
13911
|
+
entry.presentationFontSize = fontSize;
|
|
13912
|
+
entry.presentationFontWeight = fontWeight;
|
|
13354
13913
|
NSString *title = requestedTitle ?: @"";
|
|
13355
13914
|
if (!entry.baseImage && title.length == 0) {
|
|
13356
13915
|
title = object.appName.length > 0 ? [object.appName substringToIndex:MIN(1, object.appName.length)] : @"Z";
|
|
13357
13916
|
}
|
|
13917
|
+
CGFloat resolvedSize = fontSize > 0 ? fontSize : 11;
|
|
13918
|
+
NSFontWeight resolvedWeight = NativeSdkTrayFontWeight(fontWeight);
|
|
13358
13919
|
NSFont *font = monospaced
|
|
13359
|
-
?
|
|
13360
|
-
: [NSFont systemFontOfSize:
|
|
13920
|
+
? [NSFont monospacedSystemFontOfSize:resolvedSize weight:resolvedWeight]
|
|
13921
|
+
: [NSFont systemFontOfSize:resolvedSize weight:resolvedWeight];
|
|
13361
13922
|
NSStatusBarButton *button = entry.item.button;
|
|
13362
13923
|
if (tone == 0) {
|
|
13363
13924
|
button.title = title;
|
|
@@ -13398,7 +13959,7 @@ static void NativeSdkApplyTrayShell(NativeSdkAppKitHost *object, NativeSdkStatus
|
|
|
13398
13959
|
entry.item.visible = visible != 0;
|
|
13399
13960
|
}
|
|
13400
13961
|
|
|
13401
|
-
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) {
|
|
13962
|
+
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, double font_size, int font_weight, 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) {
|
|
13402
13963
|
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
13403
13964
|
@autoreleasepool {
|
|
13404
13965
|
NSNumber *key = @(status_item_id);
|
|
@@ -13415,7 +13976,7 @@ void native_sdk_appkit_create_tray(native_sdk_appkit_host_t *host, uint32_t stat
|
|
|
13415
13976
|
entry.item = [[NSStatusBar systemStatusBar] statusItemWithLength:hasTitle ? NSVariableStatusItemLength : NSSquareStatusItemLength];
|
|
13416
13977
|
NSString *titleString = hasTitle ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
13417
13978
|
NativeSdkApplyTrayShell(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);
|
|
13418
|
-
NativeSdkApplyTrayPresentation(object, entry, titleString, width, tone, icon_opacity, monospaced != 0);
|
|
13979
|
+
NativeSdkApplyTrayPresentation(object, entry, titleString, width, tone, icon_opacity, monospaced != 0, font_size, font_weight);
|
|
13419
13980
|
}
|
|
13420
13981
|
}
|
|
13421
13982
|
|
|
@@ -13425,7 +13986,7 @@ void native_sdk_appkit_update_tray_shell(native_sdk_appkit_host_t *host, uint32_
|
|
|
13425
13986
|
NativeSdkStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
13426
13987
|
if (!entry) return;
|
|
13427
13988
|
NativeSdkApplyTrayShell(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);
|
|
13428
|
-
NativeSdkApplyTrayPresentation(object, entry, entry.presentationTitle, entry.presentationWidth, entry.presentationTone, entry.presentationIconOpacity, entry.presentationMonospaced);
|
|
13989
|
+
NativeSdkApplyTrayPresentation(object, entry, entry.presentationTitle, entry.presentationWidth, entry.presentationTone, entry.presentationIconOpacity, entry.presentationMonospaced, entry.presentationFontSize, entry.presentationFontWeight);
|
|
13429
13990
|
if (entry.activationCommand.length == 0 && entry.alternateActivationCommand.length == 0) entry.item.menu = entry.menu;
|
|
13430
13991
|
else entry.item.menu = nil;
|
|
13431
13992
|
}
|
|
@@ -13438,8 +13999,115 @@ enum {
|
|
|
13438
13999
|
NativeSdkTrayRoleHero = 3,
|
|
13439
14000
|
NativeSdkTrayRoleAgent = 4,
|
|
13440
14001
|
NativeSdkTrayRoleContext = 5,
|
|
14002
|
+
NativeSdkTrayRoleSegmented = 6,
|
|
14003
|
+
NativeSdkTrayRoleChart = 7,
|
|
13441
14004
|
};
|
|
13442
14005
|
|
|
14006
|
+
@interface NativeSdkTrayBarChartView : NSView
|
|
14007
|
+
@property(nonatomic, copy) NSArray<NSNumber *> *values;
|
|
14008
|
+
@property(nonatomic, assign) double minValue;
|
|
14009
|
+
@property(nonatomic, assign) double maxValue;
|
|
14010
|
+
@end
|
|
14011
|
+
|
|
14012
|
+
@implementation NativeSdkTrayBarChartView
|
|
14013
|
+
- (BOOL)isFlipped { return YES; }
|
|
14014
|
+
- (void)drawRect:(NSRect)dirtyRect {
|
|
14015
|
+
[super drawRect:dirtyRect];
|
|
14016
|
+
if (self.values.count == 0 || !(self.maxValue > self.minValue)) return;
|
|
14017
|
+
CGFloat gap = 2;
|
|
14018
|
+
CGFloat barWidth = MAX(1, (NSWidth(self.bounds) - gap * (self.values.count - 1)) / self.values.count);
|
|
14019
|
+
CGFloat x = 0;
|
|
14020
|
+
[NSColor.controlAccentColor setFill];
|
|
14021
|
+
for (NSNumber *number in self.values) {
|
|
14022
|
+
double fraction = (number.doubleValue - self.minValue) / (self.maxValue - self.minValue);
|
|
14023
|
+
fraction = MIN(MAX(fraction, 0), 1);
|
|
14024
|
+
CGFloat height = MAX(fraction > 0 ? 1 : 0, floor(fraction * NSHeight(self.bounds)));
|
|
14025
|
+
NSRectFill(NSMakeRect(x, NSHeight(self.bounds) - height, barWidth, height));
|
|
14026
|
+
x += barWidth + gap;
|
|
14027
|
+
}
|
|
14028
|
+
}
|
|
14029
|
+
@end
|
|
14030
|
+
|
|
14031
|
+
static NSString *NativeSdkTrayString(const char *bytes, size_t len) {
|
|
14032
|
+
return bytes && len > 0 ? ([[NSString alloc] initWithBytes:bytes length:len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
14033
|
+
}
|
|
14034
|
+
|
|
14035
|
+
static NSView *NativeSdkTraySegmentedView(NativeSdkAppKitHost *object, uint32_t statusItemId, const native_sdk_appkit_tray_segment_option_t *options, size_t count) {
|
|
14036
|
+
NSView *row = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 320, 38)];
|
|
14037
|
+
NativeSdkTraySegmentedControl *control = [[NativeSdkTraySegmentedControl alloc] initWithFrame:NSMakeRect(14, 5, 292, 28)];
|
|
14038
|
+
control.segmentCount = count;
|
|
14039
|
+
control.segmentStyle = NSSegmentStyleAutomatic;
|
|
14040
|
+
control.trackingMode = NSSegmentSwitchTrackingSelectOne;
|
|
14041
|
+
control.target = object;
|
|
14042
|
+
control.action = @selector(traySegmentChanged:);
|
|
14043
|
+
control.tag = (NSInteger)statusItemId;
|
|
14044
|
+
control.sourceSelectedSegment = -1;
|
|
14045
|
+
control.autoresizingMask = NSViewWidthSizable;
|
|
14046
|
+
for (size_t i = 0; i < count; i++) {
|
|
14047
|
+
[control setLabel:NativeSdkTrayString(options[i].label, options[i].label_len) forSegment:i];
|
|
14048
|
+
[control setEnabled:options[i].enabled != 0 forSegment:i];
|
|
14049
|
+
[control setTag:(NSInteger)options[i].item_id forSegment:i];
|
|
14050
|
+
[control setSelected:options[i].selected != 0 forSegment:i];
|
|
14051
|
+
if (options[i].selected != 0) control.sourceSelectedSegment = (NSInteger)i;
|
|
14052
|
+
}
|
|
14053
|
+
[row addSubview:control];
|
|
14054
|
+
row.accessibilityRole = NSAccessibilityGroupRole;
|
|
14055
|
+
return row;
|
|
14056
|
+
}
|
|
14057
|
+
|
|
14058
|
+
static NSView *NativeSdkTrayMetricView(const native_sdk_appkit_tray_metric_row_t *metric) {
|
|
14059
|
+
NSView *row = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 320, 58)];
|
|
14060
|
+
NSTextField *primary = [NSTextField labelWithString:NativeSdkTrayString(metric->primary_text, metric->primary_text_len)];
|
|
14061
|
+
NSTextField *secondary = [NSTextField labelWithString:NativeSdkTrayString(metric->secondary_text, metric->secondary_text_len)];
|
|
14062
|
+
primary.frame = NSMakeRect(14, 25, 292, 28);
|
|
14063
|
+
secondary.frame = NSMakeRect(14, 6, 292, 16);
|
|
14064
|
+
primary.font = [NSFont fontWithName:@"Geist Mono" size:20] ?: [NSFont monospacedDigitSystemFontOfSize:20 weight:NSFontWeightMedium];
|
|
14065
|
+
secondary.font = [NSFont systemFontOfSize:11];
|
|
14066
|
+
secondary.textColor = NSColor.secondaryLabelColor;
|
|
14067
|
+
primary.autoresizingMask = NSViewWidthSizable;
|
|
14068
|
+
secondary.autoresizingMask = NSViewWidthSizable;
|
|
14069
|
+
primary.accessibilityElement = NO;
|
|
14070
|
+
secondary.accessibilityElement = NO;
|
|
14071
|
+
[row addSubview:primary];
|
|
14072
|
+
[row addSubview:secondary];
|
|
14073
|
+
row.accessibilityLabel = NativeSdkTrayString(metric->accessibility_label, metric->accessibility_label_len);
|
|
14074
|
+
row.accessibilityRole = NSAccessibilityGroupRole;
|
|
14075
|
+
return row;
|
|
14076
|
+
}
|
|
14077
|
+
|
|
14078
|
+
static NSView *NativeSdkTrayChartView(const native_sdk_appkit_tray_chart_row_t *chart) {
|
|
14079
|
+
NSString *leading = NativeSdkTrayString(chart->leading_caption, chart->leading_caption_len);
|
|
14080
|
+
NSString *trailing = NativeSdkTrayString(chart->trailing_summary, chart->trailing_summary_len);
|
|
14081
|
+
NSView *row = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 320, 58)];
|
|
14082
|
+
NSTextField *leadingField = [NSTextField labelWithString:leading];
|
|
14083
|
+
NSTextField *trailingField = [NSTextField labelWithString:trailing];
|
|
14084
|
+
leadingField.frame = NSMakeRect(14, 3, 142, 15);
|
|
14085
|
+
trailingField.frame = NSMakeRect(164, 3, 142, 15);
|
|
14086
|
+
trailingField.alignment = NSTextAlignmentRight;
|
|
14087
|
+
leadingField.font = [NSFont systemFontOfSize:10];
|
|
14088
|
+
trailingField.font = [NSFont monospacedDigitSystemFontOfSize:10 weight:NSFontWeightRegular];
|
|
14089
|
+
leadingField.textColor = NSColor.secondaryLabelColor;
|
|
14090
|
+
trailingField.textColor = NSColor.secondaryLabelColor;
|
|
14091
|
+
leadingField.autoresizingMask = NSViewWidthSizable;
|
|
14092
|
+
trailingField.autoresizingMask = NSViewMinXMargin;
|
|
14093
|
+
leadingField.accessibilityElement = NO;
|
|
14094
|
+
trailingField.accessibilityElement = NO;
|
|
14095
|
+
NativeSdkTrayBarChartView *bars = [[NativeSdkTrayBarChartView alloc] initWithFrame:NSMakeRect(14, 21, 292, 32)];
|
|
14096
|
+
NSMutableArray<NSNumber *> *values = [NSMutableArray arrayWithCapacity:chart->value_count];
|
|
14097
|
+
for (size_t i = 0; i < chart->value_count; i++) [values addObject:@(chart->values[i])];
|
|
14098
|
+
bars.values = values;
|
|
14099
|
+
bars.minValue = chart->min_value;
|
|
14100
|
+
bars.maxValue = chart->max_value;
|
|
14101
|
+
bars.autoresizingMask = NSViewWidthSizable;
|
|
14102
|
+
bars.accessibilityElement = NO;
|
|
14103
|
+
[row addSubview:leadingField];
|
|
14104
|
+
[row addSubview:trailingField];
|
|
14105
|
+
[row addSubview:bars];
|
|
14106
|
+
row.accessibilityLabel = NativeSdkTrayString(chart->accessibility_label, chart->accessibility_label_len);
|
|
14107
|
+
row.accessibilityRole = NSAccessibilityGroupRole;
|
|
14108
|
+
return row;
|
|
14109
|
+
}
|
|
14110
|
+
|
|
13443
14111
|
static NSView *NativeSdkTrayHeroView(NSString *headline, NSString *quota) {
|
|
13444
14112
|
NSArray<NSString *> *parts = [headline componentsSeparatedByString:@"\n"];
|
|
13445
14113
|
NSString *value = parts.count > 0 ? parts[0] : @"";
|
|
@@ -13667,6 +14335,7 @@ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, uint32_t
|
|
|
13667
14335
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:label ?: @""
|
|
13668
14336
|
action:@selector(trayMenuItemClicked:)
|
|
13669
14337
|
keyEquivalent:@""];
|
|
14338
|
+
item.representedObject = @(i);
|
|
13670
14339
|
item.tag = (NSInteger)(((uint64_t)status_item_id << 32) | item_ids[i]);
|
|
13671
14340
|
item.target = object;
|
|
13672
14341
|
item.enabled = enabled_flags[i] != 0;
|
|
@@ -13740,6 +14409,46 @@ void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, uint32_t
|
|
|
13740
14409
|
}
|
|
13741
14410
|
}
|
|
13742
14411
|
|
|
14412
|
+
void native_sdk_appkit_update_tray_rich_rows(native_sdk_appkit_host_t *host, uint32_t status_item_id, const native_sdk_appkit_tray_segmented_row_t *segmented_rows, size_t segmented_count, const native_sdk_appkit_tray_metric_row_t *metric_rows, size_t metric_count, const native_sdk_appkit_tray_chart_row_t *chart_rows, size_t chart_count) {
|
|
14413
|
+
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
14414
|
+
@autoreleasepool {
|
|
14415
|
+
NativeSdkStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
14416
|
+
if (!entry || !entry.menu) return;
|
|
14417
|
+
for (size_t i = 0; i < segmented_count; i++) {
|
|
14418
|
+
const native_sdk_appkit_tray_segmented_row_t *row = &segmented_rows[i];
|
|
14419
|
+
NSMenuItem *item = nil;
|
|
14420
|
+
for (NSMenuItem *candidate in entry.menu.itemArray) {
|
|
14421
|
+
if ([candidate.representedObject isEqual:@(row->row_index)]) { item = candidate; break; }
|
|
14422
|
+
}
|
|
14423
|
+
if (!item) continue;
|
|
14424
|
+
item.action = NULL;
|
|
14425
|
+
item.target = nil;
|
|
14426
|
+
item.view = NativeSdkTraySegmentedView(object, status_item_id, row->options, row->option_count);
|
|
14427
|
+
}
|
|
14428
|
+
for (size_t i = 0; i < metric_count; i++) {
|
|
14429
|
+
NSMenuItem *item = nil;
|
|
14430
|
+
for (NSMenuItem *candidate in entry.menu.itemArray) {
|
|
14431
|
+
if ([candidate.representedObject isEqual:@(metric_rows[i].row_index)]) { item = candidate; break; }
|
|
14432
|
+
}
|
|
14433
|
+
if (!item) continue;
|
|
14434
|
+
item.action = NULL;
|
|
14435
|
+
item.target = nil;
|
|
14436
|
+
item.view = NativeSdkTrayMetricView(&metric_rows[i]);
|
|
14437
|
+
}
|
|
14438
|
+
for (size_t i = 0; i < chart_count; i++) {
|
|
14439
|
+
const native_sdk_appkit_tray_chart_row_t *row = &chart_rows[i];
|
|
14440
|
+
NSMenuItem *item = nil;
|
|
14441
|
+
for (NSMenuItem *candidate in entry.menu.itemArray) {
|
|
14442
|
+
if ([candidate.representedObject isEqual:@(row->row_index)]) { item = candidate; break; }
|
|
14443
|
+
}
|
|
14444
|
+
if (!item) continue;
|
|
14445
|
+
item.action = NULL;
|
|
14446
|
+
item.target = nil;
|
|
14447
|
+
item.view = NativeSdkTrayChartView(row);
|
|
14448
|
+
}
|
|
14449
|
+
}
|
|
14450
|
+
}
|
|
14451
|
+
|
|
13743
14452
|
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) {
|
|
13744
14453
|
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
13745
14454
|
@autoreleasepool {
|
|
@@ -13753,18 +14462,20 @@ void native_sdk_appkit_update_tray_title(native_sdk_appkit_host_t *host, uint32_
|
|
|
13753
14462
|
entry.presentationWidth,
|
|
13754
14463
|
entry.presentationTone,
|
|
13755
14464
|
entry.presentationIconOpacity,
|
|
13756
|
-
entry.presentationMonospaced
|
|
14465
|
+
entry.presentationMonospaced,
|
|
14466
|
+
entry.presentationFontSize,
|
|
14467
|
+
entry.presentationFontWeight
|
|
13757
14468
|
);
|
|
13758
14469
|
}
|
|
13759
14470
|
}
|
|
13760
14471
|
|
|
13761
|
-
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) {
|
|
14472
|
+
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, double font_size, int font_weight) {
|
|
13762
14473
|
NativeSdkAppKitHost *object = (__bridge NativeSdkAppKitHost *)host;
|
|
13763
14474
|
@autoreleasepool {
|
|
13764
14475
|
NativeSdkStatusItemEntry *entry = [object statusEntryForId:status_item_id];
|
|
13765
14476
|
if (!entry) return;
|
|
13766
14477
|
NSString *value = title ? ([[NSString alloc] initWithBytes:title length:title_len encoding:NSUTF8StringEncoding] ?: @"") : @"";
|
|
13767
|
-
NativeSdkApplyTrayPresentation(object, entry, value, width, tone, icon_opacity, monospaced != 0);
|
|
14478
|
+
NativeSdkApplyTrayPresentation(object, entry, value, width, tone, icon_opacity, monospaced != 0, font_size, font_weight);
|
|
13768
14479
|
}
|
|
13769
14480
|
}
|
|
13770
14481
|
|