use new access token thingy
This commit is contained in:
parent
d34b5a2f3b
commit
e8de3985a9
3 changed files with 12 additions and 17 deletions
|
|
@ -105,9 +105,9 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> _sendCommand(
|
Future<dynamic> _sendCommand(
|
||||||
String command,
|
String command, [
|
||||||
Map<String, dynamic> data,
|
Map<String, dynamic> data = const {},
|
||||||
) async {
|
]) async {
|
||||||
final bufferPointer = data.toGomuksBufferPtr();
|
final bufferPointer = data.toGomuksBufferPtr();
|
||||||
final handle = await future;
|
final handle = await future;
|
||||||
final response = await Isolate.run(
|
final response = await Isolate.run(
|
||||||
|
|
@ -145,6 +145,11 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
return response["room_id"];
|
return response["room_id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String?> getAccessToken() async {
|
||||||
|
final response = await _sendCommand("get_account_info", {});
|
||||||
|
return response["access_token"];
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> leaveRoom(Room room) async {
|
Future<void> leaveRoom(Room room) async {
|
||||||
if (room.metadata == null) return;
|
if (room.metadata == null) return;
|
||||||
await _sendCommand("leave_room", {"room_id": room.metadata!.id});
|
await _sendCommand("leave_room", {"room_id": room.metadata!.id});
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,11 @@
|
||||||
import "dart:ffi";
|
|
||||||
import "dart:isolate";
|
|
||||||
import "package:ffi/ffi.dart";
|
|
||||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||||
import "package:nexus/controllers/client_controller.dart";
|
import "package:nexus/controllers/client_controller.dart";
|
||||||
import "package:nexus/src/third_party/gomuks.g.dart";
|
|
||||||
|
|
||||||
class HeaderController extends AsyncNotifier<Map<String, String>> {
|
class HeaderController extends AsyncNotifier<Map<String, String>> {
|
||||||
@override
|
@override
|
||||||
Future<Map<String, String>> build() async {
|
Future<Map<String, String>> build() async {
|
||||||
final handle = await ref.watch(ClientController.provider.future);
|
final client = ref.watch(ClientController.provider.notifier);
|
||||||
final info = await Isolate.run(() => GomuksGetAccountInfo(handle));
|
return {"authorization": "Bearer ${await client.getAccessToken()}"};
|
||||||
final headers = {
|
|
||||||
if (info.access_token != nullptr)
|
|
||||||
"authorization":
|
|
||||||
"Bearer ${info.access_token.cast<Utf8>().toDartString()}",
|
|
||||||
};
|
|
||||||
|
|
||||||
await Isolate.run(() => GomuksFreeAccountInfo(info));
|
|
||||||
return headers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final provider =
|
static final provider =
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ void main(List<String> args) async {
|
||||||
"--depth",
|
"--depth",
|
||||||
"1",
|
"1",
|
||||||
"https://mau.dev/gomuks/gomuks",
|
"https://mau.dev/gomuks/gomuks",
|
||||||
|
"--branch",
|
||||||
|
"tulir/ffi-updates",
|
||||||
repoDir.path,
|
repoDir.path,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue