@legendapp/spark 0.0.1-next.7 → 0.0.1-next.8
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/package.json +8 -8
- package/schema.json +9 -0
- package/skills/spark/SKILL.md +1 -1
- package/skills/spark/UPGRADING.md +21 -0
- package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-audio/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +16 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/create.js +16 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +2 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/macos-release.js +4 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +10 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/release-driver.js +35 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +18 -18
- package/vendor/node_modules/@legendapp/spark-cli/dist/updates.js +18 -8
- package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/app.json +5 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/gitignore +2 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +7 -7
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/app.json +5 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/gitignore +2 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +8 -8
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/app.json +5 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/gitignore +2 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +8 -8
- package/vendor/node_modules/@legendapp/spark-clipboard/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-codex/cpp/HybridCodexAppServer.mm +88 -76
- package/vendor/node_modules/@legendapp/spark-codex/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-context-menu/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-app/RNDesktopApp.podspec +12 -1
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/RNDesktopApp.mm +8 -1
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +8 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +84 -21
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkInstance.h +27 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkInstance.mm +207 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.h +44 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +349 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkWindow.mm +3 -1
- package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +1 -1
- package/vendor/node_modules/@legendapp/spark-desktop-app/src/api.ts +39 -6
- package/vendor/node_modules/@legendapp/spark-desktop-app/src/contracts/menu.ts +21 -7
- package/vendor/node_modules/@legendapp/spark-desktop-config/accessibility-state.cjs +50 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +9 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/autolinking.cjs +8 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +1 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/config.d.cts +7 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-scroll-view.cjs +144 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-alignment.cjs +60 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-input-alignment.cjs +112 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/schema.json +9 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/test-driver.cjs +11 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/test-driver.d.cts +2 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/text-input-accessibility.cjs +47 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/updates.cjs +4 -2
- package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +2 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -1
- package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +18 -6
- package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-host/windows/application.inc +61 -15
- package/vendor/node_modules/@legendapp/spark-desktop-host/windows/launch.inc +67 -0
- package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-windows/RNDesktopWindows.podspec +3 -0
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +5 -2
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +22 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
- package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-file-dialog/RNFileDialog.podspec +1 -0
- package/vendor/node_modules/@legendapp/spark-file-dialog/ios/RNFileDialog.mm +153 -64
- package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/index.ts +19 -7
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/native.ts +5 -1
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +42 -4
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +18 -2
- package/vendor/node_modules/@legendapp/spark-file-system/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-markdown/src/Markdown.tsx +2 -1
- package/vendor/node_modules/@legendapp/spark-message-dialog/macos/RNDesktopMessageDialog.mm +113 -12
- package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +110 -14
- package/vendor/node_modules/@legendapp/spark-native-menu/ios/RNNativeMenu.mm +116 -8
- package/vendor/node_modules/@legendapp/spark-native-menu/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-native-menu/src/api.ts +63 -18
- package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +9 -3
- package/vendor/node_modules/@legendapp/spark-notifications/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-processes/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-settings-ui/src/index.tsx +5 -2
- package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-system/macos/RNDesktopSystem.mm +13 -3
- package/vendor/node_modules/@legendapp/spark-system/macos/SparkAppearancePreferences.h +9 -0
- package/vendor/node_modules/@legendapp/spark-system/macos/SparkAppearancePreferences.mm +31 -0
- package/vendor/node_modules/@legendapp/spark-system/macos/SparkDockTile.h +24 -0
- package/vendor/node_modules/@legendapp/spark-system/macos/SparkDockTile.mm +101 -0
- package/vendor/node_modules/@legendapp/spark-system/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-system/src/index.ts +73 -7
- package/vendor/node_modules/@legendapp/spark-tray/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +2 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkLayoutDirection.h +17 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +6 -1
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +55 -8
- package/vendor/node_modules/@legendapp/spark-ui/macos/glass-effect-view/RNGlassEffectView.mm +11 -7
- package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +4 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSelect.mm +4 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +77 -14
- package/vendor/node_modules/@legendapp/spark-ui/macos/swipe-actions/RNSwipeActions.mm +31 -7
- package/vendor/node_modules/@legendapp/spark-ui/macos/text-input-search/RNTextInputSearch.mm +25 -1
- package/vendor/node_modules/@legendapp/spark-ui/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +5 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +19 -8
- package/vendor/node_modules/@legendapp/spark-updates/macos/RNDesktopUpdates.mm +25 -13
- package/vendor/node_modules/@legendapp/spark-updates/macos/SparkUpdateState.h +39 -0
- package/vendor/node_modules/@legendapp/spark-updates/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-updates/src/index.ts +45 -9
- package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "RNSwipeActions.h"
|
|
2
|
+
#import "RNSparkLayoutDirection.h"
|
|
2
3
|
#import <QuartzCore/QuartzCore.h>
|
|
3
4
|
#import <react/renderer/components/RNSparkUISpec/ComponentDescriptors.h>
|
|
4
5
|
#import <react/renderer/components/RNSparkUISpec/EventEmitters.h>
|
|
@@ -41,7 +42,7 @@ static void RNSwipeAnimate(NSTimeInterval duration, void (^changes)(void), void
|
|
|
41
42
|
@interface RNSwipeActionButton : NSView
|
|
42
43
|
@property (nonatomic, readonly) NSString *actionId;
|
|
43
44
|
@property (nonatomic, readonly) BOOL dismisses;
|
|
44
|
-
/** +1 on the
|
|
45
|
+
/** +1 on the left side, -1 on the right; the outermost button tracks the content edge once armed. */
|
|
45
46
|
@property (nonatomic) NSInteger edge;
|
|
46
47
|
@property (nonatomic) BOOL followsContent;
|
|
47
48
|
@property (nonatomic, weak) RNSwipeActions *owner;
|
|
@@ -79,6 +80,12 @@ static void RNSwipeAnimate(NSTimeInterval duration, void (^changes)(void), void
|
|
|
79
80
|
return self;
|
|
80
81
|
}
|
|
81
82
|
- (BOOL)isFlipped { return YES; }
|
|
83
|
+
- (void)setUserInterfaceLayoutDirection:(NSUserInterfaceLayoutDirection)direction
|
|
84
|
+
{
|
|
85
|
+
[super setUserInterfaceLayoutDirection:direction];
|
|
86
|
+
_icon.userInterfaceLayoutDirection = direction;
|
|
87
|
+
_label.userInterfaceLayoutDirection = direction;
|
|
88
|
+
}
|
|
82
89
|
- (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
|
|
83
90
|
// Non-opaque views drag the window by default, which would swallow the click.
|
|
84
91
|
- (BOOL)mouseDownCanMoveWindow { return NO; }
|
|
@@ -122,6 +129,8 @@ static __weak RNSwipeActions *RNSwipeOpenRow;
|
|
|
122
129
|
/** The button filling the revealed strip: the outermost once armed, or a tapped dismissing one. */
|
|
123
130
|
RNSwipeActionButton *_takeover;
|
|
124
131
|
BOOL _dismissed;
|
|
132
|
+
/** Leading actions sit on the right in right-to-left layouts. */
|
|
133
|
+
NSUserInterfaceLayoutDirection _direction;
|
|
125
134
|
NSUInteger _generation;
|
|
126
135
|
}
|
|
127
136
|
|
|
@@ -162,8 +171,9 @@ static __weak RNSwipeActions *RNSwipeOpenRow;
|
|
|
162
171
|
[childComponentView removeFromSuperview];
|
|
163
172
|
}
|
|
164
173
|
|
|
165
|
-
- (NSArray<RNSwipeActionButton *> *)buttonsFromJson:(const std::string &)json
|
|
174
|
+
- (NSArray<RNSwipeActionButton *> *)buttonsFromJson:(const std::string &)json leading:(BOOL)leading
|
|
166
175
|
{
|
|
176
|
+
NSInteger edge = leading == (_direction == NSUserInterfaceLayoutDirectionLeftToRight) ? 1 : -1;
|
|
167
177
|
NSData *data = [NSData dataWithBytes:json.data() length:json.size()];
|
|
168
178
|
NSArray *actions = data.length ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : @[];
|
|
169
179
|
NSMutableArray *buttons = [NSMutableArray new];
|
|
@@ -171,6 +181,7 @@ static __weak RNSwipeActions *RNSwipeOpenRow;
|
|
|
171
181
|
RNSwipeActionButton *button = [[RNSwipeActionButton alloc] initWithAction:action];
|
|
172
182
|
button.edge = edge;
|
|
173
183
|
button.owner = self;
|
|
184
|
+
button.userInterfaceLayoutDirection = _direction;
|
|
174
185
|
[buttons addObject:button];
|
|
175
186
|
}
|
|
176
187
|
return buttons;
|
|
@@ -183,8 +194,8 @@ static __weak RNSwipeActions *RNSwipeOpenRow;
|
|
|
183
194
|
_leadingJson = value.leadingActionsJson;
|
|
184
195
|
_trailingJson = value.trailingActionsJson;
|
|
185
196
|
for (NSView *button in [_leading arrayByAddingObjectsFromArray:_trailing]) [button removeFromSuperview];
|
|
186
|
-
_leading = [self buttonsFromJson:_leadingJson
|
|
187
|
-
_trailing = [self buttonsFromJson:_trailingJson
|
|
197
|
+
_leading = [self buttonsFromJson:_leadingJson leading:YES];
|
|
198
|
+
_trailing = [self buttonsFromJson:_trailingJson leading:NO];
|
|
188
199
|
for (NSView *button in [_leading arrayByAddingObjectsFromArray:_trailing]) [_actionsView addSubview:button];
|
|
189
200
|
[self resetPosition];
|
|
190
201
|
}
|
|
@@ -196,6 +207,14 @@ static __weak RNSwipeActions *RNSwipeOpenRow;
|
|
|
196
207
|
- (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics
|
|
197
208
|
{
|
|
198
209
|
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
210
|
+
NSUserInterfaceLayoutDirection direction = RNSparkLayoutDirection(layoutMetrics);
|
|
211
|
+
if (direction != _direction) {
|
|
212
|
+
// The sides swap, so an open row closes rather than revealing the other side's actions.
|
|
213
|
+
_direction = direction;
|
|
214
|
+
for (RNSwipeActionButton *button in _leading) { button.edge = -button.edge; button.userInterfaceLayoutDirection = direction; }
|
|
215
|
+
for (RNSwipeActionButton *button in _trailing) { button.edge = -button.edge; button.userInterfaceLayoutDirection = direction; }
|
|
216
|
+
[self resetPosition];
|
|
217
|
+
}
|
|
199
218
|
[self layoutSubviews];
|
|
200
219
|
}
|
|
201
220
|
|
|
@@ -238,8 +257,8 @@ static __weak RNSwipeActions *RNSwipeOpenRow;
|
|
|
238
257
|
{
|
|
239
258
|
NSRect bounds = _clipView.bounds;
|
|
240
259
|
_contentView.frame = NSOffsetRect(bounds, _offset, 0);
|
|
241
|
-
[self layoutButtons:
|
|
242
|
-
[self layoutButtons:
|
|
260
|
+
[self layoutButtons:[self buttonsForOffset:1] reveal:MAX(0, _offset) bounds:bounds];
|
|
261
|
+
[self layoutButtons:[self buttonsForOffset:-1] reveal:MAX(0, -_offset) bounds:bounds];
|
|
243
262
|
}
|
|
244
263
|
|
|
245
264
|
/** The first action sits at the outer edge; a takeover button fills the whole revealed strip. */
|
|
@@ -258,7 +277,12 @@ static __weak RNSwipeActions *RNSwipeOpenRow;
|
|
|
258
277
|
}];
|
|
259
278
|
}
|
|
260
279
|
|
|
261
|
-
|
|
280
|
+
/** Content moving right (a positive offset) reveals the left side's actions. */
|
|
281
|
+
- (NSArray<RNSwipeActionButton *> *)buttonsForOffset:(CGFloat)offset
|
|
282
|
+
{
|
|
283
|
+
BOOL leftToRight = _direction == NSUserInterfaceLayoutDirectionLeftToRight;
|
|
284
|
+
return offset > 0 ? (leftToRight ? _leading : _trailing) : offset < 0 ? (leftToRight ? _trailing : _leading) : @[];
|
|
285
|
+
}
|
|
262
286
|
|
|
263
287
|
- (CGFloat)commitDistance
|
|
264
288
|
{
|
package/vendor/node_modules/@legendapp/spark-ui/macos/text-input-search/RNTextInputSearch.mm
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "RNTextInputSearch.h"
|
|
2
|
+
#import "RNSparkLayoutDirection.h"
|
|
2
3
|
|
|
3
4
|
#import <react/renderer/components/RNSparkUISpec/ComponentDescriptors.h>
|
|
4
5
|
#import <react/renderer/components/RNSparkUISpec/EventEmitters.h>
|
|
@@ -21,6 +22,24 @@ static NSAppearance *RNTextInputSearchAppearanceForName(NSString *appearanceName
|
|
|
21
22
|
return nil;
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
// On macOS 26 NSSearchField draws its magnifier and cancel button in subviews it creates lazily, and those
|
|
26
|
+
// read their own direction rather than the field's.
|
|
27
|
+
@interface RNTextInputSearchField : NSSearchField
|
|
28
|
+
@end
|
|
29
|
+
|
|
30
|
+
@implementation RNTextInputSearchField
|
|
31
|
+
- (void)setUserInterfaceLayoutDirection:(NSUserInterfaceLayoutDirection)direction
|
|
32
|
+
{
|
|
33
|
+
[super setUserInterfaceLayoutDirection:direction];
|
|
34
|
+
for (NSView *subview in self.subviews) subview.userInterfaceLayoutDirection = direction;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
- (void)didAddSubview:(NSView *)subview
|
|
38
|
+
{
|
|
39
|
+
[super didAddSubview:subview];
|
|
40
|
+
subview.userInterfaceLayoutDirection = self.userInterfaceLayoutDirection;
|
|
41
|
+
}
|
|
42
|
+
@end
|
|
24
43
|
#endif
|
|
25
44
|
|
|
26
45
|
@interface RNTextInputSearch () <
|
|
@@ -46,7 +65,7 @@ static NSAppearance *RNTextInputSearchAppearanceForName(NSString *appearanceName
|
|
|
46
65
|
if (self = [super init]) {
|
|
47
66
|
_props = std::make_shared<const TextInputSearchProps>();
|
|
48
67
|
#if TARGET_OS_OSX
|
|
49
|
-
_textField = [
|
|
68
|
+
_textField = [RNTextInputSearchField new];
|
|
50
69
|
_textField.delegate = self;
|
|
51
70
|
_textField.focusRingType = NSFocusRingTypeNone;
|
|
52
71
|
_textField.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
@@ -153,6 +172,11 @@ static NSAppearance *RNTextInputSearchAppearanceForName(NSString *appearanceName
|
|
|
153
172
|
oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics
|
|
154
173
|
{
|
|
155
174
|
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
175
|
+
#if TARGET_OS_OSX
|
|
176
|
+
NSUserInterfaceLayoutDirection direction = RNSparkLayoutDirection(layoutMetrics);
|
|
177
|
+
_textField.alignment = RNSparkLeadingTextAlignment(direction);
|
|
178
|
+
_textField.userInterfaceLayoutDirection = direction;
|
|
179
|
+
#endif
|
|
156
180
|
[self layoutSubviews];
|
|
157
181
|
}
|
|
158
182
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-ui",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"react-native": "src/index",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"clsx": "^2.1.1",
|
|
71
71
|
"tailwind-merge": "^3.4.0",
|
|
72
|
-
"@legendapp/spark-desktop-app": "0.0.1-next.
|
|
72
|
+
"@legendapp/spark-desktop-app": "0.0.1-next.8"
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -11,11 +11,16 @@ export type SidebarLayoutEvent = Readonly<{
|
|
|
11
11
|
width: Double;
|
|
12
12
|
}>;
|
|
13
13
|
|
|
14
|
+
export type SidebarRowLayoutEvent = Readonly<{
|
|
15
|
+
width: Double;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
14
18
|
export interface NativeProps extends ViewProps {
|
|
15
19
|
contentInsetTop?: Double;
|
|
16
20
|
defaultRowHeight?: Double;
|
|
17
21
|
itemsJson?: string;
|
|
18
22
|
onSidebarLayout?: DirectEventHandler<SidebarLayoutEvent>;
|
|
23
|
+
onSidebarRowLayout?: DirectEventHandler<SidebarRowLayoutEvent>;
|
|
19
24
|
onSidebarSelectionChange?: DirectEventHandler<SidebarSelectionChangeEvent>;
|
|
20
25
|
selectedId?: string;
|
|
21
26
|
selectionRevision?: Int32;
|
|
@@ -30,7 +30,9 @@ export interface SidebarItemProps extends SpecializedViewProps {
|
|
|
30
30
|
selectable?: boolean;
|
|
31
31
|
onContextMenu?: (event: SidebarContextMenuEvent) => void;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
// Inside a Sidebar: the row width the native list reports, which React rows take, since it excludes
|
|
34
|
+
// the source-list insets and a scroller. Undefined until the first native layout.
|
|
35
|
+
const SidebarContext = createContext<{ rowWidth: number | undefined } | null>(null);
|
|
34
36
|
export function getSidebarAvailability() {
|
|
35
37
|
const availability = macosViewAvailability("Sidebar");
|
|
36
38
|
return availability.available ? macosViewAvailability("SidebarItem") : availability;
|
|
@@ -67,6 +69,7 @@ export function Sidebar({ items, children, selectedId, contentInsetTop = 0, defa
|
|
|
67
69
|
if (selectedId !== null && !selectableIds.has(selectedId)) throw new SparkError("E_INVALID_ARGUMENT", "Selected sidebar ID must identify a selectable row");
|
|
68
70
|
const control = useControl({ ref, onError }, getSidebarAvailability());
|
|
69
71
|
const [selectionRevision, revise] = useState(0);
|
|
72
|
+
const [rowWidth, setRowWidth] = useState<number>();
|
|
70
73
|
function selection(event: NativeSyntheticEvent<{ id: string }>) {
|
|
71
74
|
if (!control.active()) return;
|
|
72
75
|
const id = event?.nativeEvent?.id;
|
|
@@ -79,13 +82,21 @@ export function Sidebar({ items, children, selectedId, contentInsetTop = 0, defa
|
|
|
79
82
|
catch (cause) { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar layout", { cause })); return; }
|
|
80
83
|
onContentLayout?.({ width: event.nativeEvent.width, height: event.nativeEvent.height });
|
|
81
84
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
function rowLayout(event: NativeSyntheticEvent<{ width: number }>) {
|
|
86
|
+
if (!control.active()) return;
|
|
87
|
+
try { finite(event?.nativeEvent?.width, "row width"); }
|
|
88
|
+
catch (cause) { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar row layout", { cause })); return; }
|
|
89
|
+
setRowWidth(event.nativeEvent.width);
|
|
90
|
+
}
|
|
91
|
+
const context = useMemo(() => ({ rowWidth }), [rowWidth]);
|
|
92
|
+
if (control.failed) return <View {...props} ref={control.ref}><SidebarContext.Provider value={context}>{items?.map(item => <Text key={item.id}>{item.label}</Text>) ?? children}</SidebarContext.Provider></View>;
|
|
93
|
+
return <NativeSidebar {...props} ref={control.ref} itemsJson={itemsJson} selectedId={selectedId ?? ""} selectionRevision={selectionRevision} contentInsetTop={contentInsetTop} defaultRowHeight={defaultRowHeight} onSidebarLayout={layout} onSidebarRowLayout={rowLayout} onSidebarSelectionChange={selection}>
|
|
94
|
+
<SidebarContext.Provider value={context}>{children}</SidebarContext.Provider>
|
|
85
95
|
</NativeSidebar>;
|
|
86
96
|
}
|
|
87
|
-
export function SidebarItem({ id, children, rowHeight, selectable = true, onContextMenu, ref, onError, ...props }: SidebarItemProps) {
|
|
88
|
-
|
|
97
|
+
export function SidebarItem({ id, children, rowHeight, selectable = true, onContextMenu, ref, onError, style, ...props }: SidebarItemProps) {
|
|
98
|
+
const sidebar = useContext(SidebarContext);
|
|
99
|
+
if (!sidebar) throw new SparkError("E_INVALID_ARGUMENT", "SidebarItem requires a Sidebar parent");
|
|
89
100
|
identifier(id, "sidebar ID"); callback(onContextMenu, "context menu");
|
|
90
101
|
if (rowHeight !== undefined && rowHeight !== "auto") finite(rowHeight, "row height", 1);
|
|
91
102
|
if (typeof selectable !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "Expected selectable boolean");
|
|
@@ -99,6 +110,6 @@ export function SidebarItem({ id, children, rowHeight, selectable = true, onCont
|
|
|
99
110
|
} catch (cause) { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar context menu event", { cause })); return; }
|
|
100
111
|
onContextMenu?.({ id, position: { x: data.x, y: data.y }, windowPosition: { x: data.pageX, y: data.pageY }, modifiers: { alt: data.altKey, control: data.ctrlKey, meta: data.metaKey, shift: data.shiftKey } });
|
|
101
112
|
}
|
|
102
|
-
if (control.failed) return <View {...props} ref={control.ref}>{children}</View>;
|
|
103
|
-
return <NativeSidebarItem {...props} ref={control.ref} itemId={id} autoHeight={rowHeight === "auto"} rowHeight={typeof rowHeight === "number" ? rowHeight : 0} selectable={selectable} onRightClick={contextMenu}>{children}</NativeSidebarItem>;
|
|
113
|
+
if (control.failed) return <View {...props} style={style} ref={control.ref}>{children}</View>;
|
|
114
|
+
return <NativeSidebarItem {...props} style={sidebar.rowWidth === undefined ? style : [style, { width: sidebar.rowWidth }]} ref={control.ref} itemId={id} autoHeight={rowHeight === "auto"} rowHeight={typeof rowHeight === "number" ? rowHeight : 0} selectable={selectable} onRightClick={contextMenu}>{children}</NativeSidebarItem>;
|
|
104
115
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import "RNDesktopUpdates.h"
|
|
2
2
|
#import <RNDesktopApp/SparkDesktop.h>
|
|
3
3
|
#import <Sparkle/Sparkle.h>
|
|
4
|
+
#import "SparkUpdateState.h"
|
|
4
5
|
|
|
5
6
|
@interface SparkUpdater : NSObject <SPUUpdaterDelegate>
|
|
6
7
|
@property SPUStandardUpdaterController *controller;
|
|
@@ -22,10 +23,18 @@ static NSString *UnavailableReason(void) {
|
|
|
22
23
|
+ (instancetype)shared { static SparkUpdater *updater; static dispatch_once_t once; dispatch_once(&once, ^{ updater = [SparkUpdater new]; }); return updater; }
|
|
23
24
|
- (NSDictionary *)status {
|
|
24
25
|
NSString *reason = UnavailableReason();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (reason) return @{ @"available": @NO, @"reason": reason, @"started": @NO, @"canCheck": @NO, @"automaticallyChecks": @NO, @"checkIntervalSeconds": NSNull.null, @"skippedBuild": NSNull.null, @"skippedMajorBuild": NSNull.null, @"lastCheckedAt": NSNull.null };
|
|
27
|
+
// Settings read the persisted preferences without starting Sparkle.
|
|
28
|
+
SPUUpdater *updater = self.started ? self.controller.updater : nil;
|
|
29
|
+
SPUUpdaterSettings *settings = updater ? nil : [[SPUUpdaterSettings alloc] initWithHostBundle:NSBundle.mainBundle];
|
|
30
|
+
NSDate *checked = updater.lastUpdateCheckDate;
|
|
31
|
+
NSMutableDictionary *status = [SparkSkippedUpdates(SparkUpdateDefaults(NSBundle.mainBundle)) mutableCopy];
|
|
32
|
+
[status addEntriesFromDictionary:@{ @"available": @YES, @"started": @(self.started), @"canCheck": @(updater.canCheckForUpdates),
|
|
33
|
+
@"automaticallyChecks": @(updater ? updater.automaticallyChecksForUpdates : settings.automaticallyChecksForUpdates),
|
|
34
|
+
@"checkIntervalSeconds": @(updater ? updater.updateCheckInterval : settings.updateCheckInterval),
|
|
35
|
+
@"feedURL": [NSBundle.mainBundle objectForInfoDictionaryKey:@"SUFeedURL"],
|
|
36
|
+
@"lastCheckedAt": checked ? [[NSISO8601DateFormatter new] stringFromDate:checked] : NSNull.null }];
|
|
37
|
+
return status;
|
|
29
38
|
}
|
|
30
39
|
- (BOOL)start:(NSError **)error {
|
|
31
40
|
if (self.started) return YES;
|
|
@@ -33,19 +42,18 @@ static NSString *UnavailableReason(void) {
|
|
|
33
42
|
self.started = [self.controller.updater startUpdater:error];
|
|
34
43
|
return self.started;
|
|
35
44
|
}
|
|
36
|
-
- (void)event:(NSString *)state item:(SUAppcastItem *)item error:(NSError *)error {
|
|
37
|
-
NSMutableDictionary *event = [@{ @"type": @"update", @"state": state } mutableCopy];
|
|
38
|
-
if (item) event[@"version"] = item.displayVersionString;
|
|
39
|
-
if (error) event[@"message"] = error.localizedDescription;
|
|
40
|
-
SparkEmit(event);
|
|
41
|
-
}
|
|
45
|
+
- (void)event:(NSString *)state item:(SUAppcastItem *)item error:(NSError *)error { SparkEmit(SparkUpdateEvent(state, item, error)); }
|
|
42
46
|
- (BOOL)updater:(SPUUpdater *)updater mayPerformUpdateCheck:(SPUUpdateCheck)check error:(NSError **)error { [self event:@"checking" item:nil error:nil]; return YES; }
|
|
43
47
|
- (void)updater:(SPUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item { [self event:@"available" item:item error:nil]; }
|
|
44
48
|
- (void)updaterDidNotFindUpdate:(SPUUpdater *)updater error:(NSError *)error { [self event:@"notAvailable" item:nil error:nil]; }
|
|
45
49
|
- (void)updater:(SPUUpdater *)updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request { [self event:@"downloading" item:item error:nil]; }
|
|
50
|
+
- (void)updater:(SPUUpdater *)updater userDidMakeChoice:(SPUUserUpdateChoice)choice forUpdate:(SUAppcastItem *)item state:(SPUUserUpdateState *)state {
|
|
51
|
+
if (choice == SPUUserUpdateChoiceSkip) [self event:@"skipped" item:item error:nil];
|
|
52
|
+
}
|
|
46
53
|
- (void)updater:(SPUUpdater *)updater didDownloadUpdate:(SUAppcastItem *)item { [self event:@"downloaded" item:item error:nil]; }
|
|
47
54
|
- (void)updater:(SPUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item { [self event:@"installing" item:item error:nil]; }
|
|
48
|
-
- (void)
|
|
55
|
+
- (void)userDidCancelDownload:(SPUUpdater *)updater { [self event:@"cancelled" item:nil error:nil]; }
|
|
56
|
+
- (void)updater:(SPUUpdater *)updater didAbortWithError:(NSError *)error { NSDictionary *event = SparkUpdateAbortEvent(error); if (event) SparkEmit(event); }
|
|
49
57
|
@end
|
|
50
58
|
@implementation RNDesktopUpdates
|
|
51
59
|
RCT_EXPORT_MODULE(NativeDesktopUpdates)
|
|
@@ -55,17 +63,21 @@ RCT_EXPORT_MODULE(NativeDesktopUpdates)
|
|
|
55
63
|
[NSRunLoop.mainRunLoop performBlock:^{
|
|
56
64
|
SparkUpdater *updater = [SparkUpdater shared];
|
|
57
65
|
if ([method isEqual:@"status"]) { resolve(SparkJSON([updater status])); return; }
|
|
58
|
-
if (![@[@"start", @"check", @"background", @"configure"] containsObject:method]) { SparkInvalid(reject, @"Unknown update operation"); return; }
|
|
66
|
+
if (![@[@"start", @"check", @"background", @"configure", @"clearSkipped"] containsObject:method]) { SparkInvalid(reject, @"Unknown update operation"); return; }
|
|
59
67
|
NSDictionary *args = SparkArgs(json);
|
|
60
68
|
if ([method isEqual:@"configure"]) {
|
|
61
69
|
id enabled = args[@"automaticallyChecks"], interval = args[@"checkIntervalSeconds"];
|
|
62
70
|
if ((enabled && (![enabled isKindOfClass:NSNumber.class] || CFGetTypeID((__bridge CFTypeRef)enabled) != CFBooleanGetTypeID())) ||
|
|
63
|
-
(interval && (![interval isKindOfClass:NSNumber.class] || CFGetTypeID((__bridge CFTypeRef)interval) == CFBooleanGetTypeID() || !isfinite([interval doubleValue]) || [interval doubleValue]
|
|
71
|
+
(interval && (![interval isKindOfClass:NSNumber.class] || CFGetTypeID((__bridge CFTypeRef)interval) == CFBooleanGetTypeID() || !isfinite([interval doubleValue]) || [interval doubleValue] < 3600))) {
|
|
64
72
|
SparkInvalid(reject, @"Invalid updater configuration"); return;
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
NSString *reason = UnavailableReason();
|
|
68
76
|
if (reason) { reject(@"E_UNAVAILABLE", [@"Updates require a configured standalone release app; current state: " stringByAppendingString:reason], nil); return; }
|
|
77
|
+
if ([method isEqual:@"clearSkipped"]) {
|
|
78
|
+
SparkClearSkippedUpdates(SparkUpdateDefaults(NSBundle.mainBundle));
|
|
79
|
+
resolve(@"null"); return;
|
|
80
|
+
}
|
|
69
81
|
NSError *error = nil;
|
|
70
82
|
if (![updater start:&error]) { reject(@"E_NATIVE", error.localizedDescription ?: @"Could not start updater", error); return; }
|
|
71
83
|
if ([method isEqual:@"check"]) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Sparkle-to-Spark mapping shared by the module and tests/sparkle-updater.m,
|
|
2
|
+
// which exercises it against the real Sparkle framework.
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
#import <Sparkle/Sparkle.h>
|
|
5
|
+
|
|
6
|
+
// Sparkle 2.9.6 (pinned in the podspec) stores "Skip This Version" in the host's
|
|
7
|
+
// defaults (SPUSkippedUpdate.m); its API is private. A minor skip stores the
|
|
8
|
+
// skipped CFBundleVersion; a major-upgrade skip stores the item's
|
|
9
|
+
// minimumAutoupdateVersion plus the skipped CFBundleVersion.
|
|
10
|
+
static inline NSUserDefaults *SparkUpdateDefaults(NSBundle *host) {
|
|
11
|
+
id domain = [host objectForInfoDictionaryKey:@"SUDefaultsDomain"];
|
|
12
|
+
if (![domain isKindOfClass:NSString.class]) domain = [host isEqual:NSBundle.mainBundle] ? nil : host.bundleIdentifier;
|
|
13
|
+
return domain ? [[NSUserDefaults alloc] initWithSuiteName:domain] : NSUserDefaults.standardUserDefaults;
|
|
14
|
+
}
|
|
15
|
+
static inline NSDictionary *SparkSkippedUpdates(NSUserDefaults *defaults) {
|
|
16
|
+
return @{ @"skippedBuild": [defaults stringForKey:@"SUSkippedVersion"] ?: NSNull.null,
|
|
17
|
+
@"skippedMajorBuild": [defaults stringForKey:@"SUSkippedMajorSubreleaseVersion"] ?: NSNull.null };
|
|
18
|
+
}
|
|
19
|
+
static inline void SparkClearSkippedUpdates(NSUserDefaults *defaults) {
|
|
20
|
+
for (NSString *key in @[@"SUSkippedVersion", @"SUSkippedMajorVersion", @"SUSkippedMajorSubreleaseVersion"]) [defaults removeObjectForKey:key];
|
|
21
|
+
}
|
|
22
|
+
// `build` is the CFBundleVersion Sparkle orders, skips and selects deltas by;
|
|
23
|
+
// `version` is the display version. Sparkle hands willDownloadUpdate the delta
|
|
24
|
+
// item when it chose one and calls it again with the full item when it falls back.
|
|
25
|
+
static inline NSDictionary *SparkUpdateEvent(NSString *state, SUAppcastItem *item, NSError *error) {
|
|
26
|
+
NSMutableDictionary *event = [@{ @"type": @"update", @"state": state } mutableCopy];
|
|
27
|
+
if (item) { event[@"version"] = item.displayVersionString; event[@"build"] = item.versionString; }
|
|
28
|
+
if ([state isEqual:@"downloading"]) event[@"delta"] = @(item.isDeltaUpdate);
|
|
29
|
+
if ([state isEqual:@"skipped"]) event[@"major"] = @(item.isMajorUpgrade);
|
|
30
|
+
if (error) event[@"message"] = error.localizedDescription;
|
|
31
|
+
return event;
|
|
32
|
+
}
|
|
33
|
+
static inline NSDictionary *SparkUpdateAbortEvent(NSError *error) {
|
|
34
|
+
if ([error.domain isEqual:SUSparkleErrorDomain]) {
|
|
35
|
+
if (error.code == SUNoUpdateError) return nil; // Already reported by updaterDidNotFindUpdate.
|
|
36
|
+
if (error.code == SUInstallationCanceledError) return SparkUpdateEvent(@"cancelled", nil, nil);
|
|
37
|
+
}
|
|
38
|
+
return SparkUpdateEvent(@"error", nil, error);
|
|
39
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-updates",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@legendapp/spark-desktop-app": "0.0.1-next.
|
|
41
|
+
"@legendapp/spark-desktop-app": "0.0.1-next.8"
|
|
42
42
|
},
|
|
43
43
|
"private": true
|
|
44
44
|
}
|
|
@@ -5,13 +5,24 @@ import { SparkError, invokeNative, parseNativeResult, type Subscription } from "
|
|
|
5
5
|
export type { Subscription } from "@legendapp/spark-desktop-app/src/contracts";
|
|
6
6
|
|
|
7
7
|
export type UpdateUnavailableReason = "unsupported-platform" | "missing-module" | "go" | "development" | "unconfigured";
|
|
8
|
+
export type UpdateAvailability = { available: true } | { available: false; reason: UpdateUnavailableReason };
|
|
8
9
|
export type UpdateStatus = {
|
|
9
10
|
available: true;
|
|
10
11
|
started: boolean;
|
|
11
12
|
canCheck: boolean;
|
|
13
|
+
/** The persisted Sparkle preference, readable before the updater starts. */
|
|
12
14
|
automaticallyChecks: boolean;
|
|
13
15
|
checkIntervalSeconds: number;
|
|
14
16
|
feedURL: string;
|
|
17
|
+
/**
|
|
18
|
+
* Build (CFBundleVersion, the `build` of the `skipped` event) the user skipped with "Skip This Version".
|
|
19
|
+
* Background checks stop offering it and older builds; an interactive check offers them and clears the choice.
|
|
20
|
+
*/
|
|
21
|
+
skippedBuild: string | null;
|
|
22
|
+
/** Build of a skipped major upgrade (an item whose `minimumAutoupdateVersion` this app does not meet). Background checks stop offering major upgrades with the same requirement. */
|
|
23
|
+
skippedMajorBuild: string | null;
|
|
24
|
+
/** ISO time of the last completed check; null until the updater has started and checked. */
|
|
25
|
+
lastCheckedAt: string | null;
|
|
15
26
|
} | {
|
|
16
27
|
available: false;
|
|
17
28
|
reason: UpdateUnavailableReason;
|
|
@@ -19,24 +30,36 @@ export type UpdateStatus = {
|
|
|
19
30
|
canCheck: false;
|
|
20
31
|
automaticallyChecks: false;
|
|
21
32
|
checkIntervalSeconds: null;
|
|
33
|
+
skippedBuild: null;
|
|
34
|
+
skippedMajorBuild: null;
|
|
35
|
+
lastCheckedAt: null;
|
|
22
36
|
};
|
|
37
|
+
/** Sparkle's Release minimum. Shorter intervals would be silently clamped, so they are rejected. */
|
|
38
|
+
export const MINIMUM_UPDATE_CHECK_INTERVAL_SECONDS = 3600;
|
|
23
39
|
export interface UpdateConfiguration { automaticallyChecks?: boolean; checkIntervalSeconds?: number }
|
|
24
40
|
export interface CheckForUpdatesOptions { mode?: "interactive" | "background" }
|
|
41
|
+
/** `version` is the display version; `build` is the CFBundleVersion Sparkle orders, skips and selects deltas by. */
|
|
42
|
+
type UpdateItem = { type: "update"; version: string; build: string };
|
|
25
43
|
export type UpdateEvent =
|
|
26
|
-
| { type: "update"; state: "checking" | "notAvailable" }
|
|
27
|
-
|
|
|
44
|
+
| { type: "update"; state: "checking" | "notAvailable" | "cancelled" }
|
|
45
|
+
| UpdateItem & { state: "available" | "downloaded" | "installing" }
|
|
46
|
+
/** `delta` is true while Sparkle downloads a delta archive for the installed build; a failed delta is followed by another event with `delta: false` for the full archive. */
|
|
47
|
+
| UpdateItem & { state: "downloading"; delta: boolean }
|
|
48
|
+
/** `major` is true when the skipped item was a major upgrade (reported as `skippedMajorBuild`). */
|
|
49
|
+
| UpdateItem & { state: "skipped"; major: boolean }
|
|
28
50
|
| { type: "update"; state: "error"; message: string };
|
|
29
51
|
function native() {
|
|
30
52
|
if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "Native app updates require macOS");
|
|
31
53
|
if (!Native) throw new SparkError("E_MODULE_UNAVAILABLE", "Native app updater is not installed");
|
|
32
54
|
return Native;
|
|
33
55
|
}
|
|
34
|
-
const unavailable = (reason: UpdateUnavailableReason): UpdateStatus => ({ available: false, reason, started: false, canCheck: false, automaticallyChecks: false, checkIntervalSeconds: null });
|
|
56
|
+
const unavailable = (reason: UpdateUnavailableReason): UpdateStatus => ({ available: false, reason, started: false, canCheck: false, automaticallyChecks: false, checkIntervalSeconds: null, skippedBuild: null, skippedMajorBuild: null, lastCheckedAt: null });
|
|
57
|
+
const nullableString = (value: unknown) => value === null || typeof value === "string";
|
|
35
58
|
function validStatus(value: unknown): value is UpdateStatus {
|
|
36
59
|
if (!value || typeof value !== "object") return false;
|
|
37
60
|
const status = value as UpdateStatus;
|
|
38
|
-
if (status.available === false) return ["go", "development", "unconfigured"].includes(status.reason) && status.started === false && status.canCheck === false && status.automaticallyChecks === false && status.checkIntervalSeconds === null;
|
|
39
|
-
return status.available === true && typeof status.started === "boolean" && typeof status.canCheck === "boolean" && typeof status.automaticallyChecks === "boolean" && Number.isFinite(status.checkIntervalSeconds) && status.checkIntervalSeconds > 0 && typeof status.feedURL === "string" && status.feedURL.startsWith("https://");
|
|
61
|
+
if (status.available === false) return ["go", "development", "unconfigured"].includes(status.reason) && status.started === false && status.canCheck === false && status.automaticallyChecks === false && status.checkIntervalSeconds === null && status.skippedBuild === null && status.skippedMajorBuild === null && status.lastCheckedAt === null;
|
|
62
|
+
return status.available === true && typeof status.started === "boolean" && typeof status.canCheck === "boolean" && typeof status.automaticallyChecks === "boolean" && Number.isFinite(status.checkIntervalSeconds) && status.checkIntervalSeconds > 0 && typeof status.feedURL === "string" && status.feedURL.startsWith("https://") && nullableString(status.skippedBuild) && nullableString(status.skippedMajorBuild) && nullableString(status.lastCheckedAt);
|
|
40
63
|
}
|
|
41
64
|
async function command(method: string, args: object = {}): Promise<void> {
|
|
42
65
|
parseNativeResult(await invokeNative(() => native().call(method, JSON.stringify(args))), (value): value is null => value === null);
|
|
@@ -47,13 +70,21 @@ export async function getUpdateStatus(): Promise<UpdateStatus> {
|
|
|
47
70
|
if (!Native) return unavailable("missing-module");
|
|
48
71
|
return parseNativeResult(await invokeNative(() => native().call("status", "{}")), validStatus);
|
|
49
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Whether this app can self-update. Never starts the updater. Windows reports `unsupported-platform`:
|
|
75
|
+
* Spark's Windows target is development-only (no release build or distribution packaging), so there is no installed release to update.
|
|
76
|
+
*/
|
|
77
|
+
export async function getUpdateAvailability(): Promise<UpdateAvailability> {
|
|
78
|
+
const status = await getUpdateStatus();
|
|
79
|
+
return status.available ? { available: true } : { available: false, reason: status.reason };
|
|
80
|
+
}
|
|
50
81
|
/** Start the scheduler after app readiness. Repeated starts are safe. */
|
|
51
82
|
export async function startUpdates(): Promise<void> { await command("start"); }
|
|
52
83
|
function options(value: unknown, keys: string[]) {
|
|
53
84
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new SparkError("E_INVALID_ARGUMENT", "Expected update options");
|
|
54
85
|
for (const key of Object.keys(value)) if (!keys.includes(key)) throw new SparkError("E_UNSUPPORTED_OPTION", `Unsupported update option: ${key}`);
|
|
55
86
|
}
|
|
56
|
-
/** Resolves when initiated. Events describe progress, not the returned promise. */
|
|
87
|
+
/** Resolves when initiated. Events describe progress, not the returned promise. Interactive checks also offer skipped builds and, like every user-initiated Sparkle check, clear the skip choice. */
|
|
57
88
|
export async function checkForUpdates(config: CheckForUpdatesOptions = {}): Promise<void> {
|
|
58
89
|
options(config, ["mode"]);
|
|
59
90
|
const mode = config.mode ?? "interactive";
|
|
@@ -64,16 +95,21 @@ export async function checkForUpdates(config: CheckForUpdatesOptions = {}): Prom
|
|
|
64
95
|
export async function configureUpdates(config: UpdateConfiguration): Promise<void> {
|
|
65
96
|
options(config, ["automaticallyChecks", "checkIntervalSeconds"]);
|
|
66
97
|
if (config.automaticallyChecks !== undefined && typeof config.automaticallyChecks !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "automaticallyChecks must be boolean");
|
|
67
|
-
if (config.checkIntervalSeconds !== undefined && (!Number.isFinite(config.checkIntervalSeconds) || config.checkIntervalSeconds
|
|
98
|
+
if (config.checkIntervalSeconds !== undefined && (!Number.isFinite(config.checkIntervalSeconds) || config.checkIntervalSeconds < MINIMUM_UPDATE_CHECK_INTERVAL_SECONDS)) throw new SparkError("E_INVALID_ARGUMENT", `Update interval must be finite and at least ${MINIMUM_UPDATE_CHECK_INTERVAL_SECONDS} seconds`);
|
|
68
99
|
await command("configure", config);
|
|
69
100
|
}
|
|
101
|
+
/** Forget the user's "Skip This Version" choices (`skippedBuild` and `skippedMajorBuild`) so background checks offer them again. */
|
|
102
|
+
export async function clearSkippedUpdate(): Promise<void> { await command("clearSkipped"); }
|
|
103
|
+
// Item states and the boolean flag each one carries.
|
|
104
|
+
const itemFlags = new Map<string, string | undefined>([["available", undefined], ["downloaded", undefined], ["installing", undefined], ["downloading", "delta"], ["skipped", "major"]]);
|
|
70
105
|
export function onUpdateEvent(listener: (event: UpdateEvent) => void): Subscription {
|
|
71
106
|
if (typeof listener !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Expected an update listener");
|
|
72
107
|
native();
|
|
73
108
|
return onDesktopEvent(event => {
|
|
74
109
|
if (event.type !== "update" || typeof event.state !== "string") return;
|
|
75
|
-
const
|
|
76
|
-
const
|
|
110
|
+
const flag = itemFlags.get(event.state);
|
|
111
|
+
const item = itemFlags.has(event.state) && typeof event.version === "string" && typeof event.build === "string" && (!flag || typeof event[flag] === "boolean");
|
|
112
|
+
const valid = ["checking", "notAvailable", "cancelled"].includes(event.state) || item || (event.state === "error" && typeof event.message === "string");
|
|
77
113
|
if (valid) listener(event as unknown as UpdateEvent);
|
|
78
114
|
}, { types: ["update"] });
|
|
79
115
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-webview",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"react-native-webview": "16.0.0",
|
|
12
|
-
"@legendapp/spark-desktop-app": "0.0.1-next.
|
|
12
|
+
"@legendapp/spark-desktop-app": "0.0.1-next.8"
|
|
13
13
|
},
|
|
14
14
|
"private": true
|
|
15
15
|
}
|