desktop cm chat feat: disable auto jumpTo other page when current hasFocus & add unread message mark on tab
This commit is contained in:
parent
5a905174e7
commit
c100505fa1
@ -61,6 +61,7 @@ class ChatPage extends StatelessWidget implements PageShape {
|
|||||||
[],
|
[],
|
||||||
inputOptions: InputOptions(
|
inputOptions: InputOptions(
|
||||||
sendOnEnter: true,
|
sendOnEnter: true,
|
||||||
|
focusNode: chatModel.inputNode,
|
||||||
inputTextStyle: TextStyle(
|
inputTextStyle: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
|
@ -139,14 +139,20 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
selectedTabBackgroundColor:
|
selectedTabBackgroundColor:
|
||||||
Theme.of(context).hintColor.withOpacity(0.2),
|
Theme.of(context).hintColor.withOpacity(0.2),
|
||||||
tabBuilder: (key, icon, label, themeConf) {
|
tabBuilder: (key, icon, label, themeConf) {
|
||||||
|
final client = serverModel.clients.firstWhereOrNull(
|
||||||
|
(client) => client.id.toString() == key);
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
icon,
|
|
||||||
Tooltip(
|
Tooltip(
|
||||||
message: key,
|
message: key,
|
||||||
waitDuration: Duration(seconds: 1),
|
waitDuration: Duration(seconds: 1),
|
||||||
child: label),
|
child: label),
|
||||||
|
Obx(() => Offstage(
|
||||||
|
offstage:
|
||||||
|
!(client?.hasUnreadChatMessage.value ?? false),
|
||||||
|
child:
|
||||||
|
Icon(Icons.circle, color: Colors.red, size: 10)))
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -29,6 +29,7 @@ class TabInfo {
|
|||||||
final IconData? unselectedIcon;
|
final IconData? unselectedIcon;
|
||||||
final bool closable;
|
final bool closable;
|
||||||
final VoidCallback? onTabCloseButton;
|
final VoidCallback? onTabCloseButton;
|
||||||
|
final VoidCallback? onTap;
|
||||||
final Widget page;
|
final Widget page;
|
||||||
|
|
||||||
TabInfo(
|
TabInfo(
|
||||||
@ -38,6 +39,7 @@ class TabInfo {
|
|||||||
this.unselectedIcon,
|
this.unselectedIcon,
|
||||||
this.closable = true,
|
this.closable = true,
|
||||||
this.onTabCloseButton,
|
this.onTabCloseButton,
|
||||||
|
this.onTap,
|
||||||
required this.page});
|
required this.page});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +58,8 @@ class DesktopTabState {
|
|||||||
final PageController pageController = PageController();
|
final PageController pageController = PageController();
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
|
|
||||||
|
TabInfo get selectedTabInfo => tabs[selected];
|
||||||
|
|
||||||
DesktopTabState() {
|
DesktopTabState() {
|
||||||
scrollController.itemCount = tabs.length;
|
scrollController.itemCount = tabs.length;
|
||||||
}
|
}
|
||||||
@ -173,7 +177,6 @@ typedef LabelGetter = Rx<String> Function(String key);
|
|||||||
int _lastClickTime = DateTime.now().millisecondsSinceEpoch;
|
int _lastClickTime = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
|
||||||
class DesktopTab extends StatelessWidget {
|
class DesktopTab extends StatelessWidget {
|
||||||
final Function(String)? onTabClose;
|
|
||||||
final bool showTabBar;
|
final bool showTabBar;
|
||||||
final bool showLogo;
|
final bool showLogo;
|
||||||
final bool showTitle;
|
final bool showTitle;
|
||||||
@ -201,7 +204,6 @@ class DesktopTab extends StatelessWidget {
|
|||||||
DesktopTab({
|
DesktopTab({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
this.onTabClose,
|
|
||||||
this.showTabBar = true,
|
this.showTabBar = true,
|
||||||
this.showLogo = true,
|
this.showLogo = true,
|
||||||
this.showTitle = true,
|
this.showTitle = true,
|
||||||
@ -357,7 +359,6 @@ class DesktopTab extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
child: _ListView(
|
child: _ListView(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
onTabClose: onTabClose,
|
|
||||||
tabBuilder: tabBuilder,
|
tabBuilder: tabBuilder,
|
||||||
labelGetter: labelGetter,
|
labelGetter: labelGetter,
|
||||||
maxLabelWidth: maxLabelWidth,
|
maxLabelWidth: maxLabelWidth,
|
||||||
@ -613,7 +614,6 @@ Future<bool> closeConfirmDialog() async {
|
|||||||
|
|
||||||
class _ListView extends StatelessWidget {
|
class _ListView extends StatelessWidget {
|
||||||
final DesktopTabController controller;
|
final DesktopTabController controller;
|
||||||
final Function(String key)? onTabClose;
|
|
||||||
|
|
||||||
final TabBuilder? tabBuilder;
|
final TabBuilder? tabBuilder;
|
||||||
final LabelGetter? labelGetter;
|
final LabelGetter? labelGetter;
|
||||||
@ -625,7 +625,6 @@ class _ListView extends StatelessWidget {
|
|||||||
|
|
||||||
const _ListView(
|
const _ListView(
|
||||||
{required this.controller,
|
{required this.controller,
|
||||||
required this.onTabClose,
|
|
||||||
this.tabBuilder,
|
this.tabBuilder,
|
||||||
this.labelGetter,
|
this.labelGetter,
|
||||||
this.maxLabelWidth,
|
this.maxLabelWidth,
|
||||||
@ -654,7 +653,9 @@ class _ListView extends StatelessWidget {
|
|||||||
final index = e.key;
|
final index = e.key;
|
||||||
final tab = e.value;
|
final tab = e.value;
|
||||||
return _Tab(
|
return _Tab(
|
||||||
|
key: ValueKey(tab.key),
|
||||||
index: index,
|
index: index,
|
||||||
|
tabInfoKey: tab.key,
|
||||||
label: labelGetter == null
|
label: labelGetter == null
|
||||||
? Rx<String>(tab.label)
|
? Rx<String>(tab.label)
|
||||||
: labelGetter!(tab.label),
|
: labelGetter!(tab.label),
|
||||||
@ -669,18 +670,11 @@ class _ListView extends StatelessWidget {
|
|||||||
controller.remove(index);
|
controller.remove(index);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSelected: () => controller.jumpTo(index),
|
onTap: () {
|
||||||
tabBuilder: tabBuilder == null
|
controller.jumpTo(index);
|
||||||
? null
|
tab.onTap?.call();
|
||||||
: (String key, Widget icon, Widget labelWidget,
|
},
|
||||||
TabThemeConf themeConf) {
|
tabBuilder: tabBuilder,
|
||||||
return tabBuilder!(
|
|
||||||
tab.label,
|
|
||||||
icon,
|
|
||||||
labelWidget,
|
|
||||||
themeConf,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
maxLabelWidth: maxLabelWidth,
|
maxLabelWidth: maxLabelWidth,
|
||||||
selectedTabBackgroundColor: selectedTabBackgroundColor,
|
selectedTabBackgroundColor: selectedTabBackgroundColor,
|
||||||
unSelectedTabBackgroundColor: unSelectedTabBackgroundColor,
|
unSelectedTabBackgroundColor: unSelectedTabBackgroundColor,
|
||||||
@ -691,13 +685,14 @@ class _ListView extends StatelessWidget {
|
|||||||
|
|
||||||
class _Tab extends StatefulWidget {
|
class _Tab extends StatefulWidget {
|
||||||
final int index;
|
final int index;
|
||||||
|
final String tabInfoKey;
|
||||||
final Rx<String> label;
|
final Rx<String> label;
|
||||||
final IconData? selectedIcon;
|
final IconData? selectedIcon;
|
||||||
final IconData? unselectedIcon;
|
final IconData? unselectedIcon;
|
||||||
final bool closable;
|
final bool closable;
|
||||||
final int selected;
|
final int selected;
|
||||||
final Function() onClose;
|
final Function() onClose;
|
||||||
final Function() onSelected;
|
final Function() onTap;
|
||||||
final TabBuilder? tabBuilder;
|
final TabBuilder? tabBuilder;
|
||||||
final double? maxLabelWidth;
|
final double? maxLabelWidth;
|
||||||
final Color? selectedTabBackgroundColor;
|
final Color? selectedTabBackgroundColor;
|
||||||
@ -706,6 +701,7 @@ class _Tab extends StatefulWidget {
|
|||||||
const _Tab({
|
const _Tab({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.index,
|
required this.index,
|
||||||
|
required this.tabInfoKey,
|
||||||
required this.label,
|
required this.label,
|
||||||
this.selectedIcon,
|
this.selectedIcon,
|
||||||
this.unselectedIcon,
|
this.unselectedIcon,
|
||||||
@ -713,7 +709,7 @@ class _Tab extends StatefulWidget {
|
|||||||
required this.closable,
|
required this.closable,
|
||||||
required this.selected,
|
required this.selected,
|
||||||
required this.onClose,
|
required this.onClose,
|
||||||
required this.onSelected,
|
required this.onTap,
|
||||||
this.maxLabelWidth,
|
this.maxLabelWidth,
|
||||||
this.selectedTabBackgroundColor,
|
this.selectedTabBackgroundColor,
|
||||||
this.unSelectedTabBackgroundColor,
|
this.unSelectedTabBackgroundColor,
|
||||||
@ -763,7 +759,7 @@ class _TabState extends State<_Tab> with RestorationMixin {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return widget.tabBuilder!(widget.label.value, icon, labelWidget,
|
return widget.tabBuilder!(widget.tabInfoKey, icon, labelWidget,
|
||||||
TabThemeConf(iconSize: _kIconSize));
|
TabThemeConf(iconSize: _kIconSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -780,7 +776,7 @@ class _TabState extends State<_Tab> with RestorationMixin {
|
|||||||
hover.value = value;
|
hover.value = value;
|
||||||
restoreHover.value = value;
|
restoreHover.value = value;
|
||||||
},
|
},
|
||||||
onTap: () => widget.onSelected(),
|
onTap: () => widget.onTap(),
|
||||||
child: Container(
|
child: Container(
|
||||||
color: isSelected
|
color: isSelected
|
||||||
? widget.selectedTabBackgroundColor
|
? widget.selectedTabBackgroundColor
|
||||||
|
@ -14,11 +14,11 @@ class MessageBody {
|
|||||||
MessageBody(this.chatUser, this.chatMessages);
|
MessageBody(this.chatUser, this.chatMessages);
|
||||||
|
|
||||||
void insert(ChatMessage cm) {
|
void insert(ChatMessage cm) {
|
||||||
this.chatMessages.insert(0, cm);
|
chatMessages.insert(0, cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
this.chatMessages.clear();
|
chatMessages.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +54,8 @@ class ChatModel with ChangeNotifier {
|
|||||||
|
|
||||||
ChatModel(this.parent);
|
ChatModel(this.parent);
|
||||||
|
|
||||||
|
FocusNode inputNode = FocusNode();
|
||||||
|
|
||||||
ChatUser get currentUser {
|
ChatUser get currentUser {
|
||||||
final user = messages[currentID]?.chatUser;
|
final user = messages[currentID]?.chatUser;
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@ -199,6 +201,11 @@ class ChatModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
receive(int id, String text) async {
|
receive(int id, String text) async {
|
||||||
|
final session = parent.target;
|
||||||
|
if (session == null) {
|
||||||
|
debugPrint("Failed to receive msg, session state is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (text.isEmpty) return;
|
if (text.isEmpty) return;
|
||||||
// mobile: first message show overlay icon
|
// mobile: first message show overlay icon
|
||||||
if (chatIconOverlayEntry == null) {
|
if (chatIconOverlayEntry == null) {
|
||||||
@ -208,27 +215,32 @@ class ChatModel with ChangeNotifier {
|
|||||||
if (!_isShowChatPage) {
|
if (!_isShowChatPage) {
|
||||||
toggleCMChatPage(id);
|
toggleCMChatPage(id);
|
||||||
}
|
}
|
||||||
parent.target?.serverModel.jumpTo(id);
|
|
||||||
|
|
||||||
late final chatUser;
|
int toId = currentID;
|
||||||
|
|
||||||
|
late final ChatUser chatUser;
|
||||||
if (id == clientModeID) {
|
if (id == clientModeID) {
|
||||||
chatUser = ChatUser(
|
chatUser = ChatUser(
|
||||||
firstName: parent.target?.ffiModel.pi.username,
|
firstName: session.ffiModel.pi.username,
|
||||||
id: await bind.mainGetLastRemoteId(),
|
id: session.id,
|
||||||
);
|
);
|
||||||
|
toId = id;
|
||||||
} else {
|
} else {
|
||||||
final client = parent.target?.serverModel.clients
|
final client =
|
||||||
.firstWhere((client) => client.id == id);
|
session.serverModel.clients.firstWhere((client) => client.id == id);
|
||||||
if (client == null) {
|
|
||||||
return debugPrint("Failed to receive msg,user doesn't exist");
|
|
||||||
}
|
|
||||||
if (isDesktop) {
|
if (isDesktop) {
|
||||||
window_on_top(null);
|
window_on_top(null);
|
||||||
var index = parent.target?.serverModel.clients
|
// disable auto jumpTo other tab when hasFocus, and mark unread message
|
||||||
.indexWhere((client) => client.id == id);
|
final currentSelectedTab =
|
||||||
if (index != null && index >= 0) {
|
session.serverModel.tabController.state.value.selectedTabInfo;
|
||||||
gFFI.serverModel.tabController.jumpTo(index);
|
if (currentSelectedTab.key != id.toString() && inputNode.hasFocus) {
|
||||||
|
client.hasUnreadChatMessage.value = true;
|
||||||
|
} else {
|
||||||
|
parent.target?.serverModel.jumpTo(id);
|
||||||
|
toId = id;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
toId = id;
|
||||||
}
|
}
|
||||||
chatUser = ChatUser(id: client.peerId, firstName: client.name);
|
chatUser = ChatUser(id: client.peerId, firstName: client.name);
|
||||||
}
|
}
|
||||||
@ -238,7 +250,7 @@ class ChatModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
_messages[id]!.insert(
|
_messages[id]!.insert(
|
||||||
ChatMessage(text: text, user: chatUser, createdAt: DateTime.now()));
|
ChatMessage(text: text, user: chatUser, createdAt: DateTime.now()));
|
||||||
_currentID = id;
|
_currentID = toId;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/models/platform_model.dart';
|
import 'package:flutter_hbb/models/platform_model.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
import 'package:wakelock/wakelock.dart';
|
import 'package:wakelock/wakelock.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
@ -402,6 +403,15 @@ class ServerModel with ChangeNotifier {
|
|||||||
key: client.id.toString(),
|
key: client.id.toString(),
|
||||||
label: client.name,
|
label: client.name,
|
||||||
closable: false,
|
closable: false,
|
||||||
|
onTap: () {
|
||||||
|
if (client.hasUnreadChatMessage.value) {
|
||||||
|
client.hasUnreadChatMessage.value = false;
|
||||||
|
final chatModel = parent.target!.chatModel;
|
||||||
|
if (!chatModel.isShowChatPage) {
|
||||||
|
chatModel.toggleCMChatPage(client.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
page: Desktop.buildConnectionCard(client)));
|
page: Desktop.buildConnectionCard(client)));
|
||||||
Future.delayed(Duration.zero, () async {
|
Future.delayed(Duration.zero, () async {
|
||||||
window_on_top(null);
|
window_on_top(null);
|
||||||
@ -538,6 +548,8 @@ class Client {
|
|||||||
bool recording = false;
|
bool recording = false;
|
||||||
bool disconnected = false;
|
bool disconnected = false;
|
||||||
|
|
||||||
|
RxBool hasUnreadChatMessage = false.obs;
|
||||||
|
|
||||||
Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId,
|
Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId,
|
||||||
this.keyboard, this.clipboard, this.audio);
|
this.keyboard, this.clipboard, this.audio);
|
||||||
|
|
||||||
@ -557,7 +569,7 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
data['id'] = id;
|
data['id'] = id;
|
||||||
data['is_start'] = authorized;
|
data['is_start'] = authorized;
|
||||||
data['is_file_transfer'] = isFileTransfer;
|
data['is_file_transfer'] = isFileTransfer;
|
||||||
|
@ -26,13 +26,11 @@ void main(List<String> args) async {
|
|||||||
await initEnv(kAppTypeMain);
|
await initEnv(kAppTypeMain);
|
||||||
for (var client in testClients) {
|
for (var client in testClients) {
|
||||||
gFFI.serverModel.clients.add(client);
|
gFFI.serverModel.clients.add(client);
|
||||||
gFFI.serverModel.tabController.add(
|
gFFI.serverModel.tabController.add(TabInfo(
|
||||||
TabInfo(
|
key: client.id.toString(),
|
||||||
key: client.id.toString(),
|
label: client.name,
|
||||||
label: client.name,
|
closable: false,
|
||||||
closable: false,
|
page: buildConnectionCard(client)));
|
||||||
page: buildConnectionCard(client)),
|
|
||||||
authorized: client.authorized);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runApp(GetMaterialApp(
|
runApp(GetMaterialApp(
|
||||||
|
Loading…
Reference in New Issue
Block a user