diff --git a/go/mobile/bind-android-debug.sh b/go/mobile/bind-android-debug.sh index bbca168..e117d21 100644 --- a/go/mobile/bind-android-debug.sh +++ b/go/mobile/bind-android-debug.sh @@ -1 +1 @@ -gomobile bind -target=android/arm,android/arm64,android/386 -o lib/Mobile.aar ./ +gomobile bind -target=android/arm,android/arm64,android/386,android/amd64 -o lib/Mobile.aar ./ diff --git a/lib/basic/Cross.dart b/lib/basic/Cross.dart index d4733f9..1089892 100644 --- a/lib/basic/Cross.dart +++ b/lib/basic/Cross.dart @@ -82,23 +82,12 @@ Future _saveImageAndroid(String path, BuildContext context) async { /// 选择一个文件夹用于保存文件 Future chooseFolder(BuildContext context) async { - if (Platform.isAndroid) { - if (androidVersion >= 30) { - if (!(await Permission.manageExternalStorage.request()).isGranted) { - return null; - } - } else { - if (!(await Permission.storage.request()).isGranted) { - return null; - } - } - } return FilesystemPicker.open( title: '选择一个文件夹', pickText: '将文件保存到这里', context: context, fsType: FilesystemType.folder, - rootDirectory: Directory(currentChooserRoot()), + rootDirectory: Directory(await currentChooserRoot()), ); } diff --git a/lib/basic/config/ChooserRoot.dart b/lib/basic/config/ChooserRoot.dart index 6168a7a..c8c2d10 100644 --- a/lib/basic/config/ChooserRoot.dart +++ b/lib/basic/config/ChooserRoot.dart @@ -3,9 +3,11 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:permission_handler/permission_handler.dart'; import '../Common.dart'; import '../Method.dart'; +import 'Platform.dart'; const _propertyName = "chooserRoot"; late String _chooserRoot; @@ -14,7 +16,7 @@ Future initChooserRoot() async { _chooserRoot = await method.loadProperty(_propertyName, ""); } -String currentChooserRoot() { +String _currentChooserRoot() { if (_chooserRoot == "") { if (Platform.isWindows) { return '/'; @@ -23,9 +25,6 @@ String currentChooserRoot() { } else if (Platform.isLinux) { return '/'; } else if (Platform.isAndroid) { - // if (androidVersion >= 30) { - // return '/storage/emulated/0/Download'; - // } return '/storage/emulated/0'; } else { throw 'error'; @@ -34,6 +33,21 @@ String currentChooserRoot() { return _chooserRoot; } +Future currentChooserRoot() async { + if (Platform.isAndroid) { + if (androidVersion >= 30) { + if (!(await Permission.manageExternalStorage.request()).isGranted) { + throw Exception("申请权限被拒绝"); + } + } else { + if (!(await Permission.storage.request()).isGranted) { + throw Exception("申请权限被拒绝"); + } + } + } + return _currentChooserRoot(); +} + Future _inputChooserRoot(BuildContext context) async { String? input = await displayTextInputDialog( context, @@ -53,7 +67,7 @@ Widget chooserRootSetting() { builder: (BuildContext context, void Function(void Function()) setState) { return ListTile( title: Text("文件夹选择器默认路径"), - subtitle: Text(currentChooserRoot()), + subtitle: Text(_currentChooserRoot()), onTap: () async { await _inputChooserRoot(context); setState(() {}); diff --git a/lib/basic/config/DownloadAndExportPath.dart b/lib/basic/config/DownloadAndExportPath.dart index 8271354..1701f90 100644 --- a/lib/basic/config/DownloadAndExportPath.dart +++ b/lib/basic/config/DownloadAndExportPath.dart @@ -38,7 +38,13 @@ Widget downloadAndExportPathSetting() { "您即将选择一个目录, 如果文件系统可写, 下载的同时会为您自动导出一份", ); if (b) { - String? folder = await chooseFolder(context); + late String? folder; + try { + folder = await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } if (folder != null) { await method.saveDownloadAndExportPath(folder); _downloadAndExportPath = folder; diff --git a/lib/basic/config/Version.dart b/lib/basic/config/Version.dart index 96f48ee..7e4f790 100644 --- a/lib/basic/config/Version.dart +++ b/lib/basic/config/Version.dart @@ -15,6 +15,7 @@ RegExp _versionExp = RegExp(r"^v\d+\.\d+.\d+$"); late String _version; String? _latestVersion; +String? _latestVersionInfo; const _propertyName = "checkVersionPeriod"; late int _period = -1; @@ -46,6 +47,10 @@ String? latestVersion() { return _latestVersion; } +String? latestVersionInfo() { + return _latestVersionInfo; +} + Future autoCheckNewVersion() { if (_period != 0) { // -1 不检查, >0 未到检查时间 @@ -76,6 +81,7 @@ Future _versionCheck() async { String latestVersion = (json["name"]); if (latestVersion != _version) { _latestVersion = latestVersion; + _latestVersionInfo = json["body"] ?? ""; } } } // else dirtyVersion diff --git a/lib/screens/AboutScreen.dart b/lib/screens/AboutScreen.dart index 6bf0396..a71a901 100644 --- a/lib/screens/AboutScreen.dart +++ b/lib/screens/AboutScreen.dart @@ -36,6 +36,7 @@ class _AboutScreenState extends State { var min = size.width < size.height ? size.width : size.height; var _currentVersion = currentVersion(); var _latestVersion = latestVersion(); + var _latestVersionInfo = latestVersionInfo(); var _dirty = dirtyVersion(); return Scaffold( appBar: AppBar( @@ -80,6 +81,7 @@ class _AboutScreenState extends State { Expanded(child: Container()), ], ), + _buildNewVersionInfo(_latestVersionInfo), ], ), ), @@ -177,4 +179,24 @@ class _AboutScreenState extends State { ), ); } + + Widget _buildNewVersionInfo(String? latestVersionInfo) { + if (latestVersionInfo != null) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Divider(), + Text("更新内容:"), + Container( + padding: EdgeInsets.all(15), + child: Text( + latestVersionInfo, + style: TextStyle(), + ), + ), + ], + ); + } + return Container(); + } } diff --git a/lib/screens/DownloadExportToFileScreen.dart b/lib/screens/DownloadExportToFileScreen.dart index 4a9107e..e33be83 100644 --- a/lib/screens/DownloadExportToFileScreen.dart +++ b/lib/screens/DownloadExportToFileScreen.dart @@ -126,7 +126,13 @@ class _DownloadExportToFileScreenState Platform.isAndroid) { widgets.add(MaterialButton( onPressed: () async { - String? path = await chooseFolder(context); + late String? path; + try { + path = await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } print("path $path"); if (path != null) { try { @@ -156,7 +162,13 @@ class _DownloadExportToFileScreenState widgets.add(Container(height: 10)); widgets.add(MaterialButton( onPressed: () async { - String? path = await chooseFolder(context); + late String? path; + try { + path = await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } print("path $path"); if (path != null) { try { diff --git a/lib/screens/DownloadImportScreen.dart b/lib/screens/DownloadImportScreen.dart index e7235a4..a55304a 100644 --- a/lib/screens/DownloadImportScreen.dart +++ b/lib/screens/DownloadImportScreen.dart @@ -80,10 +80,17 @@ class _DownloadImportScreenState extends State { return MaterialButton( height: 80, onPressed: () async { + late String chooseRoot; + try { + chooseRoot = await currentChooserRoot(); + } catch (e) { + defaultToast(context, "$e"); + return; + } String? path = await FilesystemPicker.open( title: '选择要导入的文件', context: context, - rootDirectory: Directory(currentChooserRoot()), + rootDirectory: Directory(chooseRoot), fsType: FilesystemType.file, folderIconColor: Colors.teal, allowedExtensions: ['.zip'], @@ -117,7 +124,8 @@ class _DownloadImportScreenState extends State { return MaterialButton( height: 80, onPressed: () async { - var path = await inputString(context, '请输入导出设备提供的地址\n例如 "192.168.1.2:50000"'); + var path = + await inputString(context, '请输入导出设备提供的地址\n例如 "192.168.1.2:50000"'); if (path != null) { try { setState(() {