diff --git a/packages/celest_core/ffigen.glib.yaml b/packages/celest_core/ffigen.glib.yaml index 0af4a67b..c59218d5 100644 --- a/packages/celest_core/ffigen.glib.yaml +++ b/packages/celest_core/ffigen.glib.yaml @@ -24,6 +24,7 @@ typedefs: - gboolean - gint - gpointer + - gchar functions: include: - g_hash_table_new @@ -43,3 +44,9 @@ structs: "_GHashTable": GHashTable "_GCancellable": GCancellable "_GObject": GObject +type-map: + typedefs: + gchar: + lib: pkg_ffi + c-type: Utf8 + dart-type: Char diff --git a/packages/celest_core/lib/src/native/linux/glib.ffi.dart b/packages/celest_core/lib/src/native/linux/glib.ffi.dart index b516a959..e062d26e 100644 --- a/packages/celest_core/lib/src/native/linux/glib.ffi.dart +++ b/packages/celest_core/lib/src/native/linux/glib.ffi.dart @@ -6,6 +6,7 @@ // // Generated by `package:ffigen`. import 'dart:ffi' as ffi; +import 'package:ffi/ffi.dart' as pkg_ffi; /// Bindings for glib on Linux. /// @@ -108,7 +109,7 @@ class Glib { late final _g_hash_table_insert = _g_hash_table_insertPtr .asFunction, gpointer, gpointer)>(); - ffi.Pointer g_application_get_application_id( + ffi.Pointer g_application_get_application_id( ffi.Pointer<_GApplication> application, ) { return _g_application_get_application_id( @@ -118,11 +119,11 @@ class Glib { late final _g_application_get_application_idPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function( + ffi.Pointer Function( ffi.Pointer<_GApplication>)>>('g_application_get_application_id'); late final _g_application_get_application_id = _g_application_get_application_idPtr.asFunction< - ffi.Pointer Function(ffi.Pointer<_GApplication>)>(); + ffi.Pointer Function(ffi.Pointer<_GApplication>)>(); ffi.Pointer<_GApplication> g_application_get_default() { return _g_application_get_default(); @@ -142,7 +143,7 @@ final class GError extends ffi.Struct { @gint() external int code; - external ffi.Pointer message; + external ffi.Pointer message; } typedef gint = ffi.Int; diff --git a/packages/celest_core/lib/src/secure_storage/secure_storage.linux.dart b/packages/celest_core/lib/src/secure_storage/secure_storage.linux.dart index c50cc425..e764bc91 100644 --- a/packages/celest_core/lib/src/secure_storage/secure_storage.linux.dart +++ b/packages/celest_core/lib/src/secure_storage/secure_storage.linux.dart @@ -32,15 +32,11 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform { if (application == nullptr) { return File('/proc/self/exe').resolveSymbolicLinksSync(); } - return _gio - .g_application_get_application_id(application) - .cast() - .toDartString(); + return _gio.g_application_get_application_id(application).toDartString(); }(); - String _labelFor(String key) => '$scope/$key'; - Pointer _schemaFor(Arena arena) => arena() - ..ref.name = _appName.toNativeUtf8(allocator: arena) + Pointer _schema(Arena arena) => arena() + ..ref.name = '$_appName/$scope'.toNativeUtf8(allocator: arena) ..ref.flags = SecretSchemaFlags.SECRET_SCHEMA_NONE ..ref.attributes[0].name = 'key'.toNativeUtf8(allocator: arena) ..ref.attributes[0].type = @@ -64,7 +60,7 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform { @override void clear() => using((arena) { - final schema = _schemaFor(arena); + final schema = _schema(arena); final attributes = _attributes(arena: arena); _check( (err) => _libSecret.secret_password_clearv_sync( @@ -80,7 +76,7 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform { @override String? delete(String key) => using((arena) { final secret = read(key); - final schema = _schemaFor(arena); + final schema = _schema(arena); final attributes = _attributes(key: key, arena: arena); _check( (err) => _libSecret.secret_password_clearv_sync( @@ -97,7 +93,7 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform { @override String? read(String key) => using((arena) { final attributes = _attributes(key: key, arena: arena); - final schema = _schemaFor(arena); + final schema = _schema(arena); final result = _check( (err) => _libSecret.secret_password_lookupv_sync( schema, @@ -117,12 +113,13 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform { @override String write(String key, String value) { using((arena) { - final label = _labelFor(key).toNativeUtf8(allocator: arena); + final schema = _schema(arena); + final label = key.toNativeUtf8(allocator: arena); final secret = value.toNativeUtf8(allocator: arena); final attributes = _attributes(key: key, arena: arena); _check( (err) => _libSecret.secret_password_storev_sync( - _schemaFor(arena), + schema, attributes, nullptr, label, @@ -145,7 +142,7 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform { final error = err.value; if (error != nullptr) { arena.onReleaseAll(() => _glib.g_error_free(error)); - final message = error.ref.message.cast().toDartString(); + final message = error.ref.message.toDartString(); throw SecureStorageUnknownException(message); } return result;