diff --git a/readme.md b/readme.md index 3f4683f88..e29c32fab 100644 --- a/readme.md +++ b/readme.md @@ -52,6 +52,7 @@ The upcoming features and releases can be checked out in the [milestones](https: | [GtkSource-5][GtkSourceNuget] | Extends a Gtk.TextView to be like a source code editor | | [Secret-1][SecretNuget] | Access to the system keyring via libsecret | | [Rsvg-2.0][RsvgNuget] | SVG rendering library | +| [Geoclue-2.0][GeoclueNuget] | Location services library | ## Get Involved @@ -113,6 +114,7 @@ The code in the library folder is not complete because most of the code is gener [GtkSourceNuget]: https://www.nuget.org/packages/GirCore.GtkSource-5/ [SecretNuget]: https://www.nuget.org/packages/GirCore.Secret-1/ [RsvgNuget]: https://www.nuget.org/packages/GirCore.Rsvg-2.0/ +[GeoclueNuget]: https://www.nuget.org/packages/GirCore.Geoclue-2.0/ ## Licensing terms Gir.Core is licensed under the terms of the MIT-License. Please see the [license file](license.txt) for further information. diff --git a/scripts/GenerateLibs.fsx b/scripts/GenerateLibs.fsx index 632dc1067..6a219eab6 100644 --- a/scripts/GenerateLibs.fsx +++ b/scripts/GenerateLibs.fsx @@ -16,6 +16,7 @@ let girFiles = "GdkPixbuf-2.0.gir" "GdkWayland-4.0.gir" "GdkWin32-4.0.gir" + "Geoclue-2.0.gir" "Gio-2.0.gir" "GLib-2.0.gir" "GObject-2.0.gir" diff --git a/src/GirCore.Libs.slnf b/src/GirCore.Libs.slnf index 3fde88188..bf8747e75 100644 --- a/src/GirCore.Libs.slnf +++ b/src/GirCore.Libs.slnf @@ -14,6 +14,7 @@ "Libs\\Gdk-4.0\\Gdk-4.0.csproj", "Libs\\GdkWayland-4.0\\GdkWayland-4.0.csproj", "Libs\\GdkPixbuf-2.0\\GdkPixbuf-2.0.csproj", + "Libs\\Geoclue-2.0\\Geoclue-2.0.csproj", "Libs\\Gio-2.0\\Gio-2.0.csproj", "Libs\\GLib-2.0\\GLib-2.0.csproj", "Libs\\GObject-2.0\\GObject-2.0.csproj", diff --git a/src/GirCore.slnx b/src/GirCore.slnx index 51add69b1..de403ef83 100644 --- a/src/GirCore.slnx +++ b/src/GirCore.slnx @@ -25,6 +25,7 @@ + diff --git a/src/Libs/Geoclue-2.0/Geoclue-2.0.csproj b/src/Libs/Geoclue-2.0/Geoclue-2.0.csproj new file mode 100644 index 000000000..56612c58a --- /dev/null +++ b/src/Libs/Geoclue-2.0/Geoclue-2.0.csproj @@ -0,0 +1,12 @@ + + + GirCore.Geoclue-2.0 + Geoclue + C# bindings for libgeoclue. + + + + + + + diff --git a/src/Libs/Geoclue-2.0/Public/Module.cs b/src/Libs/Geoclue-2.0/Public/Module.cs new file mode 100644 index 000000000..6f25661ca --- /dev/null +++ b/src/Libs/Geoclue-2.0/Public/Module.cs @@ -0,0 +1,64 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Geoclue; + +public static class Module +{ + private static bool IsInitialized; + private static DllImportResolver? CustomDllImportResolver; + + /// + /// Initialize the Geoclue module. + /// + /// + /// + /// Calling this method is necessary to correctly initialize the bindings + /// and should be done before using anything else in the + /// namespace. + /// + /// + /// Calling this method will also initialize the modules this module + /// depends on: + /// + /// + /// + /// + /// + /// + public static void Initialize() + { + if (IsInitialized) + return; + + GObject.Module.Initialize(); + Gio.Module.Initialize(); + + NativeLibrary.SetDllImportResolver(typeof(Module).Assembly, CustomDllImportResolver ?? Internal.ImportResolver.Resolve); + Internal.TypeRegistration.RegisterTypes(); + + IsInitialized = true; + } + + /// + /// Set a custom DllImportResolver. This disables the automatic loading of native binaries for + /// Geoclue. If the given DllImportResolver receives the library name "Geoclue" it has to return a pointer + /// to the desired native Geoclue binary. + /// + /// + /// Please be aware that using this API means you are out of the officially supported area + /// as you are able to combine GirCore with some binary the package was not build for. Please consider + /// to generate a custom GirCore package which exactly matches your binary. + /// + /// Custom DllImportResolver to use. + /// Throws an exception if the method is called after module initialization. + [Experimental("GirCore1009", UrlFormat = "https://gircore.github.io/docs/integration/diagnostic/1009.html")] + public static void SetCustomDllImportResolver(DllImportResolver customDllImportResolver) + { + if (IsInitialized) + throw new Exception("Can't set a custom DllImportResolver after initialization is done."); + + CustomDllImportResolver = customDllImportResolver; + } +}