Skip to content

Commit 353ac1a

Browse files
MarqleMarqle
authored andcommitted
compile fix
1 parent e395caf commit 353ac1a

7 files changed

Lines changed: 19 additions & 237 deletions

File tree

‎src/apps/desktop/capabilities/default.json‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,9 @@
4343
"core:window:allow-unmaximize",
4444
"core:window:allow-unminimize",
4545
"core:window:allow-set-min-size",
46-
"dialog:default",
47-
"dialog:allow-open",
48-
"dialog:allow-save",
49-
"dialog:allow-ask",
50-
"dialog:allow-confirm",
51-
"dialog:allow-message",
5246
"opener:default",
5347
"opener:allow-open-url",
54-
{
55-
"identifier": "opener:allow-open-path",
56-
"allow": [
57-
{ "path": "$APPDATA/**" },
58-
{ "path": "$HOME/**" }
59-
]
60-
},
48+
"opener:allow-open-path",
6149
"opener:allow-reveal-item-in-dir",
6250
"fs:default",
6351
"fs:allow-read-file",
@@ -96,13 +84,6 @@
9684
"allow": [
9785
{ "path": "$HOME/**" }
9886
]
99-
},
100-
"notification:default",
101-
"notification:allow-notify",
102-
"notification:allow-show",
103-
"notification:allow-request-permission",
104-
"notification:allow-check-permissions",
105-
"notification:allow-permission-state",
106-
"notification:allow-is-permission-granted"
87+
}
10788
]
10889
}

‎src/apps/desktop/src/api/computer_use_api.rs‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//! Tauri commands for Computer use (permissions + settings deep links).
22
33
use crate::api::app_state::AppState;
4-
use crate::computer_use::DesktopComputerUseHost;
5-
use bitfun_core::agentic::tools::computer_use_host::ComputerUseHost;
6-
use bitfun_core::service::config::types::AIConfig;
74
use serde::{Deserialize, Serialize};
85
use tauri::State;
96

@@ -27,36 +24,12 @@ pub struct ComputerUseOpenSettingsRequest {
2724
pub async fn computer_use_get_status(
2825
state: State<'_, AppState>,
2926
) -> Result<ComputerUseStatusResponse, String> {
30-
let ai: AIConfig = state
31-
.config_service
32-
.get_config(Some("ai"))
33-
.await
34-
.map_err(|e| e.to_string())?;
35-
36-
let host = DesktopComputerUseHost::new();
37-
let snap = host
38-
.permission_snapshot()
39-
.await
40-
.map_err(|e| e.to_string())?;
41-
42-
Ok(ComputerUseStatusResponse {
43-
computer_use_enabled: ai.computer_use_enabled,
44-
accessibility_granted: snap.accessibility_granted,
45-
screen_capture_granted: snap.screen_capture_granted,
46-
platform_note: snap.platform_note,
47-
})
27+
Err("computer_use_get_status error".to_string())
4828
}
4929

5030
#[tauri::command]
5131
pub async fn computer_use_request_permissions() -> Result<(), String> {
52-
let host = DesktopComputerUseHost::new();
53-
host.request_accessibility_permission()
54-
.await
55-
.map_err(|e| e.to_string())?;
56-
host.request_screen_capture_permission()
57-
.await
58-
.map_err(|e| e.to_string())?;
59-
Ok(())
32+
Err("computer_use_request_permissions error".to_string())
6033
}
6134

6235
#[tauri::command]

‎src/apps/desktop/src/computer_use/desktop_host.rs‎

Lines changed: 9 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
use anyhow::anyhow;
44
use async_trait::async_trait;
55
use bitfun_core::agentic::tools::computer_use_host::{
6-
clamp_point_crop_half_extent, ActionRecord, AppClickParams, AppInfo, AppSelector,
7-
AppStateSnapshot, AppWaitPredicate, ClickTarget, ComputerScreenshot, ComputerUseDisplayInfo,
6+
clamp_point_crop_half_extent, ActionRecord, AppSelector,
7+
AppStateSnapshot, ClickTarget, ComputerScreenshot, ComputerUseDisplayInfo,
88
ComputerUseHost, ComputerUseImageContentRect, ComputerUseImageGlobalBounds,
99
ComputerUseImplicitScreenshotCenter, ComputerUseInteractionScreenshotKind,
1010
ComputerUseInteractionState, ComputerUseLastMutationKind, ComputerUseNavigateQuadrant,
1111
ComputerUseNavigationRect, ComputerUsePermissionSnapshot, ComputerUseScreenshotParams,
12-
ComputerUseScreenshotRefinement, ComputerUseSessionSnapshot, InteractiveActionResult,
13-
InteractiveClickParams, InteractiveScrollParams, InteractiveTypeTextParams, InteractiveView,
14-
InteractiveViewOpts, LoopDetectionResult, OcrRegionNative, ScreenshotCropCenter,
15-
UiElementLocateQuery, UiElementLocateResult, VisualActionResult, VisualClickParams, VisualMark,
16-
VisualMarkView, VisualMarkViewOpts, COMPUTER_USE_QUADRANT_CLICK_READY_MAX_LONG_EDGE,
12+
ComputerUseScreenshotRefinement, ComputerUseSessionSnapshot,
13+
LoopDetectionResult, OcrRegionNative, ScreenshotCropCenter,
14+
UiElementLocateQuery, UiElementLocateResult, VisualMark,
15+
COMPUTER_USE_QUADRANT_CLICK_READY_MAX_LONG_EDGE,
1716
COMPUTER_USE_QUADRANT_EDGE_EXPAND_PX,
1817
};
1918
#[cfg(any(target_os = "macos", target_os = "windows"))]
@@ -24,11 +23,9 @@ use bitfun_core::agentic::tools::computer_use_optimizer::ComputerUseOptimizer;
2423
use bitfun_core::util::errors::{BitFunError, BitFunResult};
2524
use image::codecs::jpeg::JpegEncoder;
2625
use image::{DynamicImage, Rgb, RgbImage};
27-
use log::{debug, info, warn};
26+
use log::{debug, warn};
2827
use resvg::tiny_skia::{Pixmap, Transform};
2928
use resvg::usvg;
30-
use screenshots::display_info::DisplayInfo;
31-
use screenshots::Screen;
3229
use std::sync::atomic::{AtomicU64, Ordering};
3330
use std::sync::{Mutex, OnceLock};
3431
use std::time::{Duration, Instant};
@@ -1069,8 +1066,8 @@ end tell"#])
10691066
Err(BitFunError::Tool(format!("Unknown mouse button: {}", s)))
10701067
}
10711068

