#94 new: option of moving out server func btns
This commit is contained in:
@@ -250,7 +250,7 @@ class _FullScreenPageState extends State<FullScreenPage> with AfterLayoutMixin {
|
||||
);
|
||||
return Text(
|
||||
topRightStr,
|
||||
style: textSize12Grey,
|
||||
style: textSize11Grey,
|
||||
textScaleFactor: 1.0,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/core/extension/order.dart';
|
||||
import 'package:toolbox/data/model/server/cpu.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
import 'package:toolbox/view/widget/server_func_btns.dart';
|
||||
|
||||
import '../../../core/extension/numx.dart';
|
||||
import '../../../core/route.dart';
|
||||
@@ -95,7 +96,11 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
),
|
||||
body: ReorderableListView.builder(
|
||||
padding: EdgeInsets.only(
|
||||
left: 13, right: 13, top: 13, bottom: _media.padding.bottom),
|
||||
left: 13,
|
||||
right: 13,
|
||||
top: 13,
|
||||
bottom: _media.padding.bottom,
|
||||
),
|
||||
onReorder: (int oldIndex, int newIndex) {
|
||||
setState(() {
|
||||
_cardsOrder.move(
|
||||
@@ -106,6 +111,9 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
});
|
||||
},
|
||||
footer: height13,
|
||||
header: _setting.moveOutServerTabFuncBtns.fetch()!
|
||||
? null
|
||||
: RoundRectCard(ServerFuncBtns(spi: widget.spi, s: _s)),
|
||||
itemCount: _cardsOrder.length,
|
||||
buildDefaultDragHandles: false,
|
||||
itemBuilder: (context, index) => ReorderableDelayedDragStartListener(
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:io' show Directory, File, Platform, Process;
|
||||
|
||||
import 'package:after_layout/after_layout.dart';
|
||||
import 'package:circle_chart/circle_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -9,16 +7,12 @@ import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/extension/media_queryx.dart';
|
||||
import 'package:toolbox/core/extension/order.dart';
|
||||
import 'package:toolbox/data/model/app/net_view.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
import 'package:toolbox/data/provider/snippet.dart';
|
||||
import 'package:toolbox/view/page/process.dart';
|
||||
import 'package:toolbox/view/widget/tag/picker.dart';
|
||||
import 'package:toolbox/view/widget/server_func_btns.dart';
|
||||
import 'package:toolbox/view/widget/tag/switcher.dart';
|
||||
|
||||
import '../../../core/route.dart';
|
||||
import '../../../core/utils/misc.dart' hide pathJoin;
|
||||
import '../../../core/utils/platform.dart';
|
||||
import '../../../core/utils/server.dart';
|
||||
import '../../../core/utils/ui.dart';
|
||||
import '../../../data/model/server/disk.dart';
|
||||
import '../../../data/model/server/server.dart';
|
||||
@@ -26,12 +20,10 @@ import '../../../data/model/server/server_private_info.dart';
|
||||
import '../../../data/model/server/server_status.dart';
|
||||
import '../../../data/provider/server.dart';
|
||||
import '../../../data/res/color.dart';
|
||||
import '../../../data/model/app/menu.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../../data/store/setting.dart';
|
||||
import '../../../locator.dart';
|
||||
import '../../widget/round_rect_card.dart';
|
||||
import '../ssh/term.dart';
|
||||
import 'edit.dart';
|
||||
|
||||
class ServerPage extends StatefulWidget {
|
||||
@@ -235,10 +227,11 @@ class _ServerPageState extends State<ServerPage>
|
||||
),
|
||||
),
|
||||
height13,
|
||||
SizedBox(
|
||||
height: 29,
|
||||
child: _buildMoreBtn(spi),
|
||||
),
|
||||
if (_settingStore.moveOutServerTabFuncBtns.fetch()!)
|
||||
SizedBox(
|
||||
height: 27,
|
||||
child: ServerFuncBtns(spi: spi, s: _s),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -297,14 +290,14 @@ class _ServerPageState extends State<ServerPage>
|
||||
onTap: () => _showFailReason(ss),
|
||||
child: Text(
|
||||
_s.viewErr,
|
||||
style: textSize12Grey,
|
||||
style: textSize11Grey,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Text(
|
||||
topRightStr,
|
||||
style: textSize12Grey,
|
||||
style: textSize11Grey,
|
||||
textScaleFactor: 1.0,
|
||||
);
|
||||
}
|
||||
@@ -325,84 +318,6 @@ class _ServerPageState extends State<ServerPage>
|
||||
);
|
||||
}
|
||||
|
||||
void _onTapMoreBtns(ServerTabMenuType value, ServerPrivateInfo spi) async {
|
||||
switch (value) {
|
||||
case ServerTabMenuType.pkg:
|
||||
AppRoute.pkg(spi: spi).checkClientAndGo(
|
||||
context: context,
|
||||
s: _s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.sftp:
|
||||
AppRoute.sftp(spi: spi).checkClientAndGo(
|
||||
context: context,
|
||||
s: _s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.snippet:
|
||||
final provider = locator<SnippetProvider>();
|
||||
final snippets = await showDialog<List<Snippet>>(
|
||||
context: context,
|
||||
builder: (_) => TagPicker<Snippet>(
|
||||
items: provider.snippets,
|
||||
containsTag: (t, tag) => t.tags?.contains(tag) ?? false,
|
||||
tags: provider.tags.toSet(),
|
||||
name: (t) => t.name,
|
||||
),
|
||||
);
|
||||
if (snippets == null) {
|
||||
return;
|
||||
}
|
||||
final result = await _serverProvider.runSnippets(spi.id, snippets);
|
||||
if (result != null && result.isNotEmpty) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.result),
|
||||
child: Text(result),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => copy2Clipboard(result),
|
||||
child: Text(_s.copy),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
break;
|
||||
case ServerTabMenuType.docker:
|
||||
AppRoute.docker(spi: spi).checkClientAndGo(
|
||||
context: context,
|
||||
s: _s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.process:
|
||||
AppRoute(ProcessPage(spi: spi), 'process page').checkClientAndGo(
|
||||
context: context,
|
||||
s: _s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.terminal:
|
||||
gotoSSH(spi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildMoreBtn(ServerPrivateInfo spi) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: ServerTabMenuType.values
|
||||
.map((e) => IconButton(
|
||||
onPressed: () => _onTapMoreBtns(e, spi),
|
||||
padding: EdgeInsets.zero,
|
||||
icon: Icon(e.icon, size: 15),
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNet(ServerStatus ss) {
|
||||
return ValueListenableBuilder<NetViewType>(
|
||||
valueListenable: _settingStore.netViewType.listenable(),
|
||||
@@ -488,7 +403,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
child: Text(
|
||||
'${percent.toStringAsFixed(1)}%',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 11),
|
||||
style: textSize11Grey,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
),
|
||||
@@ -497,52 +412,6 @@ class _ServerPageState extends State<ServerPage>
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> gotoSSH(ServerPrivateInfo spi) async {
|
||||
// as a `Mobile first` app -> handle mobile first
|
||||
//
|
||||
// run built-in ssh on macOS due to incompatibility
|
||||
if (!isDesktop || isMacOS) {
|
||||
AppRoute(SSHPage(spi: spi), 'ssh page').go(context);
|
||||
return;
|
||||
}
|
||||
final extraArgs = <String>[];
|
||||
if (spi.port != 22) {
|
||||
extraArgs.addAll(['-p', '${spi.port}']);
|
||||
}
|
||||
|
||||
final path = () {
|
||||
final tempKeyFileName = 'srvbox_pk_${spi.pubKeyId}';
|
||||
return pathJoin(Directory.systemTemp.path, tempKeyFileName);
|
||||
}();
|
||||
final file = File(path);
|
||||
final shouldGenKey = spi.pubKeyId != null;
|
||||
if (shouldGenKey) {
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
await file.writeAsString(getPrivateKey(spi.pubKeyId!));
|
||||
extraArgs.addAll(["-i", path]);
|
||||
}
|
||||
|
||||
List<String> sshCommand = ["ssh", "${spi.user}@${spi.ip}"] + extraArgs;
|
||||
final system = Platform.operatingSystem;
|
||||
switch (system) {
|
||||
case "windows":
|
||||
await Process.start("cmd", ["/c", "start"] + sshCommand);
|
||||
break;
|
||||
case "linux":
|
||||
await Process.start("x-terminal-emulator", ["-e"] + sshCommand);
|
||||
break;
|
||||
default:
|
||||
showSnackBar(context, Text('Mismatch system: $system'));
|
||||
}
|
||||
// For security reason, delete the private key file after use
|
||||
if (shouldGenKey) {
|
||||
if (!await file.exists()) return;
|
||||
await Future.delayed(const Duration(seconds: 2), file.delete);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
|
||||
@@ -169,6 +169,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
Widget _buildServer() {
|
||||
return Column(
|
||||
children: [
|
||||
_buildMoveOutServerFuncBtns(),
|
||||
_buildNetViewType(),
|
||||
_buildUpdateInterval(),
|
||||
_buildMaxRetry(),
|
||||
@@ -969,4 +970,12 @@ class _SettingPageState extends State<SettingPage> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMoveOutServerFuncBtns() {
|
||||
return ListTile(
|
||||
title: Text(_s.moveOutServerFuncBtns),
|
||||
subtitle: Text(_s.moveOutServerFuncBtnsHelp, style: textSize13Grey),
|
||||
trailing: buildSwitch(context, _setting.moveOutServerTabFuncBtns),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
158
lib/view/widget/server_func_btns.dart
Normal file
158
lib/view/widget/server_func_btns.dart
Normal file
@@ -0,0 +1,158 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
|
||||
import '../../core/route.dart';
|
||||
import '../../core/utils/misc.dart' hide pathJoin;
|
||||
import '../../core/utils/platform.dart';
|
||||
import '../../core/utils/server.dart';
|
||||
import '../../core/utils/ui.dart';
|
||||
import '../../data/model/app/menu.dart';
|
||||
import '../../data/model/server/server_private_info.dart';
|
||||
import '../../data/model/server/snippet.dart';
|
||||
import '../../data/provider/snippet.dart';
|
||||
import '../../locator.dart';
|
||||
import '../page/process.dart';
|
||||
import 'tag/picker.dart';
|
||||
|
||||
class ServerFuncBtns extends StatelessWidget {
|
||||
const ServerFuncBtns({super.key, required this.spi, required this.s});
|
||||
|
||||
final ServerPrivateInfo spi;
|
||||
final S s;
|
||||
|
||||
void _onTapMoreBtns(
|
||||
ServerTabMenuType value,
|
||||
ServerPrivateInfo spi,
|
||||
BuildContext context,
|
||||
) async {
|
||||
switch (value) {
|
||||
case ServerTabMenuType.pkg:
|
||||
AppRoute.pkg(spi: spi).checkClientAndGo(
|
||||
context: context,
|
||||
s: s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.sftp:
|
||||
AppRoute.sftp(spi: spi).checkClientAndGo(
|
||||
context: context,
|
||||
s: s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.snippet:
|
||||
final provider = locator<SnippetProvider>();
|
||||
final snippets = await showDialog<List<Snippet>>(
|
||||
context: context,
|
||||
builder: (_) => TagPicker<Snippet>(
|
||||
items: provider.snippets,
|
||||
containsTag: (t, tag) => t.tags?.contains(tag) ?? false,
|
||||
tags: provider.tags.toSet(),
|
||||
name: (t) => t.name,
|
||||
),
|
||||
);
|
||||
if (snippets == null) {
|
||||
return;
|
||||
}
|
||||
final result =
|
||||
await locator<ServerProvider>().runSnippets(spi.id, snippets);
|
||||
if (result != null && result.isNotEmpty) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(s.result),
|
||||
child: Text(result),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => copy2Clipboard(result),
|
||||
child: Text(s.copy),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
break;
|
||||
case ServerTabMenuType.docker:
|
||||
AppRoute.docker(spi: spi).checkClientAndGo(
|
||||
context: context,
|
||||
s: s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.process:
|
||||
AppRoute(ProcessPage(spi: spi), 'process page').checkClientAndGo(
|
||||
context: context,
|
||||
s: s,
|
||||
id: spi.id,
|
||||
);
|
||||
break;
|
||||
case ServerTabMenuType.terminal:
|
||||
_gotoSSH(spi, context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: ServerTabMenuType.values
|
||||
.map((e) => IconButton(
|
||||
onPressed: () => _onTapMoreBtns(e, spi, context),
|
||||
padding: EdgeInsets.zero,
|
||||
icon: Icon(e.icon, size: 15),
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _gotoSSH(
|
||||
ServerPrivateInfo spi,
|
||||
BuildContext context,
|
||||
) async {
|
||||
// as a `Mobile first` app -> handle mobile first
|
||||
//
|
||||
// run built-in ssh on macOS due to incompatibility
|
||||
if (!isDesktop || isMacOS) {
|
||||
AppRoute.ssh(spi: spi).go(context);
|
||||
return;
|
||||
}
|
||||
final extraArgs = <String>[];
|
||||
if (spi.port != 22) {
|
||||
extraArgs.addAll(['-p', '${spi.port}']);
|
||||
}
|
||||
|
||||
final path = () {
|
||||
final tempKeyFileName = 'srvbox_pk_${spi.pubKeyId}';
|
||||
return pathJoin(Directory.systemTemp.path, tempKeyFileName);
|
||||
}();
|
||||
final file = File(path);
|
||||
final shouldGenKey = spi.pubKeyId != null;
|
||||
if (shouldGenKey) {
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
await file.writeAsString(getPrivateKey(spi.pubKeyId!));
|
||||
extraArgs.addAll(["-i", path]);
|
||||
}
|
||||
|
||||
List<String> sshCommand = ["ssh", "${spi.user}@${spi.ip}"] + extraArgs;
|
||||
final system = Platform.operatingSystem;
|
||||
switch (system) {
|
||||
case "windows":
|
||||
await Process.start("cmd", ["/c", "start"] + sshCommand);
|
||||
break;
|
||||
case "linux":
|
||||
await Process.start("x-terminal-emulator", ["-e"] + sshCommand);
|
||||
break;
|
||||
default:
|
||||
showSnackBar(context, Text('Mismatch system: $system'));
|
||||
}
|
||||
// For security reason, delete the private key file after use
|
||||
if (shouldGenKey) {
|
||||
if (!await file.exists()) return;
|
||||
await Future.delayed(const Duration(seconds: 2), file.delete);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user