fix(app): reserved bundled module ids, existing-data warning, clipboard cleared on hide, fields reset per screen

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-26 16:34:25 +01:00
1 parent 0024438706
commit ada391a88e
11 files changed
+404 -95

No files matched your search

+3 -1
View File
@@ -22,8 +22,10 @@ class _SynapseAppState extends State<SynapseApp> {
..loadTypeIcons() ..loadTypeIcons()
..modules.load(); ..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( late final _lifecycle = AppLifecycleListener(
onHide: () => _state.modules.suspend(),
onPause: () => _state.modules.suspend(), onPause: () => _state.modules.suspend(),
); );
+6
View File
@@ -155,6 +155,10 @@ abstract class GraphBackend {
/// Drops a module's running instance (its in-memory state, e.g. unlocked keys). /// Drops a module's running instance (its in-memory state, e.g. unlocked keys).
Future<void> stopModule(String id); Future<void> 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<bool> moduleHasData(String id);
} }
class _FfiLayout implements LayoutEngine { class _FfiLayout implements LayoutEngine {
@@ -411,4 +415,6 @@ class FfiGraphBackend implements GraphBackend {
@override @override
Future<void> stopModule(String id) => _g.stopModule(id: id); Future<void> stopModule(String id) => _g.stopModule(id: id);
@override
Future<bool> moduleHasData(String id) => _g.moduleHasData(id: id);
} }
+4
View File
@@ -132,6 +132,10 @@ abstract class SynapseGraph implements RustOpaqueInterface {
/// Sends a JSON request to a module and returns its JSON response. /// Sends a JSON request to a module and returns its JSON response.
Future<String> moduleCall({required String id, required String request}); Future<String> 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<bool> moduleHasData({required String id});
/// Installed modules, by name. /// Installed modules, by name.
Future<List<ModuleDto>> modules(); Future<List<ModuleDto>> modules();
+87 -39
View File
@@ -69,7 +69,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.13.0'; String get codegenVersion => '2.13.0';
@override @override
int get rustContentHash => -821319892; int get rustContentHash => -984841087;
static const kDefaultExternalLibraryLoaderConfig = static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig( ExternalLibraryLoaderConfig(
@@ -270,6 +270,11 @@ abstract class RustLibApi extends BaseApi {
required String request, required String request,
}); });
Future<bool> crateApiGraphSynapseGraphModuleHasData({
required SynapseGraph that,
required String id,
});
Future<List<ModuleDto>> crateApiGraphSynapseGraphModules({ Future<List<ModuleDto>> crateApiGraphSynapseGraphModules({
required SynapseGraph that, required SynapseGraph that,
}); });
@@ -1845,6 +1850,44 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["that", "id", "request"], argNames: ["that", "id", "request"],
); );
@override
Future<bool> 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 @override
Future<List<ModuleDto>> crateApiGraphSynapseGraphModules({ Future<List<ModuleDto>> crateApiGraphSynapseGraphModules({
required SynapseGraph that, required SynapseGraph that,
@@ -1860,7 +1903,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 36, funcId: 37,
port: port_, port: port_,
); );
}, },
@@ -1902,7 +1945,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 37, funcId: 38,
port: port_, port: port_,
); );
}, },
@@ -1933,7 +1976,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 38, funcId: 39,
port: port_, port: port_,
); );
}, },
@@ -1969,7 +2012,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 39, funcId: 40,
port: port_, port: port_,
); );
}, },
@@ -2007,7 +2050,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 40, funcId: 41,
port: port_, port: port_,
); );
}, },
@@ -2045,7 +2088,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 41, funcId: 42,
port: port_, port: port_,
); );
}, },
@@ -2083,7 +2126,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 42, funcId: 43,
port: port_, port: port_,
); );
}, },
@@ -2121,7 +2164,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 43, funcId: 44,
port: port_, port: port_,
); );
}, },
@@ -2159,7 +2202,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 44, funcId: 45,
port: port_, port: port_,
); );
}, },
@@ -2197,7 +2240,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 45, funcId: 46,
port: port_, port: port_,
); );
}, },
@@ -2235,7 +2278,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 46, funcId: 47,
port: port_, port: port_,
); );
}, },
@@ -2277,7 +2320,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 47, funcId: 48,
port: port_, port: port_,
); );
}, },
@@ -2317,7 +2360,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 48, funcId: 49,
port: port_, port: port_,
); );
}, },
@@ -2357,7 +2400,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 49, funcId: 50,
port: port_, port: port_,
); );
}, },
@@ -2397,7 +2440,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 50, funcId: 51,
port: port_, port: port_,
); );
}, },
@@ -2435,7 +2478,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 51, funcId: 52,
port: port_, port: port_,
); );
}, },
@@ -2475,7 +2518,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 52, funcId: 53,
port: port_, port: port_,
); );
}, },
@@ -2515,7 +2558,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 53, funcId: 54,
port: port_, port: port_,
); );
}, },
@@ -2553,7 +2596,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 54, funcId: 55,
port: port_, port: port_,
); );
}, },
@@ -2591,7 +2634,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 55, funcId: 56,
port: port_, port: port_,
); );
}, },
@@ -2631,7 +2674,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 56, funcId: 57,
port: port_, port: port_,
); );
}, },
@@ -2671,7 +2714,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 57, funcId: 58,
port: port_, port: port_,
); );
}, },
@@ -2711,7 +2754,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 58, funcId: 59,
port: port_, port: port_,
); );
}, },
@@ -2751,7 +2794,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 59, funcId: 60,
port: port_, port: port_,
); );
}, },
@@ -2791,7 +2834,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 60, funcId: 61,
port: port_, port: port_,
); );
}, },
@@ -2831,7 +2874,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 61, funcId: 62,
port: port_, port: port_,
); );
}, },
@@ -2871,7 +2914,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 62, funcId: 63,
port: port_, port: port_,
); );
}, },
@@ -2911,7 +2954,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 63, funcId: 64,
port: port_, port: port_,
); );
}, },
@@ -2951,7 +2994,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 64, funcId: 65,
port: port_, port: port_,
); );
}, },
@@ -2991,7 +3034,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 65, funcId: 66,
port: port_, port: port_,
); );
}, },
@@ -3031,7 +3074,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 66, funcId: 67,
port: port_, port: port_,
); );
}, },
@@ -3069,7 +3112,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 67, funcId: 68,
port: port_, port: port_,
); );
}, },
@@ -3105,7 +3148,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 68, funcId: 69,
port: port_, port: port_,
); );
}, },
@@ -3145,7 +3188,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 69, funcId: 70,
port: port_, port: port_,
); );
}, },
@@ -3176,7 +3219,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
that, that,
serializer, serializer,
); );
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 70)!; return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 71)!;
}, },
codec: SseCodec( codec: SseCodec(
decodeSuccessData: sse_decode_String, decodeSuccessData: sse_decode_String,
@@ -3207,7 +3250,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 71, funcId: 72,
port: port_, port: port_,
); );
}, },
@@ -3247,7 +3290,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 72, funcId: 73,
port: port_, port: port_,
); );
}, },
@@ -3287,7 +3330,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 73, funcId: 74,
port: port_, port: port_,
); );
}, },
@@ -6039,6 +6082,11 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph {
request: request, 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<bool> moduleHasData({required String id}) => RustLib.instance.api
.crateApiGraphSynapseGraphModuleHasData(that: this, id: id);
/// Installed modules, by name. /// Installed modules, by name.
Future<List<ModuleDto>> modules() => Future<List<ModuleDto>> modules() =>
RustLib.instance.api.crateApiGraphSynapseGraphModules(that: this); RustLib.instance.api.crateApiGraphSynapseGraphModules(that: this);
+37 -9
View File
@@ -42,6 +42,9 @@ class ModulesController extends ChangeNotifier {
final _timers = <String, Timer>{}; final _timers = <String, Timer>{};
Timer? _clipboardTimer; Timer? _clipboardTimer;
/// Text a module copied with a clear delay, until it is cleared.
String? _clipboardSecret;
bool _disposed = false; bool _disposed = false;
Iterable<ModuleDto> get enabled => installed.where((m) => m.enabled); Iterable<ModuleDto> get enabled => installed.where((m) => m.enabled);
@@ -76,6 +79,14 @@ class ModulesController extends ChangeNotifier {
Future<ModuleDto> inspect(Uint8List wasm) => backend.inspectModule(wasm); Future<ModuleDto> inspect(Uint8List wasm) => backend.inspectModule(wasm);
Future<bool> hasData(String id) async {
try {
return await backend.moduleHasData(id);
} catch (_) {
return false;
}
}
Future<ModuleDto> install(Uint8List wasm, List<String> granted) async { Future<ModuleDto> install(Uint8List wasm, List<String> granted) async {
final m = await backend.installModule(wasm, granted); final m = await backend.installModule(wasm, granted);
await load(); await load();
@@ -129,8 +140,10 @@ class ModulesController extends ChangeNotifier {
notifyListeners(); 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<void> suspend() async { Future<void> suspend() async {
await clearClipboard();
var changed = false; var changed = false;
for (final m in enabled.toList()) { for (final m in enabled.toList()) {
final r = await call(m.id, {'op': 'suspend'}); final r = await call(m.id, {'op': 'suspend'});
@@ -156,14 +169,10 @@ class ModulesController extends ChangeNotifier {
await Clipboard.setData(ClipboardData(text: text)); await Clipboard.setData(ClipboardData(text: text));
final ms = copy['clear_after_ms']; final ms = copy['clear_after_ms'];
_clipboardTimer?.cancel(); _clipboardTimer?.cancel();
_clipboardSecret = null;
if (ms is int && ms > 0) { if (ms is int && ms > 0) {
_clipboardTimer = Timer(Duration(milliseconds: ms), () async { _clipboardSecret = text;
// Only clear what we put there. _clipboardTimer = Timer(Duration(milliseconds: ms), clearClipboard);
final now = await Clipboard.getData(Clipboard.kTextPlain);
if (now?.text == text) {
await Clipboard.setData(const ClipboardData(text: ''));
}
});
} }
} }
if (e['toast'] is String) toasts.add(e['toast'] as String); if (e['toast'] is String) toasts.add(e['toast'] as String);
@@ -176,13 +185,32 @@ class ModulesController extends ChangeNotifier {
return (toasts: toasts, openView: openView); 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<void> 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 @override
void dispose() { void dispose() {
_disposed = true; _disposed = true;
for (final t in _timers.values) { for (final t in _timers.values) {
t.cancel(); t.cancel();
} }
_clipboardTimer?.cancel(); clearClipboard().ignore();
super.dispose(); super.dispose();
} }
} }
+10
View File
@@ -87,8 +87,18 @@ class _ModuleViewState extends State<ModuleView> {
}); });
} }
/// 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. /// 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<String, dynamic> tree) { void _syncFields(Map<String, dynamic> tree) {
if (tree['key'] != _screen) {
_screen = tree['key'];
_sent.clear();
_hidden.clear();
}
final seen = <String>{}; final seen = <String>{};
void walk(Object? w) { void walk(Object? w) {
if (w is List) { if (w is List) {
+46 -6
View File
@@ -98,8 +98,14 @@ class ModulesSettings extends StatelessWidget {
} }
} }
/// Reads the module, asks for consent to its permissions and installs it. /// Reads the module, asks for consent to its permissions and installs it. Ids starting with
Future<void> installModuleBytes(BuildContext context, Uint8List bytes) async { /// `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<void> installModuleBytes(
BuildContext context,
Uint8List bytes, {
bool bundled = false,
}) async {
final modules = AppScope.read(context).modules; final modules = AppScope.read(context).modules;
final messenger = ScaffoldMessenger.of(context); final messenger = ScaffoldMessenger.of(context);
final ModuleDto m; final ModuleDto m;
@@ -111,11 +117,27 @@ Future<void> installModuleBytes(BuildContext context, Uint8List bytes) async {
); );
return; 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 previous = modules.byId(m.id);
final existingData = previous == null && await modules.hasData(m.id);
if (!context.mounted) return;
final ok = await showDialog<bool>( final ok = await showDialog<bool>(
context: context, context: context,
builder: (ctx) => _ConsentDialog(module: m, previous: previous), builder: (ctx) => _ConsentDialog(
module: m,
previous: previous,
existingData: existingData,
),
); );
if (ok != true) return; if (ok != true) return;
try { try {
@@ -136,10 +158,17 @@ String _message(Object e) {
} }
class _ConsentDialog extends StatelessWidget { 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 module;
final ModuleDto? previous; final ModuleDto? previous;
/// The graph already holds data under this module id, which it will be able to read.
final bool existingData;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final colors = context.colors; final colors = context.colors;
@@ -164,6 +193,15 @@ class _ConsentDialog extends StatelessWidget {
const SizedBox(height: 8), const SizedBox(height: 8),
Text(m.description), 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), const SizedBox(height: 16),
Text( Text(
m.permissions.isEmpty m.permissions.isEmpty
@@ -402,7 +440,9 @@ class _BundledModule extends StatelessWidget {
key: ValueKey('module-install-$id'), key: ValueKey('module-install-$id'),
onPressed: () async { onPressed: () async {
final bytes = await loadBundledModule(asset); 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'), child: const Text('Install'),
), ),
+100 -1
View File
@@ -1,4 +1,3 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -337,4 +336,104 @@ void main() {
expect(b.moduleRequests.last.$2['op'], 'suspend'); expect(b.moduleRequests.last.$2['op'], 'suspend');
expect(app.modules.macroVersion, greaterThan(before)); 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<TextField>(
find.widgetWithText(TextField, 'Master password'),
);
expect(field.controller!.text, '');
});
} }
+5
View File
@@ -73,6 +73,11 @@ class MemoryBackend implements GraphBackend {
@override @override
Future<void> stopModule(String id) async => stoppedModules.add(id); Future<void> stopModule(String id) async => stoppedModules.add(id);
/// Module ids with data in the graph.
final moduleData = <String>{};
@override
Future<bool> moduleHasData(String id) async => moduleData.contains(id);
static ModuleDto withEnabled(ModuleDto m, bool enabled) => ModuleDto( static ModuleDto withEnabled(ModuleDto m, bool enabled) => ModuleDto(
id: m.id, id: m.id,
name: m.name, name: m.name,
+6
View File
@@ -51,6 +51,12 @@ impl SynapseGraph {
Ok(self.modules.call(&id, &req)?.to_string()) 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<bool> {
Ok(self.modules.has_data(&id)?)
}
/// Stops a module's running instance (dropping its in-memory state). /// Stops a module's running instance (dropping its in-memory state).
pub fn stop_module(&self, id: String) { pub fn stop_module(&self, id: String) {
self.modules.stop(&id); self.modules.stop(&id);
+100 -39
View File
@@ -41,7 +41,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
default_rust_auto_opaque = RustAutoOpaqueMoi, default_rust_auto_opaque = RustAutoOpaqueMoi,
); );
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.13.0"; 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 // 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::SseCodec, _, _>(
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 = <RustOpaqueMoi<
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
>>::sse_decode(&mut deserializer);
let api_id = <String>::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( fn wire__crate__api__graph__SynapseGraph_modules_impl(
port_: flutter_rust_bridge::for_generated::MessagePort, port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
@@ -5119,183 +5174,189 @@ fn pde_ffi_dispatcher_primary_impl(
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
36 => wire__crate__api__graph__SynapseGraph_modules_impl(port, ptr, rust_vec_len, data_len), 36 => wire__crate__api__graph__SynapseGraph_module_has_data_impl(
37 => { 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) 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 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len),
39 => { 40 => {
wire__crate__api__graph__SynapseGraph_open_page_impl(port, ptr, rust_vec_len, data_len) 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, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
41 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len), 42 => 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_impl(port, ptr, rust_vec_len, data_len),
43 => wire__crate__api__graph__SynapseGraph_page_by_title_impl( 44 => wire__crate__api__graph__SynapseGraph_page_by_title_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
44 => wire__crate__api__graph__SynapseGraph_page_structure_impl( 45 => wire__crate__api__graph__SynapseGraph_page_structure_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
45 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( 46 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
46 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( 47 => wire__crate__api__graph__SynapseGraph_purge_pages_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
47 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( 48 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
48 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( 49 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
49 => wire__crate__api__graph__SynapseGraph_record_visit_impl( 50 => wire__crate__api__graph__SynapseGraph_record_visit_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
50 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), 51 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len),
51 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( 52 => wire__crate__api__graph__SynapseGraph_remove_alias_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
52 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( 53 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
53 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( 54 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
54 => { 55 => {
wire__crate__api__graph__SynapseGraph_remove_tag_impl(port, ptr, rust_vec_len, data_len) 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, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
56 => wire__crate__api__graph__SynapseGraph_rename_page_impl( 57 => wire__crate__api__graph__SynapseGraph_rename_page_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
57 => { 58 => {
wire__crate__api__graph__SynapseGraph_rename_tag_impl(port, ptr, rust_vec_len, data_len) 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, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
59 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( 60 => wire__crate__api__graph__SynapseGraph_search_blocks_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
60 => wire__crate__api__graph__SynapseGraph_search_titles_impl( 61 => wire__crate__api__graph__SynapseGraph_search_titles_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
61 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl( 62 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
62 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl( 63 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
63 => wire__crate__api__graph__SynapseGraph_set_module_enabled_impl( 64 => wire__crate__api__graph__SynapseGraph_set_module_enabled_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
64 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl( 65 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
65 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( 66 => wire__crate__api__graph__SynapseGraph_set_page_type_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
66 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl( 67 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
67 => wire__crate__api__graph__SynapseGraph_stop_module_impl( 68 => wire__crate__api__graph__SynapseGraph_stop_module_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
68 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl( 69 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
69 => { 70 => {
wire__crate__api__graph__SynapseGraph_timeline_impl(port, ptr, rust_vec_len, data_len) 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, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
72 => wire__crate__api__graph__SynapseGraph_uninstall_module_impl( 73 => wire__crate__api__graph__SynapseGraph_uninstall_module_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
73 => wire__crate__api__graph__SynapseGraph_update_block_impl( 74 => wire__crate__api__graph__SynapseGraph_update_block_impl(
port, port,
ptr, ptr,
rust_vec_len, 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), 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), 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), 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!(), _ => unreachable!(),
} }
} }