Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwi committed Dec 5, 2024
1 parent 2599424 commit 8e3897d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 80 deletions.
113 changes: 55 additions & 58 deletions src-tauri/src/frontend_commands/install/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::utils;
use lazy_static::lazy_static;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
Expand All @@ -9,78 +8,76 @@ mod windows;
#[cfg(target_os = "windows")]
pub use windows::*;

lazy_static! {
pub static ref VERSION: String = String::from("1.0.0");
pub static ref TESSERACT_INSTALL_FILE: String = {
#[cfg(target_os = "macos")]
{
todo!()
}
#[cfg(target_os = "windows")]
pub static VERSION: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| "1.0.0".to_string());
pub static TESSERACT_INSTALL_FILE: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
#[cfg(target_os = "macos")]
{
todo!()
}
#[cfg(target_os = "windows")]
{
utils::fs::current_dir()
.join("resources")
.join("tesseract-windows.exe")
.to_str()
.unwrap()
.to_string()
}
});
pub static PYTHON_INSTALL_FILE: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
#[cfg(target_os = "macos")]
{
#[cfg(debug_assertions)]
{
utils::fs::current_dir()
.join("resources")
.join("tesseract-windows.exe")
.join("python-macos.pkg")
.to_str()
.unwrap()
.to_string()
}
};
pub static ref PYTHON_INSTALL_FILE: String = {
#[cfg(target_os = "macos")]
#[cfg(not(debug_assertions))]
{
#[cfg(debug_assertions)]
{
utils::fs::current_dir()
.join("resources")
.join("python-macos.pkg")
.to_str()
.unwrap()
.to_string()
}
#[cfg(not(debug_assertions))]
{
"/Applications/kiwi.app/Contents/Resources/resources/python-macos.pkg".to_string()
}
"/Applications/kiwi.app/Contents/Resources/resources/python-macos.pkg".to_string()
}
#[cfg(target_os = "windows")]
}
#[cfg(target_os = "windows")]
{
utils::fs::current_dir()
.join("resources")
.join("python-windows.exe")
.to_str()
.unwrap()
.to_string()
}
});
pub static WHL_FILE: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
#[cfg(target_os = "macos")]
{
#[cfg(debug_assertions)]
{
utils::fs::current_dir()
.join("resources")
.join("python-windows.exe")
.join(format!(
"kiwi-{}-cp310-abi3-macosx_11_0_arm64.whl",
*VERSION
))
.to_str()
.unwrap()
.to_string()
}
};
static ref WHL_FILE: String = {
#[cfg(target_os = "macos")]
#[cfg(not(debug_assertions))]
{
#[cfg(debug_assertions)]
{
utils::fs::current_dir()
.join("resources")
.join(format!(
"kiwi-{}-cp310-abi3-macosx_11_0_arm64.whl",
*VERSION
))
.to_str()
.unwrap()
.to_string()
}
#[cfg(not(debug_assertions))]
{
format!("/Applications/kiwi.app/Contents/Resources/resources/kiwi-{}-cp310-abi3-macosx_11_0_arm64.whl", *VERSION)
}
}
#[cfg(target_os = "windows")]
{
utils::fs::current_dir()
.join("resources")
.join(format!("kiwi-{}-cp310-abi3-win_amd64.whl", *VERSION))
.to_str()
.unwrap()
.to_string()
format!("/Applications/kiwi.app/Contents/Resources/resources/kiwi-{}-cp310-abi3-macosx_11_0_arm64.whl", *VERSION)
}
};
}
}
#[cfg(target_os = "windows")]
{
utils::fs::current_dir()
.join("resources")
.join(format!("kiwi-{}-cp310-abi3-win_amd64.whl", *VERSION))
.to_str()
.unwrap()
.to_string()
}
});
44 changes: 23 additions & 21 deletions src-tauri/src/frontend_commands/install/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,8 @@ use super::{PYTHON_INSTALL_FILE, TESSERACT_INSTALL_FILE, WHL_FILE};
use crate::common::{PROJECTS_DIR, PYTHON_EXEC_FILE};
use crate::utils;
use crate::utils::fs::{current_dir, exists};
use lazy_static::lazy_static;
use std::path::PathBuf;

lazy_static! {
pub static ref PYTHON_DIR: String = utils::fs::current_dir()
.join("python")
.to_str()
.unwrap()
.to_string();
pub static ref TESSERACT_UNINSTALL_FILE: String =
PathBuf::from(std::env::var("ProgramFiles").unwrap())
.join("Tesseract-OCR")
.join("tesseract-uninstall.exe")
.to_str()
.unwrap()
.to_string();
pub static ref TESSERACT_DIR: String = PathBuf::from(std::env::var("ProgramFiles").unwrap())
.join("Tesseract-OCR")
.to_str()
.unwrap()
.to_string();
}

#[tauri::command]
pub fn is_installed() -> bool {
//python exec file
Expand Down Expand Up @@ -247,3 +226,26 @@ pub fn install_tessdata(architecture: String) -> Result<bool, String> {
}
Err("Not supported yet".to_string())
}

pub static PYTHON_DIR: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
utils::fs::current_dir()
.join("python")
.to_str()
.unwrap()
.to_string()
});
pub static TESSERACT_UNINSTALL_FILE: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
PathBuf::from(std::env::var("ProgramFiles").unwrap())
.join("Tesseract-OCR")
.join("tesseract-uninstall.exe")
.to_str()
.unwrap()
.to_string()
});
pub static TESSERACT_DIR: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
PathBuf::from(std::env::var("ProgramFiles").unwrap())
.join("Tesseract-OCR")
.to_str()
.unwrap()
.to_string()
});
2 changes: 1 addition & 1 deletion src-tauri/src/grpc/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ async fn init_client() {
*CLIENT.lock().unwrap() = Some(client);
}

pub static CLIENT: LazyLock<Mutex<Option<FindServiceClient<Channel>>>> =
static CLIENT: LazyLock<Mutex<Option<FindServiceClient<Channel>>>> =
LazyLock::new(|| Mutex::new(None));

0 comments on commit 8e3897d

Please sign in to comment.