Add video, data, and playlist structs
This commit is contained in:
+51
-2
@@ -2,10 +2,12 @@ use std::time::Duration;
|
||||
use eframe::{Frame, Storage, CreationContext};
|
||||
use eframe::egui::{Context, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yt_dlp::model::VideoQuality;
|
||||
|
||||
pub(crate) struct Application {
|
||||
settings: AppSettings,
|
||||
layers: Vec<Box<dyn crate::layer::Layer>>,
|
||||
data: Data,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
@@ -16,6 +18,36 @@ struct AppSettings {
|
||||
save_thumbnails: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct Data {
|
||||
playlists: Vec<Playlist>,
|
||||
videos: Vec<Video>,
|
||||
root_path: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct Video {
|
||||
name: String,
|
||||
uuid: String,
|
||||
original_url: String,
|
||||
video_path: String,
|
||||
thumbnail_path: String,
|
||||
thumbnail_path_low_quality: String,
|
||||
video_quality: VideoQuality,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct Playlist {
|
||||
name: String,
|
||||
uuid: String,
|
||||
original_url: String,
|
||||
videos: Vec<Video>,
|
||||
creator: String,
|
||||
thumbnail_path: String,
|
||||
thumbnail_path_low_quality: String,
|
||||
}
|
||||
|
||||
|
||||
impl Application {
|
||||
pub fn new(cc: &CreationContext, layers: Vec<Box<dyn crate::layer::Layer>>) -> Self {
|
||||
let mut settings = AppSettings::default();
|
||||
@@ -27,7 +59,16 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
Self { settings, layers }
|
||||
let mut data = Data::default();
|
||||
if let Some(storage) = cc.storage {
|
||||
if let Some(stored_str) = storage.get_string("app_data") {
|
||||
if let Ok(parsed) = serde_json::from_str(&stored_str) {
|
||||
data = parsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Self { settings, layers, data }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +94,18 @@ impl eframe::App for Application {
|
||||
if let Ok(serialized) = serde_json::to_string(&self.settings) {
|
||||
_storage.set_string("app_settings", serialized);
|
||||
}
|
||||
|
||||
if let Ok(serialized) = serde_json::to_string(&self.data) {
|
||||
_storage.set_string("app_data", serialized);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_exit(&mut self) {
|
||||
|
||||
let mut layers = std::mem::take(&mut self.layers);
|
||||
for layer in &mut layers {
|
||||
layer.on_exit(self);
|
||||
}
|
||||
self.layers = layers;
|
||||
}
|
||||
|
||||
fn auto_save_interval(&self) -> Duration {
|
||||
|
||||
@@ -30,7 +30,6 @@ fn main() {
|
||||
let mut layers: Vec<Box<dyn layer::Layer>> = Vec::new();
|
||||
layers.push(Box::new(TestLayer::default()));
|
||||
|
||||
|
||||
let mut options = eframe::NativeOptions::default();
|
||||
options.persistence_path = Some(args.state.parse().expect("Failed to parse state config file path into path"));
|
||||
eframe::run_native(
|
||||
|
||||
Reference in New Issue
Block a user