mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
feat: custom server logo
This commit is contained in:
@@ -16,6 +16,8 @@ final class ServerCustom {
|
||||
final Map<String, String>? cmds;
|
||||
@HiveField(4)
|
||||
final String? preferTempDev;
|
||||
@HiveField(5)
|
||||
final String? logoUrl;
|
||||
|
||||
const ServerCustom({
|
||||
//this.temperature,
|
||||
@@ -23,6 +25,7 @@ final class ServerCustom {
|
||||
this.pveIgnoreCert = false,
|
||||
this.cmds,
|
||||
this.preferTempDev,
|
||||
this.logoUrl,
|
||||
});
|
||||
|
||||
static ServerCustom fromJson(Map<String, dynamic> json) {
|
||||
@@ -31,12 +34,14 @@ final class ServerCustom {
|
||||
final pveIgnoreCert = json["pveIgnoreCert"] as bool;
|
||||
final cmds = json["cmds"] as Map<String, dynamic>?;
|
||||
final preferTempDev = json["preferTempDev"] as String?;
|
||||
final logoUrl = json["logoUrl"] as String?;
|
||||
return ServerCustom(
|
||||
//temperature: temperature,
|
||||
pveAddr: pveAddr,
|
||||
pveIgnoreCert: pveIgnoreCert,
|
||||
cmds: cmds?.cast<String, String>(),
|
||||
preferTempDev: preferTempDev,
|
||||
logoUrl: logoUrl,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -56,6 +61,9 @@ final class ServerCustom {
|
||||
if (preferTempDev != null) {
|
||||
json["preferTempDev"] = preferTempDev;
|
||||
}
|
||||
if (logoUrl != null) {
|
||||
json["logoUrl"] = logoUrl;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -71,9 +79,16 @@ final class ServerCustom {
|
||||
other.pveAddr == pveAddr &&
|
||||
other.pveIgnoreCert == pveIgnoreCert &&
|
||||
other.cmds == cmds &&
|
||||
other.preferTempDev == preferTempDev;
|
||||
other.preferTempDev == preferTempDev &&
|
||||
other.logoUrl == logoUrl;
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => toString().hashCode;
|
||||
int get hashCode =>
|
||||
//temperature.hashCode ^
|
||||
pveAddr.hashCode ^
|
||||
pveIgnoreCert.hashCode ^
|
||||
cmds.hashCode ^
|
||||
preferTempDev.hashCode ^
|
||||
logoUrl.hashCode;
|
||||
}
|
||||
|
||||
@@ -21,13 +21,14 @@ class ServerCustomAdapter extends TypeAdapter<ServerCustom> {
|
||||
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?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ServerCustom obj) {
|
||||
writer
|
||||
..writeByte(4)
|
||||
..writeByte(5)
|
||||
..writeByte(1)
|
||||
..write(obj.pveAddr)
|
||||
..writeByte(2)
|
||||
@@ -35,7 +36,9 @@ class ServerCustomAdapter extends TypeAdapter<ServerCustom> {
|
||||
..writeByte(3)
|
||||
..write(obj.cmds)
|
||||
..writeByte(4)
|
||||
..write(obj.preferTempDev);
|
||||
..write(obj.preferTempDev)
|
||||
..writeByte(5)
|
||||
..write(obj.logoUrl);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -22,12 +22,12 @@ class Server implements TagPickable {
|
||||
ServerPrivateInfo spi;
|
||||
ServerStatus status;
|
||||
SSHClient? client;
|
||||
ServerState state;
|
||||
ServerConn conn;
|
||||
|
||||
Server(
|
||||
this.spi,
|
||||
this.status,
|
||||
this.state, {
|
||||
this.conn, {
|
||||
this.client,
|
||||
});
|
||||
|
||||
@@ -39,9 +39,9 @@ class Server implements TagPickable {
|
||||
@override
|
||||
String get tagName => spi.id;
|
||||
|
||||
bool get needGenClient => state < ServerState.connecting;
|
||||
bool get needGenClient => conn < ServerConn.connecting;
|
||||
|
||||
bool get canViewDetails => state == ServerState.finished;
|
||||
bool get canViewDetails => conn == ServerConn.finished;
|
||||
|
||||
String get id => spi.id;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class ServerStatus {
|
||||
});
|
||||
}
|
||||
|
||||
enum ServerState {
|
||||
enum ServerConn {
|
||||
failed,
|
||||
disconnected,
|
||||
connecting,
|
||||
@@ -94,5 +94,5 @@ enum ServerState {
|
||||
/// Status parsing finished
|
||||
finished;
|
||||
|
||||
operator <(ServerState other) => index < other.index;
|
||||
operator <(ServerConn other) => index < other.index;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ part of 'server.dart';
|
||||
|
||||
extension ServerX on Server {
|
||||
String getTopRightStr(ServerPrivateInfo spi) {
|
||||
switch (state) {
|
||||
case ServerState.disconnected:
|
||||
switch (conn) {
|
||||
case ServerConn.disconnected:
|
||||
return l10n.disconnected;
|
||||
case ServerState.finished:
|
||||
case ServerConn.finished:
|
||||
// Highest priority of temperature display
|
||||
final cmdTemp = () {
|
||||
final val = status.customCmds['server_card_top_right'];
|
||||
@@ -46,13 +46,13 @@ extension ServerX on Server {
|
||||
final str = items.where((e) => e != null && e.isNotEmpty).join(' | ');
|
||||
if (str.isEmpty) return l10n.noResult;
|
||||
return str;
|
||||
case ServerState.loading:
|
||||
case ServerConn.loading:
|
||||
return l10n.serverTabLoading;
|
||||
case ServerState.connected:
|
||||
case ServerConn.connected:
|
||||
return l10n.connected;
|
||||
case ServerState.connecting:
|
||||
case ServerConn.connecting:
|
||||
return l10n.serverTabConnecting;
|
||||
case ServerState.failed:
|
||||
case ServerConn.failed:
|
||||
return status.err ?? l10n.serverTabFailed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user