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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user