diff --git a/lib/data/model/server/private_key_info.dart b/lib/data/model/server/private_key_info.dart index 2e63253c..fdf49aa8 100644 --- a/lib/data/model/server/private_key_info.dart +++ b/lib/data/model/server/private_key_info.dart @@ -35,7 +35,7 @@ class PrivateKeyInfo { } } -List? getPrivateKeyInfoList(dynamic data) { +List getPrivateKeyInfoList(dynamic data) { List ss = []; if (data is String) { data = json.decode(data); diff --git a/lib/data/model/server/snippet.dart b/lib/data/model/server/snippet.dart new file mode 100644 index 00000000..f97b31eb --- /dev/null +++ b/lib/data/model/server/snippet.dart @@ -0,0 +1,30 @@ +import 'dart:convert'; + +class Snippet { + late String name; + late String script; + Snippet(this.name, this.script); + + Snippet.fromJson(Map json) { + name = json['name'].toString(); + script = json['script'].toString(); + } + Map toJson() { + final data = {}; + data['name'] = name; + data['script'] = script; + return data; + } +} + +List getSnippetList(dynamic data) { + List ss = []; + if (data is String) { + data = json.decode(data); + } + for (var t in data) { + ss.add(Snippet.fromJson(t)); + } + + return ss; +} diff --git a/lib/data/store/private_key.dart b/lib/data/store/private_key.dart index 2e1d7a1c..bd35daf5 100644 --- a/lib/data/store/private_key.dart +++ b/lib/data/store/private_key.dart @@ -12,7 +12,7 @@ class PrivateKeyStore extends PersistentStore { List fetch() { return getPrivateKeyInfoList( - json.decode(box.get('key', defaultValue: '[]')!))!; + json.decode(box.get('key', defaultValue: '[]')!)); } void delete(PrivateKeyInfo s) { diff --git a/lib/data/store/snippet.dart b/lib/data/store/snippet.dart new file mode 100644 index 00000000..e580bb32 --- /dev/null +++ b/lib/data/store/snippet.dart @@ -0,0 +1,33 @@ +import 'dart:convert'; + +import 'package:toolbox/core/persistant_store.dart'; +import 'package:toolbox/data/model/server/snippet.dart'; + +class SnippetStore extends PersistentStore { + void put(Snippet snippet) { + final ss = fetch(); + if (!have(snippet)) ss.add(snippet); + box.put('snippet', json.encode(ss)); + } + + List fetch() { + return getSnippetList( + json.decode(box.get('snippet', defaultValue: '[]')!)); + } + + void delete(Snippet s) { + final ss = fetch(); + ss.removeAt(index(s)); + box.put('snippet', json.encode(ss)); + } + + void update(Snippet old, Snippet newInfo) { + final ss = fetch(); + ss[index(old)] = newInfo; + box.put('snippet', json.encode(ss)); + } + + int index(Snippet s) => fetch().indexWhere((e) => e.name == s.name); + + bool have(Snippet s) => index(s) != -1; +} \ No newline at end of file diff --git a/lib/locator.dart b/lib/locator.dart index 45edf119..bcfb34ed 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -7,6 +7,7 @@ import 'package:toolbox/data/service/app.dart'; import 'package:toolbox/data/store/private_key.dart'; import 'package:toolbox/data/store/server.dart'; import 'package:toolbox/data/store/setting.dart'; +import 'package:toolbox/data/store/snippet.dart'; GetIt locator = GetIt.instance; @@ -33,6 +34,10 @@ Future setupLocatorForStores() async { final key = PrivateKeyStore(); await key.init(boxName: 'key'); locator.registerSingleton(key); + + final snippet = SnippetStore(); + await snippet.init(boxName: 'snippet'); + locator.registerSingleton(snippet); } Future setupLocator() async { diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 1fe89aaf..6146ffff 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -1,6 +1,8 @@ import 'package:after_layout/after_layout.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; +import 'package:toolbox/core/analysis.dart'; +import 'package:toolbox/core/build_mode.dart'; import 'package:toolbox/core/route.dart'; import 'package:toolbox/core/update.dart'; import 'package:toolbox/core/utils.dart'; @@ -90,8 +92,13 @@ class _MyHomePageState extends State applicationIcon: _buildIcon(), aboutBoxChildren: const [ UrlText( - text: '\nMade with ❤️ by https://github.com/LollipopKit', replace: 'LollipopKit'), - UrlText(text: '\nThanks https://github.com/RainSunMe for participating in the test.\n\nAll rights reserved.', replace: 'RainSunMe',), + text: '\nMade with ❤️ by https://github.com/LollipopKit', + replace: 'LollipopKit'), + UrlText( + text: + '\nThanks https://github.com/RainSunMe for participating in the test.\n\nAll rights reserved.', + replace: 'RainSunMe', + ), ], ), ], @@ -118,5 +125,6 @@ class _MyHomePageState extends State await GetIt.I.allReady(); await locator().loadLocalData(); await doUpdate(context); + await Analysis.init(BuildMode.isDebug); } } diff --git a/lib/view/page/snippet/edit.dart b/lib/view/page/snippet/edit.dart new file mode 100644 index 00000000..2d07eef5 --- /dev/null +++ b/lib/view/page/snippet/edit.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class SnappetEditPage extends StatefulWidget { + const SnappetEditPage({ Key? key }) : super(key: key); + + @override + _SnappetEditPageState createState() => _SnappetEditPageState(); +} + +class _SnappetEditPageState extends State { + @override + Widget build(BuildContext context) { + return Container( + + ); + } +} \ No newline at end of file diff --git a/lib/view/page/snippet/list.dart b/lib/view/page/snippet/list.dart new file mode 100644 index 00000000..4211b2db --- /dev/null +++ b/lib/view/page/snippet/list.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class SnappetListPage extends StatefulWidget { + const SnappetListPage({ Key? key }) : super(key: key); + + @override + _SnappetListPageState createState() => _SnappetListPageState(); +} + +class _SnappetListPageState extends State { + @override + Widget build(BuildContext context) { + return Container( + + ); + } +} \ No newline at end of file