new: note of Snippet

This commit is contained in:
lollipopkit
2023-09-07 19:17:49 +08:00
parent 4bdf3694c3
commit 6e4cc8eb28
15 changed files with 80 additions and 19 deletions

View File

@@ -12,18 +12,28 @@ class Snippet implements TagPickable {
final String script;
@HiveField(2)
final List<String>? tags;
const Snippet(this.name, this.script, this.tags);
@HiveField(3)
final String? note;
const Snippet({
required this.name,
required this.script,
this.tags,
this.note,
});
Snippet.fromJson(Map<String, dynamic> json)
: name = json['name'].toString(),
script = json['script'].toString(),
tags = json['tags']?.cast<String>();
tags = json['tags']?.cast<String>(),
note = json['note']?.toString();
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['name'] = name;
data['script'] = script;
data['tags'] = tags;
data['note'] = note;
return data;
}
@@ -38,7 +48,9 @@ class Snippet implements TagPickable {
/// Snippet for installing ServerBoxMonitor
const installSBM = Snippet(
'Install ServerBoxMonitor',
'curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -s -- install',
null,
name: 'Install ServerBoxMonitor',
script:
'curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -s -- install',
tags: ['ServerBoxMonitor'],
note: 'One click script to install ServerBoxMonitor',
);

View File

@@ -17,22 +17,25 @@ class SnippetAdapter extends TypeAdapter<Snippet> {
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Snippet(
fields[0] as String,
fields[1] as String,
(fields[2] as List?)?.cast<String>(),
name: fields[0] as String,
script: fields[1] as String,
tags: (fields[2] as List?)?.cast<String>(),
note: fields[3] as String?,
);
}
@override
void write(BinaryWriter writer, Snippet obj) {
writer
..writeByte(3)
..writeByte(4)
..writeByte(0)
..write(obj.name)
..writeByte(1)
..write(obj.script)
..writeByte(2)
..write(obj.tags);
..write(obj.tags)
..writeByte(3)
..write(obj.note);
}
@override