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 String text;
|
||||||
final bool toggleable;
|
final bool toggleable;
|
||||||
final IconData? icon;
|
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 = [
|
enum VirtualKeyType { toggleIME, backspace }
|
||||||
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'),
|
|
||||||
];
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
class BuildData {
|
class BuildData {
|
||||||
static const String name = "ServerBox";
|
static const String name = "ServerBox";
|
||||||
static const int build = 198;
|
static const int build = 199;
|
||||||
static const String engine =
|
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";
|
"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 17:51:06.250008";
|
static const String buildAt = "2023-01-29 20:45:19.543947";
|
||||||
static const int modifications = 8;
|
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) {
|
(item) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(item.name),
|
title: Text(item.name),
|
||||||
subtitle: Text('${item.image}\n${item.status}'),
|
subtitle: Text('${item.image} - ${item.status}'),
|
||||||
trailing: _buildMoreBtn(item, docker.isBusy),
|
trailing: _buildMoreBtn(item, docker.isBusy),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:toolbox/data/res/color.dart';
|
||||||
import 'package:xterm/xterm.dart';
|
import 'package:xterm/xterm.dart';
|
||||||
|
|
||||||
import '../../core/utils.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/model/ssh/virtual_key.dart';
|
||||||
import '../../data/provider/virtual_keyboard.dart';
|
import '../../data/provider/virtual_keyboard.dart';
|
||||||
import '../../data/res/terminal_theme.dart';
|
import '../../data/res/terminal_theme.dart';
|
||||||
|
import '../../data/res/virtual_key.dart';
|
||||||
import '../../data/store/private_key.dart';
|
import '../../data/store/private_key.dart';
|
||||||
import '../../locator.dart';
|
import '../../locator.dart';
|
||||||
|
|
||||||
@@ -27,7 +29,8 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
late final terminal = Terminal(inputHandler: keyboard);
|
late final terminal = Terminal(inputHandler: keyboard);
|
||||||
late final SSHClient client;
|
late final SSHClient client;
|
||||||
final keyboard = locator<VirtualKeyboard>();
|
final keyboard = locator<VirtualKeyboard>();
|
||||||
late double _screenWidth;
|
late MediaQueryData _media;
|
||||||
|
final _virtualKeyboardHeight = 57.0;
|
||||||
|
|
||||||
var isDark = false;
|
var isDark = false;
|
||||||
|
|
||||||
@@ -41,7 +44,7 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
isDark = isDarkMode(context);
|
isDark = isDarkMode(context);
|
||||||
_screenWidth = MediaQuery.of(context).size.width;
|
_media = MediaQuery.of(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -66,10 +69,6 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
terminal.buffer.clear();
|
terminal.buffer.clear();
|
||||||
terminal.buffer.setCursor(0, 0);
|
terminal.buffer.setCursor(0, 0);
|
||||||
|
|
||||||
terminal.onResize = (width, height, pixelWidth, pixelHeight) {
|
|
||||||
session.resizeTerminal(width, height, pixelWidth, pixelHeight);
|
|
||||||
};
|
|
||||||
|
|
||||||
terminal.onOutput = (data) {
|
terminal.onOutput = (data) {
|
||||||
session.write(utf8.encode(data) as Uint8List);
|
session.write(utf8.encode(data) as Uint8List);
|
||||||
};
|
};
|
||||||
@@ -83,6 +82,11 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
.cast<List<int>>()
|
.cast<List<int>>()
|
||||||
.transform(const Utf8Decoder())
|
.transform(const Utf8Decoder())
|
||||||
.listen(terminal.write);
|
.listen(terminal.write);
|
||||||
|
|
||||||
|
await session.done;
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -90,20 +94,28 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
final termTheme = isDark ? termDarkTheme : termLightTheme;
|
final termTheme = isDark ? termDarkTheme : termLightTheme;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: termTheme.background,
|
backgroundColor: termTheme.background,
|
||||||
body: Column(
|
body: SizedBox(
|
||||||
children: [
|
height: _media.size.height -
|
||||||
Expanded(
|
_virtualKeyboardHeight -
|
||||||
child: TerminalView(
|
_media.padding.bottom -
|
||||||
terminal,
|
_media.padding.top,
|
||||||
keyboardType: TextInputType.visiblePassword,
|
child: TerminalView(
|
||||||
theme: termTheme,
|
terminal,
|
||||||
onSecondaryTapUp: (p0, p1) {},
|
keyboardType: TextInputType.visiblePassword,
|
||||||
keyboardAppearance: isDark ? Brightness.dark : Brightness.light,
|
theme: termTheme,
|
||||||
),
|
keyboardAppearance: isDark ? Brightness.dark : Brightness.light,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
bottomNavigationBar: AnimatedPadding(
|
||||||
|
padding: _media.viewInsets,
|
||||||
|
duration: const Duration(milliseconds: 23),
|
||||||
|
curve: Curves.fastOutSlowIn,
|
||||||
|
child: SizedBox(
|
||||||
|
height: _virtualKeyboardHeight,
|
||||||
|
child: Consumer<VirtualKeyboard>(
|
||||||
|
builder: (_, __, ___) => _buildVirtualKey(),
|
||||||
),
|
),
|
||||||
Consumer<VirtualKeyboard>(
|
),
|
||||||
builder: (_, __, ___) => _buildVirtualKey()),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -113,6 +125,7 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
final top = virtualKeys.sublist(0, half);
|
final top = virtualKeys.sublist(0, half);
|
||||||
final bottom = virtualKeys.sublist(half);
|
final bottom = virtualKeys.sublist(half);
|
||||||
return Column(
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: top.map((e) => _buildVirtualKeyItem(e)).toList(),
|
children: top.map((e) => _buildVirtualKeyItem(e)).toList(),
|
||||||
@@ -143,12 +156,27 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
color: isDark ? Colors.white : Colors.black,
|
color: isDark ? Colors.white : Colors.black,
|
||||||
size: 17,
|
size: 17,
|
||||||
)
|
)
|
||||||
: Text(item.text,
|
: Text(
|
||||||
style:
|
item.text,
|
||||||
TextStyle(color: selected ? Colors.blue : null, fontSize: 15));
|
style: TextStyle(
|
||||||
|
color: selected ? primaryColor : null,
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
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) {
|
switch (item.key) {
|
||||||
case TerminalKey.control:
|
case TerminalKey.control:
|
||||||
keyboard.ctrl = !keyboard.ctrl;
|
keyboard.ctrl = !keyboard.ctrl;
|
||||||
@@ -164,12 +192,10 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: _screenWidth / (virtualKeys.length / 2),
|
width: _media.size.width / (virtualKeys.length / 2),
|
||||||
child: Padding(
|
height: _virtualKeyboardHeight / 2,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5.7),
|
child: Center(
|
||||||
child: Center(
|
child: child,
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user