mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-24 07:19:23 +01:00
Compare commits
3 Commits
steve/fix/
...
abled-1215
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06da6c941e | ||
|
|
26386ec295 | ||
|
|
cc72c59894 |
@@ -7,19 +7,7 @@ title: "Release Notes"
|
||||
|
||||
Information about release notes of Coco App is provided here.
|
||||
|
||||
## Latest (In development)
|
||||
|
||||
### ❌ Breaking changes
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
### 🐛 Bug fix
|
||||
|
||||
### ✈️ Improvements
|
||||
|
||||
- refactor: add a timeout to open() #1025
|
||||
|
||||
## 0.10.0 (2025-12-19)
|
||||
## Latest (In development)
|
||||
|
||||
### ❌ Breaking changes
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "coco",
|
||||
"private": true,
|
||||
"version": "0.10.0",
|
||||
"version": "0.9.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
@@ -1132,7 +1132,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "coco"
|
||||
version = "0.10.0"
|
||||
version = "0.9.1"
|
||||
dependencies = [
|
||||
"actix-files",
|
||||
"actix-web",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "coco"
|
||||
version = "0.10.0"
|
||||
version = "0.9.1"
|
||||
description = "Search, connect, collaborate – all in one place."
|
||||
authors = ["INFINI Labs"]
|
||||
edition = "2024"
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
<string>Coco AI needs access to your microphone for voice input and audio recording features.</string>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>Coco AI requires camera access for scanning documents and capturing images.</string>
|
||||
<key>NSCameraUseContinuityCameraDeviceType</key>
|
||||
<true/>
|
||||
<key>NSSpeechRecognitionUsageDescription</key>
|
||||
<string>Coco AI uses speech recognition to convert your voice into text for a hands-free experience.</string>
|
||||
<key>NSAppleEventsUsageDescription</key>
|
||||
@@ -43,4 +45,4 @@
|
||||
<key>NSAccessibility</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
</plist>
|
||||
|
||||
@@ -148,171 +148,152 @@ pub(crate) async fn open(
|
||||
extra_args: Option<HashMap<String, Json>>,
|
||||
) -> Result<(), String> {
|
||||
use crate::util::open as homemade_tauri_shell_open;
|
||||
use tokio::process::Command;
|
||||
use tokio::time::Duration;
|
||||
use tokio::time::timeout;
|
||||
use std::process::Command;
|
||||
|
||||
let on_opened_clone = on_opened.clone();
|
||||
// Put the main logic in an async closure so that we can `time::timeout()`
|
||||
// it
|
||||
let async_closure = async move {
|
||||
match on_opened_clone {
|
||||
OnOpened::Application { app_path } => {
|
||||
log::debug!("open application [{}]", app_path);
|
||||
match on_opened {
|
||||
OnOpened::Application { app_path } => {
|
||||
log::debug!("open application [{}]", app_path);
|
||||
|
||||
homemade_tauri_shell_open(tauri_app_handle.clone(), app_path).await?
|
||||
}
|
||||
OnOpened::Document { url } => {
|
||||
log::debug!("open document [{}]", url);
|
||||
homemade_tauri_shell_open(tauri_app_handle.clone(), app_path).await?
|
||||
}
|
||||
OnOpened::Document { url } => {
|
||||
log::debug!("open document [{}]", url);
|
||||
|
||||
homemade_tauri_shell_open(tauri_app_handle.clone(), url).await?
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
OnOpened::WindowManagementAction { action } => {
|
||||
log::debug!("perform Window Management action [{:?}]", action);
|
||||
homemade_tauri_shell_open(tauri_app_handle.clone(), url).await?
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
OnOpened::WindowManagementAction { action } => {
|
||||
log::debug!("perform Window Management action [{:?}]", action);
|
||||
|
||||
crate::extension::built_in::window_management::perform_action_on_main_thread(
|
||||
&tauri_app_handle,
|
||||
action,
|
||||
)?;
|
||||
}
|
||||
OnOpened::Extension(ext_on_opened) => {
|
||||
// Apply the settings that would affect open behavior
|
||||
if let Some(settings) = ext_on_opened.settings {
|
||||
if let Some(should_hide) = settings.hide_before_open {
|
||||
if should_hide {
|
||||
crate::hide_coco(tauri_app_handle.clone()).await;
|
||||
}
|
||||
crate::extension::built_in::window_management::perform_action_on_main_thread(
|
||||
&tauri_app_handle,
|
||||
action,
|
||||
)?;
|
||||
}
|
||||
OnOpened::Extension(ext_on_opened) => {
|
||||
// Apply the settings that would affect open behavior
|
||||
if let Some(settings) = ext_on_opened.settings {
|
||||
if let Some(should_hide) = settings.hide_before_open {
|
||||
if should_hide {
|
||||
crate::hide_coco(tauri_app_handle.clone()).await;
|
||||
}
|
||||
}
|
||||
let permission = ext_on_opened.permission;
|
||||
}
|
||||
let permission = ext_on_opened.permission;
|
||||
|
||||
match ext_on_opened.ty {
|
||||
ExtensionOnOpenedType::Command { action } => {
|
||||
log::debug!("open (execute) command [{:?}]", action);
|
||||
match ext_on_opened.ty {
|
||||
ExtensionOnOpenedType::Command { action } => {
|
||||
log::debug!("open (execute) command [{:?}]", action);
|
||||
|
||||
let mut cmd = Command::new(action.exec);
|
||||
if let Some(args) = action.args {
|
||||
cmd.args(args);
|
||||
}
|
||||
let output = cmd.output().await.map_err(|e| e.to_string())?;
|
||||
// Sometimes, we wanna see the result in logs even though it doesn't fail.
|
||||
log::debug!(
|
||||
"executing open(Command) result, exit code: [{}], stdout: [{}], stderr: [{}]",
|
||||
let mut cmd = Command::new(action.exec);
|
||||
if let Some(args) = action.args {
|
||||
cmd.args(args);
|
||||
}
|
||||
let output = cmd.output().map_err(|e| e.to_string())?;
|
||||
// Sometimes, we wanna see the result in logs even though it doesn't fail.
|
||||
log::debug!(
|
||||
"executing open(Command) result, exit code: [{}], stdout: [{}], stderr: [{}]",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
if !output.status.success() {
|
||||
log::warn!(
|
||||
"executing open(Command) failed, exit code: [{}], stdout: [{}], stderr: [{}]",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
if !output.status.success() {
|
||||
log::warn!(
|
||||
"executing open(Command) failed, exit code: [{}], stdout: [{}], stderr: [{}]",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
|
||||
return Err(format!(
|
||||
"Command failed, stderr [{}]",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
return Err(format!(
|
||||
"Command failed, stderr [{}]",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
ExtensionOnOpenedType::Quicklink {
|
||||
link,
|
||||
open_with: opt_open_with,
|
||||
} => {
|
||||
let url = link.concatenate_url(&extra_args);
|
||||
}
|
||||
ExtensionOnOpenedType::Quicklink {
|
||||
link,
|
||||
open_with: opt_open_with,
|
||||
} => {
|
||||
let url = link.concatenate_url(&extra_args);
|
||||
|
||||
log::debug!("open quicklink [{}] with [{:?}]", url, opt_open_with);
|
||||
log::debug!("open quicklink [{}] with [{:?}]", url, opt_open_with);
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
// The `open_with` functionality is only supported on macOS, provided
|
||||
// by the `open -a` command.
|
||||
if #[cfg(target_os = "macos")] {
|
||||
let mut cmd = Command::new("open");
|
||||
if let Some(ref open_with) = opt_open_with {
|
||||
cmd.arg("-a");
|
||||
cmd.arg(open_with.as_str());
|
||||
}
|
||||
cmd.arg(&url);
|
||||
|
||||
let output = cmd.output().await.map_err(|e| format!("failed to spawn [open] due to error [{}]", e))?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(format!(
|
||||
"failed to open with app {:?}: {}",
|
||||
opt_open_with,
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
} else {
|
||||
homemade_tauri_shell_open(tauri_app_handle.clone(), url).await?
|
||||
cfg_if::cfg_if! {
|
||||
// The `open_with` functionality is only supported on macOS, provided
|
||||
// by the `open -a` command.
|
||||
if #[cfg(target_os = "macos")] {
|
||||
let mut cmd = Command::new("open");
|
||||
if let Some(ref open_with) = opt_open_with {
|
||||
cmd.arg("-a");
|
||||
cmd.arg(open_with.as_str());
|
||||
}
|
||||
cmd.arg(&url);
|
||||
|
||||
let output = cmd.output().map_err(|e| format!("failed to spawn [open] due to error [{}]", e))?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(format!(
|
||||
"failed to open with app {:?}: {}",
|
||||
opt_open_with,
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
));
|
||||
}
|
||||
} else {
|
||||
homemade_tauri_shell_open(tauri_app_handle.clone(), url).await?
|
||||
}
|
||||
}
|
||||
ExtensionOnOpenedType::View {
|
||||
name,
|
||||
icon,
|
||||
page,
|
||||
ui,
|
||||
} => {
|
||||
let page_path = Utf8Path::new(&page);
|
||||
let directory = page_path.parent().unwrap_or_else(|| {
|
||||
panic!("View extension page path should have a parent, i.e., it should be under a directory, but [{}] does not", page);
|
||||
});
|
||||
let mut url = serve_files_in(directory.as_ref()).await;
|
||||
}
|
||||
ExtensionOnOpenedType::View {
|
||||
name,
|
||||
icon,
|
||||
page,
|
||||
ui,
|
||||
} => {
|
||||
let page_path = Utf8Path::new(&page);
|
||||
let directory = page_path.parent().unwrap_or_else(|| {
|
||||
panic!("View extension page path should have a parent, i.e., it should be under a directory, but [{}] does not", page);
|
||||
});
|
||||
let mut url = serve_files_in(directory.as_ref()).await;
|
||||
|
||||
/*
|
||||
* Emit an event to let the frontend code open this extension.
|
||||
*
|
||||
* Payload `view_extension_opened` contains the information needed
|
||||
* to do that.
|
||||
*
|
||||
* See "src/pages/main/index.tsx" for more info.
|
||||
*/
|
||||
use camino::Utf8Path;
|
||||
use serde_json::Value as Json;
|
||||
use serde_json::to_value;
|
||||
/*
|
||||
* Emit an event to let the frontend code open this extension.
|
||||
*
|
||||
* Payload `view_extension_opened` contains the information needed
|
||||
* to do that.
|
||||
*
|
||||
* See "src/pages/main/index.tsx" for more info.
|
||||
*/
|
||||
use camino::Utf8Path;
|
||||
use serde_json::Value as Json;
|
||||
use serde_json::to_value;
|
||||
|
||||
let html_filename = page_path
|
||||
.file_name()
|
||||
.unwrap_or_else(|| {
|
||||
panic!("View extension page path should have a file name, but [{}] does not have one", page);
|
||||
}).to_string();
|
||||
url.push('/');
|
||||
url.push_str(&html_filename);
|
||||
let html_filename = page_path
|
||||
.file_name()
|
||||
.unwrap_or_else(|| {
|
||||
panic!("View extension page path should have a file name, but [{}] does not have one", page);
|
||||
}).to_string();
|
||||
url.push('/');
|
||||
url.push_str(&html_filename);
|
||||
|
||||
let html_file_url = url;
|
||||
debug!("View extension listening on: {}", html_file_url);
|
||||
let view_extension_opened: [Json; 5] = [
|
||||
Json::String(name),
|
||||
Json::String(icon),
|
||||
Json::String(html_file_url),
|
||||
to_value(permission).unwrap(),
|
||||
to_value(ui).unwrap(),
|
||||
];
|
||||
tauri_app_handle
|
||||
.emit("open_view_extension", view_extension_opened)
|
||||
.unwrap();
|
||||
}
|
||||
let html_file_url = url;
|
||||
debug!("View extension listening on: {}", html_file_url);
|
||||
let view_extension_opened: [Json; 5] = [
|
||||
Json::String(name),
|
||||
Json::String(icon),
|
||||
Json::String(html_file_url),
|
||||
to_value(permission).unwrap(),
|
||||
to_value(ui).unwrap(),
|
||||
];
|
||||
tauri_app_handle
|
||||
.emit("open_view_extension", view_extension_opened)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
};
|
||||
|
||||
match timeout(Duration::from_millis(500), async_closure).await {
|
||||
Ok(res) => res,
|
||||
Err(_timed_out) => {
|
||||
log::warn!("executing open(on_opened: [{:?}]) timed out", on_opened);
|
||||
|
||||
Err(format!(
|
||||
"executing open(on_opened: {:?}) timed out",
|
||||
on_opened
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
|
||||
@@ -14,8 +14,8 @@ use once_cell::sync::Lazy;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
/// Global toggle: selection monitoring disabled for this release.
|
||||
static SELECTION_ENABLED: AtomicBool = AtomicBool::new(false);
|
||||
/// Global toggle: selection monitoring enabled by default.
|
||||
static SELECTION_ENABLED: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
/// Ensure we only start the monitor thread once. Allows delayed start after
|
||||
/// Accessibility permission is granted post-launch.
|
||||
@@ -281,12 +281,19 @@ pub fn start_selection_monitor(app_handle: tauri::AppHandle) {
|
||||
let mut stable_text = String::new();
|
||||
let mut stable_count = 0;
|
||||
let mut empty_count = 0;
|
||||
let mut loop_idx: u64 = 0;
|
||||
|
||||
loop {
|
||||
loop_idx = loop_idx.wrapping_add(1);
|
||||
let verbose = loop_idx % 50 == 0; // Log roughly every 1.5s (30ms * 50)
|
||||
|
||||
std::thread::sleep(Duration::from_millis(30));
|
||||
|
||||
// If disabled: do not read AX / do not show popup; hide if currently visible.
|
||||
if !is_selection_enabled() {
|
||||
if verbose {
|
||||
println!("[SelectionMonitor] Disabled");
|
||||
}
|
||||
if popup_visible {
|
||||
let _ = app_handle.emit("selection-detected", "");
|
||||
popup_visible = false;
|
||||
@@ -301,6 +308,13 @@ pub fn start_selection_monitor(app_handle: tauri::AppHandle) {
|
||||
// system-wide focused element belongs to this process.
|
||||
let front_is_me = is_frontmost_app_me() || is_focused_element_me();
|
||||
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Loop heartbeat. front_is_me={}",
|
||||
front_is_me
|
||||
);
|
||||
}
|
||||
|
||||
// When Coco is frontmost, disable detection but do NOT hide the popup.
|
||||
// Users may be clicking the popup; we must keep it visible.
|
||||
if front_is_me {
|
||||
@@ -313,9 +327,16 @@ pub fn start_selection_monitor(app_handle: tauri::AppHandle) {
|
||||
// Lightweight retries to smooth out transient AX focus instability.
|
||||
let selected_text = {
|
||||
// Up to 2 retries, 35ms apart.
|
||||
read_selected_text_with_retries(2, 35)
|
||||
read_selected_text_with_retries(2, 35, verbose)
|
||||
};
|
||||
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] read_selected_text result: {:?}",
|
||||
selected_text
|
||||
);
|
||||
}
|
||||
|
||||
match selected_text {
|
||||
Some(text) if !text.is_empty() => {
|
||||
empty_count = 0;
|
||||
@@ -425,6 +446,7 @@ fn ensure_accessibility_permission(app_handle: &tauri::AppHandle) -> bool {
|
||||
}
|
||||
|
||||
// Still not trusted — notify frontend and deep-link to settings.
|
||||
println!("[SelectionMonitor] Accessibility permission NOT granted. Opening System Settings...");
|
||||
let _ = app_handle.emit("selection-permission-required", true);
|
||||
log::debug!(target: "coco_lib::selection_monitor", "selection-permission-required emitted");
|
||||
|
||||
@@ -563,12 +585,16 @@ fn is_focused_element_me() -> bool {
|
||||
/// Read the selected text of the frontmost application (without using the clipboard).
|
||||
/// macOS only. Returns `None` when the frontmost app is Coco to avoid false empties.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn read_selected_text() -> Option<String> {
|
||||
fn read_selected_text(verbose: bool) -> Option<String> {
|
||||
use objc2_app_kit::NSWorkspace;
|
||||
use objc2_application_services::{AXError, AXUIElement};
|
||||
use objc2_core_foundation::{CFRetained, CFString, CFType};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
if verbose {
|
||||
println!("[SelectionMonitor] read_selected_text: Attempting to read...");
|
||||
}
|
||||
|
||||
// Prefer system-wide focused element; if unavailable, fall back to app/window focused element.
|
||||
let mut focused_ui_ptr: *const CFType = std::ptr::null();
|
||||
let focused_attr = CFString::from_static_str("AXFocusedUIElement");
|
||||
@@ -583,12 +609,23 @@ fn read_selected_text() -> Option<String> {
|
||||
.copy_attribute_value(&focused_attr, NonNull::new(&mut focused_ui_ptr).unwrap())
|
||||
};
|
||||
if err != AXError::Success {
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Failed to get AXFocusedUIElement from system wide element: {:?}",
|
||||
err
|
||||
);
|
||||
}
|
||||
focused_ui_ptr = std::ptr::null();
|
||||
}
|
||||
} else if verbose {
|
||||
println!("[SelectionMonitor] AXUIElementCreateSystemWide returned null");
|
||||
}
|
||||
|
||||
// Fallback to the frontmost app's focused/window element.
|
||||
if focused_ui_ptr.is_null() {
|
||||
if verbose {
|
||||
println!("[SelectionMonitor] System-wide focus not found, trying frontmost app...");
|
||||
}
|
||||
let workspace = unsafe { NSWorkspace::sharedWorkspace() };
|
||||
let frontmost_app = unsafe { workspace.frontmostApplication() }?;
|
||||
let pid = unsafe { frontmost_app.processIdentifier() };
|
||||
@@ -596,6 +633,9 @@ fn read_selected_text() -> Option<String> {
|
||||
// Skip if frontmost is Coco (this process).
|
||||
let my_pid = std::process::id() as i32;
|
||||
if pid == my_pid {
|
||||
if verbose {
|
||||
println!("[SelectionMonitor] Frontmost app is Coco, skipping.");
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -605,6 +645,12 @@ fn read_selected_text() -> Option<String> {
|
||||
.copy_attribute_value(&focused_attr, NonNull::new(&mut focused_ui_ptr).unwrap())
|
||||
};
|
||||
if err != AXError::Success || focused_ui_ptr.is_null() {
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Failed to get AXFocusedUIElement from app (pid={}), trying AXFocusedWindow...",
|
||||
pid
|
||||
);
|
||||
}
|
||||
// Try `AXFocusedWindow` as a lightweight fallback.
|
||||
let mut focused_window_ptr: *const CFType = std::ptr::null();
|
||||
let focused_window_attr = CFString::from_static_str("AXFocusedWindow");
|
||||
@@ -615,9 +661,41 @@ fn read_selected_text() -> Option<String> {
|
||||
)
|
||||
};
|
||||
if w_err != AXError::Success || focused_window_ptr.is_null() {
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Failed to get AXFocusedWindow from app (pid={})",
|
||||
pid
|
||||
);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
focused_ui_ptr = focused_window_ptr;
|
||||
let focused_window_elem: CFRetained<AXUIElement> = unsafe {
|
||||
CFRetained::from_raw(
|
||||
NonNull::new(focused_window_ptr.cast::<AXUIElement>().cast_mut()).unwrap(),
|
||||
)
|
||||
};
|
||||
let mut inner_focused_ptr: *const CFType = std::ptr::null();
|
||||
let w_focused_err = unsafe {
|
||||
focused_window_elem.copy_attribute_value(
|
||||
&focused_attr,
|
||||
NonNull::new(&mut inner_focused_ptr).unwrap(),
|
||||
)
|
||||
};
|
||||
if w_focused_err == AXError::Success && !inner_focused_ptr.is_null() {
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Resolved AXFocusedUIElement via AXFocusedWindow (pid={})",
|
||||
pid
|
||||
);
|
||||
}
|
||||
focused_ui_ptr = inner_focused_ptr;
|
||||
} else if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Failed to get AXFocusedUIElement from focused window (pid={}), err={:?}",
|
||||
pid, w_focused_err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,6 +713,12 @@ fn read_selected_text() -> Option<String> {
|
||||
)
|
||||
};
|
||||
if err != AXError::Success || selected_text_ptr.is_null() {
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Failed to get AXSelectedText (err={:?})",
|
||||
err
|
||||
);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -643,27 +727,40 @@ fn read_selected_text() -> Option<String> {
|
||||
CFRetained::from_raw(NonNull::new(selected_text_ptr.cast::<CFString>().cast_mut()).unwrap())
|
||||
};
|
||||
|
||||
Some(selected_cfstr.to_string())
|
||||
let s = selected_cfstr.to_string();
|
||||
if verbose {
|
||||
println!("[SelectionMonitor] Success! Found text length: {}", s.len());
|
||||
}
|
||||
Some(s)
|
||||
}
|
||||
|
||||
/// Read selected text with lightweight retries to handle transient AX focus instability.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn read_selected_text_with_retries(retries: u32, delay_ms: u64) -> Option<String> {
|
||||
fn read_selected_text_with_retries(retries: u32, delay_ms: u64, verbose: bool) -> Option<String> {
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
for attempt in 0..=retries {
|
||||
if let Some(text) = read_selected_text() {
|
||||
if let Some(text) = read_selected_text(verbose) {
|
||||
if !text.is_empty() {
|
||||
if attempt > 0 {
|
||||
// log::info!(
|
||||
// "read_selected_text: 第{}次重试成功,获取到选中文本",
|
||||
// attempt
|
||||
// );
|
||||
log::info!(
|
||||
"read_selected_text: 第{}次重试成功,获取到选中文本",
|
||||
attempt
|
||||
);
|
||||
if verbose {
|
||||
println!("[SelectionMonitor] Retry success on attempt {}", attempt);
|
||||
}
|
||||
}
|
||||
return Some(text);
|
||||
}
|
||||
}
|
||||
if attempt < retries {
|
||||
if verbose {
|
||||
println!(
|
||||
"[SelectionMonitor] Attempt {} failed/empty, retrying...",
|
||||
attempt
|
||||
);
|
||||
}
|
||||
thread::sleep(Duration::from_millis(delay_ms));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ export function Connect({ setIsConnect, onAddServer }: ConnectServiceProps) {
|
||||
type="text"
|
||||
id="endpoint"
|
||||
value={endpointLink}
|
||||
autoCorrect="off"
|
||||
placeholder={t("cloud.connect.serverPlaceholder")}
|
||||
onChange={onChangeEndpoint}
|
||||
className="text-[#101010] dark:text-white flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-800"
|
||||
|
||||
@@ -243,7 +243,7 @@ const ExtensionDetail: FC<ExtensionDetailProps> = (props) => {
|
||||
}}
|
||||
deleteButtonProps={{
|
||||
className:
|
||||
"text-white bg-[#FF4949] hover:bg-[#FF4949] border-[#E6E6E6] dark:border-white/10",
|
||||
"!text-[#FF4949] bg-[#F8F9FA] dark:text-white dark:bg-[#202126] border-[#E6E6E6] dark:border-white/10",
|
||||
}}
|
||||
setIsOpen={setIsOpen}
|
||||
onCancel={handleCancel}
|
||||
|
||||
@@ -21,8 +21,8 @@ import SettingsInput from "@/components//Settings/SettingsInput";
|
||||
import platformAdapter from "@/utils/platformAdapter";
|
||||
import UpdateSettings from "./components/UpdateSettings";
|
||||
import SettingsToggle from "../SettingsToggle";
|
||||
// import SelectionSettings from "./components/Selection";
|
||||
// import { isMac } from "@/utils/platform";
|
||||
import SelectionSettings from "./components/Selection";
|
||||
import { isMac } from "@/utils/platform";
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
@@ -196,7 +196,7 @@ const Advanced = () => {
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* {isMac && <SelectionSettings />} */}
|
||||
{isMac && <SelectionSettings />}
|
||||
|
||||
<Shortcuts />
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export const useTray = () => {
|
||||
const showCocoShortcuts = useAppStore((state) => state.showCocoShortcuts);
|
||||
|
||||
const selectionEnabled = useSelectionStore((state) => state.selectionEnabled);
|
||||
// const setSelectionEnabled = useSelectionStore((state) => state.setSelectionEnabled);
|
||||
const setSelectionEnabled = useSelectionStore((state) => state.setSelectionEnabled);
|
||||
|
||||
useUpdateEffect(() => {
|
||||
if (showCocoShortcuts.length === 0) return;
|
||||
@@ -65,18 +65,18 @@ export const useTray = () => {
|
||||
|
||||
itemPromises.push(PredefinedMenuItem.new({ item: "Separator" }));
|
||||
|
||||
// if (isMac) {
|
||||
// itemPromises.push(
|
||||
// MenuItem.new({
|
||||
// text: selectionEnabled
|
||||
// ? t("tray.selectionDisable")
|
||||
// : t("tray.selectionEnable"),
|
||||
// action: async () => {
|
||||
// setSelectionEnabled(!selectionEnabled);
|
||||
// },
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
if (isMac) {
|
||||
itemPromises.push(
|
||||
MenuItem.new({
|
||||
text: selectionEnabled
|
||||
? t("tray.selectionDisable")
|
||||
: t("tray.selectionEnable"),
|
||||
action: async () => {
|
||||
setSelectionEnabled(!selectionEnabled);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
itemPromises.push(
|
||||
MenuItem.new({
|
||||
|
||||
@@ -18,7 +18,7 @@ import { useExtensionsStore } from "@/stores/extensionsStore";
|
||||
import { useSelectionStore, startSelectionStorePersistence } from "@/stores/selectionStore";
|
||||
import { useServers } from "@/hooks/useServers";
|
||||
import { useDeepLinkManager } from "@/hooks/useDeepLinkManager";
|
||||
// import { useSelectionWindow } from "@/hooks/useSelectionWindow";
|
||||
import { useSelectionWindow } from "@/hooks/useSelectionWindow";
|
||||
|
||||
export default function LayoutOutlet() {
|
||||
const location = useLocation();
|
||||
@@ -128,7 +128,7 @@ export default function LayoutOutlet() {
|
||||
});
|
||||
|
||||
// --- Selection window ---
|
||||
// useSelectionWindow();
|
||||
useSelectionWindow();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -33,7 +33,7 @@ export const useSelectionStore = create<SelectionStore>((set) => ({
|
||||
setIconsOnly: (iconsOnly) => set({ iconsOnly }),
|
||||
toolbarConfig: [],
|
||||
setToolbarConfig: (toolbarConfig) => set({ toolbarConfig }),
|
||||
selectionEnabled: false,
|
||||
selectionEnabled: true,
|
||||
setSelectionEnabled: (selectionEnabled) => set({ selectionEnabled }),
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user