Files
xuwenwei d3b6026bfd Initial commit: RustDesk 1.4.7 macOS desktop port
- 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
2026-06-08 21:43:20 +08:00

80 lines
1.9 KiB
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
typedef EventCallback<Data> = Future<dynamic> Function(Data data);
abstract class BaseEvent<EventType, Data> {
EventType type;
Data data;
/// Constructor.
BaseEvent(this.type, this.data);
/// Consume this event.
@visibleForTesting
Future<dynamic> consume() async {
final cb = findCallback(type);
if (cb == null) {
return null;
} else {
return cb(data);
}
}
EventCallback<Data>? findCallback(EventType type);
}
abstract class BaseEventLoop<EventType, Data> {
final List<BaseEvent<EventType, Data>> _evts = [];
Timer? _timer;
List<BaseEvent<EventType, Data>> get evts => _evts;
Future<void> onReady() async {
// Poll every 100ms.
_timer = Timer.periodic(Duration(milliseconds: 100), _handleTimer);
}
/// An Event is about to be consumed.
Future<void> onPreConsume(BaseEvent<EventType, Data> evt) async {}
/// An Event was consumed.
Future<void> onPostConsume(BaseEvent<EventType, Data> evt) async {}
/// Events are all handled and cleared.
Future<void> onEventsClear() async {}
/// Events start to consume.
Future<void> onEventsStartConsuming() async {}
Future<void> _handleTimer(Timer timer) async {
if (_evts.isEmpty) {
return;
}
timer.cancel();
_timer = null;
// Handle the logic.
await onEventsStartConsuming();
while (_evts.isNotEmpty) {
final evt = _evts.first;
_evts.remove(evt);
await onPreConsume(evt);
await evt.consume();
await onPostConsume(evt);
}
await onEventsClear();
// Now events are all processed.
_timer = Timer.periodic(Duration(milliseconds: 100), _handleTimer);
}
Future<void> close() async {
_timer?.cancel();
}
void pushEvent(BaseEvent<EventType, Data> evt) {
_evts.add(evt);
}
void clear() {
_evts.clear();
}
}