From ada391a88ed02ca517cabca57c35b6e4aff52190 Mon Sep 17 00:00:00 2001 From: Dasemu Date: Mon, 26 Oct 2026 16:34:25 +0100 Subject: [PATCH] fix(app): reserved bundled module ids, existing-data warning, clipboard cleared on hide, fields reset per screen Co-Authored-By: Claude Opus 5.5 --- app/lib/src/app.dart | 4 +- app/lib/src/backend/graph_backend.dart | 6 + app/lib/src/rust/api/graph.dart | 4 + app/lib/src/rust/frb_generated.dart | 126 ++++++++++++++------- app/lib/src/state/modules.dart | 46 ++++++-- app/lib/src/views/module_view.dart | 10 ++ app/lib/src/views/modules_settings.dart | 52 ++++++++- app/test/modules_test.dart | 101 ++++++++++++++++- app/test/support/memory_backend.dart | 5 + crates/synapse-ffi/src/api/modules.rs | 6 + crates/synapse-ffi/src/frb_generated.rs | 139 +++++++++++++++++------- 11 files changed, 404 insertions(+), 95 deletions(-) diff --git a/app/lib/src/app.dart b/app/lib/src/app.dart index b35e622..cf0d1ff 100644 --- a/app/lib/src/app.dart +++ b/app/lib/src/app.dart @@ -22,8 +22,10 @@ class _SynapseAppState extends State { ..loadTypeIcons() ..modules.load(); - /// On phones, modules lock what they hold (the secrets vault) when the app is paused. + /// Modules lock what they hold (the secrets vault) when the app is hidden (minimised, + /// another app in front) or paused. late final _lifecycle = AppLifecycleListener( + onHide: () => _state.modules.suspend(), onPause: () => _state.modules.suspend(), ); diff --git a/app/lib/src/backend/graph_backend.dart b/app/lib/src/backend/graph_backend.dart index 7dc2aa4..b145c20 100644 --- a/app/lib/src/backend/graph_backend.dart +++ b/app/lib/src/backend/graph_backend.dart @@ -155,6 +155,10 @@ abstract class GraphBackend { /// Drops a module's running instance (its in-memory state, e.g. unlocked keys). Future stopModule(String id); + + /// Whether the graph already holds data for module [id] (synced or left by an earlier + /// install); a module installed under that id can read it. + Future moduleHasData(String id); } class _FfiLayout implements LayoutEngine { @@ -411,4 +415,6 @@ class FfiGraphBackend implements GraphBackend { @override Future stopModule(String id) => _g.stopModule(id: id); + @override + Future moduleHasData(String id) => _g.moduleHasData(id: id); } diff --git a/app/lib/src/rust/api/graph.dart b/app/lib/src/rust/api/graph.dart index 4b56e84..5617285 100644 --- a/app/lib/src/rust/api/graph.dart +++ b/app/lib/src/rust/api/graph.dart @@ -132,6 +132,10 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// Sends a JSON request to a module and returns its JSON response. Future moduleCall({required String id, required String request}); + /// Whether the graph already holds data for module `id` (a module installed under that id + /// can read it; the consent dialog warns about it). + Future moduleHasData({required String id}); + /// Installed modules, by name. Future> modules(); diff --git a/app/lib/src/rust/frb_generated.dart b/app/lib/src/rust/frb_generated.dart index 7416cc5..b293048 100644 --- a/app/lib/src/rust/frb_generated.dart +++ b/app/lib/src/rust/frb_generated.dart @@ -69,7 +69,7 @@ class RustLib extends BaseEntrypoint { String get codegenVersion => '2.13.0'; @override - int get rustContentHash => -821319892; + int get rustContentHash => -984841087; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -270,6 +270,11 @@ abstract class RustLibApi extends BaseApi { required String request, }); + Future crateApiGraphSynapseGraphModuleHasData({ + required SynapseGraph that, + required String id, + }); + Future> crateApiGraphSynapseGraphModules({ required SynapseGraph that, }); @@ -1845,6 +1850,44 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "id", "request"], ); + @override + Future crateApiGraphSynapseGraphModuleHasData({ + required SynapseGraph that, + required String id, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(id, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 36, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_bool, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphModuleHasDataConstMeta, + argValues: [that, id], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphModuleHasDataConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_module_has_data", + argNames: ["that", "id"], + ); + @override Future> crateApiGraphSynapseGraphModules({ required SynapseGraph that, @@ -1860,7 +1903,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 36, + funcId: 37, port: port_, ); }, @@ -1902,7 +1945,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 37, + funcId: 38, port: port_, ); }, @@ -1933,7 +1976,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 38, + funcId: 39, port: port_, ); }, @@ -1969,7 +2012,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 39, + funcId: 40, port: port_, ); }, @@ -2007,7 +2050,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 40, + funcId: 41, port: port_, ); }, @@ -2045,7 +2088,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 41, + funcId: 42, port: port_, ); }, @@ -2083,7 +2126,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 42, + funcId: 43, port: port_, ); }, @@ -2121,7 +2164,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 43, + funcId: 44, port: port_, ); }, @@ -2159,7 +2202,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 44, + funcId: 45, port: port_, ); }, @@ -2197,7 +2240,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 45, + funcId: 46, port: port_, ); }, @@ -2235,7 +2278,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 46, + funcId: 47, port: port_, ); }, @@ -2277,7 +2320,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 47, + funcId: 48, port: port_, ); }, @@ -2317,7 +2360,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 48, + funcId: 49, port: port_, ); }, @@ -2357,7 +2400,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 49, + funcId: 50, port: port_, ); }, @@ -2397,7 +2440,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 50, + funcId: 51, port: port_, ); }, @@ -2435,7 +2478,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 51, + funcId: 52, port: port_, ); }, @@ -2475,7 +2518,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 52, + funcId: 53, port: port_, ); }, @@ -2515,7 +2558,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 53, + funcId: 54, port: port_, ); }, @@ -2553,7 +2596,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 54, + funcId: 55, port: port_, ); }, @@ -2591,7 +2634,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 55, + funcId: 56, port: port_, ); }, @@ -2631,7 +2674,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 56, + funcId: 57, port: port_, ); }, @@ -2671,7 +2714,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 57, + funcId: 58, port: port_, ); }, @@ -2711,7 +2754,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 58, + funcId: 59, port: port_, ); }, @@ -2751,7 +2794,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 59, + funcId: 60, port: port_, ); }, @@ -2791,7 +2834,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 60, + funcId: 61, port: port_, ); }, @@ -2831,7 +2874,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 61, + funcId: 62, port: port_, ); }, @@ -2871,7 +2914,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 62, + funcId: 63, port: port_, ); }, @@ -2911,7 +2954,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 63, + funcId: 64, port: port_, ); }, @@ -2951,7 +2994,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 64, + funcId: 65, port: port_, ); }, @@ -2991,7 +3034,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 65, + funcId: 66, port: port_, ); }, @@ -3031,7 +3074,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 66, + funcId: 67, port: port_, ); }, @@ -3069,7 +3112,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 67, + funcId: 68, port: port_, ); }, @@ -3105,7 +3148,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 68, + funcId: 69, port: port_, ); }, @@ -3145,7 +3188,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 69, + funcId: 70, port: port_, ); }, @@ -3176,7 +3219,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { that, serializer, ); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 70)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 71)!; }, codec: SseCodec( decodeSuccessData: sse_decode_String, @@ -3207,7 +3250,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 71, + funcId: 72, port: port_, ); }, @@ -3247,7 +3290,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 72, + funcId: 73, port: port_, ); }, @@ -3287,7 +3330,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 73, + funcId: 74, port: port_, ); }, @@ -6039,6 +6082,11 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { request: request, ); + /// Whether the graph already holds data for module `id` (a module installed under that id + /// can read it; the consent dialog warns about it). + Future moduleHasData({required String id}) => RustLib.instance.api + .crateApiGraphSynapseGraphModuleHasData(that: this, id: id); + /// Installed modules, by name. Future> modules() => RustLib.instance.api.crateApiGraphSynapseGraphModules(that: this); diff --git a/app/lib/src/state/modules.dart b/app/lib/src/state/modules.dart index 02a350d..243a107 100644 --- a/app/lib/src/state/modules.dart +++ b/app/lib/src/state/modules.dart @@ -42,6 +42,9 @@ class ModulesController extends ChangeNotifier { final _timers = {}; Timer? _clipboardTimer; + + /// Text a module copied with a clear delay, until it is cleared. + String? _clipboardSecret; bool _disposed = false; Iterable get enabled => installed.where((m) => m.enabled); @@ -76,6 +79,14 @@ class ModulesController extends ChangeNotifier { Future inspect(Uint8List wasm) => backend.inspectModule(wasm); + Future hasData(String id) async { + try { + return await backend.moduleHasData(id); + } catch (_) { + return false; + } + } + Future install(Uint8List wasm, List granted) async { final m = await backend.installModule(wasm, granted); await load(); @@ -129,8 +140,10 @@ class ModulesController extends ChangeNotifier { notifyListeners(); } - /// The app is going to the background: modules lock what they hold (e.g. the vault). + /// The app is going to the background: modules lock what they hold (e.g. the vault), and a + /// secret still on the clipboard is cleared (a backgrounded app cannot rely on its timer). Future suspend() async { + await clearClipboard(); var changed = false; for (final m in enabled.toList()) { final r = await call(m.id, {'op': 'suspend'}); @@ -156,14 +169,10 @@ class ModulesController extends ChangeNotifier { await Clipboard.setData(ClipboardData(text: text)); final ms = copy['clear_after_ms']; _clipboardTimer?.cancel(); + _clipboardSecret = null; if (ms is int && ms > 0) { - _clipboardTimer = Timer(Duration(milliseconds: ms), () async { - // Only clear what we put there. - final now = await Clipboard.getData(Clipboard.kTextPlain); - if (now?.text == text) { - await Clipboard.setData(const ClipboardData(text: '')); - } - }); + _clipboardSecret = text; + _clipboardTimer = Timer(Duration(milliseconds: ms), clearClipboard); } } if (e['toast'] is String) toasts.add(e['toast'] as String); @@ -176,13 +185,32 @@ class ModulesController extends ChangeNotifier { return (toasts: toasts, openView: openView); } + /// Clears the clipboard if it still holds the secret a module copied (or if it cannot be + /// read, as on Android in the background: then clearing is the safe choice). + Future clearClipboard() async { + final secret = _clipboardSecret; + _clipboardTimer?.cancel(); + _clipboardSecret = null; + if (secret == null) return; + String? now; + var readable = true; + try { + now = (await Clipboard.getData(Clipboard.kTextPlain))?.text; + } catch (_) { + readable = false; + } + if (!readable || now == null || now == secret) { + await Clipboard.setData(const ClipboardData(text: '')); + } + } + @override void dispose() { _disposed = true; for (final t in _timers.values) { t.cancel(); } - _clipboardTimer?.cancel(); + clearClipboard().ignore(); super.dispose(); } } diff --git a/app/lib/src/views/module_view.dart b/app/lib/src/views/module_view.dart index 2b61bc0..8478e2d 100644 --- a/app/lib/src/views/module_view.dart +++ b/app/lib/src/views/module_view.dart @@ -87,8 +87,18 @@ class _ModuleViewState extends State { }); } + /// The `key` of the last tree: a different one is another screen. + Object? _screen; + /// Applies field values from the new tree and drops controllers of fields that are gone. + /// On a new screen every field starts from the tree, so text typed on one screen (a + /// password) never carries over to a field with the same id on another. void _syncFields(Map tree) { + if (tree['key'] != _screen) { + _screen = tree['key']; + _sent.clear(); + _hidden.clear(); + } final seen = {}; void walk(Object? w) { if (w is List) { diff --git a/app/lib/src/views/modules_settings.dart b/app/lib/src/views/modules_settings.dart index 99ef2ec..541c07a 100644 --- a/app/lib/src/views/modules_settings.dart +++ b/app/lib/src/views/modules_settings.dart @@ -98,8 +98,14 @@ class ModulesSettings extends StatelessWidget { } } -/// Reads the module, asks for consent to its permissions and installs it. -Future installModuleBytes(BuildContext context, Uint8List bytes) async { +/// Reads the module, asks for consent to its permissions and installs it. Ids starting with +/// `synapse.` are reserved for the modules bundled with the app ([bundled]), so a file cannot +/// pose as one of them and inherit its data. +Future installModuleBytes( + BuildContext context, + Uint8List bytes, { + bool bundled = false, +}) async { final modules = AppScope.read(context).modules; final messenger = ScaffoldMessenger.of(context); final ModuleDto m; @@ -111,11 +117,27 @@ Future installModuleBytes(BuildContext context, Uint8List bytes) async { ); return; } - if (!context.mounted) return; + if (!bundled && m.id.startsWith('synapse.')) { + messenger.showSnackBar( + SnackBar( + content: Text( + '${m.id}: ids starting with "synapse." are reserved for modules included ' + 'with Synapse.', + ), + ), + ); + return; + } final previous = modules.byId(m.id); + final existingData = previous == null && await modules.hasData(m.id); + if (!context.mounted) return; final ok = await showDialog( context: context, - builder: (ctx) => _ConsentDialog(module: m, previous: previous), + builder: (ctx) => _ConsentDialog( + module: m, + previous: previous, + existingData: existingData, + ), ); if (ok != true) return; try { @@ -136,10 +158,17 @@ String _message(Object e) { } class _ConsentDialog extends StatelessWidget { - const _ConsentDialog({required this.module, this.previous}); + const _ConsentDialog({ + required this.module, + this.previous, + this.existingData = false, + }); final ModuleDto module; final ModuleDto? previous; + /// The graph already holds data under this module id, which it will be able to read. + final bool existingData; + @override Widget build(BuildContext context) { final colors = context.colors; @@ -164,6 +193,15 @@ class _ConsentDialog extends StatelessWidget { const SizedBox(height: 8), Text(m.description), ], + if (existingData) ...[ + const SizedBox(height: 12), + Text( + 'This graph already holds data of a module with the id ${m.id} ' + '(from another device or an earlier install). This module will be ' + 'able to read it. Install it only if you trust where it comes from.', + style: TextStyle(color: Theme.of(context).colorScheme.error), + ), + ], const SizedBox(height: 16), Text( m.permissions.isEmpty @@ -402,7 +440,9 @@ class _BundledModule extends StatelessWidget { key: ValueKey('module-install-$id'), onPressed: () async { final bytes = await loadBundledModule(asset); - if (context.mounted) await installModuleBytes(context, bytes); + if (context.mounted) { + await installModuleBytes(context, bytes, bundled: true); + } }, child: const Text('Install'), ), diff --git a/app/test/modules_test.dart b/app/test/modules_test.dart index fcefcaf..960c38d 100644 --- a/app/test/modules_test.dart +++ b/app/test/modules_test.dart @@ -1,4 +1,3 @@ - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -337,4 +336,104 @@ void main() { expect(b.moduleRequests.last.$2['op'], 'suspend'); expect(app.modules.macroVersion, greaterThan(before)); }); + + testWidgets('a file cannot pose as a bundled module', (tester) async { + final b = MemoryBackend()..inspectResult = vault(); + pickModuleFile = () async => Uint8List(4); + await pump(tester, b, route: const SettingsRoute(), height: 3000); + await tester.tap(find.byKey(const ValueKey('module-install-file'))); + await settle(tester); + expect( + find.textContaining('reserved for modules included'), + findsOneWidget, + ); + expect(find.text('Install Secrets 0.1.0?'), findsNothing); + expect(b.installedModules, isEmpty); + }); + + testWidgets('installing over existing data warns in the consent dialog', ( + tester, + ) async { + final m = vault(); + final b = MemoryBackend() + ..inspectResult = ModuleDto( + id: 'acme.notes', + name: 'Notes', + version: '1', + description: '', + author: 'Acme', + permissions: const ['storage'], + views: const [], + macros: const [], + enabled: true, + size: m.size, + ) + ..moduleData.add('acme.notes'); + pickModuleFile = () async => Uint8List(4); + await pump(tester, b, route: const SettingsRoute(), height: 3000); + await tester.tap(find.byKey(const ValueKey('module-install-file'))); + await settle(tester); + expect(find.text('Install Notes 1?'), findsOneWidget); + expect(find.textContaining('already holds data'), findsOneWidget); + }); + + testWidgets('suspending clears a copied secret from the clipboard', ( + tester, + ) async { + final writes = mockClipboard(tester); + final b = MemoryBackend(); + b.installedModules['synapse.secrets'] = vault(); + final app = await pump(tester, b); + await app.modules.applyEffects({ + 'effects': [ + { + 'copy': {'text': 'hunter2', 'clear_after_ms': 30000}, + }, + ], + }); + await app.modules.suspend(); + expect(writes, ['hunter2', '']); + // The pending timer was cancelled: nothing more happens later. + await tester.pump(const Duration(seconds: 31)); + expect(writes, ['hunter2', '']); + }); + + testWidgets('fields start empty on a new screen even with a reused id', ( + tester, + ) async { + final b = MemoryBackend(); + b.installedModules['synapse.secrets'] = vault(); + var screen = 'edit'; + b.moduleHandlers['synapse.secrets'] = (req) { + if (req['op'] == 'event') screen = 'locked'; + return { + 'ui': { + 'type': 'column', + 'key': screen, + 'children': [ + { + 'type': 'field', + 'id': 'password', + 'label': screen == 'edit' ? 'Password' : 'Master password', + 'value': '', + 'secret': true, + }, + {'type': 'button', 'label': 'Go', 'action': 'go'}, + ], + }, + }; + }; + await pump( + tester, + b, + route: const ModuleRoute('synapse.secrets', 'vault', title: 'Secrets'), + ); + await tester.enterText(find.widgetWithText(TextField, 'Password'), 'typed'); + await tester.tap(find.text('Go')); + await settle(tester); + final field = tester.widget( + find.widgetWithText(TextField, 'Master password'), + ); + expect(field.controller!.text, ''); + }); } diff --git a/app/test/support/memory_backend.dart b/app/test/support/memory_backend.dart index 65b7e6c..b695252 100644 --- a/app/test/support/memory_backend.dart +++ b/app/test/support/memory_backend.dart @@ -73,6 +73,11 @@ class MemoryBackend implements GraphBackend { @override Future stopModule(String id) async => stoppedModules.add(id); + /// Module ids with data in the graph. + final moduleData = {}; + @override + Future moduleHasData(String id) async => moduleData.contains(id); + static ModuleDto withEnabled(ModuleDto m, bool enabled) => ModuleDto( id: m.id, name: m.name, diff --git a/crates/synapse-ffi/src/api/modules.rs b/crates/synapse-ffi/src/api/modules.rs index 9a379c5..8b96a30 100644 --- a/crates/synapse-ffi/src/api/modules.rs +++ b/crates/synapse-ffi/src/api/modules.rs @@ -51,6 +51,12 @@ impl SynapseGraph { Ok(self.modules.call(&id, &req)?.to_string()) } + /// Whether the graph already holds data for module `id` (a module installed under that id + /// can read it; the consent dialog warns about it). + pub fn module_has_data(&self, id: String) -> Result { + Ok(self.modules.has_data(&id)?) + } + /// Stops a module's running instance (dropping its in-memory state). pub fn stop_module(&self, id: String) { self.modules.stop(&id); diff --git a/crates/synapse-ffi/src/frb_generated.rs b/crates/synapse-ffi/src/frb_generated.rs index b178063..0e7441e 100644 --- a/crates/synapse-ffi/src/frb_generated.rs +++ b/crates/synapse-ffi/src/frb_generated.rs @@ -41,7 +41,7 @@ flutter_rust_bridge::frb_generated_boilerplate!( default_rust_auto_opaque = RustAutoOpaqueMoi, ); pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.13.0"; -pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -821319892; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -984841087; // Section: executor @@ -1960,6 +1960,61 @@ fn wire__crate__api__graph__SynapseGraph_module_call_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_module_has_data_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "SynapseGraph_module_has_data", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_that = , + >>::sse_decode(&mut deserializer); + let api_id = ::sse_decode(&mut deserializer); + deserializer.end(); + move |context| { + transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>( + (move || { + let mut api_that_guard = None; + let decode_indices_ = + flutter_rust_bridge::for_generated::lockable_compute_decode_order( + vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new( + &api_that, 0, false, + )], + ); + for i in decode_indices_ { + match i { + 0 => api_that_guard = Some(api_that.lockable_decode_sync_ref()), + _ => unreachable!(), + } + } + let api_that_guard = api_that_guard.unwrap(); + let output_ok = crate::api::graph::SynapseGraph::module_has_data( + &*api_that_guard, + api_id, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_modules_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -5119,183 +5174,189 @@ fn pde_ffi_dispatcher_primary_impl( rust_vec_len, data_len, ), - 36 => wire__crate__api__graph__SynapseGraph_modules_impl(port, ptr, rust_vec_len, data_len), - 37 => { + 36 => wire__crate__api__graph__SynapseGraph_module_has_data_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 37 => wire__crate__api__graph__SynapseGraph_modules_impl(port, ptr, rust_vec_len, data_len), + 38 => { wire__crate__api__graph__SynapseGraph_move_block_impl(port, ptr, rust_vec_len, data_len) } - 38 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len), - 39 => { + 39 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len), + 40 => { wire__crate__api__graph__SynapseGraph_open_page_impl(port, ptr, rust_vec_len, data_len) } - 40 => wire__crate__api__graph__SynapseGraph_outdent_block_impl( + 41 => wire__crate__api__graph__SynapseGraph_outdent_block_impl( port, ptr, rust_vec_len, data_len, ), - 41 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len), - 42 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len), - 43 => wire__crate__api__graph__SynapseGraph_page_by_title_impl( + 42 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len), + 43 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len), + 44 => wire__crate__api__graph__SynapseGraph_page_by_title_impl( port, ptr, rust_vec_len, data_len, ), - 44 => wire__crate__api__graph__SynapseGraph_page_structure_impl( + 45 => wire__crate__api__graph__SynapseGraph_page_structure_impl( port, ptr, rust_vec_len, data_len, ), - 45 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( + 46 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( port, ptr, rust_vec_len, data_len, ), - 46 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( + 47 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( port, ptr, rust_vec_len, data_len, ), - 47 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( + 48 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( port, ptr, rust_vec_len, data_len, ), - 48 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( + 49 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( port, ptr, rust_vec_len, data_len, ), - 49 => wire__crate__api__graph__SynapseGraph_record_visit_impl( + 50 => wire__crate__api__graph__SynapseGraph_record_visit_impl( port, ptr, rust_vec_len, data_len, ), - 50 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), - 51 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( + 51 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), + 52 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( port, ptr, rust_vec_len, data_len, ), - 52 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( + 53 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( port, ptr, rust_vec_len, data_len, ), - 53 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( + 54 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( port, ptr, rust_vec_len, data_len, ), - 54 => { + 55 => { wire__crate__api__graph__SynapseGraph_remove_tag_impl(port, ptr, rust_vec_len, data_len) } - 55 => wire__crate__api__graph__SynapseGraph_remove_type_impl( + 56 => wire__crate__api__graph__SynapseGraph_remove_type_impl( port, ptr, rust_vec_len, data_len, ), - 56 => wire__crate__api__graph__SynapseGraph_rename_page_impl( + 57 => wire__crate__api__graph__SynapseGraph_rename_page_impl( port, ptr, rust_vec_len, data_len, ), - 57 => { + 58 => { wire__crate__api__graph__SynapseGraph_rename_tag_impl(port, ptr, rust_vec_len, data_len) } - 58 => wire__crate__api__graph__SynapseGraph_rename_type_impl( + 59 => wire__crate__api__graph__SynapseGraph_rename_type_impl( port, ptr, rust_vec_len, data_len, ), - 59 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( + 60 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( port, ptr, rust_vec_len, data_len, ), - 60 => wire__crate__api__graph__SynapseGraph_search_titles_impl( + 61 => wire__crate__api__graph__SynapseGraph_search_titles_impl( port, ptr, rust_vec_len, data_len, ), - 61 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl( + 62 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl( port, ptr, rust_vec_len, data_len, ), - 62 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl( + 63 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl( port, ptr, rust_vec_len, data_len, ), - 63 => wire__crate__api__graph__SynapseGraph_set_module_enabled_impl( + 64 => wire__crate__api__graph__SynapseGraph_set_module_enabled_impl( port, ptr, rust_vec_len, data_len, ), - 64 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl( + 65 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl( port, ptr, rust_vec_len, data_len, ), - 65 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( + 66 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( port, ptr, rust_vec_len, data_len, ), - 66 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl( + 67 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl( port, ptr, rust_vec_len, data_len, ), - 67 => wire__crate__api__graph__SynapseGraph_stop_module_impl( + 68 => wire__crate__api__graph__SynapseGraph_stop_module_impl( port, ptr, rust_vec_len, data_len, ), - 68 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl( + 69 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl( port, ptr, rust_vec_len, data_len, ), - 69 => { + 70 => { wire__crate__api__graph__SynapseGraph_timeline_impl(port, ptr, rust_vec_len, data_len) } - 71 => wire__crate__api__graph__SynapseGraph_type_catalog_impl( + 72 => wire__crate__api__graph__SynapseGraph_type_catalog_impl( port, ptr, rust_vec_len, data_len, ), - 72 => wire__crate__api__graph__SynapseGraph_uninstall_module_impl( + 73 => wire__crate__api__graph__SynapseGraph_uninstall_module_impl( port, ptr, rust_vec_len, data_len, ), - 73 => wire__crate__api__graph__SynapseGraph_update_block_impl( + 74 => wire__crate__api__graph__SynapseGraph_update_block_impl( port, ptr, rust_vec_len, @@ -5316,7 +5377,7 @@ fn pde_ffi_dispatcher_sync_impl( 1 => wire__crate__api__layout__ForceLayout_new_impl(ptr, rust_vec_len, data_len), 10 => wire__crate__api__graph__SynapseGraph_asset_path_impl(ptr, rust_vec_len, data_len), 20 => wire__crate__api__graph__SynapseGraph_dir_impl(ptr, rust_vec_len, data_len), - 70 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len), + 71 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len), _ => unreachable!(), } }