diff --git a/src/App/Program.cs b/src/App/Program.cs index 620929a..436c9c6 100644 --- a/src/App/Program.cs +++ b/src/App/Program.cs @@ -29,6 +29,7 @@ class Program var services = new ServiceCollection(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); return services.BuildServiceProvider(); } } \ No newline at end of file diff --git a/src/Logic/ISecretService.cs b/src/Logic/ISecretService.cs new file mode 100644 index 0000000..b9a3821 --- /dev/null +++ b/src/Logic/ISecretService.cs @@ -0,0 +1,7 @@ +namespace Logic; + +public interface ISecretService +{ + public List GetCollections(); + public void CreateCollection(string label); +} diff --git a/src/Logic/Logic.csproj b/src/Logic/Logic.csproj index 0a268a9..2bff711 100644 --- a/src/Logic/Logic.csproj +++ b/src/Logic/Logic.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/src/Logic/PasswordStoreService.cs b/src/Logic/PasswordStoreService.cs index 34e6df4..a70546c 100644 --- a/src/Logic/PasswordStoreService.cs +++ b/src/Logic/PasswordStoreService.cs @@ -6,14 +6,17 @@ namespace Logic; public class PasswordStoreService : IPasswordStoreService { private readonly IRepository repository; + private readonly ISecretService secretService; - public PasswordStoreService(IRepository repository) + public PasswordStoreService(IRepository repository, ISecretService secretService) { this.repository = repository; + this.secretService = secretService; } public void Create(PasswordStore item) { + secretService.CreateCollection(item.DisplayName ?? item.Path); repository.Create(item); } diff --git a/src/Logic/SecretService.cs b/src/Logic/SecretService.cs new file mode 100644 index 0000000..41f9d4c --- /dev/null +++ b/src/Logic/SecretService.cs @@ -0,0 +1,30 @@ +namespace Logic; + +public class SecretService : ISecretService +{ + Secret.Service service; + + public SecretService() + { + Secret.Module.Initialize(); + service = Secret.Service.GetSync(Secret.ServiceFlags.LoadCollections, null); + } + + public List GetCollections() + { + GLib.List collections = service.GetCollections() ?? throw new Exception("No collections found"); + List result = new List(); + GLib.List.Foreach(collections, data => + { + Secret.Collection collection = (Secret.Collection)GObject.Internal.InstanceWrapper.WrapHandle(data, false); + result.Add(collection); + Console.WriteLine($" - {collection.Label}"); + }); + return result; + } + + public void CreateCollection(string label) + { + Secret.Collection.CreateSync(service, label, null, Secret.CollectionCreateFlags.None, null); + } +}