Desktop file parsing improvements

This commit is contained in:
Nicola Guerrera
2023-02-28 12:17:15 +01:00
parent fd1272224a
commit abcf78797c
4 changed files with 36 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ use color_eyre::eyre::{eyre, Result};
use glam::Quat;
use mint::Vector3;
use nix::unistd::setsid;
use regex::Regex;
use stardust_xr_fusion::{
client::{Client, FrameInfo, RootHandler},
core::values::Transform,
@@ -174,7 +175,7 @@ impl RootHandler for ProtoStar {
let scale = grabbabe_move.move_by(info.delta);
self.grabbable
.content_parent()
.set_position(None, [self.position.x*scale, self.position.y*scale, self.position.z*scale])
.set_position(Some(self.client.get_root()), [self.position.x*scale, self.position.y*scale, self.position.z*scale])
.unwrap();
} else {
if grabbabe_move.final_value() == 0.0001 {
@@ -237,9 +238,9 @@ impl RootHandler for ProtoStar {
.get_position_rotation_scale(self.client.get_root())
.unwrap();
let executable = dbg!(self.execute_command.clone());
let executable = self.execute_command.clone();
//TODO: split the executable string for the args
//TODO: split the executable string for the args
tokio::task::spawn(async move {
let distance_vector = distance_future.await.ok().unwrap().0;
let distance =
@@ -248,9 +249,12 @@ impl RootHandler for ProtoStar {
let future = startup_settings.generate_startup_token().unwrap();
std::env::set_var("STARDUST_STARTUP_TOKEN", future.await.unwrap());
let re = Regex::new(r"%[fFuUdDnNickvm]").unwrap();
let exec = re.replace_all(&executable, "");
let mut executable_array : Vec<&str> = dbg!(exec.split_whitespace().collect());
unsafe {
Command::new(executable)
Command::new(executable_array.remove(0))
.args(executable_array)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())

View File

@@ -12,7 +12,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{env, fs};
use walkdir::WalkDir;
use regex::Regex;
fn get_data_dirs() -> Vec<PathBuf> {
let xdg_data_dirs_str = std::env::var("XDG_DATA_DIRS").unwrap_or_default();
@@ -88,9 +88,13 @@ pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> {
let mut categories = Vec::new();
let mut icon = None;
let mut no_display = false;
let mut desktop_entry_found = false;
let re = Regex::new(r"^\[([^\]]*)\]$").unwrap();
// Loop through each line of the file
for line in reader.lines() {
let line = match line {
Ok(line) => line,
Err(err) => return Err(format!("Failed to read line: {}", err)),
@@ -101,6 +105,14 @@ pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> {
continue;
}
if let Some(captures) = re.captures(&line){
let entry = captures.get(1).unwrap();
desktop_entry_found = entry.as_str().contains("Desktop Entry");
}
if !desktop_entry_found {
continue
}
// Split the line into a key-value pair by looking for the first "=" character
let parts = line.split_once('=');
let (key, value) = match parts {