Merge pull request #3123 from Heap-Hop/opt_chat_overlay_and_fix_pageview_2
Fix chat text selectable, refactor overlay and fix pageview
This commit is contained in:
commit
5aee66e89c
@ -367,20 +367,25 @@ class Dialog<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class OverlayKeyState {
|
||||
final _overlayKey = GlobalKey<OverlayState>();
|
||||
|
||||
/// use global overlay by default
|
||||
OverlayState? get state =>
|
||||
_overlayKey.currentState ?? globalKey.currentState?.overlay;
|
||||
|
||||
GlobalKey<OverlayState>? get key => _overlayKey;
|
||||
}
|
||||
|
||||
class OverlayDialogManager {
|
||||
OverlayState? _overlayState;
|
||||
final Map<String, Dialog> _dialogs = {};
|
||||
var _overlayKeyState = OverlayKeyState();
|
||||
int _tagCount = 0;
|
||||
|
||||
OverlayEntry? _mobileActionsOverlayEntry;
|
||||
|
||||
/// By default OverlayDialogManager use global overlay
|
||||
OverlayDialogManager() {
|
||||
_overlayState = globalKey.currentState?.overlay;
|
||||
}
|
||||
|
||||
void setOverlayState(OverlayState? overlayState) {
|
||||
_overlayState = overlayState;
|
||||
void setOverlayState(OverlayKeyState overlayKeyState) {
|
||||
_overlayKeyState = overlayKeyState;
|
||||
}
|
||||
|
||||
void dismissAll() {
|
||||
@ -404,7 +409,7 @@ class OverlayDialogManager {
|
||||
bool useAnimation = true,
|
||||
bool forceGlobal = false}) {
|
||||
final overlayState =
|
||||
forceGlobal ? globalKey.currentState?.overlay : _overlayState;
|
||||
forceGlobal ? globalKey.currentState?.overlay : _overlayKeyState.state;
|
||||
|
||||
if (overlayState == null) {
|
||||
return Future.error(
|
||||
@ -508,7 +513,8 @@ class OverlayDialogManager {
|
||||
|
||||
void showMobileActionsOverlay({FFI? ffi}) {
|
||||
if (_mobileActionsOverlayEntry != null) return;
|
||||
if (_overlayState == null) return;
|
||||
final overlayState = _overlayKeyState.state;
|
||||
if (overlayState == null) return;
|
||||
|
||||
// compute overlay position
|
||||
final screenW = MediaQuery.of(globalKey.currentContext!).size.width;
|
||||
@ -534,7 +540,7 @@ class OverlayDialogManager {
|
||||
onHidePressed: () => hideMobileActionsOverlay(),
|
||||
);
|
||||
});
|
||||
_overlayState!.insert(overlay);
|
||||
overlayState.insert(overlay);
|
||||
_mobileActionsOverlayEntry = overlay;
|
||||
}
|
||||
|
||||
|
@ -95,10 +95,31 @@ class ChatPage extends StatelessWidget implements PageShape {
|
||||
color: Theme.of(context).colorScheme.primary)),
|
||||
messageOptions: MessageOptions(
|
||||
showOtherUsersAvatar: false,
|
||||
showTime: true,
|
||||
currentUserTextColor: Colors.white,
|
||||
textColor: Colors.white,
|
||||
maxWidth: constraints.maxWidth * 0.7,
|
||||
messageTextBuilder: (message, _, __) {
|
||||
final isOwnMessage =
|
||||
message.user.id == currentUser.id;
|
||||
return Column(
|
||||
crossAxisAlignment: isOwnMessage
|
||||
? CrossAxisAlignment.end
|
||||
: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(message.text,
|
||||
style: TextStyle(color: Colors.white)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
"${message.createdAt.hour}:${message.createdAt.minute}",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
messageDecorationBuilder: (_, __, ___) =>
|
||||
defaultMessageDecoration(
|
||||
color: MyTheme.accent80,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../consts.dart';
|
||||
@ -96,12 +97,14 @@ class DraggableChatWindow extends StatelessWidget {
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
child: Row(children: [
|
||||
Icon(Icons.chat_bubble_outline,
|
||||
size: 20, color: Theme.of(context).colorScheme.primary),
|
||||
SizedBox(width: 6),
|
||||
Text(translate("Chat"))
|
||||
])),
|
||||
child: Obx(() => Opacity(
|
||||
opacity: chatModel.isWindowFocus.value ? 1.0 : 0.4,
|
||||
child: Row(children: [
|
||||
Icon(Icons.chat_bubble_outline,
|
||||
size: 20, color: Theme.of(context).colorScheme.primary),
|
||||
SizedBox(width: 6),
|
||||
Text(translate("Chat"))
|
||||
])))),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(2),
|
||||
child: ActionIcon(
|
||||
@ -304,15 +307,17 @@ class _DraggableState extends State<Draggable> {
|
||||
if (widget.checkKeyboard) {
|
||||
checkKeyboard();
|
||||
}
|
||||
if (widget.checkKeyboard) {
|
||||
if (widget.checkScreenSize) {
|
||||
checkScreenSize();
|
||||
}
|
||||
return Positioned(
|
||||
top: _position.dy,
|
||||
left: _position.dx,
|
||||
width: widget.width,
|
||||
height: widget.height,
|
||||
child: widget.builder(context, onPanUpdate));
|
||||
return Stack(children: [
|
||||
Positioned(
|
||||
top: _position.dy,
|
||||
left: _position.dx,
|
||||
width: widget.width,
|
||||
height: widget.height,
|
||||
child: widget.builder(context, onPanUpdate))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,3 +371,55 @@ class QualityMonitor extends StatelessWidget {
|
||||
)
|
||||
: const SizedBox.shrink()));
|
||||
}
|
||||
|
||||
class BlockableOverlayState extends OverlayKeyState {
|
||||
final _middleBlocked = false.obs;
|
||||
|
||||
VoidCallback? onMiddleBlockedClick; // to-do use listener
|
||||
|
||||
RxBool get middleBlocked => _middleBlocked;
|
||||
|
||||
void addMiddleBlockedListener(void Function(bool) cb) {
|
||||
_middleBlocked.listen(cb);
|
||||
}
|
||||
|
||||
void setMiddleBlocked(bool blocked) {
|
||||
if (blocked != _middleBlocked.value) {
|
||||
_middleBlocked.value = blocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BlockableOverlay extends StatelessWidget {
|
||||
final Widget underlying;
|
||||
final List<OverlayEntry>? upperLayer;
|
||||
|
||||
final BlockableOverlayState state;
|
||||
|
||||
BlockableOverlay(
|
||||
{required this.underlying, required this.state, this.upperLayer});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final initialEntries = [
|
||||
OverlayEntry(builder: (_) => underlying),
|
||||
|
||||
/// middle layer
|
||||
OverlayEntry(
|
||||
builder: (context) => Obx(() => Listener(
|
||||
onPointerDown: (_) {
|
||||
state.onMiddleBlockedClick?.call();
|
||||
},
|
||||
child: Container(
|
||||
color:
|
||||
state.middleBlocked.value ? Colors.transparent : null)))),
|
||||
];
|
||||
|
||||
if (upperLayer != null) {
|
||||
initialEntries.addAll(upperLayer!);
|
||||
}
|
||||
|
||||
/// set key
|
||||
return Overlay(key: state.key, initialEntries: initialEntries);
|
||||
}
|
||||
}
|
||||
|
@ -64,23 +64,17 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tabWidget = Container(
|
||||
child: Overlay(initialEntries: [
|
||||
OverlayEntry(builder: (context) {
|
||||
gFFI.dialogManager.setOverlayState(Overlay.of(context));
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).backgroundColor,
|
||||
body: DesktopTab(
|
||||
controller: tabController,
|
||||
tail: ActionIcon(
|
||||
message: 'Settings',
|
||||
icon: IconFont.menu,
|
||||
onTap: DesktopTabPage.onAddSetting,
|
||||
isClose: false,
|
||||
),
|
||||
));
|
||||
})
|
||||
]),
|
||||
);
|
||||
child: Scaffold(
|
||||
backgroundColor: Theme.of(context).backgroundColor,
|
||||
body: DesktopTab(
|
||||
controller: tabController,
|
||||
tail: ActionIcon(
|
||||
message: 'Settings',
|
||||
icon: IconFont.menu,
|
||||
onTap: DesktopTabPage.onAddSetting,
|
||||
isClose: false,
|
||||
),
|
||||
)));
|
||||
return Platform.isMacOS
|
||||
? tabWidget
|
||||
: Obx(
|
||||
|
@ -80,6 +80,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
Entry? _lastClickEntry;
|
||||
|
||||
final _dropMaskVisible = false.obs; // TODO impl drop mask
|
||||
final _overlayKeyState = OverlayKeyState();
|
||||
|
||||
ScrollController getBreadCrumbScrollController(bool isLocal) {
|
||||
return isLocal ? _breadCrumbScrollerLocal : _breadCrumbScrollerRemote;
|
||||
@ -115,6 +116,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
// register location listener
|
||||
_locationNodeLocal.addListener(onLocalLocationFocusChanged);
|
||||
_locationNodeRemote.addListener(onRemoteLocationFocusChanged);
|
||||
_ffi.dialogManager.setOverlayState(_overlayKeyState);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -137,9 +139,8 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Overlay(initialEntries: [
|
||||
OverlayEntry(builder: (context) {
|
||||
_ffi.dialogManager.setOverlayState(Overlay.of(context));
|
||||
return Overlay(key: _overlayKeyState.key, initialEntries: [
|
||||
OverlayEntry(builder: (_) {
|
||||
return ChangeNotifierProvider.value(
|
||||
value: _ffi.fileModel,
|
||||
child: Consumer<FileModel>(builder: (context, model, child) {
|
||||
|
@ -61,6 +61,8 @@ class _RemotePageState extends State<RemotePage>
|
||||
late RxBool _remoteCursorMoved;
|
||||
late RxBool _keyboardEnabled;
|
||||
|
||||
final _blockableOverlayState = BlockableOverlayState();
|
||||
|
||||
final FocusNode _rawKeyFocusNode = FocusNode(debugLabel: "rawkeyFocusNode");
|
||||
|
||||
Function(bool)? _onEnterOrLeaveImage4Menubar;
|
||||
@ -132,6 +134,13 @@ class _RemotePageState extends State<RemotePage>
|
||||
// });
|
||||
// _isCustomCursorInited = true;
|
||||
// }
|
||||
|
||||
_ffi.dialogManager.setOverlayState(_blockableOverlayState);
|
||||
_ffi.chatModel.setOverlayState(_blockableOverlayState);
|
||||
// make remote page penetrable automatically, effective for chat over remote
|
||||
_blockableOverlayState.onMiddleBlockedClick = () {
|
||||
_blockableOverlayState.setMiddleBlocked(false);
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
@ -191,39 +200,50 @@ class _RemotePageState extends State<RemotePage>
|
||||
|
||||
Widget buildBody(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).backgroundColor,
|
||||
body: Overlay(
|
||||
initialEntries: [
|
||||
OverlayEntry(builder: (context) {
|
||||
_ffi.chatModel.setOverlayState(Overlay.of(context));
|
||||
_ffi.dialogManager.setOverlayState(Overlay.of(context));
|
||||
return Container(
|
||||
color: Colors.black,
|
||||
child: RawKeyFocusScope(
|
||||
focusNode: _rawKeyFocusNode,
|
||||
onFocusChange: (bool imageFocused) {
|
||||
debugPrint(
|
||||
"onFocusChange(window active:${!_isWindowBlur}) $imageFocused");
|
||||
// See [onWindowBlur].
|
||||
if (Platform.isWindows) {
|
||||
if (_isWindowBlur) {
|
||||
imageFocused = false;
|
||||
Future.delayed(Duration.zero, () {
|
||||
_rawKeyFocusNode.unfocus();
|
||||
});
|
||||
}
|
||||
if (imageFocused) {
|
||||
_ffi.inputModel.enterOrLeave(true);
|
||||
} else {
|
||||
_ffi.inputModel.enterOrLeave(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
inputModel: _ffi.inputModel,
|
||||
child: getBodyForDesktop(context)));
|
||||
})
|
||||
],
|
||||
));
|
||||
backgroundColor: Theme.of(context).backgroundColor,
|
||||
|
||||
/// the Overlay key will be set with _blockableOverlayState in BlockableOverlay
|
||||
/// see override build() in [BlockableOverlay]
|
||||
body: BlockableOverlay(
|
||||
state: _blockableOverlayState,
|
||||
underlying: Container(
|
||||
color: Colors.black,
|
||||
child: RawKeyFocusScope(
|
||||
focusNode: _rawKeyFocusNode,
|
||||
onFocusChange: (bool imageFocused) {
|
||||
debugPrint(
|
||||
"onFocusChange(window active:${!_isWindowBlur}) $imageFocused");
|
||||
// See [onWindowBlur].
|
||||
if (Platform.isWindows) {
|
||||
if (_isWindowBlur) {
|
||||
imageFocused = false;
|
||||
Future.delayed(Duration.zero, () {
|
||||
_rawKeyFocusNode.unfocus();
|
||||
});
|
||||
}
|
||||
if (imageFocused) {
|
||||
_ffi.inputModel.enterOrLeave(true);
|
||||
} else {
|
||||
_ffi.inputModel.enterOrLeave(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
inputModel: _ffi.inputModel,
|
||||
child: getBodyForDesktop(context))),
|
||||
upperLayer: [
|
||||
OverlayEntry(
|
||||
builder: (context) => RemoteMenubar(
|
||||
id: widget.id,
|
||||
ffi: _ffi,
|
||||
state: widget.menubarState,
|
||||
onEnterOrLeaveImageSetter: (func) =>
|
||||
_onEnterOrLeaveImage4Menubar = func,
|
||||
onEnterOrLeaveImageCleaner: () =>
|
||||
_onEnterOrLeaveImage4Menubar = null,
|
||||
))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -344,13 +364,6 @@ class _RemotePageState extends State<RemotePage>
|
||||
QualityMonitor(_ffi.qualityMonitorModel), null, null),
|
||||
),
|
||||
);
|
||||
paints.add(RemoteMenubar(
|
||||
id: widget.id,
|
||||
ffi: _ffi,
|
||||
state: widget.menubarState,
|
||||
onEnterOrLeaveImageSetter: (func) => _onEnterOrLeaveImage4Menubar = func,
|
||||
onEnterOrLeaveImageCleaner: () => _onEnterOrLeaveImage4Menubar = null,
|
||||
));
|
||||
return Stack(
|
||||
children: paints,
|
||||
);
|
||||
|
@ -68,26 +68,19 @@ class _DesktopServerPageState extends State<DesktopServerPage>
|
||||
],
|
||||
child: Consumer<ServerModel>(
|
||||
builder: (context, serverModel, child) => Container(
|
||||
decoration: BoxDecoration(
|
||||
border:
|
||||
Border.all(color: MyTheme.color(context).border!)),
|
||||
child: Overlay(initialEntries: [
|
||||
OverlayEntry(builder: (context) {
|
||||
gFFI.dialogManager.setOverlayState(Overlay.of(context));
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).backgroundColor,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: ConnectionManager()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
})
|
||||
]),
|
||||
)));
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: MyTheme.color(context).border!)),
|
||||
child: Scaffold(
|
||||
backgroundColor: Theme.of(context).backgroundColor,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: ConnectionManager()),
|
||||
],
|
||||
),
|
||||
),
|
||||
))));
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -688,9 +688,11 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
);
|
||||
}
|
||||
|
||||
final _chatButtonKey = GlobalKey();
|
||||
Widget _buildChat(BuildContext context) {
|
||||
FfiModel ffiModel = Provider.of<FfiModel>(context);
|
||||
return mod_menu.PopupMenuButton(
|
||||
key: _chatButtonKey,
|
||||
padding: EdgeInsets.zero,
|
||||
icon: SvgPicture.asset(
|
||||
"assets/chat.svg",
|
||||
@ -779,8 +781,17 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
RenderBox? renderBox =
|
||||
_chatButtonKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
|
||||
Offset? initPos;
|
||||
if (renderBox != null) {
|
||||
final pos = renderBox.localToGlobal(Offset.zero);
|
||||
initPos = Offset(pos.dx, pos.dy + _MenubarTheme.dividerHeight);
|
||||
}
|
||||
|
||||
widget.ffi.chatModel.changeCurrentID(ChatModel.clientModeID);
|
||||
widget.ffi.chatModel.toggleChatOverlay();
|
||||
widget.ffi.chatModel.toggleChatOverlay(chatInitPos: initPos);
|
||||
},
|
||||
padding: padding,
|
||||
dismissOnClicked: true,
|
||||
|
@ -327,14 +327,32 @@ class DesktopTab extends StatelessWidget {
|
||||
));
|
||||
}
|
||||
|
||||
List<Widget> _tabWidgets = [];
|
||||
Widget _buildPageView() {
|
||||
return _buildBlock(
|
||||
child: Obx(() => PageView(
|
||||
controller: state.value.pageController,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
children: state.value.tabs
|
||||
.map((tab) => tab.page)
|
||||
.toList(growable: false))));
|
||||
children: () {
|
||||
/// to-do refactor, separate connection state and UI state for remote session.
|
||||
/// [workaround] PageView children need an immutable list, after it has been passed into PageView
|
||||
final tabLen = state.value.tabs.length;
|
||||
if (tabLen == _tabWidgets.length) {
|
||||
return _tabWidgets;
|
||||
} else if (_tabWidgets.isNotEmpty &&
|
||||
tabLen == _tabWidgets.length + 1) {
|
||||
/// On add. Use the previous list(pointer) to prevent item's state init twice.
|
||||
/// *[_tabWidgets.isNotEmpty] means TabsWindow(remote_tab_page or file_manager_tab_page) opened before, but was hidden. In this case, we have to reload, otherwise the child can't be built.
|
||||
_tabWidgets.add(state.value.tabs.last.page);
|
||||
return _tabWidgets;
|
||||
} else {
|
||||
/// On remove or change. Use new list(pointer) to reload list children so that items loading order is normal.
|
||||
/// the Widgets in list must enable [AutomaticKeepAliveClientMixin]
|
||||
final newList = state.value.tabs.map((v) => v.page).toList();
|
||||
_tabWidgets = newList;
|
||||
return newList;
|
||||
}
|
||||
}())));
|
||||
}
|
||||
|
||||
/// Check whether to show ListView
|
||||
@ -767,7 +785,8 @@ class _ListView extends StatelessWidget {
|
||||
tabBuilder: tabBuilder,
|
||||
tabMenuBuilder: tabMenuBuilder,
|
||||
maxLabelWidth: maxLabelWidth,
|
||||
selectedTabBackgroundColor: selectedTabBackgroundColor ?? MyTheme.tabbar(context).selectedTabBackgroundColor,
|
||||
selectedTabBackgroundColor: selectedTabBackgroundColor ??
|
||||
MyTheme.tabbar(context).selectedTabBackgroundColor,
|
||||
unSelectedTabBackgroundColor: unSelectedTabBackgroundColor,
|
||||
);
|
||||
}).toList()));
|
||||
@ -1121,7 +1140,8 @@ class TabbarTheme extends ThemeExtension<TabbarTheme> {
|
||||
dividerColor: dividerColor ?? this.dividerColor,
|
||||
hoverColor: hoverColor ?? this.hoverColor,
|
||||
closeHoverColor: closeHoverColor ?? this.closeHoverColor,
|
||||
selectedTabBackgroundColor: selectedTabBackgroundColor ?? this.selectedTabBackgroundColor,
|
||||
selectedTabBackgroundColor:
|
||||
selectedTabBackgroundColor ?? this.selectedTabBackgroundColor,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1147,7 +1167,8 @@ class TabbarTheme extends ThemeExtension<TabbarTheme> {
|
||||
dividerColor: Color.lerp(dividerColor, other.dividerColor, t),
|
||||
hoverColor: Color.lerp(hoverColor, other.hoverColor, t),
|
||||
closeHoverColor: Color.lerp(closeHoverColor, other.closeHoverColor, t),
|
||||
selectedTabBackgroundColor: Color.lerp(selectedTabBackgroundColor, other.selectedTabBackgroundColor, t),
|
||||
selectedTabBackgroundColor: Color.lerp(
|
||||
selectedTabBackgroundColor, other.selectedTabBackgroundColor, t),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dash_chat_2/dash_chat_2.dart';
|
||||
import 'package:draggable_float_widget/draggable_float_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
@ -27,16 +30,13 @@ class MessageBody {
|
||||
class ChatModel with ChangeNotifier {
|
||||
static final clientModeID = -1;
|
||||
|
||||
/// _overlayState:
|
||||
/// Desktop: store session overlay by using [setOverlayState].
|
||||
/// Mobile: always null, use global overlay.
|
||||
/// see [_getOverlayState] in [showChatIconOverlay] or [showChatWindowOverlay]
|
||||
OverlayState? _overlayState;
|
||||
OverlayEntry? chatIconOverlayEntry;
|
||||
OverlayEntry? chatWindowOverlayEntry;
|
||||
|
||||
bool isConnManager = false;
|
||||
|
||||
RxBool isWindowFocus = true.obs;
|
||||
BlockableOverlayState? _blockableOverlayState;
|
||||
final Rx<VoiceCallStatus> _voiceCallStatus = Rx(VoiceCallStatus.notStarted);
|
||||
|
||||
Rx<VoiceCallStatus> get voiceCallStatus => _voiceCallStatus;
|
||||
@ -58,6 +58,19 @@ class ChatModel with ChangeNotifier {
|
||||
|
||||
bool get isShowCMChatPage => _isShowCMChatPage;
|
||||
|
||||
void setOverlayState(BlockableOverlayState blockableOverlayState) {
|
||||
_blockableOverlayState = blockableOverlayState;
|
||||
|
||||
_blockableOverlayState!.addMiddleBlockedListener((v) {
|
||||
if (!v) {
|
||||
isWindowFocus.value = false;
|
||||
if (isWindowFocus.value) {
|
||||
isWindowFocus.toggle();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final WeakReference<FFI> parent;
|
||||
|
||||
ChatModel(this.parent);
|
||||
@ -74,20 +87,6 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
setOverlayState(OverlayState? os) {
|
||||
_overlayState = os;
|
||||
}
|
||||
|
||||
OverlayState? _getOverlayState() {
|
||||
if (_overlayState == null) {
|
||||
if (globalKey.currentState == null ||
|
||||
globalKey.currentState!.overlay == null) return null;
|
||||
return globalKey.currentState!.overlay;
|
||||
} else {
|
||||
return _overlayState;
|
||||
}
|
||||
}
|
||||
|
||||
showChatIconOverlay({Offset offset = const Offset(200, 50)}) {
|
||||
if (chatIconOverlayEntry != null) {
|
||||
chatIconOverlayEntry!.remove();
|
||||
@ -100,7 +99,7 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
final overlayState = _getOverlayState();
|
||||
final overlayState = _blockableOverlayState?.state;
|
||||
if (overlayState == null) return;
|
||||
|
||||
final overlay = OverlayEntry(builder: (context) {
|
||||
@ -132,23 +131,35 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
showChatWindowOverlay() {
|
||||
showChatWindowOverlay({Offset? chatInitPos}) {
|
||||
if (chatWindowOverlayEntry != null) return;
|
||||
final overlayState = _getOverlayState();
|
||||
isWindowFocus.value = true;
|
||||
_blockableOverlayState?.setMiddleBlocked(true);
|
||||
|
||||
final overlayState = _blockableOverlayState?.state;
|
||||
if (overlayState == null) return;
|
||||
final overlay = OverlayEntry(builder: (context) {
|
||||
return DraggableChatWindow(
|
||||
position: const Offset(20, 80),
|
||||
width: 250,
|
||||
height: 350,
|
||||
chatModel: this);
|
||||
return Listener(
|
||||
onPointerDown: (_) {
|
||||
if (!isWindowFocus.value) {
|
||||
isWindowFocus.value = true;
|
||||
_blockableOverlayState?.setMiddleBlocked(true);
|
||||
}
|
||||
},
|
||||
child: DraggableChatWindow(
|
||||
position: chatInitPos ?? Offset(20, 80),
|
||||
width: 250,
|
||||
height: 350,
|
||||
chatModel: this));
|
||||
});
|
||||
overlayState.insert(overlay);
|
||||
chatWindowOverlayEntry = overlay;
|
||||
requestChatInputFocus();
|
||||
}
|
||||
|
||||
hideChatWindowOverlay() {
|
||||
if (chatWindowOverlayEntry != null) {
|
||||
_blockableOverlayState?.setMiddleBlocked(false);
|
||||
chatWindowOverlayEntry!.remove();
|
||||
chatWindowOverlayEntry = null;
|
||||
return;
|
||||
@ -158,13 +169,13 @@ class ChatModel with ChangeNotifier {
|
||||
_isChatOverlayHide() => ((!isDesktop && chatIconOverlayEntry == null) ||
|
||||
chatWindowOverlayEntry == null);
|
||||
|
||||
toggleChatOverlay() {
|
||||
toggleChatOverlay({Offset? chatInitPos}) {
|
||||
if (_isChatOverlayHide()) {
|
||||
gFFI.invokeMethod("enable_soft_keyboard", true);
|
||||
if (!isDesktop) {
|
||||
showChatIconOverlay();
|
||||
}
|
||||
showChatWindowOverlay();
|
||||
showChatWindowOverlay(chatInitPos: chatInitPos);
|
||||
} else {
|
||||
hideChatIconOverlay();
|
||||
hideChatWindowOverlay();
|
||||
@ -194,6 +205,7 @@ class ChatModel with ChangeNotifier {
|
||||
await windowManager.setSizeAlignment(
|
||||
kConnectionManagerWindowSize, Alignment.topRight);
|
||||
} else {
|
||||
requestChatInputFocus();
|
||||
await windowManager.show();
|
||||
await windowManager.setSizeAlignment(Size(600, 400), Alignment.topRight);
|
||||
_isShowCMChatPage = !_isShowCMChatPage;
|
||||
@ -291,7 +303,6 @@ class ChatModel with ChangeNotifier {
|
||||
close() {
|
||||
hideChatIconOverlay();
|
||||
hideChatWindowOverlay();
|
||||
_overlayState = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@ -299,6 +310,14 @@ class ChatModel with ChangeNotifier {
|
||||
_messages[clientModeID]?.clear();
|
||||
}
|
||||
|
||||
void requestChatInputFocus() {
|
||||
Timer(Duration(milliseconds: 100), () {
|
||||
if (inputNode.hasListeners && inputNode.canRequestFocus) {
|
||||
inputNode.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onVoiceCallWaiting() {
|
||||
_voiceCallStatus.value = VoiceCallStatus.waitingForResponse;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_hbb/models/user_model.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
import 'package:flutter_hbb/common/shared_state.dart';
|
||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:image/image.dart' as img2;
|
||||
import 'package:flutter_custom_cursor/cursor_manager.dart';
|
||||
@ -26,7 +25,6 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../common.dart';
|
||||
import '../common/shared_state.dart';
|
||||
import '../utils/image.dart' as img;
|
||||
import '../mobile/widgets/dialog.dart';
|
||||
import 'input_model.dart';
|
||||
@ -1393,13 +1391,13 @@ class FFI {
|
||||
canvasModel.y, canvasModel.scale, ffiModel.pi.currentDisplay);
|
||||
}
|
||||
bind.sessionClose(id: id);
|
||||
id = '';
|
||||
imageModel.update(null);
|
||||
cursorModel.clear();
|
||||
ffiModel.clear();
|
||||
canvasModel.clear();
|
||||
inputModel.resetModifiers();
|
||||
debugPrint('model $id closed');
|
||||
id = '';
|
||||
}
|
||||
|
||||
void setMethodCallHandler(FMethod callback) {
|
||||
|
@ -16,7 +16,7 @@ final testClients = [
|
||||
Client(3, false, false, "UserDDDDDDDDDDDd", "441123123", true, false, false)
|
||||
];
|
||||
|
||||
/// -t lib/cm_main.dart to test cm
|
||||
/// flutter run -d {platform} -t lib/cm_test.dart to test cm
|
||||
void main(List<String> args) async {
|
||||
isTest = true;
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
Loading…
x
Reference in New Issue
Block a user