add events to ui

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-04-20 10:29:24 +08:00
parent 94d7339457
commit 4200734593
8 changed files with 274 additions and 5 deletions

View File

@@ -0,0 +1,135 @@
import 'dart:collection';
class UiButton {
String key;
String text;
String icon;
String tooltip;
String action;
UiButton(this.key, this.text, this.icon, this.tooltip, this.action);
UiButton.fromJson(Map<String, dynamic> json)
: key = json['key'] ?? '',
text = json['text'] ?? '',
icon = json['icon'] ?? '',
tooltip = json['tooltip'] ?? '',
action = json['action'] ?? '';
}
class UiCheckbox {
String key;
String text;
String tooltip;
String action;
UiCheckbox(this.key, this.text, this.tooltip, this.action);
UiCheckbox.fromJson(Map<String, dynamic> json)
: key = json['key'] ?? '',
text = json['text'] ?? '',
tooltip = json['tooltip'] ?? '',
action = json['action'] ?? '';
}
class UiType {
UiButton? button;
UiCheckbox? checkbox;
UiType.fromJson(Map<String, dynamic> json)
: button = json['t'] == 'Button' ? UiButton.fromJson(json['c']) : null,
checkbox =
json['t'] != 'Checkbox' ? UiCheckbox.fromJson(json['c']) : null;
}
class Location {
HashMap<String, UiType> ui;
Location(this.ui);
}
class ConfigItem {
String key;
String value;
String description;
String defaultValue;
ConfigItem(this.key, this.value, this.defaultValue, this.description);
ConfigItem.fromJson(Map<String, dynamic> json)
: key = json['key'] ?? '',
value = json['value'] ?? '',
description = json['description'] ?? '',
defaultValue = json['default'] ?? '';
}
class Config {
List<ConfigItem> local;
List<ConfigItem> peer;
Config(this.local, this.peer);
Config.fromJson(Map<String, dynamic> json)
: local = (json['local'] as List<dynamic>)
.map((e) => ConfigItem.fromJson(e))
.toList(),
peer = (json['peer'] as List<dynamic>)
.map((e) => ConfigItem.fromJson(e))
.toList();
}
class Desc {
String id;
String name;
String version;
String description;
String author;
String home;
String license;
String published;
String released;
String github;
Location location;
Config config;
Desc(
this.id,
this.name,
this.version,
this.description,
this.author,
this.home,
this.license,
this.published,
this.released,
this.github,
this.location,
this.config);
Desc.fromJson(Map<String, dynamic> json)
: id = json['id'] ?? '',
name = json['name'] ?? '',
version = json['version'] ?? '',
description = json['description'] ?? '',
author = json['author'] ?? '',
home = json['home'] ?? '',
license = json['license'] ?? '',
published = json['published'] ?? '',
released = json['released'] ?? '',
github = json['github'] ?? '',
location = Location(HashMap<String, UiType>.from(json['location'])),
config = Config(
(json['config'] as List<dynamic>)
.map((e) => ConfigItem.fromJson(e))
.toList(),
(json['config'] as List<dynamic>)
.map((e) => ConfigItem.fromJson(e))
.toList());
}
final mapPluginDesc = <String, Desc>{};
void updateDesc(Map<String, dynamic> desc) {
Desc d = Desc.fromJson(desc);
mapPluginDesc[d.id] = d;
}
Desc? getDesc(String id) {
return mapPluginDesc[id];
}

View File

@@ -0,0 +1,60 @@
void handlePluginEvent(
Map<String, dynamic> evt,
String peer,
Function(Map<String, dynamic> e) handleMsgBox,
) {
// content
//
// {
// "t": "Option",
// "c": {
// "id": "id from RustDesk platform",
// "name": "Privacy Mode",
// "version": "v0.1.0",
// "location": "client|remote|toolbar|display",
// "key": "privacy-mode",
// "value": "1"
// }
// }
//
// {
// "t": "MsgBox",
// "c": {
// "type": "custom-nocancel",
// "title": "Privacy Mode",
// "text": "Failed unknown",
// "link": ""
// }
// }
//
if (evt['content']?['c'] == null) return;
final t = evt['content']?['t'];
if (t == 'Option') {
handleOptionEvent(evt['content']?['c'], peer);
} else if (t == 'MsgBox') {
handleMsgBox(evt['content']?['c']);
}
}
void handleOptionEvent(Map<String, dynamic> evt, String peer) {
// content
//
// {
// "id": "id from RustDesk platform",
// "name": "Privacy Mode",
// "version": "v0.1.0",
// "location": "client|remote|toolbar|display",
// "key": "privacy-mode",
// "value": "1"
// }
//
final key = evt['key'];
final value = evt['value'];
if (key == 'privacy-mode') {
if (value == '1') {
// enable privacy mode
} else {
// disable privacy mode
}
}
}

View File

@@ -0,0 +1,29 @@
void handleReloading(Map<String, dynamic> evt, String peer) {
// location
// host|main|settings|display|others
// client|remote|toolbar|display
//
// ui
// {
// "t": "Button",
// "c": {
// "key": "key",
// "text": "text",
// "icon": "icon",
// "tooltip": "tooltip",
// "action": "action"
// }
// }
//
// {
// "t": "Checkbox",
// "c": {
// "key": "key",
// "text": "text",
// "tooltip": "tooltip",
// "action": "action"
// }
// }
//
}

View File

@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
final Map<String, PluginWidget> pluginWidgets = {};
class PluginWidget {
final String id;
final String name;
final String location;
final Widget widget;
PluginWidget({
required this.id,
required this.name,
required this.location,
required this.widget,
});
}