From 5cbc0814f6c5e815c67f7823aa58ce9587a354e8 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 26 Jan 2021 14:39:22 -0800 Subject: [PATCH] Unlock Profiles --- lib/cwtch/cwtch.dart | 1 + lib/cwtch/ffi.dart | 11 +++++++++++ lib/cwtch/gomobile.dart | 5 ++++- lib/views/profilemgrview.dart | 26 ++++++-------------------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/cwtch/cwtch.dart b/lib/cwtch/cwtch.dart index d1df79d..850bb13 100644 --- a/lib/cwtch/cwtch.dart +++ b/lib/cwtch/cwtch.dart @@ -3,6 +3,7 @@ abstract class Cwtch { void SelectProfile(String onion); void CreateProfile(String nick, String pass); + void LoadProfiles(String pass); Future ACNEvents(); Future ContactEvents(); diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index b8356ca..e2953f0 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -18,6 +18,9 @@ typedef VoidFromStringStringFn = void Function(Pointer, int, Pointer typedef access_cwtch_eventbus_function = Void Function(); typedef NextEventFn = void Function(); +typedef string_to_void_function = Void Function(Pointer str, Int32 length); +typedef StringFn = void Function(Pointer dir, int); + typedef get_json_blob_void_function = Pointer Function(); typedef GetJsonBlobVoidFn = Pointer Function(); @@ -80,6 +83,14 @@ class CwtchFfi implements Cwtch { CreateProfile(Utf8.toUtf8(nick), nick.length, Utf8.toUtf8(pass), pass.length); } + // ignore: non_constant_identifier_names + void LoadProfiles(String pass) { + var loadProfileC = library.lookup>("c_LoadProfiles"); + // ignore: non_constant_identifier_names + final LoadProfiles = loadProfileC.asFunction(); + LoadProfiles(Utf8.toUtf8(pass), pass.length); + } + Future ACNEvents() async { var acnEventsC = library.lookup>( "c_ACNEvents"); diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index a0816d6..bd976fa 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -57,6 +57,10 @@ class CwtchGomobile implements Cwtch { cwtchPlatform.invokeMethod("CreateProfile", {"nick": nick, "pass": pass}); } + void LoadProfiles(String pass) { + cwtchPlatform.invokeMethod("LoadProfiles", {"pass": pass}); + } + Future ACNEvents() { return cwtchPlatform.invokeMethod("ACNEvents"); } @@ -87,5 +91,4 @@ class CwtchGomobile implements Cwtch { return cwtchPlatform.invokeMethod("GetMessage", {"profile" : profile, "contact": handle, "start": start, "end": end}); } - } \ No newline at end of file diff --git a/lib/views/profilemgrview.dart b/lib/views/profilemgrview.dart index 029e399..a00f77d 100644 --- a/lib/views/profilemgrview.dart +++ b/lib/views/profilemgrview.dart @@ -19,7 +19,6 @@ class ProfileMgrView extends StatefulWidget { } class _ProfileMgrViewState extends State { - HashMap _profiles; final ctrlrPassword = TextEditingController(); @override @@ -30,24 +29,6 @@ class _ProfileMgrViewState extends State { @override Widget build(BuildContext context) { - if (_profiles == null) { - _profiles = new HashMap(); - } - - if (_profiles.length < 1) { - Provider.of(context).cwtch.GetProfiles().then((profilesJson) { - jsonDecode(profilesJson).forEach((profile) { - ProfileModel profile1 = new ProfileModel(); - profile1.onion = profile['onion']; - profile1.nickname = profile['name']; - profile1.creationDate = "4 jan 2020"; - profile1.contacts = new HashMap(); - profile1.imagePath = profile['imagePath']; - - _profiles.putIfAbsent(profile1.onion, () => profile1); - }); - }); - } return Scaffold ( appBar: AppBar( @@ -129,7 +110,12 @@ class _ProfileMgrViewState extends State { ElevatedButton( child: const Text('Unlock'), onPressed: () { - setState(() => _profiles.clear()); + Provider + .of(context, listen: false) + .cwtch + .LoadProfiles(ctrlrPassword.value.text); + Provider.of(context, listen: false) + .loadProfiles(); Navigator.pop(context); }, ),