Skip to content

Commit

Permalink
Merge pull request #12 from fanchou/main
Browse files Browse the repository at this point in the history
给macOS也增加静默检查更新
  • Loading branch information
lijy91 authored May 14, 2022
2 parents 028c2b6 + 853a5ec commit 9f7be3b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.5

* Add check update in background.

## 0.1.4

* Downgrade flutter version to 2.0.0 #7
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _HomePageState extends State<HomePage> {
}

void _handleClickCheckForUpdatesWithoutUI() async {
await autoUpdater.checkForUpdatesWithoutUI();
await autoUpdater.checkForUpdates(inBackground: true);
}

Widget _buildBody(BuildContext context) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/auto_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class AutoUpdater {
}

/// Asks the server whether there is an update. You must call setFeedURL before using this API.
Future<void> checkForUpdates() async {
await _channel.invokeMethod('checkForUpdates');
}
Future<void> checkForUpdatesWithoutUI() async {
await _channel.invokeMethod('checkForUpdatesWithoutUI');
Future<void> checkForUpdates({bool? inBackground}) async {
final Map<String, dynamic> arguments = {
'inBackground': inBackground ?? false,
};
await _channel.invokeMethod('checkForUpdates', arguments);
}
}

Expand Down
6 changes: 5 additions & 1 deletion macos/Classes/AutoUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public class AutoUpdater: NSObject, SPUUpdaterDelegate {
public func checkForUpdates() {
_updater?.checkForUpdates()
}


public func checkForUpdatesInBackground() {
_updater?.checkForUpdatesInBackground()
}

// SPUUpdaterDelegate

public func updater(_ updater: SPUUpdater, didAbortWithError error: Error) {
Expand Down
9 changes: 7 additions & 2 deletions macos/Classes/AutoUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class AutoUpdaterPlugin: NSObject, FlutterPlugin {

private var registrar: FlutterPluginRegistrar!;
private var channel: FlutterMethodChannel!

private var autoUpdater: AutoUpdater = AutoUpdater()

public init(_ registrar: FlutterPluginRegistrar, _ channel: FlutterMethodChannel) {
Expand All @@ -33,7 +33,12 @@ public class AutoUpdaterPlugin: NSObject, FlutterPlugin {
result(true)
break
case "checkForUpdates":
autoUpdater.checkForUpdates()
let inBackground = args["inBackground"] as! Bool
if(inBackground) {
autoUpdater.checkForUpdatesInBackground()
}else {
autoUpdater.checkForUpdates()
}
result(true)
break
default:
Expand Down
2 changes: 1 addition & 1 deletion 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: 0.1.4
version: 0.1.5
homepage: https://github.com/leanflutter/auto_updater

platforms:
Expand Down
15 changes: 10 additions & 5 deletions windows/auto_updater_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ void AutoUpdaterPlugin::HandleMethodCall(
auto_updater->SetFeedURL(feedURL);
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("checkForUpdates") == 0) {
auto_updater->CheckForUpdates();
result->Success(flutter::EncodableValue(true));
} else if(method_name.compare("checkForUpdatesWithoutUI") == 0){
auto_updater->CheckForUpdatesWithoutUI();
const flutter::EncodableMap& args =
std::get<flutter::EncodableMap>(*method_call.arguments());
bool inBackground =
std::get<bool>(args.at(flutter::EncodableValue("inBackground")));
if (inBackground) {
auto_updater->CheckForUpdatesWithoutUI();
} else {
auto_updater->CheckForUpdates();
}
result->Success(flutter::EncodableValue(true));
}else {
} else {
result->NotImplemented();
}
}
Expand Down

0 comments on commit 9f7be3b

Please sign in to comment.