mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-09-20 22:23:31 +00:00
Compare commits
3
Commits
v1.16.1
...
6eff8b2c6d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6eff8b2c6d | ||
|
|
dd13eee0df | ||
|
|
3d1bc24c21 |
+34
-22
@@ -5,7 +5,6 @@ mod views;
|
|||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Result, anyhow};
|
||||||
use eframe::{NativeOptions, icon_data::from_png_bytes, run_native};
|
use eframe::{NativeOptions, icon_data::from_png_bytes, run_native};
|
||||||
use egui::{Context, FontData, FontDefinitions, FontFamily, FontTweak, Vec2, ViewportBuilder};
|
use egui::{Context, FontData, FontDefinitions, FontFamily, FontTweak, Vec2, ViewportBuilder};
|
||||||
use itertools::Itertools;
|
|
||||||
use pwsp_lib::{
|
use pwsp_lib::{
|
||||||
types::{
|
types::{
|
||||||
audio_player::PlayerState,
|
audio_player::PlayerState,
|
||||||
@@ -24,6 +23,7 @@ use std::{
|
|||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fs,
|
fs,
|
||||||
hash::{DefaultHasher, Hash, Hasher},
|
hash::{DefaultHasher, Hash, Hasher},
|
||||||
|
io::BufReader,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
thread,
|
thread,
|
||||||
@@ -110,12 +110,17 @@ impl SoundpadGui {
|
|||||||
pub fn add_dirs(&mut self) {
|
pub fn add_dirs(&mut self) {
|
||||||
let file_dialog = FileDialog::new();
|
let file_dialog = FileDialog::new();
|
||||||
if let Some(paths) = file_dialog.pick_folders() {
|
if let Some(paths) = file_dialog.pick_folders() {
|
||||||
|
let mut changed = false;
|
||||||
for path in paths {
|
for path in paths {
|
||||||
self.app_state.dirs.push(path);
|
if !self.app_state.dirs.contains(&path) {
|
||||||
|
self.app_state.dirs.push(path);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if changed {
|
||||||
|
self.config.dirs = self.app_state.dirs.clone();
|
||||||
|
self.config.save_to_file().ok();
|
||||||
}
|
}
|
||||||
self.app_state.dirs = self.app_state.dirs.iter().unique().cloned().collect();
|
|
||||||
self.config.dirs = self.app_state.dirs.clone();
|
|
||||||
self.config.save_to_file().ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,11 +176,9 @@ impl SoundpadGui {
|
|||||||
|
|
||||||
// 1. Try to load from disk cache if we don't have it in memory yet
|
// 1. Try to load from disk cache if we don't have it in memory yet
|
||||||
if !is_cached
|
if !is_cached
|
||||||
&& let Ok(data) = fs::read_to_string(&cache_file)
|
&& let Ok(file) = fs::File::open(&cache_file)
|
||||||
&& let Ok((all_files, dir_updates)) = serde_json::from_str::<(
|
&& let Ok((all_files, dir_updates)) =
|
||||||
Vec<PathBuf>,
|
serde_json::from_reader(BufReader::new(file))
|
||||||
HashMap<PathBuf, Vec<PathBuf>>,
|
|
||||||
)>(&data)
|
|
||||||
{
|
{
|
||||||
finished_scans.lock().unwrap().push((
|
finished_scans.lock().unwrap().push((
|
||||||
path_clone.clone(),
|
path_clone.clone(),
|
||||||
@@ -196,18 +199,27 @@ impl SoundpadGui {
|
|||||||
if let Ok(entries) = fs::read_dir(&dir) {
|
if let Ok(entries) = fs::read_dir(&dir) {
|
||||||
let mut children = Vec::new();
|
let mut children = Vec::new();
|
||||||
for entry in entries.filter_map(|e| e.ok()) {
|
for entry in entries.filter_map(|e| e.ok()) {
|
||||||
let p = entry.path();
|
if let Ok(file_type) = entry.file_type() {
|
||||||
if p.is_dir() {
|
if file_type.is_dir() {
|
||||||
dirs_to_visit.push(p.clone());
|
let p = entry.path();
|
||||||
children.push(p);
|
dirs_to_visit.push(p.clone());
|
||||||
} else if crate::gui::SUPPORTED_EXTENSIONS.contains(
|
children.push(p);
|
||||||
&p.extension()
|
} else {
|
||||||
.unwrap_or_default()
|
let file_name = entry.file_name();
|
||||||
.to_str()
|
let is_supported = Path::new(&file_name)
|
||||||
.unwrap_or_default(),
|
.extension()
|
||||||
) {
|
.map(|e| {
|
||||||
all_files.push(p.clone());
|
crate::gui::SUPPORTED_EXTENSIONS
|
||||||
children.push(p);
|
.contains(&e.to_str().unwrap_or_default())
|
||||||
|
})
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
if is_supported {
|
||||||
|
let p = entry.path();
|
||||||
|
all_files.push(p.clone());
|
||||||
|
children.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dir_updates.insert(dir, children);
|
dir_updates.insert(dir, children);
|
||||||
|
|||||||
Reference in New Issue
Block a user