Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

build(desktop): prepare workflow for building Windows (#4246)

Elijah Potterd5cd9da475da
diff --git a/.github/workflows/desktop_windows.yml b/.github/workflows/desktop_windows.yml
new file mode 100644
index 000000000..2658df39b
--- /dev/null
+++ b/.github/workflows/desktop_windows.yml
@@ -0,0 +1,70 @@
+name: Harper Desktop for Windows
+
+on:
+ push:
+ branches: ["master"]
+ tags: ["v*"]
+ pull_request:
+ branches: ["master"]
+ merge_group:
+
+env:
+ CARGO_TERM_COLOR: always
+
+jobs:
+ desktop-windows:
+ name: just build-desktop-windows
+ runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/[email protected]
+ - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0
+ - name: Install pnpm
+ uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
+ - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
+ - name: Install Node.js
+ uses: actions/setup-node@v7
+ with:
+ node-version-file: ".node-version"
+ - name: Enable Corepack
+ run: corepack enable
+ - name: Install Tauri and cross-compilation dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y \
+ libayatana-appindicator3-dev \
+ librsvg2-dev \
+ libwebkit2gtk-4.1-dev \
+ libxdo-dev \
+ llvm \
+ nsis
+ - name: Verify Windows build tools
+ run: command -v clang-cl llvm-lib makensis
+ - name: Rust Cache
+ uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
+ with:
+ cache-bin: "true"
+ key: build-desktop-windows
+ - uses: cargo-bins/cargo-binstall@910d9e4456ce4b039662d2a02a34ef1d23c3c50c # main
+ - name: Install `wasm-pack`
+ run: cargo binstall wasm-pack --force --no-confirm
+ - name: Install `cargo-xwin`
+ run: cargo binstall cargo-xwin --force --no-confirm
+ - name: Install `tauri-cli`
+ run: cargo binstall tauri-cli --force --no-confirm
+ - name: Build Harper Desktop for Windows
+ run: just build-desktop-windows
+ - name: Upload artifacts
+ uses: actions/upload-artifact@v7
+ with:
+ name: harper-desktop-windows-x64
+ path: target/x86_64-pc-windows-msvc/release/bundle/nsis/*
+ if-no-files-found: error
+ - name: Release artifacts
+ if: startsWith(github.ref, 'refs/tags/v')
+ uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0
+ with:
+ artifacts: target/x86_64-pc-windows-msvc/release/bundle/nsis/*
+ allowUpdates: true
+ draft: true
diff --git a/harper-desktop/src-tauri/src/os_broker.rs b/harper-desktop/src-tauri/src/os_broker.rs
index 564e3e024..6e998e6a3 100644
--- a/harper-desktop/src-tauri/src/os_broker.rs
+++ b/harper-desktop/src-tauri/src/os_broker.rs
@@ -70,9 +70,11 @@ pub struct AppSearchResult {
///
/// This lets the highlighter compile on non-macOS platforms while making it explicit that there is
/// currently no accessibility or cursor integration there.
+#[cfg(not(any(target_os = "macos", target_os = "windows")))]
#[derive(Default)]
pub struct NoopBroker;
+#[cfg(not(any(target_os = "macos", target_os = "windows")))]
impl OsBroker for NoopBroker {
fn get_boxes(
&mut self,
diff --git a/harper-desktop/src-tauri/src/windows_broker/automation_service.rs b/harper-desktop/src-tauri/src/windows_broker/automation_service.rs
index 4a08705ff..79b71c7df 100644
--- a/harper-desktop/src-tauri/src/windows_broker/automation_service.rs
+++ b/harper-desktop/src-tauri/src/windows_broker/automation_service.rs
@@ -13,11 +13,9 @@ use uiautomation::{
UIAutomation, UIElement,
patterns::{UITextPattern, UIValuePattern},
};
-use windows::Win32::Foundation::{HWND, POINT};
+use windows::Win32::Foundation::HWND;
use windows::Win32::UI::Accessibility::IUIAutomationTextRange;
-use windows::Win32::UI::WindowsAndMessaging::{
- GetCursorPos, GetForegroundWindow, GetWindowThreadProcessId,
-};
+use windows::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId};
/// Information about a worker thread.
struct WorkerData {
@@ -289,9 +287,9 @@ fn get_text(element: &UIElement) -> uiautomation::Result<String> {
range.get_text(-1)
}
-/// Finds a fresh text element below `window`, preferring keyboard focus, then the smallest element
-/// below the cursor, and finally the first readable text element in UI Automation tree order. When
-/// `expected_text` is provided, unrelated text providers are excluded.
+/// Finds the focused text element below `window`.
+///
+/// When `expected_text` is provided, unrelated text providers are excluded.
fn text_element_for_window(
automation: &UIAutomation,
window: isize,
@@ -310,11 +308,7 @@ fn text_element_for_window(
)?;
let condition = automation.create_and_condition(text_condition, keyboard_condition)?;
- for (index, element) in root
- .find_all(TreeScope::Subtree, &condition)?
- .into_iter()
- .enumerate()
- {
+ for element in root.find_all(TreeScope::Subtree, &condition)? {
if let Some(expected) = expected_text {
let text = get_text(&element);
@@ -322,7 +316,7 @@ fn text_element_for_window(
continue;
};
- if expected_text.is_some_and(|expected| expected != text) {
+ if expected != text {
continue;
}
}
@@ -336,29 +330,6 @@ fn text_element_for_window(
))
}
-fn cursor_overlap_area(element: &UIElement, cursor: Option<POINT>) -> Option<i64> {
- let cursor = cursor?;
- let rect = element.get_bounding_rectangle().ok()?;
- if cursor.x < rect.get_left()
- || cursor.x >= rect.get_right()
- || cursor.y < rect.get_top()
- || cursor.y >= rect.get_bottom()
- {
- return None;
- }
-
- Some(
- (i64::from(rect.get_right()) - i64::from(rect.get_left()))
- * (i64::from(rect.get_bottom()) - i64::from(rect.get_top())),
- )
-}
-
-fn cursor_position() -> Option<POINT> {
- let mut point = POINT::default();
- unsafe { GetCursorPos(&mut point) }.ok()?;
- Some(point)
-}
-
fn get_text_job(automation: &UIAutomation, args: Vec<JobArgument>) -> JobResult {
let Some(JobArgument::Window(window)) = args.first() else {
return JobResult::Err;
diff --git a/justfile b/justfile
index c714125cd..367a7bb10 100644
--- a/justfile
+++ b/justfile
@@ -206,9 +206,11 @@ build-desktop-windows: build-harperjs build-lint-framework build-components buil
#!/usr/bin/env bash
set -eo pipefail
+ rustup target add x86_64-pc-windows-msvc
+
cd "{{justfile_directory()}}/harper-desktop"
pnpm install
- pnpm tauri build -b msi
+ pnpm tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc -b nsis --config '{"bundle":{"createUpdaterArtifacts":false}}'
# Build Harper Desktop for Apple Silicon only — faster than the universal recipe below.
build-desktop-macos-arm64: build-harperjs build-lint-framework build-components build-harper-editor