sciter hide cm (#12570)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2025-08-07 13:29:21 +08:00
committed by GitHub
parent 725a47268e
commit 77be752ff1
3 changed files with 36 additions and 8 deletions

View File

@@ -118,6 +118,11 @@ pub fn start(args: &mut [String]) {
Box::new(cm::SciterConnectionManager::new())
});
page = "cm.html";
*cm::HIDE_CM.lock().unwrap() = crate::ipc::get_config("hide_cm")
.ok()
.flatten()
.unwrap_or_default()
== "true";
} else if (args[0] == "--connect"
|| args[0] == "--file-transfer"
|| args[0] == "--port-forward"
@@ -178,6 +183,13 @@ pub fn start(args: &mut [String]) {
.unwrap_or("".to_owned()),
page
));
let hide_cm = *cm::HIDE_CM.lock().unwrap();
if !args.is_empty() && args[0] == "--cm" && hide_cm {
// run_app calls expand(show) + run_loop, we use collapse(hide) + run_loop instead to create a hidden window
frame.collapse(true);
frame.run_loop();
return;
}
frame.run_app();
}
@@ -633,9 +645,9 @@ impl UI {
pub fn verify2fa(&self, code: String) -> bool {
verify2fa(code)
}
fn verify_login(&self, raw: String, id: String) -> bool {
crate::verify_login(&raw, &id)
crate::verify_login(&raw, &id)
}
fn generate_2fa_img_src(&self, data: String) -> String {

View File

@@ -7,6 +7,10 @@ use sciter::{make_args, Element, Value, HELEMENT};
use std::sync::Mutex;
use std::{ops::Deref, sync::Arc};
lazy_static::lazy_static! {
pub static ref HIDE_CM: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
}
#[derive(Clone, Default)]
pub struct SciterHandler {
pub element: Arc<Mutex<Option<Element>>>,
@@ -151,6 +155,10 @@ impl SciterConnectionManager {
fn get_option(&self, key: String) -> String {
crate::ui_interface::get_option(key)
}
fn hide_cm(&self) -> bool {
*crate::ui::cm::HIDE_CM.lock().unwrap()
}
}
impl sciter::EventHandler for SciterConnectionManager {
@@ -172,5 +180,6 @@ impl sciter::EventHandler for SciterConnectionManager {
fn can_elevate();
fn elevate_portable(i32);
fn get_option(String);
fn hide_cm();
}
}

View File

@@ -6,6 +6,13 @@ var show_chat = false;
var show_elevation = true;
var svg_elevate = <svg t="1667992597853" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1850" width="16" height="16" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M892.761 160.724v426.504c0 25.588-6.419 51.036-19.177 76.339-12.798 25.336-29.547 49.86-50.254 73.627-20.707 23.79-44.372 46.296-70.97 67.516-26.589 21.244-53.543 40.177-80.921 56.768-27.363 16.623-53.968 30.461-79.801 41.438-25.809 11.008-48.433 18.547-67.871 22.64l-9.203 1.53-8.43-1.53c-19.958-4.093-43.094-11.632-69.432-22.64-26.337-10.969-53.708-24.816-82.080-41.438-28.388-16.591-56.256-35.524-83.618-56.768-27.378-21.219-51.776-43.725-73.265-67.516-21.488-23.759-38.868-48.291-52.155-73.627-13.319-25.305-19.974-50.759-19.974-76.339v-426.504l31.455-4.629 352.892-65.97 359.784 65.97 23.017 4.629zM510.028 151.884l-4.211-0.844-302.89 51.476v269.101h307.102v-319.734zM815.434 471.634h-305.406v383.031c19.682-4.51 41.052-11.411 64.141-20.692 23.033-9.249 45.815-20.234 68.304-32.867 22.513-12.672 44.159-26.739 64.969-42.203 20.818-15.472 39.23-32.047 55.277-49.797 16.024-17.703 28.822-36.131 38.386-55.222 9.549-19.131 14.328-38.553 14.328-58.235v-124.015z" p-id="1851" fill="#ffffff"></path></svg>;
var hide_cm = undefined;
function setWindowState(state) {
if (hide_cm == undefined) hide_cm = handler.hide_cm();
if (hide_cm) return;
view.windowState = state;
}
class Body: Reactor.Component
{
this var cur = 0;
@@ -163,7 +170,7 @@ class Body: Reactor.Component
body.update();
handler.authorize(cid);
self.timer(30ms, function() {
view.windowState = View.WINDOW_MINIMIZED;
setWindowState(View.WINDOW_MINIMIZED);
});
});
}
@@ -177,7 +184,7 @@ class Body: Reactor.Component
handler.elevate_portable(cid);
handler.authorize(cid);
self.timer(30ms, function() {
view.windowState = View.WINDOW_MINIMIZED;
setWindowState(View.WINDOW_MINIMIZED);
});
});
}
@@ -189,7 +196,7 @@ class Body: Reactor.Component
body.update();
handler.elevate_portable(cid);
self.timer(30ms, function() {
view.windowState = View.WINDOW_MINIMIZED;
setWindowState(View.WINDOW_MINIMIZED);
});
});
}
@@ -350,7 +357,7 @@ function bring_to_top(idx=-1) {
if (is_linux) {
view.focus = self;
} else {
view.windowState = View.WINDOW_SHOWN;
setWindowState(View.WINDOW_SHOWN);
}
if (idx >= 0) body.cur = idx;
} else {
@@ -396,7 +403,7 @@ handler.addConnection = function(id, is_file_transfer, is_view_camera, is_termin
self.timer(1ms, adjustHeader);
if (authorized) {
self.timer(3s, function() {
view.windowState = View.WINDOW_MINIMIZED;
setWindowState(View.WINDOW_MINIMIZED);
});
}
}
@@ -509,7 +516,7 @@ var tm0 = getTime();
function self.closing() {
if (connections.length == 0 && getTime() - tm0 > 30000) return true;
view.windowState = View.WINDOW_HIDDEN;
setWindowState(View.WINDOW_HIDDEN);
return false;
}