Skip to content

Commit 92d4b42

Browse files
committed
feat: implement support for sparkle channels
1 parent 93fee1d commit 92d4b42

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ English | [简体中文](./README-ZH.md)
3131
- [setFeedURL](#setfeedurl)
3232
- [checkForUpdates](#checkforupdates)
3333
- [setScheduledCheckInterval](#setscheduledcheckinterval)
34+
- [setAllowedChannels](#setallowedchannels)
3435
- [Related Links](#related-links)
3536
- [License](#license)
3637

@@ -72,6 +73,10 @@ Asks the server whether there is an update. You must call setFeedURL before usin
7273

7374
Sets the auto update check interval, default 86400, minimum 3600, 0 to disable update
7475

76+
##### setAllowedChannels
77+
78+
Sets which channels the app is allowed to receive updates from. On macOS this allows receiving updates from specific channels like 'beta' in addition to the default channel.
79+
7580
<!-- README_DOC_GEN -->
7681

7782
## Related Links

packages/auto_updater/lib/src/auto_updater.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ class AutoUpdater {
9696
Future<void> setScheduledCheckInterval(int interval) {
9797
return _platform.setScheduledCheckInterval(interval);
9898
}
99+
100+
/// Sets which channels the app is allowed to receive updates from.
101+
///
102+
/// On macOS this allows receiving updates from specific channels
103+
/// like 'beta' in addition to the default channel. If this is not called, the app will
104+
/// only receive updates from the default channel.
105+
///
106+
/// This has no effect on platforms other than macOS.
107+
///
108+
/// Example:
109+
/// ```dart
110+
/// // Allow updates from both default channel and beta channel
111+
/// autoUpdater.setAllowedChannels(['beta']);
112+
/// ```
113+
Future<void> setAllowedChannels(List<String> channels) {
114+
return _platform.setAllowedChannels(channels);
115+
}
99116
}
100117

101118
final autoUpdater = AutoUpdater.instance;

packages/auto_updater_macos/macos/Classes/AutoUpdater.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate {
4343
var _userDriver: SPUStandardUserDriver?
4444
var _updater: SPUUpdater?
4545
var feedURL: URL?
46+
var allowedChannels: Set<String>?
4647
public var onEvent:((String, NSDictionary) -> Void)?
4748

4849
override init() {
@@ -81,6 +82,10 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate {
8182
_updater?.updateCheckInterval = TimeInterval(interval)
8283
}
8384

85+
public func setAllowedChannels(_ channels: [String]) {
86+
self.allowedChannels = Set(channels)
87+
}
88+
8489
// SPUUpdaterDelegate
8590

8691
public func updater(_ updater: SPUUpdater, didAbortWithError error: Error) {
@@ -126,6 +131,10 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate {
126131
return true
127132
}
128133

134+
public func allowedChannels(for updater: SPUUpdater) -> Set<String>? {
135+
return allowedChannels
136+
}
137+
129138
public func _emitEvent(_ eventName: String, _ data: NSDictionary) {
130139
if (onEvent != nil) {
131140
onEvent!(eventName, data)

packages/auto_updater_macos/macos/Classes/AutoUpdaterMacosPlugin.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public class AutoUpdaterMacosPlugin: NSObject, FlutterPlugin,FlutterStreamHandle
5858
autoUpdater.setScheduledCheckInterval(interval)
5959
result(true)
6060
break
61+
case "setAllowedChannels":
62+
let channels = args["channels"] as! [String]
63+
autoUpdater.setAllowedChannels(channels)
64+
result(true)
65+
break
6166
default:
6267
result(FlutterMethodNotImplemented)
6368
}

packages/auto_updater_platform_interface/lib/src/auto_updater_method_channel.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ class MethodChannelAutoUpdater extends AutoUpdaterPlatform {
4444
};
4545
await methodChannel.invokeMethod('setScheduledCheckInterval', arguments);
4646
}
47+
48+
@override
49+
Future<void> setAllowedChannels(List<String> channels) async {
50+
final Map<String, dynamic> arguments = {
51+
'channels': channels,
52+
};
53+
await methodChannel.invokeMethod('setAllowedChannels', arguments);
54+
}
4755
}

packages/auto_updater_platform_interface/lib/src/auto_updater_platform_interface.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,15 @@ abstract class AutoUpdaterPlatform extends PlatformInterface {
4242
'setScheduledCheckInterval() has not been implemented.',
4343
);
4444
}
45+
46+
/// Sets which channels the app is allowed to receive updates from.
47+
///
48+
/// On macOS this allows receiving updates from specific channels
49+
/// like 'beta' in addition to the default channel. If this is not called, the app will
50+
/// only receive updates from the default channel.
51+
///
52+
/// This has no effect on platforms other than macOS. See https://github.com/vslavik/winsparkle/issues/248
53+
Future<void> setAllowedChannels(List<String> channels) async {
54+
throw UnimplementedError('setAllowedChannels() has not been implemented.');
55+
}
4556
}

0 commit comments

Comments
 (0)