BBreaking change

This commit is contained in:
LollipopKit
2021-10-26 07:31:42 +08:00
parent 44e9780e5a
commit a725604121
20 changed files with 710 additions and 183 deletions

View File

@@ -0,0 +1,48 @@
import 'dart:convert';
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
///
class PrivateKeyInfo {
/*
{
"id": "",
"private_key": "",
"password": ""
}
*/
late String id;
late String privateKey;
late String password;
PrivateKeyInfo(
this.id,
this.privateKey,
this.password,
);
PrivateKeyInfo.fromJson(Map<String, dynamic> json) {
id = json["id"].toString();
privateKey = json["private_key"].toString();
password = json["password"].toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["id"] = id;
data["private_key"] = privateKey;
data["password"] = password;
return data;
}
}
List<PrivateKeyInfo>? getPrivateKeyInfoList(dynamic data) {
List<PrivateKeyInfo> ss = [];
if (data is String) {
data = json.decode(data);
}
for (var t in data) {
ss.add(PrivateKeyInfo.fromJson(t));
}
return ss;
}

View File

@@ -0,0 +1,32 @@
import 'package:toolbox/core/provider_base.dart';
import 'package:toolbox/data/model/private_key_info.dart';
import 'package:toolbox/data/store/private_key.dart';
import 'package:toolbox/locator.dart';
class PrivateKeyProvider extends BusyProvider {
List<PrivateKeyInfo> get infos => _infos;
late List<PrivateKeyInfo> _infos;
void loadData() {
_infos = locator<PrivateKeyStore>().fetch();
}
void addInfo(PrivateKeyInfo info) {
_infos.add(info);
locator<PrivateKeyStore>().put(info);
notifyListeners();
}
void delInfo(PrivateKeyInfo info) {
_infos.removeWhere((e) => e.id == info.id);
locator<PrivateKeyStore>().delete(info);
notifyListeners();
}
void updateInfo(PrivateKeyInfo old, PrivateKeyInfo newInfo) {
final idx = _infos.indexWhere((e) => e.id == old.id);
_infos[idx] = newInfo;
locator<PrivateKeyStore>().update(old, newInfo);
notifyListeners();
}
}

View File

@@ -10,6 +10,7 @@ import 'package:toolbox/data/model/server_private_info.dart';
import 'package:toolbox/data/model/server_status.dart';
import 'package:toolbox/data/model/tcp_status.dart';
import 'package:toolbox/data/store/server.dart';
import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/locator.dart';
class ServerProvider extends BusyProvider {
@@ -55,18 +56,28 @@ class ServerProvider extends BusyProvider {
}
Future<void> refreshData() async {
final _serversStatus = await Future.wait(
_servers.map((s) => _getData(s.info, _servers.indexOf(s))));
int idx = 0;
for (var item in _serversStatus) {
_servers[idx].status = item;
idx++;
List<ServerStatus> _serversStatus = [];
try {
_serversStatus = await Future.wait(
_servers.map((s) => _getData(s.info, _servers.indexOf(s))));
} catch (e) {
rethrow;
} finally {
int idx = 0;
for (var item in _serversStatus) {
_servers[idx].status = item;
idx++;
}
notifyListeners();
}
notifyListeners();
}
Future<void> startAutoRefresh() async {
Timer.periodic(const Duration(seconds: 3), (_) async {
Timer.periodic(
Duration(
seconds: locator<SettingStore>()
.serverStatusUpdateInterval
.fetch()!), (_) async {
await refreshData();
});
}

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ToolBox";
static const int build = 18;
static const int build = 20;
static const String engine =
"Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (10 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
static const String buildAt = "2021-10-25 16:56:13.551427";
static const int modifications = 0;
static const String buildAt = "2021-10-26 00:28:50.061797";
static const int modifications = 21;
}

View File

@@ -0,0 +1,33 @@
import 'dart:convert';
import 'package:toolbox/core/persistant_store.dart';
import 'package:toolbox/data/model/private_key_info.dart';
class PrivateKeyStore extends PersistentStore {
void put(PrivateKeyInfo info) {
final ss = fetch();
if (!have(info)) ss.add(info);
box.put('key', json.encode(ss));
}
List<PrivateKeyInfo> fetch() {
return getPrivateKeyInfoList(
json.decode(box.get('key', defaultValue: '[]')!))!;
}
void delete(PrivateKeyInfo s) {
final ss = fetch();
ss.removeAt(index(s));
box.put('key', json.encode(ss));
}
void update(PrivateKeyInfo old, PrivateKeyInfo newInfo) {
final ss = fetch();
ss[index(old)] = newInfo;
box.put('key', json.encode(ss));
}
int index(PrivateKeyInfo s) => fetch().indexWhere((e) => e.id == s.id);
bool have(PrivateKeyInfo s) => index(s) != -1;
}

View File

@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:toolbox/core/persistant_store.dart';
class SettingStore extends PersistentStore {
StoreProperty<bool> get receiveNotification =>
property('notify', defaultValue: true);
StoreProperty<int> get primaryColor =>
property('primaryColor', defaultValue: Colors.deepPurpleAccent.value);
StoreProperty<int> get serverStatusUpdateInterval =>
property('serverStatusUpdateInterval', defaultValue: 3);
}