Skip to content

Commit 40c7e08

Browse files
committed
feat: implement support for sparkle channels
1 parent 93fee1d commit 40c7e08

File tree

13 files changed

+83
-5
lines changed

13 files changed

+83
-5
lines changed

README.md

+5
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/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.0
2+
3+
* [macos] Add support for Sparkle channels via new `setAllowedChannels` method (#74)
4+
15
## 1.0.0
26

37
* First major release.

packages/auto_updater/example/lib/pages/home.dart

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class _HomePageState extends State<HomePage> with UpdaterListener {
4949
await autoUpdater.setScheduledCheckInterval(3600);
5050
}
5151

52+
Future<void> _handleClickSetAllowedChannels() async {
53+
await autoUpdater.setAllowedChannels(['beta']);
54+
BotToast.showText(text: 'Allowed channels set to: beta');
55+
}
56+
5257
Widget _buildBody(BuildContext context) {
5358
return ListView(
5459
children: <Widget>[
@@ -80,6 +85,12 @@ class _HomePageState extends State<HomePage> with UpdaterListener {
8085
_handleClickSetScheduledCheckInterval();
8186
},
8287
),
88+
ListTile(
89+
title: const Text('setAllowedChannels'),
90+
onTap: () {
91+
_handleClickSetAllowedChannels();
92+
},
93+
),
8394
],
8495
),
8596
],

packages/auto_updater/lib/src/auto_updater.dart

+17
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/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: auto_updater
22
description: This plugin allows Flutter desktop apps to automatically update themselves (based on sparkle and winsparkle).
3-
version: 1.0.0
3+
version: 1.1.0
44
homepage: https://github.com/leanflutter/auto_updater
55

66
platforms:
@@ -15,8 +15,8 @@ environment:
1515
flutter: ">=3.3.0"
1616

1717
dependencies:
18-
auto_updater_macos: ^1.0.0
19-
auto_updater_platform_interface: ^1.0.0
18+
auto_updater_macos: ^1.1.0
19+
auto_updater_platform_interface: ^1.1.0
2020
auto_updater_windows: ^1.0.0
2121
flutter:
2222
sdk: flutter

packages/auto_updater_macos/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.0
2+
3+
* Add support for Sparkle channels via new `setAllowedChannels` method and the `allowedChannels` delegate.
4+
15
## 1.0.0
26

37
* First major release.

packages/auto_updater_macos/macos/Classes/AutoUpdater.swift

+9
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 ?? Set<String>()
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

+5
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_macos/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: auto_updater_macos
22
description: macOS implementation of the auto_updater plugin.
3-
version: 1.0.0
3+
version: 1.1.0
44
repository: https://github.com/leanflutter/auto_updater/tree/main/packages/auto_updater_macos
55

66
environment:

packages/auto_updater_platform_interface/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.0
2+
3+
* Add support for Sparkle channels via new `setAllowedChannels` method.
4+
15
## 1.0.0
26

37
* First major release.

packages/auto_updater_platform_interface/lib/src/auto_updater_method_channel.dart

+8
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

+11
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
}

packages/auto_updater_platform_interface/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: auto_updater_platform_interface
22
description: A common platform interface for the auto_updater plugin.
3-
version: 1.0.0
3+
version: 1.1.0
44
homepage: https://github.com/leanflutter/auto_updater/blob/main/packages/auto_updater_platform_interface
55

66
environment:

0 commit comments

Comments
 (0)