macos, fix input crash

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-06-05 12:54:49 +08:00
parent 3459ec722b
commit 10176d9b2c
4 changed files with 18 additions and 7 deletions

View File

@ -62,7 +62,9 @@ lazy_static::lazy_static! {
} }
lazy_static::lazy_static! { lazy_static::lazy_static! {
// Is server process, with "--server" args
static ref IS_SERVER: bool = std::env::args().nth(1) == Some("--server".to_owned()); static ref IS_SERVER: bool = std::env::args().nth(1) == Some("--server".to_owned());
// Is server logic running. The server code can invoked to run by the main process if --server is not running.
static ref SERVER_RUNNING: Arc<RwLock<bool>> = Default::default(); static ref SERVER_RUNNING: Arc<RwLock<bool>> = Default::default();
} }
@ -101,9 +103,16 @@ pub fn set_server_running(b: bool) {
*SERVER_RUNNING.write().unwrap() = b; *SERVER_RUNNING.write().unwrap() = b;
} }
// is server process, with "--server" args
#[inline] #[inline]
pub fn is_server() -> bool { pub fn is_server() -> bool {
*IS_SERVER || *SERVER_RUNNING.read().unwrap() *IS_SERVER
}
// Is server logic running.
#[inline]
pub fn is_server_running() -> bool {
*SERVER_RUNNING.read().unwrap()
} }
#[inline] #[inline]

View File

@ -321,7 +321,7 @@ pub fn uninstall_plugin(id: &str, called_by_ui: bool) {
} }
} }
if is_server() { if super::is_server_running() {
super::plugins::unload_plugin(&id); super::plugins::unload_plugin(&id);
} }
} }

View File

@ -42,8 +42,6 @@ static PLUGIN_SOURCE_LOCAL_DIR: &str = "plugins";
pub use config::{ManagerConfig, PeerConfig, SharedConfig}; pub use config::{ManagerConfig, PeerConfig, SharedConfig};
use crate::common::is_server;
/// Common plugin return. /// Common plugin return.
/// ///
/// [Note] /// [Note]
@ -96,8 +94,12 @@ impl PluginReturn {
} }
} }
fn is_server_running() -> bool {
crate::common::is_server() || crate::common::is_server_running()
}
pub fn init() { pub fn init() {
if !is_server() { if !is_server_running() {
std::thread::spawn(move || manager::start_ipc()); std::thread::spawn(move || manager::start_ipc());
} else { } else {
if let Err(e) = remove_uninstalled() { if let Err(e) = remove_uninstalled() {

View File

@ -371,7 +371,7 @@ fn load_plugin_path(path: &str) -> ResultType<()> {
PLUGIN_INFO.write().unwrap().insert(id.clone(), plugin_info); PLUGIN_INFO.write().unwrap().insert(id.clone(), plugin_info);
let init_info = serde_json::to_string(&InitInfo { let init_info = serde_json::to_string(&InitInfo {
is_server: crate::common::is_server(), is_server: super::is_server_running(),
})?; })?;
let init_data = InitData { let init_data = InitData {
version: str_to_cstr_ret(crate::VERSION), version: str_to_cstr_ret(crate::VERSION),
@ -389,7 +389,7 @@ fn load_plugin_path(path: &str) -> ResultType<()> {
log::error!("Failed to init plugin '{}', {}", desc.meta().id, e); log::error!("Failed to init plugin '{}', {}", desc.meta().id, e);
} }
if is_server() { if super::is_server_running() {
super::config::ManagerConfig::add_plugin(&desc.meta().id)?; super::config::ManagerConfig::add_plugin(&desc.meta().id)?;
} }