Skip to content

Commit 089794c

Browse files
authored
refactor!: Drop Tree::app_name (#492)
1 parent b4a89a3 commit 089794c

File tree

12 files changed

+30
-48
lines changed

12 files changed

+30
-48
lines changed

common/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,8 +2240,6 @@ impl JsonSchema for Properties {
22402240
pub struct Tree {
22412241
/// The identifier of the tree's root node.
22422242
pub root: NodeId,
2243-
/// The name of the application this tree belongs to.
2244-
pub app_name: Option<String>,
22452243
/// The name of the UI toolkit in use.
22462244
pub toolkit_name: Option<String>,
22472245
/// The version of the UI toolkit.
@@ -2253,7 +2251,6 @@ impl Tree {
22532251
pub fn new(root: NodeId) -> Tree {
22542252
Tree {
22552253
root,
2256-
app_name: None,
22572254
toolkit_name: None,
22582255
toolkit_version: None,
22592256
}

consumer/src/tree.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// the LICENSE-MIT file), at your option.
55

66
use accesskit::{FrozenNode as NodeData, NodeId, Tree as TreeData, TreeUpdate};
7-
use alloc::{string::String, sync::Arc, vec};
7+
use alloc::{sync::Arc, vec};
88
use core::fmt;
99
use hashbrown::{HashMap, HashSet};
1010
use immutable_chunkmap::map::MapM as ChunkMap;
@@ -213,16 +213,12 @@ impl State {
213213
self.focus_id().map(|id| self.node_by_id(id).unwrap())
214214
}
215215

216-
pub fn app_name(&self) -> Option<String> {
217-
self.data.app_name.clone()
216+
pub fn toolkit_name(&self) -> Option<&str> {
217+
self.data.toolkit_name.as_deref()
218218
}
219219

220-
pub fn toolkit_name(&self) -> Option<String> {
221-
self.data.toolkit_name.clone()
222-
}
223-
224-
pub fn toolkit_version(&self) -> Option<String> {
225-
self.data.toolkit_version.clone()
220+
pub fn toolkit_version(&self) -> Option<&str> {
221+
self.data.toolkit_version.as_deref()
226222
}
227223
}
228224

platforms/atspi-common/src/adapter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,8 @@ impl Adapter {
405405
let tree = self.context.read_tree();
406406
let tree_state = tree.state();
407407
let mut app_context = self.context.write_app_context();
408-
app_context.name = tree_state.app_name();
409-
app_context.toolkit_name = tree_state.toolkit_name();
410-
app_context.toolkit_version = tree_state.toolkit_version();
408+
app_context.toolkit_name = tree_state.toolkit_name().map(|s| s.to_string());
409+
app_context.toolkit_version = tree_state.toolkit_version().map(|s| s.to_string());
411410
let adapter_index = app_context.adapter_index(self.id).unwrap();
412411
let root = tree_state.root();
413412
let root_id = root.id();

platforms/atspi-common/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ pub struct AppContext {
8383
}
8484

8585
impl AppContext {
86-
pub fn new() -> Arc<RwLock<Self>> {
86+
pub fn new(name: Option<String>) -> Arc<RwLock<Self>> {
8787
Arc::new(RwLock::new(Self {
88-
name: None,
88+
name,
8989
toolkit_name: None,
9090
toolkit_version: None,
9191
id: None,

platforms/atspi-common/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,11 @@ impl PlatformNode {
695695
}
696696

697697
pub fn toolkit_name(&self) -> Result<String> {
698-
self.with_tree_state(|state| Ok(state.toolkit_name().unwrap_or_default()))
698+
self.with_tree_state(|state| Ok(state.toolkit_name().unwrap_or_default().to_string()))
699699
}
700700

701701
pub fn toolkit_version(&self) -> Result<String> {
702-
self.with_tree_state(|state| Ok(state.toolkit_version().unwrap_or_default()))
702+
self.with_tree_state(|state| Ok(state.toolkit_version().unwrap_or_default().to_string()))
703703
}
704704

705705
pub fn parent(&self) -> Result<NodeIdOrRoot> {

platforms/macos/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ objc2-app-kit = { version = "0.2.0", features = [
3434
"NSView",
3535
"NSWindow",
3636
] }
37-

platforms/unix/src/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ use crate::{
3333
static APP_CONTEXT: OnceLock<Arc<RwLock<AppContext>>> = OnceLock::new();
3434
static MESSAGES: OnceLock<Sender<Message>> = OnceLock::new();
3535

36+
fn app_name() -> Option<String> {
37+
std::env::current_exe().ok().and_then(|path| {
38+
path.file_name()
39+
.map(|name| name.to_string_lossy().to_string())
40+
})
41+
}
42+
3643
pub(crate) fn get_or_init_app_context<'a>() -> &'a Arc<RwLock<AppContext>> {
37-
APP_CONTEXT.get_or_init(AppContext::new)
44+
APP_CONTEXT.get_or_init(|| AppContext::new(app_name()))
3845
}
3946

4047
pub(crate) fn get_or_init_messages() -> Sender<Message> {

platforms/windows/examples/hello_world.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ impl ActivationHandler for InnerWindowState {
105105
let root = self.build_root();
106106
let button_1 = build_button(BUTTON_1_ID, "Button 1");
107107
let button_2 = build_button(BUTTON_2_ID, "Button 2");
108-
let mut tree = Tree::new(WINDOW_ID);
109-
tree.app_name = Some("hello_world".to_string());
108+
let tree = Tree::new(WINDOW_ID);
110109

111110
let mut result = TreeUpdate {
112111
nodes: vec![

platforms/windows/src/node.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,7 @@ impl IRawElementProviderSimple_Impl for PlatformNode_Impl {
645645
}
646646
match property_id {
647647
UIA_FrameworkIdPropertyId => result = state.toolkit_name().into(),
648-
UIA_ProviderDescriptionPropertyId => {
649-
result = app_and_toolkit_description(state).into()
650-
}
648+
UIA_ProviderDescriptionPropertyId => result = toolkit_description(state).into(),
651649
_ => (),
652650
}
653651
}

platforms/windows/src/util.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,25 +216,14 @@ pub(crate) fn window_title(hwnd: WindowHandle) -> Option<BSTR> {
216216
Some(BSTR::from_wide(&buffer).unwrap())
217217
}
218218

219-
pub(crate) fn app_and_toolkit_description(state: &TreeState) -> Option<String> {
220-
let app_name = state.app_name();
221-
let toolkit_name = state.toolkit_name();
222-
let toolkit_version = state.toolkit_version();
223-
match (&app_name, &toolkit_name, &toolkit_version) {
224-
(Some(app_name), Some(toolkit_name), Some(toolkit_version)) => Some(format!(
225-
"{} <{} {}>",
226-
app_name, toolkit_name, toolkit_version
227-
)),
228-
(Some(app_name), Some(toolkit_name), None) => {
229-
Some(format!("{} <{}>", app_name, toolkit_name))
219+
pub(crate) fn toolkit_description(state: &TreeState) -> Option<String> {
220+
state.toolkit_name().map(|name| {
221+
if let Some(version) = state.toolkit_version() {
222+
format!("{} {}", name, version)
223+
} else {
224+
name.to_string()
230225
}
231-
(None, Some(toolkit_name), Some(toolkit_version)) => {
232-
Some(format!("{} {}", toolkit_name, toolkit_version))
233-
}
234-
_ if toolkit_name.is_some() => toolkit_name,
235-
_ if app_name.is_some() => app_name,
236-
_ => None,
237-
}
226+
})
238227
}
239228

240229
pub(crate) fn upgrade<T>(weak: &Weak<T>) -> Result<Arc<T>> {

platforms/winit/examples/mixed_handlers.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ impl UiState {
8585
let root = self.build_root();
8686
let button_1 = build_button(BUTTON_1_ID, "Button 1");
8787
let button_2 = build_button(BUTTON_2_ID, "Button 2");
88-
let mut tree = Tree::new(WINDOW_ID);
89-
tree.app_name = Some("simple".to_string());
88+
let tree = Tree::new(WINDOW_ID);
9089
let mut result = TreeUpdate {
9190
nodes: vec![
9291
(WINDOW_ID, root),

platforms/winit/examples/simple.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ impl UiState {
8080
let root = self.build_root();
8181
let button_1 = build_button(BUTTON_1_ID, "Button 1");
8282
let button_2 = build_button(BUTTON_2_ID, "Button 2");
83-
let mut tree = Tree::new(WINDOW_ID);
84-
tree.app_name = Some("simple".to_string());
83+
let tree = Tree::new(WINDOW_ID);
8584
let mut result = TreeUpdate {
8685
nodes: vec![
8786
(WINDOW_ID, root),

0 commit comments

Comments
 (0)