plugin_framework, plugin manager, debug linux
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
8e117b6dde
commit
7190d451d4
@ -660,6 +660,25 @@ pub fn check_super_user_permission() -> ResultType<bool> {
|
|||||||
Ok(status.success() && status.code() == Some(0))
|
Ok(status.success() && status.code() == Some(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn elevate(arg: Vec<&str>) -> ResultType<Option<Child>> {
|
||||||
|
let cmd = std::env::current_exe()?;
|
||||||
|
match cmd.to_str() {
|
||||||
|
Some(cmd) => {
|
||||||
|
let mut args = vec![cmd];
|
||||||
|
args.append(&mut arg.clone());
|
||||||
|
// -E required for opensuse
|
||||||
|
if is_opensuse() {
|
||||||
|
args.insert(0, "-E");
|
||||||
|
}
|
||||||
|
let task = Command::new("pkexec").args(args).spawn()?;
|
||||||
|
Ok(Some(task))
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
hbb_common::bail!("Failed to get current exe as str");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type GtkSettingsPtr = *mut c_void;
|
type GtkSettingsPtr = *mut c_void;
|
||||||
type GObjectPtr = *mut c_void;
|
type GObjectPtr = *mut c_void;
|
||||||
#[link(name = "gtk-3")]
|
#[link(name = "gtk-3")]
|
||||||
|
@ -54,27 +54,6 @@ pub fn get_active_username() -> String {
|
|||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub const PA_SAMPLE_RATE: u32 = 48000;
|
pub const PA_SAMPLE_RATE: u32 = 48000;
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
|
||||||
pub fn run_as_root(arg: Vec<&str>) -> ResultType<Option<Child>> {
|
|
||||||
let cmd = std::env::current_exe()?;
|
|
||||||
match cmd.to_str() {
|
|
||||||
Some(cmd) => {
|
|
||||||
let mut args = vec![cmd];
|
|
||||||
args.append(&mut arg.clone());
|
|
||||||
// -E required for opensuse
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
if is_opensuse() {
|
|
||||||
args.insert(0, "-E");
|
|
||||||
}
|
|
||||||
let task = Command::new("sudo").args(args).spawn()?;
|
|
||||||
Ok(Some(task))
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
bail!("Failed to get current exe as str");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
use crate::ipc::{connect, Connection, Data};
|
use crate::ipc::{connect, Connection, Data};
|
||||||
use hbb_common::{allow_err, log, tokio, ResultType};
|
use hbb_common::{allow_err, log, tokio, ResultType};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
#[cfg(not(windows))]
|
|
||||||
use std::{fs::File, io::prelude::*};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub enum InstallStatus {
|
pub enum InstallStatus {
|
||||||
|
@ -190,19 +190,30 @@ pub fn install_plugin(id: &str) -> ResultType<()> {
|
|||||||
if !same_plugin_exists {
|
if !same_plugin_exists {
|
||||||
args.push(&plugin_url);
|
args.push(&plugin_url);
|
||||||
}
|
}
|
||||||
allowed_install = match crate::platform::run_as_root(&args) {
|
allowed_install = match crate::platform::elevate(args) {
|
||||||
Ok(child) => match child.wait() {
|
Ok(Some(mut child)) => match child.wait() {
|
||||||
Ok(0) => true,
|
Ok(status) => {
|
||||||
Ok(code) => {
|
if status.success() {
|
||||||
log::error!("Failed to wait install process, process code: {}", code);
|
true
|
||||||
true
|
} else {
|
||||||
|
log::error!(
|
||||||
|
"Failed to wait install process, process status: {:?}",
|
||||||
|
status
|
||||||
|
);
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Failed to wait install process, error: {}", e);
|
log::error!("Failed to wait install process, error: {}", e);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
Ok(None) => false,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to run install process, error: {}", e);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if allowed_install && same_plugin_exists {
|
if allowed_install && same_plugin_exists {
|
||||||
@ -256,7 +267,6 @@ pub(super) fn remove_plugins() -> ResultType<()> {
|
|||||||
|
|
||||||
pub fn uninstall_plugin(id: &str, called_by_ui: bool) {
|
pub fn uninstall_plugin(id: &str, called_by_ui: bool) {
|
||||||
if called_by_ui {
|
if called_by_ui {
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
match crate::platform::check_super_user_permission() {
|
match crate::platform::check_super_user_permission() {
|
||||||
Ok(true) => {
|
Ok(true) => {
|
||||||
if let Err(e) = super::ipc::uninstall_plugin(id) {
|
if let Err(e) = super::ipc::uninstall_plugin(id) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use hbb_common::{libc, log, ResultType};
|
use hbb_common::{libc, log, ResultType};
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
use std::env;
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
|
||||||
ffi::{c_char, c_int, c_void, CStr},
|
ffi::{c_char, c_int, c_void, CStr},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
ptr::null,
|
ptr::null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user