2022-11-17 17:26:46 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-11-01 17:01:43 +08:00
|
|
|
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
2022-11-17 17:26:46 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-11-01 17:01:43 +08:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
import '../consts.dart';
|
|
|
|
|
2023-06-21 16:08:45 +08:00
|
|
|
enum SvcStatus { notReady, connecting, ready }
|
|
|
|
|
2022-11-01 17:01:43 +08:00
|
|
|
class StateGlobal {
|
|
|
|
int _windowId = -1;
|
2023-01-10 14:11:49 +08:00
|
|
|
bool grabKeyboard = false;
|
2023-08-11 19:03:09 +08:00
|
|
|
bool _fullscreen = false;
|
|
|
|
bool _isMinimized = false;
|
|
|
|
final RxBool isMaximized = false.obs;
|
2022-11-01 17:01:43 +08:00
|
|
|
final RxBool _showTabBar = true.obs;
|
2022-11-17 20:24:17 +08:00
|
|
|
final RxDouble _resizeEdgeSize = RxDouble(kWindowEdgeSize);
|
2022-11-16 19:49:52 +08:00
|
|
|
final RxDouble _windowBorderWidth = RxDouble(kWindowBorderWidth);
|
2023-06-11 16:32:22 +08:00
|
|
|
final RxBool showRemoteToolBar = false.obs;
|
2023-06-21 16:08:45 +08:00
|
|
|
final svcStatus = SvcStatus.notReady.obs;
|
2023-09-07 21:50:03 +08:00
|
|
|
// Only used for macOS
|
|
|
|
bool closeOnFullscreen = false;
|
2022-11-01 17:01:43 +08:00
|
|
|
|
2023-05-19 20:48:47 +08:00
|
|
|
// Use for desktop -> remote toolbar -> resolution
|
|
|
|
final Map<String, Map<int, String?>> _lastResolutionGroupValues = {};
|
|
|
|
|
2022-11-01 17:01:43 +08:00
|
|
|
int get windowId => _windowId;
|
|
|
|
bool get fullscreen => _fullscreen;
|
2023-08-11 19:03:09 +08:00
|
|
|
bool get isMinimized => _isMinimized;
|
2022-11-01 17:01:43 +08:00
|
|
|
double get tabBarHeight => fullscreen ? 0 : kDesktopRemoteTabBarHeight;
|
|
|
|
RxBool get showTabBar => _showTabBar;
|
2022-11-01 18:16:52 +08:00
|
|
|
RxDouble get resizeEdgeSize => _resizeEdgeSize;
|
2022-11-16 19:49:52 +08:00
|
|
|
RxDouble get windowBorderWidth => _windowBorderWidth;
|
2022-11-01 17:01:43 +08:00
|
|
|
|
2023-05-19 20:48:47 +08:00
|
|
|
resetLastResolutionGroupValues(String peerId) {
|
|
|
|
_lastResolutionGroupValues[peerId] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
setLastResolutionGroupValue(
|
|
|
|
String peerId, int currentDisplay, String? value) {
|
|
|
|
if (!_lastResolutionGroupValues.containsKey(peerId)) {
|
|
|
|
_lastResolutionGroupValues[peerId] = {};
|
|
|
|
}
|
|
|
|
_lastResolutionGroupValues[peerId]![currentDisplay] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
String? getLastResolutionGroupValue(String peerId, int currentDisplay) {
|
|
|
|
return _lastResolutionGroupValues[peerId]?[currentDisplay];
|
|
|
|
}
|
|
|
|
|
2022-11-01 17:01:43 +08:00
|
|
|
setWindowId(int id) => _windowId = id;
|
2023-08-11 15:53:47 +08:00
|
|
|
setMaximized(bool v) {
|
2023-08-13 14:30:14 +08:00
|
|
|
if (!_fullscreen) {
|
|
|
|
if (isMaximized.value != v) {
|
|
|
|
isMaximized.value = v;
|
|
|
|
_resizeEdgeSize.value =
|
|
|
|
isMaximized.isTrue ? kMaximizeEdgeSize : kWindowEdgeSize;
|
|
|
|
}
|
|
|
|
if (!Platform.isMacOS) {
|
|
|
|
_windowBorderWidth.value = v ? 0 : kWindowBorderWidth;
|
|
|
|
}
|
2023-02-27 12:01:22 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-13 14:30:14 +08:00
|
|
|
|
2023-08-11 19:03:09 +08:00
|
|
|
setMinimized(bool v) => _isMinimized = v;
|
2023-05-19 20:48:47 +08:00
|
|
|
|
2023-09-07 20:04:23 +08:00
|
|
|
setFullscreen(bool v, {bool procWnd = true}) {
|
2022-11-01 17:01:43 +08:00
|
|
|
if (_fullscreen != v) {
|
|
|
|
_fullscreen = v;
|
|
|
|
_showTabBar.value = !_fullscreen;
|
2023-05-19 20:48:47 +08:00
|
|
|
_resizeEdgeSize.value = fullscreen
|
2023-03-10 00:15:07 +08:00
|
|
|
? kFullScreenEdgeSize
|
2023-08-11 19:03:09 +08:00
|
|
|
: isMaximized.isTrue
|
2023-03-10 00:15:07 +08:00
|
|
|
? kMaximizeEdgeSize
|
|
|
|
: kWindowEdgeSize;
|
|
|
|
print(
|
2023-07-27 20:45:29 +08:00
|
|
|
"fullscreen: $fullscreen, resizeEdgeSize: ${_resizeEdgeSize.value}");
|
2022-11-16 19:49:52 +08:00
|
|
|
_windowBorderWidth.value = fullscreen ? 0 : kWindowBorderWidth;
|
2023-09-07 20:04:23 +08:00
|
|
|
if (procWnd) {
|
2023-10-17 09:36:08 +08:00
|
|
|
final wc = WindowController.fromWindowId(windowId);
|
|
|
|
wc.setFullscreen(_fullscreen).then((_) {
|
2023-09-07 20:04:23 +08:00
|
|
|
// https://github.com/leanflutter/window_manager/issues/131#issuecomment-1111587982
|
|
|
|
if (Platform.isWindows && !v) {
|
|
|
|
Future.delayed(Duration.zero, () async {
|
2023-10-17 09:36:08 +08:00
|
|
|
final frame = await wc.getFrame();
|
2023-09-07 20:04:23 +08:00
|
|
|
final newRect = Rect.fromLTWH(
|
|
|
|
frame.left, frame.top, frame.width + 1, frame.height + 1);
|
2023-10-17 09:36:08 +08:00
|
|
|
await wc.setFrame(newRect);
|
2023-09-07 20:04:23 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-11-01 17:01:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StateGlobal._();
|
|
|
|
|
|
|
|
static final StateGlobal instance = StateGlobal._();
|
|
|
|
}
|
|
|
|
|
|
|
|
final stateGlobal = StateGlobal.instance;
|