mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
migrate: riverpod + freezed (#870)
This commit is contained in:
@@ -4,7 +4,7 @@ import 'package:server_box/core/extension/context/locale.dart';
|
||||
enum SSHErrType { unknown, connect, auth, noPrivateKey, chdir, segements, writeScript, getStatus }
|
||||
|
||||
class SSHErr extends Err<SSHErrType> {
|
||||
SSHErr({required super.type, super.message});
|
||||
const SSHErr({required super.type, super.message});
|
||||
|
||||
@override
|
||||
String? get solution => switch (type) {
|
||||
@@ -29,7 +29,7 @@ enum ContainerErrType {
|
||||
}
|
||||
|
||||
class ContainerErr extends Err<ContainerErrType> {
|
||||
ContainerErr({required super.type, super.message});
|
||||
const ContainerErr({required super.type, super.message});
|
||||
|
||||
@override
|
||||
String? get solution => null;
|
||||
@@ -38,7 +38,7 @@ class ContainerErr extends Err<ContainerErrType> {
|
||||
enum ICloudErrType { generic, notFound, multipleFiles }
|
||||
|
||||
class ICloudErr extends Err<ICloudErrType> {
|
||||
ICloudErr({required super.type, super.message});
|
||||
const ICloudErr({required super.type, super.message});
|
||||
|
||||
@override
|
||||
String? get solution => null;
|
||||
@@ -47,7 +47,7 @@ class ICloudErr extends Err<ICloudErrType> {
|
||||
enum WebdavErrType { generic, notFound }
|
||||
|
||||
class WebdavErr extends Err<WebdavErrType> {
|
||||
WebdavErr({required super.type, super.message});
|
||||
const WebdavErr({required super.type, super.message});
|
||||
|
||||
@override
|
||||
String? get solution => null;
|
||||
@@ -56,7 +56,7 @@ class WebdavErr extends Err<WebdavErrType> {
|
||||
enum PveErrType { unknown, net, loginFailed }
|
||||
|
||||
class PveErr extends Err<PveErrType> {
|
||||
PveErr({required super.type, super.message});
|
||||
const PveErr({required super.type, super.message});
|
||||
|
||||
@override
|
||||
String? get solution => null;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:server_box/data/model/app/scripts/script_builders.dart';
|
||||
import 'package:server_box/data/model/app/scripts/script_consts.dart';
|
||||
import 'package:server_box/data/model/server/system.dart';
|
||||
import 'package:server_box/data/provider/server.dart';
|
||||
|
||||
/// Shell functions available in the ServerBox application
|
||||
enum ShellFunc {
|
||||
@@ -26,8 +25,8 @@ enum ShellFunc {
|
||||
};
|
||||
|
||||
/// Execute this shell function on the specified server
|
||||
String exec(String id, {SystemType? systemType}) {
|
||||
final scriptPath = ShellFuncManager.getScriptPath(id, systemType: systemType);
|
||||
String exec(String id, {SystemType? systemType, required String? customDir}) {
|
||||
final scriptPath = ShellFuncManager.getScriptPath(id, systemType: systemType, customDir: customDir);
|
||||
final isWindows = systemType == SystemType.windows;
|
||||
final builder = ScriptBuilderFactory.getBuilder(isWindows);
|
||||
|
||||
@@ -51,11 +50,10 @@ class ShellFuncManager {
|
||||
/// Get the script directory for the given [id].
|
||||
///
|
||||
/// Checks for custom script directory first, then falls back to default.
|
||||
static String getScriptDir(String id, {SystemType? systemType}) {
|
||||
final customScriptDir = ServerProvider.pick(id: id)?.value.spi.custom?.scriptDir;
|
||||
static String getScriptDir(String id, {SystemType? systemType, required String? customDir}) {
|
||||
final isWindows = systemType == SystemType.windows;
|
||||
|
||||
if (customScriptDir != null) return _normalizeDir(customScriptDir, isWindows);
|
||||
if (customDir != null) return _normalizeDir(customDir, isWindows);
|
||||
return ScriptPaths.getScriptDir(id, isWindows: isWindows);
|
||||
}
|
||||
|
||||
@@ -66,11 +64,10 @@ class ShellFuncManager {
|
||||
}
|
||||
|
||||
/// Get the full script path for the given [id]
|
||||
static String getScriptPath(String id, {SystemType? systemType}) {
|
||||
final customScriptDir = ServerProvider.pick(id: id)?.value.spi.custom?.scriptDir;
|
||||
if (customScriptDir != null) {
|
||||
static String getScriptPath(String id, {SystemType? systemType, required String? customDir}) {
|
||||
if (customDir != null) {
|
||||
final isWindows = systemType == SystemType.windows;
|
||||
final normalizedDir = _normalizeDir(customScriptDir, isWindows);
|
||||
final normalizedDir = _normalizeDir(customDir, isWindows);
|
||||
final fileName = isWindows ? ScriptConstants.scriptFileWindows : ScriptConstants.scriptFile;
|
||||
final separator = isWindows ? ScriptConstants.windowsPathSeparator : ScriptConstants.unixPathSeparator;
|
||||
return '$normalizedDir$separator$fileName';
|
||||
@@ -81,8 +78,8 @@ class ShellFuncManager {
|
||||
}
|
||||
|
||||
/// Get the installation shell command for the script
|
||||
static String getInstallShellCmd(String id, {SystemType? systemType}) {
|
||||
final scriptDir = getScriptDir(id, systemType: systemType);
|
||||
static String getInstallShellCmd(String id, {SystemType? systemType, required String? customDir}) {
|
||||
final scriptDir = getScriptDir(id, systemType: systemType, customDir: customDir);
|
||||
final isWindows = systemType == SystemType.windows;
|
||||
final normalizedDir = _normalizeDir(scriptDir, isWindows);
|
||||
final builder = ScriptBuilderFactory.getBuilder(isWindows);
|
||||
|
||||
@@ -20,11 +20,11 @@ ServerCustom _$ServerCustomFromJson(Map<String, dynamic> json) => ServerCustom(
|
||||
|
||||
Map<String, dynamic> _$ServerCustomToJson(ServerCustom instance) =>
|
||||
<String, dynamic>{
|
||||
'pveAddr': ?instance.pveAddr,
|
||||
if (instance.pveAddr case final value?) 'pveAddr': value,
|
||||
'pveIgnoreCert': instance.pveIgnoreCert,
|
||||
'cmds': ?instance.cmds,
|
||||
'preferTempDev': ?instance.preferTempDev,
|
||||
'logoUrl': ?instance.logoUrl,
|
||||
'netDev': ?instance.netDev,
|
||||
'scriptDir': ?instance.scriptDir,
|
||||
if (instance.cmds case final value?) 'cmds': value,
|
||||
if (instance.preferTempDev case final value?) 'preferTempDev': value,
|
||||
if (instance.logoUrl case final value?) 'logoUrl': value,
|
||||
if (instance.netDev case final value?) 'netDev': value,
|
||||
if (instance.scriptDir case final value?) 'scriptDir': value,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:server_box/data/model/app/scripts/cmd_types.dart';
|
||||
import 'package:server_box/data/model/server/amd.dart';
|
||||
@@ -11,25 +10,9 @@ import 'package:server_box/data/model/server/memory.dart';
|
||||
import 'package:server_box/data/model/server/net_speed.dart';
|
||||
import 'package:server_box/data/model/server/nvdia.dart';
|
||||
import 'package:server_box/data/model/server/sensors.dart';
|
||||
import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/data/model/server/system.dart';
|
||||
import 'package:server_box/data/model/server/temp.dart';
|
||||
|
||||
class Server {
|
||||
Spi spi;
|
||||
ServerStatus status;
|
||||
SSHClient? client;
|
||||
ServerConn conn;
|
||||
|
||||
Server(this.spi, this.status, this.conn, {this.client});
|
||||
|
||||
bool get needGenClient => conn < ServerConn.connecting;
|
||||
|
||||
bool get canViewDetails => conn == ServerConn.finished;
|
||||
|
||||
String get id => spi.id;
|
||||
}
|
||||
|
||||
class ServerStatus {
|
||||
Cpus cpu;
|
||||
Memory mem;
|
||||
|
||||
@@ -4,10 +4,8 @@ import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:server_box/data/model/app/error.dart';
|
||||
import 'package:server_box/data/model/server/custom.dart';
|
||||
import 'package:server_box/data/model/server/server.dart';
|
||||
import 'package:server_box/data/model/server/system.dart';
|
||||
import 'package:server_box/data/model/server/wol_cfg.dart';
|
||||
import 'package:server_box/data/provider/server.dart';
|
||||
import 'package:server_box/data/store/server.dart';
|
||||
|
||||
part 'server_private_info.freezed.dart';
|
||||
@@ -87,9 +85,6 @@ extension Spix on Spi {
|
||||
|
||||
String toJsonString() => json.encode(toJson());
|
||||
|
||||
VNode<Server>? get server => ServerProvider.pick(spi: this);
|
||||
VNode<Server>? get jumpServer => ServerProvider.pick(id: jumpId);
|
||||
|
||||
bool shouldReconnect(Spi old) {
|
||||
return user != old.user ||
|
||||
ip != old.ip ||
|
||||
|
||||
@@ -41,18 +41,19 @@ Map<String, dynamic> _$SpiToJson(_Spi instance) => <String, dynamic>{
|
||||
'ip': instance.ip,
|
||||
'port': instance.port,
|
||||
'user': instance.user,
|
||||
'pwd': ?instance.pwd,
|
||||
'pubKeyId': ?instance.keyId,
|
||||
'tags': ?instance.tags,
|
||||
'alterUrl': ?instance.alterUrl,
|
||||
if (instance.pwd case final value?) 'pwd': value,
|
||||
if (instance.keyId case final value?) 'pubKeyId': value,
|
||||
if (instance.tags case final value?) 'tags': value,
|
||||
if (instance.alterUrl case final value?) 'alterUrl': value,
|
||||
'autoConnect': instance.autoConnect,
|
||||
'jumpId': ?instance.jumpId,
|
||||
'custom': ?instance.custom,
|
||||
'wolCfg': ?instance.wolCfg,
|
||||
'envs': ?instance.envs,
|
||||
if (instance.jumpId case final value?) 'jumpId': value,
|
||||
if (instance.custom case final value?) 'custom': value,
|
||||
if (instance.wolCfg case final value?) 'wolCfg': value,
|
||||
if (instance.envs case final value?) 'envs': value,
|
||||
'id': instance.id,
|
||||
'customSystemType': ?_$SystemTypeEnumMap[instance.customSystemType],
|
||||
'disabledCmdTypes': ?instance.disabledCmdTypes,
|
||||
if (_$SystemTypeEnumMap[instance.customSystemType] case final value?)
|
||||
'customSystemType': value,
|
||||
if (instance.disabledCmdTypes case final value?) 'disabledCmdTypes': value,
|
||||
};
|
||||
|
||||
const _$SystemTypeEnumMap = {
|
||||
|
||||
@@ -16,5 +16,5 @@ Map<String, dynamic> _$WakeOnLanCfgToJson(WakeOnLanCfg instance) =>
|
||||
<String, dynamic>{
|
||||
'mac': instance.mac,
|
||||
'ip': instance.ip,
|
||||
'pwd': ?instance.pwd,
|
||||
if (instance.pwd case final value?) 'pwd': value,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user