From 40c7e08696088f3aec499d8ffb63275460063587 Mon Sep 17 00:00:00 2001 From: Ben Hagen Date: Wed, 23 Apr 2025 18:15:50 +0200 Subject: [PATCH] feat: implement support for sparkle channels --- README.md | 5 +++++ packages/auto_updater/CHANGELOG.md | 4 ++++ .../auto_updater/example/lib/pages/home.dart | 11 +++++++++++ packages/auto_updater/lib/src/auto_updater.dart | 17 +++++++++++++++++ packages/auto_updater/pubspec.yaml | 6 +++--- packages/auto_updater_macos/CHANGELOG.md | 4 ++++ .../macos/Classes/AutoUpdater.swift | 9 +++++++++ .../macos/Classes/AutoUpdaterMacosPlugin.swift | 5 +++++ packages/auto_updater_macos/pubspec.yaml | 2 +- .../CHANGELOG.md | 4 ++++ .../lib/src/auto_updater_method_channel.dart | 8 ++++++++ .../src/auto_updater_platform_interface.dart | 11 +++++++++++ .../pubspec.yaml | 2 +- 13 files changed, 83 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3c37183..1c8f216 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ English | [简体中文](./README-ZH.md) - [setFeedURL](#setfeedurl) - [checkForUpdates](#checkforupdates) - [setScheduledCheckInterval](#setscheduledcheckinterval) + - [setAllowedChannels](#setallowedchannels) - [Related Links](#related-links) - [License](#license) @@ -72,6 +73,10 @@ Asks the server whether there is an update. You must call setFeedURL before usin Sets the auto update check interval, default 86400, minimum 3600, 0 to disable update +##### setAllowedChannels + +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. + ## Related Links diff --git a/packages/auto_updater/CHANGELOG.md b/packages/auto_updater/CHANGELOG.md index 9e4d60f..e87f75d 100644 --- a/packages/auto_updater/CHANGELOG.md +++ b/packages/auto_updater/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +* [macos] Add support for Sparkle channels via new `setAllowedChannels` method (#74) + ## 1.0.0 * First major release. diff --git a/packages/auto_updater/example/lib/pages/home.dart b/packages/auto_updater/example/lib/pages/home.dart index 6100015..3eeb169 100644 --- a/packages/auto_updater/example/lib/pages/home.dart +++ b/packages/auto_updater/example/lib/pages/home.dart @@ -49,6 +49,11 @@ class _HomePageState extends State with UpdaterListener { await autoUpdater.setScheduledCheckInterval(3600); } + Future _handleClickSetAllowedChannels() async { + await autoUpdater.setAllowedChannels(['beta']); + BotToast.showText(text: 'Allowed channels set to: beta'); + } + Widget _buildBody(BuildContext context) { return ListView( children: [ @@ -80,6 +85,12 @@ class _HomePageState extends State with UpdaterListener { _handleClickSetScheduledCheckInterval(); }, ), + ListTile( + title: const Text('setAllowedChannels'), + onTap: () { + _handleClickSetAllowedChannels(); + }, + ), ], ), ], diff --git a/packages/auto_updater/lib/src/auto_updater.dart b/packages/auto_updater/lib/src/auto_updater.dart index 4f4bb2c..f23ef5e 100644 --- a/packages/auto_updater/lib/src/auto_updater.dart +++ b/packages/auto_updater/lib/src/auto_updater.dart @@ -96,6 +96,23 @@ class AutoUpdater { Future setScheduledCheckInterval(int interval) { return _platform.setScheduledCheckInterval(interval); } + + /// 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. If this is not called, the app will + /// only receive updates from the default channel. + /// + /// This has no effect on platforms other than macOS. + /// + /// Example: + /// ```dart + /// // Allow updates from both default channel and beta channel + /// autoUpdater.setAllowedChannels(['beta']); + /// ``` + Future setAllowedChannels(List channels) { + return _platform.setAllowedChannels(channels); + } } final autoUpdater = AutoUpdater.instance; diff --git a/packages/auto_updater/pubspec.yaml b/packages/auto_updater/pubspec.yaml index 8d4c2a8..47e155d 100644 --- a/packages/auto_updater/pubspec.yaml +++ b/packages/auto_updater/pubspec.yaml @@ -1,6 +1,6 @@ name: auto_updater description: This plugin allows Flutter desktop apps to automatically update themselves (based on sparkle and winsparkle). -version: 1.0.0 +version: 1.1.0 homepage: https://github.com/leanflutter/auto_updater platforms: @@ -15,8 +15,8 @@ environment: flutter: ">=3.3.0" dependencies: - auto_updater_macos: ^1.0.0 - auto_updater_platform_interface: ^1.0.0 + auto_updater_macos: ^1.1.0 + auto_updater_platform_interface: ^1.1.0 auto_updater_windows: ^1.0.0 flutter: sdk: flutter diff --git a/packages/auto_updater_macos/CHANGELOG.md b/packages/auto_updater_macos/CHANGELOG.md index ada13fa..48fc393 100644 --- a/packages/auto_updater_macos/CHANGELOG.md +++ b/packages/auto_updater_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +* Add support for Sparkle channels via new `setAllowedChannels` method and the `allowedChannels` delegate. + ## 1.0.0 * First major release. diff --git a/packages/auto_updater_macos/macos/Classes/AutoUpdater.swift b/packages/auto_updater_macos/macos/Classes/AutoUpdater.swift index 1525b32..d13627b 100644 --- a/packages/auto_updater_macos/macos/Classes/AutoUpdater.swift +++ b/packages/auto_updater_macos/macos/Classes/AutoUpdater.swift @@ -43,6 +43,7 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate { var _userDriver: SPUStandardUserDriver? var _updater: SPUUpdater? var feedURL: URL? + var allowedChannels: Set? public var onEvent:((String, NSDictionary) -> Void)? override init() { @@ -81,6 +82,10 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate { _updater?.updateCheckInterval = TimeInterval(interval) } + public func setAllowedChannels(_ channels: [String]) { + self.allowedChannels = Set(channels) + } + // SPUUpdaterDelegate public func updater(_ updater: SPUUpdater, didAbortWithError error: Error) { @@ -126,6 +131,10 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate { return true } + public func allowedChannels(for updater: SPUUpdater) -> Set { + return allowedChannels ?? Set() + } + public func _emitEvent(_ eventName: String, _ data: NSDictionary) { if (onEvent != nil) { onEvent!(eventName, data) diff --git a/packages/auto_updater_macos/macos/Classes/AutoUpdaterMacosPlugin.swift b/packages/auto_updater_macos/macos/Classes/AutoUpdaterMacosPlugin.swift index ddd2870..ab60d5b 100644 --- a/packages/auto_updater_macos/macos/Classes/AutoUpdaterMacosPlugin.swift +++ b/packages/auto_updater_macos/macos/Classes/AutoUpdaterMacosPlugin.swift @@ -58,6 +58,11 @@ public class AutoUpdaterMacosPlugin: NSObject, FlutterPlugin,FlutterStreamHandle autoUpdater.setScheduledCheckInterval(interval) result(true) break + case "setAllowedChannels": + let channels = args["channels"] as! [String] + autoUpdater.setAllowedChannels(channels) + result(true) + break default: result(FlutterMethodNotImplemented) } diff --git a/packages/auto_updater_macos/pubspec.yaml b/packages/auto_updater_macos/pubspec.yaml index f26e44f..39a9897 100644 --- a/packages/auto_updater_macos/pubspec.yaml +++ b/packages/auto_updater_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: auto_updater_macos description: macOS implementation of the auto_updater plugin. -version: 1.0.0 +version: 1.1.0 repository: https://github.com/leanflutter/auto_updater/tree/main/packages/auto_updater_macos environment: diff --git a/packages/auto_updater_platform_interface/CHANGELOG.md b/packages/auto_updater_platform_interface/CHANGELOG.md index ada13fa..d9ed0e8 100644 --- a/packages/auto_updater_platform_interface/CHANGELOG.md +++ b/packages/auto_updater_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +* Add support for Sparkle channels via new `setAllowedChannels` method. + ## 1.0.0 * First major release. diff --git a/packages/auto_updater_platform_interface/lib/src/auto_updater_method_channel.dart b/packages/auto_updater_platform_interface/lib/src/auto_updater_method_channel.dart index 9af60b9..a0a31c1 100644 --- a/packages/auto_updater_platform_interface/lib/src/auto_updater_method_channel.dart +++ b/packages/auto_updater_platform_interface/lib/src/auto_updater_method_channel.dart @@ -44,4 +44,12 @@ class MethodChannelAutoUpdater extends AutoUpdaterPlatform { }; await methodChannel.invokeMethod('setScheduledCheckInterval', arguments); } + + @override + Future setAllowedChannels(List channels) async { + final Map arguments = { + 'channels': channels, + }; + await methodChannel.invokeMethod('setAllowedChannels', arguments); + } } diff --git a/packages/auto_updater_platform_interface/lib/src/auto_updater_platform_interface.dart b/packages/auto_updater_platform_interface/lib/src/auto_updater_platform_interface.dart index cec1ac6..bb224ca 100644 --- a/packages/auto_updater_platform_interface/lib/src/auto_updater_platform_interface.dart +++ b/packages/auto_updater_platform_interface/lib/src/auto_updater_platform_interface.dart @@ -42,4 +42,15 @@ abstract class AutoUpdaterPlatform extends PlatformInterface { 'setScheduledCheckInterval() has not been implemented.', ); } + + /// 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. If this is not called, the app will + /// only receive updates from the default channel. + /// + /// This has no effect on platforms other than macOS. See https://github.com/vslavik/winsparkle/issues/248 + Future setAllowedChannels(List channels) async { + throw UnimplementedError('setAllowedChannels() has not been implemented.'); + } } diff --git a/packages/auto_updater_platform_interface/pubspec.yaml b/packages/auto_updater_platform_interface/pubspec.yaml index 1f82854..e2164ef 100644 --- a/packages/auto_updater_platform_interface/pubspec.yaml +++ b/packages/auto_updater_platform_interface/pubspec.yaml @@ -1,6 +1,6 @@ name: auto_updater_platform_interface description: A common platform interface for the auto_updater plugin. -version: 1.0.0 +version: 1.1.0 homepage: https://github.com/leanflutter/auto_updater/blob/main/packages/auto_updater_platform_interface environment: