This commit is contained in:
lollipopkit
2023-08-08 17:46:04 +08:00
parent 159942de95
commit d35d106ad4
7 changed files with 94 additions and 66 deletions

View File

@@ -18,7 +18,6 @@ import 'utils/platform.dart';
import 'utils/ui.dart';
final _logger = Logger('UPDATE');
late final String _dlDir;
Future<bool> isFileAvailable(String url) async {
try {
@@ -97,22 +96,44 @@ Future<void> _doUpdate(AppUpdate update, BuildContext context, S s) async {
fileName: fileName,
isAutoRequestInstall: false,
);
if (id == null) {
showSnackBar(context, const Text('install id is null'));
return;
}
final sha256 = update.sha256.current;
if (sha256 == null) {
showSnackBar(context, const Text('sha256 is null'));
return;
}
final dlPath = pathJoin(_dlDir, fileName);
final computed = await getFileSha256(dlPath);
if (computed != sha256) {
showSnackBar(context, Text('Mismatch sha256: $computed, $sha256'));
return;
}
RUpgrade.install(id);
RUpgrade.stream.listen((event) async {
if (event.status?.value == 3) {
if (id == null) {
showSnackBar(context, const Text('install id is null'));
return;
}
final sha256 = () {
try {
return fileName.split('.').first;
} catch (e) {
_logger.warning('sha256 parse failed: $e');
return null;
}
}();
final dlPath = pathJoin(await _dlDir, fileName);
final computed = await getFileSha256(dlPath);
if (computed != sha256) {
_logger.info('Mismatch sha256: $computed, $sha256');
final resume = await showRoundDialog(
context: context,
title: Text(s.attention),
child: const Text('sha256 is null'),
actions: [
TextButton(
onPressed: () => context.pop(false),
child: Text(s.cancel),
),
TextButton(
onPressed: () => context.pop(true),
child: Text(s.ok, style: const TextStyle(color: Colors.red)),
),
],
);
if (!resume) return;
}
RUpgrade.install(id);
}
});
} else if (isIOS) {
await RUpgrade.upgradeFromAppStore('1586449703');
} else {
@@ -132,9 +153,10 @@ Future<void> _doUpdate(AppUpdate update, BuildContext context, S s) async {
// rmdir Download
Future<void> _rmDownloadApks() async {
if (!isAndroid) return;
_dlDir = pathJoin((await docDir).path, 'Download');
final dlDir = Directory(_dlDir);
final dlDir = Directory(await _dlDir);
if (await dlDir.exists()) {
await dlDir.delete(recursive: true);
}
}
Future<String> get _dlDir async => pathJoin((await docDir).path, 'Download');

View File

@@ -34,13 +34,11 @@ class AppUpdate {
required this.changelog,
required this.build,
required this.url,
required this.sha256,
});
final AppUpdatePlatformSpecific<String> changelog;
final Build build;
final AppUpdatePlatformSpecific<String> url;
final AppUpdatePlatformSpecific<String?> sha256;
factory AppUpdate.fromRawJson(String str) =>
AppUpdate.fromJson(json.decode(str));
@@ -51,14 +49,12 @@ class AppUpdate {
changelog: AppUpdatePlatformSpecific.fromJson(json["changelog"]),
build: Build.fromJson(json["build"]),
url: AppUpdatePlatformSpecific.fromJson(json["url"]),
sha256: AppUpdatePlatformSpecific.fromJson(json["sha256"]),
);
Map<String, dynamic> toJson() => {
"changelog": changelog.toJson(),
"build": build.toJson(),
"url": url.toJson(),
"sha256": sha256.toJson(),
};
}

View File

@@ -2,8 +2,8 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 452;
static const int build = 453;
static const String engine = "3.10.6";
static const String buildAt = "2023-08-08 16:29:00.513310";
static const int modifications = 11;
static const String buildAt = "2023-08-08 17:41:45.597966";
static const int modifications = 1;
}

View File

@@ -149,10 +149,16 @@ class _ServerPageState extends State<ServerPage>
}
return GestureDetector(
key: Key(si.spi.id + (_tag ?? '')),
onTap: () => AppRoute(
ServerDetailPage(si.spi.id),
'server detail page',
).go(context),
onTap: () {
if (si.state == ServerState.connected) {
AppRoute(
ServerDetailPage(si.spi.id),
'server detail page',
).go(context);
} else {
_showFailReason(si.status);
}
},
child: RoundRectCard(
Padding(
padding: const EdgeInsets.all(13),
@@ -260,19 +266,7 @@ class _ServerPageState extends State<ServerPage>
);
if (cs == ServerState.failed && ss.failedInfo != null) {
return GestureDetector(
onTap: () => showRoundDialog(
context: context,
title: Text(_s.error),
child: SingleChildScrollView(
child: Text(ss.failedInfo!),
),
actions: [
TextButton(
onPressed: () => copy2Clipboard(ss.failedInfo!),
child: Text(_s.copy),
)
],
),
onTap: () => _showFailReason(ss),
child: Text(
_s.viewErr,
style: textSize12Grey,
@@ -287,6 +281,22 @@ class _ServerPageState extends State<ServerPage>
);
}
void _showFailReason(ServerStatus ss) {
showRoundDialog(
context: context,
title: Text(_s.error),
child: SingleChildScrollView(
child: Text(ss.failedInfo!),
),
actions: [
TextButton(
onPressed: () => copy2Clipboard(ss.failedInfo!),
child: Text(_s.copy),
)
],
);
}
Widget _buildSSHBtn(ServerPrivateInfo spi) {
return GestureDetector(
child: const Icon(Icons.terminal, size: 21),