diff --git a/src/App/Program.cs b/src/App/Program.cs index 790832a..db5d941 100644 --- a/src/App/Program.cs +++ b/src/App/Program.cs @@ -15,7 +15,7 @@ class Program var application = Adw.Application.New("org.typomustakes.keychain", Gio.ApplicationFlags.FlagsNone); application.OnActivate += (sender, args) => { - var passwordStoreService = provider.GetRequiredService(); + var passwordStoreService = provider.GetRequiredService(); var window = new UI.MainWindow(passwordStoreService).Window; window.Application = (Adw.Application)sender; window.Show(); @@ -27,7 +27,7 @@ class Program private static ServiceProvider SetupServices() { var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); return services.BuildServiceProvider(); diff --git a/src/App/UI/MainWindow/MainWindow.cs b/src/App/UI/MainWindow/MainWindow.cs index d6b7a9d..a612224 100644 --- a/src/App/UI/MainWindow/MainWindow.cs +++ b/src/App/UI/MainWindow/MainWindow.cs @@ -19,7 +19,7 @@ public partial class MainWindow private const string searchEntryId = "search_entry"; private const string passwordListId = "password_list"; - public MainWindow(IPasswordStoreService passwordStoreService) + public MainWindow(ICollectionsService passwordStoreService) { this.passwordStoreService = passwordStoreService; diff --git a/src/App/UI/MainWindow/ShortcutSidebar.cs b/src/App/UI/MainWindow/ShortcutSidebar.cs index 0f54f58..5ec20f7 100644 --- a/src/App/UI/MainWindow/ShortcutSidebar.cs +++ b/src/App/UI/MainWindow/ShortcutSidebar.cs @@ -7,7 +7,7 @@ namespace Keychain.UI; public partial class MainWindow { private const string DEFAULT_SHORTCUT_NAME = "Keychain"; - private readonly IPasswordStoreService passwordStoreService; + private readonly ICollectionsService passwordStoreService; private PreferencesGroup shortcutsGroup; private BookmarkCollection shortcuts; diff --git a/src/App/ViewModels/Bookmark/BookmarkCollection.cs b/src/App/ViewModels/Bookmark/BookmarkCollection.cs index 1d85cdb..410e961 100644 --- a/src/App/ViewModels/Bookmark/BookmarkCollection.cs +++ b/src/App/ViewModels/Bookmark/BookmarkCollection.cs @@ -8,12 +8,12 @@ using System.Collections.Specialized; public class BookmarkCollection : ObservableCollection { - private readonly IPasswordStoreService _passwordStoreService; + private readonly ICollectionsService _passwordStoreService; private readonly PreferencesGroup shortcutsGroup; private Dictionary itemToRowMap = new(); - public BookmarkCollection(PreferencesGroup shortcutsGroup, IPasswordStoreService passwordStoreService) + public BookmarkCollection(PreferencesGroup shortcutsGroup, ICollectionsService passwordStoreService) : base() { this.shortcutsGroup = shortcutsGroup; @@ -94,7 +94,9 @@ public class BookmarkCollection : ObservableCollection public void Add(string path, string? displayName = null) { BookmarkViewModel item = new BookmarkViewModel(path, displayName); - Add(item); - _passwordStoreService.Create(item.Model); + if (_passwordStoreService.Create(item.Model)) + { + Add(item); + } } } \ No newline at end of file diff --git a/src/App/ViewModels/Password/PasswordList.cs b/src/App/ViewModels/Password/PasswordList.cs index 816f4d1..18e5b14 100644 --- a/src/App/ViewModels/Password/PasswordList.cs +++ b/src/App/ViewModels/Password/PasswordList.cs @@ -8,11 +8,11 @@ namespace Keychain.ViewModels; public class PasswordList : ObservableCollection { - private readonly IPasswordStoreService _passwordService; + private readonly ICollectionsService _passwordService; private readonly PreferencesGroup list; private Dictionary itemToRowMap = new(); - public PasswordList(PreferencesGroup list, IPasswordStoreService passwordService) + public PasswordList(PreferencesGroup list, ICollectionsService passwordService) : base() { this.list = list; diff --git a/src/Logic/PasswordStoreService.cs b/src/Logic/CollectionsService.cs similarity index 84% rename from src/Logic/PasswordStoreService.cs rename to src/Logic/CollectionsService.cs index 599facf..28464c7 100644 --- a/src/Logic/PasswordStoreService.cs +++ b/src/Logic/CollectionsService.cs @@ -3,21 +3,25 @@ using Repository; namespace Logic; -public class PasswordStoreService : IPasswordStoreService +public class CollectionsService : ICollectionsService { private readonly IBookmarksRepository repository; private readonly ISecretService secretService; - public PasswordStoreService(IBookmarksRepository repository, ISecretService secretService) + public CollectionsService(IBookmarksRepository repository, ISecretService secretService) { this.repository = repository; this.secretService = secretService; } - public void Create(PasswordStore item) + public bool Create(PasswordStore item) { - secretService.CreateCollection(item.DisplayName ?? item.Path); - repository.Create(item); + if (secretService.CreateCollection(item.DisplayName ?? item.Path)) + { + repository.Create(item); + return true; + } + return false; } public void Delete(uint ID) diff --git a/src/Logic/IPasswordStoreService.cs b/src/Logic/ICollectionsService.cs similarity index 74% rename from src/Logic/IPasswordStoreService.cs rename to src/Logic/ICollectionsService.cs index 74b5969..446cea1 100644 --- a/src/Logic/IPasswordStoreService.cs +++ b/src/Logic/ICollectionsService.cs @@ -2,12 +2,12 @@ using Models; namespace Logic; -public interface IPasswordStoreService +public interface ICollectionsService { IEnumerable GetAll(); PasswordStore Get(uint ID); void Delete(uint ID); void Delete(PasswordStore item); - void Create(PasswordStore item); + bool Create(PasswordStore item); void Edit(uint ID, PasswordStore newItem); }