mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
opt.
This commit is contained in:
@@ -11,14 +11,14 @@ class Backup {
|
||||
final List<PrivateKeyInfo> keys;
|
||||
final Map<String, String> dockerHosts;
|
||||
|
||||
Backup(
|
||||
this.version,
|
||||
this.date,
|
||||
this.spis,
|
||||
this.snippets,
|
||||
this.keys,
|
||||
this.dockerHosts,
|
||||
);
|
||||
Backup({
|
||||
required this.version,
|
||||
required this.date,
|
||||
required this.spis,
|
||||
required this.snippets,
|
||||
required this.keys,
|
||||
required this.dockerHosts,
|
||||
});
|
||||
|
||||
Backup.fromJson(Map<String, dynamic> json)
|
||||
: version = json['version'] as int,
|
||||
|
||||
34
lib/data/model/app/error.dart
Normal file
34
lib/data/model/app/error.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
enum ErrFrom {
|
||||
unknown,
|
||||
apt,
|
||||
docker,
|
||||
sftp,
|
||||
ssh,
|
||||
status;
|
||||
}
|
||||
|
||||
abstract class Err<T> {
|
||||
final ErrFrom from;
|
||||
final T type;
|
||||
final String? message;
|
||||
|
||||
Err({required this.from, required this.type, this.message});
|
||||
}
|
||||
|
||||
enum DockerErrType {
|
||||
unknown,
|
||||
noClient,
|
||||
notInstalled,
|
||||
invalidVersion,
|
||||
cmdNoPrefix
|
||||
}
|
||||
|
||||
class DockerErr extends Err<DockerErrType> {
|
||||
DockerErr({required DockerErrType type, String? message})
|
||||
: super(from: ErrFrom.docker, type: type, message: message);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DockerErr<$type>: $message';
|
||||
}
|
||||
}
|
||||
105
lib/data/model/app/menu.dart
Normal file
105
lib/data/model/app/menu.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
enum ServerTabMenuType {
|
||||
sftp,
|
||||
snippet,
|
||||
pkg,
|
||||
docker,
|
||||
edit;
|
||||
|
||||
IconData get icon {
|
||||
switch (this) {
|
||||
case ServerTabMenuType.sftp:
|
||||
return Icons.insert_drive_file;
|
||||
case ServerTabMenuType.snippet:
|
||||
return Icons.code;
|
||||
case ServerTabMenuType.pkg:
|
||||
return Icons.system_security_update;
|
||||
case ServerTabMenuType.docker:
|
||||
return Icons.view_agenda;
|
||||
case ServerTabMenuType.edit:
|
||||
return Icons.edit;
|
||||
}
|
||||
}
|
||||
|
||||
String text(S s) {
|
||||
switch (this) {
|
||||
case ServerTabMenuType.sftp:
|
||||
return 'SFTP';
|
||||
case ServerTabMenuType.snippet:
|
||||
return s.snippet;
|
||||
case ServerTabMenuType.pkg:
|
||||
return s.pkg;
|
||||
case ServerTabMenuType.docker:
|
||||
return 'Docker';
|
||||
case ServerTabMenuType.edit:
|
||||
return s.edit;
|
||||
}
|
||||
}
|
||||
|
||||
PopupMenuItem<ServerTabMenuType> build(S s) => _build(this, icon, text(s));
|
||||
}
|
||||
|
||||
enum DockerMenuType {
|
||||
start,
|
||||
stop,
|
||||
restart,
|
||||
rm,
|
||||
logs;
|
||||
|
||||
static List<DockerMenuType> items(bool running) {
|
||||
if (running) {
|
||||
return [stop, restart, rm, logs];
|
||||
} else {
|
||||
return [start, rm, logs];
|
||||
}
|
||||
}
|
||||
|
||||
IconData get icon {
|
||||
switch (this) {
|
||||
case DockerMenuType.start:
|
||||
return Icons.play_arrow;
|
||||
case DockerMenuType.stop:
|
||||
return Icons.stop;
|
||||
case DockerMenuType.restart:
|
||||
return Icons.restart_alt;
|
||||
case DockerMenuType.rm:
|
||||
return Icons.delete;
|
||||
case DockerMenuType.logs:
|
||||
return Icons.logo_dev;
|
||||
}
|
||||
}
|
||||
|
||||
String text(S s) {
|
||||
switch (this) {
|
||||
case DockerMenuType.start:
|
||||
return s.start;
|
||||
case DockerMenuType.stop:
|
||||
return s.stop;
|
||||
case DockerMenuType.restart:
|
||||
return s.restart;
|
||||
case DockerMenuType.rm:
|
||||
return s.delete;
|
||||
case DockerMenuType.logs:
|
||||
return s.log;
|
||||
}
|
||||
}
|
||||
|
||||
PopupMenuItem<DockerMenuType> build(S s) => _build(this, icon, text(s));
|
||||
}
|
||||
|
||||
PopupMenuItem<T> _build<T>(T t, IconData icon, String text) {
|
||||
return PopupMenuItem<T>(
|
||||
value: t,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(text),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,16 +1,10 @@
|
||||
class PathWithPrefix {
|
||||
late String _prefixPath;
|
||||
final String _prefixPath;
|
||||
String _path = '/';
|
||||
String? _prePath;
|
||||
String get path => _prefixPath + _path;
|
||||
|
||||
PathWithPrefix(String prefixPath) {
|
||||
if (prefixPath.endsWith('/')) {
|
||||
_prefixPath = prefixPath.substring(0, prefixPath.length - 1);
|
||||
} else {
|
||||
_prefixPath = prefixPath;
|
||||
}
|
||||
}
|
||||
PathWithPrefix(String prefixPath) : _prefixPath = _trimSuffix(prefixPath);
|
||||
|
||||
void update(String newPath) {
|
||||
_prePath = _path;
|
||||
@@ -36,3 +30,10 @@ class PathWithPrefix {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String _trimSuffix(String prefixPath) {
|
||||
if (prefixPath.endsWith('/')) {
|
||||
return prefixPath.substring(0, prefixPath.length - 1);
|
||||
}
|
||||
return prefixPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user