Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ simple_logger = "5.2.0"
log = "0.4.32"
any_ascii = "0.3.3"
rstar = "0.13.0"

[[test]]
name = "lifecycle_tests"
path = "tests/lifecycle_tests.rs"
harness = false
6 changes: 1 addition & 5 deletions src/app_engine/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl AppEngine {
msg
}

fn draw_dashboard(&mut self, key_prefix: &str) {
pub(super) fn draw_dashboard(&mut self, key_prefix: &str) {
// NOTE: need `self.last_app_window_info` for `is_workflow_valid` check,
// but shouldn't set `self.selected` yet
if self.selected.is_none() {
Expand Down Expand Up @@ -288,10 +288,6 @@ impl AppEngine {
pub(super) fn menu_refresh(&mut self, key_prefix: &str, set_mode: bool) {
if let Some(eoi) = self.selected.as_ref() {
self.draw_element_menu(key_prefix, eoi.role(), set_mode);
} else {
self.draw_dashboard(key_prefix);
// NOTE: for slow element.press() call
self.set_mode(Mode::DashBoard);
}
}

Expand Down
26 changes: 14 additions & 12 deletions src/app_engine/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const DEBOUNCE_TIMEOUT: u64 = 150;
impl AppEngine {
fn ocr_res_filtering(&mut self) {
if self.hint_boxes.is_empty() {
let Some(ocr_res) = self.ocr_cache.as_ref() else {
log::warn!("ocr_res_filtering called but OCR cache is not set.");
return;
};
let (digits, ocr_hints) = {
let ocr_res = self
.ocr_cache
.as_ref()
.expect("Internal Error: OCR cache not set.");
let len = ocr_res.len();
let iter = ocr_res.iter().map(|(_, rect)| Frame::from_cgrect(rect));
hint_boxes_from_frames(
Expand All @@ -44,10 +44,11 @@ impl AppEngine {
{
if self.multi_selection.is_on {
if let Some((idx1, idx2)) = self.multi_selection.set_one_side(hb_idx) {
let choices: Vec<(String, Frame, bool)> = self
.ocr_cache
.as_ref()
.expect("Internal Error: OCR cache not set.")
let Some(ocr_res) = self.ocr_cache.as_ref() else {
log::warn!("ocr_res_filtering called but OCR cache is not set.");
return;
};
let choices: Vec<(String, Frame, bool)> = ocr_res
.iter()
.map(|(s, rect)| (s.clone(), Frame::from_cgrect(rect), true))
.collect::<Vec<_>>();
Expand All @@ -62,10 +63,11 @@ impl AppEngine {
self.update_hints();
}
} else {
let (selected_text, cg_rect) = self
.ocr_cache
.as_ref()
.expect("Internal Error: OCR cache not set.")
let Some(ocr_res) = self.ocr_cache.as_ref() else {
log::warn!("ocr_res_filtering called but OCR cache is not set.");
return;
};
let (selected_text, cg_rect) = ocr_res
.get(hb_idx)
.expect("Internal Error: wrong ocr hint indexing.");
let selected_text = selected_text.clone();
Expand Down
6 changes: 5 additions & 1 deletion src/app_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ impl AppEngine {
AppSignal::MenuRefresh(key_prefix) => {
self.menu_refresh(&key_prefix, false);
}
AppSignal::DashboardRefresh(key_prefix) => {
self.draw_dashboard(&key_prefix);
self.set_mode(Mode::DashBoard);
}
AppSignal::RunWorkFlow(idx) => {
self.drawer.clear_menus();
self.execute_workflow(idx);
Expand Down Expand Up @@ -229,8 +233,8 @@ impl AppEngine {
if self.target == Target::ChildElement {
// To act on selected parent node
self.clear_cache();
self.draw_dashboard("");
self.set_mode(Mode::DashBoard);
self.menu_refresh("", false);
}
}
AppSignal::ScreenShot => {
Expand Down
8 changes: 7 additions & 1 deletion src/app_engine/workflow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::AppEngine;
use crate::{
Mode,
ax_element::{CompiledTarget, GetAttribute, SetAttribute, Target},
config::{RoleOfInterest, WorkFlow, WorkFlowAction},
};
Expand Down Expand Up @@ -35,7 +36,12 @@ impl AppEngine {
// Actions don't need a selected element
match act {
WorkFlowAction::GlyphlowMenu => {
self.menu_refresh("", true);
if self.selected.is_some() {
self.menu_refresh("", true);
} else {
self.draw_dashboard("");
self.set_mode(Mode::DashBoard);
}
// HACK: break the loop so the notification will be kept,
// basically `GlyphlowMenu` should be a terminal op
self.pending_workflow_actions.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/key_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub enum AppSignal {
HintFilter(char, FilterMode),
SearchFilter(char, FilterMode),
MenuRefresh(String),
DashboardRefresh(String),
ActOnEnter,
// Sub state signals
FileUpdate(PathBuf),
Expand Down Expand Up @@ -372,7 +373,7 @@ impl KeyListener {
|| k.right_alternative()
.is_some_and(|r| *k == r || key_state.pressed_keys.contains(&r))
}) {
self.send(AppSignal::MenuRefresh("".into()));
self.send(AppSignal::DashboardRefresh("".into()));
*state = Mode::DashBoard;
true
} else {
Expand Down
Loading
Loading