desktop close connection tab (remote page)

This commit is contained in:
csf 2022-08-16 21:27:21 +08:00
parent c9c40508e7
commit ce050e250d
8 changed files with 33 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import 'dart:io';
import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
import 'package:get/instance_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';
@ -66,11 +67,11 @@ final ButtonStyle flatButtonStyle = TextButton.styleFrom(
),
);
backToHomePage() {
closeConnection({String? id}) {
if (isAndroid || isIOS) {
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
} else {
// TODO desktop
closeTab(id);
}
}
@ -306,7 +307,7 @@ void msgBox(
0,
wrap(translate('OK'), () {
dialogManager.dismissAll();
backToHomePage();
closeConnection();
}));
}
if (hasCancel == null) {

View File

@ -60,7 +60,7 @@ class _RemotePageState extends State<RemotePage>
WidgetsBinding.instance.addPostFrameCallback((_) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
_ffi.dialogManager
.showLoading(translate('Connecting...'), onCancel: backToHomePage);
.showLoading(translate('Connecting...'), onCancel: closeConnection);
});
if (!Platform.isLinux) {
Wakelock.enable();

View File

@ -10,6 +10,25 @@ const double _kTabBarHeight = kDesktopRemoteTabBarHeight;
const double _kIconSize = 18;
const double _kDividerIndent = 10;
const double _kAddIconSize = _kTabBarHeight - 15;
final tabBarKey = GlobalKey();
void closeTab(String? id) {
final tabBar = tabBarKey.currentWidget as TabBar?;
if (tabBar == null) return;
final tabs = tabBar.tabs as List<_Tab>;
if (id == null) {
final current = tabBar.controller?.index;
if (current == null) return;
tabs[current].onClose();
} else {
for (final tab in tabs) {
if (tab.label == id) {
tab.onClose();
break;
}
}
}
}
class TabInfo {
late final String label;
@ -59,6 +78,7 @@ class DesktopTabBar extends StatelessWidget {
),
Flexible(
child: Obx(() => TabBar(
key: tabBarKey,
indicatorColor: _theme.indicatorColor,
labelPadding: const EdgeInsets.symmetric(
vertical: 0, horizontal: 0),

View File

@ -29,7 +29,7 @@ class _FileManagerPageState extends State<FileManagerPage> {
gFFI.connect(widget.id, isFileTransfer: true);
WidgetsBinding.instance.addPostFrameCallback((_) {
gFFI.dialogManager
.showLoading(translate('Connecting...'), onCancel: backToHomePage);
.showLoading(translate('Connecting...'), onCancel: closeConnection);
});
gFFI.ffiModel.updateEventListener(widget.id);
Wakelock.enable();

View File

@ -51,7 +51,7 @@ class _RemotePageState extends State<RemotePage> {
WidgetsBinding.instance.addPostFrameCallback((_) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
gFFI.dialogManager
.showLoading(translate('Connecting...'), onCancel: backToHomePage);
.showLoading(translate('Connecting...'), onCancel: closeConnection);
_interval =
Timer.periodic(Duration(milliseconds: 30), (timer) => interval());
});

View File

@ -132,7 +132,7 @@ class _ScanPageState extends State<ScanPage> {
}
void showServerSettingFromQr(String data) async {
backToHomePage();
closeConnection();
await controller?.pauseCamera();
if (!data.startsWith('config=')) {
showToast('Invalid QR code');

View File

@ -184,7 +184,7 @@ void enterPasswordDialog(String id, OverlayDialogManager dialogManager) async {
style: flatButtonStyle,
onPressed: () {
close();
backToHomePage();
closeConnection();
},
child: Text(translate('Cancel')),
),
@ -196,7 +196,7 @@ void enterPasswordDialog(String id, OverlayDialogManager dialogManager) async {
gFFI.login(id, text, remember);
close();
dialogManager.showLoading(translate('Logging in...'),
onCancel: backToHomePage);
onCancel: closeConnection);
},
child: Text(translate('OK')),
),
@ -214,7 +214,7 @@ void wrongPasswordDialog(String id, OverlayDialogManager dialogManager) {
style: flatButtonStyle,
onPressed: () {
close();
backToHomePage();
closeConnection();
},
child: Text(translate('Cancel')),
),

View File

@ -287,7 +287,7 @@ class FfiModel with ChangeNotifier {
bind.sessionReconnect(id: id);
clearPermissions();
dialogManager.showLoading(translate('Connecting...'),
onCancel: backToHomePage);
onCancel: closeConnection);
});
_reconnects *= 2;
} else {
@ -335,7 +335,7 @@ class FfiModel with ChangeNotifier {
if (displays.length > 0) {
parent.target?.dialogManager.showLoading(
translate('Connected, waiting for image...'),
onCancel: backToHomePage);
onCancel: closeConnection);
_waitForImage = true;
_reconnects = 1;
}