use mlua::prelude::*; use url::Url; use ron::de::from_bytes; use crate::{ globals::BULB_STATE_PATH, errors::RonError }; use serde::{ Serialize, Deserialize }; use std::{ fs, path::Path }; #[derive(Serialize, Deserialize, Clone)] pub struct State { pub plugins: Vec, pub repos: Vec } impl State { pub fn parse

(path: P) -> LuaResult where P: AsRef { let data = fs::read(path)?; // let mut manifest: Manifest = serde_json::from_slice(data.as_slice()).map_err(JsonError)?; let state = from_bytes(data.as_slice()).map_err(RonError)?; Ok(state) } pub fn new() -> Self { Self { plugins: Vec::new(), repos: Vec::new() } } pub fn clean(&self) { fs::write( BULB_STATE_PATH.lock().unwrap().to_owned(), ron::to_string(self).unwrap() ).expect("Couldn't write state"); } // pub fn clean_lua(_: &Lua, this: &Self, (): ()) -> LuaResult<()> { // this.clean(); // Ok(()) // } } // impl LuaUserData for State { // fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { // methods.add_method("clean", State::clean_lua) // } // } impl Drop for State { fn drop(&mut self) { self.clean(); } }