added a bunch of frontend things
7
frontend/src-tauri/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
5715
frontend/src-tauri/Cargo.lock
generated
Normal file
31
frontend/src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "haystack"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix may seem redundant but it is necessary
|
||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||
name = "haystack_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = ["macos-private-api"] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tauri-plugin-dialog = "2"
|
||||
notify = "6.1.1"
|
||||
base64 = "0.21.7"
|
||||
tokio = { version = "1.36.0", features = ["full"] }
|
||||
|
||||
[target."cfg(target_os = \"macos\")".dependencies]
|
||||
cocoa = "0.26"
|
||||
3
frontend/src-tauri/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
12
frontend/src-tauri/capabilities/default.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default",
|
||||
"dialog:default",
|
||||
"core:window:allow-start-dragging"
|
||||
]
|
||||
}
|
||||
BIN
frontend/src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
frontend/src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
frontend/src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
frontend/src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
frontend/src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
frontend/src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
frontend/src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
frontend/src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
frontend/src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
frontend/src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
frontend/src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
frontend/src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
frontend/src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
frontend/src-tauri/icons/icon.icns
Normal file
BIN
frontend/src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
frontend/src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
151
frontend/src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,151 @@
|
||||
use std::path::PathBuf;
|
||||
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
|
||||
use tauri::Emitter;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::fs;
|
||||
use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64};
|
||||
use std::sync::Mutex;
|
||||
use std::sync::Arc;
|
||||
use tauri::AppHandle;
|
||||
use tauri::{TitleBarStyle, WebviewUrl, WebviewWindowBuilder};
|
||||
|
||||
|
||||
struct WatcherState {
|
||||
watcher: Option<RecommendedWatcher>,
|
||||
}
|
||||
|
||||
impl WatcherState {
|
||||
fn new() -> Self {
|
||||
Self { watcher: None }
|
||||
}
|
||||
}
|
||||
|
||||
// Handle PNG file processing
|
||||
fn process_png_file(path: &PathBuf, app: AppHandle) -> Result<(), String> {
|
||||
println!("Processing PNG file: {}", path.display());
|
||||
|
||||
// Read the file
|
||||
let contents = fs::read(path)
|
||||
.map_err(|e| format!("Failed to read file: {}", e))?;
|
||||
|
||||
// Convert to base64
|
||||
let base64_string = BASE64.encode(&contents);
|
||||
println!("Generated base64 string of length: {}", base64_string.len());
|
||||
|
||||
// Emit the base64 to frontend
|
||||
app.emit("png-processed", base64_string)
|
||||
.map_err(|e| format!("Failed to emit event: {}", e))?;
|
||||
|
||||
println!("Successfully processed file: {}", path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn handle_selected_folder(
|
||||
path: String,
|
||||
state: tauri::State<'_, Arc<Mutex<WatcherState>>>,
|
||||
app: AppHandle,
|
||||
) -> Result<String, String> {
|
||||
let path_buf = PathBuf::from(&path);
|
||||
|
||||
if !path_buf.exists() || !path_buf.is_dir() {
|
||||
return Err("Invalid directory path".to_string());
|
||||
}
|
||||
|
||||
// Stop existing watcher if any
|
||||
let mut state = state.lock().map_err(|_| "Failed to lock state".to_string())?;
|
||||
state.watcher = None;
|
||||
|
||||
// Create a channel to receive file system events
|
||||
let (tx, rx) = channel();
|
||||
|
||||
// Create a new watcher
|
||||
let mut watcher = RecommendedWatcher::new(
|
||||
tx,
|
||||
Config::default(),
|
||||
).map_err(|e| format!("Failed to create watcher: {}", e))?;
|
||||
|
||||
// Start watching the directory
|
||||
watcher.watch(path_buf.as_ref(), RecursiveMode::Recursive)
|
||||
.map_err(|e| format!("Failed to watch directory: {}", e))?;
|
||||
|
||||
// Store the watcher in state
|
||||
state.watcher = Some(watcher);
|
||||
|
||||
let path_clone = path.clone();
|
||||
let app_clone = app.clone();
|
||||
tokio::spawn(async move {
|
||||
println!("Starting to watch directory: {}", path_clone);
|
||||
for res in rx {
|
||||
match res {
|
||||
Ok(event) => {
|
||||
println!("Received event: {:?}", event);
|
||||
match event.kind {
|
||||
notify::EventKind::Create(_) | notify::EventKind::Modify(_) => {
|
||||
for path in event.paths {
|
||||
println!("Processing path: {}", path.display());
|
||||
if let Some(extension) = path.extension() {
|
||||
if extension.to_string_lossy().to_lowercase() == "png" {
|
||||
if let Err(e) = process_png_file(&path, app_clone.clone()) {
|
||||
eprintln!("Error processing PNG file: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("Watch error: {:?}", e),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(format!("Now watching directory: {}", path))
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let watcher_state = Arc::new(Mutex::new(WatcherState::new()));
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.manage(watcher_state)
|
||||
.invoke_handler(tauri::generate_handler![handle_selected_folder])
|
||||
.setup(|app| {
|
||||
let win_builder =
|
||||
WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
|
||||
.hidden_title(true)
|
||||
.inner_size(480.0, 320.0);
|
||||
|
||||
// set transparent title bar only when building for macOS
|
||||
#[cfg(target_os = "macos")]
|
||||
let win_builder = win_builder.title_bar_style(TitleBarStyle::Transparent);
|
||||
|
||||
let window = win_builder.build().unwrap();
|
||||
|
||||
// set background color only when building for macOS
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use cocoa::appkit::{NSColor, NSWindow};
|
||||
use cocoa::base::{id, nil};
|
||||
|
||||
let ns_window = window.ns_window().unwrap() as id;
|
||||
unsafe {
|
||||
let bg_color = NSColor::colorWithRed_green_blue_alpha_(
|
||||
nil,
|
||||
250.0 / 255.0,
|
||||
250.0 / 255.0,
|
||||
250.5 / 255.0,
|
||||
1.0,
|
||||
);
|
||||
ns_window.setBackgroundColor_(bg_color);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
6
frontend/src-tauri/src/main.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
haystack_lib::run()
|
||||
}
|
||||
30
frontend/src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "haystack",
|
||||
"version": "0.1.0",
|
||||
"identifier": "com.haystack.app",
|
||||
"build": {
|
||||
"beforeDevCommand": "bun run dev",
|
||||
"devUrl": "http://localhost:1420",
|
||||
"beforeBuildCommand": "bun run build",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"windows": [],
|
||||
"macOSPrivateApi": true,
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||