diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b10e8..8e608dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v1.1.1 + +### Changelog +* Restore old update method for windows version (Double-click the `iris-updater.bat` in the same directory as the executable file to upgrade if you have problems updating.) + +### 更新日志 +* windows 版本恢复为旧的更新方式(更新出问题的可双击打开可执行文件同级目录下的 `iris-updater.bat` 升级) + + ## v1.1.0 ### Breaking Changes diff --git a/lib/pages/dialog/show_release_dialog.dart b/lib/pages/dialog/show_release_dialog.dart index af3afa7..8ab1334 100644 --- a/lib/pages/dialog/show_release_dialog.dart +++ b/lib/pages/dialog/show_release_dialog.dart @@ -2,9 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:iris/utils/file_size_convert.dart'; import 'package:iris/utils/is_desktop.dart'; -import 'package:iris/utils/path.dart'; import 'package:path/path.dart' as p; -import 'package:http/http.dart' as http; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; @@ -29,102 +27,25 @@ class ReleaseDialog extends HookWidget { @override Widget build(BuildContext context) { final t = getLocalizations(context); - final progress = useState(0.0); - final isError = useState(false); - final isDownload = useState(false); - final downloadingTask = useState(null); - const downloadFileName = 'Iris.zip'; void update() async { if (Platform.isWindows) { - final String executableDirPath = await getExecutableDirPath(); - final String tempPath = await getTempPath(); - final String filePath = p.join(tempPath, downloadFileName); - final String executablePath = p.join(executableDirPath, 'iris.exe'); - - if (!File(filePath).existsSync()) { - return; - } - - final commands = [ - 'title Iris', - 'timeout /t 2 /nobreak', - 'powerShell Expand-Archive -Path "$filePath" -DestinationPath "$tempPath" -Force', - 'xcopy $tempPath\\Iris\\* $executableDirPath /s /E /I /Y', - 'rd /s /q $tempPath', - 'start $executablePath', - ]; - + String resolvedExecutablePath = Platform.resolvedExecutable; + String path = p.dirname(resolvedExecutablePath); + String batFilePath = p.join(path, 'iris-updater.bat'); + // 执行 bat 文件 await Process.start( - 'cmd', - ['/c', commands.join(' && ')], + 'cmd.exe', + ['/c', batFilePath], mode: ProcessStartMode.detached, runInShell: true, - workingDirectory: executableDirPath, ); - + // 退出应用 exit(0); } } - Future downloadFile(String url, String filePath) async { - final client = http.Client(); - final request = http.Request('GET', Uri.parse(url)); - final response = await client.send(request); - if (response.statusCode == 200) { - final totalBytes = response.contentLength ?? 0; - - var file = File(filePath); - var sink = file.openWrite(); - - final streamSubscription = response.stream.listen( - (List chunk) { - sink.add(chunk); - progress.value += chunk.length / totalBytes; - }, - onDone: () async { - await sink.close(); - client.close(); - }, - onError: (error) { - sink.close(); - client.close(); - isError.value = true; - isDownload.value = false; - }, - cancelOnError: true, - ); - return streamSubscription; - } else { - throw Exception('Download failed with status ${response.statusCode}'); - } - } - - Future download() async { - if (isDesktop && !isDownload.value) { - final String tempPath = await getTempPath(); - final String filePath = p.join(tempPath, downloadFileName); - - try { - isDownload.value = true; - isError.value = false; - final sub = await downloadFile(release.url, filePath); - downloadingTask.value = sub; - } catch (e) { - isError.value = true; - } - } else { - launchURL(release.url); - Navigator.pop(context, 'OK'); - } - } - Future cancel() async { - if (!(progress.value == 0) && downloadingTask.value != null) { - await downloadingTask.value!.cancel(); - progress.value = 0.0; - } - if (context.mounted) { Navigator.pop(context, 'Cancel'); } @@ -133,23 +54,7 @@ class ReleaseDialog extends HookWidget { return AlertDialog( title: Text('${t.checked_new_version}: ${release.version}'), content: SingleChildScrollView( - child: isError.value - ? SizedBox( - height: 100, - width: 100, - child: Center( - child: Text(t.download_error), - ), - ) - : isDownload.value - ? SizedBox( - height: 100, - width: 100, - child: Center( - child: CircularProgressIndicator(value: progress.value), - ), - ) - : MarkdownBody(data: release.changeLog, shrinkWrap: true), + child: MarkdownBody(data: release.changeLog, shrinkWrap: true), ), actions: [ TextButton( @@ -163,26 +68,19 @@ class ReleaseDialog extends HookWidget { Visibility( visible: !isDesktop, child: TextButton( - onPressed: download, + onPressed: () { + launchURL(release.url); + Navigator.pop(context, 'OK'); + }, child: Text(t.download), ), ), Visibility( visible: isDesktop, child: TextButton( - onPressed: progress.value >= 1 - ? update - : isDownload.value - ? null - : download, - child: isError.value - ? Text(t.retry) - : progress.value >= 1 - ? Text(t.confirmUpdate) - : isDownload.value - ? Text('${(progress.value * 100).toStringAsFixed(2)} %') - : Text( - '${t.download} (${fileSizeConvert(release.size)} MB)'), + onPressed: update, + child: Text( + '${t.download_and_update} (${fileSizeConvert(release.size)} MB)'), ), ), ], diff --git a/pubspec.yaml b/pubspec.yaml index 3f96192..68aea85 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.1.0+2 +version: 1.1.1+2 environment: sdk: ^3.5.4