allow multiple types in rofi-steam-game-list

This commit is contained in:
chayleaf 2023-03-07 19:46:23 +07:00
parent 19f01e9998
commit a53cd961f6
3 changed files with 12 additions and 11 deletions

View file

@ -1,11 +1,11 @@
{ lib, rustPlatform }: { lib, rustPlatform, nix-gitignore }:
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "home-daemon"; pname = "home-daemon";
version = "0.1"; version = "0.1";
src = ../home-daemon; src = nix-gitignore.gitignoreSource ["/target" "default.nix"] (lib.cleanSource ./.);
cargoLock.lockFile = ../home-daemon/Cargo.lock; cargoLock.lockFile = ./Cargo.lock;
meta = with lib; { meta = with lib; {
description = "My custom home daemon"; description = "My custom home daemon";

View file

@ -1,11 +1,11 @@
{ lib, rustPlatform }: { lib, rustPlatform, nix-gitignore }:
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "rofi-steam-game-list"; pname = "rofi-steam-game-list";
version = "0.1"; version = "0.1";
src = ../rofi-steam-game-list; src = nix-gitignore.gitignoreSource ["/target" "default.nix"] (lib.cleanSource ./.);
cargoLock.lockFile = ../rofi-steam-game-list/Cargo.lock; cargoLock.lockFile = ./Cargo.lock;
meta = with lib; { meta = with lib; {
description = "A program to list Steam games for Rofi"; description = "A program to list Steam games for Rofi";

View file

@ -255,11 +255,12 @@ fn read_time(s: String) -> io::Result<SystemTime> {
std::fs::metadata(s + "/Steam/appcache/appinfo.vdf")?.modified() std::fs::metadata(s + "/Steam/appcache/appinfo.vdf")?.modified()
} }
fn read_appinfo(target_type: String, s: String) -> io::Result<(SystemTime, Vec<(u32, String)>)> { fn read_appinfo(target_type: &str, s: String) -> io::Result<(SystemTime, Vec<(u32, String)>)> {
let time = read_time(s.clone())?; let time = read_time(s.clone())?;
let vec = read_file(s + "/Steam/appcache/appinfo.vdf")?; let vec = read_file(s + "/Steam/appcache/appinfo.vdf")?;
let data = read_app_info(&mut &vec[..])?; let data = read_app_info(&mut &vec[..])?;
let mut ret = Vec::new(); let mut ret = Vec::new();
let target_types = target_type.split(',').collect::<HashSet<_>>();
for mut info in data.entries { for mut info in data.entries {
if let Some(mut x) = info if let Some(mut x) = info
.info .info
@ -279,7 +280,7 @@ fn read_appinfo(target_type: String, s: String) -> io::Result<(SystemTime, Vec<(
.and_then(|x| String::from_utf8(x).ok()) .and_then(|x| String::from_utf8(x).ok())
{ {
t.make_ascii_lowercase(); t.make_ascii_lowercase();
if t == target_type { if target_types.contains(t.as_str()) {
ret.push((info.app_id, n)); ret.push((info.app_id, n));
} }
} }
@ -411,7 +412,7 @@ impl std::future::Future for PendingFut {
fn main() { fn main() {
let target_type = std::env::var("STEAM_GAME_LIST_TYPE").map_or_else( let target_type = std::env::var("STEAM_GAME_LIST_TYPE").map_or_else(
|_| "game".to_owned(), |_| "game,application".to_owned(),
|mut x| { |mut x| {
x.make_ascii_lowercase(); x.make_ascii_lowercase();
x x
@ -437,7 +438,7 @@ fn main() {
* */ * */
let xdg_home = xdg_home(); let xdg_home = xdg_home();
let xdg_home2 = xdg_home.clone(); let xdg_home2 = xdg_home.clone();
let xdg_home3 = xdg_home; let xdg_home3 = xdg_home.clone();
let target_type2 = target_type.clone(); let target_type2 = target_type.clone();
let target_type3 = target_type.clone(); let target_type3 = target_type.clone();
let target_type4 = target_type.clone(); let target_type4 = target_type.clone();
@ -448,7 +449,7 @@ fn main() {
let tx1 = tx0.clone(); let tx1 = tx0.clone();
std::thread::spawn(move || { std::thread::spawn(move || {
tx0.send( tx0.send(
read_appinfo(target_type2, crate::xdg_home()).map_or_else(|_| { read_appinfo(&target_type2, xdg_home).map_or_else(|_| {
let _ = tx2.send(None); let _ = tx2.send(None);
None None
}, |info| { }, |info| {