Skip to content

Commit c2fbd3e

Browse files
authored
More robust error handling for desktop autotype windows implementation (#16501)
* Desktop autotype windows error handling * create a subdir * extract window handle to separate file * remove println in case tracing doesn't make it in * touchups * reduce scope of unsafe call * use tracing * Fix comparison on GetLastError result * Remove the WindowHandle wrapper and save it for the unit testing PR * restore apps/browser/src/platform/system-notifications/browser-system-notification.service.ts * use the human readable message for GetLastError debug * don't call GetLastError outside of error path * add some more debug statements * feedback coltonhorst: nits, fix false positive when len zero, re-add handle validation * lint * feedback coltonhurst: add comments and update var names
1 parent babbc2b commit c2fbd3e

File tree

6 files changed

+188
-105
lines changed

6 files changed

+188
-105
lines changed

apps/desktop/desktop_native/Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/desktop_native/autotype/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ license.workspace = true
55
edition.workspace = true
66
publish.workspace = true
77

8+
[dependencies]
9+
anyhow = { workspace = true }
10+
811
[target.'cfg(windows)'.dependencies]
912
tracing.workspace = true
1013
windows = { workspace = true, features = [
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1+
use anyhow::Result;
2+
13
#[cfg_attr(target_os = "linux", path = "linux.rs")]
24
#[cfg_attr(target_os = "macos", path = "macos.rs")]
35
#[cfg_attr(target_os = "windows", path = "windows.rs")]
46
mod windowing;
57

68
/// Gets the title bar string for the foreground window.
79
///
8-
/// TODO: The error handling will be improved in a future PR: PM-23615
9-
#[allow(clippy::result_unit_err)]
10-
pub fn get_foreground_window_title() -> std::result::Result<String, ()> {
10+
/// # Errors
11+
///
12+
/// This function returns an `anyhow::Error` if there is any
13+
/// issue obtaining the window title. Detailed reasons will
14+
/// vary based on platform implementation.
15+
pub fn get_foreground_window_title() -> Result<String> {
1116
windowing::get_foreground_window_title()
1217
}
1318

1419
/// Attempts to type the input text wherever the user's cursor is.
1520
///
16-
/// `input` must be an array of utf-16 encoded characters to insert.
21+
/// # Arguments
22+
///
23+
/// * `input` must be an array of utf-16 encoded characters to insert.
24+
///
25+
/// # Errors
1726
///
18-
/// TODO: The error handling will be improved in a future PR: PM-23615
19-
#[allow(clippy::result_unit_err)]
20-
pub fn type_input(input: Vec<u16>, keyboard_shortcut: Vec<String>) -> std::result::Result<(), ()> {
27+
/// This function returns an `anyhow::Error` if there is any
28+
/// issue obtaining the window title. Detailed reasons will
29+
/// vary based on platform implementation.
30+
pub fn type_input(input: Vec<u16>, keyboard_shortcut: Vec<String>) -> Result<()> {
2131
windowing::type_input(input, keyboard_shortcut)
2232
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
pub fn get_foreground_window_title() -> std::result::Result<String, ()> {
1+
pub fn get_foreground_window_title() -> anyhow::Result<String> {
22
todo!("Bitwarden does not yet support Linux autotype");
33
}
44

5-
pub fn type_input(
6-
_input: Vec<u16>,
7-
_keyboard_shortcut: Vec<String>,
8-
) -> std::result::Result<(), ()> {
5+
pub fn type_input(_input: Vec<u16>, _keyboard_shortcut: Vec<String>) -> anyhow::Result<()> {
96
todo!("Bitwarden does not yet support Linux autotype");
107
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
pub fn get_foreground_window_title() -> std::result::Result<String, ()> {
1+
pub fn get_foreground_window_title() -> anyhow::Result<String> {
22
todo!("Bitwarden does not yet support macOS autotype");
33
}
44

5-
pub fn type_input(
6-
_input: Vec<u16>,
7-
_keyboard_shortcut: Vec<String>,
8-
) -> std::result::Result<(), ()> {
5+
pub fn type_input(_input: Vec<u16>, _keyboard_shortcut: Vec<String>) -> anyhow::Result<()> {
96
todo!("Bitwarden does not yet support macOS autotype");
107
}

0 commit comments

Comments
 (0)