mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-13 03:28:03 +00:00
plugin_framework, plugin manager
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:collection';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
const String kValueTrue = '1';
|
||||
const String kValueFalse = '0';
|
||||
@@ -154,13 +155,27 @@ class Desc {
|
||||
.toList());
|
||||
}
|
||||
|
||||
final mapPluginDesc = <String, Desc>{};
|
||||
class DescModel with ChangeNotifier {
|
||||
final data = <String, Desc>{};
|
||||
|
||||
void updateDesc(Map<String, dynamic> desc) {
|
||||
Desc d = Desc.fromJson(desc);
|
||||
mapPluginDesc[d.id] = d;
|
||||
DescModel._();
|
||||
|
||||
void _updateDesc(Map<String, dynamic> desc) {
|
||||
Desc d = Desc.fromJson(desc);
|
||||
data[d.id] = d;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Desc? _getDesc(String id) {
|
||||
return data[id];
|
||||
}
|
||||
|
||||
Map<String, Desc> get all => data;
|
||||
|
||||
static final DescModel _instance = DescModel._();
|
||||
static DescModel get instance => _instance;
|
||||
}
|
||||
|
||||
Desc? getDesc(String id) {
|
||||
return mapPluginDesc[id];
|
||||
}
|
||||
void updateDesc(Map<String, dynamic> desc) =>
|
||||
DescModel.instance._updateDesc(desc);
|
||||
Desc? getDesc(String id) => DescModel.instance._getDesc(id);
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import './common.dart';
|
||||
import './desc.dart';
|
||||
|
||||
final Map<String, LocationModel> locationModels = {};
|
||||
final Map<String, OptionModel> optionModels = {};
|
||||
final Map<String, LocationModel> _locationModels = {};
|
||||
final Map<String, OptionModel> _optionModels = {};
|
||||
|
||||
class OptionModel with ChangeNotifier {
|
||||
String? v;
|
||||
@@ -46,31 +46,48 @@ class LocationModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
pluginModels.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool get isEmpty => pluginModels.isEmpty;
|
||||
}
|
||||
|
||||
void addLocationUi(String location, PluginId id, UiType ui) {
|
||||
locationModels[location]?.add(id, ui);
|
||||
_locationModels[location]?.add(id, ui);
|
||||
}
|
||||
|
||||
LocationModel addLocation(String location) {
|
||||
if (locationModels[location] == null) {
|
||||
locationModels[location] = LocationModel();
|
||||
if (_locationModels[location] == null) {
|
||||
_locationModels[location] = LocationModel();
|
||||
}
|
||||
return _locationModels[location]!;
|
||||
}
|
||||
|
||||
void clearPlugin(PluginId pluginId) {
|
||||
for (var element in _locationModels.values) {
|
||||
element.pluginModels.remove(pluginId);
|
||||
}
|
||||
}
|
||||
|
||||
void clearLocations() {
|
||||
for (var element in _locationModels.values) {
|
||||
element.clear();
|
||||
}
|
||||
return locationModels[location]!;
|
||||
}
|
||||
|
||||
OptionModel addOptionModel(
|
||||
String location, PluginId pluginId, String peer, String key) {
|
||||
final k = OptionModel.key(location, pluginId, peer, key);
|
||||
if (optionModels[k] == null) {
|
||||
optionModels[k] = OptionModel();
|
||||
if (_optionModels[k] == null) {
|
||||
_optionModels[k] = OptionModel();
|
||||
}
|
||||
return optionModels[k]!;
|
||||
return _optionModels[k]!;
|
||||
}
|
||||
|
||||
void updateOption(
|
||||
String location, PluginId id, String peer, String key, String value) {
|
||||
final k = OptionModel.key(location, id, peer, key);
|
||||
optionModels[k]?.value = value;
|
||||
_optionModels[k]?.value = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user