Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(desktop): create debug mode for the highlighter (#4609)
Elijah Potterad1db0e5842c
diff --git a/harper-desktop/src-tauri/src/args.rs b/harper-desktop/src-tauri/src/args.rsindex d209ac9e5..665919ac8 100644--- a/harper-desktop/src-tauri/src/args.rs+++ b/harper-desktop/src-tauri/src/args.rs@@ -12,4 +12,7 @@ pub enum Command {#[arg(long)]no_parent: bool,},+ // Runs the application only showing the popup window for an example suggestion. Useful for+ // making visual modifications to the popup window.+ PopupDebug,}diff --git a/harper-desktop/src-tauri/src/debug_broker.rs b/harper-desktop/src-tauri/src/debug_broker.rsnew file mode 100644index 000000000..0810e6b67--- /dev/null+++ b/harper-desktop/src-tauri/src/debug_broker.rs@@ -0,0 +1,64 @@+use std::collections::BTreeMap;++use egui::Pos2;+use harper_core::Span;+use harper_core::linting::{Lint, Suggestion};++use crate::os_broker::{AccessibilityPermissionStatus, OsBroker};+use crate::rect::ActionableLint;++/// A broker that allows one to mock an operating system for testing or debugging purposes.+/// For the time being, most functionality does nothing.+pub struct DebugBroker;++impl OsBroker for DebugBroker {+ fn get_boxes(+ &mut self,+ _: &mut dyn FnMut(&str) -> BTreeMap<String, Vec<Lint>>,+ ) -> Option<Vec<ActionableLint>> {+ Some(vec![ActionableLint::new(+ crate::rect::Rect::new(100.0, 100.0, 50.0, 25.0),+ "ExampleRule".to_string(),+ Lint {+ span: Span::new(0, 4),+ lint_kind: harper_core::linting::LintKind::Miscellaneous,+ suggestions: vec![+ Suggestion::ReplaceWith("Sug1".chars().collect()),+ Suggestion::Remove,+ ],+ message: "This is a mocked message for a suggestion.".to_string(),+ priority: 1,+ },+ "This is some mocking text.".to_string(),+ |_| {},+ )])+ }++ fn cursor_position(&self) -> Option<Pos2> {+ Some(Pos2 { x: 105.0, y: 105.0 })+ }++ fn accessibility_permission_status(&self) -> AccessibilityPermissionStatus {+ AccessibilityPermissionStatus::Granted+ }++ fn request_accessibility_permission(&self) -> AccessibilityPermissionStatus {+ AccessibilityPermissionStatus::Granted+ }++ fn installed_application_bundle_ids(&self) -> Result<Vec<String>, String> {+ Ok(Vec::new())+ }++ fn application_icon_png(&self, _bundle_id: &str) -> Result<Vec<u8>, String> {+ Err("Cannot get icon PNGs with the mocked broker.".to_string())+ }++ fn launch_app_bundle(&self, _bundle_id: &str) -> Result<(), String> {+ Err("Cannot launch an app with the mocked broker.".to_string())+ }++ fn search_apps(&self, _query: &str) -> Result<Vec<crate::os_broker::AppSearchResult>, String> {+ Err("Cannot search installed apps with the mocked broker.".to_string())+ }+}diff --git a/harper-desktop/src-tauri/src/main.rs b/harper-desktop/src-tauri/src/main.rsindex 6d169df69..3842af8b4 100644--- a/harper-desktop/src-tauri/src/main.rs+++ b/harper-desktop/src-tauri/src/main.rs@@ -1,9 +1,11 @@// Prevents additional console window on Windows in release, DO NOT REMOVE!!#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]+mod debug_broker;mod tray;mod windows;+use self::debug_broker::DebugBroker;use self::highlighter::Highlighter;use self::highlighter_service::HighlighterService;use self::tray::set_up_tray_menu;@@ -18,6 +20,7 @@ use harper_core::{spell::MutableDictionary,};use serde::Serialize;+use std::collections::BTreeMap;use std::io::stderr;use std::{cell::RefCell,@@ -117,6 +120,7 @@ pub fn main() {match args.command {Some(Command::Highlighter { no_parent }) => run_highlighter(!no_parent),+ Some(Command::PopupDebug) => popup_debug(),None => run_tauri(),}}@@ -222,6 +226,19 @@ pub fn run_tauri() {});}+pub fn popup_debug() {+ let highlighter = Highlighter::new(+ DebugBroker,+ |_| BTreeMap::new(),+ |_, _| {},+ |_| {},+ |_| {},+ || {},+ )+ .unwrap();+ highlighter.run_window_for_each_monitor().unwrap();+}+/// Run as a highlighter process./// Can configure whether to run standalone, or with a parent Tauri processpub fn run_highlighter(has_parent: bool) {