mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
rm: r_upgrade
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:r_upgrade/r_upgrade.dart';
|
||||
import 'package:toolbox/core/extension/context/common.dart';
|
||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/extension/context/snackbar.dart';
|
||||
@@ -13,10 +10,7 @@ import 'package:toolbox/core/utils/ui.dart';
|
||||
import 'package:toolbox/data/model/app/update.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/res/logger.dart';
|
||||
import 'package:toolbox/data/res/path.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/data/res/ui.dart';
|
||||
import 'package:toolbox/data/service/app.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
@@ -25,17 +19,15 @@ Future<bool> isFileAvailable(String url) async {
|
||||
final resp = await Dio().head(url);
|
||||
return resp.statusCode == 200;
|
||||
} catch (e) {
|
||||
Loggers.app.warning('HEAD update file failed', e);
|
||||
Loggers.app.warning('HEAD update file failed', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
await _rmDownloadApks();
|
||||
|
||||
final update = await locator<AppService>().getUpdate();
|
||||
|
||||
final newest = update.build.last.current;
|
||||
final newest = update.build.last.current;
|
||||
if (newest == null) {
|
||||
Loggers.app.warning('Update not available on ${OS.type}');
|
||||
return;
|
||||
@@ -81,81 +73,10 @@ Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
Future<void> _doUpdate(AppUpdate update, BuildContext context) async {
|
||||
final url = update.url.current;
|
||||
if (url == null) {
|
||||
Loggers.app.warning('Update url not is null');
|
||||
Loggers.app.warning('Update url is null');
|
||||
context.showSnackBar(l10n.failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAndroid) {
|
||||
final useBrowser = await _openUrlUpdate(context);
|
||||
final _ = switch (useBrowser) {
|
||||
1 => await RUpgrade.upgrade(url, fileName: url.split('/').last),
|
||||
2 => await openUrl(url),
|
||||
_ => null,
|
||||
};
|
||||
} else if (isIOS) {
|
||||
await RUpgrade.upgradeFromAppStore('1586449703');
|
||||
} else {
|
||||
await openUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
Future<int?> _openUrlUpdate(BuildContext context) async {
|
||||
final inAppUpdate = Stores.setting.inAppUpdate;
|
||||
final val = inAppUpdate.fetch();
|
||||
if (val == 0) {
|
||||
var remember = true;
|
||||
final selection = await context.showRoundDialog<int>(
|
||||
title: Text(l10n.attention),
|
||||
child: StatefulBuilder(builder: (_, setState) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(l10n.inAppUpdate, style: UIs.text15Bold),
|
||||
CheckboxListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
value: remember,
|
||||
onChanged: (v) => setState(() => remember = v ?? true),
|
||||
title: Text(l10n.rememberChoice),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(0),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (remember) {
|
||||
inAppUpdate.put(1);
|
||||
}
|
||||
context.pop(1);
|
||||
},
|
||||
child: const Text('App'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (remember) {
|
||||
inAppUpdate.put(2);
|
||||
}
|
||||
context.pop(2);
|
||||
},
|
||||
child: Text(l10n.browser),
|
||||
),
|
||||
],
|
||||
);
|
||||
return selection;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
// rmdir Download
|
||||
Future<void> _rmDownloadApks() async {
|
||||
if (!isAndroid) return;
|
||||
final dlDir = Directory(await Paths.dl);
|
||||
if (await dlDir.exists()) {
|
||||
await dlDir.delete(recursive: true);
|
||||
}
|
||||
await openUrl(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user