mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Store music library path
This commit is contained in:
parent
34546dcd8a
commit
4b88eec93f
2 changed files with 29 additions and 4 deletions
|
|
@ -2,8 +2,10 @@ use super::database::*;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use futures_channel::oneshot::Sender;
|
use futures_channel::oneshot::Sender;
|
||||||
use futures_channel::{mpsc, oneshot};
|
use futures_channel::{mpsc, oneshot};
|
||||||
|
use gio::prelude::*;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub enum BackendState {
|
pub enum BackendState {
|
||||||
NoMusicLibrary,
|
NoMusicLibrary,
|
||||||
|
|
@ -45,6 +47,7 @@ pub struct Backend {
|
||||||
pub state_stream: RefCell<mpsc::Receiver<BackendState>>,
|
pub state_stream: RefCell<mpsc::Receiver<BackendState>>,
|
||||||
state_sender: RefCell<mpsc::Sender<BackendState>>,
|
state_sender: RefCell<mpsc::Sender<BackendState>>,
|
||||||
action_sender: RefCell<Option<std::sync::mpsc::Sender<BackendAction>>>,
|
action_sender: RefCell<Option<std::sync::mpsc::Sender<BackendAction>>>,
|
||||||
|
settings: gio::Settings,
|
||||||
music_library_path: RefCell<Option<PathBuf>>,
|
music_library_path: RefCell<Option<PathBuf>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,10 +59,24 @@ impl Backend {
|
||||||
state_stream: RefCell::new(state_stream),
|
state_stream: RefCell::new(state_stream),
|
||||||
state_sender: RefCell::new(state_sender),
|
state_sender: RefCell::new(state_sender),
|
||||||
action_sender: RefCell::new(None),
|
action_sender: RefCell::new(None),
|
||||||
|
settings: gio::Settings::new("de.johrpan.musicus"),
|
||||||
music_library_path: RefCell::new(None),
|
music_library_path: RefCell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn init(self: Rc<Backend>) {
|
||||||
|
if let Some(path) = self.settings.get_string("music-library-path") {
|
||||||
|
if !path.is_empty() {
|
||||||
|
let context = glib::MainContext::default();
|
||||||
|
context.spawn_local(async move {
|
||||||
|
self.set_music_library_path_priv(PathBuf::from(path.to_string()))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_person(&self, person: Person) -> Result<()> {
|
pub async fn update_person(&self, person: Person) -> Result<()> {
|
||||||
let (sender, receiver) = oneshot::channel();
|
let (sender, receiver) = oneshot::channel();
|
||||||
self.unwrap_action_sender()?
|
self.unwrap_action_sender()?
|
||||||
|
|
@ -229,6 +246,16 @@ impl Backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_music_library_path(&self, path: PathBuf) -> Result<()> {
|
pub async fn set_music_library_path(&self, path: PathBuf) -> Result<()> {
|
||||||
|
self.settings
|
||||||
|
.set_string("music-library-path", path.to_str().unwrap())?;
|
||||||
|
self.set_music_library_path_priv(path).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_music_library_path(&self) -> Option<PathBuf> {
|
||||||
|
self.music_library_path.borrow().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_music_library_path_priv(&self, path: PathBuf) -> Result<()> {
|
||||||
self.music_library_path.replace(Some(path.clone()));
|
self.music_library_path.replace(Some(path.clone()));
|
||||||
self.set_state(BackendState::Loading);
|
self.set_state(BackendState::Loading);
|
||||||
|
|
||||||
|
|
@ -247,10 +274,6 @@ impl Backend {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_music_library_path(&self) -> Option<PathBuf> {
|
|
||||||
self.music_library_path.borrow().clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_state(&self, state: BackendState) {
|
fn set_state(&self, state: BackendState) {
|
||||||
self.state_sender.borrow_mut().try_send(state).unwrap();
|
self.state_sender.borrow_mut().try_send(state).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ impl Window {
|
||||||
get_widget!(builder, gtk::Box, empty_screen);
|
get_widget!(builder, gtk::Box, empty_screen);
|
||||||
|
|
||||||
let backend = Rc::new(Backend::new());
|
let backend = Rc::new(Backend::new());
|
||||||
|
backend.clone().init();
|
||||||
|
|
||||||
let poe_list = PoeList::new(backend.clone());
|
let poe_list = PoeList::new(backend.clone());
|
||||||
let navigator = Navigator::new(&empty_screen);
|
let navigator = Navigator::new(&empty_screen);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue