mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-01-11 22:40:36 +00:00
refactor: improve download button logic and clean up code
This commit is contained in:
parent
a26a764753
commit
a0df094504
2 changed files with 25 additions and 22 deletions
|
|
@ -74,25 +74,28 @@ class _DownloadFileScreenState extends ConsumerState<DownloadFileScreen> {
|
|||
),
|
||||
const SizedBox(width: 15),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (Platform.isAndroid) {
|
||||
final deviceInfo = DeviceInfoPlugin();
|
||||
final androidInfo = await deviceInfo.androidInfo;
|
||||
String apkUrl = "";
|
||||
for (String abi in androidInfo.supportedAbis) {
|
||||
final url = updateAvailable.$4.firstWhereOrNull(
|
||||
(apk) => (apk as String).contains(abi),
|
||||
);
|
||||
if (url != null) {
|
||||
apkUrl = url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await _downloadApk(apkUrl);
|
||||
} else {
|
||||
_launchInBrowser(Uri.parse(updateAvailable.$3));
|
||||
}
|
||||
},
|
||||
onPressed:
|
||||
_total == 0
|
||||
? () async {
|
||||
if (Platform.isAndroid) {
|
||||
final deviceInfo = DeviceInfoPlugin();
|
||||
final androidInfo = await deviceInfo.androidInfo;
|
||||
String apkUrl = "";
|
||||
for (String abi in androidInfo.supportedAbis) {
|
||||
final url = updateAvailable.$4.firstWhereOrNull(
|
||||
(apk) => (apk as String).contains(abi),
|
||||
);
|
||||
if (url != null) {
|
||||
apkUrl = url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await _downloadApk(apkUrl);
|
||||
} else {
|
||||
_launchInBrowser(Uri.parse(updateAvailable.$3));
|
||||
}
|
||||
}
|
||||
: null,
|
||||
child: Text(l10n.download),
|
||||
),
|
||||
],
|
||||
|
|
@ -113,7 +116,7 @@ class _DownloadFileScreenState extends ConsumerState<DownloadFileScreen> {
|
|||
);
|
||||
if (await file.exists()) {
|
||||
await _installApk(file);
|
||||
if (context.mounted) {
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
return;
|
||||
|
|
@ -129,7 +132,7 @@ class _DownloadFileScreenState extends ConsumerState<DownloadFileScreen> {
|
|||
_subscription?.onDone(() async {
|
||||
await file.writeAsBytes(_bytes);
|
||||
await _installApk(file);
|
||||
if (context.mounted) {
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class WindowsProtocolHandler extends ProtocolHandler {
|
|||
hKey,
|
||||
txtKey,
|
||||
txtValue,
|
||||
REG_VALUE_TYPE.REG_SZ,
|
||||
REG_SZ,
|
||||
txtData,
|
||||
txtData.length * 2 + 2,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue