fix: cloud sync (#769)

This commit is contained in:
lollipopkit🏳️‍⚧️
2025-06-04 00:11:31 +08:00
committed by GitHub
parent 9547d92ac5
commit 0c1ada0067
70 changed files with 2348 additions and 1906 deletions

View File

@@ -1,37 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'backup.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Backup _$BackupFromJson(Map<String, dynamic> json) => Backup(
version: (json['version'] as num).toInt(),
date: json['date'] as String,
spis: (json['spis'] as List<dynamic>)
.map((e) => Spi.fromJson(e as Map<String, dynamic>))
.toList(),
snippets: (json['snippets'] as List<dynamic>)
.map((e) => Snippet.fromJson(e as Map<String, dynamic>))
.toList(),
keys: (json['keys'] as List<dynamic>)
.map((e) => PrivateKeyInfo.fromJson(e as Map<String, dynamic>))
.toList(),
container: json['container'] as Map<String, dynamic>,
history: json['history'] as Map<String, dynamic>,
settings: json['settings'] as Map<String, dynamic>?,
lastModTime: (json['lastModTime'] as num?)?.toInt(),
);
Map<String, dynamic> _$BackupToJson(Backup instance) => <String, dynamic>{
'version': instance.version,
'date': instance.date,
'spis': instance.spis,
'snippets': instance.snippets,
'keys': instance.keys,
'container': instance.container,
'history': instance.history,
'lastModTime': instance.lastModTime,
'settings': instance.settings,
};

View File

@@ -46,7 +46,7 @@ class Backup implements Mergeable {
Map<String, dynamic> toJson() => _$BackupToJson(this);
static Future<Backup> loadFromStore() async {
final lastModTime = Stores.lastModTime?.millisecondsSinceEpoch;
final lastModTime = Stores.lastModTime;
return Backup(
version: backupFormatVersion,
date: DateTime.now().toString().split('.').firstOrNull ?? '',
@@ -70,7 +70,7 @@ class Backup implements Mergeable {
@override
Future<void> merge({bool force = false}) async {
final curTime = Stores.lastModTime?.millisecondsSinceEpoch ?? 0;
final curTime = Stores.lastModTime;
final bakTime = lastModTime ?? 0;
final shouldRestore = force || curTime < bakTime;
if (!shouldRestore) {
@@ -234,3 +234,4 @@ String _diyDecrypt(String raw) {
rethrow;
}
}

View File

@@ -0,0 +1,37 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'backup.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Backup _$BackupFromJson(Map<String, dynamic> json) => Backup(
version: (json['version'] as num).toInt(),
date: json['date'] as String,
spis: (json['spis'] as List<dynamic>)
.map((e) => Spi.fromJson(e as Map<String, dynamic>))
.toList(),
snippets: (json['snippets'] as List<dynamic>)
.map((e) => Snippet.fromJson(e as Map<String, dynamic>))
.toList(),
keys: (json['keys'] as List<dynamic>)
.map((e) => PrivateKeyInfo.fromJson(e as Map<String, dynamic>))
.toList(),
container: json['container'] as Map<String, dynamic>,
history: json['history'] as Map<String, dynamic>,
settings: json['settings'] as Map<String, dynamic>?,
lastModTime: (json['lastModTime'] as num?)?.toInt(),
);
Map<String, dynamic> _$BackupToJson(Backup instance) => <String, dynamic>{
'version': instance.version,
'date': instance.date,
'spis': instance.spis,
'snippets': instance.snippets,
'keys': instance.keys,
'container': instance.container,
'history': instance.history,
'lastModTime': instance.lastModTime,
'settings': instance.settings,
};

View File

@@ -0,0 +1,89 @@
import 'dart:convert';
import 'dart:io';
import 'package:fl_lib/fl_lib.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:logging/logging.dart';
import 'package:server_box/data/res/misc.dart';
import 'package:server_box/data/res/store.dart';
part 'backup2.freezed.dart';
part 'backup2.g.dart';
final _loggerV2 = Logger('BackupV2');
@freezed
abstract class BackupV2 with _$BackupV2 implements Mergeable {
const BackupV2._();
/// Construct a backup with the latest format (v2).
///
/// All `Map<String, dynamic>` are:
/// ```json
/// {
/// "key1": Model{},
/// "_lastModTime": {
/// "key1": 1234567890,
/// },
/// }
/// ```
const factory BackupV2({
required int version,
required int date,
required Map<String, Object?> spis,
required Map<String, Object?> snippets,
required Map<String, Object?> keys,
required Map<String, Object?> container,
required Map<String, Object?> history,
required Map<String, Object?> settings,
}) = _BackupV2;
factory BackupV2.fromJson(Map<String, dynamic> json) => _$BackupV2FromJson(json);
@override
Future<void> merge({bool force = false}) async {
_loggerV2.info('Merging...');
// Merge each store
await Mergeable.mergeStore(backupData: spis, store: Stores.server, force: force);
await Mergeable.mergeStore(backupData: snippets, store: Stores.snippet, force: force);
await Mergeable.mergeStore(backupData: keys, store: Stores.key, force: force);
await Mergeable.mergeStore(backupData: container, store: Stores.container, force: force);
await Mergeable.mergeStore(backupData: history, store: Stores.history, force: force);
await Mergeable.mergeStore(backupData: settings, store: Stores.setting, force: force);
// Reload providers and notify listeners
Provider.reload();
RNodes.app.notify();
_loggerV2.info('Merge completed');
}
static const formatVer = 2;
static Future<BackupV2> loadFromStore() async {
return BackupV2(
version: formatVer,
date: DateTimeX.timestamp,
spis: Stores.server.getAllMap(includeInternalKeys: true),
snippets: Stores.snippet.getAllMap(includeInternalKeys: true),
keys: Stores.key.getAllMap(includeInternalKeys: true),
container: Stores.container.getAllMap(includeInternalKeys: true),
history: Stores.history.getAllMap(includeInternalKeys: true),
settings: Stores.setting.getAllMap(includeInternalKeys: true),
);
}
static Future<String> backup([String? name]) async {
final bak = await BackupV2.loadFromStore();
final result = json.encode(bak.toJson());
final path = Paths.doc.joinPath(name ?? Miscs.bakFileName);
await File(path).writeAsString(result);
return path;
}
factory BackupV2.fromJsonString(String jsonString) {
final map = json.decode(jsonString) as Map<String, dynamic>;
return BackupV2.fromJson(map);
}
}

View File

@@ -0,0 +1,372 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'backup2.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
BackupV2 _$BackupV2FromJson(Map<String, dynamic> json) {
return _BackupV2.fromJson(json);
}
/// @nodoc
mixin _$BackupV2 {
int get version => throw _privateConstructorUsedError;
int get date => throw _privateConstructorUsedError;
Map<String, Object?> get spis => throw _privateConstructorUsedError;
Map<String, Object?> get snippets => throw _privateConstructorUsedError;
Map<String, Object?> get keys => throw _privateConstructorUsedError;
Map<String, Object?> get container => throw _privateConstructorUsedError;
Map<String, Object?> get history => throw _privateConstructorUsedError;
Map<String, Object?> get settings => throw _privateConstructorUsedError;
/// Serializes this BackupV2 to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of BackupV2
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$BackupV2CopyWith<BackupV2> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $BackupV2CopyWith<$Res> {
factory $BackupV2CopyWith(BackupV2 value, $Res Function(BackupV2) then) =
_$BackupV2CopyWithImpl<$Res, BackupV2>;
@useResult
$Res call({
int version,
int date,
Map<String, Object?> spis,
Map<String, Object?> snippets,
Map<String, Object?> keys,
Map<String, Object?> container,
Map<String, Object?> history,
Map<String, Object?> settings,
});
}
/// @nodoc
class _$BackupV2CopyWithImpl<$Res, $Val extends BackupV2>
implements $BackupV2CopyWith<$Res> {
_$BackupV2CopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of BackupV2
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? version = null,
Object? date = null,
Object? spis = null,
Object? snippets = null,
Object? keys = null,
Object? container = null,
Object? history = null,
Object? settings = null,
}) {
return _then(
_value.copyWith(
version: null == version
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as int,
date: null == date
? _value.date
: date // ignore: cast_nullable_to_non_nullable
as int,
spis: null == spis
? _value.spis
: spis // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
snippets: null == snippets
? _value.snippets
: snippets // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
keys: null == keys
? _value.keys
: keys // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
container: null == container
? _value.container
: container // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
history: null == history
? _value.history
: history // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
settings: null == settings
? _value.settings
: settings // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$BackupV2ImplCopyWith<$Res>
implements $BackupV2CopyWith<$Res> {
factory _$$BackupV2ImplCopyWith(
_$BackupV2Impl value,
$Res Function(_$BackupV2Impl) then,
) = __$$BackupV2ImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
int version,
int date,
Map<String, Object?> spis,
Map<String, Object?> snippets,
Map<String, Object?> keys,
Map<String, Object?> container,
Map<String, Object?> history,
Map<String, Object?> settings,
});
}
/// @nodoc
class __$$BackupV2ImplCopyWithImpl<$Res>
extends _$BackupV2CopyWithImpl<$Res, _$BackupV2Impl>
implements _$$BackupV2ImplCopyWith<$Res> {
__$$BackupV2ImplCopyWithImpl(
_$BackupV2Impl _value,
$Res Function(_$BackupV2Impl) _then,
) : super(_value, _then);
/// Create a copy of BackupV2
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? version = null,
Object? date = null,
Object? spis = null,
Object? snippets = null,
Object? keys = null,
Object? container = null,
Object? history = null,
Object? settings = null,
}) {
return _then(
_$BackupV2Impl(
version: null == version
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as int,
date: null == date
? _value.date
: date // ignore: cast_nullable_to_non_nullable
as int,
spis: null == spis
? _value._spis
: spis // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
snippets: null == snippets
? _value._snippets
: snippets // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
keys: null == keys
? _value._keys
: keys // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
container: null == container
? _value._container
: container // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
history: null == history
? _value._history
: history // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
settings: null == settings
? _value._settings
: settings // ignore: cast_nullable_to_non_nullable
as Map<String, Object?>,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$BackupV2Impl extends _BackupV2 {
const _$BackupV2Impl({
required this.version,
required this.date,
required final Map<String, Object?> spis,
required final Map<String, Object?> snippets,
required final Map<String, Object?> keys,
required final Map<String, Object?> container,
required final Map<String, Object?> history,
required final Map<String, Object?> settings,
}) : _spis = spis,
_snippets = snippets,
_keys = keys,
_container = container,
_history = history,
_settings = settings,
super._();
factory _$BackupV2Impl.fromJson(Map<String, dynamic> json) =>
_$$BackupV2ImplFromJson(json);
@override
final int version;
@override
final int date;
final Map<String, Object?> _spis;
@override
Map<String, Object?> get spis {
if (_spis is EqualUnmodifiableMapView) return _spis;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_spis);
}
final Map<String, Object?> _snippets;
@override
Map<String, Object?> get snippets {
if (_snippets is EqualUnmodifiableMapView) return _snippets;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_snippets);
}
final Map<String, Object?> _keys;
@override
Map<String, Object?> get keys {
if (_keys is EqualUnmodifiableMapView) return _keys;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_keys);
}
final Map<String, Object?> _container;
@override
Map<String, Object?> get container {
if (_container is EqualUnmodifiableMapView) return _container;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_container);
}
final Map<String, Object?> _history;
@override
Map<String, Object?> get history {
if (_history is EqualUnmodifiableMapView) return _history;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_history);
}
final Map<String, Object?> _settings;
@override
Map<String, Object?> get settings {
if (_settings is EqualUnmodifiableMapView) return _settings;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_settings);
}
@override
String toString() {
return 'BackupV2(version: $version, date: $date, spis: $spis, snippets: $snippets, keys: $keys, container: $container, history: $history, settings: $settings)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$BackupV2Impl &&
(identical(other.version, version) || other.version == version) &&
(identical(other.date, date) || other.date == date) &&
const DeepCollectionEquality().equals(other._spis, _spis) &&
const DeepCollectionEquality().equals(other._snippets, _snippets) &&
const DeepCollectionEquality().equals(other._keys, _keys) &&
const DeepCollectionEquality().equals(
other._container,
_container,
) &&
const DeepCollectionEquality().equals(other._history, _history) &&
const DeepCollectionEquality().equals(other._settings, _settings));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
version,
date,
const DeepCollectionEquality().hash(_spis),
const DeepCollectionEquality().hash(_snippets),
const DeepCollectionEquality().hash(_keys),
const DeepCollectionEquality().hash(_container),
const DeepCollectionEquality().hash(_history),
const DeepCollectionEquality().hash(_settings),
);
/// Create a copy of BackupV2
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$BackupV2ImplCopyWith<_$BackupV2Impl> get copyWith =>
__$$BackupV2ImplCopyWithImpl<_$BackupV2Impl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$BackupV2ImplToJson(this);
}
}
abstract class _BackupV2 extends BackupV2 {
const factory _BackupV2({
required final int version,
required final int date,
required final Map<String, Object?> spis,
required final Map<String, Object?> snippets,
required final Map<String, Object?> keys,
required final Map<String, Object?> container,
required final Map<String, Object?> history,
required final Map<String, Object?> settings,
}) = _$BackupV2Impl;
const _BackupV2._() : super._();
factory _BackupV2.fromJson(Map<String, dynamic> json) =
_$BackupV2Impl.fromJson;
@override
int get version;
@override
int get date;
@override
Map<String, Object?> get spis;
@override
Map<String, Object?> get snippets;
@override
Map<String, Object?> get keys;
@override
Map<String, Object?> get container;
@override
Map<String, Object?> get history;
@override
Map<String, Object?> get settings;
/// Create a copy of BackupV2
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$BackupV2ImplCopyWith<_$BackupV2Impl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,31 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'backup2.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$BackupV2Impl _$$BackupV2ImplFromJson(Map<String, dynamic> json) =>
_$BackupV2Impl(
version: (json['version'] as num).toInt(),
date: (json['date'] as num).toInt(),
spis: json['spis'] as Map<String, dynamic>,
snippets: json['snippets'] as Map<String, dynamic>,
keys: json['keys'] as Map<String, dynamic>,
container: json['container'] as Map<String, dynamic>,
history: json['history'] as Map<String, dynamic>,
settings: json['settings'] as Map<String, dynamic>,
);
Map<String, dynamic> _$$BackupV2ImplToJson(_$BackupV2Impl instance) =>
<String, dynamic>{
'version': instance.version,
'date': instance.date,
'spis': instance.spis,
'snippets': instance.snippets,
'keys': instance.keys,
'container': instance.container,
'history': instance.history,
'settings': instance.settings,
};

View File

@@ -0,0 +1,15 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:server_box/data/model/app/bak/backup.dart';
import 'package:server_box/data/model/app/bak/backup2.dart';
abstract final class MergeableUtils {
static (Mergeable, String) fromJsonString(String json) {
try {
final bak = BackupV2.fromJsonString(json);
return (bak, DateTime.fromMillisecondsSinceEpoch(bak.date).hms());
} catch (e) {
final bak = Backup.fromJsonString(json);
return (bak, bak.date);
}
}
}

View File

@@ -1,26 +1,5 @@
import 'package:server_box/core/extension/context/locale.dart';
enum ErrFrom {
unknown,
apt,
docker,
sftp,
ssh,
status,
icloud,
webdav,
;
}
abstract class Err<T> {
final ErrFrom from;
final T type;
final String? message;
String? get solution;
Err({required this.from, required this.type, this.message});
}
import 'package:fl_lib/fl_lib.dart';
enum SSHErrType {
unknown,
@@ -35,7 +14,7 @@ enum SSHErrType {
}
class SSHErr extends Err<SSHErrType> {
SSHErr({required super.type, super.message}) : super(from: ErrFrom.ssh);
SSHErr({required super.type, super.message});
@override
String? get solution => switch (type) {
@@ -45,11 +24,6 @@ class SSHErr extends Err<SSHErrType> {
SSHErrType.noPrivateKey => l10n.noPrivateKeyTip,
_ => null,
};
@override
String toString() {
return 'SSHErr<$type>: $message';
}
}
enum ContainerErrType {
@@ -65,16 +39,10 @@ enum ContainerErrType {
}
class ContainerErr extends Err<ContainerErrType> {
ContainerErr({required super.type, super.message})
: super(from: ErrFrom.docker);
ContainerErr({required super.type, super.message});
@override
String? get solution => null;
@override
String toString() {
return 'ContainerErr<$type>: $message';
}
}
enum ICloudErrType {
@@ -84,15 +52,10 @@ enum ICloudErrType {
}
class ICloudErr extends Err<ICloudErrType> {
ICloudErr({required super.type, super.message}) : super(from: ErrFrom.icloud);
ICloudErr({required super.type, super.message});
@override
String? get solution => null;
@override
String toString() {
return 'ICloudErr<$type>: $message';
}
}
enum WebdavErrType {
@@ -102,15 +65,10 @@ enum WebdavErrType {
}
class WebdavErr extends Err<WebdavErrType> {
WebdavErr({required super.type, super.message}) : super(from: ErrFrom.webdav);
WebdavErr({required super.type, super.message});
@override
String? get solution => null;
@override
String toString() {
return 'WebdavErr<$type>: $message';
}
}
enum PveErrType {
@@ -121,13 +79,8 @@ enum PveErrType {
}
class PveErr extends Err<PveErrType> {
PveErr({required super.type, super.message}) : super(from: ErrFrom.status);
PveErr({required super.type, super.message});
@override
String? get solution => null;
@override
String toString() {
return 'PveErr<$type>: $message';
}
}

View File

@@ -1,36 +1,23 @@
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:server_box/core/extension/context/locale.dart';
import 'package:server_box/data/res/store.dart';
part 'server_func.g.dart';
@HiveType(typeId: 6)
enum ServerFuncBtn {
@HiveField(0)
terminal._(),
@HiveField(1)
sftp._(),
@HiveField(2)
container._(),
@HiveField(3)
process._(),
//@HiveField(4)
//pkg,
@HiveField(5)
snippet._(),
@HiveField(6)
iperf._(),
// @HiveField(7)
// pve,
@HiveField(8)
systemd._(1058),
terminal(),
sftp(),
container(),
process(),
//pkg(),
snippet(),
iperf(),
// pve(),
systemd(1058),
;
final int? addedVersion;
const ServerFuncBtn._([this.addedVersion]);
const ServerFuncBtn([this.addedVersion]);
static void autoAddNewFuncs(int cur) {
if (cur >= systemd.addedVersion!) {

View File

@@ -1,71 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'server_func.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class ServerFuncBtnAdapter extends TypeAdapter<ServerFuncBtn> {
@override
final int typeId = 6;
@override
ServerFuncBtn read(BinaryReader reader) {
switch (reader.readByte()) {
case 0:
return ServerFuncBtn.terminal;
case 1:
return ServerFuncBtn.sftp;
case 2:
return ServerFuncBtn.container;
case 3:
return ServerFuncBtn.process;
case 5:
return ServerFuncBtn.snippet;
case 6:
return ServerFuncBtn.iperf;
case 8:
return ServerFuncBtn.systemd;
default:
return ServerFuncBtn.terminal;
}
}
@override
void write(BinaryWriter writer, ServerFuncBtn obj) {
switch (obj) {
case ServerFuncBtn.terminal:
writer.writeByte(0);
break;
case ServerFuncBtn.sftp:
writer.writeByte(1);
break;
case ServerFuncBtn.container:
writer.writeByte(2);
break;
case ServerFuncBtn.process:
writer.writeByte(3);
break;
case ServerFuncBtn.snippet:
writer.writeByte(5);
break;
case ServerFuncBtn.iperf:
writer.writeByte(6);
break;
case ServerFuncBtn.systemd:
writer.writeByte(8);
break;
}
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ServerFuncBtnAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -1,17 +1,10 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:server_box/core/extension/context/locale.dart';
import 'package:server_box/data/model/server/server.dart';
part 'net_view.g.dart';
@HiveType(typeId: 5)
enum NetViewType {
@HiveField(0)
conn,
@HiveField(1)
speed,
@HiveField(2)
traffic;
NetViewType get next => switch (this) {

View File

@@ -1,51 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'net_view.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class NetViewTypeAdapter extends TypeAdapter<NetViewType> {
@override
final int typeId = 5;
@override
NetViewType read(BinaryReader reader) {
switch (reader.readByte()) {
case 0:
return NetViewType.conn;
case 1:
return NetViewType.speed;
case 2:
return NetViewType.traffic;
default:
return NetViewType.conn;
}
}
@override
void write(BinaryWriter writer, NetViewType obj) {
switch (obj) {
case NetViewType.conn:
writer.writeByte(0);
break;
case NetViewType.speed:
writer.writeByte(1);
break;
case NetViewType.traffic:
writer.writeByte(2);
break;
}
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NetViewTypeAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -1,24 +0,0 @@
import 'dart:async';
class SyncResult<T, E> {
final List<T> up;
final List<T> down;
final Map<T, E> err;
const SyncResult({
required this.up,
required this.down,
required this.err,
});
@override
String toString() {
return 'SyncResult{up: $up, down: $down, err: $err}';
}
}
abstract class SyncIface<T> {
/// Merge [other] into [this], return [this] after merge.
/// Data in [other] has higher priority than [this].
FutureOr<void> sync(T other);
}

View File

@@ -1,32 +1,27 @@
import 'package:hive_flutter/adapters.dart';
import 'package:json_annotation/json_annotation.dart';
part 'custom.g.dart';
@JsonSerializable()
@HiveType(typeId: 7)
@JsonSerializable(includeIfNull: false)
final class ServerCustom {
// @HiveField(0)
// final String? temperature;
@HiveField(1)
final String? pveAddr;
@HiveField(2, defaultValue: false)
final bool pveIgnoreCert;
/// {"title": "cmd"}
@HiveField(3)
final Map<String, String>? cmds;
@HiveField(4)
final String? preferTempDev;
@HiveField(5)
final String? logoUrl;
/// The device name of the network interface displayed in the home server card.
@HiveField(6)
final String? netDev;
/// The directory where the script is stored.
@HiveField(7)
final String? scriptDir;
const ServerCustom({
@@ -40,8 +35,7 @@ final class ServerCustom {
this.scriptDir,
});
factory ServerCustom.fromJson(Map<String, dynamic> json) =>
_$ServerCustomFromJson(json);
factory ServerCustom.fromJson(Map<String, dynamic> json) => _$ServerCustomFromJson(json);
Map<String, dynamic> toJson() => _$ServerCustomToJson(this);

View File

@@ -2,85 +2,29 @@
part of 'custom.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class ServerCustomAdapter extends TypeAdapter<ServerCustom> {
@override
final int typeId = 7;
@override
ServerCustom read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return ServerCustom(
pveAddr: fields[1] as String?,
pveIgnoreCert: fields[2] == null ? false : fields[2] as bool,
cmds: (fields[3] as Map?)?.cast<String, String>(),
preferTempDev: fields[4] as String?,
logoUrl: fields[5] as String?,
netDev: fields[6] as String?,
scriptDir: fields[7] as String?,
);
}
@override
void write(BinaryWriter writer, ServerCustom obj) {
writer
..writeByte(7)
..writeByte(1)
..write(obj.pveAddr)
..writeByte(2)
..write(obj.pveIgnoreCert)
..writeByte(3)
..write(obj.cmds)
..writeByte(4)
..write(obj.preferTempDev)
..writeByte(5)
..write(obj.logoUrl)
..writeByte(6)
..write(obj.netDev)
..writeByte(7)
..write(obj.scriptDir);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ServerCustomAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
ServerCustom _$ServerCustomFromJson(Map<String, dynamic> json) => ServerCustom(
pveAddr: json['pveAddr'] as String?,
pveIgnoreCert: json['pveIgnoreCert'] as bool? ?? false,
cmds: (json['cmds'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as String),
),
preferTempDev: json['preferTempDev'] as String?,
logoUrl: json['logoUrl'] as String?,
netDev: json['netDev'] as String?,
scriptDir: json['scriptDir'] as String?,
);
pveAddr: json['pveAddr'] as String?,
pveIgnoreCert: json['pveIgnoreCert'] as bool? ?? false,
cmds: (json['cmds'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as String),
),
preferTempDev: json['preferTempDev'] as String?,
logoUrl: json['logoUrl'] as String?,
netDev: json['netDev'] as String?,
scriptDir: json['scriptDir'] as String?,
);
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,
};

View File

@@ -1,15 +1,11 @@
import 'package:hive_flutter/hive_flutter.dart';
import 'package:json_annotation/json_annotation.dart';
part 'private_key_info.g.dart';
@JsonSerializable()
@HiveType(typeId: 1)
class PrivateKeyInfo {
@HiveField(0)
final String id;
@JsonKey(name: 'private_key')
@HiveField(1)
final String key;
const PrivateKeyInfo({
@@ -17,8 +13,7 @@ class PrivateKeyInfo {
required this.key,
});
factory PrivateKeyInfo.fromJson(Map<String, dynamic> json) =>
_$PrivateKeyInfoFromJson(json);
factory PrivateKeyInfo.fromJson(Map<String, dynamic> json) => _$PrivateKeyInfoFromJson(json);
Map<String, dynamic> toJson() => _$PrivateKeyInfoToJson(this);

View File

@@ -2,47 +2,6 @@
part of 'private_key_info.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class PrivateKeyInfoAdapter extends TypeAdapter<PrivateKeyInfo> {
@override
final int typeId = 1;
@override
PrivateKeyInfo read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return PrivateKeyInfo(
id: fields[0] as String,
key: fields[1] as String,
);
}
@override
void write(BinaryWriter writer, PrivateKeyInfo obj) {
writer
..writeByte(2)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.key);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PrivateKeyInfoAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
@@ -54,7 +13,4 @@ PrivateKeyInfo _$PrivateKeyInfoFromJson(Map<String, dynamic> json) =>
);
Map<String, dynamic> _$PrivateKeyInfoToJson(PrivateKeyInfo instance) =>
<String, dynamic>{
'id': instance.id,
'private_key': instance.key,
};
<String, dynamic>{'id': instance.id, 'private_key': instance.key};

View File

@@ -1,5 +1,5 @@
import 'package:dartssh2/dartssh2.dart';
import 'package:server_box/data/model/app/error.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:server_box/data/model/app/shell_func.dart';
import 'package:server_box/data/model/server/battery.dart';
import 'package:server_box/data/model/server/conn.dart';

View File

@@ -2,7 +2,7 @@ import 'dart:convert';
import 'package:fl_lib/fl_lib.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:hive_ce_flutter/hive_flutter.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/wol_cfg.dart';
@@ -20,31 +20,31 @@ part 'server_private_info.freezed.dart';
/// Some params named as `spi` in the codebase which is the abbreviation of `ServerPrivateInfo`.
///
/// Nowaday, more fields are added to this class, and it's renamed to `Spi`.
@freezed
@HiveType(typeId: 3)
@Freezed(fromJson: false)
@JsonSerializable(includeIfNull: false)
class Spi with _$Spi {
const Spi._();
const factory Spi({
@HiveField(0) required String name,
@HiveField(1) required String ip,
@HiveField(2) required int port,
@HiveField(3) required String user,
@HiveField(4) String? pwd,
required String name,
required String ip,
required int port,
required String user,
String? pwd,
/// [id] of private key
@JsonKey(name: 'pubKeyId') @HiveField(5) String? keyId,
@HiveField(6) List<String>? tags,
@HiveField(7) String? alterUrl,
@HiveField(8, defaultValue: true) @Default(true) bool autoConnect,
@JsonKey(name: 'pubKeyId') String? keyId,
List<String>? tags,
String? alterUrl,
@Default(true) @JsonKey(defaultValue: true) bool autoConnect,
/// [id] of the jump server
@HiveField(9) String? jumpId,
@HiveField(10) ServerCustom? custom,
@HiveField(11) WakeOnLanCfg? wolCfg,
String? jumpId,
ServerCustom? custom,
WakeOnLanCfg? wolCfg,
/// It only applies to SSH terminal.
@HiveField(12) Map<String, String>? envs,
Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId) @HiveField(13, defaultValue: '') required String id,
}) = _Spi;

View File

@@ -12,46 +12,31 @@ part of 'server_private_info.dart';
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
Spi _$SpiFromJson(Map<String, dynamic> json) {
return _Spi.fromJson(json);
}
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$Spi {
@HiveField(0)
String get name => throw _privateConstructorUsedError;
@HiveField(1)
String get ip => throw _privateConstructorUsedError;
@HiveField(2)
int get port => throw _privateConstructorUsedError;
@HiveField(3)
String get user => throw _privateConstructorUsedError;
@HiveField(4)
String? get pwd => throw _privateConstructorUsedError;
/// [id] of private key
@JsonKey(name: 'pubKeyId')
@HiveField(5)
String? get keyId => throw _privateConstructorUsedError;
@HiveField(6)
List<String>? get tags => throw _privateConstructorUsedError;
@HiveField(7)
String? get alterUrl => throw _privateConstructorUsedError;
@HiveField(8, defaultValue: true)
@JsonKey(defaultValue: true)
bool get autoConnect => throw _privateConstructorUsedError;
/// [id] of the jump server
@HiveField(9)
String? get jumpId => throw _privateConstructorUsedError;
@HiveField(10)
ServerCustom? get custom => throw _privateConstructorUsedError;
@HiveField(11)
WakeOnLanCfg? get wolCfg => throw _privateConstructorUsedError;
/// It only applies to SSH terminal.
@HiveField(12)
Map<String, String>? get envs => throw _privateConstructorUsedError;
@JsonKey(fromJson: Spi.parseId)
@HiveField(13, defaultValue: '')
@@ -71,23 +56,22 @@ abstract class $SpiCopyWith<$Res> {
factory $SpiCopyWith(Spi value, $Res Function(Spi) then) =
_$SpiCopyWithImpl<$Res, Spi>;
@useResult
$Res call(
{@HiveField(0) String name,
@HiveField(1) String ip,
@HiveField(2) int port,
@HiveField(3) String user,
@HiveField(4) String? pwd,
@JsonKey(name: 'pubKeyId') @HiveField(5) String? keyId,
@HiveField(6) List<String>? tags,
@HiveField(7) String? alterUrl,
@HiveField(8, defaultValue: true) bool autoConnect,
@HiveField(9) String? jumpId,
@HiveField(10) ServerCustom? custom,
@HiveField(11) WakeOnLanCfg? wolCfg,
@HiveField(12) Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId)
@HiveField(13, defaultValue: '')
String id});
$Res call({
String name,
String ip,
int port,
String user,
String? pwd,
@JsonKey(name: 'pubKeyId') String? keyId,
List<String>? tags,
String? alterUrl,
@JsonKey(defaultValue: true) bool autoConnect,
String? jumpId,
ServerCustom? custom,
WakeOnLanCfg? wolCfg,
Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId) @HiveField(13, defaultValue: '') String id,
});
}
/// @nodoc
@@ -119,64 +103,67 @@ class _$SpiCopyWithImpl<$Res, $Val extends Spi> implements $SpiCopyWith<$Res> {
Object? envs = freezed,
Object? id = null,
}) {
return _then(_value.copyWith(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
ip: null == ip
? _value.ip
: ip // ignore: cast_nullable_to_non_nullable
as String,
port: null == port
? _value.port
: port // ignore: cast_nullable_to_non_nullable
as int,
user: null == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as String,
pwd: freezed == pwd
? _value.pwd
: pwd // ignore: cast_nullable_to_non_nullable
as String?,
keyId: freezed == keyId
? _value.keyId
: keyId // ignore: cast_nullable_to_non_nullable
as String?,
tags: freezed == tags
? _value.tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
alterUrl: freezed == alterUrl
? _value.alterUrl
: alterUrl // ignore: cast_nullable_to_non_nullable
as String?,
autoConnect: null == autoConnect
? _value.autoConnect
: autoConnect // ignore: cast_nullable_to_non_nullable
as bool,
jumpId: freezed == jumpId
? _value.jumpId
: jumpId // ignore: cast_nullable_to_non_nullable
as String?,
custom: freezed == custom
? _value.custom
: custom // ignore: cast_nullable_to_non_nullable
as ServerCustom?,
wolCfg: freezed == wolCfg
? _value.wolCfg
: wolCfg // ignore: cast_nullable_to_non_nullable
as WakeOnLanCfg?,
envs: freezed == envs
? _value.envs
: envs // ignore: cast_nullable_to_non_nullable
as Map<String, String>?,
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
return _then(
_value.copyWith(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
ip: null == ip
? _value.ip
: ip // ignore: cast_nullable_to_non_nullable
as String,
port: null == port
? _value.port
: port // ignore: cast_nullable_to_non_nullable
as int,
user: null == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as String,
pwd: freezed == pwd
? _value.pwd
: pwd // ignore: cast_nullable_to_non_nullable
as String?,
keyId: freezed == keyId
? _value.keyId
: keyId // ignore: cast_nullable_to_non_nullable
as String?,
tags: freezed == tags
? _value.tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
alterUrl: freezed == alterUrl
? _value.alterUrl
: alterUrl // ignore: cast_nullable_to_non_nullable
as String?,
autoConnect: null == autoConnect
? _value.autoConnect
: autoConnect // ignore: cast_nullable_to_non_nullable
as bool,
jumpId: freezed == jumpId
? _value.jumpId
: jumpId // ignore: cast_nullable_to_non_nullable
as String?,
custom: freezed == custom
? _value.custom
: custom // ignore: cast_nullable_to_non_nullable
as ServerCustom?,
wolCfg: freezed == wolCfg
? _value.wolCfg
: wolCfg // ignore: cast_nullable_to_non_nullable
as WakeOnLanCfg?,
envs: freezed == envs
? _value.envs
: envs // ignore: cast_nullable_to_non_nullable
as Map<String, String>?,
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
)
as $Val,
);
}
}
@@ -186,30 +173,29 @@ abstract class _$$SpiImplCopyWith<$Res> implements $SpiCopyWith<$Res> {
__$$SpiImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@HiveField(0) String name,
@HiveField(1) String ip,
@HiveField(2) int port,
@HiveField(3) String user,
@HiveField(4) String? pwd,
@JsonKey(name: 'pubKeyId') @HiveField(5) String? keyId,
@HiveField(6) List<String>? tags,
@HiveField(7) String? alterUrl,
@HiveField(8, defaultValue: true) bool autoConnect,
@HiveField(9) String? jumpId,
@HiveField(10) ServerCustom? custom,
@HiveField(11) WakeOnLanCfg? wolCfg,
@HiveField(12) Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId)
@HiveField(13, defaultValue: '')
String id});
$Res call({
String name,
String ip,
int port,
String user,
String? pwd,
@JsonKey(name: 'pubKeyId') String? keyId,
List<String>? tags,
String? alterUrl,
@JsonKey(defaultValue: true) bool autoConnect,
String? jumpId,
ServerCustom? custom,
WakeOnLanCfg? wolCfg,
Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId) @HiveField(13, defaultValue: '') String id,
});
}
/// @nodoc
class __$$SpiImplCopyWithImpl<$Res> extends _$SpiCopyWithImpl<$Res, _$SpiImpl>
implements _$$SpiImplCopyWith<$Res> {
__$$SpiImplCopyWithImpl(_$SpiImpl _value, $Res Function(_$SpiImpl) _then)
: super(_value, _then);
: super(_value, _then);
/// Create a copy of Spi
/// with the given fields replaced by the non-null parameter values.
@@ -231,118 +217,110 @@ class __$$SpiImplCopyWithImpl<$Res> extends _$SpiCopyWithImpl<$Res, _$SpiImpl>
Object? envs = freezed,
Object? id = null,
}) {
return _then(_$SpiImpl(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
ip: null == ip
? _value.ip
: ip // ignore: cast_nullable_to_non_nullable
as String,
port: null == port
? _value.port
: port // ignore: cast_nullable_to_non_nullable
as int,
user: null == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as String,
pwd: freezed == pwd
? _value.pwd
: pwd // ignore: cast_nullable_to_non_nullable
as String?,
keyId: freezed == keyId
? _value.keyId
: keyId // ignore: cast_nullable_to_non_nullable
as String?,
tags: freezed == tags
? _value._tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
alterUrl: freezed == alterUrl
? _value.alterUrl
: alterUrl // ignore: cast_nullable_to_non_nullable
as String?,
autoConnect: null == autoConnect
? _value.autoConnect
: autoConnect // ignore: cast_nullable_to_non_nullable
as bool,
jumpId: freezed == jumpId
? _value.jumpId
: jumpId // ignore: cast_nullable_to_non_nullable
as String?,
custom: freezed == custom
? _value.custom
: custom // ignore: cast_nullable_to_non_nullable
as ServerCustom?,
wolCfg: freezed == wolCfg
? _value.wolCfg
: wolCfg // ignore: cast_nullable_to_non_nullable
as WakeOnLanCfg?,
envs: freezed == envs
? _value._envs
: envs // ignore: cast_nullable_to_non_nullable
as Map<String, String>?,
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
));
return _then(
_$SpiImpl(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
ip: null == ip
? _value.ip
: ip // ignore: cast_nullable_to_non_nullable
as String,
port: null == port
? _value.port
: port // ignore: cast_nullable_to_non_nullable
as int,
user: null == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as String,
pwd: freezed == pwd
? _value.pwd
: pwd // ignore: cast_nullable_to_non_nullable
as String?,
keyId: freezed == keyId
? _value.keyId
: keyId // ignore: cast_nullable_to_non_nullable
as String?,
tags: freezed == tags
? _value._tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
alterUrl: freezed == alterUrl
? _value.alterUrl
: alterUrl // ignore: cast_nullable_to_non_nullable
as String?,
autoConnect: null == autoConnect
? _value.autoConnect
: autoConnect // ignore: cast_nullable_to_non_nullable
as bool,
jumpId: freezed == jumpId
? _value.jumpId
: jumpId // ignore: cast_nullable_to_non_nullable
as String?,
custom: freezed == custom
? _value.custom
: custom // ignore: cast_nullable_to_non_nullable
as ServerCustom?,
wolCfg: freezed == wolCfg
? _value.wolCfg
: wolCfg // ignore: cast_nullable_to_non_nullable
as WakeOnLanCfg?,
envs: freezed == envs
? _value._envs
: envs // ignore: cast_nullable_to_non_nullable
as Map<String, String>?,
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
@JsonSerializable()
@JsonSerializable(createFactory: false)
class _$SpiImpl extends _Spi {
const _$SpiImpl(
{@HiveField(0) required this.name,
@HiveField(1) required this.ip,
@HiveField(2) required this.port,
@HiveField(3) required this.user,
@HiveField(4) this.pwd,
@JsonKey(name: 'pubKeyId') @HiveField(5) this.keyId,
@HiveField(6) final List<String>? tags,
@HiveField(7) this.alterUrl,
@HiveField(8, defaultValue: true) this.autoConnect = true,
@HiveField(9) this.jumpId,
@HiveField(10) this.custom,
@HiveField(11) this.wolCfg,
@HiveField(12) final Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId)
@HiveField(13, defaultValue: '')
required this.id})
: _tags = tags,
_envs = envs,
super._();
factory _$SpiImpl.fromJson(Map<String, dynamic> json) =>
_$$SpiImplFromJson(json);
const _$SpiImpl({
required this.name,
required this.ip,
required this.port,
required this.user,
this.pwd,
@JsonKey(name: 'pubKeyId') this.keyId,
final List<String>? tags,
this.alterUrl,
@JsonKey(defaultValue: true) this.autoConnect = true,
this.jumpId,
this.custom,
this.wolCfg,
final Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId)
@HiveField(13, defaultValue: '')
required this.id,
}) : _tags = tags,
_envs = envs,
super._();
@override
@HiveField(0)
final String name;
@override
@HiveField(1)
final String ip;
@override
@HiveField(2)
final int port;
@override
@HiveField(3)
final String user;
@override
@HiveField(4)
final String? pwd;
/// [id] of private key
@override
@JsonKey(name: 'pubKeyId')
@HiveField(5)
final String? keyId;
final List<String>? _tags;
@override
@HiveField(6)
List<String>? get tags {
final value = _tags;
if (value == null) return null;
@@ -352,22 +330,17 @@ class _$SpiImpl extends _Spi {
}
@override
@HiveField(7)
final String? alterUrl;
@override
@JsonKey()
@HiveField(8, defaultValue: true)
@JsonKey(defaultValue: true)
final bool autoConnect;
/// [id] of the jump server
@override
@HiveField(9)
final String? jumpId;
@override
@HiveField(10)
final ServerCustom? custom;
@override
@HiveField(11)
final WakeOnLanCfg? wolCfg;
/// It only applies to SSH terminal.
@@ -375,7 +348,6 @@ class _$SpiImpl extends _Spi {
/// It only applies to SSH terminal.
@override
@HiveField(12)
Map<String, String>? get envs {
final value = _envs;
if (value == null) return null;
@@ -415,21 +387,22 @@ class _$SpiImpl extends _Spi {
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
name,
ip,
port,
user,
pwd,
keyId,
const DeepCollectionEquality().hash(_tags),
alterUrl,
autoConnect,
jumpId,
custom,
wolCfg,
const DeepCollectionEquality().hash(_envs),
id);
runtimeType,
name,
ip,
port,
user,
pwd,
keyId,
const DeepCollectionEquality().hash(_tags),
alterUrl,
autoConnect,
jumpId,
custom,
wolCfg,
const DeepCollectionEquality().hash(_envs),
id,
);
/// Create a copy of Spi
/// with the given fields replaced by the non-null parameter values.
@@ -441,79 +414,64 @@ class _$SpiImpl extends _Spi {
@override
Map<String, dynamic> toJson() {
return _$$SpiImplToJson(
this,
);
return _$$SpiImplToJson(this);
}
}
abstract class _Spi extends Spi {
const factory _Spi(
{@HiveField(0) required final String name,
@HiveField(1) required final String ip,
@HiveField(2) required final int port,
@HiveField(3) required final String user,
@HiveField(4) final String? pwd,
@JsonKey(name: 'pubKeyId') @HiveField(5) final String? keyId,
@HiveField(6) final List<String>? tags,
@HiveField(7) final String? alterUrl,
@HiveField(8, defaultValue: true) final bool autoConnect,
@HiveField(9) final String? jumpId,
@HiveField(10) final ServerCustom? custom,
@HiveField(11) final WakeOnLanCfg? wolCfg,
@HiveField(12) final Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId)
@HiveField(13, defaultValue: '')
required final String id}) = _$SpiImpl;
const factory _Spi({
required final String name,
required final String ip,
required final int port,
required final String user,
final String? pwd,
@JsonKey(name: 'pubKeyId') final String? keyId,
final List<String>? tags,
final String? alterUrl,
@JsonKey(defaultValue: true) final bool autoConnect,
final String? jumpId,
final ServerCustom? custom,
final WakeOnLanCfg? wolCfg,
final Map<String, String>? envs,
@JsonKey(fromJson: Spi.parseId)
@HiveField(13, defaultValue: '')
required final String id,
}) = _$SpiImpl;
const _Spi._() : super._();
factory _Spi.fromJson(Map<String, dynamic> json) = _$SpiImpl.fromJson;
@override
@HiveField(0)
String get name;
@override
@HiveField(1)
String get ip;
@override
@HiveField(2)
int get port;
@override
@HiveField(3)
String get user;
@override
@HiveField(4)
String? get pwd;
/// [id] of private key
@override
@JsonKey(name: 'pubKeyId')
@HiveField(5)
String? get keyId;
@override
@HiveField(6)
List<String>? get tags;
@override
@HiveField(7)
String? get alterUrl;
@override
@HiveField(8, defaultValue: true)
@JsonKey(defaultValue: true)
bool get autoConnect;
/// [id] of the jump server
@override
@HiveField(9)
String? get jumpId;
@override
@HiveField(10)
ServerCustom? get custom;
@override
@HiveField(11)
WakeOnLanCfg? get wolCfg;
/// It only applies to SSH terminal.
@override
@HiveField(12)
Map<String, String>? get envs;
@override
@JsonKey(fromJson: Spi.parseId)

View File

@@ -2,123 +2,63 @@
part of 'server_private_info.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class SpiAdapter extends TypeAdapter<Spi> {
@override
final int typeId = 3;
@override
Spi read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Spi(
name: fields[0] as String,
ip: fields[1] as String,
port: fields[2] as int,
user: fields[3] as String,
pwd: fields[4] as String?,
keyId: fields[5] as String?,
tags: (fields[6] as List?)?.cast<String>(),
alterUrl: fields[7] as String?,
autoConnect: fields[8] == null ? true : fields[8] as bool,
jumpId: fields[9] as String?,
custom: fields[10] as ServerCustom?,
wolCfg: fields[11] as WakeOnLanCfg?,
envs: (fields[12] as Map?)?.cast<String, String>(),
id: fields[13] == null ? '' : fields[13] as String,
);
}
@override
void write(BinaryWriter writer, Spi obj) {
writer
..writeByte(14)
..writeByte(0)
..write(obj.name)
..writeByte(1)
..write(obj.ip)
..writeByte(2)
..write(obj.port)
..writeByte(3)
..write(obj.user)
..writeByte(4)
..write(obj.pwd)
..writeByte(5)
..write(obj.keyId)
..writeByte(6)
..write(obj.tags)
..writeByte(7)
..write(obj.alterUrl)
..writeByte(8)
..write(obj.autoConnect)
..writeByte(9)
..write(obj.jumpId)
..writeByte(10)
..write(obj.custom)
..writeByte(11)
..write(obj.wolCfg)
..writeByte(12)
..write(obj.envs)
..writeByte(13)
..write(obj.id);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SpiAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$SpiImpl _$$SpiImplFromJson(Map<String, dynamic> json) => _$SpiImpl(
name: json['name'] as String,
ip: json['ip'] as String,
port: (json['port'] as num).toInt(),
user: json['user'] as String,
pwd: json['pwd'] as String?,
keyId: json['pubKeyId'] as String?,
tags: (json['tags'] as List<dynamic>?)?.map((e) => e as String).toList(),
alterUrl: json['alterUrl'] as String?,
autoConnect: json['autoConnect'] as bool? ?? true,
jumpId: json['jumpId'] as String?,
custom: json['custom'] == null
? null
: ServerCustom.fromJson(json['custom'] as Map<String, dynamic>),
wolCfg: json['wolCfg'] == null
? null
: WakeOnLanCfg.fromJson(json['wolCfg'] as Map<String, dynamic>),
envs: (json['envs'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as String),
),
id: Spi.parseId(json['id']),
);
Spi _$SpiFromJson(Map<String, dynamic> json) => Spi(
name: json['name'] as String,
ip: json['ip'] as String,
port: (json['port'] as num).toInt(),
user: json['user'] as String,
pwd: json['pwd'] as String?,
keyId: json['pubKeyId'] as String?,
tags: (json['tags'] as List<dynamic>?)?.map((e) => e as String).toList(),
alterUrl: json['alterUrl'] as String?,
autoConnect: json['autoConnect'] as bool? ?? true,
jumpId: json['jumpId'] as String?,
custom: json['custom'] == null
? null
: ServerCustom.fromJson(json['custom'] as Map<String, dynamic>),
wolCfg: json['wolCfg'] == null
? null
: WakeOnLanCfg.fromJson(json['wolCfg'] as Map<String, dynamic>),
envs: (json['envs'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as String),
),
id: Spi.parseId(json['id']),
);
Map<String, dynamic> _$SpiToJson(Spi instance) => <String, dynamic>{
'name': instance.name,
'ip': instance.ip,
'port': instance.port,
'user': instance.user,
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,
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,
};
Map<String, dynamic> _$$SpiImplToJson(_$SpiImpl instance) => <String, dynamic>{
'name': instance.name,
'ip': instance.ip,
'port': instance.port,
'user': instance.user,
'pwd': instance.pwd,
'pubKeyId': instance.keyId,
'tags': instance.tags,
'alterUrl': instance.alterUrl,
'autoConnect': instance.autoConnect,
'jumpId': instance.jumpId,
'custom': instance.custom,
'wolCfg': instance.wolCfg,
'envs': instance.envs,
'id': instance.id,
};
'name': instance.name,
'ip': instance.ip,
'port': instance.port,
'user': instance.user,
'pwd': instance.pwd,
'pubKeyId': instance.keyId,
'tags': instance.tags,
'alterUrl': instance.alterUrl,
'autoConnect': instance.autoConnect,
'jumpId': instance.jumpId,
'custom': instance.custom,
'wolCfg': instance.wolCfg,
'envs': instance.envs,
'id': instance.id,
};

View File

@@ -2,7 +2,6 @@ import 'dart:async';
import 'package:fl_lib/fl_lib.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:server_box/data/model/server/server_private_info.dart';
import 'package:xterm/core.dart';
@@ -10,20 +9,19 @@ part 'snippet.g.dart';
part 'snippet.freezed.dart';
@freezed
@HiveType(typeId: 2)
class Snippet with _$Snippet {
const factory Snippet({
@HiveField(0) required String name,
@HiveField(1) required String script,
@HiveField(2) List<String>? tags,
@HiveField(3) String? note,
required String name,
required String script,
List<String>? tags,
String? note,
/// List of server id that this snippet should be auto run on
@HiveField(4) List<String>? autoRunOn,
List<String>? autoRunOn,
}) = _Snippet;
factory Snippet.fromJson(Map<String, dynamic> json) => _$SnippetFromJson(json);
static const example = Snippet(
name: 'example',
script: 'echo hello',
@@ -59,7 +57,7 @@ extension SnippetX on Snippet {
/// There is no [TerminalKey] in the script
if (matches.isEmpty) {
terminal.textInput(argsFmted);
terminal.textInput(argsFmted);
if (autoEnter) terminal.keyInput(TerminalKey.enter);
return;
}

View File

@@ -12,7 +12,8 @@ part of 'snippet.dart';
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
Snippet _$SnippetFromJson(Map<String, dynamic> json) {
return _Snippet.fromJson(json);
@@ -20,17 +21,12 @@ Snippet _$SnippetFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$Snippet {
@HiveField(0)
String get name => throw _privateConstructorUsedError;
@HiveField(1)
String get script => throw _privateConstructorUsedError;
@HiveField(2)
List<String>? get tags => throw _privateConstructorUsedError;
@HiveField(3)
String? get note => throw _privateConstructorUsedError;
/// List of server id that this snippet should be auto run on
@HiveField(4)
List<String>? get autoRunOn => throw _privateConstructorUsedError;
/// Serializes this Snippet to a JSON map.
@@ -47,12 +43,13 @@ abstract class $SnippetCopyWith<$Res> {
factory $SnippetCopyWith(Snippet value, $Res Function(Snippet) then) =
_$SnippetCopyWithImpl<$Res, Snippet>;
@useResult
$Res call(
{@HiveField(0) String name,
@HiveField(1) String script,
@HiveField(2) List<String>? tags,
@HiveField(3) String? note,
@HiveField(4) List<String>? autoRunOn});
$Res call({
String name,
String script,
List<String>? tags,
String? note,
List<String>? autoRunOn,
});
}
/// @nodoc
@@ -76,44 +73,49 @@ class _$SnippetCopyWithImpl<$Res, $Val extends Snippet>
Object? note = freezed,
Object? autoRunOn = freezed,
}) {
return _then(_value.copyWith(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
script: null == script
? _value.script
: script // ignore: cast_nullable_to_non_nullable
as String,
tags: freezed == tags
? _value.tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
note: freezed == note
? _value.note
: note // ignore: cast_nullable_to_non_nullable
as String?,
autoRunOn: freezed == autoRunOn
? _value.autoRunOn
: autoRunOn // ignore: cast_nullable_to_non_nullable
as List<String>?,
) as $Val);
return _then(
_value.copyWith(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
script: null == script
? _value.script
: script // ignore: cast_nullable_to_non_nullable
as String,
tags: freezed == tags
? _value.tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
note: freezed == note
? _value.note
: note // ignore: cast_nullable_to_non_nullable
as String?,
autoRunOn: freezed == autoRunOn
? _value.autoRunOn
: autoRunOn // ignore: cast_nullable_to_non_nullable
as List<String>?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$SnippetImplCopyWith<$Res> implements $SnippetCopyWith<$Res> {
factory _$$SnippetImplCopyWith(
_$SnippetImpl value, $Res Function(_$SnippetImpl) then) =
__$$SnippetImplCopyWithImpl<$Res>;
_$SnippetImpl value,
$Res Function(_$SnippetImpl) then,
) = __$$SnippetImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@HiveField(0) String name,
@HiveField(1) String script,
@HiveField(2) List<String>? tags,
@HiveField(3) String? note,
@HiveField(4) List<String>? autoRunOn});
$Res call({
String name,
String script,
List<String>? tags,
String? note,
List<String>? autoRunOn,
});
}
/// @nodoc
@@ -121,8 +123,9 @@ class __$$SnippetImplCopyWithImpl<$Res>
extends _$SnippetCopyWithImpl<$Res, _$SnippetImpl>
implements _$$SnippetImplCopyWith<$Res> {
__$$SnippetImplCopyWithImpl(
_$SnippetImpl _value, $Res Function(_$SnippetImpl) _then)
: super(_value, _then);
_$SnippetImpl _value,
$Res Function(_$SnippetImpl) _then,
) : super(_value, _then);
/// Create a copy of Snippet
/// with the given fields replaced by the non-null parameter values.
@@ -135,55 +138,54 @@ class __$$SnippetImplCopyWithImpl<$Res>
Object? note = freezed,
Object? autoRunOn = freezed,
}) {
return _then(_$SnippetImpl(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
script: null == script
? _value.script
: script // ignore: cast_nullable_to_non_nullable
as String,
tags: freezed == tags
? _value._tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
note: freezed == note
? _value.note
: note // ignore: cast_nullable_to_non_nullable
as String?,
autoRunOn: freezed == autoRunOn
? _value._autoRunOn
: autoRunOn // ignore: cast_nullable_to_non_nullable
as List<String>?,
));
return _then(
_$SnippetImpl(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
script: null == script
? _value.script
: script // ignore: cast_nullable_to_non_nullable
as String,
tags: freezed == tags
? _value._tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>?,
note: freezed == note
? _value.note
: note // ignore: cast_nullable_to_non_nullable
as String?,
autoRunOn: freezed == autoRunOn
? _value._autoRunOn
: autoRunOn // ignore: cast_nullable_to_non_nullable
as List<String>?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$SnippetImpl implements _Snippet {
const _$SnippetImpl(
{@HiveField(0) required this.name,
@HiveField(1) required this.script,
@HiveField(2) final List<String>? tags,
@HiveField(3) this.note,
@HiveField(4) final List<String>? autoRunOn})
: _tags = tags,
_autoRunOn = autoRunOn;
const _$SnippetImpl({
required this.name,
required this.script,
final List<String>? tags,
this.note,
final List<String>? autoRunOn,
}) : _tags = tags,
_autoRunOn = autoRunOn;
factory _$SnippetImpl.fromJson(Map<String, dynamic> json) =>
_$$SnippetImplFromJson(json);
@override
@HiveField(0)
final String name;
@override
@HiveField(1)
final String script;
final List<String>? _tags;
@override
@HiveField(2)
List<String>? get tags {
final value = _tags;
if (value == null) return null;
@@ -193,7 +195,6 @@ class _$SnippetImpl implements _Snippet {
}
@override
@HiveField(3)
final String? note;
/// List of server id that this snippet should be auto run on
@@ -201,7 +202,6 @@ class _$SnippetImpl implements _Snippet {
/// List of server id that this snippet should be auto run on
@override
@HiveField(4)
List<String>? get autoRunOn {
final value = _autoRunOn;
if (value == null) return null;
@@ -224,19 +224,22 @@ class _$SnippetImpl implements _Snippet {
(identical(other.script, script) || other.script == script) &&
const DeepCollectionEquality().equals(other._tags, _tags) &&
(identical(other.note, note) || other.note == note) &&
const DeepCollectionEquality()
.equals(other._autoRunOn, _autoRunOn));
const DeepCollectionEquality().equals(
other._autoRunOn,
_autoRunOn,
));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
name,
script,
const DeepCollectionEquality().hash(_tags),
note,
const DeepCollectionEquality().hash(_autoRunOn));
runtimeType,
name,
script,
const DeepCollectionEquality().hash(_tags),
note,
const DeepCollectionEquality().hash(_autoRunOn),
);
/// Create a copy of Snippet
/// with the given fields replaced by the non-null parameter values.
@@ -248,38 +251,32 @@ class _$SnippetImpl implements _Snippet {
@override
Map<String, dynamic> toJson() {
return _$$SnippetImplToJson(
this,
);
return _$$SnippetImplToJson(this);
}
}
abstract class _Snippet implements Snippet {
const factory _Snippet(
{@HiveField(0) required final String name,
@HiveField(1) required final String script,
@HiveField(2) final List<String>? tags,
@HiveField(3) final String? note,
@HiveField(4) final List<String>? autoRunOn}) = _$SnippetImpl;
const factory _Snippet({
required final String name,
required final String script,
final List<String>? tags,
final String? note,
final List<String>? autoRunOn,
}) = _$SnippetImpl;
factory _Snippet.fromJson(Map<String, dynamic> json) = _$SnippetImpl.fromJson;
@override
@HiveField(0)
String get name;
@override
@HiveField(1)
String get script;
@override
@HiveField(2)
List<String>? get tags;
@override
@HiveField(3)
String? get note;
/// List of server id that this snippet should be auto run on
@override
@HiveField(4)
List<String>? get autoRunOn;
/// Create a copy of Snippet

View File

@@ -2,56 +2,6 @@
part of 'snippet.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class SnippetAdapter extends TypeAdapter<Snippet> {
@override
final int typeId = 2;
@override
Snippet read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Snippet(
name: fields[0] as String,
script: fields[1] as String,
tags: (fields[2] as List?)?.cast<String>(),
note: fields[3] as String?,
autoRunOn: (fields[4] as List?)?.cast<String>(),
);
}
@override
void write(BinaryWriter writer, Snippet obj) {
writer
..writeByte(5)
..writeByte(0)
..write(obj.name)
..writeByte(1)
..write(obj.script)
..writeByte(2)
..write(obj.tags)
..writeByte(3)
..write(obj.note)
..writeByte(4)
..write(obj.autoRunOn);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SnippetAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

View File

@@ -1,19 +1,14 @@
import 'dart:io';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:wake_on_lan/wake_on_lan.dart';
part 'wol_cfg.g.dart';
@JsonSerializable()
@HiveType(typeId: 8)
@JsonSerializable(includeIfNull: false)
final class WakeOnLanCfg {
@HiveField(0)
final String mac;
@HiveField(1)
final String ip;
@HiveField(2)
final String? pwd;
const WakeOnLanCfg({
@@ -26,18 +21,12 @@ final class WakeOnLanCfg {
final macValidation = MACAddress.validate(mac);
final ipValidation = IPAddress.validate(
ip,
type: ip.contains(':')
? InternetAddressType.IPv6
: InternetAddressType.IPv4,
type: ip.contains(':') ? InternetAddressType.IPv6 : InternetAddressType.IPv4,
);
final pwdValidation = pwd != null
? SecureONPassword.validate(pwd)
: (state: true, error: null);
final pwdValidation = pwd != null ? SecureONPassword.validate(pwd) : (state: true, error: null);
final valid =
macValidation.state && ipValidation.state && pwdValidation.state;
final err =
macValidation.error ?? ipValidation.error ?? pwdValidation.error;
final valid = macValidation.state && ipValidation.state && pwdValidation.state;
final err = macValidation.error ?? ipValidation.error ?? pwdValidation.error;
return (err, valid);
}
@@ -56,8 +45,7 @@ final class WakeOnLanCfg {
);
}
factory WakeOnLanCfg.fromJson(Map<String, dynamic> json) =>
_$WakeOnLanCfgFromJson(json);
factory WakeOnLanCfg.fromJson(Map<String, dynamic> json) => _$WakeOnLanCfgFromJson(json);
Map<String, dynamic> toJson() => _$WakeOnLanCfgToJson(this);
}

View File

@@ -2,63 +2,19 @@
part of 'wol_cfg.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class WakeOnLanCfgAdapter extends TypeAdapter<WakeOnLanCfg> {
@override
final int typeId = 8;
@override
WakeOnLanCfg read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return WakeOnLanCfg(
mac: fields[0] as String,
ip: fields[1] as String,
pwd: fields[2] as String?,
);
}
@override
void write(BinaryWriter writer, WakeOnLanCfg obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.mac)
..writeByte(1)
..write(obj.ip)
..writeByte(2)
..write(obj.pwd);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is WakeOnLanCfgAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
WakeOnLanCfg _$WakeOnLanCfgFromJson(Map<String, dynamic> json) => WakeOnLanCfg(
mac: json['mac'] as String,
ip: json['ip'] as String,
pwd: json['pwd'] as String?,
);
mac: json['mac'] as String,
ip: json['ip'] as String,
pwd: json['pwd'] as String?,
);
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,
};

View File

@@ -1,103 +1,55 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:server_box/core/extension/context/locale.dart';
import 'package:server_box/data/res/store.dart';
import 'package:xterm/core.dart';
part 'virtual_key.g.dart';
enum VirtualKeyFunc { toggleIME, backspace, clipboard, snippet, file }
@HiveType(typeId: 4)
enum VirtKey {
@HiveField(0)
esc,
@HiveField(1)
alt,
@HiveField(2)
home,
@HiveField(3)
up,
@HiveField(4)
end,
@HiveField(5)
sftp,
@HiveField(6)
snippet,
@HiveField(7)
tab,
@HiveField(8)
ctrl,
@HiveField(9)
left,
@HiveField(10)
down,
@HiveField(11)
right,
@HiveField(12)
clipboard,
@HiveField(13)
ime,
@HiveField(14)
pgup,
@HiveField(15)
pgdn,
@HiveField(16)
slash,
@HiveField(17)
backSlash,
@HiveField(18)
underscore,
@HiveField(19)
plus,
@HiveField(20)
equal,
@HiveField(21)
minus,
@HiveField(22)
parenLeft,
@HiveField(23)
parenRight,
@HiveField(24)
bracketLeft,
@HiveField(25)
bracketRight,
@HiveField(26)
braceLeft,
@HiveField(27)
braceRight,
@HiveField(28)
chevronLeft,
@HiveField(29)
chevronRight,
@HiveField(30)
colon,
@HiveField(31)
semicolon,
@HiveField(32)
f1,
@HiveField(33)
f2,
@HiveField(34)
f3,
@HiveField(35)
f4,
@HiveField(36)
f5,
@HiveField(37)
f6,
@HiveField(38)
f7,
@HiveField(39)
f8,
@HiveField(40)
f9,
@HiveField(41)
f10,
@HiveField(42)
f11,
@HiveField(43)
f12;
}

View File

@@ -1,256 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'virtual_key.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class VirtKeyAdapter extends TypeAdapter<VirtKey> {
@override
final int typeId = 4;
@override
VirtKey read(BinaryReader reader) {
switch (reader.readByte()) {
case 0:
return VirtKey.esc;
case 1:
return VirtKey.alt;
case 2:
return VirtKey.home;
case 3:
return VirtKey.up;
case 4:
return VirtKey.end;
case 5:
return VirtKey.sftp;
case 6:
return VirtKey.snippet;
case 7:
return VirtKey.tab;
case 8:
return VirtKey.ctrl;
case 9:
return VirtKey.left;
case 10:
return VirtKey.down;
case 11:
return VirtKey.right;
case 12:
return VirtKey.clipboard;
case 13:
return VirtKey.ime;
case 14:
return VirtKey.pgup;
case 15:
return VirtKey.pgdn;
case 16:
return VirtKey.slash;
case 17:
return VirtKey.backSlash;
case 18:
return VirtKey.underscore;
case 19:
return VirtKey.plus;
case 20:
return VirtKey.equal;
case 21:
return VirtKey.minus;
case 22:
return VirtKey.parenLeft;
case 23:
return VirtKey.parenRight;
case 24:
return VirtKey.bracketLeft;
case 25:
return VirtKey.bracketRight;
case 26:
return VirtKey.braceLeft;
case 27:
return VirtKey.braceRight;
case 28:
return VirtKey.chevronLeft;
case 29:
return VirtKey.chevronRight;
case 30:
return VirtKey.colon;
case 31:
return VirtKey.semicolon;
case 32:
return VirtKey.f1;
case 33:
return VirtKey.f2;
case 34:
return VirtKey.f3;
case 35:
return VirtKey.f4;
case 36:
return VirtKey.f5;
case 37:
return VirtKey.f6;
case 38:
return VirtKey.f7;
case 39:
return VirtKey.f8;
case 40:
return VirtKey.f9;
case 41:
return VirtKey.f10;
case 42:
return VirtKey.f11;
case 43:
return VirtKey.f12;
default:
return VirtKey.esc;
}
}
@override
void write(BinaryWriter writer, VirtKey obj) {
switch (obj) {
case VirtKey.esc:
writer.writeByte(0);
break;
case VirtKey.alt:
writer.writeByte(1);
break;
case VirtKey.home:
writer.writeByte(2);
break;
case VirtKey.up:
writer.writeByte(3);
break;
case VirtKey.end:
writer.writeByte(4);
break;
case VirtKey.sftp:
writer.writeByte(5);
break;
case VirtKey.snippet:
writer.writeByte(6);
break;
case VirtKey.tab:
writer.writeByte(7);
break;
case VirtKey.ctrl:
writer.writeByte(8);
break;
case VirtKey.left:
writer.writeByte(9);
break;
case VirtKey.down:
writer.writeByte(10);
break;
case VirtKey.right:
writer.writeByte(11);
break;
case VirtKey.clipboard:
writer.writeByte(12);
break;
case VirtKey.ime:
writer.writeByte(13);
break;
case VirtKey.pgup:
writer.writeByte(14);
break;
case VirtKey.pgdn:
writer.writeByte(15);
break;
case VirtKey.slash:
writer.writeByte(16);
break;
case VirtKey.backSlash:
writer.writeByte(17);
break;
case VirtKey.underscore:
writer.writeByte(18);
break;
case VirtKey.plus:
writer.writeByte(19);
break;
case VirtKey.equal:
writer.writeByte(20);
break;
case VirtKey.minus:
writer.writeByte(21);
break;
case VirtKey.parenLeft:
writer.writeByte(22);
break;
case VirtKey.parenRight:
writer.writeByte(23);
break;
case VirtKey.bracketLeft:
writer.writeByte(24);
break;
case VirtKey.bracketRight:
writer.writeByte(25);
break;
case VirtKey.braceLeft:
writer.writeByte(26);
break;
case VirtKey.braceRight:
writer.writeByte(27);
break;
case VirtKey.chevronLeft:
writer.writeByte(28);
break;
case VirtKey.chevronRight:
writer.writeByte(29);
break;
case VirtKey.colon:
writer.writeByte(30);
break;
case VirtKey.semicolon:
writer.writeByte(31);
break;
case VirtKey.f1:
writer.writeByte(32);
break;
case VirtKey.f2:
writer.writeByte(33);
break;
case VirtKey.f3:
writer.writeByte(34);
break;
case VirtKey.f4:
writer.writeByte(35);
break;
case VirtKey.f5:
writer.writeByte(36);
break;
case VirtKey.f6:
writer.writeByte(37);
break;
case VirtKey.f7:
writer.writeByte(38);
break;
case VirtKey.f8:
writer.writeByte(39);
break;
case VirtKey.f9:
writer.writeByte(40);
break;
case VirtKey.f10:
writer.writeByte(41);
break;
case VirtKey.f11:
writer.writeByte(42);
break;
case VirtKey.f12:
writer.writeByte(43);
break;
}
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is VirtKeyAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}