plugin_framework, Remove plugin enable option

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-05-06 18:45:58 +08:00
parent e6f72e76dd
commit 6f5ff0ac0e
3 changed files with 10 additions and 83 deletions

View File

@ -1512,18 +1512,7 @@ class _PluginState extends State<_Plugin> {
List<Widget> _buildCards(DescModel model) => [ List<Widget> _buildCards(DescModel model) => [
_Card( _Card(
title: 'Plugin', title: 'Plugin',
children: [ children: [],
_Checkbox(
label: 'Enable',
getValue: () => bind.pluginIsEnabled() ?? false,
setValue: (bool v) async {
if (!v) {
clearLocations();
}
await bind.pluginEnable(v: v);
},
),
],
), ),
...model.all.entries ...model.all.entries
.map((entry) => PluginCard(pluginId: entry.key, desc: entry.value)) .map((entry) => PluginCard(pluginId: entry.key, desc: entry.value))

View File

@ -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> { pub fn plugin_feature_is_enabled() -> SyncReturn<bool> {
#[cfg(feature = "plugin_framework")] #[cfg(feature = "plugin_framework")]
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]

View File

@ -214,7 +214,6 @@ const MANAGER_VERSION: &str = "0.1.0";
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct ManagerConfig { pub struct ManagerConfig {
pub version: String, pub version: String,
pub enabled: bool,
#[serde(default)] #[serde(default)]
pub options: HashMap<String, String>, pub options: HashMap<String, String>,
#[serde(default)] #[serde(default)]
@ -225,7 +224,6 @@ impl Default for ManagerConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
version: MANAGER_VERSION.to_owned(), version: MANAGER_VERSION.to_owned(),
enabled: true,
options: HashMap::new(), options: HashMap::new(),
plugins: HashMap::new(), plugins: HashMap::new(),
} }
@ -241,9 +239,6 @@ impl ManagerConfig {
#[inline] #[inline]
pub fn get_option(key: &str) -> Option<String> { pub fn get_option(key: &str) -> Option<String> {
if key == "enabled" {
Some(CONFIG_MANAGER.lock().unwrap().enabled.to_string())
} else {
CONFIG_MANAGER CONFIG_MANAGER
.lock() .lock()
.unwrap() .unwrap()
@ -251,33 +246,12 @@ impl ManagerConfig {
.get(key) .get(key)
.map(|s| s.to_owned()) .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)
}
#[inline] #[inline]
pub fn set_option(key: &str, value: &str) { pub fn set_option(key: &str, value: &str) {
if key == "enabled" { let mut lock = CONFIG_MANAGER.lock().unwrap();
let enabled = bool::from_str(value).unwrap_or(false); lock.options.insert(key.to_owned(), value.to_owned());
allow_err!(Self::set_option_enabled(enabled)); allow_err!(hbb_common::config::store_path(Self::path(), &*lock));
if enabled {
allow_err!(super::load_plugins());
} else {
super::unload_plugins();
}
} else {
allow_err!(Self::set_option_not_enabled(key, value));
}
} }
#[inline] #[inline]