mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 09:22:26 -04:00
Add basic running script functionality.
Will likely move api methods out to be more generic, but this runs for now and gives true on success, false on failure, etc. May also need to change from process.poll to wait for longer running scripts. will do once tested more.
This commit is contained in:
parent
8f0f6e7976
commit
e2cc4c2b38
3 changed files with 32 additions and 0 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -875,10 +875,21 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"serde",
|
"serde",
|
||||||
|
"subprocess",
|
||||||
"zbus",
|
"zbus",
|
||||||
"zbus_macros",
|
"zbus_macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subprocess"
|
||||||
|
version = "0.2.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
|
|
@ -8,5 +8,6 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-std = { version = "1.12.0", features = ["attributes"] }
|
async-std = { version = "1.12.0", features = ["attributes"] }
|
||||||
serde = { version = "1.0.188", features = ["derive"] }
|
serde = { version = "1.0.188", features = ["derive"] }
|
||||||
|
subprocess = "0.2.9"
|
||||||
zbus = "3.14.1"
|
zbus = "3.14.1"
|
||||||
zbus_macros = "3.14.1"
|
zbus_macros = "3.14.1"
|
||||||
|
|
|
@ -23,19 +23,39 @@
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use subprocess::{ExitStatus::Exited, Popen, PopenConfig, Redirection};
|
||||||
use zbus_macros::dbus_interface;
|
use zbus_macros::dbus_interface;
|
||||||
use zbus::{ObjectServer, SignalContext, MessageHeader};
|
use zbus::{ObjectServer, SignalContext, MessageHeader};
|
||||||
pub struct SMManager {
|
pub struct SMManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_script(script: String) -> bool {
|
||||||
|
// Run given script and return true on success
|
||||||
|
let mut process = Popen::create(&[script], PopenConfig {
|
||||||
|
stdout: Redirection::Pipe, ..Default::default()
|
||||||
|
}).unwrap();
|
||||||
|
let (out, err) = process.communicate(None).unwrap();
|
||||||
|
if let Some(exit_status) = process.poll() {
|
||||||
|
return exit_status == Exited(0);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[dbus_interface(name = "com.steampowered.SteamOSManager1")]
|
#[dbus_interface(name = "com.steampowered.SteamOSManager1")]
|
||||||
impl SMManager {
|
impl SMManager {
|
||||||
const API_VERSION: u32 = 1;
|
const API_VERSION: u32 = 1;
|
||||||
|
|
||||||
|
|
||||||
async fn say_hello(&self, name: &str) -> String {
|
async fn say_hello(&self, name: &str) -> String {
|
||||||
format!("Hello {}!", name)
|
format!("Hello {}!", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn factory_reset(&self) -> bool {
|
||||||
|
// Run steamos factory reset script and return true on success
|
||||||
|
return run_script("steamos-factory-reset".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
/// A version property.
|
/// A version property.
|
||||||
#[dbus_interface(property)]
|
#[dbus_interface(property)]
|
||||||
async fn version(&self) -> u32 {
|
async fn version(&self) -> u32 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue