49 lines
1.2 KiB
Dart
49 lines
1.2 KiB
Dart
|
import 'dart:ffi';
|
||
|
import 'package:ffi/ffi.dart';
|
||
|
import 'dart:async';
|
||
|
import 'dart:io';
|
||
|
|
||
|
typedef acn_events_function = Pointer<Utf8> Function();
|
||
|
typedef ACNEventsFn = Pointer<Utf8> Function();
|
||
|
|
||
|
|
||
|
|
||
|
class AppModel {
|
||
|
|
||
|
final DynamicLibrary library;
|
||
|
AppModel({this.library});
|
||
|
|
||
|
Stream<String> contactEvents() async* {
|
||
|
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
|
||
|
"ContactEvents");
|
||
|
final ContactEvents = acnEventsC.asFunction<ACNEventsFn>();
|
||
|
|
||
|
while (true) {
|
||
|
Pointer<Utf8> result = ContactEvents();
|
||
|
String event = Utf8.fromUtf8(result);
|
||
|
if (event != "") {
|
||
|
print(event);
|
||
|
yield event;
|
||
|
} else {
|
||
|
await Future.delayed(Duration(seconds: 1));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
Stream<String> torStatus() async* {
|
||
|
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
|
||
|
"ACNEvents");
|
||
|
final ACNEvents = acnEventsC.asFunction<ACNEventsFn>();
|
||
|
|
||
|
while (true) {
|
||
|
Pointer<Utf8> result = ACNEvents();
|
||
|
String event = Utf8.fromUtf8(result);
|
||
|
if (event != "") {
|
||
|
yield event;
|
||
|
} else {
|
||
|
await Future.delayed(Duration(seconds: 1));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|