toggle offline/online mode
This commit is contained in:
parent
f03b676313
commit
e73f186b0f
@ -31,6 +31,11 @@ impl GrandMother {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn demote_to_offline(&mut self) {
|
||||||
|
let offline_mother = GrandMother::new_offline(self.config.clone());
|
||||||
|
(self.parser, self.playlist) = (offline_mother.parser, offline_mother.playlist);
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn promote_to_online(&mut self) -> Result<(), Error> {
|
pub async fn promote_to_online(&mut self) -> Result<(), Error> {
|
||||||
let online_mother = GrandMother::new_online(self.config.clone()).await?;
|
let online_mother = GrandMother::new_online(self.config.clone()).await?;
|
||||||
(self.parser, self.playlist) = (online_mother.parser, online_mother.playlist);
|
(self.parser, self.playlist) = (online_mother.parser, online_mother.playlist);
|
||||||
|
11
src/lib.rs
11
src/lib.rs
@ -8,7 +8,10 @@ mod opt;
|
|||||||
pub mod parser;
|
pub mod parser;
|
||||||
mod playlist;
|
mod playlist;
|
||||||
|
|
||||||
use std::{io::{stdin, stdout, Stdin, StdoutLock, Write}, rc::Rc};
|
use std::{
|
||||||
|
io::{stdin, stdout, Stdin, StdoutLock, Write},
|
||||||
|
rc::Rc,
|
||||||
|
};
|
||||||
|
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
pub use config::Configuration;
|
pub use config::Configuration;
|
||||||
@ -65,10 +68,10 @@ pub async fn get_gm(
|
|||||||
mode: Mode,
|
mode: Mode,
|
||||||
readline: &mut Readline<'_>,
|
readline: &mut Readline<'_>,
|
||||||
config: Rc<Configuration>,
|
config: Rc<Configuration>,
|
||||||
) -> Result<GrandMother, String> {
|
) -> Result<(GrandMother, bool), String> {
|
||||||
match mode {
|
match mode {
|
||||||
Mode::Online => GrandMother::new_online(config).await,
|
Mode::Online => Ok((GrandMother::new_online(config).await?, true)),
|
||||||
Mode::Offline => Ok(GrandMother::new_offline(config)),
|
Mode::Offline => Ok((GrandMother::new_offline(config), false)),
|
||||||
Mode::Ask => loop {
|
Mode::Ask => loop {
|
||||||
let input = readline
|
let input = readline
|
||||||
.input("Online/Offline mode? [1/2] ")
|
.input("Online/Offline mode? [1/2] ")
|
||||||
|
13
src/main.rs
13
src/main.rs
@ -31,7 +31,7 @@ async fn main() {
|
|||||||
" {} is to make entries availibe for offline use later on in the program",
|
" {} is to make entries availibe for offline use later on in the program",
|
||||||
"o".bold()
|
"o".bold()
|
||||||
),
|
),
|
||||||
format!(" {} is to switch to online mode", "m".bold()),
|
format!(" {} is to switch between modes (toggle)", "m".bold()),
|
||||||
format!(" {} is to perform a new search", "s".bold()),
|
format!(" {} is to perform a new search", "s".bold()),
|
||||||
format!(" {} is to select all", "a".bold()),
|
format!(" {} is to select all", "a".bold()),
|
||||||
format!(" {} is to toggtle fullscreen for mpv", "f".bold()),
|
format!(" {} is to toggtle fullscreen for mpv", "f".bold()),
|
||||||
@ -47,7 +47,7 @@ async fn main() {
|
|||||||
let mut mpv_fs = false;
|
let mut mpv_fs = false;
|
||||||
let mut search_result: Option<Rc<Vec<&M3u8>>> = None;
|
let mut search_result: Option<Rc<Vec<&M3u8>>> = None;
|
||||||
let mut readline = Readline::new();
|
let mut readline = Readline::new();
|
||||||
let gm = get_gm(
|
let (gm, mut in_online) = get_gm(
|
||||||
opt.mode,
|
opt.mode,
|
||||||
&mut readline,
|
&mut readline,
|
||||||
Rc::new(Configuration::new().expect("Failed to write to configfile")),
|
Rc::new(Configuration::new().expect("Failed to write to configfile")),
|
||||||
@ -100,10 +100,19 @@ async fn main() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
"m" => {
|
"m" => {
|
||||||
|
if in_online {
|
||||||
|
unsafe { get_mut_ref(&gm) }.demote_to_offline();
|
||||||
|
println!("Switched to offline mode");
|
||||||
|
} else {
|
||||||
let result = unsafe { get_mut_ref(&gm) }.promote_to_online().await;
|
let result = unsafe { get_mut_ref(&gm) }.promote_to_online().await;
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
println!("Failed to switch to onlinemode {:?}", e);
|
println!("Failed to switch to onlinemode {:?}", e);
|
||||||
|
} else {
|
||||||
|
println!("Switched to online mode");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
in_online = !in_online;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user