2021-06-24 23:10:45 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:ffi';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:isolate';
|
|
|
|
import 'dart:io' show Platform;
|
|
|
|
import 'package:cwtch/cwtch/cwtchNotifier.dart';
|
|
|
|
import 'package:path/path.dart' as path;
|
|
|
|
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
import 'package:cwtch/cwtch/cwtch.dart';
|
|
|
|
|
|
|
|
import '../config.dart';
|
|
|
|
|
2021-08-18 22:50:58 +00:00
|
|
|
import "package:path/path.dart" show dirname, join;
|
|
|
|
import 'dart:io' show Platform;
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
/////////////////////
|
|
|
|
/// Cwtch API ///
|
|
|
|
/////////////////////
|
|
|
|
|
|
|
|
typedef start_cwtch_function = Int8 Function(Pointer<Utf8> str, Int32 length, Pointer<Utf8> str2, Int32 length2);
|
|
|
|
typedef StartCwtchFn = int Function(Pointer<Utf8> dir, int len, Pointer<Utf8> tor, int torLen);
|
|
|
|
|
|
|
|
typedef void_from_void_funtion = Void Function();
|
|
|
|
typedef VoidFromVoidFunction = void Function();
|
|
|
|
|
2021-08-25 05:06:26 +00:00
|
|
|
typedef free_function = Void Function(Pointer<Utf8>);
|
|
|
|
typedef FreeFn = void Function(Pointer<Utf8>);
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
typedef void_from_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef VoidFromStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
|
2023-03-02 21:17:44 +00:00
|
|
|
typedef VoidFromStringFn = void Function(Pointer<Utf8>, int);
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
typedef void_from_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef VoidFromStringStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
|
|
|
typedef void_from_string_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef VoidFromStringStringStringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
2021-11-18 23:44:54 +00:00
|
|
|
// DownloadFile
|
|
|
|
typedef void_from_string_int_string_string_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef VoidFromStringIntStringStringStringFn = void Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
|
2021-09-21 21:57:40 +00:00
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
typedef void_from_string_string_int_int_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int64, Int64);
|
|
|
|
typedef VoidFromStringStringIntIntFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int, int);
|
|
|
|
|
2021-10-29 23:37:02 +00:00
|
|
|
typedef void_from_string_string_byte_function = Void Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int8);
|
|
|
|
typedef VoidFromStringStringByteFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
typedef string_to_void_function = Void Function(Pointer<Utf8> str, Int32 length);
|
|
|
|
typedef StringFn = void Function(Pointer<Utf8> dir, int);
|
|
|
|
|
|
|
|
typedef string_string_to_void_function = Void Function(Pointer<Utf8> str, Int32 length, Pointer<Utf8> str2, Int32 length2);
|
|
|
|
typedef StringStringFn = void Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
2022-03-09 22:35:12 +00:00
|
|
|
typedef string_string_to_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length, Pointer<Utf8> str2, Int32 length2);
|
|
|
|
typedef StringFromStringStringFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
2021-11-18 23:44:54 +00:00
|
|
|
typedef string_int_to_void_function = Void Function(Pointer<Utf8> str, Int32 length, Int32 handle);
|
|
|
|
typedef VoidFromStringIntFn = void Function(Pointer<Utf8>, int, int);
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
|
|
|
|
typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str, int len);
|
|
|
|
|
2022-04-06 21:35:10 +00:00
|
|
|
typedef get_json_blob_from_string_int_string_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32);
|
2022-03-23 23:08:19 +00:00
|
|
|
typedef GetJsonBlobFromStrIntStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int);
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
//func GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, message_index C.int) *C.char {
|
|
|
|
typedef get_json_blob_from_str_str_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int32);
|
|
|
|
typedef GetJsonBlobFromStrStrIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);
|
|
|
|
|
2022-07-06 18:54:07 +00:00
|
|
|
typedef get_json_blob_from_str_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32);
|
|
|
|
typedef GetJsonBlobFromStrIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int);
|
|
|
|
|
2023-04-04 20:58:42 +00:00
|
|
|
typedef get_json_blob_from_str_str_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef GetJsonBlobFromStrStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
2023-03-27 19:00:49 +00:00
|
|
|
typedef get_json_blob_from_str_int_int_str_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef GetJsonBlobFromStrIntIntStrFn = Pointer<Utf8> Function(
|
|
|
|
Pointer<Utf8>,
|
|
|
|
int,
|
|
|
|
int,
|
|
|
|
int,
|
|
|
|
Pointer<Utf8>,
|
|
|
|
int,
|
|
|
|
);
|
|
|
|
|
2021-11-18 23:44:54 +00:00
|
|
|
typedef get_json_blob_from_str_int_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Int32);
|
2021-11-25 23:59:54 +00:00
|
|
|
typedef GetJsonBlobFromStrIntIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, int);
|
2021-11-18 23:44:54 +00:00
|
|
|
|
2022-03-23 23:08:19 +00:00
|
|
|
typedef get_json_blob_from_str_int_int_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Int32, Int32);
|
|
|
|
typedef GetJsonBlobFromStrIntIntIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, int, int, int);
|
|
|
|
|
2021-11-18 23:44:54 +00:00
|
|
|
typedef get_json_blob_from_str_int_string_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32);
|
2021-11-25 23:59:54 +00:00
|
|
|
typedef GetJsonBlobFromStrIntStringFn = Pointer<Utf8> Function(
|
|
|
|
Pointer<Utf8>,
|
|
|
|
int,
|
|
|
|
int,
|
|
|
|
Pointer<Utf8>,
|
|
|
|
int,
|
|
|
|
);
|
2021-11-18 23:44:54 +00:00
|
|
|
|
2021-07-05 19:31:16 +00:00
|
|
|
// func c_GetMessagesByContentHash(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, contenthash_ptr *C.char, contenthash_len C.int) *C.char
|
|
|
|
typedef get_json_blob_from_str_str_str_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef GetJsonBlobFromStrStrStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
|
2021-06-24 23:10:45 +00:00
|
|
|
|
2021-11-18 23:44:54 +00:00
|
|
|
typedef void_from_string_int_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef VoidFromStringIntStringFn = void Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int);
|
|
|
|
|
|
|
|
typedef void_from_string_int_string_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef VoidFromStringIntStringStringFn = void Function(Pointer<Utf8>, int, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
2021-12-01 12:17:48 +00:00
|
|
|
typedef void_from_string_int_int_int_string_string_function = Void Function(Pointer<Utf8>, Int32, Int32, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
|
|
|
typedef VoidFromStringIntIntIntStringStringFn = void Function(Pointer<Utf8>, int, int, int, int, Pointer<Utf8>, int, Pointer<Utf8>, int);
|
|
|
|
|
2021-11-25 23:59:54 +00:00
|
|
|
typedef void_from_string_int_int_function = Void Function(Pointer<Utf8>, Int32, Int32, Int32);
|
2021-11-18 23:44:54 +00:00
|
|
|
typedef VoidFromStringIntIntFn = void Function(Pointer<Utf8>, int, int, int);
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
typedef appbus_events_function = Pointer<Utf8> Function();
|
|
|
|
typedef AppbusEventsFn = Pointer<Utf8> Function();
|
|
|
|
|
2022-04-14 22:34:17 +00:00
|
|
|
typedef void_to_string = Pointer<Utf8> Function();
|
|
|
|
typedef StringFromVoid = Pointer<Utf8> Function();
|
|
|
|
|
2021-08-19 00:40:25 +00:00
|
|
|
const String UNSUPPORTED_OS = "unsupported-os";
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
class CwtchFfi implements Cwtch {
|
|
|
|
late DynamicLibrary library;
|
|
|
|
late CwtchNotifier cwtchNotifier;
|
|
|
|
late Isolate cwtchIsolate;
|
|
|
|
ReceivePort _receivePort = ReceivePort();
|
2022-02-08 21:54:17 +00:00
|
|
|
bool _isL10nInit = false;
|
2021-06-24 23:10:45 +00:00
|
|
|
|
2021-08-19 00:40:25 +00:00
|
|
|
static String getLibraryPath() {
|
2021-06-24 23:10:45 +00:00
|
|
|
if (Platform.isWindows) {
|
2021-08-19 00:40:25 +00:00
|
|
|
return "libCwtch.dll";
|
2021-06-24 23:10:45 +00:00
|
|
|
} else if (Platform.isLinux) {
|
2021-08-19 00:40:25 +00:00
|
|
|
return "libCwtch.so";
|
2021-08-18 22:50:58 +00:00
|
|
|
} else if (Platform.isMacOS) {
|
2022-06-22 19:05:46 +00:00
|
|
|
if (Abi.current() == Abi.macosX64) {
|
|
|
|
return "libCwtch.x64.dylib";
|
|
|
|
} else {
|
2022-06-22 19:34:53 +00:00
|
|
|
return "libCwtch.arm64.dylib";
|
2022-06-22 19:05:46 +00:00
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
} else {
|
2021-08-19 00:40:25 +00:00
|
|
|
return UNSUPPORTED_OS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CwtchFfi(CwtchNotifier _cwtchNotifier) {
|
2021-12-18 00:54:30 +00:00
|
|
|
String libraryPath = getLibraryPath();
|
|
|
|
if (libraryPath == UNSUPPORTED_OS) {
|
2021-06-24 23:10:45 +00:00
|
|
|
print("OS ${Platform.operatingSystem} not supported by cwtch/ffi");
|
|
|
|
// emergency, ideally the app stays on splash and just posts the error till user closes
|
|
|
|
exit(0);
|
|
|
|
}
|
2021-12-18 00:54:30 +00:00
|
|
|
library = DynamicLibrary.open(libraryPath);
|
2021-06-24 23:10:45 +00:00
|
|
|
cwtchNotifier = _cwtchNotifier;
|
2022-04-01 22:54:06 +00:00
|
|
|
cwtchNotifier.setMessageSeenCallback((String profile, int conversation, DateTime time) => {this.SetConversationAttribute(profile, conversation, LastMessageSeenTimeKey, time.toIso8601String())});
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
Future<void> Start() async {
|
|
|
|
String home = "";
|
|
|
|
String bundledTor = "";
|
|
|
|
Map<String, String> envVars = Platform.environment;
|
2021-08-28 17:23:37 +00:00
|
|
|
String cwtchDir = "";
|
2021-06-24 23:10:45 +00:00
|
|
|
if (Platform.isLinux) {
|
2022-12-04 17:32:22 +00:00
|
|
|
home = envVars['HOME'] ?? "";
|
2023-02-08 23:05:36 +00:00
|
|
|
if (EnvironmentConfig.TEST_MODE) {
|
|
|
|
cwtchDir = envVars['CWTCH_HOME']!;
|
2023-02-08 23:09:09 +00:00
|
|
|
} else {
|
|
|
|
cwtchDir = envVars['CWTCH_HOME'] ?? path.join(envVars['HOME']!, ".cwtch");
|
2023-02-08 23:05:36 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 22:19:32 +00:00
|
|
|
if (await File("linux/Tor/tor").exists()) {
|
|
|
|
bundledTor = "linux/Tor/tor";
|
|
|
|
} else if (await File("lib/Tor/tor").exists()) {
|
|
|
|
bundledTor = "lib/Tor/tor";
|
|
|
|
} else if (await File(path.join(home, ".local/lib/cwtch/Tor/tor")).exists()) {
|
|
|
|
bundledTor = path.join(home, ".local/lib/cwtch/Tor/tor");
|
|
|
|
} else if (await File("/usr/lib/cwtch/Tor/tor").exists()) {
|
|
|
|
bundledTor = "/usr/lib/cwtch/Tor/tor";
|
2021-07-06 16:24:42 +00:00
|
|
|
} else {
|
|
|
|
bundledTor = "tor";
|
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
} else if (Platform.isWindows) {
|
2021-08-28 17:23:37 +00:00
|
|
|
cwtchDir = envVars['CWTCH_DIR'] ?? path.join(envVars['UserProfile']!, ".cwtch");
|
2022-04-21 01:19:36 +00:00
|
|
|
String currentTor = path.join(Directory.current.absolute.path, "Tor\\Tor\\tor.exe");
|
|
|
|
if (await File(currentTor).exists()) {
|
|
|
|
bundledTor = currentTor;
|
|
|
|
} else {
|
|
|
|
String exeDir = path.dirname(Platform.resolvedExecutable);
|
|
|
|
bundledTor = path.join(exeDir, "Tor\\Tor\\tor.exe");
|
|
|
|
}
|
2021-08-28 17:23:37 +00:00
|
|
|
} else if (Platform.isMacOS) {
|
|
|
|
cwtchDir = envVars['CWTCH_HOME'] ?? path.join(envVars['HOME']!, "Library/Application Support/Cwtch");
|
2021-08-29 00:41:08 +00:00
|
|
|
if (await File("Cwtch.app/Contents/MacOS/Tor/tor.real").exists()) {
|
|
|
|
bundledTor = "Cwtch.app/Contents/MacOS/Tor/tor.real";
|
2021-09-04 17:48:49 +00:00
|
|
|
} else if (await File("/Applications/Cwtch.app/Contents/MacOS/Tor/tor.real").exists()) {
|
2021-09-04 10:42:13 +00:00
|
|
|
bundledTor = "/Applications/Cwtch.app/Contents/MacOS/Tor/tor.real";
|
2021-08-29 00:41:08 +00:00
|
|
|
} else if (await File("/Volumes/Cwtch/Cwtch.app/Contents/MacOS/Tor/tor.real").exists()) {
|
|
|
|
bundledTor = "/Volumes/Cwtch/Cwtch.app/Contents/MacOS/Tor/tor.real";
|
2021-09-04 13:41:01 +00:00
|
|
|
} else if (await File("/Applications/Tor Browser.app/Contents/MacOS/Tor/tor.real").exists()) {
|
|
|
|
bundledTor = "/Applications/Tor Browser.app/Contents/MacOS/Tor/tor.real";
|
|
|
|
print("We couldn't find Tor in the Cwtch app directory, however we can fall back to the Tor Browser binary");
|
2021-09-04 10:42:13 +00:00
|
|
|
} else {
|
|
|
|
var splitPath = path.split(dirname(Platform.script.path));
|
2021-09-17 20:38:10 +00:00
|
|
|
if (splitPath[0] == "/" && splitPath[1] == "Applications") {
|
2021-09-04 10:42:13 +00:00
|
|
|
var appName = splitPath[2];
|
|
|
|
print("We're running in /Applications in a non standard app name: $appName");
|
|
|
|
if (await File("/Applications/$appName/Contents/MacOS/Tor/tor.real").exists()) {
|
|
|
|
bundledTor = "/Applications/$appName/Contents/MacOS/Tor/tor.real";
|
|
|
|
}
|
|
|
|
}
|
2021-08-28 17:23:37 +00:00
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
2021-07-07 23:12:20 +00:00
|
|
|
|
2021-09-10 23:34:43 +00:00
|
|
|
// the first Cwtch MacOS release (1.2) accidently was a dev build
|
|
|
|
// we need to temporarily remedy this for a release or two then delete
|
2021-09-17 20:38:10 +00:00
|
|
|
// if macOs and release build and no profile and is dev profile
|
|
|
|
// copy dev profile to release profile
|
2021-09-10 23:34:43 +00:00
|
|
|
if (Platform.isMacOS && EnvironmentConfig.BUILD_VER != dev_version) {
|
|
|
|
var devProfileExists = await Directory(path.join(cwtchDir, "dev", "profiles")).exists();
|
|
|
|
var releaseProfileExists = await Directory(path.join(cwtchDir, "profiles")).exists();
|
|
|
|
if (devProfileExists && !releaseProfileExists) {
|
|
|
|
print("MacOS one time dev -> release profile migration...");
|
|
|
|
await Process.run("cp", ["-r", "-p", path.join(cwtchDir, "dev", "profiles"), cwtchDir]);
|
|
|
|
await Process.run("cp", ["-r", "-p", path.join(cwtchDir, "dev", "SALT"), cwtchDir]);
|
|
|
|
await Process.run("cp", ["-r", "-p", path.join(cwtchDir, "dev", "ui.globals"), cwtchDir]);
|
2021-08-28 17:23:37 +00:00
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
2021-07-07 23:12:20 +00:00
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
if (EnvironmentConfig.BUILD_VER == dev_version) {
|
|
|
|
cwtchDir = path.join(cwtchDir, "dev");
|
|
|
|
}
|
2021-08-28 17:23:37 +00:00
|
|
|
|
2021-07-06 16:24:42 +00:00
|
|
|
print("StartCwtch( cwtchdir: $cwtchDir, torPath: $bundledTor )");
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
var startCwtchC = library.lookup<NativeFunction<start_cwtch_function>>("c_StartCwtch");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final StartCwtch = startCwtchC.asFunction<StartCwtchFn>();
|
|
|
|
|
2022-04-26 19:16:09 +00:00
|
|
|
final utf8CwtchDir = cwtchDir.toNativeUtf8();
|
|
|
|
StartCwtch(utf8CwtchDir, utf8CwtchDir.length, bundledTor.toNativeUtf8(), bundledTor.length);
|
|
|
|
malloc.free(utf8CwtchDir);
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
// Spawn an isolate to listen to events from libcwtch-go and then dispatch them when received on main thread to cwtchNotifier
|
|
|
|
cwtchIsolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort);
|
|
|
|
_receivePort.listen((message) {
|
|
|
|
var env = jsonDecode(message);
|
|
|
|
cwtchNotifier.handleMessage(env["EventType"], env["Data"]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
Future<void> ReconnectCwtchForeground() async {
|
|
|
|
var reconnectCwtch = library.lookup<NativeFunction<Void Function()>>("c_ReconnectCwtchForeground");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final ReconnectCwtchForeground = reconnectCwtch.asFunction<void Function()>();
|
|
|
|
ReconnectCwtchForeground();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called on object being disposed to (presumably on app close) to close the isolate that's listening to libcwtch-go events
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2021-08-25 05:06:26 +00:00
|
|
|
cwtchIsolate.kill(priority: Isolate.immediate);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point for an isolate to listen to a stream of events pulled from libcwtch-go and return them on the sendPort
|
|
|
|
static void _checkAppbusEvents(SendPort sendPort) async {
|
|
|
|
var stream = pollAppbusEvents();
|
|
|
|
await for (var value in stream) {
|
|
|
|
sendPort.send(value);
|
|
|
|
}
|
|
|
|
print("checkAppBusEvents finished...");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Steam of appbus events. Call blocks in libcwtch-go GetAppbusEvent. Static so the isolate can use it
|
|
|
|
static Stream<String> pollAppbusEvents() async* {
|
2021-08-19 00:40:25 +00:00
|
|
|
late DynamicLibrary library = DynamicLibrary.open(getLibraryPath());
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
var getAppbusEventC = library.lookup<NativeFunction<appbus_events_function>>("c_GetAppBusEvent");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final GetAppbusEvent = getAppbusEventC.asFunction<AppbusEventsFn>();
|
|
|
|
|
2021-08-25 05:06:26 +00:00
|
|
|
// Embedded Version of _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved
|
|
|
|
var free = library.lookup<NativeFunction<free_function>>("c_FreePointer");
|
|
|
|
final Free = free.asFunction<FreeFn>();
|
|
|
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final GetAppBusEvent = () {
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-06-24 23:10:45 +00:00
|
|
|
Pointer<Utf8> result = GetAppbusEvent();
|
|
|
|
String event = result.toDartString();
|
2021-08-25 05:06:26 +00:00
|
|
|
Free(result);
|
|
|
|
return event;
|
|
|
|
};
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
final event = GetAppBusEvent();
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
if (event.startsWith("{\"EventType\":\"Shutdown\"")) {
|
|
|
|
print("Shutting down isolate thread: $event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
yield event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: non_constant_identifier_names
|
2022-12-11 01:21:08 +00:00
|
|
|
void CreateProfile(String nick, String pass, bool autostart) {
|
|
|
|
var createProfileC = library.lookup<NativeFunction<void_from_string_string_byte_function>>("c_CreateProfile");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2022-12-11 01:21:08 +00:00
|
|
|
final CreateProfile = createProfileC.asFunction<VoidFromStringStringByteFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final utf8nick = nick.toNativeUtf8();
|
|
|
|
final ut8pass = pass.toNativeUtf8();
|
2022-12-11 01:21:08 +00:00
|
|
|
CreateProfile(utf8nick, utf8nick.length, ut8pass, ut8pass.length, autostart ? 1 : 0);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(utf8nick);
|
|
|
|
malloc.free(ut8pass);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 19:58:44 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void ActivatePeerEngine(String profile) {
|
|
|
|
var activatePeerEngineC = library.lookup<NativeFunction<string_to_void_function>>("c_ActivatePeerEngine");
|
|
|
|
final ActivatePeerEngine = activatePeerEngineC.asFunction<StringFn>();
|
|
|
|
final ut8profile = profile.toNativeUtf8();
|
|
|
|
ActivatePeerEngine(ut8profile, ut8profile.length);
|
|
|
|
malloc.free(ut8profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void DeactivatePeerEngine(String profile) {
|
2022-12-11 23:59:37 +00:00
|
|
|
var deactivatePeerEngineC = library.lookup<NativeFunction<string_to_void_function>>("c_DeactivatePeerEngine");
|
2022-12-05 19:58:44 +00:00
|
|
|
final DeactivatePeerEngine = deactivatePeerEngineC.asFunction<StringFn>();
|
|
|
|
final ut8profile = profile.toNativeUtf8();
|
|
|
|
DeactivatePeerEngine(ut8profile, ut8profile.length);
|
|
|
|
malloc.free(ut8profile);
|
|
|
|
}
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
// 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>();
|
|
|
|
final ut8pass = pass.toNativeUtf8();
|
|
|
|
LoadProfiles(ut8pass, ut8pass.length);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(ut8pass);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
Future<String> GetMessage(String profile, int handle, int index) async {
|
|
|
|
var getMessageC = library.lookup<NativeFunction<get_json_blob_from_str_int_int_function>>("c_GetMessage");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final GetMessage = getMessageC.asFunction<GetJsonBlobFromStrIntIntFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final utf8profile = profile.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
Pointer<Utf8> jsonMessageBytes = GetMessage(utf8profile, utf8profile.length, handle, index);
|
2021-06-24 23:10:45 +00:00
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
2021-08-25 05:06:26 +00:00
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
2021-06-24 23:10:45 +00:00
|
|
|
return jsonMessage;
|
|
|
|
}
|
|
|
|
|
2022-03-23 23:08:19 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
Future<dynamic> GetMessages(String profile, int handle, int index, int count) async {
|
|
|
|
var getMessagesC = library.lookup<NativeFunction<get_json_blob_from_str_int_int_int_function>>("c_GetMessages");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final GetMessages = getMessagesC.asFunction<GetJsonBlobFromStrIntIntIntFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
Pointer<Utf8> jsonMessageBytes = GetMessages(utf8profile, utf8profile.length, handle, index, count);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
2022-04-26 19:16:09 +00:00
|
|
|
|
2022-03-23 23:08:19 +00:00
|
|
|
return jsonMessage;
|
|
|
|
}
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
void AcceptContact(String profileOnion, int contactHandle) {
|
2021-11-25 23:59:54 +00:00
|
|
|
var acceptContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_AcceptConversation");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final AcceptContact = acceptContact.asFunction<VoidFromStringIntFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
AcceptContact(u1, u1.length, contactHandle);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
void BlockContact(String profileOnion, int contactHandle) {
|
|
|
|
var blockContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_BlockContact");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final BlockContact = blockContact.asFunction<VoidFromStringIntFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
BlockContact(u1, u1.length, contactHandle);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
2022-01-06 21:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void UnblockContact(String profileOnion, int contactHandle) {
|
|
|
|
var unblockContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_UnblockContact");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final UnblockContact = unblockContact.asFunction<VoidFromStringIntFn>();
|
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
|
|
|
UnblockContact(u1, u1.length, contactHandle);
|
|
|
|
malloc.free(u1);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2022-03-23 23:08:19 +00:00
|
|
|
Future<dynamic> SendMessage(String profileOnion, int contactHandle, String message) async {
|
|
|
|
var sendMessage = library.lookup<NativeFunction<get_json_blob_from_string_int_string_function>>("c_SendMessage");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2022-03-23 23:08:19 +00:00
|
|
|
final SendMessage = sendMessage.asFunction<GetJsonBlobFromStrIntStrFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
|
|
|
final u3 = message.toNativeUtf8();
|
2022-04-06 21:35:10 +00:00
|
|
|
Pointer<Utf8> jsonMessageBytes = SendMessage(u1, u1.length, contactHandle, u3, u3.length);
|
2022-03-23 23:08:19 +00:00
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u3);
|
2022-03-23 23:08:19 +00:00
|
|
|
return jsonMessage;
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2022-03-23 23:08:19 +00:00
|
|
|
Future<dynamic> SendInvitation(String profileOnion, int contactHandle, int target) async {
|
2023-03-02 21:17:44 +00:00
|
|
|
var sendInvitation = library.lookup<NativeFunction<get_json_blob_from_str_int_int_function>>("c_SendInviteMessage");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2022-03-23 23:08:19 +00:00
|
|
|
final SendInvitation = sendInvitation.asFunction<GetJsonBlobFromStrIntIntFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
2022-03-23 23:08:19 +00:00
|
|
|
Pointer<Utf8> jsonMessageBytes = SendInvitation(u1, u1.length, contactHandle, target);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
2022-03-23 23:08:19 +00:00
|
|
|
return jsonMessage;
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 21:57:40 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2022-03-23 23:08:19 +00:00
|
|
|
Future<dynamic> ShareFile(String profileOnion, int contactHandle, String filepath) async {
|
|
|
|
var shareFile = library.lookup<NativeFunction<get_json_blob_from_string_int_string_function>>("c_ShareFile");
|
2021-09-21 21:57:40 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2022-03-23 23:08:19 +00:00
|
|
|
final ShareFile = shareFile.asFunction<GetJsonBlobFromStrIntStrFn>();
|
2021-09-21 21:57:40 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
|
|
|
final u3 = filepath.toNativeUtf8();
|
2022-03-23 23:08:19 +00:00
|
|
|
Pointer<Utf8> jsonMessageBytes = ShareFile(u1, u1.length, contactHandle, u3, u3.length);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
2021-09-21 21:57:40 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u3);
|
2022-03-23 23:08:19 +00:00
|
|
|
return jsonMessage;
|
2021-09-21 21:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
void DownloadFile(String profileOnion, int contactHandle, String filepath, String manifestpath, String filekey) {
|
2023-03-02 21:17:44 +00:00
|
|
|
var dlFile = library.lookup<NativeFunction<void_from_string_int_string_string_string_function>>("c_DownloadFileDefaultLimit");
|
2021-09-21 21:57:40 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final DownloadFile = dlFile.asFunction<VoidFromStringIntStringStringStringFn>();
|
2021-09-21 21:57:40 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
|
|
|
final u3 = filepath.toNativeUtf8();
|
|
|
|
final u4 = manifestpath.toNativeUtf8();
|
|
|
|
final u5 = filekey.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
DownloadFile(u1, u1.length, contactHandle, u3, u3.length, u4, u4.length, u5, u5.length);
|
2021-09-21 21:57:40 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u3);
|
|
|
|
malloc.free(u4);
|
|
|
|
malloc.free(u5);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2023-03-16 23:37:38 +00:00
|
|
|
void CreateDownloadableFile(String profileOnion, int contactHandle, String filenameSuggestion, String filekey, String manifestPath) {
|
2021-09-21 21:57:40 +00:00
|
|
|
// android only - do nothing
|
|
|
|
}
|
|
|
|
|
2021-12-14 23:50:08 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void ExportPreviewedFile(String sourceFile, String suggestion) {
|
|
|
|
// android only - do nothing
|
|
|
|
}
|
|
|
|
|
2021-09-29 20:31:01 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void CheckDownloadStatus(String profileOnion, String fileKey) {
|
|
|
|
var checkDownloadStatus = library.lookup<NativeFunction<string_string_to_void_function>>("c_CheckDownloadStatus");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final CheckDownloadStatus = checkDownloadStatus.asFunction<VoidFromStringStringFn>();
|
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
|
|
|
final u2 = fileKey.toNativeUtf8();
|
|
|
|
CheckDownloadStatus(u1, u1.length, u2, u2.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u2);
|
|
|
|
}
|
|
|
|
|
2021-11-04 22:31:50 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
void VerifyOrResumeDownload(String profileOnion, int contactHandle, String filekey) {
|
|
|
|
var fn = library.lookup<NativeFunction<void_from_string_int_string_function>>("c_VerifyOrResumeDownload");
|
2021-11-04 22:31:50 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final VerifyOrResumeDownload = fn.asFunction<VoidFromStringIntStringFn>();
|
2021-11-04 22:31:50 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
|
|
|
final u3 = filekey.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
VerifyOrResumeDownload(u1, u1.length, contactHandle, u3, u3.length);
|
2021-11-04 22:31:50 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u3);
|
|
|
|
}
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void ResetTor() {
|
|
|
|
var resetTor = library.lookup<NativeFunction<Void Function()>>("c_ResetTor");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final ResetTor = resetTor.asFunction<void Function()>();
|
|
|
|
ResetTor();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2022-08-16 05:33:09 +00:00
|
|
|
Future<dynamic> ImportBundle(String profileOnion, String bundle) async {
|
|
|
|
var importBundle = library.lookup<NativeFunction<string_string_to_string_function>>("c_ImportBundle");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2022-08-16 05:33:09 +00:00
|
|
|
final ImportBundle = importBundle.asFunction<StringFromStringStringFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
|
|
|
final u2 = bundle.toNativeUtf8();
|
2022-08-16 05:33:09 +00:00
|
|
|
Pointer<Utf8> responsePtr = ImportBundle(u1, u1.length, u2, u2.length);
|
|
|
|
String response = responsePtr.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(responsePtr);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u2);
|
2022-08-16 05:33:09 +00:00
|
|
|
return response;
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-08-25 05:06:26 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-06-24 23:10:45 +00:00
|
|
|
void CreateGroup(String profileOnion, String server, String groupName) {
|
2023-03-02 21:17:44 +00:00
|
|
|
var createGroup = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_StartGroup");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final CreateGroup = createGroup.asFunction<VoidFromStringStringStringFn>();
|
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
2023-03-02 21:17:44 +00:00
|
|
|
final u3 = server.toNativeUtf8();
|
|
|
|
final u2 = groupName.toNativeUtf8();
|
2021-06-24 23:10:45 +00:00
|
|
|
CreateGroup(u1, u1.length, u2, u2.length, u3, u3.length);
|
2021-08-25 05:06:26 +00:00
|
|
|
|
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u2);
|
|
|
|
malloc.free(u3);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
void ArchiveConversation(String profileOnion, int handle) {
|
|
|
|
var archiveConversation = library.lookup<NativeFunction<string_int_to_void_function>>("c_ArchiveConversation");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final ArchiveConversation = archiveConversation.asFunction<VoidFromStringIntFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
ArchiveConversation(u1, u1.length, handle);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
void DeleteContact(String profileOnion, int handle) {
|
|
|
|
var deleteContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_DeleteContact");
|
2021-06-24 23:10:45 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final DeleteContact = deleteContact.asFunction<VoidFromStringIntFn>();
|
2021-06-24 23:10:45 +00:00
|
|
|
final u1 = profileOnion.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
DeleteContact(u1, u1.length, handle);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void DeleteProfile(String onion, String currentPassword) {
|
|
|
|
var deleteprofile = library.lookup<NativeFunction<string_string_to_void_function>>("c_DeleteProfile");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final DeleteProfile = deleteprofile.asFunction<VoidFromStringStringFn>();
|
|
|
|
final u1 = onion.toNativeUtf8();
|
|
|
|
final u2 = currentPassword.toNativeUtf8();
|
|
|
|
DeleteProfile(u1, u1.length, u2, u2.length);
|
2021-08-25 05:06:26 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u2);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 01:24:07 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void SetProfileAttribute(String profile, String key, String val) {
|
|
|
|
var setProfileAttribute = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_SetProfileAttribute");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final SetProfileAttribute = setProfileAttribute.asFunction<VoidFromStringStringStringFn>();
|
|
|
|
final u1 = profile.toNativeUtf8();
|
|
|
|
final u2 = key.toNativeUtf8();
|
2021-12-14 21:33:30 +00:00
|
|
|
final u3 = val.toNativeUtf8();
|
2021-10-14 01:24:07 +00:00
|
|
|
SetProfileAttribute(u1, u1.length, u2, u2.length, u3, u3.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u2);
|
|
|
|
malloc.free(u3);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
void SetConversationAttribute(String profile, int contact, String key, String val) {
|
2021-11-26 23:07:37 +00:00
|
|
|
var setContactAttribute = library.lookup<NativeFunction<void_from_string_int_string_string_function>>("c_SetConversationAttribute");
|
2021-10-14 01:24:07 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final SetContactAttribute = setContactAttribute.asFunction<VoidFromStringIntStringStringFn>();
|
2021-10-14 01:24:07 +00:00
|
|
|
final u1 = profile.toNativeUtf8();
|
|
|
|
final u3 = key.toNativeUtf8();
|
2021-11-26 23:07:37 +00:00
|
|
|
final u4 = val.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
SetContactAttribute(u1, u1.length, contact, u3, u3.length, u4, u4.length);
|
2021-10-14 01:24:07 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u3);
|
|
|
|
malloc.free(u4);
|
|
|
|
}
|
|
|
|
|
2021-12-01 12:17:48 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void SetMessageAttribute(String profile, int conversation, int channel, int message, String key, String val) {
|
2023-03-02 21:17:44 +00:00
|
|
|
var setMessageAttribute = library.lookup<NativeFunction<void_from_string_int_int_int_string_string_function>>("c_UpdateMessageAttribute");
|
2021-12-01 12:17:48 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final SetMessageAttribute = setMessageAttribute.asFunction<VoidFromStringIntIntIntStringStringFn>();
|
|
|
|
final u1 = profile.toNativeUtf8();
|
|
|
|
final u3 = key.toNativeUtf8();
|
|
|
|
final u4 = val.toNativeUtf8();
|
|
|
|
SetMessageAttribute(u1, u1.length, conversation, channel, message, u3, u3.length, u4, u4.length);
|
2021-10-14 01:24:07 +00:00
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u3);
|
|
|
|
malloc.free(u4);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void LoadServers(String password) {
|
|
|
|
var loadServers = library.lookup<NativeFunction<string_to_void_function>>("c_LoadServers");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final LoadServers = loadServers.asFunction<StringFn>();
|
|
|
|
final u1 = password.toNativeUtf8();
|
|
|
|
LoadServers(u1, u1.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-10-29 23:37:02 +00:00
|
|
|
void CreateServer(String password, String description, bool autostart) {
|
|
|
|
var createServer = library.lookup<NativeFunction<void_from_string_string_byte_function>>("c_CreateServer");
|
2021-10-14 01:24:07 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-10-29 23:37:02 +00:00
|
|
|
final CreateServer = createServer.asFunction<VoidFromStringStringByteFn>();
|
2021-10-14 01:24:07 +00:00
|
|
|
final u1 = password.toNativeUtf8();
|
2021-10-29 23:37:02 +00:00
|
|
|
final u2 = description.toNativeUtf8();
|
|
|
|
CreateServer(u1, u1.length, u2, u2.length, autostart ? 1 : 0);
|
2021-10-14 01:24:07 +00:00
|
|
|
malloc.free(u1);
|
2021-10-29 23:37:02 +00:00
|
|
|
malloc.free(u2);
|
2021-10-14 01:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void DeleteServer(String serverOnion, String password) {
|
|
|
|
var deleteServer = library.lookup<NativeFunction<string_string_to_void_function>>("c_DeleteServer");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final DeleteServer = deleteServer.asFunction<VoidFromStringStringFn>();
|
|
|
|
final u1 = serverOnion.toNativeUtf8();
|
|
|
|
final u2 = password.toNativeUtf8();
|
|
|
|
DeleteServer(u1, u1.length, u2, u2.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void LaunchServers() {
|
|
|
|
var launchServers = library.lookup<NativeFunction<Void Function()>>("c_LaunchServers");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final LaunchServers = launchServers.asFunction<void Function()>();
|
|
|
|
LaunchServers();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void LaunchServer(String serverOnion) {
|
|
|
|
var launchServer = library.lookup<NativeFunction<string_to_void_function>>("c_LaunchServer");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final LaunchServer = launchServer.asFunction<StringFn>();
|
|
|
|
final u1 = serverOnion.toNativeUtf8();
|
|
|
|
LaunchServer(u1, u1.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-02 02:29:58 +00:00
|
|
|
void StopServer(String serverOnion) {
|
|
|
|
var shutdownServer = library.lookup<NativeFunction<string_to_void_function>>("c_StopServer");
|
2021-10-14 01:24:07 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final ShutdownServer = shutdownServer.asFunction<StringFn>();
|
|
|
|
final u1 = serverOnion.toNativeUtf8();
|
|
|
|
ShutdownServer(u1, u1.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-02 02:29:58 +00:00
|
|
|
void StopServers() {
|
|
|
|
var shutdownServers = library.lookup<NativeFunction<Void Function()>>("c_StopServers");
|
2021-10-14 01:24:07 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final ShutdownServers = shutdownServers.asFunction<void Function()>();
|
|
|
|
ShutdownServers();
|
|
|
|
}
|
|
|
|
|
2021-11-02 02:29:58 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void DestroyServers() {
|
|
|
|
var destroyServers = library.lookup<NativeFunction<Void Function()>>("c_DestroyServers");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final DestroyServers = destroyServers.asFunction<void Function()>();
|
|
|
|
DestroyServers();
|
|
|
|
}
|
|
|
|
|
2021-10-29 23:37:02 +00:00
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void SetServerAttribute(String serverOnion, String key, String val) {
|
|
|
|
var setServerAttribute = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_SetServerAttribute");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final SetServerAttribute = setServerAttribute.asFunction<VoidFromStringStringStringFn>();
|
|
|
|
final u1 = serverOnion.toNativeUtf8();
|
|
|
|
final u2 = key.toNativeUtf8();
|
|
|
|
final u3 = val.toNativeUtf8();
|
|
|
|
SetServerAttribute(u1, u1.length, u2, u2.length, u3, u3.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
malloc.free(u2);
|
|
|
|
malloc.free(u3);
|
|
|
|
}
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
@override
|
2021-08-25 05:06:26 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-06-24 23:10:45 +00:00
|
|
|
Future<void> Shutdown() async {
|
|
|
|
var shutdown = library.lookup<NativeFunction<void_from_void_funtion>>("c_ShutdownCwtch");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
|
|
|
|
// Shutdown Cwtch + Tor...
|
2021-08-25 05:06:26 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-06-24 23:10:45 +00:00
|
|
|
final Shutdown = shutdown.asFunction<VoidFromVoidFunction>();
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
// Kill our Isolate
|
|
|
|
cwtchIsolate.kill(priority: Isolate.immediate);
|
|
|
|
print("Isolate killed");
|
|
|
|
|
|
|
|
_receivePort.close();
|
|
|
|
print("Receive Port Closed");
|
|
|
|
}
|
2021-07-05 19:31:16 +00:00
|
|
|
|
|
|
|
@override
|
2021-08-25 05:06:26 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
Future GetMessageByContentHash(String profile, int handle, String contentHash) async {
|
2023-03-02 21:17:44 +00:00
|
|
|
var getMessagesByContentHashC = library.lookup<NativeFunction<get_json_blob_from_str_int_string_function>>("c_GetMessageByContentHash");
|
2021-07-05 19:31:16 +00:00
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-18 23:44:54 +00:00
|
|
|
final GetMessagesByContentHash = getMessagesByContentHashC.asFunction<GetJsonBlobFromStrIntStringFn>();
|
2021-07-05 19:31:16 +00:00
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final utf8contentHash = contentHash.toNativeUtf8();
|
2021-11-18 23:44:54 +00:00
|
|
|
Pointer<Utf8> jsonMessageBytes = GetMessagesByContentHash(utf8profile, utf8profile.length, handle, utf8contentHash, utf8contentHash.length);
|
2021-07-05 19:31:16 +00:00
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
2021-08-25 05:06:26 +00:00
|
|
|
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(utf8contentHash);
|
2021-07-05 19:31:16 +00:00
|
|
|
return jsonMessage;
|
|
|
|
}
|
2021-08-25 05:06:26 +00:00
|
|
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
// Incredibly dangerous function which invokes a free in libCwtch, should only be used
|
|
|
|
// as documented in `MEMORY.md` in libCwtch repo.
|
|
|
|
void _UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(Pointer<Utf8> ptr) {
|
|
|
|
var free = library.lookup<NativeFunction<free_function>>("c_FreePointer");
|
|
|
|
final Free = free.asFunction<FreeFn>();
|
|
|
|
Free(ptr);
|
|
|
|
}
|
2021-12-14 21:33:30 +00:00
|
|
|
|
|
|
|
@override
|
2022-09-09 19:23:08 +00:00
|
|
|
String? defaultDownloadPath() {
|
2021-12-14 21:33:30 +00:00
|
|
|
Map<String, String> envVars = Platform.environment;
|
2022-09-09 19:23:08 +00:00
|
|
|
String nominalPath = path.join(envVars[Platform.isWindows ? 'UserProfile' : 'HOME']!, "Downloads");
|
|
|
|
if (Directory(nominalPath).existsSync() == false) {
|
2023-02-01 22:48:36 +00:00
|
|
|
return Directory.current.path;
|
2022-09-09 19:23:08 +00:00
|
|
|
}
|
|
|
|
return nominalPath;
|
2021-12-14 21:33:30 +00:00
|
|
|
}
|
2021-12-14 21:37:48 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
2021-11-26 22:25:21 +00:00
|
|
|
Future<String> GetMessageByID(String profile, int handle, int index) async {
|
|
|
|
var getMessageC = library.lookup<NativeFunction<get_json_blob_from_str_int_int_function>>("c_GetMessageByID");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final GetMessage = getMessageC.asFunction<GetJsonBlobFromStrIntIntFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
Pointer<Utf8> jsonMessageBytes = GetMessage(utf8profile, utf8profile.length, handle, index);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
return jsonMessage;
|
|
|
|
}
|
2021-12-18 00:54:30 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void ChangePassword(String profile, String pass, String newpass, String newpassAgain) {
|
|
|
|
var changePasswordC = library.lookup<NativeFunction<void_from_string_string_string_string_function>>("c_ChangePassword");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final ChangePasswordFn = changePasswordC.asFunction<VoidFromStringStringStringStringFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final utf8pass = pass.toNativeUtf8();
|
|
|
|
final utf8newpass = newpass.toNativeUtf8();
|
|
|
|
final utf8newpasssagain = newpassAgain.toNativeUtf8();
|
|
|
|
ChangePasswordFn(utf8profile, utf8profile.length, utf8pass, utf8pass.length, utf8newpass, utf8newpass.length, utf8newpasssagain, utf8newpasssagain.length);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(utf8pass);
|
|
|
|
malloc.free(utf8newpass);
|
|
|
|
malloc.free(utf8newpasssagain);
|
|
|
|
}
|
2022-02-08 21:54:17 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool isL10nInit() {
|
|
|
|
return _isL10nInit;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void l10nInit(String notificationSimple, String notificationConversationInfo) {
|
|
|
|
cwtchNotifier.l10nInit(notificationSimple, notificationConversationInfo);
|
|
|
|
_isL10nInit = true;
|
|
|
|
}
|
2022-03-09 22:35:12 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
void ExportProfile(String profile, String file) {
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final utf8file = file.toNativeUtf8();
|
|
|
|
var exportProfileC = library.lookup<NativeFunction<void_from_string_string_function>>("c_ExportProfile");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final ExportProfileFn = exportProfileC.asFunction<VoidFromStringStringFn>();
|
|
|
|
ExportProfileFn(utf8profile, utf8profile.length, utf8file, utf8file.length);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(utf8file);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
Future<String> ImportProfile(String file, String pass) async {
|
|
|
|
final utf8pass = pass.toNativeUtf8();
|
|
|
|
final utf8file = file.toNativeUtf8();
|
|
|
|
var exportProfileC = library.lookup<NativeFunction<string_string_to_string_function>>("c_ImportProfile");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final ExportProfileFn = exportProfileC.asFunction<StringFromStringStringFn>();
|
|
|
|
Pointer<Utf8> result = ExportProfileFn(utf8file, utf8file.length, utf8pass, utf8pass.length);
|
|
|
|
String importResult = result.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(result);
|
|
|
|
malloc.free(utf8pass);
|
|
|
|
malloc.free(utf8file);
|
|
|
|
return importResult;
|
|
|
|
}
|
2022-04-14 22:34:17 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<String> GetDebugInfo() async {
|
|
|
|
var getDebugInfo = library.lookup<NativeFunction<void_to_string>>("c_GetDebugInfo");
|
|
|
|
final GetDebugInfo = getDebugInfo.asFunction<StringFromVoid>();
|
|
|
|
Pointer<Utf8> result = GetDebugInfo();
|
|
|
|
String debugResult = result.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(result);
|
|
|
|
return debugResult;
|
|
|
|
}
|
2022-07-06 18:54:07 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<String> GetSharedFiles(String profile, int handle) async {
|
|
|
|
var getSharedFiles = library.lookup<NativeFunction<get_json_blob_from_str_int_function>>("c_GetSharedFiles");
|
|
|
|
final GetSharedFiles = getSharedFiles.asFunction<GetJsonBlobFromStrIntFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
Pointer<Utf8> jsonMessageBytes = GetSharedFiles(utf8profile, utf8profile.length, handle);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
return jsonMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void RestartSharing(String profile, String filekey) {
|
|
|
|
var restartSharingC = library.lookup<NativeFunction<void_from_string_string_function>>("c_RestartSharing");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final RestartSharing = restartSharingC.asFunction<VoidFromStringStringFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final ut8filekey = filekey.toNativeUtf8();
|
|
|
|
RestartSharing(utf8profile, utf8profile.length, ut8filekey, ut8filekey.length);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(ut8filekey);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void StopSharing(String profile, String filekey) {
|
|
|
|
var stopSharingC = library.lookup<NativeFunction<void_from_string_string_function>>("c_StopSharing");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final StopSharing = stopSharingC.asFunction<VoidFromStringStringFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final ut8filekey = filekey.toNativeUtf8();
|
|
|
|
StopSharing(utf8profile, utf8profile.length, ut8filekey, ut8filekey.length);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(ut8filekey);
|
|
|
|
}
|
2023-03-02 21:17:44 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void UpdateSettings(String json) {
|
|
|
|
var updateSettings = library.lookup<NativeFunction<string_to_void_function>>("c_UpdateSettings");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final UpdateSettingsFn = updateSettings.asFunction<VoidFromStringFn>();
|
|
|
|
final u1 = json.toNativeUtf8();
|
|
|
|
UpdateSettingsFn(u1, u1.length);
|
|
|
|
malloc.free(u1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool IsServersCompiled() {
|
|
|
|
return library.providesSymbol("c_LoadServers");
|
|
|
|
}
|
2023-03-27 19:00:49 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<String> SummarizeConversation(String profile, int conversation) async {
|
|
|
|
if (!library.providesSymbol("c_Summarize")) {
|
|
|
|
return Future.value("");
|
|
|
|
}
|
|
|
|
var summarize = library.lookup<NativeFunction<get_json_blob_from_str_int_function>>("c_Summarize");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final SummarizeFn = summarize.asFunction<GetJsonBlobFromStrIntFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
Pointer<Utf8> jsonMessageBytes = SummarizeFn(utf8profile, utf8profile.length, conversation);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
return jsonMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<String> TranslateMessage(String profile, int conversation, int message, String language) async {
|
|
|
|
if (!library.providesSymbol("c_Translate")) {
|
|
|
|
return Future.value("");
|
|
|
|
}
|
|
|
|
var translate = library.lookup<NativeFunction<get_json_blob_from_str_int_int_str_function>>("c_Translate");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final TranslateFn = translate.asFunction<GetJsonBlobFromStrIntIntStrFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final utf8lang = language.toNativeUtf8();
|
|
|
|
Pointer<Utf8> jsonMessageBytes = TranslateFn(
|
|
|
|
utf8profile,
|
|
|
|
utf8profile.length,
|
|
|
|
conversation,
|
|
|
|
message,
|
|
|
|
utf8lang,
|
|
|
|
utf8lang.length,
|
|
|
|
);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(utf8lang);
|
|
|
|
return jsonMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool IsBlodeuweddSupported() {
|
|
|
|
if (library.providesSymbol("c_Translate")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-04-04 20:58:42 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String? GetProfileAttribute(String profile, String key) {
|
|
|
|
var getProfileAttributeC = library.lookup<NativeFunction<get_json_blob_from_str_str_function>>("c_GetProfileAttribute");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final GetProfileAttribute = getProfileAttributeC.asFunction<GetJsonBlobFromStrStrFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final utf8key = key.toNativeUtf8();
|
|
|
|
Pointer<Utf8> jsonMessageBytes = GetProfileAttribute(utf8profile, utf8profile.length, utf8key, utf8key.length);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(utf8key);
|
|
|
|
|
|
|
|
try {
|
|
|
|
dynamic attributeResult = json.decode(jsonMessage);
|
|
|
|
if (attributeResult["Exists"]) {
|
|
|
|
return attributeResult["Value"];
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
EnvironmentConfig.debugLog("error getting profile attribute: $e");
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String? GetConversationAttribute(String profile, int conversation, String key) {
|
|
|
|
var getConversationAttributeC = library.lookup<NativeFunction<get_json_blob_from_str_int_string_function>>("c_GetConversationAttribute");
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
final GetConversationAttribute = getConversationAttributeC.asFunction<GetJsonBlobFromStrIntStringFn>();
|
|
|
|
final utf8profile = profile.toNativeUtf8();
|
|
|
|
final utf8key = key.toNativeUtf8();
|
|
|
|
Pointer<Utf8> jsonMessageBytes = GetConversationAttribute(utf8profile, utf8profile.length, conversation, utf8key, utf8key.length);
|
|
|
|
String jsonMessage = jsonMessageBytes.toDartString();
|
|
|
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(jsonMessageBytes);
|
|
|
|
malloc.free(utf8profile);
|
|
|
|
malloc.free(utf8key);
|
|
|
|
|
|
|
|
try {
|
|
|
|
dynamic attributeResult = json.decode(jsonMessage);
|
|
|
|
if (attributeResult["Exists"]) {
|
|
|
|
return attributeResult["Value"];
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
EnvironmentConfig.debugLog("error getting profile attribute: $e");
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|