From 4ec7f5895ea283df5269ff5f5a1f5e5129a57001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Mon, 1 Sep 2025 23:06:58 +0800 Subject: [PATCH] fix: imported servers from ssh config are the same (#882) --- lib/core/utils/ssh_config.dart | 1 + lib/data/res/store.dart | 38 +++++++++++++++++++++------------- pubspec.lock | 8 +++++++ pubspec.yaml | 3 ++- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/core/utils/ssh_config.dart b/lib/core/utils/ssh_config.dart index 9c12829b..23a62b3e 100644 --- a/lib/core/utils/ssh_config.dart +++ b/lib/core/utils/ssh_config.dart @@ -63,6 +63,7 @@ abstract final class SSHConfig { void addServer() { if (currentHost != null && currentHost != '*' && hostname != null) { final spi = Spi( + id: ShortId.generate(), name: currentHost, ip: hostname, port: port, diff --git a/lib/data/res/store.dart b/lib/data/res/store.dart index fc198b6f..efb84973 100644 --- a/lib/data/res/store.dart +++ b/lib/data/res/store.dart @@ -1,4 +1,5 @@ import 'package:fl_lib/fl_lib.dart'; +import 'package:get_it/get_it.dart'; import 'package:server_box/data/store/container.dart'; import 'package:server_box/data/store/history.dart'; import 'package:server_box/data/store/private_key.dart'; @@ -6,25 +7,34 @@ import 'package:server_box/data/store/server.dart'; import 'package:server_box/data/store/setting.dart'; import 'package:server_box/data/store/snippet.dart'; +final GetIt getIt = GetIt.instance; + abstract final class Stores { - static final setting = SettingStore.instance; - static final server = ServerStore.instance; - static final container = ContainerStore.instance; - static final key = PrivateKeyStore.instance; - static final snippet = SnippetStore.instance; - static final history = HistoryStore.instance; + static SettingStore get setting => getIt(); + static ServerStore get server => getIt(); + static ContainerStore get container => getIt(); + static PrivateKeyStore get key => getIt(); + static SnippetStore get snippet => getIt(); + static HistoryStore get history => getIt(); /// All stores that need backup - static final List _allBackup = [ - SettingStore.instance, - ServerStore.instance, - ContainerStore.instance, - PrivateKeyStore.instance, - SnippetStore.instance, - HistoryStore.instance, - ]; + static List get _allBackup => [ + setting, + server, + container, + key, + snippet, + history, + ]; static Future init() async { + getIt.registerLazySingleton(() => SettingStore.instance); + getIt.registerLazySingleton(() => ServerStore.instance); + getIt.registerLazySingleton(() => ContainerStore.instance); + getIt.registerLazySingleton(() => PrivateKeyStore.instance); + getIt.registerLazySingleton(() => SnippetStore.instance); + getIt.registerLazySingleton(() => HistoryStore.instance); + await Future.wait(_allBackup.map((store) => store.init())); } diff --git a/pubspec.lock b/pubspec.lock index 20601a03..2f42bfa1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -682,6 +682,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" + get_it: + dependency: "direct main" + description: + name: get_it + sha256: a4292e7cf67193f8e7c1258203104eb2a51ec8b3a04baa14695f4064c144297b + url: "https://pub.dev" + source: hosted + version: "8.2.0" glob: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 72034407..c8c3175f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,6 +65,7 @@ dependencies: url: https://github.com/lppcg/fl_lib ref: v1.0.345 flutter_gbk2utf8: ^1.0.1 + get_it: ^8.2.0 dependency_overrides: # webdav_client_plus: @@ -77,7 +78,7 @@ dependency_overrides: # path: ../fl_lib # fl_build: # path: ../fl_build - gtk: + gtk: # TODO: remove it after fixed in upstream git: url: https://github.com/lollipopkit/gtk.dart ref: v0.0.36