Gomuks SDK Rewrite #2
3 changed files with 31 additions and 24 deletions
kind of working!
commit
c0dfb6370e
|
|
@ -37,21 +37,25 @@ class ClientController extends Notifier<int> {
|
||||||
|
|
||||||
GomuksStart(
|
GomuksStart(
|
||||||
handle,
|
handle,
|
||||||
Pointer.fromFunction<
|
NativeCallable<
|
||||||
Void Function(Pointer<Char>, Int64, GomuksBorrowedBuffer)
|
Void Function(Pointer<Char>, Int64, GomuksBorrowedBuffer)
|
||||||
>(gomuksCallback),
|
>.listener(gomuksCallback)
|
||||||
|
.nativeFunction,
|
||||||
);
|
);
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> sendCommand(String command, Map<String, dynamic> data) {
|
Map<String, dynamic> sendCommand(String command, Map<String, dynamic> data) {
|
||||||
|
final bufferPointer = data.toGomuksBufferPtr();
|
||||||
final response = GomuksSubmitCommand(
|
final response = GomuksSubmitCommand(
|
||||||
state,
|
state,
|
||||||
command.toNativeUtf8().cast<Char>(),
|
command.toNativeUtf8().cast<Char>(),
|
||||||
data.toGomuksBuffer(),
|
bufferPointer.ref,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
calloc.free(bufferPointer);
|
||||||
|
|
||||||
return response.buf.toJson();
|
return response.buf.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,26 +31,27 @@ extension GomuksOwnedBufferToJson on GomuksOwnedBuffer {
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final bytes = toBytes();
|
final bytes = toBytes();
|
||||||
if (bytes.isEmpty) return {};
|
if (bytes.isEmpty) return {};
|
||||||
return jsonDecode(utf8.decode(bytes));
|
final json = jsonDecode(utf8.decode(bytes));
|
||||||
|
|
||||||
|
if (json is Map<String, dynamic>?) return json ?? {};
|
||||||
|
throw json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
extension JsonToGomuksBuffer on Map<String, dynamic> {
|
||||||
GomuksBorrowedBuffer toGomuksBuffer() {
|
Pointer<GomuksBorrowedBuffer> toGomuksBufferPtr() {
|
||||||
final jsonString = json.encode(this);
|
final jsonString = json.encode(this);
|
||||||
final bytes = utf8.encode(jsonString);
|
final bytes = utf8.encode(jsonString);
|
||||||
|
|
||||||
final dataPtr = calloc<Uint8>(bytes.length);
|
final dataPtr = calloc<Uint8>(bytes.length);
|
||||||
dataPtr.asTypedList(bytes.length).setAll(0, bytes);
|
dataPtr.asTypedList(bytes.length).setAll(0, bytes);
|
||||||
|
|
||||||
final bufPtr = calloc<GomuksBorrowedBuffer>();
|
final ptr = calloc<GomuksBorrowedBuffer>();
|
||||||
bufPtr.ref.base = dataPtr;
|
|
||||||
bufPtr.ref.length = bytes.length;
|
|
||||||
|
|
||||||
final bufByValue = bufPtr.ref;
|
ptr.ref
|
||||||
|
..base = dataPtr
|
||||||
|
..length = bytes.length;
|
||||||
|
|
||||||
calloc.free(bufPtr);
|
return ptr;
|
||||||
|
|
||||||
return bufByValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,17 +97,19 @@ class App extends ConsumerWidget {
|
||||||
builder: (context) => ref
|
builder: (context) => ref
|
||||||
.watch(SharedPrefsController.provider)
|
.watch(SharedPrefsController.provider)
|
||||||
.betterWhen(
|
.betterWhen(
|
||||||
data: (_) {
|
data: (_) => ElevatedButton(
|
||||||
final response = ref
|
onPressed: () async {
|
||||||
.watch(ClientController.provider.notifier)
|
final response = ref
|
||||||
.sendCommand("login", {
|
.watch(ClientController.provider.notifier)
|
||||||
"homeserver_url": "federated.nexus",
|
.sendCommand("login", {
|
||||||
"username": "quadradical",
|
"homeserver_url": "https://matrix.federated.nexus",
|
||||||
"password": "Quadmarad1!",
|
"username": "quadradical",
|
||||||
});
|
"password": "Quadfnrad1!",
|
||||||
|
});
|
||||||
return Text(response.toString());
|
print(response);
|
||||||
},
|
},
|
||||||
|
child: Text("foo"),
|
||||||
|
),
|
||||||
// .betterWhen(
|
// .betterWhen(
|
||||||
// data: (client) =>
|
// data: (client) =>
|
||||||
// client.accessToken == null ? LoginPage() : ChatPage(),
|
// client.accessToken == null ? LoginPage() : ChatPage(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue