update library version and fix args
This commit is contained in:
parent
ebad72d440
commit
f332bca033
2
library
2
library
@ -1 +1 @@
|
|||||||
Subproject commit 979c717cc0ecc3f9a0c26ce868dafc2b20c3328c
|
Subproject commit 96cb053e659123afc394187229949e7f32c23372
|
@ -5,127 +5,141 @@
|
|||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use tokio::runtime::Runtime;
|
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
extern crate ip_lib;
|
extern crate ip_lib;
|
||||||
extern crate rand;
|
|
||||||
extern crate open;
|
extern crate open;
|
||||||
|
extern crate rand;
|
||||||
|
|
||||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn get_version() -> String {
|
fn get_version() -> String {
|
||||||
option_env!("CARGO_PKG_VERSION").unwrap_or("x.x.x").to_string()
|
option_env!("CARGO_PKG_VERSION")
|
||||||
|
.unwrap_or("x.x.x")
|
||||||
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn create_entry(name: String, username: String, pw: &str, mpw: String) -> bool {
|
fn create_entry(name: &str, username: String, pw: &str, mpw: &str) -> bool {
|
||||||
let return_value = ip_lib::create_entry(&name, username+";"+pw, mpw);
|
let username_and_pw = username + ";" + pw;
|
||||||
if return_value {
|
let return_value = ip_lib::create_entry(name, &username_and_pw, mpw);
|
||||||
isync_save();
|
if return_value {
|
||||||
}
|
isync_save();
|
||||||
return_value
|
}
|
||||||
|
return_value
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn random_password() -> String {
|
fn random_password() -> String {
|
||||||
ip_lib::random_password()
|
ip_lib::random_password()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn get_entry(name: String, mpw: String) -> Result<(String,String),String> {
|
fn get_entry(name: &str, mpw: &str) -> Result<(String, String), String> {
|
||||||
let binding = ip_lib::get_entry(&name, mpw);
|
let binding = ip_lib::get_entry(name, mpw);
|
||||||
if let Ok(data) = binding {
|
if let Ok(data) = binding {
|
||||||
let mut split = data.split(';');
|
let mut split = data.split(';');
|
||||||
Ok((split.next().unwrap().to_string(),split.next().unwrap().to_string()))
|
Ok((
|
||||||
} else {
|
split.next().unwrap().to_string(),
|
||||||
Err(binding.expect_err("expected error"))
|
split.next().unwrap().to_string(),
|
||||||
}
|
))
|
||||||
|
} else {
|
||||||
|
Err(binding.expect_err("expected error"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn get_entries() -> Vec<String> {
|
fn get_entries() -> Vec<String> {
|
||||||
let mut vector: Vec<String> = Vec::default();
|
let mut vector: Vec<String> = Vec::default();
|
||||||
for entry in ip_lib::get_entries() {
|
for entry in ip_lib::get_entries() {
|
||||||
let entry_filename = entry.unwrap().file_name();
|
let entry_filename = entry.unwrap().file_name();
|
||||||
let ent = entry_filename.to_str().unwrap();
|
let ent = entry_filename.to_str().unwrap();
|
||||||
if ent != "token.ipasst" && ent.len()>6 {
|
if ent != "token.ipasst" && ent.len() > 6 {
|
||||||
vector.insert(0, ent[..ent.len()-6].to_string());
|
vector.insert(0, ent[..ent.len() - 6].to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector.sort();
|
vector.sort();
|
||||||
|
|
||||||
vector
|
vector
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn remove_entry(name: &str) -> bool {
|
fn remove_entry(name: &str) -> bool {
|
||||||
let filepath = &(ip_lib::get_ipass_folder()+name+".ipass");
|
let filepath = &(ip_lib::get_ipass_folder() + name + ".ipass");
|
||||||
if std::path::Path::new(filepath).exists() {
|
if std::path::Path::new(filepath).exists() {
|
||||||
std::fs::remove_file(filepath).unwrap();
|
std::fs::remove_file(filepath).unwrap();
|
||||||
isync_save();
|
isync_save();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn open_authorize() -> u32 {
|
fn open_authorize() -> u32 {
|
||||||
let code:u32 = rand::random();
|
let code: u32 = rand::random();
|
||||||
open::that(format!("https://ipost.rocks/authorize?id=1&extra={}",code)).unwrap();
|
open::that(format!("https://ipost.rocks/authorize?id=1&extra={}", code)).unwrap();
|
||||||
//the IPass app id is 1
|
//the IPass app id is 1
|
||||||
code
|
code
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn store_token(token: String) {
|
fn store_token(token: String) {
|
||||||
let filepath = &(ip_lib::get_ipass_folder()+"token.ipasst");
|
let filepath = &(ip_lib::get_ipass_folder() + "token.ipasst");
|
||||||
let mut file = File::create(filepath).unwrap();
|
let mut file = File::create(filepath).unwrap();
|
||||||
file.write_all(token.as_bytes()).unwrap();
|
file.write_all(token.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn remove_token() {
|
fn remove_token() {
|
||||||
let filepath = &(ip_lib::get_ipass_folder()+"token.ipasst");
|
let filepath = &(ip_lib::get_ipass_folder() + "token.ipasst");
|
||||||
std::fs::remove_file(filepath).unwrap();
|
std::fs::remove_file(filepath).unwrap();
|
||||||
//TODO: cleaner solution via IPass api call to unauthorize
|
//TODO: cleaner solution via IPass api call to unauthorize
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn get_isync_status() -> bool {
|
fn get_isync_status() -> bool {
|
||||||
let filepath = &(ip_lib::get_ipass_folder()+"token.ipasst");
|
let filepath = &(ip_lib::get_ipass_folder() + "token.ipasst");
|
||||||
std::path::Path::new(filepath).exists()
|
std::path::Path::new(filepath).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn isync_save() {
|
fn isync_save() {
|
||||||
let isync_save_future = ip_lib::isync_save();
|
let isync_save_future = ip_lib::isync_save();
|
||||||
|
|
||||||
let rt = Runtime::new().unwrap();
|
let rt = Runtime::new().unwrap();
|
||||||
let _save_output = rt.block_on(isync_save_future);
|
let _save_output = rt.block_on(isync_save_future);
|
||||||
//println!("isync_save: {}",save_output);
|
//println!("isync_save: {}",save_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn sync_isync(rt: State<Runtime>) {
|
fn sync_isync(rt: State<Runtime>) {
|
||||||
//println!("going to sync");
|
//println!("going to sync");
|
||||||
rt.spawn(async {
|
rt.spawn(async {
|
||||||
let _get_output = ip_lib::isync_get().await;
|
let _get_output = ip_lib::isync_get().await;
|
||||||
//println!("isync_get: {}",_get_output);
|
//println!("isync_get: {}",_get_output);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rt = Runtime::new().unwrap();
|
let rt = Runtime::new().unwrap();
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
get_version,create_entry,random_password,
|
get_version,
|
||||||
get_entry,get_entries,remove_entry,
|
create_entry,
|
||||||
open_authorize,store_token,get_isync_status,
|
random_password,
|
||||||
sync_isync,remove_token])
|
get_entry,
|
||||||
.manage(rt)
|
get_entries,
|
||||||
.run(tauri::generate_context!())
|
remove_entry,
|
||||||
.expect("error while running tauri application");
|
open_authorize,
|
||||||
|
store_token,
|
||||||
|
get_isync_status,
|
||||||
|
sync_isync,
|
||||||
|
remove_token
|
||||||
|
])
|
||||||
|
.manage(rt)
|
||||||
|
.run(tauri::generate_context!())
|
||||||
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user