From 259e7bec5ec86d891fe379c12ab0ee1d250464ef Mon Sep 17 00:00:00 2001 From: Marco Quinten Date: Mon, 7 Aug 2023 00:53:33 +0200 Subject: [PATCH] Fix compilation issues (#70) * Fix platforms where `c_ulong` is 32 bits wide * Adjust workflow to run for PRs and pushes --- .editorconfig | 33 ++-- .github/workflows/main.yml | 78 +++++---- src-tauri/Cargo.lock | 4 +- src-tauri/src/platform/shared.rs | 290 +++++++++++++++---------------- 4 files changed, 206 insertions(+), 199 deletions(-) diff --git a/.editorconfig b/.editorconfig index c834ba23..fedeeeb0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,15 +1,18 @@ -# EditorConfig is awesome: https://EditorConfig.org - -# top-most EditorConfig file -root = true - -[*] -indent_style = space -indent_size = 4 -end_of_line = crlf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 55fd2cb2..e6b0dae1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,37 +1,41 @@ -name: 'Build release' -on: workflow_dispatch -env: - CI: false - -jobs: - publish-tauri: - strategy: - fail-fast: false - matrix: - platform: [macos-latest, ubuntu-20.04, windows-latest] - - runs-on: ${{ matrix.platform }} - steps: - - uses: actions/checkout@v3 - - name: setup node - uses: actions/setup-node@v3 - with: - node-version: 16 - - name: install Rust stable - uses: dtolnay/rust-toolchain@stable - - name: install dependencies (ubuntu only) - if: matrix.platform == 'ubuntu-20.04' - run: | - sudo apt-get update - sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf - - name: install app dependencies and build it - run: yarn && yarn build - - uses: tauri-apps/tauri-action@v0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tagName: Neuz-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version - releaseName: 'Neuz v__VERSION__' - releaseBody: 'See the assets to download this version and install.' - releaseDraft: true - prerelease: false +name: 'Build release' +on: + pull_request: + push: + branches: + - main +env: + CI: false + +jobs: + publish-tauri: + strategy: + fail-fast: false + matrix: + platform: [macos-latest, ubuntu-20.04, windows-latest] + + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v3 + - name: setup node + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: install Rust stable + uses: dtolnay/rust-toolchain@stable + - name: install dependencies (ubuntu only) + if: matrix.platform == 'ubuntu-20.04' + run: | + sudo apt-get update + sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf + - name: install app dependencies and build it + run: yarn && yarn build + - uses: tauri-apps/tauri-action@v0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tagName: Neuz-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version + releaseName: 'Neuz v__VERSION__' + releaseBody: 'See the assets to download this version and install.' + releaseDraft: true + prerelease: false diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 34f8a9df..c8cea946 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4072,9 +4072,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.7.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" +checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" dependencies = [ "cfg-if", "fastrand 2.0.0", diff --git a/src-tauri/src/platform/shared.rs b/src-tauri/src/platform/shared.rs index 74fbcca6..8ea5d021 100644 --- a/src-tauri/src/platform/shared.rs +++ b/src-tauri/src/platform/shared.rs @@ -1,145 +1,145 @@ -use std::time::Duration; - -use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; -use tauri::Window; - -use crate::data::Point; - -#[derive(Debug)] -pub enum KeyMode { - Press, - Hold, - Release, -} - -// For visual recognition: Avoids mouse clicks outside the window by ignoring monster names that are too close to the bottom of the GUI -pub const IGNORE_AREA_BOTTOM: u32 = 110; - -/// Get the native window id. -pub fn get_window_id(window: &Window) -> Option { - #[allow(unused_variables)] - match window.raw_window_handle() { - RawWindowHandle::Xlib(handle) => Some(handle.window), - RawWindowHandle::Win32(handle) => Some(handle.hwnd as u64), - RawWindowHandle::AppKit(handle) => { - #[cfg(target_os = "macos")] - unsafe { - use std::ffi::c_void; - let ns_window_ptr = handle.ns_window as *const c_void; - libscreenshot::platform::macos::macos_helper::ns_window_to_window_id(ns_window_ptr) - .map(|id| id as u64) - } - #[cfg(not(target_os = "macos"))] - unreachable!() - } - _ => Some(0_u64), - } -} - -pub fn eval_send_key(window: &Window, key: &str, mode: KeyMode) { - match mode { - KeyMode::Press => { - drop(window.eval(format!(" - document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keydown', {{'key': '{0}'}})) - document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keyup', {{'key': '{0}'}}))" - , key).as_str())) - }, - KeyMode::Hold => { - drop(window.eval(format!(" - document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keydown', {{'key': '{0}'}}))" - , key).as_str())) - }, - KeyMode::Release => { - drop(window.eval(format!(" - document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keyup', {{'key': '{0}'}}))" - , key).as_str())) - }, - } -} - -pub fn send_slot_eval(window: &Window, slot_bar_index: usize, k: usize) { - eval_send_key( - window, - format!("F{}", slot_bar_index + 1).to_string().as_str(), - KeyMode::Press, - ); - eval_send_key(window, k.to_string().as_str(), KeyMode::Press); - //std::thread::sleep(Duration::from_millis(100)); -} - -/* pub fn eval_mouse_click_at_point(window: &Window, pos: Point) { - drop( - window.eval( - format!( - " - document.querySelector('canvas').dispatchEvent(new MouseEvent('mousedown', {{ - clientX: {0}, - clientY: {1} - }})) - - document.querySelector('canvas').dispatchEvent(new MouseEvent('mouseup', {{ - clientX: {0}, - clientY: {1} - }}))", - pos.x, pos.y - ) - .as_str(), - ), - ); -} */ - -pub fn eval_mouse_move(window: &Window, pos: Point) { - drop( - window.eval( - format!( - " - document.querySelector('canvas').dispatchEvent(new MouseEvent('mousemove', {{ - clientX: {0}, - clientY: {1} - }}))", - pos.x, pos.y - ) - .as_str(), - ), - ); -} - -pub fn eval_mob_click(window: &Window, pos: Point) { - eval_mouse_move(window, pos); - std::thread::sleep(Duration::from_millis(25)); - drop( - window.eval( - format!( - " - if (document.body.style.cursor.indexOf('curattack') > 0) {{ - document.querySelector('canvas').dispatchEvent(new MouseEvent('mousedown', {{ - clientX: {0}, - clientY: {1} - }})) - - document.querySelector('canvas').dispatchEvent(new MouseEvent('mouseup', {{ - clientX: {0}, - clientY: {1} - }})) - }} - global.gc();;", - pos.x, pos.y - ) - .as_str(), - ), - ); -} - -pub fn eval_send_message(window: &Window, text: &str) { - drop( - window.eval( - format!( - " - document.querySelector('input').value = '{0}'; - document.querySelector('input').select();", - text - ) - .as_str(), - ), - ); -} +use std::time::Duration; + +use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; +use tauri::Window; + +use crate::data::Point; + +#[derive(Debug)] +pub enum KeyMode { + Press, + Hold, + Release, +} + +// For visual recognition: Avoids mouse clicks outside the window by ignoring monster names that are too close to the bottom of the GUI +pub const IGNORE_AREA_BOTTOM: u32 = 110; + +/// Get the native window id. +pub fn get_window_id(window: &Window) -> Option { + #[allow(unused_variables)] + match window.raw_window_handle() { + RawWindowHandle::Xlib(handle) => Some(handle.window as u64), + RawWindowHandle::Win32(handle) => Some(handle.hwnd as u64), + RawWindowHandle::AppKit(handle) => { + #[cfg(target_os = "macos")] + unsafe { + use std::ffi::c_void; + let ns_window_ptr = handle.ns_window as *const c_void; + libscreenshot::platform::macos::macos_helper::ns_window_to_window_id(ns_window_ptr) + .map(|id| id as u64) + } + #[cfg(not(target_os = "macos"))] + unreachable!() + } + _ => Some(0_u64), + } +} + +pub fn eval_send_key(window: &Window, key: &str, mode: KeyMode) { + match mode { + KeyMode::Press => { + drop(window.eval(format!(" + document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keydown', {{'key': '{0}'}})) + document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keyup', {{'key': '{0}'}}))" + , key).as_str())) + }, + KeyMode::Hold => { + drop(window.eval(format!(" + document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keydown', {{'key': '{0}'}}))" + , key).as_str())) + }, + KeyMode::Release => { + drop(window.eval(format!(" + document.querySelector('canvas').dispatchEvent(new KeyboardEvent('keyup', {{'key': '{0}'}}))" + , key).as_str())) + }, + } +} + +pub fn send_slot_eval(window: &Window, slot_bar_index: usize, k: usize) { + eval_send_key( + window, + format!("F{}", slot_bar_index + 1).to_string().as_str(), + KeyMode::Press, + ); + eval_send_key(window, k.to_string().as_str(), KeyMode::Press); + //std::thread::sleep(Duration::from_millis(100)); +} + +/* pub fn eval_mouse_click_at_point(window: &Window, pos: Point) { + drop( + window.eval( + format!( + " + document.querySelector('canvas').dispatchEvent(new MouseEvent('mousedown', {{ + clientX: {0}, + clientY: {1} + }})) + + document.querySelector('canvas').dispatchEvent(new MouseEvent('mouseup', {{ + clientX: {0}, + clientY: {1} + }}))", + pos.x, pos.y + ) + .as_str(), + ), + ); +} */ + +pub fn eval_mouse_move(window: &Window, pos: Point) { + drop( + window.eval( + format!( + " + document.querySelector('canvas').dispatchEvent(new MouseEvent('mousemove', {{ + clientX: {0}, + clientY: {1} + }}))", + pos.x, pos.y + ) + .as_str(), + ), + ); +} + +pub fn eval_mob_click(window: &Window, pos: Point) { + eval_mouse_move(window, pos); + std::thread::sleep(Duration::from_millis(25)); + drop( + window.eval( + format!( + " + if (document.body.style.cursor.indexOf('curattack') > 0) {{ + document.querySelector('canvas').dispatchEvent(new MouseEvent('mousedown', {{ + clientX: {0}, + clientY: {1} + }})) + + document.querySelector('canvas').dispatchEvent(new MouseEvent('mouseup', {{ + clientX: {0}, + clientY: {1} + }})) + }} + global.gc();;", + pos.x, pos.y + ) + .as_str(), + ), + ); +} + +pub fn eval_send_message(window: &Window, text: &str) { + drop( + window.eval( + format!( + " + document.querySelector('input').value = '{0}'; + document.querySelector('input').select();", + text + ) + .as_str(), + ), + ); +}