Skip to content

Commit 18827a1

Browse files
committed
feat: expose cleanup api from WinSparkle
1 parent ce21def commit 18827a1

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

packages/auto_updater/lib/src/auto_updater.dart

+6-3
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

+12
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_platform_interface/lib/src/auto_updater_platform_interface.dart

+5
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ abstract class AutoUpdaterPlatform extends PlatformInterface {
4949
'checkForUpdateInformation() has not been implemented.',
5050
);
5151
}
52+
53+
/// Cleans up the auto updater.
54+
Future<void> cleanup() async {
55+
throw UnimplementedError('cleanup() has not been implemented.');
56+
}
5257
}

packages/auto_updater_windows/windows/auto_updater.cpp

+5-1
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);
@@ -70,7 +71,6 @@ void AutoUpdater::SetFeedURL(std::string feedURL) {
7071
win_sparkle_set_update_skipped_callback(__onUpdateSkippedCallback);
7172
win_sparkle_set_update_postponed_callback(__onUpdatePostponedCallback);
7273
win_sparkle_set_update_dismissed_callback(__onUpdateDismissedCallback);
73-
win_sparkle_set_user_run_installer_callback(__onUserRunInstallerCallback);
7474
}
7575

7676
void AutoUpdater::CheckForUpdates() {
@@ -87,6 +87,10 @@ void AutoUpdater::SetScheduledCheckInterval(int interval) {
8787
win_sparkle_set_update_check_interval(interval);
8888
}
8989

90+
void AutoUpdater::Cleanup() {
91+
win_sparkle_cleanup();
92+
}
93+
9094
void AutoUpdater::RegisterEventSink(
9195
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> ptr) {
9296
event_sink_ = std::move(ptr);

packages/auto_updater_windows/windows/auto_updater_windows_plugin.cpp

+6
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)