adjust cm display behavior

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-09-01 21:18:53 +08:00
parent 39a1545e94
commit f6bc448cec
10 changed files with 83 additions and 40 deletions

View File

@ -20,7 +20,8 @@ class ConnectionTabPage extends StatefulWidget {
}
class _ConnectionTabPageState extends State<ConnectionTabPage> {
final tabController = Get.put(DesktopTabController());
final tabController =
Get.put(DesktopTabController(tabType: DesktopTabType.remoteScreen));
static const IconData selectedIcon = Icons.desktop_windows_sharp;
static const IconData unselectedIcon = Icons.desktop_windows_outlined;
@ -60,6 +61,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
if (call.method == "new_remote_desktop") {
final args = jsonDecode(call.arguments);
final id = args['id'];
ConnectionTypeState.init(id);
window_on_top(windowId());
ConnectionTypeState.init(id);
tabController.add(TabInfo(
@ -94,7 +96,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
body: Obx(() => DesktopTab(
controller: tabController,
theme: theme,
tabType: DesktopTabType.remoteScreen,
showTabBar: fullscreen.isFalse,
onClose: () {
tabController.clear();

View File

@ -15,7 +15,7 @@ class DesktopTabPage extends StatefulWidget {
}
class _DesktopTabPageState extends State<DesktopTabPage> {
final tabController = DesktopTabController();
final tabController = DesktopTabController(tabType: DesktopTabType.main);
@override
void initState() {
@ -46,7 +46,6 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
body: DesktopTab(
controller: tabController,
theme: dark ? TarBarTheme.dark() : TarBarTheme.light(),
tabType: DesktopTabType.main,
tail: ActionIcon(
message: 'Settings',
icon: IconFont.menu,

View File

@ -25,7 +25,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
static final IconData unselectedIcon = Icons.file_copy_outlined;
_FileManagerTabPageState(Map<String, dynamic> params) {
Get.put(DesktopTabController());
Get.put(DesktopTabController(tabType: DesktopTabType.fileTransfer));
tabController.add(TabInfo(
key: params['id'],
label: params['id'],
@ -74,7 +74,6 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
body: DesktopTab(
controller: tabController,
theme: theme,
tabType: DesktopTabType.fileTransfer,
onClose: () {
tabController.clear();
},

View File

@ -18,7 +18,7 @@ class PortForwardTabPage extends StatefulWidget {
}
class _PortForwardTabPageState extends State<PortForwardTabPage> {
final tabController = Get.put(DesktopTabController());
late final DesktopTabController tabController;
late final bool isRDP;
static const IconData selectedIcon = Icons.forward_sharp;
@ -26,6 +26,8 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
_PortForwardTabPageState(Map<String, dynamic> params) {
isRDP = params['isRDP'];
tabController = Get.put(DesktopTabController(
tabType: isRDP ? DesktopTabType.rdp : DesktopTabType.portForward));
tabController.add(TabInfo(
key: params['id'],
label: params['id'],
@ -78,7 +80,6 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
body: DesktopTab(
controller: tabController,
theme: theme,
tabType: isRDP ? DesktopTabType.rdp : DesktopTabType.portForward,
onClose: () {
tabController.clear();
},

View File

@ -19,10 +19,12 @@ class DesktopServerPage extends StatefulWidget {
class _DesktopServerPageState extends State<DesktopServerPage>
with WindowListener, AutomaticKeepAliveClientMixin {
final tabController = gFFI.serverModel.tabController;
@override
void initState() {
gFFI.ffiModel.updateEventListener("");
windowManager.addListener(this);
tabController.onRemove = (_, id) => onRemoveId(id);
super.initState();
}
@ -39,6 +41,13 @@ class _DesktopServerPageState extends State<DesktopServerPage>
super.onWindowClose();
}
void onRemoveId(String id) {
if (tabController.state.value.tabs.isEmpty) {
windowManager.close();
}
}
@override
Widget build(BuildContext context) {
super.build(context);
return MultiProvider(
@ -115,7 +124,6 @@ class ConnectionManagerState extends State<ConnectionManager> {
showMinimize: true,
showClose: true,
controller: serverModel.tabController,
tabType: DesktopTabType.cm,
pageViewBuilder: (pageView) => Row(children: [
Expanded(child: pageView),
Consumer<ChatModel>(
@ -454,8 +462,10 @@ class _CmControlPanel extends StatelessWidget {
decoration: BoxDecoration(
color: MyTheme.accent, borderRadius: BorderRadius.circular(10)),
child: InkWell(
onTap: () =>
checkClickTime(client.id, () => handleAccept(context)),
onTap: () => checkClickTime(client.id, () {
handleAccept(context);
windowManager.minimize();
}),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [

View File

@ -59,13 +59,15 @@ class DesktopTabState {
class DesktopTabController {
final state = DesktopTabState().obs;
final DesktopTabType tabType;
/// index, key
Function(int, String)? onRemove;
Function(int)? onSelected;
void add(TabInfo tab) {
DesktopTabController({required this.tabType});
void add(TabInfo tab, {bool authorized = false}) {
if (!isDesktop) return;
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
int toIndex;
@ -79,6 +81,16 @@ class DesktopTabController {
toIndex = state.value.tabs.length - 1;
assert(toIndex >= 0);
}
if (tabType == DesktopTabType.cm) {
Future.delayed(Duration.zero, () async {
window_on_top(null);
});
if (authorized) {
Future.delayed(const Duration(seconds: 3), () {
windowManager.minimize();
});
}
}
try {
jumpTo(toIndex);
} catch (e) {
@ -106,6 +118,7 @@ class DesktopTabController {
}
void jumpTo(int index) {
if (!isDesktop || index < 0) return;
state.update((val) {
val!.selected = index;
Future.delayed(Duration.zero, (() {
@ -114,12 +127,14 @@ class DesktopTabController {
}
if (val.scrollController.hasClients &&
val.scrollController.canScroll &&
val.scrollController.itemCount >= index) {
val.scrollController.itemCount > index) {
val.scrollController.scrollToItem(index, center: true, animate: true);
}
}));
});
onSelected?.call(index);
if (state.value.tabs.length > index) {
onSelected?.call(index);
}
}
void closeBy(String? key) {
@ -154,8 +169,6 @@ typedef LabelGetter = Rx<String> Function(String key);
class DesktopTab extends StatelessWidget {
final Function(String)? onTabClose;
final TarBarTheme theme;
final DesktopTabType tabType;
final bool isMainWindow;
final bool showTabBar;
final bool showLogo;
final bool showTitle;
@ -170,10 +183,12 @@ class DesktopTab extends StatelessWidget {
final DesktopTabController controller;
Rx<DesktopTabState> get state => controller.state;
late final DesktopTabType tabType;
late final bool isMainWindow;
const DesktopTab({
DesktopTab({
Key? key,
required this.controller,
required this.tabType,
this.theme = const TarBarTheme.light(),
this.onTabClose,
this.showTabBar = true,
@ -187,8 +202,11 @@ class DesktopTab extends StatelessWidget {
this.onClose,
this.tabBuilder,
this.labelGetter,
}) : isMainWindow =
tabType == DesktopTabType.main || tabType == DesktopTabType.cm;
}) : super(key: key) {
tabType = controller.tabType;
isMainWindow =
tabType == DesktopTabType.main || tabType == DesktopTabType.cm;
}
@override
Widget build(BuildContext context) {

View File

@ -165,6 +165,7 @@ void runConnectionManagerScreen() async {
await windowManager.setAlignment(Alignment.topRight);
await windowManager.show();
await windowManager.focus();
await windowManager.setAlignment(Alignment.topRight); // ensure
})
]);
runApp(GetMaterialApp(

View File

@ -59,6 +59,7 @@ class ChatPage extends StatelessWidget implements PageShape {
messages: chatModel
.messages[chatModel.currentID]?.chatMessages ??
[],
inputOptions: const InputOptions(sendOnEnter: true),
messageOptions: MessageOptions(
showOtherUsersAvatar: false,
showTime: true,

View File

@ -209,10 +209,19 @@ class ChatModel with ChangeNotifier {
id: await bind.mainGetLastRemoteId(),
);
} else {
final client = _ffi.target?.serverModel.clients[id];
final client = _ffi.target?.serverModel.clients
.firstWhere((client) => client.id == id);
if (client == null) {
return debugPrint("Failed to receive msg,user doesn't exist");
}
if (isDesktop) {
window_on_top(null);
var index = _ffi.target?.serverModel.clients
.indexWhere((client) => client.id == id);
if (index != null && index >= 0) {
gFFI.serverModel.tabController.jumpTo(index);
}
}
chatUser = ChatUser(id: client.peerId, firstName: client.name);
}

View File

@ -32,7 +32,7 @@ class ServerModel with ChangeNotifier {
late final TextEditingController _serverId;
final _serverPasswd = TextEditingController(text: "");
final tabController = DesktopTabController();
final tabController = DesktopTabController(tabType: DesktopTabType.cm);
List<Client> _clients = [];
@ -347,20 +347,18 @@ class ServerModel with ChangeNotifier {
var res = await bind.mainGetClientsState();
try {
final List clientsJson = jsonDecode(res);
if (isDesktop && clientsJson.isEmpty && _clients.isNotEmpty) {
// exit cm when >1 peers to no peers
exit(0);
}
_clients.clear();
tabController.state.value.tabs.clear();
for (var clientJson in clientsJson) {
final client = Client.fromJson(clientJson);
_clients.add(client);
tabController.add(TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)));
tabController.add(
TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)),
authorized: client.authorized);
}
notifyListeners();
} catch (e) {
@ -471,14 +469,18 @@ class ServerModel with ChangeNotifier {
} else {
_clients[index].authorized = true;
}
tabController.add(TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)));
tabController.add(
TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)),
authorized: true);
scrollToBottom();
notifyListeners();
} catch (e) {}
} catch (e) {
debugPrint("onClientAuthorized:$e");
}
}
void onClientRemove(Map<String, dynamic> evt) {
@ -486,8 +488,10 @@ class ServerModel with ChangeNotifier {
final id = int.parse(evt['id'] as String);
if (_clients.any((c) => c.id == id)) {
final index = _clients.indexWhere((client) => client.id == id);
_clients.removeAt(index);
tabController.remove(index);
if (index >= 0) {
_clients.removeAt(index);
tabController.remove(index);
}
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(id));
parent.target?.invokeMethod("cancel_notification", id);
}