Skip to content

feat: implement support for sparkle channels #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ English | [简体中文](./README-ZH.md)
- [setFeedURL](#setfeedurl)
- [checkForUpdates](#checkforupdates)
- [setScheduledCheckInterval](#setscheduledcheckinterval)
- [setAllowedChannels](#setallowedchannels)
- [Related Links](#related-links)
- [License](#license)

Expand Down Expand Up @@ -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.

<!-- README_DOC_GEN -->

## Related Links
Expand Down
4 changes: 4 additions & 0 deletions packages/auto_updater/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

* [macos] Add support for Sparkle channels via new `setAllowedChannels` method (#74)

## 1.0.0

* First major release.
Expand Down
11 changes: 11 additions & 0 deletions packages/auto_updater/example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class _HomePageState extends State<HomePage> with UpdaterListener {
await autoUpdater.setScheduledCheckInterval(3600);
}

Future<void> _handleClickSetAllowedChannels() async {
await autoUpdater.setAllowedChannels(['beta']);
BotToast.showText(text: 'Allowed channels set to: beta');
}

Widget _buildBody(BuildContext context) {
return ListView(
children: <Widget>[
Expand Down Expand Up @@ -80,6 +85,12 @@ class _HomePageState extends State<HomePage> with UpdaterListener {
_handleClickSetScheduledCheckInterval();
},
),
ListTile(
title: const Text('setAllowedChannels'),
onTap: () {
_handleClickSetAllowedChannels();
},
),
],
),
],
Expand Down
17 changes: 17 additions & 0 deletions packages/auto_updater/lib/src/auto_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ class AutoUpdater {
Future<void> 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<void> setAllowedChannels(List<String> channels) {
return _platform.setAllowedChannels(channels);
}
}

final autoUpdater = AutoUpdater.instance;
6 changes: 3 additions & 3 deletions packages/auto_updater/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/auto_updater_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 9 additions & 0 deletions packages/auto_updater_macos/macos/Classes/AutoUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate {
var _userDriver: SPUStandardUserDriver?
var _updater: SPUUpdater?
var feedURL: URL?
var allowedChannels: Set<String>?
public var onEvent:((String, NSDictionary) -> Void)?

override init() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -126,6 +131,10 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate {
return true
}

public func allowedChannels(for updater: SPUUpdater) -> Set<String> {
return allowedChannels ?? Set<String>()
}

public func _emitEvent(_ eventName: String, _ data: NSDictionary) {
if (onEvent != nil) {
onEvent!(eventName, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/auto_updater_macos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 4 additions & 0 deletions packages/auto_updater_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

* Add support for Sparkle channels via new `setAllowedChannels` method.

## 1.0.0

* First major release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ class MethodChannelAutoUpdater extends AutoUpdaterPlatform {
};
await methodChannel.invokeMethod('setScheduledCheckInterval', arguments);
}

@override
Future<void> setAllowedChannels(List<String> channels) async {
final Map<String, dynamic> arguments = {
'channels': channels,
};
await methodChannel.invokeMethod('setAllowedChannels', arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> setAllowedChannels(List<String> channels) async {
throw UnimplementedError('setAllowedChannels() has not been implemented.');
}
}
2 changes: 1 addition & 1 deletion packages/auto_updater_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down