Initial bug fixes (#127)

* Initial bug fixes

* fix compile error on non-mac

* Fix even more bugs

* Fix more

* fix more

* fix build

* fix build

* address review comments
This commit is contained in:
Geometrically
2023-06-02 07:09:46 -07:00
committed by GitHub
parent 9ea548cfe3
commit ee61951698
57 changed files with 3823 additions and 2813 deletions

View File

@@ -16,6 +16,11 @@ pub async fn auth_authenticate_await_completion() -> Result<Credentials> {
Ok(auth::authenticate_await_complete_flow().await?)
}
#[tauri::command]
pub async fn auth_cancel_flow() -> Result<()> {
Ok(auth::cancel_flow().await?)
}
/// Refresh some credentials using Hydra, if needed
// invoke('auth_refresh',user)
#[tauri::command]

View File

@@ -18,11 +18,7 @@ pub async fn logs_get_logs(
profile_uuid: Uuid,
clear_contents: Option<bool>,
) -> Result<Vec<Logs>> {
use std::time::Instant;
let now = Instant::now();
let val = logs::get_logs(profile_uuid, clear_contents).await?;
let elapsed = now.elapsed();
println!("Elapsed: {:.2?}", elapsed);
Ok(val)
}

View File

@@ -12,6 +12,7 @@ pub mod profile;
pub mod profile_create;
pub mod settings;
pub mod tags;
pub mod utils;
pub type Result<T> = std::result::Result<T, TheseusSerializableError>;

View File

@@ -4,13 +4,15 @@ use theseus::prelude::*;
#[tauri::command]
pub async fn pack_install_version_id(
project_id: String,
version_id: String,
pack_title: String,
pack_icon: Option<String>,
) -> Result<PathBuf> {
let res =
pack::install_pack_from_version_id(version_id, pack_title, pack_icon)
.await?;
let res = pack::install_pack_from_version_id(
project_id, version_id, pack_title, pack_icon,
)
.await?;
Ok(res)
}

View File

@@ -88,7 +88,7 @@ pub async fn profile_update_project(
path: &Path,
project_path: &Path,
) -> Result<PathBuf> {
Ok(profile::update_project(path, project_path).await?)
Ok(profile::update_project(path, project_path, None).await?)
}
// Adds a project to a profile from a version ID

View File

@@ -0,0 +1,76 @@
use crate::api::Result;
use std::process::Command;
// cfg only on mac os
// disables mouseover and fixes a random crash error only fixed by recent versions of macos
#[cfg(target_os = "macos")]
#[tauri::command]
pub async fn should_disable_mouseover() -> bool {
// We try to match version to 12.2 or higher. If unrecognizable to pattern or lower, we default to the css with disabled mouseover for safety
let os = os_info::get();
if let os_info::Version::Semantic(major, minor, _) = os.version() {
if *major >= 12 && *minor >= 3 {
// Mac os version is 12.3 or higher, we allow mouseover
return false;
}
}
true
}
#[cfg(not(target_os = "macos"))]
#[tauri::command]
pub async fn should_disable_mouseover() -> bool {
false
}
#[tauri::command]
pub fn show_in_folder(path: String) -> Result<()> {
{
#[cfg(target_os = "windows")]
{
Command::new("explorer")
.args(["/select,", &path]) // The comma after select is not a typo
.spawn()?;
}
#[cfg(target_os = "linux")]
{
use std::fs;
use std::fs::metadata;
use std::path::PathBuf;
if path.contains(",") {
// see https://gitlab.freedesktop.org/dbus/dbus/-/issues/76
let new_path = match metadata(&path)?.is_dir() {
true => path.clone(),
false => {
let mut path2 = PathBuf::from(path.clone());
path2.pop();
path2.to_string_lossy().to_string()
}
};
Command::new("xdg-open").arg(&new_path).spawn()?;
} else {
Command::new("dbus-send")
.args([
"--session",
"--dest=org.freedesktop.FileManager1",
"--type=method_call",
"/org/freedesktop/FileManager1",
"org.freedesktop.FileManager1.ShowItems",
format!("array:string:\"file://{path}\"").as_str(),
"string:\"\"",
])
.spawn()?;
}
}
#[cfg(target_os = "macos")]
{
Command::new("open").args(["-R", &path]).spawn()?;
}
Ok::<(), theseus::Error>(())
}?;
Ok(())
}

View File

@@ -5,6 +5,7 @@
use theseus::prelude::*;
use tauri::Manager;
use tracing_error::ErrorLayer;
use tracing_subscriber::EnvFilter;
@@ -20,29 +21,14 @@ async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
Ok(())
}
// cfg only on mac os
// disables mouseover and fixes a random crash error only fixed by recent versions of macos
#[cfg(target_os = "macos")]
#[tauri::command]
async fn should_disable_mouseover() -> bool {
// We try to match version to 12.2 or higher. If unrecognizable to pattern or lower, we default to the css with disabled mouseover for safety
let os = os_info::get();
if let os_info::Version::Semantic(major, minor, _) = os.version() {
if *major >= 12 && *minor >= 3 {
// Mac os version is 12.3 or higher, we allow mouseover
return false;
}
}
true
}
#[cfg(not(target_os = "macos"))]
#[tauri::command]
async fn should_disable_mouseover() -> bool {
false
}
use tracing_subscriber::prelude::*;
#[derive(Clone, serde::Serialize)]
struct Payload {
args: Vec<String>,
cwd: String,
}
fn main() {
/*
tracing is set basd on the environment variable RUST_LOG=xxx, depending on the amount of logs to show
@@ -70,9 +56,13 @@ fn main() {
.expect("setting default subscriber failed");
tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
app.emit_all("single-instance", Payload { args: argv, cwd })
.unwrap();
}))
.plugin(tauri_plugin_window_state::Builder::default().build())
.invoke_handler(tauri::generate_handler![
initialize_state,
should_disable_mouseover,
api::progress_bars_list,
api::profile_create::profile_create_empty,
api::profile_create::profile_create,
@@ -98,6 +88,7 @@ fn main() {
api::pack::pack_install_file,
api::auth::auth_authenticate_begin_flow,
api::auth::auth_authenticate_await_completion,
api::auth::auth_cancel_flow,
api::auth::auth_refresh,
api::auth::auth_remove_user,
api::auth::auth_has_user,
@@ -141,6 +132,8 @@ fn main() {
api::logs::logs_get_stderr_by_datetime,
api::logs::logs_delete_logs,
api::logs::logs_delete_logs_by_datetime,
api::utils::show_in_folder,
api::utils::should_disable_mouseover,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");