remove many unwrap and enum_value_or_default

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-07-22 14:16:41 +08:00
parent 31b3c5d721
commit aa740f4263
26 changed files with 345 additions and 191 deletions

View File

@@ -56,9 +56,15 @@ impl Interface for Session {
}
"re-input-password" => {
log::error!("{}: {}", title, text);
let password = rpassword::prompt_password("Enter password: ").unwrap();
let login_data = Data::Login((password, true));
self.sender.send(login_data).ok();
match rpassword::prompt_password("Enter password: ") {
Ok(password) => {
let login_data = Data::Login((password, true));
self.sender.send(login_data).ok();
}
Err(e) => {
log::error!("reinput password failed, {:?}", e);
}
}
}
msg if msg.contains("error") => {
log::error!("{}: {}: {}", msgtype, title, text);
@@ -85,8 +91,23 @@ impl Interface for Session {
handle_hash(self.lc.clone(), &pass, hash, self, peer).await;
}
async fn handle_login_from_ui(&mut self, os_username: String, os_password: String, password: String, remember: bool, peer: &mut Stream) {
handle_login_from_ui(self.lc.clone(), os_username, os_password, password, remember, peer).await;
async fn handle_login_from_ui(
&mut self,
os_username: String,
os_password: String,
password: String,
remember: bool,
peer: &mut Stream,
) {
handle_login_from_ui(
self.lc.clone(),
os_username,
os_password,
password,
remember,
peer,
)
.await;
}
async fn handle_test_delay(&mut self, t: TestDelay, peer: &mut Stream) {
@@ -117,13 +138,14 @@ pub async fn connect_test(id: &str, key: String, token: String) {
break;
}
Ok(Some(Ok(bytes))) => {
let msg_in = Message::parse_from_bytes(&bytes).unwrap();
match msg_in.union {
Some(message::Union::Hash(hash)) => {
log::info!("Got hash");
break;
if let Ok(msg_in) = Message::parse_from_bytes(&bytes) {
match msg_in.union {
Some(message::Union::Hash(hash)) => {
log::info!("Got hash");
break;
}
_ => {}
}
_ => {}
}
}
_ => {}

View File

@@ -317,19 +317,20 @@ impl Client {
if !ph.other_failure.is_empty() {
bail!(ph.other_failure);
}
match ph.failure.enum_value_or_default() {
punch_hole_response::Failure::ID_NOT_EXIST => {
match ph.failure.enum_value() {
Ok(punch_hole_response::Failure::ID_NOT_EXIST) => {
bail!("ID does not exist");
}
punch_hole_response::Failure::OFFLINE => {
Ok(punch_hole_response::Failure::OFFLINE) => {
bail!("Remote desktop is offline");
}
punch_hole_response::Failure::LICENSE_MISMATCH => {
Ok(punch_hole_response::Failure::LICENSE_MISMATCH) => {
bail!("Key mismatch");
}
punch_hole_response::Failure::LICENSE_OVERUSE => {
Ok(punch_hole_response::Failure::LICENSE_OVERUSE) => {
bail!("Key overuse");
}
_ => bail!("other punch hole failure"),
}
} else {
peer_nat_type = ph.nat_type();
@@ -470,11 +471,8 @@ impl Client {
)
.await;
interface.update_direct(Some(false));
if conn.is_err() {
bail!(
"Failed to connect via relay server: {}",
conn.err().unwrap()
);
if let Err(e) = conn {
bail!("Failed to connect via relay server: {}", e);
}
direct = false;
} else {
@@ -507,11 +505,13 @@ impl Client {
});
let mut sign_pk = None;
let mut option_pk = None;
if !signed_id_pk.is_empty() && rs_pk.is_some() {
if let Ok((id, pk)) = decode_id_pk(&signed_id_pk, &rs_pk.unwrap()) {
if id == peer_id {
sign_pk = Some(sign::PublicKey(pk));
option_pk = Some(pk.to_vec());
if !signed_id_pk.is_empty() {
if let Some(rs_pk) = rs_pk {
if let Ok((id, pk)) = decode_id_pk(&signed_id_pk, &rs_pk) {
if id == peer_id {
sign_pk = Some(sign::PublicKey(pk));
option_pk = Some(pk.to_vec());
}
}
}
if sign_pk.is_none() {

View File

@@ -725,7 +725,7 @@ pub fn run_me<T: AsRef<std::ffi::OsStr>>(args: Vec<T>) -> std::io::Result<std::p
}
#[cfg(feature = "appimage")]
{
let appdir = std::env::var("APPDIR").unwrap();
let appdir = std::env::var("APPDIR").map_err(|_| std::io::ErrorKind::Other)?;
let appimage_cmd = std::path::Path::new(&appdir).join("AppRun");
log::info!("path: {:?}", appimage_cmd);
return std::process::Command::new(appimage_cmd).args(&args).spawn();

View File

@@ -104,7 +104,10 @@ fn rust_args_to_c_args(args: Vec<String>, outlen: *mut c_int) -> *mut *mut c_cha
// Let's fill a vector with null-terminated strings
for s in args {
v.push(CString::new(s).unwrap());
match CString::new(s) {
Ok(s) => v.push(s),
Err(_) => return std::ptr::null_mut() as _,
}
}
// Turning each null-terminated string into a pointer.

View File

@@ -12,15 +12,14 @@ fn main() {
let args: Vec<_> = std::env::args().skip(1).collect();
let api = args.get(2).cloned().unwrap_or_default();
if args.len() >= 2 {
println!(
"rustdesk-licensed-{}.exe",
gen_name(&License {
key: args[0].clone(),
host: args[1].clone(),
api,
})
.unwrap()
);
match gen_name(&License {
key: args[0].clone(),
host: args[1].clone(),
api,
}) {
Ok(name) => println!("rustdesk-licensed-{}.exe", name),
Err(e) => println!("{:?}", e),
}
}
if args.len() == 1 {
println!("{:?}", get_license_from_string(&args[0]));

View File

@@ -64,11 +64,10 @@ impl AppHandler for Rc<Host> {
// https://github.com/xi-editor/druid/blob/master/druid-shell/src/platform/mac/application.rs
pub unsafe fn set_delegate(handler: Option<Box<dyn AppHandler>>) {
let decl = ClassDecl::new("AppDelegate", class!(NSObject));
if decl.is_none() {
let Some(mut decl) = ClassDecl::new("AppDelegate", class!(NSObject)) else {
log::error!("Failed to new AppDelegate");
return;
}
let mut decl = decl.unwrap();
};
decl.add_ivar::<*mut c_void>(APP_HANDLER_IVAR);
decl.add_method(
@@ -116,7 +115,10 @@ pub unsafe fn set_delegate(handler: Option<Box<dyn AppHandler>>) {
let handler_ptr = Box::into_raw(Box::new(state));
(*delegate).set_ivar(APP_HANDLER_IVAR, handler_ptr as *mut c_void);
// Set the url scheme handler
let cls = Class::get("NSAppleEventManager").unwrap();
let Some(cls) = Class::get("NSAppleEventManager") else {
log::error!("Failed to get NSAppleEventManager");
return;
};
let manager: *mut Object = msg_send![cls, sharedAppleEventManager];
let _: () = msg_send![manager,
setEventHandler: delegate
@@ -199,10 +201,10 @@ fn service_should_handle_reopen(
_sel: Sel,
_sender: id,
_has_visible_windows: BOOL,
) -> BOOL {
) -> BOOL {
log::debug!("Invoking the main rustdesk process");
std::thread::spawn(move || crate::handle_url_scheme("".to_string()));
// Prevent default logic.
std::thread::spawn(move || crate::handle_url_scheme("".to_string()));
// Prevent default logic.
NO
}

View File

@@ -728,7 +728,9 @@ pub fn get_double_click_time() -> u32 {
// g_object_get (settings, "gtk-double-click-time", &double_click_time, NULL);
unsafe {
let mut double_click_time = 0u32;
let property = std::ffi::CString::new("gtk-double-click-time").unwrap();
let Ok(property) = std::ffi::CString::new("gtk-double-click-time") else {
return 0;
};
let settings = gtk_settings_get_default();
g_object_get(
settings,
@@ -801,7 +803,10 @@ pub fn resolutions(name: &str) -> Vec<Resolution> {
if let Some(resolutions) = caps.name("resolutions") {
let resolution_pat =
r"\s*(?P<width>\d+)x(?P<height>\d+)\s+(?P<rates>(\d+\.\d+\D*)+)\s*\n";
let resolution_re = Regex::new(&format!(r"{}", resolution_pat)).unwrap();
let Ok(resolution_re) = Regex::new(&format!(r"{}", resolution_pat)) else {
log::error!("Regex new failed");
return vec![];
};
for resolution_caps in resolution_re.captures_iter(resolutions.as_str()) {
if let Some((width, height)) =
get_width_height_from_captures(&resolution_caps)

View File

@@ -74,7 +74,7 @@ pub fn is_can_input_monitoring(prompt: bool) -> bool {
// remove just one app from all the permissions: tccutil reset All com.carriez.rustdesk
pub fn is_can_screen_recording(prompt: bool) -> bool {
// we got some report that we show no permission even after set it, so we try to use new api for screen recording check
// the new api is only available on macOS >= 10.15, but on stackoverflow, some people said it works on >= 10.16 (crash on 10.15),
// the new api is only available on macOS >= 10.15, but on stackoverflow, some people said it works on >= 10.16 (crash on 10.15),
// but also some said it has bug on 10.16, so we just use it on 11.0.
unsafe {
if CanUseNewApiForScreenCaptureCheck() == YES {
@@ -146,14 +146,26 @@ pub fn is_installed_daemon(prompt: bool) -> bool {
return true;
}
let install_script = PRIVILEGES_SCRIPTS_DIR.get_file("install.scpt").unwrap();
let install_script_body = install_script.contents_utf8().unwrap();
let Some(install_script) = PRIVILEGES_SCRIPTS_DIR.get_file("install.scpt") else {
return false;
};
let Some(install_script_body) = install_script.contents_utf8() else {
return false;
};
let daemon_plist = PRIVILEGES_SCRIPTS_DIR.get_file(&daemon).unwrap();
let daemon_plist_body = daemon_plist.contents_utf8().unwrap();
let Some(daemon_plist) = PRIVILEGES_SCRIPTS_DIR.get_file(&daemon) else {
return false;
};
let Some(daemon_plist_body) = daemon_plist.contents_utf8() else {
return false;
};
let agent_plist = PRIVILEGES_SCRIPTS_DIR.get_file(&agent).unwrap();
let agent_plist_body = agent_plist.contents_utf8().unwrap();
let Some(agent_plist) = PRIVILEGES_SCRIPTS_DIR.get_file(&agent) else {
return false;
};
let Some(agent_plist_body) = agent_plist.contents_utf8() else {
return false;
};
std::thread::spawn(move || {
match std::process::Command::new("osascript")
@@ -198,8 +210,12 @@ pub fn uninstall_service(show_new_window: bool) -> bool {
return false;
}
let script_file = PRIVILEGES_SCRIPTS_DIR.get_file("uninstall.scpt").unwrap();
let script_body = script_file.contents_utf8().unwrap();
let Some(script_file) = PRIVILEGES_SCRIPTS_DIR.get_file("uninstall.scpt") else {
return false;
};
let Some(script_body) = script_file.contents_utf8() else {
return false;
};
std::thread::spawn(move || {
match std::process::Command::new("osascript")

View File

@@ -6,7 +6,9 @@ use crate::{
privacy_win_mag::{self, WIN_MAG_INJECTED_PROCESS_EXE},
};
use hbb_common::{
allow_err, bail,
allow_err,
anyhow::anyhow,
bail,
config::{self, Config},
log,
message_proto::Resolution,
@@ -848,10 +850,9 @@ pub fn check_update_broker_process() -> ResultType<()> {
let origin_process_exe = privacy_win_mag::ORIGIN_PROCESS_EXE;
let exe_file = std::env::current_exe()?;
if exe_file.parent().is_none() {
let Some(cur_dir) = exe_file.parent() else {
bail!("Cannot get parent of current exe file");
}
let cur_dir = exe_file.parent().unwrap();
};
let cur_exe = cur_dir.join(process_exe);
if !std::path::Path::new(&cur_exe).exists() {
@@ -902,29 +903,29 @@ fn get_install_info_with_subkey(subkey: String) -> (String, String, String, Stri
(subkey, path, start_menu, exe)
}
pub fn copy_raw_cmd(src_raw: &str, _raw: &str, _path: &str) -> String {
pub fn copy_raw_cmd(src_raw: &str, _raw: &str, _path: &str) -> ResultType<String> {
let main_raw = format!(
"XCOPY \"{}\" \"{}\" /Y /E /H /C /I /K /R /Z",
PathBuf::from(src_raw)
.parent()
.unwrap()
.ok_or(anyhow!("Can't get parent directory of {src_raw}"))?
.to_string_lossy()
.to_string(),
_path
);
return main_raw;
return Ok(main_raw);
}
pub fn copy_exe_cmd(src_exe: &str, exe: &str, path: &str) -> String {
let main_exe = copy_raw_cmd(src_exe, exe, path);
format!(
pub fn copy_exe_cmd(src_exe: &str, exe: &str, path: &str) -> ResultType<String> {
let main_exe = copy_raw_cmd(src_exe, exe, path)?;
Ok(format!(
"
{main_exe}
copy /Y \"{ORIGIN_PROCESS_EXE}\" \"{path}\\{broker_exe}\"
",
ORIGIN_PROCESS_EXE = privacy_win_mag::ORIGIN_PROCESS_EXE,
broker_exe = privacy_win_mag::INJECTED_PROCESS_EXE,
)
))
}
fn get_after_install(exe: &str) -> String {
@@ -1118,7 +1119,7 @@ copy /Y \"{tmp_path}\\Uninstall {app_name}.lnk\" \"{path}\\\"
} else {
&dels
},
copy_exe = copy_exe_cmd(&src_exe, &exe, &path),
copy_exe = copy_exe_cmd(&src_exe, &exe, &path)?,
import_config = get_import_config(&exe),
);
run_cmds(cmds, debug, "install")?;
@@ -1200,7 +1201,7 @@ fn write_cmds(cmds: String, ext: &str, tip: &str) -> ResultType<std::path::PathB
tmp.push(format!("{}_{}.{}", crate::get_app_name(), tip, ext));
let mut file = std::fs::File::create(&tmp)?;
if ext == "bat" {
let tmp2 = get_undone_file(&tmp);
let tmp2 = get_undone_file(&tmp)?;
std::fs::File::create(&tmp2).ok();
cmds = format!(
"
@@ -1231,18 +1232,20 @@ fn to_le(v: &mut [u16]) -> &[u8] {
unsafe { v.align_to().1 }
}
fn get_undone_file(tmp: &PathBuf) -> PathBuf {
fn get_undone_file(tmp: &PathBuf) -> ResultType<PathBuf> {
let mut tmp1 = tmp.clone();
tmp1.set_file_name(format!(
"{}.undone",
tmp.file_name().unwrap().to_string_lossy()
tmp.file_name()
.ok_or(anyhow!("Failed to get filename of {:?}", tmp))?
.to_string_lossy()
));
tmp1
Ok(tmp1)
}
fn run_cmds(cmds: String, show: bool, tip: &str) -> ResultType<()> {
let tmp = write_cmds(cmds, "bat", tip)?;
let tmp2 = get_undone_file(&tmp);
let tmp2 = get_undone_file(&tmp)?;
let tmp_fn = tmp.to_str().unwrap_or("");
let res = runas::Command::new("cmd")
.args(&["/C", &tmp_fn])

View File

@@ -153,10 +153,10 @@ pub fn start() -> ResultType<()> {
}
let exe_file = std::env::current_exe()?;
if exe_file.parent().is_none() {
let Some(cur_dir) = exe_file
.parent() else {
bail!("Cannot get parent of current exe file");
}
let cur_dir = exe_file.parent().unwrap();
};
let dll_file = cur_dir.join("WindowInjection.dll");
if !dll_file.exists() {
@@ -344,6 +344,7 @@ async fn set_privacy_mode_state(
}
pub(super) mod privacy_hook {
use super::*;
use std::sync::mpsc::{channel, Sender};
@@ -426,7 +427,7 @@ pub(super) mod privacy_hook {
}
Err(e) => {
// Fatal error
tx.send(format!("Unexpected err when hook {}", e)).unwrap();
allow_err!(tx.send(format!("Unexpected err when hook {}", e)));
return;
}
}

View File

@@ -186,16 +186,18 @@ impl RendezvousMediator {
}
Some(rendezvous_message::Union::RegisterPkResponse(rpr)) => {
update_latency();
match rpr.result.enum_value_or_default() {
register_pk_response::Result::OK => {
match rpr.result.enum_value() {
Ok(register_pk_response::Result::OK) => {
Config::set_key_confirmed(true);
Config::set_host_key_confirmed(&rz.host_prefix, true);
*SOLVING_PK_MISMATCH.lock().unwrap() = "".to_owned();
}
register_pk_response::Result::UUID_MISMATCH => {
Ok(register_pk_response::Result::UUID_MISMATCH) => {
allow_err!(rz.handle_uuid_mismatch(&mut socket).await);
}
_ => {}
_ => {
log::error!("unknown RegisterPkResponse");
}
}
}
Some(rendezvous_message::Union::PunchHole(ph)) => {
@@ -376,7 +378,7 @@ impl RendezvousMediator {
async fn handle_punch_hole(&self, ph: PunchHole, server: ServerPtr) -> ResultType<()> {
let relay_server = self.get_relay_server(ph.relay_server);
if ph.nat_type.enum_value_or_default() == NatType::SYMMETRIC
if ph.nat_type.enum_value() == Ok(NatType::SYMMETRIC)
|| Config::get_nat_type() == NatType::SYMMETRIC as i32
{
let uuid = Uuid::new_v4().to_string();
@@ -515,7 +517,7 @@ async fn direct_server(server: ServerPtr) {
listener = Some(l);
log::info!(
"Direct server listening on: {:?}",
listener.as_ref().unwrap().local_addr()
listener.as_ref().map(|l| l.local_addr())
);
}
Err(err) => {

View File

@@ -13,10 +13,10 @@
// https://github.com/krruzic/pulsectl
use super::*;
use magnum_opus::{Application::*, Channels::*, Encoder};
use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(not(any(target_os = "linux", target_os = "android")))]
use hbb_common::anyhow::anyhow;
use magnum_opus::{Application::*, Channels::*, Encoder};
use std::sync::atomic::{AtomicBool, Ordering};
pub const NAME: &'static str = "audio";
pub const AUDIO_DATA_SIZE_U8: usize = 960 * 4; // 10ms in 48000 stereo
@@ -206,13 +206,10 @@ mod cpal_impl {
}
}
}
if device.is_none() {
device = Some(
HOST.default_input_device()
.with_context(|| "Failed to get default input device for loopback")?,
);
}
let device = device.unwrap();
let device = device.unwrap_or(
HOST.default_input_device()
.with_context(|| "Failed to get default input device for loopback")?,
);
log::info!("Input device: {}", device.name().unwrap_or("".to_owned()));
let format = device
.default_input_config()

View File

@@ -665,11 +665,11 @@ impl Connection {
}
MessageInput::Key((mut msg, press)) => {
// todo: press and down have similar meanings.
if press && msg.mode.unwrap() == KeyboardMode::Legacy {
if press && msg.mode.enum_value() == Ok(KeyboardMode::Legacy) {
msg.down = true;
}
handle_key(&msg);
if press && msg.mode.unwrap() == KeyboardMode::Legacy {
if press && msg.mode.enum_value() == Ok(KeyboardMode::Legacy) {
msg.down = false;
handle_key(&msg);
}
@@ -1621,11 +1621,11 @@ impl Connection {
me.press
};
let key = match me.mode.enum_value_or_default() {
KeyboardMode::Map => {
let key = match me.mode.enum_value() {
Ok(KeyboardMode::Map) => {
Some(crate::keyboard::keycode_to_rdev_key(me.chr()))
}
KeyboardMode::Translate => {
Ok(KeyboardMode::Translate) => {
if let Some(key_event::Union::Chr(code)) = me.union {
Some(crate::keyboard::keycode_to_rdev_key(code & 0x0000FFFF))
} else {
@@ -1908,11 +1908,9 @@ impl Connection {
// Drop the audio sender previously.
drop(std::mem::replace(&mut self.audio_sender, None));
self.audio_sender = Some(start_audio_thread());
allow_err!(self
.audio_sender
self.audio_sender
.as_ref()
.unwrap()
.send(MediaData::AudioFormat(format)));
.map(|a| allow_err!(a.send(MediaData::AudioFormat(format))));
}
}
#[cfg(feature = "flutter")]
@@ -2341,6 +2339,8 @@ async fn start_ipc(
mut _rx_desktop_ready: mpsc::Receiver<()>,
tx_stream_ready: mpsc::Sender<()>,
) -> ResultType<()> {
use hbb_common::anyhow::anyhow;
loop {
if !crate::platform::is_prelogin() {
break;
@@ -2434,7 +2434,7 @@ async fn start_ipc(
}
let _res = tx_stream_ready.send(()).await;
let mut stream = stream.unwrap();
let mut stream = stream.ok_or(anyhow!("none stream"))?;
loop {
tokio::select! {
res = stream.next() => {

View File

@@ -1497,11 +1497,11 @@ pub fn handle_key_(evt: &KeyEvent) {
_ => {}
};
match evt.mode.unwrap() {
KeyboardMode::Map => {
match evt.mode.enum_value() {
Ok(KeyboardMode::Map) => {
map_keyboard_mode(evt);
}
KeyboardMode::Translate => {
Ok(KeyboardMode::Translate) => {
translate_keyboard_mode(evt);
}
_ => {

View File

@@ -231,7 +231,13 @@ pub mod server {
}
pub fn run_portable_service() {
let shmem = Arc::new(SharedMemory::open_existing(SHMEM_NAME).unwrap());
let shmem = match SharedMemory::open_existing(SHMEM_NAME) {
Ok(shmem) => Arc::new(shmem),
Err(e) => {
log::error!("Failed to open existing shared memory: {:?}", e);
return;
}
};
let shmem1 = shmem.clone();
let shmem2 = shmem.clone();
let mut threads = vec![];
@@ -249,7 +255,7 @@ pub mod server {
}));
let record_pos_handle = crate::input_service::try_start_record_cursor_pos();
for th in threads.drain(..) {
th.join().unwrap();
th.join().ok();
log::info!("thread joined");
}
@@ -319,7 +325,11 @@ pub mod server {
}
if c.is_none() {
*crate::video_service::CURRENT_DISPLAY.lock().unwrap() = current_display;
let (_, _current, display) = get_current_display().unwrap();
let Ok((_, _current, display)) = get_current_display() else {
log::error!("Failed to get current display");
*EXIT.lock().unwrap() = true;
return;
};
display_width = display.width();
display_height = display.height();
match Capturer::new(display, use_yuv) {
@@ -380,8 +390,8 @@ pub mod server {
continue;
}
}
match c.as_mut().unwrap().frame(spf) {
Ok(f) => {
match c.as_mut().map(|f| f.frame(spf)) {
Some(Ok(f)) => {
utils::set_frame_info(
&shmem,
FrameInfo {
@@ -396,7 +406,7 @@ pub mod server {
first_frame_captured = true;
dxgi_failed_times = 0;
}
Err(e) => {
Some(Err(e)) => {
if e.kind() != std::io::ErrorKind::WouldBlock {
// DXGI_ERROR_INVALID_CALL after each success on Microsoft GPU driver
// log::error!("capture frame failed:{:?}", e);
@@ -406,7 +416,8 @@ pub mod server {
std::thread::sleep(spf);
continue;
}
if !c.as_ref().unwrap().is_gdi() {
if c.as_ref().map(|c| c.is_gdi()) == Some(false) {
// nog gdi
dxgi_failed_times += 1;
}
if dxgi_failed_times > MAX_DXGI_FAIL_TIME {
@@ -418,6 +429,9 @@ pub mod server {
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(TRUE));
}
}
_ => {
println!("unreachable!");
}
}
}
}

View File

@@ -144,7 +144,7 @@ pub fn capture_cursor_embedded() -> bool {
#[inline]
pub fn notify_video_frame_fetched(conn_id: i32, frame_tm: Option<Instant>) {
FRAME_FETCHED_NOTIFIER.0.send((conn_id, frame_tm)).unwrap()
FRAME_FETCHED_NOTIFIER.0.send((conn_id, frame_tm)).ok();
}
#[inline]

View File

@@ -124,8 +124,16 @@ pub fn start(args: &mut [String]) {
crate::platform::windows::enable_lowlevel_keyboard(hw as _);
}
let mut iter = args.iter();
let cmd = iter.next().unwrap().clone();
let id = iter.next().unwrap().clone();
let Some(cmd) = iter.next() else {
log::error!("Failed to get cmd arg");
return;
};
let cmd = cmd.to_owned();
let Some(id) = iter.next() else {
log::error!("Failed to get id arg");
return;
};
let id = id.to_owned();
let pass = iter.next().unwrap_or(&"".to_owned()).clone();
let args: Vec<String> = iter.map(|x| x.clone()).collect();
frame.set_title(&id);
@@ -259,7 +267,8 @@ impl UI {
}
fn get_options(&self) -> Value {
let hashmap: HashMap<String, String> = serde_json::from_str(&get_options()).unwrap();
let hashmap: HashMap<String, String> =
serde_json::from_str(&get_options()).unwrap_or_default();
let mut m = Value::map();
for (k, v) in hashmap {
m.set_item(k, v);

View File

@@ -377,7 +377,7 @@ impl sciter::EventHandler for SciterSession {
let source = Element::from(source);
use sciter::dom::ELEMENT_AREAS;
let flags = ELEMENT_AREAS::CONTENT_BOX as u32 | ELEMENT_AREAS::SELF_RELATIVE as u32;
let rc = source.get_location(flags).unwrap();
let rc = source.get_location(flags).unwrap_or_default();
log::debug!(
"[video] start video thread on <{}> which is about {:?} pixels",
source,

View File

@@ -233,7 +233,7 @@ pub fn get_options() -> String {
for (k, v) in options.iter() {
m.insert(k.into(), v.to_owned().into());
}
serde_json::to_string(&m).unwrap()
serde_json::to_string(&m).unwrap_or_default()
}
#[inline]
@@ -1112,23 +1112,23 @@ async fn check_id(
{
match msg_in.union {
Some(rendezvous_message::Union::RegisterPkResponse(rpr)) => {
match rpr.result.enum_value_or_default() {
register_pk_response::Result::OK => {
match rpr.result.enum_value() {
Ok(register_pk_response::Result::OK) => {
ok = true;
}
register_pk_response::Result::ID_EXISTS => {
Ok(register_pk_response::Result::ID_EXISTS) => {
return "Not available";
}
register_pk_response::Result::TOO_FREQUENT => {
Ok(register_pk_response::Result::TOO_FREQUENT) => {
return "Too frequent";
}
register_pk_response::Result::NOT_SUPPORT => {
Ok(register_pk_response::Result::NOT_SUPPORT) => {
return "server_not_support";
}
register_pk_response::Result::SERVER_ERROR => {
Ok(register_pk_response::Result::SERVER_ERROR) => {
return "Server error";
}
register_pk_response::Result::INVALID_ID_FORMAT => {
Ok(register_pk_response::Result::INVALID_ID_FORMAT) => {
return INVALID_FORMAT;
}
_ => {}