| 
									
										
										
										
											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'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class StateGlobal { | 
					
						
							|  |  |  |   int _windowId = -1; | 
					
						
							|  |  |  |   bool _fullscreen = false; | 
					
						
							|  |  |  |   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); | 
					
						
							| 
									
										
										
										
											2022-11-10 14:32:22 +08:00
										 |  |  |   final RxBool showRemoteMenuBar = false.obs; | 
					
						
							| 
									
										
										
										
											2022-11-01 17:01:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   int get windowId => _windowId; | 
					
						
							|  |  |  |   bool get fullscreen => _fullscreen; | 
					
						
							|  |  |  |   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
										 |  |  | 
 | 
					
						
							|  |  |  |   setWindowId(int id) => _windowId = id; | 
					
						
							|  |  |  |   setFullscreen(bool v) { | 
					
						
							|  |  |  |     if (_fullscreen != v) { | 
					
						
							|  |  |  |       _fullscreen = v; | 
					
						
							|  |  |  |       _showTabBar.value = !_fullscreen; | 
					
						
							| 
									
										
										
										
											2022-11-01 18:16:52 +08:00
										 |  |  |       _resizeEdgeSize.value = | 
					
						
							|  |  |  |           fullscreen ? kFullScreenEdgeSize : kWindowEdgeSize; | 
					
						
							| 
									
										
										
										
											2022-11-16 19:49:52 +08:00
										 |  |  |       _windowBorderWidth.value = fullscreen ? 0 : kWindowBorderWidth; | 
					
						
							| 
									
										
										
										
											2022-11-17 17:26:46 +08:00
										 |  |  |       WindowController.fromWindowId(windowId) | 
					
						
							|  |  |  |           .setFullscreen(_fullscreen) | 
					
						
							|  |  |  |           .then((_) { | 
					
						
							|  |  |  |         // https://github.com/leanflutter/window_manager/issues/131#issuecomment-1111587982
 | 
					
						
							|  |  |  |         if (Platform.isWindows && !v) { | 
					
						
							|  |  |  |           Future.delayed(Duration.zero, () async { | 
					
						
							|  |  |  |             final frame = | 
					
						
							|  |  |  |                 await WindowController.fromWindowId(windowId).getFrame(); | 
					
						
							|  |  |  |             final newRect = Rect.fromLTWH( | 
					
						
							|  |  |  |                 frame.left, frame.top, frame.width + 1, frame.height + 1); | 
					
						
							|  |  |  |             await WindowController.fromWindowId(windowId).setFrame(newRect); | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-11-01 17:01:43 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   StateGlobal._(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static final StateGlobal instance = StateGlobal._(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | final stateGlobal = StateGlobal.instance; |