Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src-tauri/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Default for AppConfig {
let home_dir = std::env::var("HOME").unwrap_or_default();
Self {
default_save_location: format!("{}/Desktop", home_dir),
capture_hotkey: "CommandOrControl+Shift+2".to_string(),
capture_hotkey: "CommandOrControl+Shift+S".to_string(),
preferences_hotkey: "CommandOrControl+Comma".to_string(),
auto_copy_after_capture: true,
auto_copy_after_edit: false,
Expand All @@ -28,6 +28,7 @@ impl Default for AppConfig {
impl AppConfig {
pub fn load() -> Result<Self, Box<dyn std::error::Error>> {
let config_path = Self::get_config_path()?;
println!("config path: {}", config_path.to_string_lossy());

if config_path.exists() {
let contents = std::fs::read_to_string(&config_path)?;
Expand Down
49 changes: 6 additions & 43 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::PathBuf;
use std::sync::Mutex;
use std::collections::HashMap;
use base64::prelude::*;
use image::GenericImageView;


#[cfg(target_os = "macos")]
use cocoa::appkit::NSEvent;
Expand Down Expand Up @@ -488,40 +488,7 @@ async fn update_config(
Ok(())
}

#[tauri::command]
async fn open_preferences_window(app_handle: AppHandle) -> Result<(), String> {
if app_handle.get_webview_window("preferences").is_some() {
return Ok(());
}

let _preferences_window = WebviewWindowBuilder::new(
&app_handle,
"preferences",
WebviewUrl::App("preferences.html".into())
)
.title("Snipp Preferences")
.inner_size(480.0, 400.0)
.resizable(false)
.center()
.build()
.map_err(|e| format!("Failed to create preferences window: {}", e))?;

Ok(())
}

#[tauri::command]
async fn open_preferences(app_handle: AppHandle) -> Result<(), String> {
open_preferences_window(app_handle).await
}

#[tauri::command]
async fn close_preferences_window(app_handle: AppHandle) -> Result<(), String> {
if let Some(preferences_window) = app_handle.get_webview_window("preferences") {
preferences_window.close()
.map_err(|e| format!("Failed to close preferences: {}", e))?;
}
Ok(())
}

#[tauri::command]
async fn hide_window(app_handle: AppHandle) -> Result<(), String> {
Expand Down Expand Up @@ -858,12 +825,11 @@ fn apply_global_shortcuts(app_handle: &AppHandle, config: &AppConfig) -> Result<
global_shortcut
.on_shortcut(preferences_hotkey.as_str(), move |app, _shortcut, event| {
if event.state() == ShortcutState::Pressed {
let app_handle = app.clone();
tauri::async_runtime::spawn(async move {
if let Err(e) = open_preferences_window(app_handle).await {
eprintln!("Failed to open preferences: {}", e);
}
});
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
let _ = window.center();
}
}
})
.map_err(|e| format!("Failed to register preferences hotkey: {}", e))?;
Expand Down Expand Up @@ -922,9 +888,6 @@ pub fn run() {
close_popup_window,
get_config,
update_config,
open_preferences_window,
open_preferences,
close_preferences_window,
choose_save_location,
get_recent_screenshots,
copy_screenshot_from_path,
Expand Down
37 changes: 11 additions & 26 deletions src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ pub fn create_tray_menu(
) -> Result<Menu<tauri::Wry>, Box<dyn std::error::Error>> {
let capture_area_hotkey = format_hotkey_for_menu(&config.capture_hotkey);
let capture_screen_hotkey = format_hotkey_for_menu(DEFAULT_FULLSCREEN_HOTKEY);
let preferences_hotkey = format_hotkey_for_menu(&config.preferences_hotkey);
let open_snipp = MenuItem::with_id(app, "open_snipp", "Open Snipp", true, None::<&str>)?;
let dashboard_hotkey = format_hotkey_for_menu(&config.preferences_hotkey);

let open_snipp = MenuItem::with_id(
app,
"open_snipp",
"Open Snipp",
true,
Some(dashboard_hotkey)
)?;
let separator1 = PredefinedMenuItem::separator(app)?;
let capture_screen = MenuItem::with_id(
app,
"capture_screen",
"Capture Screen",
"Capture Full Screen",
true,
Some(capture_screen_hotkey),
)?;
Expand All @@ -36,13 +43,6 @@ pub fn create_tray_menu(
let suggest_feature = MenuItem::with_id(app, "suggest_feature", "Suggest a Feature", true, None::<&str>)?;
let report_bug = MenuItem::with_id(app, "report_bug", "Report a Bug", true, None::<&str>)?;
let separator3 = PredefinedMenuItem::separator(app)?;
let preferences = MenuItem::with_id(
app,
"preferences",
"Preferences...",
true,
Some(preferences_hotkey),
)?;
let quit = PredefinedMenuItem::quit(app, Some("Quit Snipp"))?;

let menu = Menu::with_items(app, &[
Expand All @@ -54,7 +54,6 @@ pub fn create_tray_menu(
&suggest_feature,
&report_bug,
&separator3,
&preferences,
&quit,
])?;

Expand Down Expand Up @@ -112,11 +111,6 @@ pub fn setup_system_tray(app: &AppHandle) -> Result<(), Box<dyn std::error::Erro
eprintln!("Failed to open bug report URL: {}", e);
}
}
"preferences" => {
if let Err(e) = show_preferences_window(app) {
eprintln!("Failed to show preferences: {}", e);
}
}
_ => {}
}
})
Expand Down Expand Up @@ -207,13 +201,4 @@ fn open_url_with_app(app: &AppHandle, url: &str) -> Result<(), Box<dyn std::erro
}
}

fn show_preferences_window(app: &AppHandle) -> Result<(), Box<dyn std::error::Error>> {
let app_handle = app.clone();
tauri::async_runtime::spawn(async move {
match crate::open_preferences_window(app_handle).await {
Ok(_) => println!("Preferences window opened"),
Err(e) => eprintln!("Failed to open preferences: {}", e),
}
});
Ok(())
}

Loading