portable service

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-11-10 10:27:13 +08:00
parent eb60ab0b79
commit 8e1545b432
46 changed files with 1217 additions and 72 deletions

View File

@@ -85,6 +85,8 @@ pub trait InvokeUiCM: Send + Clone + 'static + Sized {
fn change_theme(&self, dark: String);
fn change_language(&self);
fn show_elevation(&self, show: bool);
}
impl<T: InvokeUiCM> Deref for ConnectionManager<T> {
@@ -171,6 +173,10 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
self.ui_handler.remove_connection(id, close);
}
fn show_elevation(&self, show: bool) {
self.ui_handler.show_elevation(show);
}
}
#[inline]
@@ -362,6 +368,9 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
LocalConfig::set_option("lang".to_owned(), lang);
self.cm.change_language();
}
Data::DataPortableService(ipc::DataPortableService::CmShowElevation(show)) => {
self.cm.show_elevation(show);
}
_ => {
}
@@ -757,3 +766,28 @@ fn cm_inner_send(id: i32, data: Data) {
}
}
}
pub fn can_elevate() -> bool {
#[cfg(windows)]
{
use crate::portable_service::client::{
PortableServiceStatus::NotStarted, PORTABLE_SERVICE_STATUS,
};
return !crate::platform::is_installed()
&& PORTABLE_SERVICE_STATUS.lock().unwrap().clone() == NotStarted;
}
#[cfg(not(windows))]
return false;
}
pub fn elevate_portable(id: i32) {
#[cfg(windows)]
{
let lock = CLIENTS.read().unwrap();
if let Some(s) = lock.get(&id) {
allow_err!(s.tx.send(ipc::Data::DataPortableService(
ipc::DataPortableService::RequestStart
)));
}
}
}