mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 15:54:35 +01:00
#94 new: option of moving out server func btns
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user