style: formatting

This commit is contained in:
ByteAtATime 2025-06-19 20:49:39 -07:00
parent 41c880f9d5
commit 00eb6d6e18
No known key found for this signature in database
6 changed files with 253 additions and 236 deletions

View file

@ -56,7 +56,8 @@ enum IncomingMessage {
pub struct WsState { pub struct WsState {
pub connection: Arc<Mutex<Option<tokio::sync::mpsc::Sender<String>>>>, pub connection: Arc<Mutex<Option<tokio::sync::mpsc::Sender<String>>>>,
pub is_connected: Arc<Mutex<bool>>, pub is_connected: Arc<Mutex<bool>>,
pub pending_requests: Arc<Mutex<HashMap<u64, oneshot::Sender<Result<serde_json::Value, String>>>>>, pub pending_requests:
Arc<Mutex<HashMap<u64, oneshot::Sender<Result<serde_json::Value, String>>>>>,
pub request_id_counter: Arc<Mutex<u64>>, pub request_id_counter: Arc<Mutex<u64>>,
} }
@ -90,7 +91,11 @@ async fn handle_connection(stream: TcpStream, app_handle: AppHandle) {
let sender_task = tokio::spawn(async move { let sender_task = tokio::spawn(async move {
while let Some(msg_to_send) = rx.recv().await { while let Some(msg_to_send) = rx.recv().await {
if ws_sender.send(Message::Binary(msg_to_send.into())).await.is_err() { if ws_sender
.send(Message::Binary(msg_to_send.into()))
.await
.is_err()
{
break; break;
} }
} }
@ -113,14 +118,24 @@ async fn handle_connection(stream: TcpStream, app_handle: AppHandle) {
"result": null, "result": null,
"id": id "id": id
}); });
let tx = app_clone_for_receiver.state::<WsState>().connection.lock().unwrap().clone(); let tx = app_clone_for_receiver
.state::<WsState>()
.connection
.lock()
.unwrap()
.clone();
if let Some(tx) = tx { if let Some(tx) = tx {
let _ = tx.send(response.to_string()).await; let _ = tx.send(response.to_string()).await;
} }
} }
} }
Ok(IncomingMessage::Response { id, result, error }) => { Ok(IncomingMessage::Response { id, result, error }) => {
let sender = app_clone_for_receiver.state::<WsState>().pending_requests.lock().unwrap().remove(&id); let sender = app_clone_for_receiver
.state::<WsState>()
.pending_requests
.lock()
.unwrap()
.remove(&id);
if let Some(sender) = sender { if let Some(sender) = sender {
if !error.is_null() { if !error.is_null() {
let _ = sender.send(Err(error.to_string())); let _ = sender.send(Err(error.to_string()));
@ -161,7 +176,9 @@ pub async fn run_server(app_handle: AppHandle) {
} }
#[tauri::command] #[tauri::command]
pub async fn browser_extension_check_connection(state: tauri::State<'_, WsState>) -> Result<bool, String> { pub async fn browser_extension_check_connection(
state: tauri::State<'_, WsState>,
) -> Result<bool, String> {
Ok(*state.is_connected.lock().unwrap()) Ok(*state.is_connected.lock().unwrap())
} }
@ -212,4 +229,3 @@ pub async fn browser_extension_request(
Err("Browser extension not connected".into()) Err("Browser extension not connected".into())
} }
} }

View file

@ -31,7 +31,7 @@ pub async fn clipboard_read_text(app: tauri::AppHandle) -> Result<ReadResult, St
Ok(ReadResult { Ok(ReadResult {
text, text,
html: None, html: None,
file: None file: None,
}) })
} }
@ -60,7 +60,7 @@ pub async fn clipboard_read(app: tauri::AppHandle) -> Result<ReadResult, String>
pub async fn clipboard_copy( pub async fn clipboard_copy(
app: tauri::AppHandle, app: tauri::AppHandle,
content: ClipboardContent, content: ClipboardContent,
_options: Option<CopyOptions> _options: Option<CopyOptions>,
) -> Result<(), String> { ) -> Result<(), String> {
let clipboard = app.clipboard(); let clipboard = app.clipboard();
@ -73,7 +73,9 @@ pub async fn clipboard_copy(
.write_html(html.clone(), content.text) .write_html(html.clone(), content.text)
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
} else if let Some(text) = &content.text { } else if let Some(text) = &content.text {
clipboard.write_text(text.clone()).map_err(|e| e.to_string())?; clipboard
.write_text(text.clone())
.map_err(|e| e.to_string())?;
} }
Ok(()) Ok(())
@ -82,7 +84,7 @@ pub async fn clipboard_copy(
#[tauri::command] #[tauri::command]
pub async fn clipboard_paste( pub async fn clipboard_paste(
app: tauri::AppHandle, app: tauri::AppHandle,
content: ClipboardContent content: ClipboardContent,
) -> Result<(), String> { ) -> Result<(), String> {
let clipboard = app.clipboard(); let clipboard = app.clipboard();
let original_text = clipboard.read_text().ok(); let original_text = clipboard.read_text().ok();

View file

@ -14,7 +14,7 @@ use selection::get_text;
use std::process::Command; use std::process::Command;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use tauri::{Manager, Emitter}; use tauri::{Emitter, Manager};
use tauri_plugin_deep_link::DeepLinkExt; use tauri_plugin_deep_link::DeepLinkExt;
#[tauri::command] #[tauri::command]
@ -66,7 +66,7 @@ fn setup_background_refresh() {
fn setup_global_shortcut(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> { fn setup_global_shortcut(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
use tauri_plugin_global_shortcut::{ use tauri_plugin_global_shortcut::{
Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState,
}; };
let spotlight_shortcut = Shortcut::new(Some(Modifiers::ALT), Code::Space); let spotlight_shortcut = Shortcut::new(Some(Modifiers::ALT), Code::Space);
@ -89,7 +89,7 @@ fn setup_global_shortcut(app: &mut tauri::App) -> Result<(), Box<dyn std::error:
} }
} }
}) })
.build() .build(),
)?; )?;
app.global_shortcut().register(spotlight_shortcut)?; app.global_shortcut().register(spotlight_shortcut)?;

View file

@ -56,8 +56,7 @@ pub fn oauth_set_tokens(
let path = get_storage_path(&app)?; let path = get_storage_path(&app)?;
let mut store = read_store(&path)?; let mut store = read_store(&path)?;
let token_set: StoredTokenSet = let token_set: StoredTokenSet = serde_json::from_value(tokens).map_err(|e| e.to_string())?;
serde_json::from_value(tokens).map_err(|e| e.to_string())?;
store.insert(provider_id, token_set); store.insert(provider_id, token_set);
write_store(&path, &store) write_store(&path, &store)