mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
Improve.
- make the refresh interval setting makes effect immediately. - auto stop/restart status update when app goto background/resume
This commit is contained in:
@@ -23,6 +23,8 @@ class ServerProvider extends BusyProvider {
|
|||||||
List<ServerInfo> _servers = [];
|
List<ServerInfo> _servers = [];
|
||||||
List<ServerInfo> get servers => _servers;
|
List<ServerInfo> get servers => _servers;
|
||||||
|
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
final logger = Logger('ServerProvider');
|
final logger = Logger('ServerProvider');
|
||||||
|
|
||||||
Memory get emptyMemory =>
|
Memory get emptyMemory =>
|
||||||
@@ -95,11 +97,19 @@ class ServerProvider extends BusyProvider {
|
|||||||
final duration =
|
final duration =
|
||||||
locator<SettingStore>().serverStatusUpdateInterval.fetch()!;
|
locator<SettingStore>().serverStatusUpdateInterval.fetch()!;
|
||||||
if (duration == 0) return;
|
if (duration == 0) return;
|
||||||
Timer.periodic(Duration(seconds: duration), (_) async {
|
stopAutoRefresh();
|
||||||
|
_timer = Timer.periodic(Duration(seconds: duration), (_) async {
|
||||||
await refreshData();
|
await refreshData();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopAutoRefresh() {
|
||||||
|
if (_timer != null) {
|
||||||
|
_timer!.cancel();
|
||||||
|
_timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addServer(ServerPrivateInfo info) {
|
void addServer(ServerPrivateInfo info) {
|
||||||
_servers.add(genInfo(info));
|
_servers.add(genInfo(info));
|
||||||
locator<ServerStore>().put(info);
|
locator<ServerStore>().put(info);
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
class BuildData {
|
class BuildData {
|
||||||
static const String name = "ToolBox";
|
static const String name = "ToolBox";
|
||||||
static const int build = 65;
|
static const int build = 68;
|
||||||
static const String engine =
|
static const String engine =
|
||||||
"Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (2 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
|
"Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (2 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
|
||||||
static const String buildAt = "2021-12-31 15:55:47.350456";
|
static const String buildAt = "2022-01-02 14:53:09.769990";
|
||||||
static const int modifications = 7;
|
static const int modifications = 3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,16 +31,37 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
with
|
with
|
||||||
AutomaticKeepAliveClientMixin,
|
AutomaticKeepAliveClientMixin,
|
||||||
SingleTickerProviderStateMixin,
|
SingleTickerProviderStateMixin,
|
||||||
AfterLayoutMixin {
|
AfterLayoutMixin,
|
||||||
|
WidgetsBindingObserver {
|
||||||
final List<String> _tabs = ['Servers', 'En/Decode'];
|
final List<String> _tabs = ['Servers', 'En/Decode'];
|
||||||
late final TabController _tabController;
|
late final TabController _tabController;
|
||||||
|
late final ServerProvider _serverProvider;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_serverProvider = locator<ServerProvider>();
|
||||||
|
WidgetsBinding.instance?.addObserver(this);
|
||||||
_tabController = TabController(length: _tabs.length, vsync: this);
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
WidgetsBinding.instance?.removeObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
super.didChangeAppLifecycleState(state);
|
||||||
|
if (state == AppLifecycleState.paused) {
|
||||||
|
_serverProvider.stopAutoRefresh();
|
||||||
|
}
|
||||||
|
if (state == AppLifecycleState.resumed) {
|
||||||
|
_serverProvider.startAutoRefresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
setTransparentNavigationBar(context);
|
setTransparentNavigationBar(context);
|
||||||
|
|||||||
@@ -210,8 +210,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
_buildMemExplain(convertMB(ss.memory.used), pColor),
|
_buildMemExplain(convertMB(ss.memory.used), pColor),
|
||||||
_buildMemExplain(
|
_buildMemExplain(
|
||||||
convertMB(ss.memory.cache), pColor.withAlpha(77)),
|
convertMB(ss.memory.cache), pColor.withAlpha(77)),
|
||||||
_buildMemExplain(
|
_buildMemExplain(convertMB(ss.memory.total - ss.memory.used),
|
||||||
convertMB(ss.memory.total - ss.memory.avail), progressColor.resolve(context))
|
progressColor.resolve(context))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
@@ -243,7 +243,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMemExplain(String type, Color color) {
|
Widget _buildMemExplain(String value, Color color) {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
@@ -252,7 +252,12 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
width: 11,
|
width: 11,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Text(type, style: style11, textScaleFactor: 1.0)
|
Text(
|
||||||
|
value,
|
||||||
|
style: style11,
|
||||||
|
textScaleFactor: 1.0,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
child: AnimationLimiter(
|
child: AnimationLimiter(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: AnimationConfiguration.toStaggeredList(
|
children: AnimationConfiguration.toStaggeredList(
|
||||||
duration: const Duration(milliseconds: 777),
|
duration: const Duration(milliseconds: 477),
|
||||||
childAnimationBuilder: (widget) => SlideAnimation(
|
childAnimationBuilder: (widget) => SlideAnimation(
|
||||||
verticalOffset: 77.0,
|
verticalOffset: 77.0,
|
||||||
child: FadeInAnimation(
|
child: FadeInAnimation(
|
||||||
@@ -155,7 +155,9 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
accelerationCurve: Curves.linear,
|
accelerationCurve: Curves.linear,
|
||||||
decelerationDuration: const Duration(seconds: 3),
|
decelerationDuration: const Duration(seconds: 3),
|
||||||
decelerationCurve: Curves.linear,
|
decelerationCurve: Curves.linear,
|
||||||
text: topRightStr, textScaleFactor: 1.0, style: style),
|
text: topRightStr,
|
||||||
|
textScaleFactor: 1.0,
|
||||||
|
style: style),
|
||||||
)
|
)
|
||||||
: Text(topRightStr, style: style, textScaleFactor: 1.0),
|
: Text(topRightStr, style: style, textScaleFactor: 1.0),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter_material_color_picker/flutter_material_color_picker.dart
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:toolbox/core/update.dart';
|
import 'package:toolbox/core/update.dart';
|
||||||
import 'package:toolbox/data/provider/app.dart';
|
import 'package:toolbox/data/provider/app.dart';
|
||||||
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
import 'package:toolbox/data/res/build_data.dart';
|
import 'package:toolbox/data/res/build_data.dart';
|
||||||
import 'package:toolbox/data/res/color.dart';
|
import 'package:toolbox/data/res/color.dart';
|
||||||
import 'package:toolbox/data/store/setting.dart';
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
@@ -22,6 +23,7 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
double _intervalValue = 0;
|
double _intervalValue = 0;
|
||||||
late Color priColor;
|
late Color priColor;
|
||||||
static const textStyle = TextStyle(fontSize: 14);
|
static const textStyle = TextStyle(fontSize: 14);
|
||||||
|
late final ServerProvider _serverProvider;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
@@ -32,6 +34,7 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_serverProvider = locator<ServerProvider>();
|
||||||
_store = locator<SettingStore>();
|
_store = locator<SettingStore>();
|
||||||
_intervalValue = _store.serverStatusUpdateInterval.fetch()!.toDouble();
|
_intervalValue = _store.serverStatusUpdateInterval.fetch()!.toDouble();
|
||||||
}
|
}
|
||||||
@@ -88,7 +91,7 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
textAlign: TextAlign.start,
|
textAlign: TextAlign.start,
|
||||||
),
|
),
|
||||||
subtitle: const Text(
|
subtitle: const Text(
|
||||||
'Will take effect the next time app launches.',
|
'Will take effect immediately.',
|
||||||
style: TextStyle(color: Colors.grey),
|
style: TextStyle(color: Colors.grey),
|
||||||
),
|
),
|
||||||
trailing: Text('${_intervalValue.toInt()} s'),
|
trailing: Text('${_intervalValue.toInt()} s'),
|
||||||
@@ -104,8 +107,10 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
_intervalValue = newValue;
|
_intervalValue = newValue;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onChangeEnd: (val) =>
|
onChangeEnd: (val) {
|
||||||
_store.serverStatusUpdateInterval.put(val.toInt()),
|
_store.serverStatusUpdateInterval.put(val.toInt());
|
||||||
|
_serverProvider.startAutoRefresh();
|
||||||
|
},
|
||||||
label: '${_intervalValue.toInt()} seconds',
|
label: '${_intervalValue.toInt()} seconds',
|
||||||
divisions: 10,
|
divisions: 10,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user