mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-19 00:13:01 +08:00
plugin_framework, Remove plugin enable option
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
e6f72e76dd
commit
6f5ff0ac0e
@ -1512,18 +1512,7 @@ class _PluginState extends State<_Plugin> {
|
||||
List<Widget> _buildCards(DescModel model) => [
|
||||
_Card(
|
||||
title: 'Plugin',
|
||||
children: [
|
||||
_Checkbox(
|
||||
label: 'Enable',
|
||||
getValue: () => bind.pluginIsEnabled() ?? false,
|
||||
setValue: (bool v) async {
|
||||
if (!v) {
|
||||
clearLocations();
|
||||
}
|
||||
await bind.pluginEnable(v: v);
|
||||
},
|
||||
),
|
||||
],
|
||||
children: [],
|
||||
),
|
||||
...model.all.entries
|
||||
.map((entry) => PluginCard(pluginId: entry.key, desc: entry.value))
|
||||
|
@ -1545,42 +1545,6 @@ pub fn plugin_id_is_enabled(_id: String) -> SyncReturn<bool> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plugin_enable(_v: bool) {
|
||||
#[cfg(feature = "plugin_framework")]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
allow_err!(crate::plugin::ipc::set_manager_config(
|
||||
"enabled",
|
||||
_v.to_string()
|
||||
));
|
||||
if _v {
|
||||
allow_err!(crate::plugin::load_plugins());
|
||||
} else {
|
||||
crate::plugin::unload_plugins();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plugin_is_enabled() -> SyncReturn<Option<bool>> {
|
||||
#[cfg(feature = "plugin_framework")]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
let r = match crate::plugin::ipc::get_manager_config("enabled") {
|
||||
Ok(Some(enabled)) => Some(bool::from_str(&enabled).unwrap_or(false)),
|
||||
_ => None,
|
||||
};
|
||||
SyncReturn(r)
|
||||
}
|
||||
#[cfg(any(
|
||||
not(feature = "plugin_framework"),
|
||||
target_os = "android",
|
||||
target_os = "ios"
|
||||
))]
|
||||
{
|
||||
SyncReturn(Some(false))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plugin_feature_is_enabled() -> SyncReturn<bool> {
|
||||
#[cfg(feature = "plugin_framework")]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
|
@ -214,7 +214,6 @@ const MANAGER_VERSION: &str = "0.1.0";
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ManagerConfig {
|
||||
pub version: String,
|
||||
pub enabled: bool,
|
||||
#[serde(default)]
|
||||
pub options: HashMap<String, String>,
|
||||
#[serde(default)]
|
||||
@ -225,7 +224,6 @@ impl Default for ManagerConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
version: MANAGER_VERSION.to_owned(),
|
||||
enabled: true,
|
||||
options: HashMap::new(),
|
||||
plugins: HashMap::new(),
|
||||
}
|
||||
@ -241,43 +239,19 @@ impl ManagerConfig {
|
||||
|
||||
#[inline]
|
||||
pub fn get_option(key: &str) -> Option<String> {
|
||||
if key == "enabled" {
|
||||
Some(CONFIG_MANAGER.lock().unwrap().enabled.to_string())
|
||||
} else {
|
||||
CONFIG_MANAGER
|
||||
.lock()
|
||||
.unwrap()
|
||||
.options
|
||||
.get(key)
|
||||
.map(|s| s.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
fn set_option_enabled(enabled: bool) -> ResultType<()> {
|
||||
let mut lock = CONFIG_MANAGER.lock().unwrap();
|
||||
lock.enabled = enabled;
|
||||
hbb_common::config::store_path(Self::path(), &*lock)
|
||||
}
|
||||
|
||||
fn set_option_not_enabled(key: &str, value: &str) -> ResultType<()> {
|
||||
let mut lock = CONFIG_MANAGER.lock().unwrap();
|
||||
lock.options.insert(key.to_owned(), value.to_owned());
|
||||
hbb_common::config::store_path(Self::path(), &*lock)
|
||||
CONFIG_MANAGER
|
||||
.lock()
|
||||
.unwrap()
|
||||
.options
|
||||
.get(key)
|
||||
.map(|s| s.to_owned())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_option(key: &str, value: &str) {
|
||||
if key == "enabled" {
|
||||
let enabled = bool::from_str(value).unwrap_or(false);
|
||||
allow_err!(Self::set_option_enabled(enabled));
|
||||
if enabled {
|
||||
allow_err!(super::load_plugins());
|
||||
} else {
|
||||
super::unload_plugins();
|
||||
}
|
||||
} else {
|
||||
allow_err!(Self::set_option_not_enabled(key, value));
|
||||
}
|
||||
let mut lock = CONFIG_MANAGER.lock().unwrap();
|
||||
lock.options.insert(key.to_owned(), value.to_owned());
|
||||
allow_err!(hbb_common::config::store_path(Self::path(), &*lock));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user