Desktop file parsing improvements

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

12
Cargo.lock generated
View File

@@ -40,6 +40,15 @@ dependencies = [
"version_check",
]
[[package]]
name = "aho-corasick"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "aliasable"
version = "0.1.3"
@@ -1537,6 +1546,7 @@ dependencies = [
"manifest-dir-macros",
"mint",
"nix 0.26.1",
"regex",
"resvg",
"rustc-hash",
"stardust-xr-fusion",
@@ -1679,6 +1689,8 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]

View File

@@ -17,6 +17,7 @@ linicon = "2.3.0"
manifest-dir-macros = "0.1.16"
mint = "0.5.9"
nix = "0.26.1"
regex = "1.7.1"
resvg = "0.29.0"
rustc-hash = "1.1.0"
stardust-xr-fusion = "0.38.1"
@@ -28,4 +29,4 @@ ustr = "0.9.0"
walkdir = "2.3.2"
[dev-dependencies]
tempdir = "0.3.7"
tempdir = "0.3.7"

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 {