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:flutter_hbb/models/chat_model.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'home_page.dart';
|
import '../../mobile/pages/home_page.dart';
|
||||||
|
|
||||||
class ChatPage extends StatelessWidget implements PageShape {
|
class ChatPage extends StatelessWidget implements PageShape {
|
||||||
late final ChatModel chatModel;
|
late final ChatModel chatModel;
|
||||||
@ -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)
|
||||||
@ -94,6 +95,8 @@ class ChatPage extends StatelessWidget implements PageShape {
|
|||||||
messageOptions: MessageOptions(
|
messageOptions: MessageOptions(
|
||||||
showOtherUsersAvatar: false,
|
showOtherUsersAvatar: false,
|
||||||
showTime: true,
|
showTime: true,
|
||||||
|
currentUserTextColor: Colors.white,
|
||||||
|
textColor: Colors.white,
|
||||||
maxWidth: constraints.maxWidth * 0.7,
|
maxWidth: constraints.maxWidth * 0.7,
|
||||||
messageDecorationBuilder: (_, __, ___) =>
|
messageDecorationBuilder: (_, __, ___) =>
|
||||||
defaultMessageDecoration(
|
defaultMessageDecoration(
|
@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_hbb/common.dart';
|
import 'package:flutter_hbb/common.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../../consts.dart';
|
||||||
import '../../desktop/widgets/tabbar_widget.dart';
|
import '../../desktop/widgets/tabbar_widget.dart';
|
||||||
import '../../mobile/pages/chat_page.dart';
|
|
||||||
import '../../models/chat_model.dart';
|
import '../../models/chat_model.dart';
|
||||||
import '../../models/model.dart';
|
import '../../models/model.dart';
|
||||||
|
import 'chat_page.dart';
|
||||||
|
|
||||||
class DraggableChatWindow extends StatelessWidget {
|
class DraggableChatWindow extends StatelessWidget {
|
||||||
const DraggableChatWindow(
|
const DraggableChatWindow(
|
||||||
@ -173,17 +174,17 @@ class DraggableMobileActions extends StatelessWidget {
|
|||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
onPressed: onBackPressed,
|
onPressed: onBackPressed,
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.arrow_back)),
|
icon: const Icon(Icons.arrow_back)),
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
onPressed: onHomePressed,
|
onPressed: onHomePressed,
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.home)),
|
icon: const Icon(Icons.home)),
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
onPressed: onRecentPressed,
|
onPressed: onRecentPressed,
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.more_horiz)),
|
icon: const Icon(Icons.more_horiz)),
|
||||||
const VerticalDivider(
|
const VerticalDivider(
|
||||||
width: 0,
|
width: 0,
|
||||||
@ -194,7 +195,7 @@ class DraggableMobileActions extends StatelessWidget {
|
|||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
onPressed: onHidePressed,
|
onPressed: onHidePressed,
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.keyboard_arrow_down)),
|
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
|
// Tabbar transition duration, now we remove the duration
|
||||||
const Duration kTabTransitionDuration = Duration.zero;
|
const Duration kTabTransitionDuration = Duration.zero;
|
||||||
const double kEmptyMarginTop = 50;
|
const double kEmptyMarginTop = 50;
|
||||||
|
const double kDesktopIconButtonSplashRadius = 20;
|
||||||
|
|
||||||
/// [kDefaultScrollAmountMultiplier] indicates how many rows can be scrolled after a minimum scroll action of mouse
|
/// [kDefaultScrollAmountMultiplier] indicates how many rows can be scrolled after a minimum scroll action of mouse
|
||||||
const kDefaultScrollAmountMultiplier = 5.0;
|
const kDefaultScrollAmountMultiplier = 5.0;
|
||||||
|
@ -175,7 +175,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
},
|
},
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: const Icon(Icons.more_vert),
|
icon: const Icon(Icons.more_vert),
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
onPressed: () => mod_menu.showMenu(
|
onPressed: () => mod_menu.showMenu(
|
||||||
context: context,
|
context: context,
|
||||||
position: menuPos,
|
position: menuPos,
|
||||||
@ -482,12 +482,12 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
model.resumeJob(item.id);
|
model.resumeJob(item.id);
|
||||||
},
|
},
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.restart_alt_rounded)),
|
icon: const Icon(Icons.restart_alt_rounded)),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.delete_forever_outlined),
|
icon: const Icon(Icons.delete_forever_outlined),
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
model.jobTable.removeAt(index);
|
model.jobTable.removeAt(index);
|
||||||
model.cancelJob(item.id);
|
model.cancelJob(item.id);
|
||||||
@ -556,7 +556,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.arrow_back),
|
icon: const Icon(Icons.arrow_back),
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
selectedItems.clear();
|
selectedItems.clear();
|
||||||
model.goBack(isLocal: isLocal);
|
model.goBack(isLocal: isLocal);
|
||||||
@ -564,7 +564,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.arrow_upward),
|
icon: const Icon(Icons.arrow_upward),
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
selectedItems.clear();
|
selectedItems.clear();
|
||||||
model.goToParentDirectory(isLocal: isLocal);
|
model.goToParentDirectory(isLocal: isLocal);
|
||||||
@ -614,13 +614,13 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
Future.delayed(
|
Future.delayed(
|
||||||
Duration.zero, () => focusNode.requestFocus());
|
Duration.zero, () => focusNode.requestFocus());
|
||||||
},
|
},
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: Icon(Icons.search));
|
icon: Icon(Icons.search));
|
||||||
case LocationStatus.pathLocation:
|
case LocationStatus.pathLocation:
|
||||||
return IconButton(
|
return IconButton(
|
||||||
color: Theme.of(context).disabledColor,
|
color: Theme.of(context).disabledColor,
|
||||||
onPressed: null,
|
onPressed: null,
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: Icon(Icons.close));
|
icon: Icon(Icons.close));
|
||||||
case LocationStatus.fileSearchBar:
|
case LocationStatus.fileSearchBar:
|
||||||
return IconButton(
|
return IconButton(
|
||||||
@ -638,7 +638,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
breadCrumbScrollToEnd(isLocal);
|
breadCrumbScrollToEnd(isLocal);
|
||||||
model.refresh(isLocal: isLocal);
|
model.refresh(isLocal: isLocal);
|
||||||
},
|
},
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.refresh)),
|
icon: const Icon(Icons.refresh)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -655,7 +655,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
model.goHome(isLocal: isLocal);
|
model.goHome(isLocal: isLocal);
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.home_outlined),
|
icon: const Icon(Icons.home_outlined),
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -704,7 +704,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.create_new_folder_outlined)),
|
icon: const Icon(Icons.create_new_folder_outlined)),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: validItems(selectedItems)
|
onPressed: validItems(selectedItems)
|
||||||
@ -714,7 +714,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
selectedItems.clear();
|
selectedItems.clear();
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
splashRadius: 20,
|
splashRadius: kDesktopIconButtonSplashRadius,
|
||||||
icon: const Icon(Icons.delete_forever_outlined)),
|
icon: const Icon(Icons.delete_forever_outlined)),
|
||||||
menu(isLocal: isLocal),
|
menu(isLocal: isLocal),
|
||||||
],
|
],
|
||||||
|
@ -5,7 +5,6 @@ import 'dart:async';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/consts.dart';
|
import 'package:flutter_hbb/consts.dart';
|
||||||
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.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:flutter_hbb/models/chat_model.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:provider/provider.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 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
|
||||||
import '../../common.dart';
|
import '../../common.dart';
|
||||||
|
import '../../common/widgets/chat_page.dart';
|
||||||
import '../../models/platform_model.dart';
|
import '../../models/platform_model.dart';
|
||||||
import '../../models/server_model.dart';
|
import '../../models/server_model.dart';
|
||||||
|
|
||||||
@ -107,6 +107,13 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serverModel = Provider.of<ServerModel>(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
|
return serverModel.clients.isEmpty
|
||||||
? Column(
|
? Column(
|
||||||
children: [
|
children: [
|
||||||
@ -118,35 +125,44 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: DesktopTab(
|
: Listener(
|
||||||
showTitle: false,
|
onPointerDown: pointerHandler,
|
||||||
showMaximize: false,
|
onPointerMove: pointerHandler,
|
||||||
showMinimize: true,
|
child: DesktopTab(
|
||||||
showClose: true,
|
showTitle: false,
|
||||||
controller: serverModel.tabController,
|
showMaximize: false,
|
||||||
maxLabelWidth: 100,
|
showMinimize: true,
|
||||||
tail: buildScrollJumper(),
|
showClose: true,
|
||||||
selectedTabBackgroundColor:
|
controller: serverModel.tabController,
|
||||||
Theme.of(context).hintColor.withOpacity(0.2),
|
maxLabelWidth: 100,
|
||||||
tabBuilder: (key, icon, label, themeConf) {
|
tail: buildScrollJumper(),
|
||||||
return Row(
|
selectedTabBackgroundColor:
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
Theme.of(context).hintColor.withOpacity(0.2),
|
||||||
children: [
|
tabBuilder: (key, icon, label, themeConf) {
|
||||||
icon,
|
final client = serverModel.clients.firstWhereOrNull(
|
||||||
Tooltip(
|
(client) => client.id.toString() == key);
|
||||||
message: key,
|
return Row(
|
||||||
waitDuration: Duration(seconds: 1),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
child: label),
|
children: [
|
||||||
],
|
Tooltip(
|
||||||
);
|
message: key,
|
||||||
},
|
waitDuration: Duration(seconds: 1),
|
||||||
pageViewBuilder: (pageView) => Row(children: [
|
child: label),
|
||||||
Expanded(child: pageView),
|
Obx(() => Offstage(
|
||||||
Consumer<ChatModel>(
|
offstage:
|
||||||
builder: (_, model, child) => model.isShowChatPage
|
!(client?.hasUnreadChatMessage.value ?? false),
|
||||||
? Expanded(child: Scaffold(body: ChatPage()))
|
child:
|
||||||
: Offstage())
|
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() {
|
Widget buildTitleBar() {
|
||||||
@ -334,10 +350,10 @@ class _CmHeaderState extends State<_CmHeader>
|
|||||||
Offstage(
|
Offstage(
|
||||||
offstage: !client.authorized || client.isFileTransfer,
|
offstage: !client.authorized || client.isFileTransfer,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
onPressed: () => checkClickTime(
|
onPressed: () => checkClickTime(
|
||||||
client.id, () => gFFI.chatModel.toggleCMChatPage(client.id)),
|
client.id, () => gFFI.chatModel.toggleCMChatPage(client.id)),
|
||||||
icon: Icon(Icons.message_outlined),
|
icon: Icon(Icons.message_outlined),
|
||||||
),
|
splashRadius: kDesktopIconButtonSplashRadius),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
@ -73,7 +77,7 @@ class DesktopTabController {
|
|||||||
|
|
||||||
int get length => state.value.tabs.length;
|
int get length => state.value.tabs.length;
|
||||||
|
|
||||||
void add(TabInfo tab, {bool authorized = false}) {
|
void add(TabInfo tab) {
|
||||||
if (!isDesktop) return;
|
if (!isDesktop) return;
|
||||||
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
||||||
int toIndex;
|
int toIndex;
|
||||||
@ -87,16 +91,6 @@ class DesktopTabController {
|
|||||||
toIndex = state.value.tabs.length - 1;
|
toIndex = state.value.tabs.length - 1;
|
||||||
assert(toIndex >= 0);
|
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 {
|
try {
|
||||||
jumpTo(toIndex);
|
jumpTo(toIndex);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -127,12 +121,12 @@ class DesktopTabController {
|
|||||||
if (!isDesktop || index < 0) return;
|
if (!isDesktop || index < 0) return;
|
||||||
state.update((val) {
|
state.update((val) {
|
||||||
val!.selected = index;
|
val!.selected = index;
|
||||||
Future.delayed(Duration.zero, (() {
|
Future.delayed(Duration(milliseconds: 100), (() {
|
||||||
if (val.pageController.hasClients) {
|
if (val.pageController.hasClients) {
|
||||||
val.pageController.jumpToPage(index);
|
val.pageController.jumpToPage(index);
|
||||||
}
|
}
|
||||||
|
val.scrollController.itemCount = val.tabs.length;
|
||||||
if (val.scrollController.hasClients &&
|
if (val.scrollController.hasClients &&
|
||||||
val.scrollController.canScroll &&
|
|
||||||
val.scrollController.itemCount > index) {
|
val.scrollController.itemCount > index) {
|
||||||
val.scrollController
|
val.scrollController
|
||||||
.scrollToItem(index, center: false, animate: true);
|
.scrollToItem(index, center: false, animate: true);
|
||||||
@ -183,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;
|
||||||
@ -211,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,
|
||||||
@ -367,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,
|
||||||
@ -623,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;
|
||||||
@ -635,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,
|
||||||
@ -664,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),
|
||||||
@ -679,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,
|
||||||
@ -701,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;
|
||||||
@ -716,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,
|
||||||
@ -723,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,
|
||||||
@ -773,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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -790,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
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
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/server_page.dart';
|
||||||
import 'package:flutter_hbb/mobile/pages/settings_page.dart';
|
import 'package:flutter_hbb/mobile/pages/settings_page.dart';
|
||||||
import '../../common.dart';
|
import '../../common.dart';
|
||||||
|
import '../../common/widgets/chat_page.dart';
|
||||||
import 'connection_page.dart';
|
import 'connection_page.dart';
|
||||||
|
|
||||||
abstract class PageShape extends Widget {
|
abstract class PageShape extends Widget {
|
||||||
|
@ -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) {
|
||||||
@ -108,6 +110,7 @@ class ChatModel with ChangeNotifier {
|
|||||||
hideChatWindowOverlay();
|
hideChatWindowOverlay();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
child: Icon(Icons.message)));
|
child: Icon(Icons.message)));
|
||||||
});
|
});
|
||||||
overlayState.insert(overlay);
|
overlayState.insert(overlay);
|
||||||
@ -198,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) {
|
||||||
@ -207,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);
|
||||||
}
|
}
|
||||||
@ -237,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,7 +4,9 @@ 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 '../common.dart';
|
import '../common.dart';
|
||||||
import '../common/formatter/id_formatter.dart';
|
import '../common/formatter/id_formatter.dart';
|
||||||
@ -37,6 +39,8 @@ class ServerModel with ChangeNotifier {
|
|||||||
|
|
||||||
final List<Client> _clients = [];
|
final List<Client> _clients = [];
|
||||||
|
|
||||||
|
Timer? cmHiddenTimer;
|
||||||
|
|
||||||
bool get isStart => _isStart;
|
bool get isStart => _isStart;
|
||||||
|
|
||||||
bool get mediaOk => _mediaOk;
|
bool get mediaOk => _mediaOk;
|
||||||
@ -353,13 +357,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
for (var clientJson in clientsJson) {
|
for (var clientJson in clientsJson) {
|
||||||
final client = Client.fromJson(clientJson);
|
final client = Client.fromJson(clientJson);
|
||||||
_clients.add(client);
|
_clients.add(client);
|
||||||
tabController.add(
|
_addTab(client);
|
||||||
TabInfo(
|
|
||||||
key: client.id.toString(),
|
|
||||||
label: client.name,
|
|
||||||
closable: false,
|
|
||||||
page: Desktop.buildConnectionCard(client)),
|
|
||||||
authorized: client.authorized);
|
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -384,13 +382,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
_clients.add(client);
|
_clients.add(client);
|
||||||
}
|
}
|
||||||
tabController.add(
|
_addTab(client);
|
||||||
TabInfo(
|
|
||||||
key: client.id.toString(),
|
|
||||||
label: client.name,
|
|
||||||
closable: false,
|
|
||||||
page: Desktop.buildConnectionCard(client)),
|
|
||||||
authorized: client.authorized);
|
|
||||||
// remove disconnected
|
// remove disconnected
|
||||||
final index_disconnected = _clients
|
final index_disconnected = _clients
|
||||||
.indexWhere((c) => c.disconnected && c.peerId == client.peerId);
|
.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) {
|
void showLoginDialog(Client client) {
|
||||||
parent.target?.dialogManager.show((setState, close) {
|
parent.target?.dialogManager.show((setState, close) {
|
||||||
cancel() {
|
cancel() {
|
||||||
@ -530,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);
|
||||||
|
|
||||||
@ -549,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…
x
Reference in New Issue
Block a user