mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-09 15:38:13 -07:00
feature: HTPC mode startup argument (#358)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
a8795cf0c9
commit
69a5e3db7a
24 changed files with 416 additions and 151 deletions
63
lib/util/resolution_checker.dart
Normal file
63
lib/util/resolution_checker.dart
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:screen_retriever/screen_retriever.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import 'package:fladder/providers/arguments_provider.dart';
|
||||
|
||||
class ResolutionChecker extends ConsumerStatefulWidget {
|
||||
final Widget child;
|
||||
const ResolutionChecker({required this.child, super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ResolutionChecker> createState() => _ResolutionCheckerState();
|
||||
}
|
||||
|
||||
class _ResolutionCheckerState extends ConsumerState<ResolutionChecker> {
|
||||
Size? lastResolution;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((value) async {
|
||||
if (ref.read(argumentsStateProvider).htpcMode) {
|
||||
lastResolution = (await screenRetriever.getPrimaryDisplay()).size;
|
||||
_timer = Timer.periodic(const Duration(seconds: 2), (timer) => checkResolution());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> checkResolution() async {
|
||||
if (!mounted) return;
|
||||
final newResolution = (await screenRetriever.getPrimaryDisplay()).size;
|
||||
if (lastResolution != newResolution) {
|
||||
lastResolution = newResolution;
|
||||
shouldSetResolution();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> shouldSetResolution() async {
|
||||
if (lastResolution != null) {
|
||||
final isFullScreen = await windowManager.isFullScreen();
|
||||
if (isFullScreen) {
|
||||
await windowManager.setFullScreen(false);
|
||||
}
|
||||
await windowManager.setFullScreen(true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.child;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue