结构初始化

This commit is contained in:
LollipopKit
2021-09-13 14:25:54 +08:00
commit 4dd509a1d9
90 changed files with 2715 additions and 0 deletions

42
lib/core/update.dart Normal file
View File

@@ -0,0 +1,42 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/provider/app.dart';
import 'package:toolbox/data/res/build_data.dart';
import 'package:toolbox/data/service/app.dart';
import 'package:toolbox/locator.dart';
Future<bool> isFileAvailable(String url) async {
try {
final resp = await Dio().head(url);
return resp.statusCode == 200;
} catch (e) {
print('update file not available: $e');
return false;
}
}
Future<void> doUpdate(BuildContext context, {bool force = false}) async {
final update = await locator<AppService>().getUpdate();
locator<AppProvider>().setNewestBuild(update.newest);
if (!force && update.newest <= BuildData.build) {
print('Update ignored due to current: ${BuildData.build}, '
'update: ${update.newest}');
return;
}
print('Update available: ${update.newest}');
if (Platform.isAndroid && !await isFileAvailable(update.android)) {
return;
}
showSnackBarWithAction(
context,
'${BuildData.name}有更新啦Ver${update.newest}\n${update.changelog}',
'更新',
() => openUrl(Platform.isAndroid ? update.android : update.ios));
}