mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt.: Loggers
This commit is contained in:
@@ -3,10 +3,10 @@ import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:r_upgrade/r_upgrade.dart';
|
||||
import 'package:toolbox/core/extension/context.dart';
|
||||
import 'package:toolbox/data/model/app/update.dart';
|
||||
import 'package:toolbox/data/res/logger.dart';
|
||||
import 'package:toolbox/data/res/path.dart';
|
||||
|
||||
import '../data/provider/app.dart';
|
||||
@@ -16,14 +16,12 @@ import '../locator.dart';
|
||||
import 'utils/platform.dart';
|
||||
import 'utils/ui.dart';
|
||||
|
||||
final _logger = Logger('UPDATE');
|
||||
|
||||
Future<bool> isFileAvailable(String url) async {
|
||||
try {
|
||||
final resp = await Dio().head(url);
|
||||
return resp.statusCode == 200;
|
||||
} catch (e) {
|
||||
_logger.warning('update file not available: $e');
|
||||
Loggers.app.warning('HEAD update file failed', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -35,41 +33,36 @@ Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
|
||||
final newest = update.build.last.current;
|
||||
if (newest == null) {
|
||||
_logger.warning('Update not available on $platform');
|
||||
Loggers.app.warning('Update not available on $platform');
|
||||
return;
|
||||
}
|
||||
|
||||
locator<AppProvider>().newestBuild = newest;
|
||||
|
||||
if (!force && newest <= BuildData.build) {
|
||||
_logger.info('Update ignored due to current: ${BuildData.build}, '
|
||||
'update: $newest');
|
||||
Loggers.app.info('Update ignored: ${BuildData.build} >= $newest');
|
||||
return;
|
||||
}
|
||||
_logger.info('Update available: $newest');
|
||||
Loggers.app.info('Update available: $newest');
|
||||
|
||||
final url = update.url.current!;
|
||||
|
||||
if (isAndroid && !await isFileAvailable(url)) {
|
||||
_logger.warning('Android update file not available');
|
||||
if ((isAndroid || isMacOS) && !await isFileAvailable(url)) {
|
||||
Loggers.app.warning('Update file not available');
|
||||
return;
|
||||
}
|
||||
|
||||
final s = S.of(context);
|
||||
if (s == null) {
|
||||
context.showSnackBar('Null l10n');
|
||||
return;
|
||||
}
|
||||
|
||||
final min = update.build.min.current;
|
||||
|
||||
if (min != null && min > BuildData.build) {
|
||||
context.showRoundDialog(
|
||||
child: Text(s.updateTipTooLow(newest)),
|
||||
child: Text(s?.updateTipTooLow(newest) ?? 'Update: $newest'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => _doUpdate(update, context, s),
|
||||
child: Text(s.ok),
|
||||
child: Text(s?.ok ?? 'Ok'),
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -77,13 +70,13 @@ Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
}
|
||||
|
||||
context.showSnackBarWithAction(
|
||||
'${s.updateTip(newest)} \n${update.changelog.current}',
|
||||
s.update,
|
||||
'${s?.updateTip(newest) ?? "Update: $newest"} \n${update.changelog.current}',
|
||||
s?.update ?? 'Update',
|
||||
() => _doUpdate(update, context, s),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _doUpdate(AppUpdate update, BuildContext context, S s) async {
|
||||
Future<void> _doUpdate(AppUpdate update, BuildContext context, S? s) async {
|
||||
final url = update.url.current;
|
||||
if (url == null) return;
|
||||
|
||||
@@ -96,11 +89,11 @@ Future<void> _doUpdate(AppUpdate update, BuildContext context, S s) async {
|
||||
await openUrl(url);
|
||||
} else {
|
||||
context.showRoundDialog(
|
||||
child: Text(s.platformNotSupportUpdate),
|
||||
child: Text(s?.platformNotSupportUpdate ?? 'Unsupported platform'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: Text(s.ok),
|
||||
child: Text(s?.ok ?? 'Ok'),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user