Fix usage of loginctl inside flatpak
Signed-off-by: sandroid <sandroid@posteo.net>
This commit is contained in:
parent
c67c55f74b
commit
e667dad144
@ -38,6 +38,7 @@ machine-uid = "0.2"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
quic = []
|
quic = []
|
||||||
|
flatpak = []
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
protobuf-codegen = { version = "3.1" }
|
protobuf-codegen = { version = "3.1" }
|
||||||
|
@ -6,9 +6,7 @@ pub fn get_display_server() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_display_server_of_session(session: &str) -> String {
|
fn get_display_server_of_session(session: &str) -> String {
|
||||||
if let Ok(output) = std::process::Command::new("loginctl")
|
if let Ok(output) = run_loginctl(Some(vec!["show-session", "-p", "Type", session]))
|
||||||
.args(vec!["show-session", "-p", "Type", session])
|
|
||||||
.output()
|
|
||||||
// Check session type of the session
|
// Check session type of the session
|
||||||
{
|
{
|
||||||
let display_server = String::from_utf8_lossy(&output.stdout)
|
let display_server = String::from_utf8_lossy(&output.stdout)
|
||||||
@ -17,9 +15,7 @@ fn get_display_server_of_session(session: &str) -> String {
|
|||||||
.into();
|
.into();
|
||||||
if display_server == "tty" {
|
if display_server == "tty" {
|
||||||
// If the type is tty...
|
// If the type is tty...
|
||||||
if let Ok(output) = std::process::Command::new("loginctl")
|
if let Ok(output) = run_loginctl(Some(vec!["show-session", "-p", "TTY", session]))
|
||||||
.args(vec!["show-session", "-p", "TTY", session])
|
|
||||||
.output()
|
|
||||||
// Get the tty number
|
// Get the tty number
|
||||||
{
|
{
|
||||||
let tty: String = String::from_utf8_lossy(&output.stdout)
|
let tty: String = String::from_utf8_lossy(&output.stdout)
|
||||||
@ -56,7 +52,7 @@ fn get_display_server_of_session(session: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_value_of_seat0(i: usize) -> String {
|
pub fn get_value_of_seat0(i: usize) -> String {
|
||||||
if let Ok(output) = std::process::Command::new("loginctl").output() {
|
if let Ok(output) = run_loginctl(None) {
|
||||||
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
||||||
if line.contains("seat0") {
|
if line.contains("seat0") {
|
||||||
if let Some(sid) = line.split_whitespace().nth(0) {
|
if let Some(sid) = line.split_whitespace().nth(0) {
|
||||||
@ -71,7 +67,7 @@ pub fn get_value_of_seat0(i: usize) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// some case, there is no seat0 https://github.com/rustdesk/rustdesk/issues/73
|
// some case, there is no seat0 https://github.com/rustdesk/rustdesk/issues/73
|
||||||
if let Ok(output) = std::process::Command::new("loginctl").output() {
|
if let Ok(output) = run_loginctl(None) {
|
||||||
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
||||||
if let Some(sid) = line.split_whitespace().nth(0) {
|
if let Some(sid) = line.split_whitespace().nth(0) {
|
||||||
let d = get_display_server_of_session(sid);
|
let d = get_display_server_of_session(sid);
|
||||||
@ -93,9 +89,7 @@ pub fn get_value_of_seat0(i: usize) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_active(sid: &str) -> bool {
|
fn is_active(sid: &str) -> bool {
|
||||||
if let Ok(output) = std::process::Command::new("loginctl")
|
if let Ok(output) = run_loginctl(Some(vec!["show-session", "-p", "State", sid]))
|
||||||
.args(vec!["show-session", "-p", "State", sid])
|
|
||||||
.output()
|
|
||||||
{
|
{
|
||||||
String::from_utf8_lossy(&output.stdout).contains("active")
|
String::from_utf8_lossy(&output.stdout).contains("active")
|
||||||
} else {
|
} else {
|
||||||
@ -109,3 +103,23 @@ pub fn run_cmds(cmds: String) -> ResultType<String> {
|
|||||||
.output()?;
|
.output()?;
|
||||||
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "flatpak"))]
|
||||||
|
fn run_loginctl(args: Option<Vec<&str>>) -> std::io::Result<std::process::Output> {
|
||||||
|
let mut cmd = std::process::Command::new("loginctl");
|
||||||
|
if let Some(a) = args {
|
||||||
|
return cmd.args(a).output();
|
||||||
|
}
|
||||||
|
cmd.output()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "flatpak")]
|
||||||
|
fn run_loginctl(args: Option<Vec<&str>>) -> std::io::Result<std::process::Output> {
|
||||||
|
let mut l_args = String::from("loginctl");
|
||||||
|
if let Some(a) = args {
|
||||||
|
l_args = format!("{} {}", l_args, a.join(" "));
|
||||||
|
}
|
||||||
|
std::process::Command::new("flatpak-spawn")
|
||||||
|
.args(vec![String::from("--host"), l_args])
|
||||||
|
.output()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user