mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
ssh page opt: performance & auto exit
This commit is contained in:
@@ -6,21 +6,10 @@ class VirtualKey {
|
||||
final String text;
|
||||
final bool toggleable;
|
||||
final IconData? icon;
|
||||
final VirtualKeyType? extFunc;
|
||||
|
||||
VirtualKey(this.key, this.text, {this.toggleable = false, this.icon});
|
||||
VirtualKey(this.key, this.text,
|
||||
{this.toggleable = false, this.icon, this.extFunc});
|
||||
}
|
||||
|
||||
var virtualKeys = [
|
||||
VirtualKey(TerminalKey.escape, 'Esc'),
|
||||
VirtualKey(TerminalKey.alt, 'Alt', toggleable: true),
|
||||
VirtualKey(TerminalKey.pageUp, 'PgUp'),
|
||||
VirtualKey(TerminalKey.arrowUp, 'Up', icon: Icons.arrow_upward),
|
||||
VirtualKey(TerminalKey.pageDown, 'PgDn'),
|
||||
VirtualKey(TerminalKey.end, 'End'),
|
||||
VirtualKey(TerminalKey.tab, 'Tab'),
|
||||
VirtualKey(TerminalKey.control, 'Ctrl', toggleable: true),
|
||||
VirtualKey(TerminalKey.arrowLeft, 'Left', icon: Icons.arrow_back),
|
||||
VirtualKey(TerminalKey.arrowDown, 'Down', icon: Icons.arrow_downward),
|
||||
VirtualKey(TerminalKey.arrowRight, 'Right', icon: Icons.arrow_forward),
|
||||
VirtualKey(TerminalKey.home, 'Home'),
|
||||
];
|
||||
enum VirtualKeyType { toggleIME, backspace }
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 198;
|
||||
static const int build = 199;
|
||||
static const String engine =
|
||||
"Flutter 3.7.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision b06b8b2710 (5 days ago) • 2023-01-23 16:55:55 -0800\nEngine • revision b24591ed32\nTools • Dart 2.19.0 • DevTools 2.20.1\n";
|
||||
static const String buildAt = "2023-01-29 17:51:06.250008";
|
||||
static const int modifications = 8;
|
||||
"Flutter 3.7.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision b06b8b2710 (6 days ago) • 2023-01-23 16:55:55 -0800\nEngine • revision b24591ed32\nTools • Dart 2.19.0 • DevTools 2.20.1\n";
|
||||
static const String buildAt = "2023-01-29 20:45:19.543947";
|
||||
static const int modifications = 3;
|
||||
}
|
||||
|
||||
21
lib/data/res/virtual_key.dart
Normal file
21
lib/data/res/virtual_key.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:xterm/core.dart';
|
||||
|
||||
import '../model/ssh/virtual_key.dart';
|
||||
|
||||
var virtualKeys = [
|
||||
VirtualKey(TerminalKey.escape, 'Esc'),
|
||||
VirtualKey(TerminalKey.alt, 'Alt', toggleable: true),
|
||||
VirtualKey(TerminalKey.home, 'Home'),
|
||||
VirtualKey(TerminalKey.arrowUp, 'Up', icon: Icons.arrow_upward),
|
||||
VirtualKey(TerminalKey.end, 'End'),
|
||||
VirtualKey(TerminalKey.backspace, 'Backspace',
|
||||
extFunc: VirtualKeyType.backspace, icon: Icons.backspace),
|
||||
VirtualKey(TerminalKey.tab, 'Tab'),
|
||||
VirtualKey(TerminalKey.control, 'Ctrl', toggleable: true),
|
||||
VirtualKey(TerminalKey.arrowLeft, 'Left', icon: Icons.arrow_back),
|
||||
VirtualKey(TerminalKey.arrowDown, 'Down', icon: Icons.arrow_downward),
|
||||
VirtualKey(TerminalKey.arrowRight, 'Right', icon: Icons.arrow_forward),
|
||||
VirtualKey(TerminalKey.none, 'IME',
|
||||
extFunc: VirtualKeyType.toggleIME, icon: Icons.keyboard_hide),
|
||||
];
|
||||
@@ -441,7 +441,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
(item) {
|
||||
return ListTile(
|
||||
title: Text(item.name),
|
||||
subtitle: Text('${item.image}\n${item.status}'),
|
||||
subtitle: Text('${item.image} - ${item.status}'),
|
||||
trailing: _buildMoreBtn(item, docker.isBusy),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:xterm/xterm.dart';
|
||||
|
||||
import '../../core/utils.dart';
|
||||
@@ -12,6 +13,7 @@ import '../../data/model/server/server_private_info.dart';
|
||||
import '../../data/model/ssh/virtual_key.dart';
|
||||
import '../../data/provider/virtual_keyboard.dart';
|
||||
import '../../data/res/terminal_theme.dart';
|
||||
import '../../data/res/virtual_key.dart';
|
||||
import '../../data/store/private_key.dart';
|
||||
import '../../locator.dart';
|
||||
|
||||
@@ -27,7 +29,8 @@ class _SSHPageState extends State<SSHPage> {
|
||||
late final terminal = Terminal(inputHandler: keyboard);
|
||||
late final SSHClient client;
|
||||
final keyboard = locator<VirtualKeyboard>();
|
||||
late double _screenWidth;
|
||||
late MediaQueryData _media;
|
||||
final _virtualKeyboardHeight = 57.0;
|
||||
|
||||
var isDark = false;
|
||||
|
||||
@@ -41,7 +44,7 @@ class _SSHPageState extends State<SSHPage> {
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
isDark = isDarkMode(context);
|
||||
_screenWidth = MediaQuery.of(context).size.width;
|
||||
_media = MediaQuery.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -66,10 +69,6 @@ class _SSHPageState extends State<SSHPage> {
|
||||
terminal.buffer.clear();
|
||||
terminal.buffer.setCursor(0, 0);
|
||||
|
||||
terminal.onResize = (width, height, pixelWidth, pixelHeight) {
|
||||
session.resizeTerminal(width, height, pixelWidth, pixelHeight);
|
||||
};
|
||||
|
||||
terminal.onOutput = (data) {
|
||||
session.write(utf8.encode(data) as Uint8List);
|
||||
};
|
||||
@@ -83,6 +82,11 @@ class _SSHPageState extends State<SSHPage> {
|
||||
.cast<List<int>>()
|
||||
.transform(const Utf8Decoder())
|
||||
.listen(terminal.write);
|
||||
|
||||
await session.done;
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -90,20 +94,28 @@ class _SSHPageState extends State<SSHPage> {
|
||||
final termTheme = isDark ? termDarkTheme : termLightTheme;
|
||||
return Scaffold(
|
||||
backgroundColor: termTheme.background,
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
body: SizedBox(
|
||||
height: _media.size.height -
|
||||
_virtualKeyboardHeight -
|
||||
_media.padding.bottom -
|
||||
_media.padding.top,
|
||||
child: TerminalView(
|
||||
terminal,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
theme: termTheme,
|
||||
onSecondaryTapUp: (p0, p1) {},
|
||||
keyboardAppearance: isDark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
),
|
||||
Consumer<VirtualKeyboard>(
|
||||
builder: (_, __, ___) => _buildVirtualKey()),
|
||||
],
|
||||
bottomNavigationBar: AnimatedPadding(
|
||||
padding: _media.viewInsets,
|
||||
duration: const Duration(milliseconds: 23),
|
||||
curve: Curves.fastOutSlowIn,
|
||||
child: SizedBox(
|
||||
height: _virtualKeyboardHeight,
|
||||
child: Consumer<VirtualKeyboard>(
|
||||
builder: (_, __, ___) => _buildVirtualKey(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -113,6 +125,7 @@ class _SSHPageState extends State<SSHPage> {
|
||||
final top = virtualKeys.sublist(0, half);
|
||||
final bottom = virtualKeys.sublist(half);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: top.map((e) => _buildVirtualKeyItem(e)).toList(),
|
||||
@@ -143,12 +156,27 @@ class _SSHPageState extends State<SSHPage> {
|
||||
color: isDark ? Colors.white : Colors.black,
|
||||
size: 17,
|
||||
)
|
||||
: Text(item.text,
|
||||
style:
|
||||
TextStyle(color: selected ? Colors.blue : null, fontSize: 15));
|
||||
: Text(
|
||||
item.text,
|
||||
style: TextStyle(
|
||||
color: selected ? primaryColor : null,
|
||||
fontSize: 15,
|
||||
),
|
||||
);
|
||||
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if (item.extFunc != null) {
|
||||
switch (item.extFunc!) {
|
||||
case VirtualKeyType.toggleIME:
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
break;
|
||||
case VirtualKeyType.backspace:
|
||||
terminal.keyInput(TerminalKey.backspace);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
switch (item.key) {
|
||||
case TerminalKey.control:
|
||||
keyboard.ctrl = !keyboard.ctrl;
|
||||
@@ -164,14 +192,12 @@ class _SSHPageState extends State<SSHPage> {
|
||||
}
|
||||
},
|
||||
child: SizedBox(
|
||||
width: _screenWidth / (virtualKeys.length / 2),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 5.7),
|
||||
width: _media.size.width / (virtualKeys.length / 2),
|
||||
height: _virtualKeyboardHeight / 2,
|
||||
child: Center(
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user