Skip to content

Commit 97a5e46

Browse files
committed
chore: Update sign_update script
1 parent 96af23a commit 97a5e46

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

packages/auto_updater/bin/sign_update.dart

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import 'dart:io';
22
import 'package:path/path.dart' as p;
33

4-
Future<void> main(List<String> args) async {
5-
if (!(Platform.isMacOS || Platform.isWindows)) {
6-
throw UnsupportedError('auto_updater:sign_update');
7-
}
4+
class SignUpdateResult {
5+
const SignUpdateResult({
6+
required this.signature,
7+
required this.length,
8+
});
89

10+
final String signature;
11+
final int length;
12+
}
13+
14+
SignUpdateResult signUpdate(List<String> args) {
915
String executable = Platform.isMacOS
1016
? '${Directory.current.path}/macos/Pods/Sparkle/bin/sign_update'
1117
: p.joinAll(
@@ -35,14 +41,34 @@ Future<void> main(List<String> args) async {
3541
);
3642

3743
int exitCode = processResult.exitCode;
44+
45+
String? signUpdateOutput;
3846
if (exitCode == 0) {
39-
String signature = processResult.stdout.toString();
47+
signUpdateOutput = processResult.stdout.toString();
4048
if (Platform.isWindows) {
41-
signature = signature.replaceFirst('\r\n', '').trim();
42-
signature = 'sparkle:dsaSignature="$signature" length="0"';
49+
signUpdateOutput = signUpdateOutput.replaceFirst('\r\n', '').trim();
50+
signUpdateOutput = 'sparkle:dsaSignature="$signUpdateOutput" length="0"';
4351
}
44-
stdout.write(signature);
52+
stdout.write(signUpdateOutput);
4553
} else {
4654
stderr.write(processResult.stderr);
4755
}
56+
57+
RegExp regex = RegExp(r'sparkle:(dsa|ed)Signature="([^"]+)" length="(\d+)"');
58+
RegExpMatch? match = regex.firstMatch(signUpdateOutput!);
59+
60+
if (match == null) {
61+
throw Exception('Failed to sign update');
62+
}
63+
return SignUpdateResult(
64+
signature: match.group(2)!,
65+
length: int.tryParse(match.group(3)!)!,
66+
);
67+
}
68+
69+
Future<void> main(List<String> args) async {
70+
if (!(Platform.isMacOS || Platform.isWindows)) {
71+
throw UnsupportedError('auto_updater:sign_update');
72+
}
73+
signUpdate(args);
4874
}

0 commit comments

Comments
 (0)