feat: Introduce Wolf3dAppManager for managing audio shutdown and game data directory selection

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-23 19:37:32 +01:00
parent 88050dbc7d
commit 6441592534
3 changed files with 149 additions and 11 deletions
@@ -21,37 +21,47 @@ class Wolf3dApp extends StatefulWidget {
}
class _Wolf3dAppState extends State<Wolf3dApp> with WidgetsBindingObserver {
Future<void>? _shutdownFuture;
late final Wolf3dAppManager _manager;
@override
void initState() {
super.initState();
_manager = Wolf3dAppManager(engine: widget.engine);
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
unawaited(_ensureAudioShutdown());
unawaited(_manager.ensureAudioShutdown());
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.detached) {
unawaited(_ensureAudioShutdown());
unawaited(_manager.ensureAudioShutdown());
}
}
Future<void> _ensureAudioShutdown() {
final Future<void>? existing = _shutdownFuture;
if (existing != null) {
return existing;
}
Future<void> _pickGameDataDirectory() {
return _manager.pickGameDataDirectory(
notifyChanged: () {
if (mounted) {
setState(() {});
}
},
);
}
final Future<void> shutdown = widget.engine.shutdownAudio();
_shutdownFuture = shutdown;
return shutdown;
Future<void> _pickGameDataFiles() {
return _manager.pickGameDataFiles(
notifyChanged: () {
if (mounted) {
setState(() {});
}
},
);
}
@override
@@ -59,6 +69,10 @@ class _Wolf3dAppState extends State<Wolf3dApp> with WidgetsBindingObserver {
return widget.engine.availableGames.isEmpty
? NoGameDataScreen(
configuredDataDirectory: widget.engine.configuredDataDirectory,
onPickGameDataDirectory: _pickGameDataDirectory,
onPickGameDataFiles: _pickGameDataFiles,
isLoadingGameData: _manager.isLoadingGameData,
pickerError: _manager.pickerError,
)
: GameScreen(wolf3d: widget.engine);
}