Skip to content

feat: support isCriticalUpdate flag and add user-update-choice callback #70

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 7 commits 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
35 changes: 34 additions & 1 deletion packages/auto_updater/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
include: package:flutter_lints/flutter.yaml

analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"

linter:
rules:
- require_trailing_commas

- prefer_collection_literals
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals

- sized_box_for_whitespace
- use_decorated_box

- unnecessary_parenthesis
- unnecessary_await_in_return
- unnecessary_raw_strings

- avoid_unnecessary_containers
- avoid_redundant_argument_values
- avoid_unused_constructor_parameters

- always_declare_return_types

- sort_constructors_first
- unawaited_futures

errors:
invalid_annotation_target: ignore
7 changes: 4 additions & 3 deletions packages/auto_updater/bin/generate_keys.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as p;

Future<void> main(List<String> arguments) async {
if (!(Platform.isMacOS || Platform.isWindows)) {
throw UnsupportedError('auto_updater:generate_keys');
}

String executable = Platform.isMacOS
final String executable = Platform.isMacOS
? '${Directory.current.path}/macos/Pods/Sparkle/bin/generate_keys'
: p.joinAll(
[
Expand All @@ -18,13 +19,13 @@ Future<void> main(List<String> arguments) async {
'.plugin_symlinks',
'auto_updater_windows',
'windows',
'WinSparkle-0.8.1',
'WinSparkle-0.8.3',
'bin',
'generate_keys.bat',
],
);

Process process = await Process.start(
final Process process = await Process.start(
executable,
arguments,
);
Expand Down
16 changes: 9 additions & 7 deletions packages/auto_updater/bin/sign_update.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';

import 'package:path/path.dart' as p;

class SignUpdateResult {
Expand All @@ -12,7 +13,7 @@ class SignUpdateResult {
}

SignUpdateResult signUpdate(List<String> args) {
String executable = Platform.isMacOS
final String executable = Platform.isMacOS
? '${Directory.current.path}/macos/Pods/Sparkle/bin/sign_update'
: p.joinAll(
[
Expand All @@ -23,24 +24,24 @@ SignUpdateResult signUpdate(List<String> args) {
'.plugin_symlinks',
'auto_updater_windows',
'windows',
'WinSparkle-0.8.1',
'WinSparkle-0.8.3',
'bin',
'sign_update.bat',
],
);
List<String> arguments = List<String>.from(args);
final List<String> arguments = List<String>.from(args);
if (Platform.isWindows) {
if (arguments.length == 1) {
arguments.add(p.join('dsa_priv.pem'));
}
}

ProcessResult processResult = Process.runSync(
final ProcessResult processResult = Process.runSync(
executable,
arguments,
);

int exitCode = processResult.exitCode;
final int exitCode = processResult.exitCode;

String? signUpdateOutput;
if (exitCode == 0) {
Expand All @@ -54,8 +55,9 @@ SignUpdateResult signUpdate(List<String> args) {
stderr.write(processResult.stderr);
}

RegExp regex = RegExp(r'sparkle:(dsa|ed)Signature="([^"]+)" length="(\d+)"');
RegExpMatch? match = regex.firstMatch(signUpdateOutput!);
final RegExp regex =
RegExp(r'sparkle:(dsa|ed)Signature="([^"]+)" length="(\d+)"');
final RegExpMatch? match = regex.firstMatch(signUpdateOutput!);

if (match == null) {
throw Exception('Failed to sign update');
Expand Down
21 changes: 21 additions & 0 deletions packages/auto_updater/example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,25 @@ class _HomePageState extends State<HomePage> with UpdaterListener {
}
windowManager.setPreventClose(false);
}

@override
void onUpdaterUpdateSkipped(AppcastItem? appcastItem) {
if (kDebugMode) {
print('onUpdaterUpdateSkipped: ${appcastItem?.toJson()}');
}
}

@override
void onUpdaterUpdateCancelled(AppcastItem? appcastItem) {
if (kDebugMode) {
print('onUpdaterUpdateCancelled: ${appcastItem?.toJson()}');
}
}

@override
void onUpdaterUpdateInstalled(AppcastItem? appcastItem) {
if (kDebugMode) {
print('onUpdaterUpdateInstalled: ${appcastItem?.toJson()}');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "generated_plugin_registrant.h"

#include <auto_updater_windows/auto_updater_windows_plugin_c_api.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AutoUpdaterWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AutoUpdaterWindowsPluginCApi"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverWindowsPluginCApi"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
auto_updater_windows
screen_retriever
screen_retriever_windows
window_manager
)

Expand Down
2 changes: 2 additions & 0 deletions packages/auto_updater/lib/auto_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ library auto_updater;

export 'src/appcast.dart';
export 'src/auto_updater.dart';
export 'src/events.dart';
export 'src/updater_error.dart';
export 'src/updater_listener.dart';
export 'src/user_update_choice.dart';
4 changes: 4 additions & 0 deletions packages/auto_updater/lib/src/appcast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AppcastItem {
this.maximumSystemVersion,
this.maximumOperatingSystemVersionIsOK,
this.channel,
this.criticalUpdate,
this.os,
});

factory AppcastItem.fromJson(Map<String, dynamic> json) =>
Expand All @@ -60,6 +62,8 @@ class AppcastItem {
final String? maximumSystemVersion;
final bool? maximumOperatingSystemVersionIsOK;
final String? channel;
final bool? criticalUpdate;
final String? os;

Map<String, dynamic> toJson() => _$AppcastItemToJson(this);
}
6 changes: 5 additions & 1 deletion packages/auto_updater/lib/src/appcast.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading