2025-01-13 19:08:17 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
2025-01-13 19:08:17 +08:00
|
|
|
import 'package:flutter/scheduler.dart';
|
|
|
|
|
|
|
|
|
|
class Render {
|
|
|
|
|
static Render? _instance;
|
|
|
|
|
bool _isPaused = false;
|
|
|
|
|
final _dispatcher = SchedulerBinding.instance.platformDispatcher;
|
|
|
|
|
FrameCallback? _beginFrame;
|
|
|
|
|
VoidCallback? _drawFrame;
|
|
|
|
|
|
|
|
|
|
Render._internal();
|
|
|
|
|
|
|
|
|
|
factory Render() {
|
|
|
|
|
_instance ??= Render._internal();
|
|
|
|
|
return _instance!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
active() {
|
|
|
|
|
resume();
|
|
|
|
|
pause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pause() {
|
2025-03-12 17:15:31 +08:00
|
|
|
throttler.call(
|
2025-05-02 02:24:12 +08:00
|
|
|
FunctionTag.renderPause,
|
2025-01-13 19:08:17 +08:00
|
|
|
_pause,
|
2025-03-09 01:58:46 +08:00
|
|
|
duration: Duration(seconds: 5),
|
2025-01-13 19:08:17 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resume() {
|
2025-05-02 02:24:12 +08:00
|
|
|
throttler.cancel(FunctionTag.renderPause);
|
2025-01-13 19:08:17 +08:00
|
|
|
_resume();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 17:15:31 +08:00
|
|
|
void _pause() async {
|
2025-01-13 19:08:17 +08:00
|
|
|
if (_isPaused) return;
|
|
|
|
|
_isPaused = true;
|
|
|
|
|
_beginFrame = _dispatcher.onBeginFrame;
|
|
|
|
|
_drawFrame = _dispatcher.onDrawFrame;
|
|
|
|
|
_dispatcher.onBeginFrame = null;
|
|
|
|
|
_dispatcher.onDrawFrame = null;
|
2025-02-09 18:39:38 +08:00
|
|
|
commonPrint.log("pause");
|
2025-01-13 19:08:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _resume() {
|
|
|
|
|
if (!_isPaused) return;
|
|
|
|
|
_isPaused = false;
|
|
|
|
|
_dispatcher.onBeginFrame = _beginFrame;
|
|
|
|
|
_dispatcher.onDrawFrame = _drawFrame;
|
2025-02-03 23:32:00 +08:00
|
|
|
_dispatcher.scheduleFrame();
|
2025-02-09 18:39:38 +08:00
|
|
|
commonPrint.log("resume");
|
2025-01-13 19:08:17 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-09 16:46:14 +08:00
|
|
|
final Render? render = system.isDesktop ? Render() : null;
|