mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-19 00:13:01 +08:00
Merge pull request #1831 from Heap-Hop/feat/cm_chat_page_unread_msg
feat: desktop cm chat page unread msg
This commit is contained in:
commit
b9a5514b7b
@ -4,7 +4,7 @@ import 'package:flutter_hbb/common.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'home_page.dart';
|
||||
import '../../mobile/pages/home_page.dart';
|
||||
|
||||
class ChatPage extends StatelessWidget implements PageShape {
|
||||
late final ChatModel chatModel;
|
||||
@ -61,6 +61,7 @@ class ChatPage extends StatelessWidget implements PageShape {
|
||||
[],
|
||||
inputOptions: InputOptions(
|
||||
sendOnEnter: true,
|
||||
focusNode: chatModel.inputNode,
|
||||
inputTextStyle: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context)
|
||||
@ -94,6 +95,8 @@ class ChatPage extends StatelessWidget implements PageShape {
|
||||
messageOptions: MessageOptions(
|
||||
showOtherUsersAvatar: false,
|
||||
showTime: true,
|
||||
currentUserTextColor: Colors.white,
|
||||
textColor: Colors.white,
|
||||
maxWidth: constraints.maxWidth * 0.7,
|
||||
messageDecorationBuilder: (_, __, ___) =>
|
||||
defaultMessageDecoration(
|
@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../consts.dart';
|
||||
import '../../desktop/widgets/tabbar_widget.dart';
|
||||
import '../../mobile/pages/chat_page.dart';
|
||||
import '../../models/chat_model.dart';
|
||||
import '../../models/model.dart';
|
||||
import 'chat_page.dart';
|
||||
|
||||
class DraggableChatWindow extends StatelessWidget {
|
||||
const DraggableChatWindow(
|
||||
@ -173,17 +174,17 @@ class DraggableMobileActions extends StatelessWidget {
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
onPressed: onBackPressed,
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.arrow_back)),
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
onPressed: onHomePressed,
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.home)),
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
onPressed: onRecentPressed,
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.more_horiz)),
|
||||
const VerticalDivider(
|
||||
width: 0,
|
||||
@ -194,7 +195,7 @@ class DraggableMobileActions extends StatelessWidget {
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
onPressed: onHidePressed,
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.keyboard_arrow_down)),
|
||||
],
|
||||
),
|
||||
|
@ -39,6 +39,7 @@ const Size kConnectionManagerWindowSize = Size(300, 400);
|
||||
// Tabbar transition duration, now we remove the duration
|
||||
const Duration kTabTransitionDuration = Duration.zero;
|
||||
const double kEmptyMarginTop = 50;
|
||||
const double kDesktopIconButtonSplashRadius = 20;
|
||||
|
||||
/// [kDefaultScrollAmountMultiplier] indicates how many rows can be scrolled after a minimum scroll action of mouse
|
||||
const kDefaultScrollAmountMultiplier = 5.0;
|
||||
|
@ -175,7 +175,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
},
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
onPressed: () => mod_menu.showMenu(
|
||||
context: context,
|
||||
position: menuPos,
|
||||
@ -482,12 +482,12 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
onPressed: () {
|
||||
model.resumeJob(item.id);
|
||||
},
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.restart_alt_rounded)),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_forever_outlined),
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
onPressed: () {
|
||||
model.jobTable.removeAt(index);
|
||||
model.cancelJob(item.id);
|
||||
@ -556,7 +556,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
onPressed: () {
|
||||
selectedItems.clear();
|
||||
model.goBack(isLocal: isLocal);
|
||||
@ -564,7 +564,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_upward),
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
onPressed: () {
|
||||
selectedItems.clear();
|
||||
model.goToParentDirectory(isLocal: isLocal);
|
||||
@ -614,13 +614,13 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
Future.delayed(
|
||||
Duration.zero, () => focusNode.requestFocus());
|
||||
},
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: Icon(Icons.search));
|
||||
case LocationStatus.pathLocation:
|
||||
return IconButton(
|
||||
color: Theme.of(context).disabledColor,
|
||||
onPressed: null,
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: Icon(Icons.close));
|
||||
case LocationStatus.fileSearchBar:
|
||||
return IconButton(
|
||||
@ -638,7 +638,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
breadCrumbScrollToEnd(isLocal);
|
||||
model.refresh(isLocal: isLocal);
|
||||
},
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.refresh)),
|
||||
],
|
||||
),
|
||||
@ -655,7 +655,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
model.goHome(isLocal: isLocal);
|
||||
},
|
||||
icon: const Icon(Icons.home_outlined),
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
@ -704,7 +704,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
);
|
||||
});
|
||||
},
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.create_new_folder_outlined)),
|
||||
IconButton(
|
||||
onPressed: validItems(selectedItems)
|
||||
@ -714,7 +714,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
selectedItems.clear();
|
||||
}
|
||||
: null,
|
||||
splashRadius: 20,
|
||||
splashRadius: kDesktopIconButtonSplashRadius,
|
||||
icon: const Icon(Icons.delete_forever_outlined)),
|
||||
menu(isLocal: isLocal),
|
||||
],
|
||||
|
@ -5,7 +5,6 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
|
||||
import 'package:flutter_hbb/mobile/pages/chat_page.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -13,6 +12,7 @@ import 'package:window_manager/window_manager.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../common/widgets/chat_page.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
import '../../models/server_model.dart';
|
||||
|
||||
@ -107,6 +107,13 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serverModel = Provider.of<ServerModel>(context);
|
||||
final pointerHandler = serverModel.cmHiddenTimer != null
|
||||
? (PointerEvent e) {
|
||||
serverModel.cmHiddenTimer!.cancel();
|
||||
serverModel.cmHiddenTimer = null;
|
||||
debugPrint("CM hidden timer has been canceled");
|
||||
}
|
||||
: null;
|
||||
return serverModel.clients.isEmpty
|
||||
? Column(
|
||||
children: [
|
||||
@ -118,35 +125,44 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
||||
),
|
||||
],
|
||||
)
|
||||
: DesktopTab(
|
||||
showTitle: false,
|
||||
showMaximize: false,
|
||||
showMinimize: true,
|
||||
showClose: true,
|
||||
controller: serverModel.tabController,
|
||||
maxLabelWidth: 100,
|
||||
tail: buildScrollJumper(),
|
||||
selectedTabBackgroundColor:
|
||||
Theme.of(context).hintColor.withOpacity(0.2),
|
||||
tabBuilder: (key, icon, label, themeConf) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
icon,
|
||||
Tooltip(
|
||||
message: key,
|
||||
waitDuration: Duration(seconds: 1),
|
||||
child: label),
|
||||
],
|
||||
);
|
||||
},
|
||||
pageViewBuilder: (pageView) => Row(children: [
|
||||
Expanded(child: pageView),
|
||||
Consumer<ChatModel>(
|
||||
builder: (_, model, child) => model.isShowChatPage
|
||||
? Expanded(child: Scaffold(body: ChatPage()))
|
||||
: Offstage())
|
||||
]));
|
||||
: Listener(
|
||||
onPointerDown: pointerHandler,
|
||||
onPointerMove: pointerHandler,
|
||||
child: DesktopTab(
|
||||
showTitle: false,
|
||||
showMaximize: false,
|
||||
showMinimize: true,
|
||||
showClose: true,
|
||||
controller: serverModel.tabController,
|
||||
maxLabelWidth: 100,
|
||||
tail: buildScrollJumper(),
|
||||
selectedTabBackgroundColor:
|
||||
Theme.of(context).hintColor.withOpacity(0.2),
|
||||
tabBuilder: (key, icon, label, themeConf) {
|
||||
final client = serverModel.clients.firstWhereOrNull(
|
||||
(client) => client.id.toString() == key);
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Tooltip(
|
||||
message: key,
|
||||
waitDuration: Duration(seconds: 1),
|
||||
child: label),
|
||||
Obx(() => Offstage(
|
||||
offstage:
|
||||
!(client?.hasUnreadChatMessage.value ?? false),
|
||||
child:
|
||||
Icon(Icons.circle, color: Colors.red, size: 10)))
|
||||
],
|
||||
);
|
||||
},
|
||||
pageViewBuilder: (pageView) => Row(children: [
|
||||
Expanded(child: pageView),
|
||||
Consumer<ChatModel>(
|
||||
builder: (_, model, child) => model.isShowChatPage
|
||||
? Expanded(child: Scaffold(body: ChatPage()))
|
||||
: Offstage())
|
||||
])));
|
||||
}
|
||||
|
||||
Widget buildTitleBar() {
|
||||
@ -334,10 +350,10 @@ class _CmHeaderState extends State<_CmHeader>
|
||||
Offstage(
|
||||
offstage: !client.authorized || client.isFileTransfer,
|
||||
child: IconButton(
|
||||
onPressed: () => checkClickTime(
|
||||
client.id, () => gFFI.chatModel.toggleCMChatPage(client.id)),
|
||||
icon: Icon(Icons.message_outlined),
|
||||
),
|
||||
onPressed: () => checkClickTime(
|
||||
client.id, () => gFFI.chatModel.toggleCMChatPage(client.id)),
|
||||
icon: Icon(Icons.message_outlined),
|
||||
splashRadius: kDesktopIconButtonSplashRadius),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
@ -29,6 +29,7 @@ class TabInfo {
|
||||
final IconData? unselectedIcon;
|
||||
final bool closable;
|
||||
final VoidCallback? onTabCloseButton;
|
||||
final VoidCallback? onTap;
|
||||
final Widget page;
|
||||
|
||||
TabInfo(
|
||||
@ -38,6 +39,7 @@ class TabInfo {
|
||||
this.unselectedIcon,
|
||||
this.closable = true,
|
||||
this.onTabCloseButton,
|
||||
this.onTap,
|
||||
required this.page});
|
||||
}
|
||||
|
||||
@ -56,6 +58,8 @@ class DesktopTabState {
|
||||
final PageController pageController = PageController();
|
||||
int selected = 0;
|
||||
|
||||
TabInfo get selectedTabInfo => tabs[selected];
|
||||
|
||||
DesktopTabState() {
|
||||
scrollController.itemCount = tabs.length;
|
||||
}
|
||||
@ -73,7 +77,7 @@ class DesktopTabController {
|
||||
|
||||
int get length => state.value.tabs.length;
|
||||
|
||||
void add(TabInfo tab, {bool authorized = false}) {
|
||||
void add(TabInfo tab) {
|
||||
if (!isDesktop) return;
|
||||
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
||||
int toIndex;
|
||||
@ -87,16 +91,6 @@ 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) {
|
||||
@ -127,12 +121,12 @@ class DesktopTabController {
|
||||
if (!isDesktop || index < 0) return;
|
||||
state.update((val) {
|
||||
val!.selected = index;
|
||||
Future.delayed(Duration.zero, (() {
|
||||
Future.delayed(Duration(milliseconds: 100), (() {
|
||||
if (val.pageController.hasClients) {
|
||||
val.pageController.jumpToPage(index);
|
||||
}
|
||||
val.scrollController.itemCount = val.tabs.length;
|
||||
if (val.scrollController.hasClients &&
|
||||
val.scrollController.canScroll &&
|
||||
val.scrollController.itemCount > index) {
|
||||
val.scrollController
|
||||
.scrollToItem(index, center: false, animate: true);
|
||||
@ -183,7 +177,6 @@ typedef LabelGetter = Rx<String> Function(String key);
|
||||
int _lastClickTime = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
class DesktopTab extends StatelessWidget {
|
||||
final Function(String)? onTabClose;
|
||||
final bool showTabBar;
|
||||
final bool showLogo;
|
||||
final bool showTitle;
|
||||
@ -211,7 +204,6 @@ class DesktopTab extends StatelessWidget {
|
||||
DesktopTab({
|
||||
Key? key,
|
||||
required this.controller,
|
||||
this.onTabClose,
|
||||
this.showTabBar = true,
|
||||
this.showLogo = true,
|
||||
this.showTitle = true,
|
||||
@ -367,7 +359,6 @@ class DesktopTab extends StatelessWidget {
|
||||
},
|
||||
child: _ListView(
|
||||
controller: controller,
|
||||
onTabClose: onTabClose,
|
||||
tabBuilder: tabBuilder,
|
||||
labelGetter: labelGetter,
|
||||
maxLabelWidth: maxLabelWidth,
|
||||
@ -623,7 +614,6 @@ Future<bool> closeConfirmDialog() async {
|
||||
|
||||
class _ListView extends StatelessWidget {
|
||||
final DesktopTabController controller;
|
||||
final Function(String key)? onTabClose;
|
||||
|
||||
final TabBuilder? tabBuilder;
|
||||
final LabelGetter? labelGetter;
|
||||
@ -635,7 +625,6 @@ class _ListView extends StatelessWidget {
|
||||
|
||||
const _ListView(
|
||||
{required this.controller,
|
||||
required this.onTabClose,
|
||||
this.tabBuilder,
|
||||
this.labelGetter,
|
||||
this.maxLabelWidth,
|
||||
@ -664,7 +653,9 @@ class _ListView extends StatelessWidget {
|
||||
final index = e.key;
|
||||
final tab = e.value;
|
||||
return _Tab(
|
||||
key: ValueKey(tab.key),
|
||||
index: index,
|
||||
tabInfoKey: tab.key,
|
||||
label: labelGetter == null
|
||||
? Rx<String>(tab.label)
|
||||
: labelGetter!(tab.label),
|
||||
@ -679,18 +670,11 @@ class _ListView extends StatelessWidget {
|
||||
controller.remove(index);
|
||||
}
|
||||
},
|
||||
onSelected: () => controller.jumpTo(index),
|
||||
tabBuilder: tabBuilder == null
|
||||
? null
|
||||
: (String key, Widget icon, Widget labelWidget,
|
||||
TabThemeConf themeConf) {
|
||||
return tabBuilder!(
|
||||
tab.label,
|
||||
icon,
|
||||
labelWidget,
|
||||
themeConf,
|
||||
);
|
||||
},
|
||||
onTap: () {
|
||||
controller.jumpTo(index);
|
||||
tab.onTap?.call();
|
||||
},
|
||||
tabBuilder: tabBuilder,
|
||||
maxLabelWidth: maxLabelWidth,
|
||||
selectedTabBackgroundColor: selectedTabBackgroundColor,
|
||||
unSelectedTabBackgroundColor: unSelectedTabBackgroundColor,
|
||||
@ -701,13 +685,14 @@ class _ListView extends StatelessWidget {
|
||||
|
||||
class _Tab extends StatefulWidget {
|
||||
final int index;
|
||||
final String tabInfoKey;
|
||||
final Rx<String> label;
|
||||
final IconData? selectedIcon;
|
||||
final IconData? unselectedIcon;
|
||||
final bool closable;
|
||||
final int selected;
|
||||
final Function() onClose;
|
||||
final Function() onSelected;
|
||||
final Function() onTap;
|
||||
final TabBuilder? tabBuilder;
|
||||
final double? maxLabelWidth;
|
||||
final Color? selectedTabBackgroundColor;
|
||||
@ -716,6 +701,7 @@ class _Tab extends StatefulWidget {
|
||||
const _Tab({
|
||||
Key? key,
|
||||
required this.index,
|
||||
required this.tabInfoKey,
|
||||
required this.label,
|
||||
this.selectedIcon,
|
||||
this.unselectedIcon,
|
||||
@ -723,7 +709,7 @@ class _Tab extends StatefulWidget {
|
||||
required this.closable,
|
||||
required this.selected,
|
||||
required this.onClose,
|
||||
required this.onSelected,
|
||||
required this.onTap,
|
||||
this.maxLabelWidth,
|
||||
this.selectedTabBackgroundColor,
|
||||
this.unSelectedTabBackgroundColor,
|
||||
@ -773,7 +759,7 @@ class _TabState extends State<_Tab> with RestorationMixin {
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return widget.tabBuilder!(widget.label.value, icon, labelWidget,
|
||||
return widget.tabBuilder!(widget.tabInfoKey, icon, labelWidget,
|
||||
TabThemeConf(iconSize: _kIconSize));
|
||||
}
|
||||
}
|
||||
@ -790,7 +776,7 @@ class _TabState extends State<_Tab> with RestorationMixin {
|
||||
hover.value = value;
|
||||
restoreHover.value = value;
|
||||
},
|
||||
onTap: () => widget.onSelected(),
|
||||
onTap: () => widget.onTap(),
|
||||
child: Container(
|
||||
color: isSelected
|
||||
? widget.selectedTabBackgroundColor
|
||||
|
@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/mobile/pages/chat_page.dart';
|
||||
import 'package:flutter_hbb/mobile/pages/server_page.dart';
|
||||
import 'package:flutter_hbb/mobile/pages/settings_page.dart';
|
||||
import '../../common.dart';
|
||||
import '../../common/widgets/chat_page.dart';
|
||||
import 'connection_page.dart';
|
||||
|
||||
abstract class PageShape extends Widget {
|
||||
|
@ -14,11 +14,11 @@ class MessageBody {
|
||||
MessageBody(this.chatUser, this.chatMessages);
|
||||
|
||||
void insert(ChatMessage cm) {
|
||||
this.chatMessages.insert(0, cm);
|
||||
chatMessages.insert(0, cm);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
this.chatMessages.clear();
|
||||
chatMessages.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,8 @@ class ChatModel with ChangeNotifier {
|
||||
|
||||
ChatModel(this.parent);
|
||||
|
||||
FocusNode inputNode = FocusNode();
|
||||
|
||||
ChatUser get currentUser {
|
||||
final user = messages[currentID]?.chatUser;
|
||||
if (user == null) {
|
||||
@ -108,6 +110,7 @@ class ChatModel with ChangeNotifier {
|
||||
hideChatWindowOverlay();
|
||||
}
|
||||
},
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
child: Icon(Icons.message)));
|
||||
});
|
||||
overlayState.insert(overlay);
|
||||
@ -198,6 +201,11 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
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;
|
||||
// mobile: first message show overlay icon
|
||||
if (chatIconOverlayEntry == null) {
|
||||
@ -207,27 +215,32 @@ class ChatModel with ChangeNotifier {
|
||||
if (!_isShowChatPage) {
|
||||
toggleCMChatPage(id);
|
||||
}
|
||||
parent.target?.serverModel.jumpTo(id);
|
||||
|
||||
late final chatUser;
|
||||
int toId = currentID;
|
||||
|
||||
late final ChatUser chatUser;
|
||||
if (id == clientModeID) {
|
||||
chatUser = ChatUser(
|
||||
firstName: parent.target?.ffiModel.pi.username,
|
||||
id: await bind.mainGetLastRemoteId(),
|
||||
firstName: session.ffiModel.pi.username,
|
||||
id: session.id,
|
||||
);
|
||||
toId = id;
|
||||
} else {
|
||||
final client = parent.target?.serverModel.clients
|
||||
.firstWhere((client) => client.id == id);
|
||||
if (client == null) {
|
||||
return debugPrint("Failed to receive msg,user doesn't exist");
|
||||
}
|
||||
final client =
|
||||
session.serverModel.clients.firstWhere((client) => client.id == id);
|
||||
if (isDesktop) {
|
||||
window_on_top(null);
|
||||
var index = parent.target?.serverModel.clients
|
||||
.indexWhere((client) => client.id == id);
|
||||
if (index != null && index >= 0) {
|
||||
gFFI.serverModel.tabController.jumpTo(index);
|
||||
// disable auto jumpTo other tab when hasFocus, and mark unread message
|
||||
final currentSelectedTab =
|
||||
session.serverModel.tabController.state.value.selectedTabInfo;
|
||||
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);
|
||||
}
|
||||
@ -237,7 +250,7 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
_messages[id]!.insert(
|
||||
ChatMessage(text: text, user: chatUser, createdAt: DateTime.now()));
|
||||
_currentID = id;
|
||||
_currentID = toId;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,9 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:wakelock/wakelock.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../common.dart';
|
||||
import '../common/formatter/id_formatter.dart';
|
||||
@ -37,6 +39,8 @@ class ServerModel with ChangeNotifier {
|
||||
|
||||
final List<Client> _clients = [];
|
||||
|
||||
Timer? cmHiddenTimer;
|
||||
|
||||
bool get isStart => _isStart;
|
||||
|
||||
bool get mediaOk => _mediaOk;
|
||||
@ -353,13 +357,7 @@ class ServerModel with ChangeNotifier {
|
||||
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)),
|
||||
authorized: client.authorized);
|
||||
_addTab(client);
|
||||
}
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
@ -384,13 +382,7 @@ class ServerModel with ChangeNotifier {
|
||||
}
|
||||
_clients.add(client);
|
||||
}
|
||||
tabController.add(
|
||||
TabInfo(
|
||||
key: client.id.toString(),
|
||||
label: client.name,
|
||||
closable: false,
|
||||
page: Desktop.buildConnectionCard(client)),
|
||||
authorized: client.authorized);
|
||||
_addTab(client);
|
||||
// remove disconnected
|
||||
final index_disconnected = _clients
|
||||
.indexWhere((c) => c.disconnected && c.peerId == client.peerId);
|
||||
@ -406,6 +398,32 @@ class ServerModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void _addTab(Client client) {
|
||||
tabController.add(TabInfo(
|
||||
key: client.id.toString(),
|
||||
label: client.name,
|
||||
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)));
|
||||
Future.delayed(Duration.zero, () async {
|
||||
window_on_top(null);
|
||||
});
|
||||
if (client.authorized) {
|
||||
cmHiddenTimer = Timer(const Duration(seconds: 3), () {
|
||||
windowManager.minimize();
|
||||
cmHiddenTimer = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void showLoginDialog(Client client) {
|
||||
parent.target?.dialogManager.show((setState, close) {
|
||||
cancel() {
|
||||
@ -530,6 +548,8 @@ class Client {
|
||||
bool recording = false;
|
||||
bool disconnected = false;
|
||||
|
||||
RxBool hasUnreadChatMessage = false.obs;
|
||||
|
||||
Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId,
|
||||
this.keyboard, this.clipboard, this.audio);
|
||||
|
||||
@ -549,7 +569,7 @@ class Client {
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['id'] = id;
|
||||
data['is_start'] = authorized;
|
||||
data['is_file_transfer'] = isFileTransfer;
|
||||
|
@ -26,13 +26,11 @@ void main(List<String> args) async {
|
||||
await initEnv(kAppTypeMain);
|
||||
for (var client in testClients) {
|
||||
gFFI.serverModel.clients.add(client);
|
||||
gFFI.serverModel.tabController.add(
|
||||
TabInfo(
|
||||
key: client.id.toString(),
|
||||
label: client.name,
|
||||
closable: false,
|
||||
page: buildConnectionCard(client)),
|
||||
authorized: client.authorized);
|
||||
gFFI.serverModel.tabController.add(TabInfo(
|
||||
key: client.id.toString(),
|
||||
label: client.name,
|
||||
closable: false,
|
||||
page: buildConnectionCard(client)));
|
||||
}
|
||||
|
||||
runApp(GetMaterialApp(
|
||||
|
Loading…
Reference in New Issue
Block a user