Skip to content

Commit 872f52c

Browse files
authored
Merge pull request #5 from projectM-visualizer/config-dirs
Use /usr/local/share/projectM if exists
2 parents 46f9855 + a7515b7 commit 872f52c

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/app/config.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::app::App;
22
use projectm_rs::core::Projectm;
3+
use std::path::Path;
34

45
pub type FrameRate = u32;
56

@@ -25,11 +26,28 @@ pub struct Config {
2526

2627
impl Default for Config {
2728
fn default() -> Self {
28-
// default preset path
29+
// get paths to presets and textures
30+
// TODO: get from config file or env
31+
//
32+
// use /usr/local/share/projectM if it exists, otherwise use local paths
33+
let resource_dir = "/usr/local/share/projectM";
34+
let dir_exists = Path::new(&resource_dir).exists();
35+
let preset_path = if dir_exists {
36+
String::from(resource_dir) + "/presets"
37+
} else {
38+
// just test presets
39+
"./presets".to_owned()
40+
};
41+
let texture_path = if dir_exists {
42+
String::from(resource_dir) + "/textures"
43+
} else {
44+
// doesn't exist
45+
"./textures".to_owned()
46+
};
47+
2948
Self {
30-
// TODO: load from home dir or w/e
31-
preset_path: Some("/usr/local/share/projectM/presets".to_owned()),
32-
texture_path: Some("/usr/local/share/projectM/textures".to_owned()),
49+
preset_path: Path::new(&preset_path).exists().then(|| preset_path),
50+
texture_path: Path::new(&texture_path).exists().then(|| texture_path),
3351
frame_rate: Some(60),
3452
beat_sensitivity: Some(1.0),
3553
preset_duration: Some(10.0),
@@ -67,6 +85,9 @@ impl App {
6785
if let Some(preset_duration) = config.preset_duration {
6886
Projectm::set_preset_duration(pm, preset_duration);
6987
}
88+
89+
// set preset shuffle mode
90+
// self.playlist.set_shuffle(true);
7091
}
7192

7293
pub fn get_frame_rate(&self) -> FrameRate {

0 commit comments

Comments
 (0)