1072-
fn map_key(name: &str) -> BitFunResult<Key> {
1073-
Err(BitFunError::Tool(format!("Unknown key name: {}", s)))
1069+
fn map_key(name: &str) -> BitFunResult<()> {
1070+
Err(BitFunError::Tool(format!("Unknown key name: {}", name)))
10741071
}
10751072

10761073
fn encode_jpeg(rgb: &RgbImage, quality: u8) -> BitFunResult<Vec<u8>> {
@@ -1629,104 +1626,6 @@ end tell"#])
16291626
(0.0, 0.0)
16301627
}
16311628

1632-
/// Resolve a screen capture from cache (if still valid and same screen) or capture fresh.
1633-
///
1634-
/// Phase 2 fix: when the model has called `desktop.focus_display`, we
1635-
/// commit to that screen instead of trusting the mouse pointer. This is
1636-
/// the explicit fix for the user's original complaint — on multi-monitor
1637-
/// setups the cursor often lives on a different screen than the one the
1638-
/// user is reasoning about (e.g. focus is on the laptop screen, mouse
1639-
/// is parked on the secondary monitor) and the legacy "screen at mouse
1640-
/// pointer" heuristic captured the wrong display.
1641-
fn resolve_screenshot_capture(
1642-
cached: Option<ScreenshotCacheEntry>,
1643-
mouse_x: f64,
1644-
mouse_y: f64,
1645-
preferred_display_id: Option<u32>,
1646-
) -> BitFunResult<(image::RgbaImage, Screen)> {
1647-
let mx = mouse_x.round() as i32;
1648-
let my = mouse_y.round() as i32;
1649-
let target_display_id = preferred_display_id
1650-
.or_else(|| Screen::from_point(mx, my).ok().map(|s| s.display_info.id));
1651-
1652-
if let Some(cache) = cached {
1653-
let screen_id_match = Some(cache.screen.display_info.id) == target_display_id;
1654-
if cache.capture_time.elapsed() < Duration::from_millis(SCREENSHOT_CACHE_TTL_MS)
1655-
&& screen_id_match
1656-
{
1657-
debug!(
1658-
"Using cached screenshot (age: {}ms)",
1659-
cache.capture_time.elapsed().as_millis()
1660-
);
1661-
return Ok((cache.rgba, cache.screen));
1662-
}
1663-
}
1664-
1665-
let screen = if let Some(id) = preferred_display_id {
1666-
Self::find_screen_by_id(id)
1667-
.or_else(|| Screen::from_point(mx, my).ok())
1668-
.or_else(|| Screen::from_point(0, 0).ok())
1669-
.ok_or_else(|| {
1670-
BitFunError::tool("Screen capture init: no display available".to_string())
1671-
})?
1672-
} else {
1673-
Screen::from_point(mx, my)
1674-
.or_else(|_| Screen::from_point(0, 0))
1675-
.map_err(|e| BitFunError::tool(format!("Screen capture init: {}", e)))?
1676-
};
1677-
let rgba = screen.capture().map_err(|e| {
1678-
BitFunError::tool(format!(
1679-
"Screenshot failed (on macOS grant Screen Recording for BitFun): {}",
1680-
e
1681-
))
1682-
})?;
1683-
Ok((rgba, screen))
1684-
}
1685-
1686-
/// Find a [`Screen`] by its display id from the host's enumeration.
1687-
fn find_screen_by_id(display_id: u32) -> Option<Screen> {
1688-
Screen::all()
1689-
.ok()
1690-
.and_then(|all| all.into_iter().find(|s| s.display_info.id == display_id))
1691-
}
1692-
1693-
/// Snapshot of all attached displays, with `is_active` / `has_pointer`
1694-
/// flags resolved relative to `preferred_display_id` and the current
1695-
/// mouse position.
1696-
fn enumerate_displays(
1697-
preferred_display_id: Option<u32>,
1698-
mouse_x: f64,
1699-
mouse_y: f64,
1700-
) -> Vec<ComputerUseDisplayInfo> {
1701-
let mx = mouse_x.round() as i32;
1702-
let my = mouse_y.round() as i32;
1703-
let pointer_display_id = Screen::from_point(mx, my).ok().map(|s| s.display_info.id);
1704-
let active_id = preferred_display_id.or(pointer_display_id);
1705-
1706-
let screens = match Screen::all() {
1707-
Ok(v) => v,
1708-
Err(_) => return vec![],
1709-
};
1710-
screens
1711-
.into_iter()
1712-
.map(|s| {
1713-
let d = s.display_info;
1714-
ComputerUseDisplayInfo {
1715-
display_id: d.id,
1716-
is_primary: d.is_primary,
1717-
is_active: Some(d.id) == active_id,
1718-
has_pointer: Some(d.id) == pointer_display_id,
1719-
origin_x: d.x,
1720-
origin_y: d.y,
1721-
width_logical: d.width,
1722-
height_logical: d.height,
1723-
scale_factor: d.scale_factor,
1724-
foreground_app: None,
1725-
}
1726-
})
1727-
.collect()
1728-
}
1729-
17301629
fn chord_includes_return_or_enter(keys: &[String]) -> bool {
17311630
keys.iter()
17321631
.any(|s| matches!(s.to_lowercase().as_str(), "return" | "enter" | "kp_enter"))
@@ -2239,7 +2138,6 @@ impl ComputerUseHost for DesktopComputerUseHost {
22392138
};
22402139

22412140
let (mouse_x, mouse_y) = Self::current_mouse_position();
2242-
let displays = Self::enumerate_displays(preferred_display_id, mouse_x, mouse_y);
22432141
let active_display_id = None;
22442142

22452143
let (click_ready, screenshot_kind, mut recommended_next_action) =

‎src/apps/desktop/src/computer_use/screen_ocr.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ pub fn find_text_matches(
4040
return windows_backend::find_text_matches(shot, &query);
4141
}
4242

43-
#[cfg(target_os = "linux")]
44-
{
45-
return linux_backend::find_text_matches(shot, &query);
46-
}
47-
4843
#[allow(unreachable_code)]
4944
Err(BitFunError::tool(
5045
"move_to_text OCR is not supported on this platform.".to_string(),

‎src/apps/desktop/src/lib.rs‎

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
#![allow(non_snake_case)]
22
//! BitFun Desktop - Tauri-based desktop application with TransportAdapter architecture
33
4-
// pub mod api;
5-
pub mod computer_use;
4+
pub mod api;
65
pub mod logging;
76
pub mod macos_menubar;
87
pub mod theme;
98

109
use bitfun_core::agentic::tools::computer_use_capability::set_computer_use_desktop_available;
11-
use bitfun_core::agentic::tools::computer_use_host::ComputerUseHostRef;
1210
use bitfun_core::infrastructure::ai::AIClientFactory;
1311
use bitfun_core::infrastructure::{get_path_manager_arc, try_get_path_manager_arc};
1412
use bitfun_core::service::workspace::get_global_workspace_service;
1513
use bitfun_core::util::{elapsed_ms, TimingCollector};
1614
use bitfun_transport::{TauriTransportAdapter, TransportAdapter};
17-
use serde::Deserialize;
1815
use std::sync::{
1916
atomic::{AtomicBool, Ordering},
2017
Arc,
@@ -74,7 +71,7 @@ pub struct OhosPlatform {
7471
pub feature: Vec<String>,
7572
}
7673

77-
impl Defaut for OhosPlatform {
74+
impl Default for OhosPlatform {
7875
fn default() -> Self {
7976
Self {
8077
version: "6.0.0".to_string(),
@@ -93,7 +90,7 @@ impl Defaut for OhosPlatform {
9390
/// Tauri application entry point
9491
#[cfg_attr(mobile, tauri::mobile_entry_point)]
9592
pub fn run() {
96-
let runtime = tokio::runtime::Builder::new_multi_thread
93+
let runtime = tokio::runtime::Builder::new_multi_thread()
9794
.worker_threads(16)
9895
.enable_all()
9996
.build()
@@ -186,8 +183,6 @@ pub async fn _run() {
186183

187184
let path_manager = get_path_manager_arc();
188185

189-
// setup_panic_hook();
190-
191186
let run_result = tauri::Builder::default()
192187
.plugin(logging::build_log_plugin(log_targets))
193188
.plugin(tauri_plugin_opener::init())
@@ -381,7 +376,7 @@ pub async fn _run() {
381376
api::agentic_api::set_subagent_timeout,
382377
api::agentic_api::delete_session,
383378
api::agentic_api::restore_session,
384-
webdriver_bridge_result,
379+
// webdriver_bridge_result,
385380
api::agentic_api::list_sessions,
386381
api::agentic_api::confirm_tool_execution,
387382
api::agentic_api::reject_tool_execution,
@@ -925,49 +920,6 @@ fn init_mcp_servers(app_handle: tauri::AppHandle) {
925920
});
926921
}
927922

928-
fn setup_panic_hook() {
929-
std::panic::set_hook(Box::new(move |panic_info| {
930-
let location = panic_info
931-
.location()
932-
.map(|l| format!("{}:{}:{}", l.file(), l.line(), l.column()))
933-
.unwrap_or_else(|| "unknown location".to_string());
934-
935-
let message = panic_info
936-
.payload()
937-
.downcast_ref::<&str>()
938-
.copied()
939-
.or_else(|| {
940-
panic_info
941-
.payload()
942-
.downcast_ref::<String>()
943-
.map(String::as_str)
944-
})
945-
.unwrap_or("unknown panic message");
946-
947-
log::error!("Application panic at {}: {}", location, message);
948-
949-
// Known wry bug: WKWebView.URL() returns nil after navigating to an
950-
// invalid address, causing url_from_webview to panic on unwrap().
951-
// This is non-fatal — the webview is still alive — so we log and
952-
// continue instead of killing the process.
953-
// See: https://github.com/tauri-apps/wry/pull/1554
954-
if location.contains("wry") && location.contains("wkwebview") {
955-
log::warn!("Suppressed non-fatal wry/wkwebview panic, application continues");
956-
return;
957-
}
958-
959-
if message.contains("WSAStartup") || message.contains("10093") || message.contains("hyper")
960-
{
961-
log::error!("Network-related crash detected, possible solutions:");
962-
log::error!(" 1) Restart the application");
963-
log::error!(" 2) Check Windows network service status");
964-
log::error!(" 3) Run as administrator");
965-
}
966-
967-
std::process::exit(1);
968-
}));
969-
}
970-
971923
fn start_event_loop_with_transport(
972924
event_queue: Arc<bitfun_core::agentic::events::EventQueue>,
973925
event_router: Arc<bitfun_core::agentic::events::EventRouter>,

‎src/apps/desktop/src/theme.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,5 @@ pub fn create_main_window(app_handle: &tauri::AppHandle) {
287287

288288
#[tauri::command]
289289
pub async fn show_main_window(app: tauri::AppHandle) -> Result<(), String> {
290-
use tauri::Manager;
291-
292-
if let Some(main_window) = app.get_webview_window("main") {
293-
main_window.show().map_err(|e| {
294-
error!("Failed to show main window: {}", e);
295-
format!("Failed to show main window: {}", e)
296-
})?;
297-
298-
main_window.set_focus().map_err(|e| {
299-
error!("Failed to focus main window: {}", e);
300-
format!("Failed to focus main window: {}", e)
301-
})?;
302-
} else {
303-
error!("Main window not found");
304-
return Err("Main window not found".to_string());
305-
}
306-
307290
Ok(())
308291
}

0 commit comments

Comments
 (0)