add global init and update wayland error map

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-10-11 20:36:19 -07:00
parent 244c07e50e
commit 2da5401fd4
9 changed files with 151 additions and 12 deletions

View File

@@ -1,4 +1,7 @@
use std::sync::{Arc, Mutex};
use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub use arboard::Clipboard as ClipboardContext;
@@ -31,6 +34,36 @@ lazy_static::lazy_static! {
pub static ref DEVICE_NAME: Arc<Mutex<String>> = Default::default();
}
lazy_static::lazy_static! {
static ref GLOBAL_INIT_FUNCS: Mutex<HashMap<String, fn() -> bool>> = Default::default();
static ref GLOBAL_CLEAN_FUNCS: Mutex<HashMap<String, fn()>> = Default::default();
}
pub fn reg_global_init(key: String, f: fn() -> bool) {
GLOBAL_INIT_FUNCS.lock().unwrap().insert(key, f);
}
pub fn reg_global_clean(key: String, f: fn()) {
GLOBAL_CLEAN_FUNCS.lock().unwrap().insert(key, f);
}
pub fn global_init() -> bool {
for (k, f) in GLOBAL_INIT_FUNCS.lock().unwrap().iter() {
println!("Init {}", k);
if !f() {
return false;
}
}
true
}
pub fn global_clean() {
for (k, f) in GLOBAL_CLEAN_FUNCS.lock().unwrap().iter() {
println!("Clean {}", k);
f();
}
}
#[inline]
pub fn valid_for_numlock(evt: &KeyEvent) -> bool {
if let Some(key_event::Union::ControlKey(ck)) = evt.union {