diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 48e890f4a..a91e1dc6f 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -231,7 +231,6 @@ class FfiModel with ChangeNotifier { } else if (name == 'fingerprint') { FingerprintState.find(peerId).value = evt['fingerprint'] ?? ''; } else if (name == 'plugin_manager') { - debugPrint('REMOVE ME ==================== plugin_manager $evt'); pluginManager.handleEvent(evt); } else if (name == 'plugin_event') { handlePluginEvent( diff --git a/flutter/lib/plugin/manager.dart b/flutter/lib/plugin/manager.dart index 326b2a5e4..c7a9c7b3f 100644 --- a/flutter/lib/plugin/manager.dart +++ b/flutter/lib/plugin/manager.dart @@ -223,7 +223,7 @@ class PluginManager with ChangeNotifier { _plugins.add(plugin); } } catch (e) { - debugPrint('Failed to decode plugin list \'$pluginList\''); + debugPrint('Failed to decode $e, plugin list \'$pluginList\''); } notifyListeners(); } @@ -245,6 +245,22 @@ class PluginManager with ChangeNotifier { if (m == null) { return null; } + + late DateTime lastReleased; + late DateTime published; + try { + lastReleased = DateTime.parse( + m['publish_info']?['last_released'] ?? '1970-01-01T00+00:00'); + } catch (e) { + lastReleased = DateTime.utc(1970); + } + try { + published = DateTime.parse( + m['publish_info']?['published'] ?? '1970-01-01T00+00:00'); + } catch (e) { + published = DateTime.utc(1970); + } + final meta = Meta( id: m['id'], name: m['name'], @@ -254,17 +270,22 @@ class PluginManager with ChangeNotifier { home: m['home'] ?? '', license: m['license'] ?? '', source: m['source'] ?? '', - publishInfo: PublishInfo( - lastReleased: DateTime.parse( - m['publish_info']?['lastReleased'] ?? '1970-01-01T00+00:00'), - published: DateTime.parse( - m['publish_info']?['published'] ?? '1970-01-01T00+00:00')), + publishInfo: + PublishInfo(lastReleased: lastReleased, published: published), ); + + late DateTime installTime; + try { + installTime = + DateTime.parse(evt['install_time'] ?? '1970-01-01T00+00:00'); + } catch (e) { + installTime = DateTime.utc(1970); + } return PluginInfo( sourceInfo: source, meta: meta, installedVersion: evt['installed_version'], - installTime: evt['install_time'], + installTime: installTime, invalidReason: evt['invalid_reason'] ?? '', ); } diff --git a/src/plugin/manager.rs b/src/plugin/manager.rs index 3d8fbef5a..1828cd7e5 100644 --- a/src/plugin/manager.rs +++ b/src/plugin/manager.rs @@ -2,8 +2,10 @@ // 2. Install or uninstall. use super::{desc::Meta as PluginMeta, ipc::InstallStatus, *}; -use crate::{common::is_server, flutter}; -use hbb_common::{allow_err, bail, config::load_path, log, tokio, toml}; +use crate::flutter; +#[cfg(not(debug_assertions))] +use hbb_common::toml; +use hbb_common::{allow_err, bail, config::load_path, log, tokio}; use serde_derive::{Deserialize, Serialize}; use serde_json; use std::{ @@ -38,7 +40,7 @@ pub struct PluginSource { #[derive(Debug, Serialize)] pub struct PluginInfo { pub source: PluginSource, - pub plugin: PluginMeta, + pub meta: PluginMeta, pub installed_version: String, pub install_time: String, pub invalid_reason: String, @@ -60,18 +62,18 @@ fn get_plugin_source_list() -> Vec { fn get_source_plugins() -> HashMap { let meta_file = super::get_plugins_dir().unwrap().join("meta.toml"); let mut plugins = HashMap::new(); - let meta = load_path::(meta_file); + let manager_meta = load_path::(meta_file); let source = PluginSource { name: "rustdesk".to_string(), url: "https://github.com/fufesou/rustdesk-plugins".to_string(), description: "".to_string(), }; - for plugin in meta.plugins.iter() { + for meta in manager_meta.plugins.iter() { plugins.insert( - plugin.id.clone(), + meta.id.clone(), PluginInfo { source: source.clone(), - plugin: plugin.clone(), + meta: meta.clone(), installed_version: "".to_string(), install_time: "".to_string(), invalid_reason: "".to_string(), @@ -95,22 +97,24 @@ fn get_source_plugins() -> HashMap { resp.status() ); } - match resp.json::() { - Ok(meta) => { - for plugin in meta.plugins.iter() { - plugins.insert( - plugin.id.clone(), - PluginInfo { - source: source.clone(), - plugin: plugin.clone(), - installed_version: "".to_string(), - install_time: "".to_string(), - invalid_reason: "".to_string(), - }, - ); + if let Ok(text) = resp.text() { + match toml::from_str::(&text) { + Ok(manager_meta) => { + for meta in manager_meta.plugins.iter() { + plugins.insert( + meta.id.clone(), + PluginInfo { + source: source.clone(), + meta: meta.clone(), + installed_version: "".to_string(), + install_time: "".to_string(), + invalid_reason: "".to_string(), + }, + ); + } } + Err(e) => log::error!("Failed to parse plugin list from '{}', {}", url, e), } - Err(e) => log::error!("Failed to parse plugin list from '{}', {}", url, e), } } Err(e) => log::error!("Failed to get plugin list from '{}', {}", url, e), @@ -121,7 +125,7 @@ fn get_source_plugins() -> HashMap { fn send_plugin_list_event(plugins: &HashMap) { let mut plugin_list = plugins.values().collect::>(); - plugin_list.sort_by(|a, b| a.plugin.name.cmp(&b.plugin.name)); + plugin_list.sort_by(|a, b| a.meta.name.cmp(&b.meta.name)); if let Ok(plugin_list) = serde_json::to_string(&plugin_list) { let mut m = HashMap::new(); m.insert("name", MSG_TO_UI_TYPE_PLUGIN_MANAGER); @@ -148,7 +152,7 @@ pub fn load_plugin_list() { url: PLUGIN_SOURCE_LOCAL_DIR.to_string(), description: "".to_string(), }, - plugin: info.desc.meta().clone(), + meta: info.desc.meta().clone(), installed_version: info.desc.meta().version.clone(), install_time: info.install_time.clone(), invalid_reason: "".to_string(), @@ -165,7 +169,7 @@ pub fn install_plugin(id: &str) -> ResultType<()> { Some(plugin) => { let _plugin_url = format!( "{}/plugins/{}/{}_{}.zip", - plugin.source.url, plugin.plugin.id, plugin.plugin.id, plugin.plugin.version + plugin.source.url, plugin.meta.id, plugin.meta.id, plugin.meta.version ); #[cfg(windows)] let _res = diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index c539196f0..878f0b98b 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -1,4 +1,4 @@ -use hbb_common::{libc, tokio, ResultType, allow_err, log}; +use hbb_common::{allow_err, libc, log, ResultType}; use std::{ env, ffi::{c_char, c_int, c_void, CStr},