veilidchat/lib/tools/window_control.dart

62 lines
1.7 KiB
Dart
Raw Normal View History

2023-12-27 22:56:24 -05:00
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
2024-07-08 21:29:52 -04:00
import '../theme/views/responsive.dart';
2023-12-27 22:56:24 -05:00
export 'package:window_manager/window_manager.dart' show TitleBarStyle;
enum OrientationCapability {
normal,
portraitOnly,
landscapeOnly,
}
// Window Control
Future<void> initializeWindowControl() async {
if (isDesktop) {
await windowManager.ensureInitialized();
const windowOptions = WindowOptions(
size: Size(768, 1024),
2024-07-08 21:29:52 -04:00
minimumSize: Size(400, 500),
2023-12-27 22:56:24 -05:00
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
);
await windowManager.waitUntilReadyToShow(windowOptions, () async {
2024-01-08 21:37:08 -05:00
await changeWindowSetup(
TitleBarStyle.hidden, OrientationCapability.normal);
2023-12-27 22:56:24 -05:00
await windowManager.show();
await windowManager.focus();
});
}
}
2024-01-08 21:37:08 -05:00
Future<void> changeWindowSetup(TitleBarStyle titleBarStyle,
2023-12-27 22:56:24 -05:00
OrientationCapability orientationCapability) async {
if (isDesktop) {
await windowManager.setTitleBarStyle(titleBarStyle);
} else {
switch (orientationCapability) {
case OrientationCapability.normal:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
case OrientationCapability.portraitOnly:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
case OrientationCapability.landscapeOnly:
await SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
}
}