docs(plan): add set_window_opacity Rust command
Tauri 2 JS WebviewWindow does not expose setOpacity (only the Rust side has set_opacity), so the JS layer routes through a custom command. Surfaced during Task 9 implementation; updates Tasks 16 and 17 to register the command. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1881,6 +1881,20 @@ pub fn get_hotkey_status(app: AppHandle) -> Result<crate::HotkeyStatus, String>
|
||||
let guard = state.hotkey_status.lock().map_err(|_| "poisoned".to_string())?;
|
||||
Ok(guard.clone())
|
||||
}
|
||||
|
||||
/// Set window opacity. Tauri 2's JS WebviewWindow does NOT expose setOpacity
|
||||
/// (only the Rust side does), so the JS layer routes through this command.
|
||||
#[tauri::command]
|
||||
pub fn set_window_opacity<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
label: String,
|
||||
opacity: f32,
|
||||
) -> Result<(), String> {
|
||||
let Some(window) = app.get_webview_window(&label) else {
|
||||
return Err(format!("window not found: {label}"));
|
||||
};
|
||||
window.set_opacity(opacity).map_err(|e| e.to_string())
|
||||
}
|
||||
```
|
||||
|
||||
> **Note on the design:** Tauri 2 doesn't expose a getter for `ignore_cursor_events` / `opacity` on `WebviewWindow`. Rather than rely on getters, we keep a tiny Rust-side cache (`AppState.click_through`) that the JS side keeps in sync via `sync_click_through_cache`. The global shortcut handler reads this cache, computes the inverse, calls `apply_state`. The JS-driven toggle path uses `toggle_click_through(current)` and skips the cache.
|
||||
@@ -1994,6 +2008,7 @@ pub fn run() {
|
||||
commands::overlay::toggle_click_through,
|
||||
commands::overlay::sync_click_through_cache,
|
||||
commands::overlay::get_hotkey_status,
|
||||
commands::overlay::set_window_opacity,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user