mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
ssh: support copy/paste, fix ios backspace
This commit is contained in:
@@ -356,7 +356,7 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 205;
|
CURRENT_PROJECT_VERSION = 208;
|
||||||
DEVELOPMENT_TEAM = BA88US33G6;
|
DEVELOPMENT_TEAM = BA88US33G6;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@@ -364,7 +364,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.205;
|
MARKETING_VERSION = 1.0.208;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
@@ -486,7 +486,7 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 205;
|
CURRENT_PROJECT_VERSION = 208;
|
||||||
DEVELOPMENT_TEAM = BA88US33G6;
|
DEVELOPMENT_TEAM = BA88US33G6;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@@ -494,7 +494,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.205;
|
MARKETING_VERSION = 1.0.208;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
@@ -510,7 +510,7 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 205;
|
CURRENT_PROJECT_VERSION = 208;
|
||||||
DEVELOPMENT_TEAM = BA88US33G6;
|
DEVELOPMENT_TEAM = BA88US33G6;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@@ -518,7 +518,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.205;
|
MARKETING_VERSION = 1.0.208;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
|
|||||||
@@ -73,9 +73,7 @@ class MyApp extends StatelessWidget {
|
|||||||
colorScheme: ColorScheme.fromSwatch(
|
colorScheme: ColorScheme.fromSwatch(
|
||||||
primarySwatch: primaryColor.materialColor,
|
primarySwatch: primaryColor.materialColor,
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
accentColor: primaryColor
|
accentColor: primaryColor)),
|
||||||
)
|
|
||||||
),
|
|
||||||
home: const MyHomePage(),
|
home: const MyHomePage(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
@@ -21,3 +22,16 @@ Future<bool> shareFiles(BuildContext context, List<String> filePaths) async {
|
|||||||
await Share.shareXFiles(xfiles, text: 'ServerBox -> $text');
|
await Share.shareXFiles(xfiles, text: 'ServerBox -> $text');
|
||||||
return filePaths.isNotEmpty;
|
return filePaths.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get longPressEnabled {
|
||||||
|
switch (defaultTargetPlatform) {
|
||||||
|
case TargetPlatform.android:
|
||||||
|
case TargetPlatform.iOS:
|
||||||
|
return true;
|
||||||
|
case TargetPlatform.macOS:
|
||||||
|
case TargetPlatform.fuchsia:
|
||||||
|
case TargetPlatform.linux:
|
||||||
|
case TargetPlatform.windows:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:xterm/core.dart';
|
import 'package:xterm/core.dart';
|
||||||
|
|
||||||
class VirtualKey {
|
class VirtualKey {
|
||||||
final TerminalKey key;
|
|
||||||
final String text;
|
final String text;
|
||||||
final bool toggleable;
|
final bool toggleable;
|
||||||
|
final TerminalKey? key;
|
||||||
final IconData? icon;
|
final IconData? icon;
|
||||||
final VirtualKeyType? extFunc;
|
final VirtualKeyFunc? func;
|
||||||
|
|
||||||
VirtualKey(this.key, this.text,
|
VirtualKey(this.text,
|
||||||
{this.toggleable = false, this.icon, this.extFunc});
|
{this.key, this.toggleable = false, this.icon, this.func});
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VirtualKeyType { toggleIME, backspace }
|
enum VirtualKeyFunc { toggleIME, backspace, copy, paste }
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
class BuildData {
|
class BuildData {
|
||||||
static const String name = "ServerBox";
|
static const String name = "ServerBox";
|
||||||
static const int build = 206;
|
static const int build = 208;
|
||||||
static const String engine =
|
static const String engine =
|
||||||
"Flutter 3.7.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision b06b8b2710 (8 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 (8 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-02-01 17:24:19.787396";
|
static const String buildAt = "2023-02-01 18:33:57.761096";
|
||||||
static const int modifications = 4;
|
static const int modifications = 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,27 @@ import 'package:xterm/core.dart';
|
|||||||
|
|
||||||
import '../model/ssh/virtual_key.dart';
|
import '../model/ssh/virtual_key.dart';
|
||||||
|
|
||||||
var virtualKeys = [
|
final virtualKeys = [
|
||||||
VirtualKey(TerminalKey.escape, 'Esc'),
|
VirtualKey('Esc', key: TerminalKey.escape),
|
||||||
VirtualKey(TerminalKey.alt, 'Alt', toggleable: true),
|
VirtualKey('Alt', key: TerminalKey.alt, toggleable: true),
|
||||||
VirtualKey(TerminalKey.home, 'Home'),
|
VirtualKey('Home', key: TerminalKey.home),
|
||||||
VirtualKey(TerminalKey.arrowUp, 'Up', icon: Icons.arrow_upward),
|
VirtualKey('Up', key: TerminalKey.arrowUp, icon: Icons.arrow_upward),
|
||||||
VirtualKey(TerminalKey.end, 'End'),
|
VirtualKey('End', key: TerminalKey.end),
|
||||||
VirtualKey(TerminalKey.backspace, 'Backspace',
|
VirtualKey(
|
||||||
extFunc: VirtualKeyType.backspace, icon: Icons.backspace),
|
'Copy',
|
||||||
VirtualKey(TerminalKey.tab, 'Tab'),
|
func: VirtualKeyFunc.copy,
|
||||||
VirtualKey(TerminalKey.control, 'Ctrl', toggleable: true),
|
icon: Icons.copy,
|
||||||
VirtualKey(TerminalKey.arrowLeft, 'Left', icon: Icons.arrow_back),
|
),
|
||||||
VirtualKey(TerminalKey.arrowDown, 'Down', icon: Icons.arrow_downward),
|
VirtualKey('Backspace', func: VirtualKeyFunc.backspace, icon: Icons.backspace,),
|
||||||
VirtualKey(TerminalKey.arrowRight, 'Right', icon: Icons.arrow_forward),
|
VirtualKey('Tab', key: TerminalKey.tab),
|
||||||
VirtualKey(TerminalKey.none, 'IME',
|
VirtualKey('Ctrl', key: TerminalKey.control, toggleable: true),
|
||||||
extFunc: VirtualKeyType.toggleIME, icon: Icons.keyboard_hide),
|
VirtualKey('Left', key: TerminalKey.arrowLeft, icon: Icons.arrow_back),
|
||||||
|
VirtualKey('Down', key: TerminalKey.arrowDown, icon: Icons.arrow_downward),
|
||||||
|
VirtualKey('Right', key: TerminalKey.arrowRight, icon: Icons.arrow_forward),
|
||||||
|
VirtualKey(
|
||||||
|
'Paste',
|
||||||
|
func: VirtualKeyFunc.paste,
|
||||||
|
icon: Icons.paste,
|
||||||
|
),
|
||||||
|
VirtualKey('IME', func: VirtualKeyFunc.toggleIME, icon: Icons.keyboard_hide,),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -144,8 +144,7 @@ class _PkgManagePageState extends State<PkgManagePage>
|
|||||||
ConstrainedBox(
|
ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(
|
||||||
maxHeight: _media.size.height * 0.3,
|
maxHeight: _media.size.height * 0.3,
|
||||||
minWidth: _media.size.width
|
minWidth: _media.size.width),
|
||||||
),
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(17),
|
padding: const EdgeInsets.all(17),
|
||||||
child: RoundRectCard(
|
child: RoundRectCard(
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dartssh2/dartssh2.dart';
|
import 'package:dartssh2/dartssh2.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
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/ui.dart';
|
import '../../core/utils/ui.dart';
|
||||||
@@ -13,6 +13,7 @@ import '../../core/utils/server.dart';
|
|||||||
import '../../data/model/server/server_private_info.dart';
|
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/color.dart';
|
||||||
import '../../data/res/terminal_theme.dart';
|
import '../../data/res/terminal_theme.dart';
|
||||||
import '../../data/res/virtual_key.dart';
|
import '../../data/res/virtual_key.dart';
|
||||||
import '../../locator.dart';
|
import '../../locator.dart';
|
||||||
@@ -26,11 +27,12 @@ class SSHPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SSHPageState extends State<SSHPage> {
|
class _SSHPageState extends State<SSHPage> {
|
||||||
late final terminal = Terminal(inputHandler: keyboard);
|
late final _terminal = Terminal(inputHandler: _keyboard);
|
||||||
SSHClient? client;
|
SSHClient? _client;
|
||||||
final keyboard = locator<VirtualKeyboard>();
|
final _keyboard = locator<VirtualKeyboard>();
|
||||||
late MediaQueryData _media;
|
late MediaQueryData _media;
|
||||||
final _virtualKeyboardHeight = 57.0;
|
final _virtualKeyboardHeight = 57.0;
|
||||||
|
final TerminalController _terminalController = TerminalController();
|
||||||
|
|
||||||
var isDark = false;
|
var isDark = false;
|
||||||
|
|
||||||
@@ -49,39 +51,39 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
client?.close();
|
_client?.close();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initTerminal() async {
|
Future<void> initTerminal() async {
|
||||||
terminal.write('Connecting...\r\n');
|
_terminal.write('Connecting...\r\n');
|
||||||
|
|
||||||
client = await genClient(widget.spi);
|
_client = await genClient(widget.spi);
|
||||||
terminal.write('Connected\r\n');
|
_terminal.write('Connected\r\n');
|
||||||
|
|
||||||
final session = await client!.shell(
|
final session = await _client!.shell(
|
||||||
pty: SSHPtyConfig(
|
pty: SSHPtyConfig(
|
||||||
width: terminal.viewWidth,
|
width: _terminal.viewWidth,
|
||||||
height: terminal.viewHeight,
|
height: _terminal.viewHeight,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
terminal.buffer.clear();
|
_terminal.buffer.clear();
|
||||||
terminal.buffer.setCursor(0, 0);
|
_terminal.buffer.setCursor(0, 0);
|
||||||
|
|
||||||
terminal.onOutput = (data) {
|
_terminal.onOutput = (data) {
|
||||||
session.write(utf8.encode(data) as Uint8List);
|
session.write(utf8.encode(data) as Uint8List);
|
||||||
};
|
};
|
||||||
|
|
||||||
session.stdout
|
session.stdout
|
||||||
.cast<List<int>>()
|
.cast<List<int>>()
|
||||||
.transform(const Utf8Decoder())
|
.transform(const Utf8Decoder())
|
||||||
.listen(terminal.write);
|
.listen(_terminal.write);
|
||||||
|
|
||||||
session.stderr
|
session.stderr
|
||||||
.cast<List<int>>()
|
.cast<List<int>>()
|
||||||
.transform(const Utf8Decoder())
|
.transform(const Utf8Decoder())
|
||||||
.listen(terminal.write);
|
.listen(_terminal.write);
|
||||||
|
|
||||||
await session.done;
|
await session.done;
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@@ -100,9 +102,12 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
_media.padding.bottom -
|
_media.padding.bottom -
|
||||||
_media.padding.top,
|
_media.padding.top,
|
||||||
child: TerminalView(
|
child: TerminalView(
|
||||||
terminal,
|
_terminal,
|
||||||
|
controller: _terminalController,
|
||||||
keyboardType: TextInputType.visiblePassword,
|
keyboardType: TextInputType.visiblePassword,
|
||||||
theme: termTheme,
|
theme: termTheme,
|
||||||
|
deleteDetection: Platform.isIOS,
|
||||||
|
autofocus: true,
|
||||||
keyboardAppearance: isDark ? Brightness.dark : Brightness.light,
|
keyboardAppearance: isDark ? Brightness.dark : Brightness.light,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -141,10 +146,10 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
var selected = false;
|
var selected = false;
|
||||||
switch (item.key) {
|
switch (item.key) {
|
||||||
case TerminalKey.control:
|
case TerminalKey.control:
|
||||||
selected = keyboard.ctrl;
|
selected = _keyboard.ctrl;
|
||||||
break;
|
break;
|
||||||
case TerminalKey.alt:
|
case TerminalKey.alt:
|
||||||
selected = keyboard.alt;
|
selected = _keyboard.alt;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -165,32 +170,7 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () => _doVirtualKey(item),
|
||||||
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;
|
|
||||||
setState(() {});
|
|
||||||
break;
|
|
||||||
case TerminalKey.alt:
|
|
||||||
keyboard.alt = !keyboard.alt;
|
|
||||||
setState(() {});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
terminal.keyInput(item.key);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: _media.size.width / (virtualKeys.length / 2),
|
width: _media.size.width / (virtualKeys.length / 2),
|
||||||
height: _virtualKeyboardHeight / 2,
|
height: _virtualKeyboardHeight / 2,
|
||||||
@@ -200,4 +180,53 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _doVirtualKey(VirtualKey item) {
|
||||||
|
if (item.func != null) {
|
||||||
|
_doVirtualKeyFunc(item.func!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (item.key != null) {
|
||||||
|
_doVirtualKeyInput(item.key!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _doVirtualKeyInput(TerminalKey key) {
|
||||||
|
switch (key) {
|
||||||
|
case TerminalKey.control:
|
||||||
|
_keyboard.ctrl = !_keyboard.ctrl;
|
||||||
|
setState(() {});
|
||||||
|
break;
|
||||||
|
case TerminalKey.alt:
|
||||||
|
_keyboard.alt = !_keyboard.alt;
|
||||||
|
setState(() {});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_terminal.keyInput(key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _doVirtualKeyFunc(VirtualKeyFunc type) {
|
||||||
|
switch (type) {
|
||||||
|
case VirtualKeyFunc.toggleIME:
|
||||||
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
|
break;
|
||||||
|
case VirtualKeyFunc.backspace:
|
||||||
|
_terminal.keyInput(TerminalKey.backspace);
|
||||||
|
break;
|
||||||
|
case VirtualKeyFunc.paste:
|
||||||
|
Clipboard.getData(Clipboard.kTextPlain).then((value) {
|
||||||
|
if (value != null) {
|
||||||
|
_terminal.textInput(value.text!);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case VirtualKeyFunc.copy:
|
||||||
|
final range = _terminalController.selection;
|
||||||
|
final text = _terminal.buffer.getText(range);
|
||||||
|
Clipboard.setData(ClipboardData(text: text));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user