wip
This commit is contained in:
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"biome.enabled": true,
|
||||||
"editor.defaultFormatter": "biomejs.biome",
|
"editor.defaultFormatter": "biomejs.biome",
|
||||||
"[typescript]": {
|
"[typescript]": {
|
||||||
"editor.defaultFormatter": "biomejs.biome"
|
"editor.defaultFormatter": "biomejs.biome"
|
||||||
@ -6,5 +7,9 @@
|
|||||||
"[typescriptreact]": {
|
"[typescriptreact]": {
|
||||||
"editor.defaultFormatter": "biomejs.biome"
|
"editor.defaultFormatter": "biomejs.biome"
|
||||||
},
|
},
|
||||||
"editor.formatOnSave": true
|
"editor.formatOnSave": true,
|
||||||
|
"[rust]": {
|
||||||
|
"editor.defaultFormatter": "rust-lang.rust-analyzer"
|
||||||
|
},
|
||||||
|
"rust-analyzer.linkedProjects": ["./frontend/src-tauri/Cargo.toml"]
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
use std::path::PathBuf;
|
use base64::{engine::general_purpose::STANDARD as BASE64, Engine as _};
|
||||||
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
|
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
|
||||||
use tauri::Emitter;
|
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64};
|
use std::path::PathBuf;
|
||||||
use std::sync::Mutex;
|
use std::sync::mpsc::channel;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::Mutex;
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
|
use tauri::Emitter;
|
||||||
use tauri::{TitleBarStyle, WebviewUrl, WebviewWindowBuilder};
|
use tauri::{TitleBarStyle, WebviewUrl, WebviewWindowBuilder};
|
||||||
|
|
||||||
|
|
||||||
struct WatcherState {
|
struct WatcherState {
|
||||||
watcher: Option<RecommendedWatcher>,
|
watcher: Option<RecommendedWatcher>,
|
||||||
}
|
}
|
||||||
@ -25,8 +24,7 @@ fn process_png_file(path: &PathBuf, app: AppHandle) -> Result<(), String> {
|
|||||||
println!("Processing PNG file: {}", path.display());
|
println!("Processing PNG file: {}", path.display());
|
||||||
|
|
||||||
// Read the file
|
// Read the file
|
||||||
let contents = fs::read(path)
|
let contents = fs::read(path).map_err(|e| format!("Failed to read file: {}", e))?;
|
||||||
.map_err(|e| format!("Failed to read file: {}", e))?;
|
|
||||||
|
|
||||||
// Convert to base64
|
// Convert to base64
|
||||||
let base64_string = BASE64.encode(&contents);
|
let base64_string = BASE64.encode(&contents);
|
||||||
@ -53,20 +51,21 @@ async fn handle_selected_folder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop existing watcher if any
|
// Stop existing watcher if any
|
||||||
let mut state = state.lock().map_err(|_| "Failed to lock state".to_string())?;
|
let mut state = state
|
||||||
|
.lock()
|
||||||
|
.map_err(|_| "Failed to lock state".to_string())?;
|
||||||
state.watcher = None;
|
state.watcher = None;
|
||||||
|
|
||||||
// Create a channel to receive file system events
|
// Create a channel to receive file system events
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
// Create a new watcher
|
// Create a new watcher
|
||||||
let mut watcher = RecommendedWatcher::new(
|
let mut watcher = RecommendedWatcher::new(tx, Config::default())
|
||||||
tx,
|
.map_err(|e| format!("Failed to create watcher: {}", e))?;
|
||||||
Config::default(),
|
|
||||||
).map_err(|e| format!("Failed to create watcher: {}", e))?;
|
|
||||||
|
|
||||||
// Start watching the directory
|
// Start watching the directory
|
||||||
watcher.watch(path_buf.as_ref(), RecursiveMode::Recursive)
|
watcher
|
||||||
|
.watch(path_buf.as_ref(), RecursiveMode::Recursive)
|
||||||
.map_err(|e| format!("Failed to watch directory: {}", e))?;
|
.map_err(|e| format!("Failed to watch directory: {}", e))?;
|
||||||
|
|
||||||
// Store the watcher in state
|
// Store the watcher in state
|
||||||
@ -114,8 +113,7 @@ pub fn run() {
|
|||||||
.manage(watcher_state)
|
.manage(watcher_state)
|
||||||
.invoke_handler(tauri::generate_handler![handle_selected_folder])
|
.invoke_handler(tauri::generate_handler![handle_selected_folder])
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
let win_builder =
|
let win_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
|
||||||
WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
|
|
||||||
.hidden_title(true)
|
.hidden_title(true)
|
||||||
.inner_size(480.0, 360.0)
|
.inner_size(480.0, 360.0)
|
||||||
.resizable(false);
|
.resizable(false);
|
||||||
@ -128,24 +126,24 @@ pub fn run() {
|
|||||||
// set background color only when building for macOS
|
// set background color only when building for macOS
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
use cocoa::appkit::{NSColor, NSWindow};
|
use cocoa::appkit::{NSColor, NSWindow};
|
||||||
use cocoa::base::{id, nil};
|
use cocoa::base::{id, nil};
|
||||||
|
|
||||||
let ns_window = window.ns_window().unwrap() as id;
|
let ns_window = window.ns_window().unwrap() as id;
|
||||||
unsafe {
|
unsafe {
|
||||||
let bg_color = NSColor::colorWithRed_green_blue_alpha_(
|
let bg_color = NSColor::colorWithRed_green_blue_alpha_(
|
||||||
nil,
|
nil,
|
||||||
245.0 / 255.0,
|
245.0 / 255.0,
|
||||||
245.0 / 255.0,
|
245.0 / 255.0,
|
||||||
245.0 / 255.0,
|
245.0 / 255.0,
|
||||||
1.0,
|
1.0,
|
||||||
);
|
);
|
||||||
ns_window.setBackgroundColor_(bg_color);
|
ns_window.setBackgroundColor_(bg_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user