d3b6026bfd
- Filled empty libs/hbb_common/ submodule (cloned from rustdesk/hbb_common) - Patched Flutter 3.44 / Dart 3.12 compatibility: * flutter/lib/generated_bridge.dart: asTypedList with cast<>, DartPort=Int64 * flutter/lib/common.dart: DialogTheme->DialogThemeData, TabBarTheme->TabBarThemeData * flutter/pubspec.yaml: extended_text 14.0.0->15.0.2, google_fonts override 5.0.0 * flutter/macos/Runner/Configs/Release.xcconfig: EXCLUDED_ARCHS=x86_64 - Build verified: cargo check + cargo build --features flutter + cargo build --release --features flutter - Verified flutter build macos --debug and --release both produce working .app - Verified .dmg installer (27MB arm64) created via hdiutil - Build deps: Xcode 26.5, CocoaPods 1.16.2, Flutter 3.44, VCPKG arm64-osx
80 lines
2.5 KiB
Dart
80 lines
2.5 KiB
Dart
import 'dart:convert';
|
|
import 'dart:ffi';
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hbb/plugin/ui_manager.dart';
|
|
import 'package:flutter_hbb/plugin/utils/dialogs.dart';
|
|
|
|
abstract class NativeHandler {
|
|
bool onEvent(Map<String, dynamic> evt);
|
|
}
|
|
|
|
typedef OnSelectPeersCallback = Bool Function(Int returnCode,
|
|
Pointer<Void> data, Uint64 dataLength, Pointer<Void> userData);
|
|
typedef OnSelectPeersCallbackDart = bool Function(
|
|
int returnCode, Pointer<Void> data, int dataLength, Pointer<Void> userData);
|
|
|
|
class NativeUiHandler extends NativeHandler {
|
|
NativeUiHandler._();
|
|
|
|
static NativeUiHandler instance = NativeUiHandler._();
|
|
|
|
@override
|
|
bool onEvent(Map<String, dynamic> evt) {
|
|
final name = evt['name'];
|
|
final action = evt['action'];
|
|
if (name != "native_ui") {
|
|
return false;
|
|
}
|
|
switch (action) {
|
|
case "select_peers":
|
|
int cb = evt['cb'];
|
|
int userData = evt['user_data'] ?? 0;
|
|
final cbFuncNative = Pointer.fromAddress(cb)
|
|
.cast<NativeFunction<OnSelectPeersCallback>>();
|
|
final cbFuncDart = cbFuncNative.asFunction<OnSelectPeersCallbackDart>();
|
|
onSelectPeers(cbFuncDart, userData);
|
|
break;
|
|
case "register_ui_entry":
|
|
int cb = evt['on_tap_cb'];
|
|
int userData = evt['user_data'] ?? 0;
|
|
String title = evt['title'] ?? "";
|
|
final cbFuncNative = Pointer.fromAddress(cb)
|
|
.cast<NativeFunction<OnSelectPeersCallback>>();
|
|
final cbFuncDart = cbFuncNative.asFunction<OnSelectPeersCallbackDart>();
|
|
onRegisterUiEntry(title, cbFuncDart, userData);
|
|
break;
|
|
default:
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void onSelectPeers(OnSelectPeersCallbackDart cb, int userData) async {
|
|
showPeerSelectionDialog(onPeersCallback: (peers) {
|
|
String json = jsonEncode(<String, dynamic> {
|
|
"peers": peers
|
|
});
|
|
final native = json.toNativeUtf8();
|
|
cb(0, native.cast(), native.length, Pointer.fromAddress(userData));
|
|
malloc.free(native);
|
|
});
|
|
}
|
|
|
|
void onRegisterUiEntry(String title, OnSelectPeersCallbackDart cbFuncDart, int userData) {
|
|
Widget widget = InkWell(
|
|
child: Container(
|
|
height: 25.0,
|
|
child: Row(
|
|
children: [
|
|
Expanded(child: Text(title)),
|
|
Icon(Icons.chevron_right_rounded, size: 12.0,)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
PluginUiManager.instance.registerEntry(title, widget);
|
|
}
|
|
}
|