Skip to content

Commit

Permalink
clean up linux
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Mar 7, 2024
1 parent cad92d1 commit 8dabb71
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
7 changes: 7 additions & 0 deletions packages/celest_core/ffigen.glib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedefs:
- gboolean
- gint
- gpointer
- gchar
functions:
include:
- g_hash_table_new
Expand All @@ -43,3 +44,9 @@ structs:
"_GHashTable": GHashTable
"_GCancellable": GCancellable
"_GObject": GObject
type-map:
typedefs:
gchar:
lib: pkg_ffi
c-type: Utf8
dart-type: Char
9 changes: 5 additions & 4 deletions packages/celest_core/lib/src/native/linux/glib.ffi.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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<Utf8>()
.toDartString();
return _gio.g_application_get_application_id(application).toDartString();
}();

String _labelFor(String key) => '$scope/$key';
Pointer<SecretSchema> _schemaFor(Arena arena) => arena<SecretSchema>()
..ref.name = _appName.toNativeUtf8(allocator: arena)
Pointer<SecretSchema> _schema(Arena arena) => arena<SecretSchema>()
..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 =
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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<Utf8>().toDartString();
final message = error.ref.message.toDartString();
throw SecureStorageUnknownException(message);
}
return result;
Expand Down

0 comments on commit 8dabb71

Please sign in to comment.