Skip to content

Commit 47bd7a2

Browse files
committed
feat: expose cleanup api from WinSparkle
1 parent ce21def commit 47bd7a2

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

packages/auto_updater/lib/src/auto_updater.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ class AutoUpdater {
4040
Future<void> checkForUpdateInformation() =>
4141
_platform.checkForUpdateInformation();
4242

43+
/// Cleans up the auto updater.
44+
///
45+
/// Notes: this function is only available on Windows.
46+
Future<void> cleanup() => _platform.cleanup();
47+
4348
void _handleSparkleEvents(dynamic event) {
4449
final type = event['type'] as String;
4550
final eventType = UpdaterEvent.fromString(type);
46-
final eventData = event['data'] as Map<Object?, Object?>?;
47-
48-
if (eventData == null) return;
51+
final eventData = event['data'] as Map<Object?, Object?>? ?? {};
4952

5053
// Parse event data
5154
final updaterError = eventData['error'] != null

packages/auto_updater/lib/src/events.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,40 @@ enum UpdaterEvent {
2222
case 'error':
2323
return UpdaterEvent.error;
2424
case 'checking-for-update':
25+
case 'checkingForUpdate':
2526
return UpdaterEvent.checkingForUpdate;
2627
case 'update-available':
28+
case 'updateAvailable':
2729
return UpdaterEvent.updateAvailable;
2830
case 'update-not-available':
31+
case 'updateNotAvailable':
2932
return UpdaterEvent.updateNotAvailable;
3033
case 'update-downloaded':
34+
case 'updateDownloaded':
3135
return UpdaterEvent.updateDownloaded;
3236
case 'before-quit-for-update':
37+
case 'beforeQuitForUpdate':
3338
return UpdaterEvent.beforeQuitForUpdate;
3439
case 'user-update-choice':
40+
case 'userUpdateChoice':
3541
return UpdaterEvent.userUpdateChoice;
3642
case 'update-cancelled':
43+
case 'updateCancelled':
3744
return UpdaterEvent.updateCancelled;
3845
case 'update-skipped':
46+
case 'updateSkipped':
3947
return UpdaterEvent.updateSkipped;
4048
case 'update-installed':
49+
case 'updateInstalled':
4150
return UpdaterEvent.updateInstalled;
4251
case 'update-postponed':
52+
case 'updatePostponed':
4353
return UpdaterEvent.updatePostponed;
4454
case 'update-dismissed':
55+
case 'updateDismissed':
4556
return UpdaterEvent.updateDismissed;
4657
case 'user-run-installer':
58+
case 'userRunInstaller':
4759
return UpdaterEvent.userRunInstaller;
4860
default:
4961
throw ArgumentError('Invalid event name: $name');

packages/auto_updater_windows/windows/auto_updater.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AutoUpdater {
3232
void AutoUpdater::CheckForUpdates();
3333
void AutoUpdater::CheckForUpdatesWithoutUI();
3434
void AutoUpdater::SetScheduledCheckInterval(int interval);
35+
void AutoUpdater::Cleanup();
3536

3637
void AutoUpdater::RegisterEventSink(
3738
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> ptr);
@@ -87,6 +88,10 @@ void AutoUpdater::SetScheduledCheckInterval(int interval) {
8788
win_sparkle_set_update_check_interval(interval);
8889
}
8990

91+
void AutoUpdater::Cleanup() {
92+
win_sparkle_cleanup();
93+
}
94+
9095
void AutoUpdater::RegisterEventSink(
9196
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> ptr) {
9297
event_sink_ = std::move(ptr);

packages/auto_updater_windows/windows/auto_updater_windows_plugin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ void AutoUpdaterWindowsPlugin::HandleMethodCall(
9191
std::get<flutter::EncodableMap>(*method_call.arguments());
9292
auto_updater.CheckForUpdatesWithoutUI();
9393
result->Success(flutter::EncodableValue(true));
94+
95+
} else if (method_name.compare("cleanup") == 0) {
96+
auto_updater.Cleanup();
97+
result->Success(flutter::EncodableValue(true));
98+
9499
} else {
95100
result->NotImplemented();
101+
96102
}
97103
}
98104

0 commit comments

Comments
 (0)