Compare commits
11 Commits
67a948bb66
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e83dc45039 | |||
| 7dcaa1436b | |||
| c423993a93 | |||
| bbffa5dbd3 | |||
| d6b9d566d2 | |||
| 2c2f35ff0a | |||
| 2aa0e5a1e8 | |||
| 1b0af636df | |||
| f143e7976c | |||
| f8281640f1 | |||
| a21295ecc8 |
0
CHANGELOG.md
Normal file
0
CHANGELOG.md
Normal file
46
Cargo.lock
generated
46
Cargo.lock
generated
@@ -1387,6 +1387,12 @@ version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
|
||||
|
||||
[[package]]
|
||||
name = "downcast-rs"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "117240f60069e65410b3ae1bb213295bd828f707b5bec6596a1afc8793ce0cbc"
|
||||
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.27.2"
|
||||
@@ -3892,6 +3898,12 @@ dependencies = [
|
||||
"tiny-skia",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.214"
|
||||
@@ -4933,7 +4945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "056535ced7a150d45159d3a8dc30f91a2e2d588ca0b23f70e56033622b8016f6"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"downcast-rs",
|
||||
"downcast-rs 1.2.1",
|
||||
"rustix 0.38.39",
|
||||
"scoped-tls",
|
||||
"smallvec",
|
||||
@@ -5744,7 +5756,7 @@ checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-cache"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
@@ -5761,7 +5773,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-cliargs"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"camino",
|
||||
"clap",
|
||||
@@ -5771,7 +5783,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-core"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
@@ -5783,21 +5795,24 @@ dependencies = [
|
||||
"xmpd-gui",
|
||||
"xmpd-manifest",
|
||||
"xmpd-settings",
|
||||
"xmpd-update",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-gui"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
"dirs",
|
||||
"downcast-rs 2.0.2",
|
||||
"eframe",
|
||||
"egui",
|
||||
"egui_extras",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"rfd",
|
||||
"url",
|
||||
"uuid",
|
||||
"xmpd-cache",
|
||||
"xmpd-cliargs",
|
||||
@@ -5808,7 +5823,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-manifest"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"serde",
|
||||
@@ -5822,7 +5837,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-player"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"lazy_static",
|
||||
@@ -5832,7 +5847,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-settings"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
@@ -5840,11 +5855,24 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"serde",
|
||||
"toml 0.8.19",
|
||||
"xmpd-cliargs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-tooling"
|
||||
version = "2.0.0"
|
||||
version = "2.1.3"
|
||||
|
||||
[[package]]
|
||||
name = "xmpd-update"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"log",
|
||||
"reqwest",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus"
|
||||
|
||||
10
Cargo.toml
10
Cargo.toml
@@ -8,12 +8,13 @@ members=[
|
||||
"xmpd-cache",
|
||||
"xmpd-settings",
|
||||
"xmpd-tooling",
|
||||
"xmpd-player",
|
||||
"xmpd-player", "xmpd-update",
|
||||
# "xmpd-tui"
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version="2.0.0"
|
||||
version="2.1.3"
|
||||
edition="2024"
|
||||
repository="https://git.mcorangehq.xyz/XOR64/xmpd/"
|
||||
license="GPL-3.0"
|
||||
authors=[
|
||||
@@ -35,7 +36,7 @@ lazy_static = "1.4.0"
|
||||
log = "0.4.21"
|
||||
# notify-rust = "4.11.3"
|
||||
# open = "5.3.0"
|
||||
reqwest = { version = "0.12.3", features = ["blocking", "h2", "http2", "rustls-tls"], default-features = false }
|
||||
reqwest = { version = "0.12.3", features = ["blocking", "h2", "http2", "rustls-tls", "json"], default-features = false }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.115"
|
||||
url = { version = "2.5.0", features = ["serde"] }
|
||||
@@ -48,3 +49,6 @@ toml = "0.8.19"
|
||||
rfd = "0.15.1"
|
||||
rodio = { version = "0.20.1", features = ["symphonia-all"] }
|
||||
image = "0.25.5"
|
||||
downcast-rs = "2.0.2"
|
||||
semver = "1.0.27"
|
||||
parse-changelog = "0.6.14"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# (XMPD) Xor64 Music Player/Downloader
|
||||
|
||||
|
||||
# **NOTE** This readme has outdated info, and needs to be updated
|
||||
|
||||
|
||||
An open source music downloader AND player (soon (TM))
|
||||
|
||||
## Design
|
||||
|
||||
3127
manifest.json
3127
manifest.json
File diff suppressed because it is too large
Load Diff
12
scripts/build_release.sh
Executable file
12
scripts/build_release.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
set -x
|
||||
rm target/xmpd target/xmpd.exe
|
||||
|
||||
set -e
|
||||
|
||||
cargo build --release --target x86_64-pc-windows-gnu
|
||||
cargo build --release --target x86_64-unknown-linux-gnu
|
||||
|
||||
cp target/x86_64-unknown-linux-gnu/release/xmpd target/xmpd
|
||||
cp target/x86_64-pc-windows-gnu/release/xmpd.exe target/xmpd.exe
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "xmpd-cache"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
readme="README.md"
|
||||
authors.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
@@ -30,11 +30,12 @@ impl IconCacheDl {
|
||||
pub fn download(&mut self, sid: uuid::Uuid, song: Song) -> crate::Result<()> {
|
||||
match song.icon_type().clone() {
|
||||
IconType::FromSource => {
|
||||
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
|
||||
let settings = xmpd_settings::Settings::get()?.clone();
|
||||
let tooling = settings.tooling.clone();
|
||||
match song.source_type() {
|
||||
SourceType::Youtube => {
|
||||
self.jobs.insert(sid.clone(), DlStatus::Downloading);
|
||||
let mut path = xmpd_cliargs::CLIARGS.cache_path();
|
||||
let mut path = settings.cache_settings.cache_path.clone();
|
||||
path.push("icons");
|
||||
path.push(sid.to_string());
|
||||
|
||||
@@ -91,7 +92,7 @@ impl IconCacheDl {
|
||||
anyhow::bail!("Url without extension, cant continue");
|
||||
};
|
||||
let ext = ext.to_string_lossy().to_string();
|
||||
let mut path = xmpd_cliargs::CLIARGS.cache_path();
|
||||
let mut path = xmpd_settings::Settings::get()?.clone().cache_settings.cache_path;
|
||||
path.push("icons");
|
||||
path.push(sid.to_string());
|
||||
path.set_extension(ext);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{collections::HashMap, ffi::OsStr, process::{Command, Stdio}, sync::{Arc, Mutex, MutexGuard}};
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use xmpd_manifest::song::{Song, SourceType};
|
||||
|
||||
|
||||
@@ -14,6 +15,12 @@ pub enum SongStatus {
|
||||
Done
|
||||
}
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
const PATH_SEP: char = ';';
|
||||
#[cfg(target_family = "unix")]
|
||||
const PATH_SEP: char = ':';
|
||||
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct SongCacheDl {
|
||||
pub jobs: HashMap<uuid::Uuid, SongStatus>,
|
||||
@@ -31,11 +38,14 @@ impl SongCacheDl {
|
||||
self.current_jobs >= 5
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn download(&mut self, sid: uuid::Uuid, song: Song) -> crate::Result<()> {
|
||||
self.current_jobs += 1;
|
||||
let song_format = xmpd_settings::Settings::get().unwrap().tooling.song_format.clone();
|
||||
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
|
||||
let mut song_cache_d = xmpd_cliargs::CLIARGS.cache_path();
|
||||
let settings = xmpd_settings::Settings::get()?.clone();
|
||||
let tooling = settings.tooling.clone();
|
||||
let mut song_cache_d = settings.cache_settings.cache_path.clone();
|
||||
song_cache_d.push("songs");
|
||||
match song.source_type() {
|
||||
SourceType::Youtube |
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::{collections::HashMap, path::PathBuf, str::FromStr, sync::{mpsc::{self, Receiver, Sender}, Arc, Mutex, MutexGuard}, time::Duration};
|
||||
use anyhow::anyhow;
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use downloader::song::SongStatus;
|
||||
use xmpd_manifest::song::Song;
|
||||
|
||||
@@ -41,18 +43,42 @@ impl Cache {
|
||||
Err(e) => Err(anyhow::anyhow!(format!("{e:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_if_tool_exists(&self, tool_path: &Utf8Path) -> crate::Result<()> {
|
||||
if std::fs::metadata(tool_path).is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(path) = std::env::var("PATH") {
|
||||
for p in path.split(":") {
|
||||
let p_str = Utf8PathBuf::from(p).join(tool_path);
|
||||
if std::fs::metadata(p_str).is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
// anyhow::bail!("Tool {} was not found", tool_path)
|
||||
log::error!("Tool {tool_path:?} doesnt exist!");
|
||||
Ok(())
|
||||
}
|
||||
pub fn init(&mut self) -> Result<Receiver<Message>> {
|
||||
// Check for missing tooling
|
||||
|
||||
let tooling = xmpd_settings::Settings::get()?.tooling.clone();
|
||||
self.check_if_tool_exists(&tooling.ytdlp_path)?;
|
||||
self.check_if_tool_exists(&tooling.spotdl_path)?;
|
||||
self.check_if_tool_exists(&tooling.ffmpeg_path)?;
|
||||
|
||||
|
||||
|
||||
let (internal_tx, cache_rx) = mpsc::channel::<Message>();
|
||||
// let (internal_rx, cache_tx) = mpsc::channel::<Message>();
|
||||
start_cache_mv_thread(internal_tx);
|
||||
self.cache_dir = xmpd_cliargs::CLIARGS.cache_path();
|
||||
|
||||
self.cache_dir = xmpd_settings::Settings::get()?.cache_settings.cache_path.clone();
|
||||
std::fs::create_dir_all(&self.cache_dir)?;
|
||||
{ // Get cached songs
|
||||
let mut song_cache_dir = self.cache_dir.clone();
|
||||
std::fs::create_dir_all(&song_cache_dir)?;
|
||||
song_cache_dir.push("songs");
|
||||
for file in song_cache_dir.read_dir_utf8()? {
|
||||
std::fs::create_dir_all(&song_cache_dir)?;
|
||||
for file in song_cache_dir.read_dir_utf8().map_err(|e| anyhow!("failed to read cache dir: {e}"))? {
|
||||
if let Ok(file) = file {
|
||||
if !file.file_type()?.is_file() {
|
||||
log::warn!("Non song file in: {}", file.path());
|
||||
@@ -104,7 +130,7 @@ impl Cache {
|
||||
}
|
||||
|
||||
macro_rules! he {
|
||||
($tx:expr, $val:expr) => {
|
||||
($tx:expr_2021, $val:expr_2021) => {
|
||||
match $val {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
@@ -126,7 +152,7 @@ fn start_cache_mv_thread(tx: Sender<Message>) {
|
||||
for (sid, status) in &dlc.jobs {
|
||||
if *status == SongStatus::Done {
|
||||
let mut cache = he!(tx, CACHE.lock());
|
||||
let mut song_p = xmpd_cliargs::CLIARGS.cache_path().clone();
|
||||
let mut song_p = he!(tx, xmpd_settings::Settings::get()).cache_settings.cache_path.clone();
|
||||
song_p.push("songs");
|
||||
song_p.push(sid.clone().to_string());
|
||||
let song_p = song_p.with_extension(&song_format);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "xmpd-cliargs"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
readme="README.md"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@@ -10,72 +10,28 @@ lazy_static::lazy_static!(
|
||||
#[derive(Debug, clap::Parser)]
|
||||
pub struct CliArgs {
|
||||
/// Manifest path
|
||||
#[arg(long, short, default_value_t=get_default_manifest_path())]
|
||||
manifest: camino::Utf8PathBuf,
|
||||
#[arg(long, short)]
|
||||
manifest: Option<camino::Utf8PathBuf>,
|
||||
/// settings file path
|
||||
#[arg(long, short, default_value_t=get_default_settings_path())]
|
||||
#[arg(long, short, default_value="./settings.toml")]
|
||||
settings: camino::Utf8PathBuf,
|
||||
/// Cache dir path
|
||||
#[arg(long, short, default_value_t=get_default_cache_path())]
|
||||
cache: camino::Utf8PathBuf,
|
||||
#[arg(long, short)]
|
||||
cache: Option<camino::Utf8PathBuf>,
|
||||
/// Debug mode
|
||||
#[arg(long, short)]
|
||||
pub debug: bool,
|
||||
}
|
||||
|
||||
impl CliArgs {
|
||||
pub fn manifest_path(&self) -> PathBuf {
|
||||
self.manifest.clone().into_std_path_buf()
|
||||
pub fn manifest_path(&self) -> Option<Utf8PathBuf> {
|
||||
self.manifest.clone()
|
||||
}
|
||||
pub fn settings_path(&self) -> PathBuf {
|
||||
self.settings.clone().into_std_path_buf()
|
||||
pub fn settings_path(&self) -> Utf8PathBuf {
|
||||
self.settings.clone()
|
||||
}
|
||||
pub fn cache_path(&self) -> Utf8PathBuf {
|
||||
pub fn cache_path(&self) -> Option<Utf8PathBuf> {
|
||||
self.cache.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(irrefutable_let_patterns)] // Broken?
|
||||
fn get_default_settings_path() -> camino::Utf8PathBuf {
|
||||
if let Ok(p) = std::env::var("XMPD_SETTINGS_PATH") {
|
||||
if let Ok(p) = camino::Utf8PathBuf::from_str(&p) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(mut p) = dirs::config_dir() {
|
||||
p.push("xmpd");
|
||||
p.push("config.toml");
|
||||
return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path");
|
||||
}
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
#[allow(irrefutable_let_patterns)] // Broken?
|
||||
fn get_default_manifest_path() -> camino::Utf8PathBuf {
|
||||
if let Ok(p) = std::env::var("XMPD_MANIFEST_PATH") {
|
||||
if let Ok(p) = camino::Utf8PathBuf::from_str(&p) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
if let Some(mut p) = dirs::config_dir() {
|
||||
p.push("xmpd");
|
||||
p.push("manifest.json");
|
||||
return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path");
|
||||
}
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
#[allow(irrefutable_let_patterns)] // Broken?
|
||||
fn get_default_cache_path() -> camino::Utf8PathBuf {
|
||||
if let Ok(p) = std::env::var("XMPD_CACHE_PATH") {
|
||||
if let Ok(p) = camino::Utf8PathBuf::from_str(&p) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
if let Some(mut p) = dirs::cache_dir() {
|
||||
p.push("xmpd");
|
||||
return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path");
|
||||
}
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "xmpd-core"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
readme="README.md"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
@@ -25,6 +25,7 @@ xmpd-cliargs.path="../xmpd-cliargs"
|
||||
xmpd-gui.path="../xmpd-gui"
|
||||
xmpd-manifest.path="../xmpd-manifest"
|
||||
xmpd-settings.path = "../xmpd-settings"
|
||||
xmpd-update.path = "../xmpd-update"
|
||||
clap.workspace=true
|
||||
camino.workspace = true
|
||||
anyhow.workspace = true
|
||||
|
||||
@@ -10,9 +10,16 @@ fn main() -> Result<()> {
|
||||
// NOTE: Parses on first load
|
||||
let cliargs = &xmpd_cliargs::CLIARGS;
|
||||
logger::init(&cliargs);
|
||||
log::debug!("Initialising settings");
|
||||
xmpd_settings::Settings::get()?.load(Some(cliargs.settings_path()))?;
|
||||
log::debug!("Starting gui");
|
||||
log::info!("Initialising settings");
|
||||
{
|
||||
xmpd_settings::Settings::get()?.load(Some(cliargs.settings_path().into_std_path_buf()))?;
|
||||
xmpd_settings::Settings::get()?.load_cli_args(cliargs);
|
||||
}
|
||||
|
||||
log::info!("Starting updater");
|
||||
xmpd_update::Update::new().update_xmpd_if_needed()?;
|
||||
|
||||
log::info!("Starting gui");
|
||||
xmpd_gui::start()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "xmpd-gui"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
readme="README.md"
|
||||
authors.workspace = true
|
||||
version.workspace = true
|
||||
@@ -33,3 +33,5 @@ uuid.workspace = true
|
||||
camino.workspace = true
|
||||
rfd.workspace = true
|
||||
dirs.workspace = true
|
||||
downcast-rs.workspace = true
|
||||
url.workspace = true
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use eframe::Frame;
|
||||
use egui::{Align, Align2, Area, Key, Layout, Order, Style};
|
||||
use uuid::Uuid;
|
||||
use xmpd_cache::DlStatus;
|
||||
use xmpd_manifest::{song::Song, store::BaseStore};
|
||||
|
||||
use crate::{components::{left_nav::LeftNav, toast::ToastType, CompGetter, CompUi}, windows::WindowId};
|
||||
use crate::{components::{CompGetter, CompUi, left_nav::LeftNav, toast::ToastType}, utils::SearchType, windows::WindowId};
|
||||
|
||||
use super::SongList;
|
||||
|
||||
@@ -15,6 +17,8 @@ pub struct Header {
|
||||
|
||||
component_register!(Header);
|
||||
|
||||
|
||||
|
||||
impl CompUi for Header {
|
||||
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
||||
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
||||
@@ -26,7 +30,54 @@ impl CompUi for Header {
|
||||
.tint(theme.accent_color);
|
||||
ui.add(search_icon);
|
||||
{
|
||||
ui.text_edit_singleline(&mut handle_error_ui!(Header::get()).search_text);
|
||||
let resp = ui.text_edit_singleline(&mut handle_error_ui!(Header::get()).search_text);
|
||||
let popup_id = resp.id.with("mode_popup");
|
||||
if resp.clicked() {
|
||||
ui.memory_mut(|m| m.open_popup(popup_id));
|
||||
}
|
||||
|
||||
// NOTE: Genuinely cancerous code incoming
|
||||
let search_text = handle_error_ui!(Header::get()).search_text.clone();
|
||||
if !search_text.is_empty() {
|
||||
if ui.memory(|mem: &egui::Memory| mem.is_popup_open(popup_id)) {
|
||||
Area::new(popup_id)
|
||||
.order(Order::Foreground)
|
||||
.constrain(true)
|
||||
.fixed_pos(resp.rect.left_bottom())
|
||||
.pivot(Align2::LEFT_TOP)
|
||||
.show(ui.ctx(), |ui| {
|
||||
let tf = crate::main_window::get_themed_frame(&theme)
|
||||
.stroke(egui::Stroke::new(
|
||||
1.5,
|
||||
theme.secondary_bg_color,
|
||||
));
|
||||
let frame_margin = tf.total_margin();
|
||||
tf.show(ui, |ui| {
|
||||
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
|
||||
ui.with_layout(Layout::top_down_justified(Align::LEFT), |ui| {
|
||||
ui.set_width(resp.rect.width() - frame_margin.sum().x);
|
||||
let st = SearchType::from_str(&search_text);
|
||||
let style = ui.style_mut();
|
||||
style.visuals.selection.bg_fill = theme.secondary_bg_color;
|
||||
style.visuals.selection.stroke.color = theme.accent_color;
|
||||
for item in &[SearchType::Author, SearchType::Source, SearchType::Genre] {
|
||||
if ui.selectable_label(st.0 == *item, item.new_query(&st.1)).clicked() {
|
||||
{
|
||||
handle_error_ui!(Header::get()).search_text = item.new_query(&st.1);
|
||||
}
|
||||
ui.memory_mut(|m| m.close_popup());
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
if ui.input(|i| i.key_pressed(Key::Escape)) || resp.clicked_elsewhere() {
|
||||
ui.memory_mut(|mem| mem.close_popup());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::RIGHT), |ui| {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use anyhow::anyhow;
|
||||
use egui::{Color32, CursorIcon, ImageSource, RichText, Sense, Vec2};
|
||||
use xmpd_cache::DlStatus;
|
||||
use xmpd_manifest::{query, song::Song, store::{BaseStore, StoreExtras}};
|
||||
use crate::utils::SearchType;
|
||||
|
||||
use crate::{components::toast::{Toast, ToastType}, utils::SearchType, windows::WindowId};
|
||||
use std::any::Any;
|
||||
use super::{CompGetter, CompUi};
|
||||
use downcast_rs::Downcast;
|
||||
|
||||
pub mod header;
|
||||
|
||||
@@ -23,7 +25,7 @@ impl CompUi for SongList {
|
||||
let mut sl = SongList::get()?;
|
||||
sl.playable_songs = Self::get_playable_songs(&songs)?;
|
||||
if let Some((sid, _)) = songs.first() {
|
||||
if sl.selected_sid == Default::default() {
|
||||
if sl.selected_sid.eq(&uuid::Uuid::default()) {
|
||||
sl.selected_sid = (*sid).clone();
|
||||
}
|
||||
}
|
||||
@@ -64,6 +66,7 @@ impl SongList {
|
||||
let should_display = match &query_type {
|
||||
SearchType::Normal |
|
||||
SearchType::Author |
|
||||
SearchType::Genre |
|
||||
SearchType::Source if query_text.is_empty() => true,
|
||||
|
||||
SearchType::Source => {
|
||||
@@ -81,6 +84,13 @@ impl SongList {
|
||||
.to_lowercase()
|
||||
.contains(&query_text)
|
||||
},
|
||||
SearchType::Genre => {
|
||||
song.genres()
|
||||
.iter()
|
||||
.map(|v| v.to_lowercase().contains(&query_text))
|
||||
.collect::<Vec<bool>>()
|
||||
.contains(&true)
|
||||
},
|
||||
};
|
||||
|
||||
if should_display {
|
||||
@@ -93,7 +103,7 @@ impl SongList {
|
||||
fn display_song_tab(ui: &mut egui::Ui, state: &mut crate::GuiState, sid: &uuid::Uuid) -> crate::Result<()> {
|
||||
let mut clicked = false;
|
||||
ui.horizontal(|ui| {
|
||||
let song = handle_option!("(internal)", state.manifest.store().get_song(sid));
|
||||
let song = handle_option!("(internal)", state.manifest.store().get_song(sid)).clone();
|
||||
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
|
||||
// let icon_status = handle_error_ui!(xmpd_cache::Cache::get()).get_cached_icon_status(&sid).clone();
|
||||
let img = ui.add(
|
||||
@@ -151,7 +161,7 @@ impl SongList {
|
||||
}
|
||||
}
|
||||
|
||||
// label.context_menu(|ui| handle_error_ui!(Self::show_context_menu(ui, sid, song)));
|
||||
label.context_menu(|ui| handle_error_ui!(Self::show_context_menu(state, ui, sid, &song)));
|
||||
ui.monospace(
|
||||
RichText::new(format!("By {}", song.author()))
|
||||
.color(theme.dim_text_color)
|
||||
@@ -165,14 +175,14 @@ impl SongList {
|
||||
|
||||
match status {
|
||||
Some(DlStatus::Done(_)) => {
|
||||
//let img = egui::Image::new(crate::data::CHECK_ICON)
|
||||
// .tint(Color32::LIGHT_GREEN)
|
||||
// .sense(Sense::hover())
|
||||
// .fit_to_exact_size(Vec2::new(16.0, 16.0));
|
||||
let img = egui::Image::new(crate::data::CHECK_ICON)
|
||||
.tint(Color32::LIGHT_GREEN)
|
||||
.sense(Sense::hover())
|
||||
.fit_to_exact_size(Vec2::new(16.0, 16.0));
|
||||
|
||||
//ui.add(img).on_hover_ui(|ui| {
|
||||
// ui.label(format!("Path: {p}"));
|
||||
//});
|
||||
ui.add(img).on_hover_ui(|ui| {
|
||||
ui.label(format!("Id: {sid}"));
|
||||
});
|
||||
}
|
||||
Some(DlStatus::Downloading) => {
|
||||
let spinner = egui::Spinner::new()
|
||||
@@ -264,10 +274,36 @@ impl SongList {
|
||||
}
|
||||
Ok(playable_songs)
|
||||
}
|
||||
//fn show_context_menu(ui: &mut egui::Ui, sid: &uuid::Uuid, song: &Song) -> crate::Result<()> {
|
||||
// if ui.button("Download icon").clicked() {
|
||||
// xmpd_cache::Cache::get()?.download_icon_to_cache(sid.clone(), song.clone());
|
||||
// }
|
||||
// Ok(())
|
||||
//}
|
||||
fn show_context_menu(state: &mut crate::GuiState, ui: &mut egui::Ui, sid: &uuid::Uuid, song: &Song) -> crate::Result<()> {
|
||||
if ui.button("Edit").clicked() {
|
||||
// TODO: Implement song editing
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Song editing is not implemented", ToastType::Error);
|
||||
//state.windows.toggle(&crate::windows::WindowId::NewSong, status);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Add to playlist").clicked() {
|
||||
// TODO: Implement song editing
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Adding songs to another playlist is not implemented, go to that playlist and press add song", ToastType::Error);
|
||||
//state.windows.toggle(&WindowId::AddSongToPl, true);
|
||||
//let mut windows = crate::windows::WINDOWS.lock().map_err(|e| anyhow!("{e}"))?;
|
||||
//let mut w = windows.get_mut(&WindowId::AddSongToPl);
|
||||
//let w = w.as_any_mut();
|
||||
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Songs by artist").clicked() {
|
||||
crate::components::song_list::header::Header::get()?.search_text = format!("author:{}", song.author());
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button(RichText::new("Remove from playlist").color(Color32::RED)).clicked() {
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Removing songs from playlists is not implemented", ToastType::Error);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button(RichText::new("Remove song globally").color(Color32::RED)).clicked() {
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Removing songs globally is not implemented", ToastType::Error);
|
||||
ui.close_menu();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ impl CompUi for TopNav {
|
||||
}
|
||||
});
|
||||
ui.menu_button("Manifest", |ui| {
|
||||
if ui.button("Add New Song").clicked() {
|
||||
state.windows.toggle(&WindowId::NewSong, true);
|
||||
}
|
||||
if ui.button("Save").clicked() {
|
||||
handle_error_ui!(state.manifest.save());
|
||||
ui.close_menu();
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::path::Path;
|
||||
use std::time::{Duration, Instant};
|
||||
use anyhow::anyhow;
|
||||
use xmpd_manifest::{store::JsonStore, Manifest};
|
||||
|
||||
#[macro_use]
|
||||
@@ -9,15 +11,19 @@ mod components;
|
||||
mod data;
|
||||
mod utils;
|
||||
|
||||
const W_NAME: &str = "xmpd v2.0.0a";
|
||||
|
||||
type Result<T> = anyhow::Result<T>;
|
||||
|
||||
pub fn start() -> Result<()> {
|
||||
let cache_rx = xmpd_cache::Cache::get()?.init()?;
|
||||
let manifest_p = xmpd_settings::Settings::get()?.cache_settings.manifest_path.clone().into_std_path_buf();
|
||||
let cache_rx = xmpd_cache::Cache::get()
|
||||
.map_err(|e| anyhow!("Failed to get cache: {e}"))?
|
||||
.init()
|
||||
.map_err(|e| anyhow!("Failed to init cache: {e}"))?;
|
||||
|
||||
let options = eframe::NativeOptions::default();
|
||||
let mut state = GuiState::new()?;
|
||||
let res = eframe::run_simple_native(W_NAME, options, move |ctx, _frame| {
|
||||
let mut state = GuiState::new(&manifest_p)?;
|
||||
let res = eframe::run_simple_native(&format!("xmpd v{}", env!("CARGO_PKG_VERSION")), options, move |ctx, _frame| {
|
||||
#[cfg(debug_assertions)]
|
||||
let f_start = Instant::now();
|
||||
|
||||
@@ -54,22 +60,22 @@ pub struct GuiState {
|
||||
|
||||
impl GuiState {
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(manifest_p: &Path) -> Result<Self> {
|
||||
Ok(Self {
|
||||
debug_info: DebugInfo {
|
||||
last_frame_time: Default::default()
|
||||
},
|
||||
player: xmpd_player::Player::new(),
|
||||
manifest: Manifest::new(&xmpd_cliargs::CLIARGS.manifest_path())?,
|
||||
manifest: Manifest::new(manifest_p)?,
|
||||
windows: windows::Windows::new(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(manifest_p: &Path) -> Result<Self> {
|
||||
Ok(Self {
|
||||
player: xmpd_player::Player::new(),
|
||||
manifest: Manifest::new(&xmpd_cliargs::CLIARGS.manifest_path())?,
|
||||
manifest: Manifest::new(manifest_p)?,
|
||||
windows: windows::Windows::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ macro_rules! component_register {
|
||||
}
|
||||
|
||||
macro_rules! handle_error_ui {
|
||||
($val:expr) => {
|
||||
($val:expr_2021) => {
|
||||
match $val {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
@@ -37,7 +37,7 @@ macro_rules! handle_error_ui {
|
||||
}
|
||||
|
||||
macro_rules! handle_option {
|
||||
($reason:expr, $val:expr) => {
|
||||
($reason:expr_2021, $val:expr_2021) => {
|
||||
if let Some(v) = $val {
|
||||
v
|
||||
} else {
|
||||
|
||||
@@ -94,7 +94,7 @@ pub fn draw(ctx: &egui::Context, state: &mut GuiState, cache_rx: &Receiver<Messa
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_themed_frame(theme: &Theme) -> egui::Frame {
|
||||
pub fn get_themed_frame(theme: &Theme) -> egui::Frame {
|
||||
egui::Frame::none()
|
||||
.fill(theme.primary_bg_color)
|
||||
.stroke(egui::Stroke::new(
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd)]
|
||||
pub enum SearchType {
|
||||
Normal,
|
||||
Author,
|
||||
Source,
|
||||
Genre
|
||||
}
|
||||
|
||||
impl SearchType {
|
||||
@@ -13,9 +16,27 @@ impl SearchType {
|
||||
(Self::Source, i.strip_prefix("source:").unwrap_or("").to_string().to_lowercase()),
|
||||
i @ _ if i.starts_with("author:") =>
|
||||
(Self::Author, i.strip_prefix("author:").unwrap_or("").to_string().to_lowercase()),
|
||||
i @ _ if i.starts_with("genre:") =>
|
||||
(Self::Author, i.strip_prefix("genre:").unwrap_or("").to_string().to_lowercase()),
|
||||
i @ _ => (Self::Normal, i.to_string().to_lowercase())
|
||||
}
|
||||
}
|
||||
pub fn new_query(&self, s: &str) -> String {
|
||||
format!("{self}:{s}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SearchType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let s = match self {
|
||||
Self::Normal => "",
|
||||
Self::Genre => "genre",
|
||||
Self::Source => "source",
|
||||
Self::Author => "author"
|
||||
};
|
||||
f.write_str(s)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn super_separator(ui: &mut egui::Ui, color: egui::Color32, width: f32, height: f32) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use egui::{RichText, TextEdit};
|
||||
use egui::{RichText, Sense, TextEdit, TopBottomPanel};
|
||||
use xmpd_cache::DlStatus;
|
||||
use xmpd_manifest::store::{BaseStore, StoreExtras};
|
||||
use xmpd_manifest::{song::Song, store::{BaseStore, StoreExtras}};
|
||||
|
||||
use crate::{components::{CompGetter, toast::{Toast, ToastType}}, windows::WindowId};
|
||||
|
||||
use super::Window;
|
||||
|
||||
@@ -8,6 +10,7 @@ use super::Window;
|
||||
#[derive(Debug, Default)]
|
||||
pub struct AddSongW {
|
||||
sid: uuid::Uuid,
|
||||
pid: Option<uuid::Uuid>,
|
||||
}
|
||||
|
||||
impl Window for AddSongW {
|
||||
@@ -18,6 +21,8 @@ impl Window for AddSongW {
|
||||
"Add Song to Playlist"
|
||||
}
|
||||
fn draw(&mut self, ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
||||
let mut save = false;
|
||||
self.pid = crate::components::left_nav::LeftNav::get()?.selected_playlist_id.clone();
|
||||
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
||||
|
||||
let songs: Vec<_> = state.manifest.store().get_songs_sorted();
|
||||
@@ -61,7 +66,7 @@ impl Window for AddSongW {
|
||||
.show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
for (sid, song) in songs {
|
||||
ui.group(|ui| {
|
||||
let resp = ui.group(|ui| {
|
||||
let avail = ui.available_size();
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_width(avail.x);
|
||||
@@ -87,13 +92,62 @@ impl Window for AddSongW {
|
||||
});
|
||||
});
|
||||
});
|
||||
if resp.response.interact(Sense::click()).clicked() {
|
||||
self.sid = sid.clone();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
|
||||
TopBottomPanel::bottom("bottom_bar")
|
||||
.frame(
|
||||
egui::Frame::none()
|
||||
.fill(theme.primary_bg_color)
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
theme.secondary_bg_color,
|
||||
)),
|
||||
)
|
||||
.show(ui.ctx(), |ui| {
|
||||
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
|
||||
|
||||
ui.add_space(3.0);
|
||||
ui.horizontal(|ui| {
|
||||
// ui.add_space(3.0);
|
||||
|
||||
|
||||
if ui.button("Add").clicked() {
|
||||
save = true;
|
||||
}
|
||||
|
||||
if ui.button("Cancel").clicked() {
|
||||
state.windows.toggle(&WindowId::AddSongToPl, false);
|
||||
}
|
||||
if ui.button("Close").clicked() {
|
||||
state.windows.toggle(&WindowId::AddSongToPl, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
if save {
|
||||
match &self.pid {
|
||||
Some(pid) => {
|
||||
let pl = state.manifest.store_mut().get_playlist_mut(pid);
|
||||
match pl {
|
||||
Some(pl) => pl.add_song(&self.sid),
|
||||
None => Toast::get().unwrap().show_toast("Not Allowed", "You cant add a song to the 'All Songs' playlist", ToastType::Error)
|
||||
};
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ impl Window for DebugW {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugW {
|
||||
|
||||
@@ -17,4 +17,7 @@ impl Window for ErrorW {
|
||||
ui.label("Hello from other window!");
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ use egui::{ViewportBuilder, ViewportId};
|
||||
use crate::GuiState;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
mod debug;
|
||||
mod error;
|
||||
mod settings;
|
||||
mod add_song;
|
||||
mod new_song;
|
||||
mod new_playlist;
|
||||
pub mod debug;
|
||||
pub mod error;
|
||||
pub mod settings;
|
||||
pub mod add_song;
|
||||
pub mod new_song;
|
||||
pub mod new_playlist;
|
||||
|
||||
lazy_static::lazy_static!(
|
||||
static ref WINDOWS: Arc<Mutex<HashMap<WindowId, Box<dyn Window>>>> = Arc::new(Mutex::new(HashMap::new()));
|
||||
pub static ref WINDOWS: Arc<Mutex<HashMap<WindowId, Box<dyn Window>>>> = Arc::new(Mutex::new(HashMap::new()));
|
||||
static ref OPEN_WINDOWS: Arc<Mutex<HashSet<WindowId>>> = Arc::new(Mutex::new(HashSet::new()));
|
||||
);
|
||||
|
||||
@@ -22,6 +22,7 @@ pub trait Window: std::fmt::Debug + Send {
|
||||
fn close(&self) where Self: Sized{
|
||||
OPEN_WINDOWS.lock().unwrap().remove(&Self::id());
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Ord, Eq)]
|
||||
@@ -104,4 +105,10 @@ impl Windows {
|
||||
pub fn is_open(&self, id: &WindowId) -> bool {
|
||||
OPEN_WINDOWS.lock().unwrap().contains(&id)
|
||||
}
|
||||
|
||||
pub fn set_value(&self, id: &WindowId, k: impl ToString, v: impl ToString) -> crate::Result<()> {
|
||||
// WINDOWS.lock().unwrap().get_mut(&win_id).unwrap().set_value();
|
||||
//
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,4 +99,7 @@ impl Window for NewPlaylistW {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use egui::{Sense, Vec2};
|
||||
use xmpd_manifest::{song::{Song, SourceType}, store::BaseStore};
|
||||
|
||||
use crate::{components::{CompGetter, toast::{Toast, ToastType}}, windows::WindowId};
|
||||
|
||||
use super::Window;
|
||||
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct NewSongW {
|
||||
|
||||
name: String,
|
||||
author: String,
|
||||
source_t: SourceType,
|
||||
source_url: String,
|
||||
source_url_old: String,
|
||||
}
|
||||
|
||||
impl Window for NewSongW {
|
||||
@@ -13,8 +24,113 @@ impl Window for NewSongW {
|
||||
fn default_title() -> &'static str where Self: Sized {
|
||||
"New Song"
|
||||
}
|
||||
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
|
||||
ui.label("Hello from other window!");
|
||||
fn draw(&mut self, ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
||||
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
||||
let img_size = 64.0;
|
||||
let img_spacing = 10.0;
|
||||
ui.vertical(|ui| {
|
||||
let mut rect = egui::Rect::ZERO;
|
||||
rect.set_width(img_size);
|
||||
rect.set_height(img_size);
|
||||
rect.set_top(img_spacing);
|
||||
rect.set_left(img_spacing);
|
||||
let rect_int = ui.interact(rect, "new_playlist_w".into(), Sense::click());
|
||||
if rect_int.hovered() {
|
||||
ui.allocate_ui_at_rect(rect, |ui| {
|
||||
ui.group(|ui| {
|
||||
let img = egui::Image::new(crate::data::PLUS_ICON)
|
||||
.tint(theme.accent_color)
|
||||
.fit_to_exact_size(Vec2::new(img_size, img_size));
|
||||
//.paint_at(ui, rect);
|
||||
ui.add(img);
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
ui.allocate_ui_at_rect(rect, |ui| {
|
||||
ui.group(|ui| {
|
||||
let img = egui::Image::new(crate::data::NOTE_ICON)
|
||||
.tint(theme.accent_color)
|
||||
.fit_to_exact_size(Vec2::new(img_size, img_size));
|
||||
//.paint_at(ui, rect);
|
||||
ui.add(img);
|
||||
});
|
||||
});
|
||||
}
|
||||
if rect_int.clicked() {
|
||||
// TODO: Add a way to add custom icons
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Adding icons to songs is not implemented", ToastType::Error);
|
||||
}
|
||||
ui.add_space(img_spacing);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Name: ");
|
||||
ui.text_edit_singleline(&mut self.name);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Author: ");
|
||||
ui.text_edit_singleline(&mut self.author);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Source Type: ");
|
||||
egui::ComboBox::new("new_song_song_t_sel", "")
|
||||
.selected_text(self.source_t.to_string())
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut self.source_t, SourceType::Youtube, SourceType::Youtube.to_string());
|
||||
ui.selectable_value(&mut self.source_t, SourceType::Spotify, SourceType::Spotify.to_string());
|
||||
ui.selectable_value(&mut self.source_t, SourceType::Soundcloud, SourceType::Soundcloud.to_string());
|
||||
//ui.selectable_value(&mut self.source_t, SourceType::HttpBare, SourceType::HttpBare.to_string());
|
||||
//ui.selectable_value(&mut self.source_t, SourceType::HttpZip, SourceType::HttpZip.to_string());
|
||||
//ui.selectable_value(&mut self.source_t, SourceType::Http7z, SourceType::Http7z.to_string());
|
||||
}
|
||||
);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Source URL: ");
|
||||
ui.text_edit_singleline(&mut self.source_url);
|
||||
if self.source_url != self.source_url_old {
|
||||
if let Some(t) = SourceType::from_url(&handle_error_ui!(url::Url::from_str(&self.source_url))) {
|
||||
self.source_t = t;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Max), |ui| {
|
||||
ui.add_space(3.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(3.0);
|
||||
if ui.button("Close").clicked() {
|
||||
self.author = String::from("Unknown");
|
||||
self.name = String::from("New Song");
|
||||
self.source_t = SourceType::Youtube;
|
||||
self.source_url = String::default();
|
||||
state.windows.toggle(&WindowId::NewSong, false);
|
||||
}
|
||||
|
||||
if ui.button("Add").clicked() {
|
||||
let mut s = handle_error_ui!(Song::new_from_str(&self.source_url, self.source_t));
|
||||
s.set_name(&self.name);
|
||||
s.set_author(&self.author);
|
||||
state.manifest.store_mut().get_songs_mut().insert(uuid::Uuid::new_v4(), s);
|
||||
let _ = state.manifest.save();
|
||||
self.author = String::from("Unknown");
|
||||
self.name = String::from("New Song");
|
||||
self.source_t = SourceType::Youtube;
|
||||
self.source_url = String::default();
|
||||
}
|
||||
|
||||
if ui.button("Cancel").clicked() {
|
||||
self.author = String::from("Unknown");
|
||||
self.name = String::from("New Song");
|
||||
self.source_t = SourceType::Youtube;
|
||||
self.source_url = String::default();
|
||||
state.windows.toggle(&WindowId::NewSong, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, _: String, _: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,9 @@ impl Window for SettingsW {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl SettingsW {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "xmpd-manifest"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
readme="README.md"
|
||||
authors.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::anyhow;
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests;
|
||||
@@ -59,12 +61,13 @@ impl<ST: store::BaseStore + Clone> Manifest<ST> {
|
||||
}
|
||||
|
||||
pub fn get_song_as_path(&self, sid: uuid::Uuid) -> Result<PathBuf> {
|
||||
let ext = &xmpd_settings::Settings::get()?.tooling.song_format;
|
||||
let mut p = xmpd_cliargs::CLIARGS.cache_path().into_std_path_buf();
|
||||
let settings = &xmpd_settings::Settings::get()?;
|
||||
let ext = &settings.tooling.song_format;
|
||||
let mut p = settings.cache_settings.cache_path.clone();
|
||||
p.push("songs");
|
||||
p.push(sid.to_string());
|
||||
p.set_extension(ext);
|
||||
Ok(p)
|
||||
Ok(p.into_std_path_buf())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,9 @@ impl Song {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, PartialOrd, Default)]
|
||||
pub enum SourceType {
|
||||
#[default]
|
||||
Youtube,
|
||||
Spotify,
|
||||
Soundcloud,
|
||||
@@ -94,7 +95,7 @@ pub enum SourceType {
|
||||
}
|
||||
|
||||
impl SourceType {
|
||||
fn from_url(url: &url::Url) -> Option<Self> {
|
||||
pub fn from_url(url: &url::Url) -> Option<Self> {
|
||||
match url.host_str() {
|
||||
Some("youtube.com") | Some("youtu.be") =>
|
||||
Some(Self::Youtube),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "xmpd-player"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
[package]
|
||||
name = "xmpd-settings"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
[dependencies]
|
||||
xmpd-cliargs.path = "../xmpd-cliargs"
|
||||
anyhow.workspace = true
|
||||
camino.workspace = true
|
||||
egui.workspace = true
|
||||
|
||||
29
xmpd-settings/src/cache.rs
Normal file
29
xmpd-settings/src/cache.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use camino::Utf8PathBuf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Cache {
|
||||
#[serde(default="Cache::default_cache_path")]
|
||||
pub cache_path: Utf8PathBuf,
|
||||
#[serde(default="Cache::default_manifest_path")]
|
||||
pub manifest_path: Utf8PathBuf,
|
||||
}
|
||||
|
||||
impl Default for Cache {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cache_path: Self::default_cache_path(),
|
||||
manifest_path: Self::default_manifest_path(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Cache {
|
||||
fn default_cache_path() -> Utf8PathBuf {
|
||||
Utf8PathBuf::from("./cache")
|
||||
}
|
||||
fn default_manifest_path() -> Utf8PathBuf {
|
||||
Utf8PathBuf::from("./manifest.json")
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use tooling::Tooling;
|
||||
|
||||
pub mod theme;
|
||||
pub mod tooling;
|
||||
pub mod cache;
|
||||
|
||||
lazy_static::lazy_static!(
|
||||
static ref SETTINGS: Arc<Mutex<Settings>> = Arc::new(Mutex::new(Settings::default()));
|
||||
@@ -20,6 +21,8 @@ pub struct Settings {
|
||||
pub theme: Theme,
|
||||
#[serde(default)]
|
||||
pub tooling: Tooling,
|
||||
#[serde(default)]
|
||||
pub cache_settings: cache::Cache
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
@@ -54,6 +57,16 @@ impl Settings {
|
||||
self.settings_path = path;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub fn load_cli_args(&mut self, cli_args: &xmpd_cliargs::CliArgs) {
|
||||
if let Some(mp) = cli_args.manifest_path() {
|
||||
self.cache_settings.manifest_path = mp;
|
||||
}
|
||||
if let Some(cp) = cli_args.cache_path() {
|
||||
self.cache_settings.cache_path = cp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "xmpd-tooling"
|
||||
edition = "2021"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
15
xmpd-update/Cargo.toml
Normal file
15
xmpd-update/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "xmpd-update"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
[dependencies]
|
||||
reqwest.workspace = true
|
||||
anyhow.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
semver.workspace = true
|
||||
log.workspace = true
|
||||
123
xmpd-update/src/lib.rs
Normal file
123
xmpd-update/src/lib.rs
Normal file
@@ -0,0 +1,123 @@
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::{fs::Permissions, os::unix::fs::PermissionsExt};
|
||||
use std::{env::args, path::PathBuf, process::{Stdio, exit}, str::FromStr};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use reqwest::blocking::Client;
|
||||
use serde::Deserialize;
|
||||
|
||||
|
||||
const CURRENT_VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
const GIT_HOST: &'static str = "git.mcorangehq.xyz";
|
||||
const GIT_USER: &'static str = "XOR64";
|
||||
const GIT_REPO: &'static str = "xmpd";
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
const EXT: &'static str = ".exe";
|
||||
#[cfg(target_family = "unix")]
|
||||
const EXT: &'static str = "";
|
||||
|
||||
|
||||
|
||||
pub type Result<T> = anyhow::Result<T>;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ReleaseInfo {
|
||||
tag_name: String,
|
||||
assets: Vec<ReleaseAsset>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ReleaseAsset {
|
||||
browser_download_url: String,
|
||||
name: String,
|
||||
}
|
||||
|
||||
|
||||
pub struct Update {
|
||||
|
||||
}
|
||||
|
||||
impl Update {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
pub fn update_xmpd_if_needed(&self) -> Result<()> {
|
||||
let current = semver::Version::parse(CURRENT_VERSION)?;
|
||||
log::info!("Current xmpd version: {current}");
|
||||
let client = Client::new();
|
||||
let req = client
|
||||
.get(format!("https://{GIT_HOST}/api/v1/repos/{GIT_USER}/{GIT_REPO}/releases/latest"))
|
||||
.send();
|
||||
|
||||
let Ok(req) = req else {
|
||||
log::warn!("Unable to check latest release! (No internet?)");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let exec_p = std::env::current_exe()?;
|
||||
let exec_d = exec_p.parent().unwrap_or(&exec_p);
|
||||
|
||||
let release: ReleaseInfo = req.json().map_err(|e| anyhow!("Unable to parse release info: {e}"))?;
|
||||
let latest = semver::Version::parse(&release.tag_name)?;
|
||||
|
||||
|
||||
log::info!("Latest xmpd version: {latest}");
|
||||
if latest > current {
|
||||
log::warn!("Update available, proceeding to update!");
|
||||
for asset in release.assets {
|
||||
if asset.name != format!("xmpd{EXT}") {
|
||||
continue;
|
||||
}
|
||||
let tmp_f = exec_d.join(format!("xmpd.update{EXT}"));
|
||||
let old_f = exec_d.join(format!("xmpd.old{EXT}"));
|
||||
log::info!("Downloading {}...", asset.browser_download_url);
|
||||
let mut res;
|
||||
match reqwest::blocking::get(asset.browser_download_url) {
|
||||
Ok(r) => res = r,
|
||||
Err(e) => {
|
||||
log::error!("Failed to download update: {e}");
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
let mut tmp_h = std::fs::File::create(&tmp_f)?;
|
||||
if let Err(e) = std::io::copy(&mut res, &mut tmp_h) {
|
||||
log::error!("Failed to write update to file: {e}");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
drop(tmp_h); // close handle (just in case you didnt know)
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
// set *only* the exec bit, doesnt change other permissions
|
||||
let meta = std::fs::metadata(&tmp_f)?;
|
||||
let mut perms = meta.permissions();
|
||||
perms.set_mode(perms.mode() | 0o111);
|
||||
|
||||
std::fs::set_permissions(&tmp_f, perms)?;
|
||||
}
|
||||
std::fs::rename(&exec_p, &old_f)?;
|
||||
std::fs::rename(&tmp_f, &exec_p)?;
|
||||
|
||||
log::debug!("{exec_p:?} -> {old_f:?}");
|
||||
log::debug!("{tmp_f:?} -> {exec_p:?}");
|
||||
log::info!("Update done, restarting!");
|
||||
|
||||
let status = std::process::Command::new(exec_p)
|
||||
.args(&args().collect::<Vec<String>>().as_slice()[1..])
|
||||
.stdin(Stdio::inherit())
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
.status()?;
|
||||
exit(status.code().unwrap_or(0));
|
||||
}
|
||||
|
||||
} else {
|
||||
log::info!("Already at latest version, skipping update!");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user