cancel cm hidden timer when active

This commit is contained in:
csf 2022-10-26 21:39:28 +09:00
parent e759b62f5d
commit 5a905174e7
3 changed files with 62 additions and 54 deletions

View File

@ -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,38 @@ 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, return Row(
Tooltip( mainAxisAlignment: MainAxisAlignment.center,
message: key, children: [
waitDuration: Duration(seconds: 1), icon,
child: label), Tooltip(
], message: key,
); waitDuration: Duration(seconds: 1),
}, child: label),
pageViewBuilder: (pageView) => Row(children: [ ],
Expanded(child: pageView), );
Consumer<ChatModel>( },
builder: (_, model, child) => model.isShowChatPage pageViewBuilder: (pageView) => Row(children: [
? Expanded(child: Scaffold(body: ChatPage())) Expanded(child: pageView),
: Offstage()) Consumer<ChatModel>(
])); builder: (_, model, child) => model.isShowChatPage
? Expanded(child: Scaffold(body: ChatPage()))
: Offstage())
])));
} }
Widget buildTitleBar() { Widget buildTitleBar() {

View File

@ -73,7 +73,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 +87,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) {

View File

@ -5,6 +5,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: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 +38,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 +356,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 +381,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 +397,23 @@ class ServerModel with ChangeNotifier {
} }
} }
void _addTab(Client client) {
tabController.add(TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
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() {