initial commit
This commit is contained in:
67
rust/src/lib.rs
Normal file
67
rust/src/lib.rs
Normal file
@ -0,0 +1,67 @@
|
||||
mod cfg;
|
||||
mod types;
|
||||
mod cmd;
|
||||
mod pkg_remote;
|
||||
mod pkg_local;
|
||||
mod util;
|
||||
|
||||
use tokio::{fs, try_join};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use types::{local, Package};
|
||||
|
||||
use tauri::Manager;
|
||||
|
||||
struct AppData {
|
||||
profile: Option<local::Profile>,
|
||||
mods_local: Vec<Package>,
|
||||
mods_store: Vec<Package>,
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub async fn run(args: Vec<String>) {
|
||||
simple_logger::init_with_env().unwrap();
|
||||
|
||||
log::info!(
|
||||
"Running from {}",
|
||||
std::env::current_dir().unwrap_or_default().to_str().unwrap_or_default()
|
||||
);
|
||||
|
||||
try_join!(
|
||||
fs::create_dir_all(util::config_dir()),
|
||||
fs::create_dir_all(util::pkg_dir()),
|
||||
fs::create_dir_all(util::cache_dir())
|
||||
).expect("Unable to create working directories");
|
||||
|
||||
let app_data = AppData {
|
||||
profile: pkg_local::load_config(),
|
||||
mods_local: pkg_local::walk_packages(true).await,
|
||||
mods_store: [].to_vec(),
|
||||
};
|
||||
|
||||
if args.len() == 1 {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
app.manage(Mutex::new(app_data));
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
cmd::get_packages,
|
||||
cmd::reload_packages,
|
||||
cmd::get_listings,
|
||||
cmd::download_package,
|
||||
cmd::delete_package,
|
||||
cmd::get_current_profile,
|
||||
cmd::init_profile,
|
||||
cmd::save_profile,
|
||||
cmd::startline
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
} else {
|
||||
panic!("Not implemented");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user