Unlock Profiles
This commit is contained in:
parent
c1d8c630c8
commit
5cbc0814f6
|
@ -3,6 +3,7 @@ abstract class Cwtch {
|
|||
|
||||
void SelectProfile(String onion);
|
||||
void CreateProfile(String nick, String pass);
|
||||
void LoadProfiles(String pass);
|
||||
|
||||
Future<String> ACNEvents();
|
||||
Future<String> ContactEvents();
|
||||
|
|
|
@ -18,6 +18,9 @@ typedef VoidFromStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>
|
|||
typedef access_cwtch_eventbus_function = Void Function();
|
||||
typedef NextEventFn = void Function();
|
||||
|
||||
typedef string_to_void_function = Void Function(Pointer<Utf8> str, Int32 length);
|
||||
typedef StringFn = void Function(Pointer<Utf8> dir, int);
|
||||
|
||||
typedef get_json_blob_void_function = Pointer<Utf8> Function();
|
||||
typedef GetJsonBlobVoidFn = Pointer<Utf8> 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<NativeFunction<string_to_void_function>>("c_LoadProfiles");
|
||||
// ignore: non_constant_identifier_names
|
||||
final LoadProfiles = loadProfileC.asFunction<StringFn>();
|
||||
LoadProfiles(Utf8.toUtf8(pass), pass.length);
|
||||
}
|
||||
|
||||
Future<String> ACNEvents() async {
|
||||
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
|
||||
"c_ACNEvents");
|
||||
|
|
|
@ -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<String> 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});
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -19,7 +19,6 @@ class ProfileMgrView extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ProfileMgrViewState extends State<ProfileMgrView> {
|
||||
HashMap<String, ProfileModel> _profiles;
|
||||
final ctrlrPassword = TextEditingController();
|
||||
|
||||
@override
|
||||
|
@ -30,24 +29,6 @@ class _ProfileMgrViewState extends State<ProfileMgrView> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_profiles == null) {
|
||||
_profiles = new HashMap<String, ProfileModel>();
|
||||
}
|
||||
|
||||
if (_profiles.length < 1) {
|
||||
Provider.of<FlwtchState>(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<String, ContactModel>();
|
||||
profile1.imagePath = profile['imagePath'];
|
||||
|
||||
_profiles.putIfAbsent(profile1.onion, () => profile1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return Scaffold (
|
||||
appBar: AppBar(
|
||||
|
@ -129,7 +110,12 @@ class _ProfileMgrViewState extends State<ProfileMgrView> {
|
|||
ElevatedButton(
|
||||
child: const Text('Unlock'),
|
||||
onPressed: () {
|
||||
setState(() => _profiles.clear());
|
||||
Provider
|
||||
.of<FlwtchState>(context, listen: false)
|
||||
.cwtch
|
||||
.LoadProfiles(ctrlrPassword.value.text);
|
||||
Provider.of<FlwtchState>(context, listen: false)
|
||||
.loadProfiles();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue