@@ -20,39 +20,57 @@ class Hints {
2020}
2121
2222class Config {
23- static Hints hints = Hints ();
24- static String _proxy = '' ;
25- static bool _proxyEnabled = false ;
26- static ThemeMode _mode = ThemeMode .system;
27- static Envvars envvars = Envvars ();
28-
29- static String get proxy => _proxy;
30- static setProxy (String value) async {
23+ static final Config _instance = Config ._internal ();
24+ Config ._internal ();
25+
26+ factory Config () {
27+ return _instance;
28+ }
29+
30+ final List <String > _externalModels = [];
31+ List <String > get externalModels => _externalModels;
32+ addExternalModel (String path) async {
33+ _externalModels.add (path);
34+ await _save ('externalModels' , _externalModels);
35+ }
36+ removeExternalModel (String path) async {
37+ _externalModels.remove (path);
38+ await _save ('externalModels' , _externalModels);
39+ }
40+
41+ Hints hints = Hints ();
42+ String _proxy = '' ;
43+ bool _proxyEnabled = false ;
44+ ThemeMode _mode = ThemeMode .system;
45+ Envvars envvars = Envvars ();
46+
47+ String get proxy => _proxy;
48+ setProxy (String value) async {
3149 _proxy = value;
3250 await _save ('proxy' , value);
3351 }
3452
35- static bool get proxyEnabled => _proxyEnabled;
36- static setProxyEnabled (bool value) async {
53+ bool get proxyEnabled => _proxyEnabled;
54+ setProxyEnabled (bool value) async {
3755 _proxyEnabled = value;
3856 await _save ('proxyEnabled' , value);
3957 }
4058
41- static ThemeMode get themeMode => _mode;
42- static setThemeMode (ThemeMode value) async {
59+ ThemeMode get themeMode => _mode;
60+ setThemeMode (ThemeMode value) async {
4361 _mode = value;
4462 await _save ('mode' , value.index);
4563 }
4664
47- static void reset () {
65+ void reset () {
4866 hints = Hints ();
4967 _proxy = '' ;
5068 _proxyEnabled = false ;
5169 _mode = ThemeMode .system;
5270 envvars = Envvars ();
5371 }
5472
55- static Future <String > _getProxy () async {
73+ Future <String > _getProxy () async {
5674 final dio = Dio (BaseOptions (connectTimeout: const Duration (seconds: 10 )));
5775 dio.httpClientAdapter = IOHttpClientAdapter (
5876 createHttpClient: () {
@@ -79,7 +97,7 @@ class Config {
7997 return '' ;
8098 }
8199
82- static Future <void > loadFromFile () async {
100+ Future <void > loadFromFile () async {
83101 final directory = await getApplicationSupportDirectory ();
84102 final file = File ('${directory .path }/config.json' );
85103 if (await file.exists ()) {
@@ -92,10 +110,11 @@ class Config {
92110 _proxy = await _getProxy ();
93111 }
94112 _mode = ThemeMode .values[json['mode' ] ?? 0 ];
113+ _externalModels.addAll (List <String >.from (json['externalModels' ] ?? []));
95114 }
96115 }
97116
98- static Future <void > _save (String key, dynamic value) async {
117+ Future <void > _save (String key, dynamic value) async {
99118 final directory = await getApplicationSupportDirectory ();
100119 final file = File ('${directory .path }/config.json' );
101120 Map <String , dynamic > json = {};
@@ -104,7 +123,8 @@ class Config {
104123 json = jsonDecode (contents);
105124 }
106125 json[key] = value;
107- await file.writeAsString (jsonEncode (json));
126+ const encoder = JsonEncoder .withIndent (" " );
127+ await file.writeAsString (encoder.convert (json));
108128 }
109129
110130}
0 commit comments