cwtchNotifier shared between ffi and gomobile
This commit is contained in:
parent
a3e681b60b
commit
1a59b72815
|
@ -0,0 +1,19 @@
|
|||
import '../model.dart';
|
||||
|
||||
class CwtchNotifier {
|
||||
ProfileListState profileCN;
|
||||
|
||||
CwtchNotifier(ProfileListState pcn) {
|
||||
profileCN = pcn;
|
||||
}
|
||||
|
||||
void handleMessage(String type, dynamic data) {
|
||||
switch (type) {
|
||||
case "NewPeer":
|
||||
profileCN.add(ProfileInfoState(onion: data["Identity"], nickname: data["name"], imagePath: data["picture"]));
|
||||
break;
|
||||
default:
|
||||
print("unhandled gomobile appbus event: ${type}");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'package:flutter_app/cwtch/cwtchNotifier.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
@ -54,10 +55,12 @@ class CwtchFfi implements Cwtch {
|
|||
DynamicLibrary library;
|
||||
Stream<bool> repaintProfileStream;
|
||||
ProfileListState profileCN;
|
||||
CwtchNotifier cwtchNotifier;
|
||||
|
||||
CwtchFfi(ProfileListState profs) {
|
||||
library = DynamicLibrary.open("libCwtch.so");
|
||||
profileCN = profs;
|
||||
cwtchNotifier = new CwtchNotifier(profs);
|
||||
}
|
||||
|
||||
Future<void> Start() async {
|
||||
|
@ -81,14 +84,7 @@ class CwtchFfi implements Cwtch {
|
|||
var _isolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort);
|
||||
_receivePort.listen((message) {
|
||||
var env = jsonDecode(message);
|
||||
var obj = env["Data"];
|
||||
switch (env["EventType"]) {
|
||||
case "NewPeer":
|
||||
print(env["Data"]);
|
||||
profileCN.add(ProfileInfoState(onion: obj["Identity"], nickname: obj["name"], imagePath: obj["picture"]));
|
||||
break;
|
||||
default: print("unhandled gomobile appbus event: ${env["EventType"]}");
|
||||
}
|
||||
cwtchNotifier.handleMessage(env["EventType"], env["Data"]);
|
||||
});
|
||||
|
||||
//repaintProfileStream = pollRepaintProfileEvents();
|
||||
|
|
|
@ -9,6 +9,7 @@ import 'package:path/path.dart' as path;
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'cwtch.dart';
|
||||
import 'cwtchNotifier.dart';
|
||||
|
||||
/*
|
||||
TODO: make a reusable plugin for other flutter apps
|
||||
|
@ -30,10 +31,13 @@ class CwtchGomobile implements Cwtch {
|
|||
Future<String> androidLibraryDir;
|
||||
Future<Directory> androidHomeDirectory;
|
||||
ProfileListState profileCN;
|
||||
CwtchNotifier cwtchNotifier;
|
||||
|
||||
|
||||
CwtchGomobile(ProfileListState profs) {
|
||||
print("gomobile.dart: CwtchGomobile()");
|
||||
profileCN = profs;
|
||||
cwtchNotifier = new CwtchNotifier(profs);
|
||||
androidHomeDirectory = getApplicationDocumentsDirectory();
|
||||
androidLibraryDir = appInfoPlatform.invokeMethod('getNativeLibDir');
|
||||
|
||||
|
@ -52,12 +56,8 @@ class CwtchGomobile implements Cwtch {
|
|||
Future<void> _handleAppbusEvent(MethodCall call) async {
|
||||
final String json = call.arguments;
|
||||
var obj = jsonDecode(json);
|
||||
switch (call.method) {
|
||||
case "NewPeer":
|
||||
profileCN.add(ProfileInfoState(onion: obj["Identity"], nickname: obj["ProfileName"], imagePath: obj["Path"]));
|
||||
break;
|
||||
default: print("unhandled gomobile appbus event: $call");
|
||||
}
|
||||
|
||||
cwtchNotifier.handleMessage(call.method, obj);
|
||||
}
|
||||
|
||||
void SelectProfile(String onion) {
|
||||
|
|
Loading…
Reference in New Issue