Skip to content

Commit d8d8698

Browse files
committed
Finish Linux impl
1 parent dea2e31 commit d8d8698

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/celest_core/lib/src/secure_storage/secure_storage.linux.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform {
1616
final _glibDylib = DynamicLibrary.open('libglib-2.0.so.0');
1717
late final _glib = Glib(_glibDylib);
1818

19+
final _gioDylib = DynamicLibrary.open('libgio-2.0.so');
20+
late final _gio = Glib(_gioDylib);
21+
1922
final _libSecretDylib = DynamicLibrary.open('libsecret-1.so.0');
2023
late final _libSecret = Libsecret(_libSecretDylib);
2124

@@ -24,11 +27,11 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform {
2427
'g_str_hash');
2528

2629
late final String _appName = () {
27-
final application = _glib.g_application_get_default();
30+
final application = _gio.g_application_get_default();
2831
if (application == nullptr) {
2932
return File('/proc/self/exe').resolveSymbolicLinksSync();
3033
}
31-
return _glib
34+
return _gio
3235
.g_application_get_application_id(application)
3336
.cast<Utf8>()
3437
.toDartString();
@@ -43,23 +46,25 @@ final class SecureStoragePlatformLinux extends SecureStoragePlatform {
4346
SecretSchemaAttributeType.SECRET_SCHEMA_ATTRIBUTE_STRING;
4447

4548
Pointer<GHashTable> _attributes({
46-
required String key,
49+
String? key,
4750
required Arena arena,
4851
}) {
4952
final hashTable = _glib.g_hash_table_new(_gStrHashPointer, nullptr);
50-
_glib.g_hash_table_insert(
51-
hashTable,
52-
'key'.toNativeUtf8(allocator: arena).cast(),
53-
key.toNativeUtf8(allocator: arena).cast(),
54-
);
53+
if (key != null) {
54+
_glib.g_hash_table_insert(
55+
hashTable,
56+
'key'.toNativeUtf8(allocator: arena).cast(),
57+
key.toNativeUtf8(allocator: arena).cast(),
58+
);
59+
}
5560
arena.onReleaseAll(() => _glib.g_hash_table_destroy(hashTable));
5661
return hashTable;
5762
}
5863

5964
@override
6065
void clear() => using((arena) {
6166
final schema = _schemaFor(arena);
62-
final attributes = _attributes(key: '', arena: arena);
67+
final attributes = _attributes(arena: arena);
6368
_libSecret.secret_password_clearv_sync(
6469
schema,
6570
attributes,

packages/celest_core/lib/src/secure_storage/secure_storage_platform.vm.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:io';
33
import 'package:celest_core/src/secure_storage/secure_storage.android.dart';
44
import 'package:celest_core/src/secure_storage/secure_storage.dart';
55
import 'package:celest_core/src/secure_storage/secure_storage.darwin.dart';
6+
import 'package:celest_core/src/secure_storage/secure_storage.linux.dart';
67
import 'package:meta/meta.dart';
78

89
abstract base class SecureStoragePlatform implements SecureStorage {
@@ -15,6 +16,9 @@ abstract base class SecureStoragePlatform implements SecureStorage {
1516
if (Platform.isAndroid) {
1617
return SecureStoragePlatformAndroid(scope: scope ?? _defaultScope);
1718
}
19+
if (Platform.isLinux) {
20+
return SecureStoragePlatformLinux(scope: scope ?? _defaultScope);
21+
}
1822
throw UnsupportedError('This platform is not yet supported.');
1923
}
2024

0 commit comments

Comments
 (0)