Compare commits

...
20 Commits
Author SHA1 Message Date
meehl 3eacd43837 chore: Release rusty-path-of-building version 0.2.9
Release / create-release (push) Successful in 6s
2025-12-03 16:10:25 +01:00
meehl 523d5ffe29 Update CHANGELOG 2025-12-03 16:09:53 +01:00
meehl e18623edb4 Update README 2025-11-30 11:22:18 +01:00
meehl 1812edcbe9 Implement UI scale overriding
Closes #16
2025-11-30 11:16:04 +01:00
meehl df06c8f9c6 installer: Download highest supported version instead of latest version
Closes #17
2025-11-30 10:05:43 +01:00
meehl ae6a24f82c Reduce CPU usage while window is unfocused and not hovered over
Only render if window is focused, hovered, subscript is running,
or coroutine is active.

Closes #18
2025-11-28 18:30:25 +01:00
meehl 0066a05e13 Register AbortSubscript function under right name 2025-11-27 10:54:43 +01:00
meehl 3d8143c4d1 Add help text to import url argument 2025-11-27 10:54:43 +01:00
meehl a3ef4b39d0 Remove unneeded 'return' statement 2025-11-27 10:54:43 +01:00
meehl f48ab50633 Create CONTRIBUTING.md 2025-11-23 20:51:17 +01:00
meehl b86486d5aa Move config.yml into right directory 2025-11-23 18:05:05 +01:00
meehl 1f1a331cc2 Create config.yml 2025-11-23 18:01:45 +01:00
meehl 27b93c4a9d Update issue templates 2025-11-23 17:48:35 +01:00
meehl c95514036f Fix compiler warning caused by uninitialized variable 2025-11-22 13:48:13 +01:00
meehl 37bc3c5dbb chore: Release rusty-path-of-building version 0.2.8
Release / create-release (push) Successful in 5s
2025-11-07 07:55:07 +01:00
meehl 56155d066a Remove note about clipboard support in known issues section of README 2025-11-07 01:00:06 +01:00
meehl f27e83b467 Use smithay-clipboard crate for clipboard support on Wayland
Fixes #8
2025-11-07 00:59:37 +01:00
meehl 50d4b4b09c Replace non-ASCII characters in text input with '?'
This matches `SimpleGraphics` behavior and prevents a crash that can
happen if PoB tries to delete a non-ASCII character.

Fixes #9.
2025-11-06 16:55:31 +01:00
meehl 51e6881cb0 Simplify input event handling 2025-11-06 16:30:24 +01:00
meehl 8a69d15b49 Set app_id only on platforms that support it.
This fixes a build error on windows.
2025-11-03 13:26:03 +01:00
22 changed files with 705 additions and 247 deletions

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
# Contributing to Rusty Path Of Building
## Reporting bugs
- Ensure the bug was not already reported by searching through existing [issues](https://github.com/meehl/rusty-path-of-building/issues).
- If the bug can also be reproduced with the official runtime (e.g. by running through wine), please open an issue in the [PoB1](https://github.com/PathOfBuildingCommunity/PathOfBuilding) or [PoB2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2) repo instead. If you're unsure, feel free to just open it here.
- If possible, use the bug report template to create the issue and provide as much information as possible.
## Contributing code
- Get familiar with the code base before you start. I'll try to add more documentation providing a high-level overview of the architecture in the future. Until then, feel free to reach out through [Discussions](https://github.com/meehl/rusty-path-of-building/discussions) if you have any questions.
- If you intend to work on the API functions, also check out the [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) code base. A great place to ask questions about it is the PoB dev discord server. [Here](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) is more info on how to join.
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
+30
View File
@@ -0,0 +1,30 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A description of what you expected to happen.
**System information:**
- OS: [e.g. Linux, Windows, macOS]
- Desktop Environment/Compositor: [e.g. KDE, Gnome, sway, etc.] (only on Linux)
- Rusty Path of Building Version: [e.g. v0.2.8]
- Path of Building Version: [e.g. PoB1 v2.59.0 or PoB2 v0.12.2]
**Additional context**
Add any other context about the problem here. Feel free to add screenshots or any other info like PoB build codes if relevant.
+5
View File
@@ -0,0 +1,5 @@
blank_issues_enabled: yes
contact_links:
- name: GitHub Discussions
url: https://github.com/meehl/rusty-path-of-building/discussions
about: Please ask questions unrelated to actual bugs/issues here.
+25 -1
View File
@@ -2,6 +2,28 @@
## [Unreleased] - ReleaseDate ## [Unreleased] - ReleaseDate
## [0.2.9] - 2025-12-03
### Added
- Implement UI scale overriding
### Changed
- Reduce CPU usage while window is unfocused and not hovered over
- Download highest compatible PoB version instead of latest version
### Fixed
- Register `AbortSubscript` function under right name
## [0.2.8] - 2025-11-07
### Changed
- Replace non-ASCII characters in text input with '?'
- Use `smithay-clipboard` crate for clipboard support on Wayland
## [0.2.7] - 2025-11-02 ## [0.2.7] - 2025-11-02
### Added ### Added
@@ -111,8 +133,10 @@
- First release - First release
<!-- next-url --> <!-- next-url -->
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...HEAD [Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.9...HEAD
[0.2.9]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.8...v0.2.9
[0.2.8]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...v0.2.8
[0.2.7]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...v0.2.7 [0.2.7]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...v0.2.7
[0.2.6]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.5...v0.2.6 [0.2.6]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.5...v0.2.6
[0.2.5]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.4...v0.2.5 [0.2.5]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.4...v0.2.5
Generated
+100 -101
View File
@@ -173,7 +173,6 @@ dependencies = [
"parking_lot", "parking_lot",
"percent-encoding", "percent-encoding",
"windows-sys 0.60.2", "windows-sys 0.60.2",
"wl-clipboard-rs",
"x11rb", "x11rb",
] ]
@@ -242,7 +241,7 @@ dependencies = [
"anyhow", "anyhow",
"arrayvec", "arrayvec",
"log", "log",
"nom 8.0.0", "nom",
"num-rational", "num-rational",
"v_frame", "v_frame",
] ]
@@ -387,18 +386,43 @@ dependencies = [
"thiserror 1.0.69", "thiserror 1.0.69",
] ]
[[package]]
name = "calloop"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb9f6e1368bd4621d2c86baa7e37de77a938adf5221e5dd3d6133340101b309e"
dependencies = [
"bitflags 2.10.0",
"polling",
"rustix 1.1.2",
"slab",
"tracing",
]
[[package]] [[package]]
name = "calloop-wayland-source" name = "calloop-wayland-source"
version = "0.3.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20"
dependencies = [ dependencies = [
"calloop", "calloop 0.13.0",
"rustix 0.38.44", "rustix 0.38.44",
"wayland-backend", "wayland-backend",
"wayland-client", "wayland-client",
] ]
[[package]]
name = "calloop-wayland-source"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa"
dependencies = [
"calloop 0.14.3",
"rustix 1.1.2",
"wayland-backend",
"wayland-client",
]
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.43" version = "1.2.43"
@@ -803,12 +827,6 @@ dependencies = [
"thiserror 2.0.17", "thiserror 2.0.17",
] ]
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]] [[package]]
name = "fdeflate" name = "fdeflate"
version = "0.3.7" version = "0.3.7"
@@ -836,12 +854,6 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.1.5" version = "1.1.5"
@@ -1397,12 +1409,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.8.9" version = "0.8.9"
@@ -1518,16 +1524,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "8.0.0" version = "8.0.0"
@@ -1943,16 +1939,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "os_pipe"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
dependencies = [
"libc",
"windows-sys 0.61.2",
]
[[package]] [[package]]
name = "owned_ttf_parser" name = "owned_ttf_parser"
version = "0.25.1" version = "0.25.1"
@@ -2017,16 +2003,6 @@ version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "petgraph"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]] [[package]]
name = "pin-project" name = "pin-project"
version = "1.1.10" version = "1.1.10"
@@ -2530,7 +2506,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]] [[package]]
name = "rusty-path-of-building" name = "rusty-path-of-building"
version = "0.2.7" version = "0.2.9"
dependencies = [ dependencies = [
"ahash", "ahash",
"anyhow", "anyhow",
@@ -2555,7 +2531,9 @@ dependencies = [
"pollster", "pollster",
"profiling", "profiling",
"puffin_http", "puffin_http",
"raw-window-handle",
"regex", "regex",
"smithay-clipboard",
"swash", "swash",
"tar", "tar",
"ureq", "ureq",
@@ -2594,7 +2572,7 @@ dependencies = [
"ab_glyph", "ab_glyph",
"log", "log",
"memmap2", "memmap2",
"smithay-client-toolkit", "smithay-client-toolkit 0.19.2",
"tiny-skia", "tiny-skia",
] ]
@@ -2687,8 +2665,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016"
dependencies = [ dependencies = [
"bitflags 2.10.0", "bitflags 2.10.0",
"calloop", "calloop 0.13.0",
"calloop-wayland-source", "calloop-wayland-source 0.3.0",
"cursor-icon", "cursor-icon",
"libc", "libc",
"log", "log",
@@ -2705,6 +2683,44 @@ dependencies = [
"xkeysym", "xkeysym",
] ]
[[package]]
name = "smithay-client-toolkit"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0512da38f5e2b31201a93524adb8d3136276fa4fe4aafab4e1f727a82b534cc0"
dependencies = [
"bitflags 2.10.0",
"calloop 0.14.3",
"calloop-wayland-source 0.4.1",
"cursor-icon",
"libc",
"log",
"memmap2",
"rustix 1.1.2",
"thiserror 2.0.17",
"wayland-backend",
"wayland-client",
"wayland-csd-frame",
"wayland-cursor",
"wayland-protocols",
"wayland-protocols-experimental",
"wayland-protocols-misc",
"wayland-protocols-wlr",
"wayland-scanner",
"xkeysym",
]
[[package]]
name = "smithay-clipboard"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226"
dependencies = [
"libc",
"smithay-client-toolkit 0.20.0",
"wayland-backend",
]
[[package]] [[package]]
name = "smol_str" name = "smol_str"
version = "0.2.2" version = "0.2.2"
@@ -2799,19 +2815,6 @@ version = "0.12.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
[[package]]
name = "tempfile"
version = "3.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
dependencies = [
"fastrand",
"getrandom 0.3.4",
"once_cell",
"rustix 1.1.2",
"windows-sys 0.61.2",
]
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.4.1" version = "1.4.1"
@@ -2967,6 +2970,7 @@ version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [ dependencies = [
"log",
"pin-project-lite", "pin-project-lite",
"tracing-core", "tracing-core",
] ]
@@ -2977,18 +2981,6 @@ version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
[[package]]
name = "tree_magic_mini"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f943391d896cdfe8eec03a04d7110332d445be7df856db382dd96a730667562c"
dependencies = [
"memchr",
"nom 7.1.3",
"once_cell",
"petgraph",
]
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
version = "0.25.1" version = "0.25.1"
@@ -3227,6 +3219,32 @@ dependencies = [
"wayland-scanner", "wayland-scanner",
] ]
[[package]]
name = "wayland-protocols-experimental"
version = "20250721.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40a1f863128dcaaec790d7b4b396cc9b9a7a079e878e18c47e6c2d2c5a8dcbb1"
dependencies = [
"bitflags 2.10.0",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-scanner",
]
[[package]]
name = "wayland-protocols-misc"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfe33d551eb8bffd03ff067a8b44bb963919157841a99957151299a6307d19c"
dependencies = [
"bitflags 2.10.0",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-scanner",
]
[[package]] [[package]]
name = "wayland-protocols-plasma" name = "wayland-protocols-plasma"
version = "0.3.9" version = "0.3.9"
@@ -3737,7 +3755,7 @@ dependencies = [
"bitflags 2.10.0", "bitflags 2.10.0",
"block2", "block2",
"bytemuck", "bytemuck",
"calloop", "calloop 0.13.0",
"cfg_aliases", "cfg_aliases",
"concurrent-queue", "concurrent-queue",
"core-foundation", "core-foundation",
@@ -3759,7 +3777,7 @@ dependencies = [
"redox_syscall 0.4.1", "redox_syscall 0.4.1",
"rustix 0.38.44", "rustix 0.38.44",
"sctk-adwaita", "sctk-adwaita",
"smithay-client-toolkit", "smithay-client-toolkit 0.19.2",
"smol_str", "smol_str",
"tracing", "tracing",
"unicode-segmentation", "unicode-segmentation",
@@ -3792,25 +3810,6 @@ version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "wl-clipboard-rs"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5ff8d0e60065f549fafd9d6cb626203ea64a798186c80d8e7df4f8af56baeb"
dependencies = [
"libc",
"log",
"os_pipe",
"rustix 0.38.44",
"tempfile",
"thiserror 2.0.17",
"tree_magic_mini",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-protocols-wlr",
]
[[package]] [[package]]
name = "writeable" name = "writeable"
version = "0.6.2" version = "0.6.2"
+6 -2
View File
@@ -4,14 +4,14 @@ authors = ["meehl"]
description = "Cross-platform runtime for Path of Building" description = "Cross-platform runtime for Path of Building"
repository = "https://github.com/meehl/rusty-path-of-building" repository = "https://github.com/meehl/rusty-path-of-building"
license = "MIT" license = "MIT"
version = "0.2.7" version = "0.2.9"
edition = "2024" edition = "2024"
publish = false publish = false
[dependencies] [dependencies]
ahash = "0.8.12" ahash = "0.8.12"
anyhow = "1.0" anyhow = "1.0"
arboard = { version = "3.6.1", default-features = false, features = ["wayland-data-control"] } arboard = { version = "3.6.1", default-features = false }
bytemuck = "1.23.2" bytemuck = "1.23.2"
clap = { version = "4.5.46", features = ["derive"] } clap = { version = "4.5.46", features = ["derive"] }
dds = "0.1.0" dds = "0.1.0"
@@ -32,6 +32,7 @@ parley = "0.6.0"
pollster = "0.3" pollster = "0.3"
profiling = "1.0" profiling = "1.0"
puffin_http = { version = "0.16", optional = true } puffin_http = { version = "0.16", optional = true }
raw-window-handle = "0.6.2"
regex = "1.11.2" regex = "1.11.2"
swash = "0.2.5" swash = "0.2.5"
tar = "0.4.44" tar = "0.4.44"
@@ -40,5 +41,8 @@ wgpu = { version = "27.0.1", default-features = false, features = ["std", "parki
winit = "0.30" winit = "0.30"
zstd = "0.13.3" zstd = "0.13.3"
[target.'cfg(unix)'.dependencies]
smithay-clipboard = "0.7.3"
[features] [features]
profile-with-puffin = ["profiling/profile-with-puffin", "dep:puffin_http"] profile-with-puffin = ["profiling/profile-with-puffin", "dep:puffin_http"]
-2
View File
@@ -43,6 +43,4 @@ Please refer to the [Lua documentation](https://www.lua.org/manual/5.1/manual.ht
## Known Issues ## Known Issues
- The clipboard doesn't work with Wayland compositors that don't support the data-control extension(s). It is recommended to fall back to `Xwayland` in these cases. This can be done by unsetting `WAYLAND_DISPLAY`. More info here: https://github.com/1Password/arboard?tab=readme-ov-file#backend-support
- Overriding UI scaling through the options is currently not implemented.
- If automatic updates fail, navigate to `~/.local/share/RustyPathOfBuilding{1,2}/` and delete both the `rpob.version` file and the `Update` directory. This will force a complete re-download of PoB's latest assets and Lua code on the next startup. (Note: Third-party backends, like this project, face challenges supporting PoB's update mechanism. To make it work, fragile workarounds had to be implemented that can break unexpectedly) - If automatic updates fail, navigate to `~/.local/share/RustyPathOfBuilding{1,2}/` and delete both the `rpob.version` file and the `Update` directory. This will force a complete re-download of PoB's latest assets and Lua code on the next startup. (Note: Third-party backends, like this project, face challenges supporting PoB's update mechanism. To make it work, fragile workarounds had to be implemented that can break unexpectedly)
+1 -1
View File
@@ -646,7 +646,7 @@ static int l_zipFile_Read(lua_State* L)
if (n < 1) { if (n < 1) {
luaL_error(L, "Usage: zipFile:Read(count) or zipFile:read(\"*a\")"); luaL_error(L, "Usage: zipFile:Read(count) or zipFile:read(\"*a\")");
} }
int count; int count = 0;
if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 1)) {
count = lua_tointeger(L, 1); count = lua_tointeger(L, 1);
} else { } else {
+3 -10
View File
@@ -3,18 +3,11 @@ use mlua::{Lua, Result as LuaResult};
pub fn copy(l: &Lua, text: String) -> LuaResult<()> { pub fn copy(l: &Lua, text: String) -> LuaResult<()> {
let ctx = l.app_data_ref::<&'static Context>().unwrap(); let ctx = l.app_data_ref::<&'static Context>().unwrap();
ctx ctx.window().set_clipboard_text(text);
.clipboard()
.set_text(text)
.map_err(|e| anyhow::anyhow!("{}", e))?;
Ok(()) Ok(())
} }
pub fn paste(l: &Lua, _: ()) -> LuaResult<String> { pub fn paste(l: &Lua, _: ()) -> LuaResult<Option<String>> {
let ctx = l.app_data_ref::<&'static Context>().unwrap(); let ctx = l.app_data_ref::<&'static Context>().unwrap();
let text = ctx Ok(ctx.window().get_clipboard_text())
.clipboard()
.get_text()
.map_err(|e| anyhow::anyhow!("{}", e))?;
Ok(text)
} }
+4 -7
View File
@@ -390,9 +390,8 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
ctx.layers().set_draw_color(last_segment.color); ctx.layers().set_draw_color(last_segment.color);
} }
let layout = ctx.fonts().layout(job, ctx.window().scale_factor); let layout = ctx.fonts().layout(job, ctx.window().scale_factor());
ctx ctx.layers()
.layers()
.draw_text(position, layout, is_absolute_position); .draw_text(position, layout, is_absolute_position);
0 0
@@ -415,9 +414,7 @@ unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) -> c_in
}; };
let job = build_layout_job(text, Srgba::WHITE, font_type, line_height, None); let job = build_layout_job(text, Srgba::WHITE, font_type, line_height, None);
let width = ctx let width = ctx.fonts().get_text_width(job, ctx.window().scale_factor());
.fonts()
.get_text_width(job, ctx.window().scale_factor);
unsafe { ffi::lua_pushnumber(state, width as f64) }; unsafe { ffi::lua_pushnumber(state, width as f64) };
1 1
@@ -436,7 +433,7 @@ fn get_index_at_cur(
let index = ctx.fonts().get_text_index_at_cursor( let index = ctx.fonts().get_text_index_at_cursor(
job, job,
Point::new(cur_x, cur_y), Point::new(cur_x, cur_y),
ctx.window().scale_factor, ctx.window().scale_factor(),
); );
// convert to lua's 1-based indexing // convert to lua's 1-based indexing
+14 -6
View File
@@ -18,7 +18,7 @@ pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
pub fn get_screen_scale(l: &Lua, _: ()) -> LuaResult<f32> { pub fn get_screen_scale(l: &Lua, _: ()) -> LuaResult<f32> {
let ctx = l.app_data_ref::<&'static Context>().unwrap(); let ctx = l.app_data_ref::<&'static Context>().unwrap();
let scale_factor = ctx.window().scale_factor; let scale_factor = ctx.window().scale_factor();
Ok(scale_factor) Ok(scale_factor)
} }
@@ -34,12 +34,20 @@ pub fn set_foreground(l: &Lua, _: ()) -> LuaResult<()> {
Ok(()) Ok(())
} }
pub fn set_dpi_scale_override(_: &Lua, _percent: i32) -> LuaResult<()> { pub fn set_dpi_scale_override(l: &Lua, percent: i32) -> LuaResult<()> {
// TODO: let socket = l.app_data_ref::<&'static Context>().unwrap();
match percent {
0 => socket.window().scale_factor_override = None,
p if p > 0 => socket.window().scale_factor_override = Some(p as f32 / 100.0),
_ => {}
}
Ok(()) Ok(())
} }
pub fn get_dpi_scale_override(_: &Lua, _: ()) -> LuaResult<i32> { pub fn get_dpi_scale_override(l: &Lua, _: ()) -> LuaResult<i32> {
// TODO: let socket = l.app_data_ref::<&'static Context>().unwrap();
Ok(0) match socket.window().scale_factor_override {
Some(scale_factor) => Ok((scale_factor * 100.0) as i32),
None => Ok(0),
}
} }
+106 -81
View File
@@ -11,19 +11,15 @@ use crate::{
window::WindowState, window::WindowState,
}; };
use anyhow::Result; use anyhow::Result;
use arboard::Clipboard;
use std::sync::Arc; use std::sync::Arc;
use winit::{ use winit::{
application::ApplicationHandler, application::ApplicationHandler, event::*, event_loop::ActiveEventLoop, keyboard::PhysicalKey,
event::*, platform::modifier_supplement::KeyEventExtModifierSupplement, window::Window,
event_loop::ActiveEventLoop,
keyboard::{ModifiersState, PhysicalKey},
platform::wayland::WindowAttributesExtWayland,
window::Window,
}; };
struct FrameOutput { struct FrameOutput {
pub render_job: RenderJob, pub render_job: RenderJob,
pub should_continue: bool,
} }
pub struct AppState { pub struct AppState {
@@ -31,13 +27,12 @@ pub struct AppState {
pub input: InputState, pub input: InputState,
pub fonts: Fonts, pub fonts: Fonts,
pub texture_manager: WrappedTextureManager, pub texture_manager: WrappedTextureManager,
pub clipboard: Clipboard,
} }
impl AppState { impl AppState {
fn set_mouse_pos(&mut self, pos: PhysicalPoint<f32>) { fn set_mouse_pos(&mut self, pos: PhysicalPoint<f32>) {
self.input self.input
.set_mouse_pos(pos.to_logical(self.window.scale_factor)); .set_mouse_pos(pos.to_logical(self.window.scale_factor()));
} }
} }
@@ -45,6 +40,7 @@ pub struct App {
gfx_context: Option<GraphicsContext>, gfx_context: Option<GraphicsContext>,
state: AppState, state: AppState,
tessellator: Tessellator, tessellator: Tessellator,
needs_reconfigure: bool,
force_render: bool, force_render: bool,
current_mode: AppMode, current_mode: AppMode,
} }
@@ -58,10 +54,10 @@ impl App {
input: InputState::default(), input: InputState::default(),
fonts: Fonts::new(pob_font_definitions()), fonts: Fonts::new(pob_font_definitions()),
texture_manager: WrappedTextureManager::new(), texture_manager: WrappedTextureManager::new(),
clipboard: arboard::Clipboard::new()?,
}, },
tessellator: Tessellator::default(), tessellator: Tessellator::default(),
force_render: false, needs_reconfigure: true,
force_render: true,
current_mode: AppMode::Install(InstallMode::new()), current_mode: AppMode::Install(InstallMode::new()),
}) })
} }
@@ -99,12 +95,10 @@ impl App {
{ {
RenderJob::Skip RenderJob::Skip
} else { } else {
self.force_render = false;
let meshes = self.tessellator.convert_clipped_primitives( let meshes = self.tessellator.convert_clipped_primitives(
mode_output.primitives, mode_output.primitives,
font_atlas_size, font_atlas_size,
self.state.window.scale_factor, self.state.window.scale_factor(),
); );
RenderJob::Render { RenderJob::Render {
@@ -113,7 +107,10 @@ impl App {
} }
}; };
Ok(FrameOutput { render_job }) Ok(FrameOutput {
render_job,
should_continue: mode_output.should_continue,
})
} }
fn handle_event(&mut self, event: AppEvent) { fn handle_event(&mut self, event: AppEvent) {
@@ -121,40 +118,46 @@ impl App {
log::error!("{err}"); log::error!("{err}");
} }
} }
}
impl ApplicationHandler<GraphicsContext> for App { fn create_window(&mut self, event_loop: &ActiveEventLoop) -> anyhow::Result<()> {
fn resumed(&mut self, event_loop: &ActiveEventLoop) { let (title, _app_id) = match Game::current() {
let (title, app_id) = match Game::current() {
Game::Poe1 => ("Path of Building 1", "rusty-path-of-building-1"), Game::Poe1 => ("Path of Building 1", "rusty-path-of-building-1"),
Game::Poe2 => ("Path of Building 2", "rusty-path-of-building-2"), Game::Poe2 => ("Path of Building 2", "rusty-path-of-building-2"),
}; };
let window_attributes = Window::default_attributes() #[allow(unused_mut)]
let mut window_attributes = Window::default_attributes()
.with_title(title) .with_title(title)
.with_window_icon(load_icon()) // only works on windows and x11 .with_window_icon(load_icon());
// on wayland we need an `app_id` that matches the name of a `.desktop` entry to load
// the icon
.with_name(app_id, app_id);
let window = match event_loop.create_window(window_attributes) { #[cfg(target_os = "linux")]
Ok(window) => Arc::new(window), {
Err(err) => { use winit::platform::wayland::ActiveEventLoopExtWayland;
log::error!("{err}"); use winit::platform::x11::ActiveEventLoopExtX11;
event_loop.exit();
return; if event_loop.is_x11() {
use winit::platform::x11::WindowAttributesExtX11;
window_attributes = window_attributes.with_name(_app_id, _app_id);
} else if event_loop.is_wayland() {
use winit::platform::wayland::WindowAttributesExtWayland;
window_attributes = window_attributes.with_name(_app_id, _app_id);
} }
}; }
let window = event_loop.create_window(window_attributes)?;
let window = Arc::new(window);
self.state.window.set_window(Arc::clone(&window)); self.state.window.set_window(Arc::clone(&window));
self.gfx_context = Some(pollster::block_on(GraphicsContext::new(window))?);
self.gfx_context = match pollster::block_on(GraphicsContext::new(window)) { Ok(())
Ok(gfx) => Some(gfx), }
Err(err) => { }
log::error!("{err}");
event_loop.exit(); impl ApplicationHandler<GraphicsContext> for App {
return; fn resumed(&mut self, event_loop: &ActiveEventLoop) {
} if let Err(err) = self.create_window(event_loop) {
log::error!("{err}");
event_loop.exit();
} }
} }
@@ -178,26 +181,50 @@ impl ApplicationHandler<GraphicsContext> for App {
return; return;
} }
let render_job = match self.frame() { if self.needs_reconfigure {
Ok(FrameOutput { render_job }) => render_job, if let Some(ref mut gfx) = self.gfx_context {
Err(err) => { let size = gfx.window.inner_size();
log::error!("{err}"); gfx.resize(size.width, size.height);
event_loop.exit();
return;
} }
}; self.needs_reconfigure = false;
// Render at least one frame after reconfigure
self.force_render = true;
}
if let Some(ref mut gfx) = self.gfx_context { let is_focused = self.state.window.is_focused;
match gfx.render(render_job) { let is_hovered = self.state.window.is_hovered;
Ok(_) => {} let should_render = is_focused || is_hovered || self.force_render;
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => { if should_render {
let size = gfx.window.inner_size(); let FrameOutput {
gfx.resize(size.width, size.height); render_job,
self.force_render = true; should_continue,
} } = match self.frame() {
Ok(frame_output) => frame_output,
Err(err) => { Err(err) => {
log::error!("Unable to render: {err}"); log::error!("{err}");
event_loop.exit();
return;
}
};
if let Some(ref mut gfx) = self.gfx_context {
match gfx.render(render_job, self.state.window.scale_factor()) {
Ok(_) => {
self.force_render = should_continue;
if is_focused || is_hovered || should_continue {
self.state.window.request_redraw();
}
}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
self.needs_reconfigure = true;
self.state.window.request_redraw();
}
Err(err) => {
log::error!("Unable to render: {err}");
}
} }
} }
} }
@@ -205,27 +232,31 @@ impl ApplicationHandler<GraphicsContext> for App {
profiling::finish_frame!(); profiling::finish_frame!();
} }
WindowEvent::Resized(size) => { WindowEvent::Resized(size) => {
if let Some(ref mut gfx) = self.gfx_context {
gfx.resize(size.width, size.height);
self.force_render = true;
}
self.state.window.size = PhysicalSize::new(size.width, size.height); self.state.window.size = PhysicalSize::new(size.width, size.height);
self.needs_reconfigure = true;
}
WindowEvent::Focused(focused) => {
self.state.window.is_focused = focused;
if focused {
self.state.window.request_redraw();
}
} }
WindowEvent::ScaleFactorChanged { scale_factor, .. } => { WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
self.state.window.scale_factor = scale_factor as f32; self.state.window.set_scale_factor(scale_factor as f32);
} }
WindowEvent::KeyboardInput { WindowEvent::KeyboardInput {
event: event:
KeyEvent { key_event @ KeyEvent {
physical_key: PhysicalKey::Code(code), physical_key: PhysicalKey::Code(code),
logical_key,
state, state,
.. ..
}, },
.. ..
} => { } => {
// update input state
self.state.input.set_key_pressed(code, state.is_pressed()); self.state.input.set_key_pressed(code, state.is_pressed());
// forward KeyUp/KeyDown events
let event = match state { let event = match state {
ElementState::Pressed => AppEvent::KeyDown { code }, ElementState::Pressed => AppEvent::KeyDown { code },
ElementState::Released => AppEvent::KeyUp { code }, ElementState::Released => AppEvent::KeyUp { code },
@@ -233,25 +264,12 @@ impl ApplicationHandler<GraphicsContext> for App {
self.handle_event(event); self.handle_event(event);
// handle text input // handle text input
if state.is_pressed() { if let Some(text) = key_event.text_with_all_modifiers()
match logical_key { && state.is_pressed()
winit::keyboard::Key::Character(text) => { {
// only emit event if no modifier except Shift is pressed. for ch in text.chars() {
let modifiers = self.state.input.key_modifiers; let event = AppEvent::CharacterInput { ch };
if modifiers.difference(ModifiersState::SHIFT).is_empty() { self.handle_event(event);
for ch in text.chars() {
let event = AppEvent::CharacterInput { ch };
self.handle_event(event);
}
}
}
winit::keyboard::Key::Named(named) => {
if named == winit::keyboard::NamedKey::Space {
let event = AppEvent::CharacterInput { ch: ' ' };
self.handle_event(event);
}
}
_ => {}
} }
} }
} }
@@ -277,6 +295,13 @@ impl ApplicationHandler<GraphicsContext> for App {
let pos = PhysicalPoint::new(position.x as f32, position.y as f32); let pos = PhysicalPoint::new(position.x as f32, position.y as f32);
self.state.set_mouse_pos(pos); self.state.set_mouse_pos(pos);
} }
WindowEvent::CursorEntered { .. } => {
self.state.window.is_hovered = true;
self.state.window.request_redraw();
}
WindowEvent::CursorLeft { .. } => {
self.state.window.is_hovered = false;
}
WindowEvent::MouseWheel { delta, .. } => { WindowEvent::MouseWheel { delta, .. } => {
let delta = match delta { let delta = match delta {
MouseScrollDelta::LineDelta(_, y) => y, MouseScrollDelta::LineDelta(_, y) => y,
+4 -1
View File
@@ -9,7 +9,10 @@ pub struct Args {
#[arg(value_enum)] #[arg(value_enum)]
pub game: Game, pub game: Game,
pub build_path: Option<String>, #[arg(
help = "URL of build to import on startup. Needs to use custom protocol schema, e.g. `pob://pobbin/<id>`"
)]
pub import_url: Option<String>,
} }
#[derive(Debug, Clone, ValueEnum)] #[derive(Debug, Clone, ValueEnum)]
+81
View File
@@ -0,0 +1,81 @@
use raw_window_handle::RawDisplayHandle;
/// Abstraction over clipboard crates
///
/// `smithay_clipboard`: Used on wayland
/// `arboard`: All other platforms (check arboard docs for platform support)
pub struct Clipboard {
#[cfg(target_family = "unix")]
smithay: Option<smithay_clipboard::Clipboard>,
arboard: Option<arboard::Clipboard>,
// fallback if everything else fails. only supports intra-application copy/paste
fallback: Option<String>,
}
impl Clipboard {
pub fn new(_raw_display_handle: Option<RawDisplayHandle>) -> Self {
Self {
#[cfg(target_family = "unix")]
smithay: create_smithay_clipboard(_raw_display_handle),
arboard: create_arboard_clipboard(),
fallback: None,
}
}
/// Sets the text content of clipboard
pub fn set_text(&mut self, text: String) {
#[cfg(target_family = "unix")]
if let Some(clipboard) = &mut self.smithay {
clipboard.store(text);
return;
}
if let Some(clipboard) = &mut self.arboard {
let _ = clipboard.set_text(text);
return;
}
self.fallback = Some(text);
}
/// Gets the text content of clipboard
pub fn get_text(&mut self) -> Option<String> {
#[cfg(target_family = "unix")]
if let Some(clipboard) = &mut self.smithay {
return clipboard.load().ok();
}
if let Some(clipboard) = &mut self.arboard {
return clipboard.get_text().ok();
}
if let Some(text) = &self.fallback {
return Some(text.clone());
}
None
}
}
#[cfg(target_family = "unix")]
fn create_smithay_clipboard(
raw_display_handle: Option<RawDisplayHandle>,
) -> Option<smithay_clipboard::Clipboard> {
if let Some(RawDisplayHandle::Wayland(handle)) = raw_display_handle {
log::debug!("Creating smithay clipboard...");
Some(unsafe { smithay_clipboard::Clipboard::new(handle.display.as_ptr()) })
} else {
None
}
}
fn create_arboard_clipboard() -> Option<arboard::Clipboard> {
log::debug!("Creating arboard clipboard...");
match arboard::Clipboard::new() {
Ok(clipboard) => Some(clipboard),
Err(err) => {
log::warn!("Failed to create arboard clipboard: {err}");
None
}
}
}
+8 -7
View File
@@ -144,11 +144,13 @@ impl GraphicsContext {
} }
} }
pub fn render(&mut self, render_job: RenderJob) -> Result<(), wgpu::SurfaceError> { pub fn render(
&mut self,
render_job: RenderJob,
scale_factor: f32,
) -> Result<(), wgpu::SurfaceError> {
profiling::scope!("render"); profiling::scope!("render");
self.window.request_redraw();
if !self.is_surface_configured { if !self.is_surface_configured {
return Ok(()); return Ok(());
} }
@@ -174,7 +176,6 @@ impl GraphicsContext {
} = render_job } = render_job
{ {
let screen_size = PhysicalSize::new(self.config.width, self.config.height); let screen_size = PhysicalSize::new(self.config.width, self.config.height);
let pixels_per_point = self.window.as_ref().scale_factor() as f32;
// upload new textures // upload new textures
self.renderer self.renderer
@@ -186,7 +187,7 @@ impl GraphicsContext {
&self.queue, &self.queue,
&meshes, &meshes,
screen_size, screen_size,
pixels_per_point, scale_factor,
); );
let rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
@@ -214,10 +215,10 @@ impl GraphicsContext {
&mut rpass.forget_lifetime(), &mut rpass.forget_lifetime(),
&meshes, &meshes,
screen_size, screen_size,
pixels_per_point, scale_factor,
); );
self.renderer.free_textures(&textures_delta) self.renderer.free_textures(&textures_delta);
} }
{ {
+214 -8
View File
@@ -7,7 +7,6 @@ use crate::{
mode::{AppEvent, ModeFrameOutput, ModeTransition}, mode::{AppEvent, ModeFrameOutput, ModeTransition},
renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive}, renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive},
}; };
use anyhow::bail;
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use parley::{FontFamily, GenericFamily}; use parley::{FontFamily, GenericFamily};
use regex::Regex; use regex::Regex;
@@ -73,6 +72,7 @@ impl InstallMode {
Ok(ModeFrameOutput { Ok(ModeFrameOutput {
primitives, primitives,
can_elide: false, can_elide: false,
should_continue: true,
}) })
} }
@@ -137,7 +137,7 @@ impl InstallMode {
}; };
job.append(&progress_text, Srgba::WHITE); job.append(&progress_text, Srgba::WHITE);
let layout = app_state.fonts.layout(job, app_state.window.scale_factor); let layout = app_state.fonts.layout(job, app_state.window.scale_factor());
// center text vertically and horizontally // center text vertically and horizontally
let screen_size = app_state.window.logical_size().cast::<f32>(); let screen_size = app_state.window.logical_size().cast::<f32>();
@@ -160,10 +160,10 @@ fn install<P: AsRef<Path>>(
progress_tx: &mpsc::Sender<Progress>, progress_tx: &mpsc::Sender<Progress>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
// Skip installation if version file exists // Skip installation if version file exists
let current_version = env!("CARGO_PKG_VERSION");
let version_file_path = target_dir.as_ref().join("rpob.version"); let version_file_path = target_dir.as_ref().join("rpob.version");
if version_file_path.exists() { if version_file_path.exists() {
let old_version = fs::read_to_string(&version_file_path).unwrap(); let old_version = fs::read_to_string(&version_file_path).unwrap();
let current_version = env!("CARGO_PKG_VERSION");
if old_version != current_version { if old_version != current_version {
log::info!("New version detected: {old_version} -> {current_version}"); log::info!("New version detected: {old_version} -> {current_version}");
@@ -173,7 +173,11 @@ fn install<P: AsRef<Path>>(
return Ok(()); return Ok(());
} }
download_path_of_building(&target_dir, progress_tx)?; let compatibility_info = fetch_compatibility_info()?;
let needed_pob_version = highest_supported_pob_version(&compatibility_info, current_version)
.ok_or_else(|| anyhow::anyhow!("Unable to determine supported PoB version"))?;
download_path_of_building(&target_dir, needed_pob_version, progress_tx)?;
replace_updatecheck(&target_dir)?; replace_updatecheck(&target_dir)?;
set_branch_and_platform(&target_dir)?; set_branch_and_platform(&target_dir)?;
@@ -183,9 +187,73 @@ fn install<P: AsRef<Path>>(
Ok(()) Ok(())
} }
/// Downloads latest release of Path of Building #[derive(Debug)]
struct VersionReq {
pob_ver: String,
min_rpob_ver: String,
}
/// Fetches and evaluates compatibility table
fn fetch_compatibility_info() -> anyhow::Result<Vec<VersionReq>> {
let compatibility_info_file_name = match Game::current() {
Game::Poe1 => "Compatibility_pob1.lua",
Game::Poe2 => "Compatibility_pob2.lua",
};
let compatibility_info_file_url = &format!(
"https://raw.githubusercontent.com/{REPO_NAME}/main/{}",
compatibility_info_file_name
);
let compatibility_info_file = download_file_contents(compatibility_info_file_url)?;
// Load and evaluate compatibility file contents as Lua code
let lua = mlua::Lua::new();
let compatibility_table = lua.load(compatibility_info_file).eval::<mlua::Table>()?;
// Compatibility table maps PoB version to minimum required Rusty PoB version
Ok(compatibility_table
.pairs::<String, String>()
.filter_map(|p| p.ok())
.map(|(pob_version, min_req_rpob_ver)| VersionReq {
pob_ver: pob_version,
min_rpob_ver: min_req_rpob_ver,
})
.collect())
}
/// Determines highest PoB version supported by given Rusty PoB version
fn highest_supported_pob_version<'a>(
compatibility_info: &'a Vec<VersionReq>,
rpob_version: &str,
) -> Option<&'a str> {
let mut highest_pob_version = None;
for VersionReq {
pob_ver,
min_rpob_ver,
} in compatibility_info
{
if is_higher_version(min_rpob_ver, rpob_version).unwrap_or(false) {
// found PoB version that meets our minimum requirements
match highest_pob_version {
// make sure it is the highest PoB version possible
Some(h_pob_version) => {
if is_higher_version(h_pob_version, pob_ver).unwrap_or(false) {
highest_pob_version = Some(pob_ver.as_str());
}
}
None => highest_pob_version = Some(pob_ver.as_str()),
}
}
}
highest_pob_version
}
/// Downloads specified version of Path of Building
fn download_path_of_building<P: AsRef<Path>>( fn download_path_of_building<P: AsRef<Path>>(
target_dir: P, target_dir: P,
pob_version: &str,
progress_tx: &mpsc::Sender<Progress>, progress_tx: &mpsc::Sender<Progress>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
log::info!("Downloading Path of Building assets..."); log::info!("Downloading Path of Building assets...");
@@ -195,8 +263,8 @@ fn download_path_of_building<P: AsRef<Path>>(
Game::Poe2 => "PathOfBuildingCommunity/PathOfBuilding-PoE2", Game::Poe2 => "PathOfBuildingCommunity/PathOfBuilding-PoE2",
}; };
let url = format!( let url = format!(
"https://github.com/{}/archive/refs/heads/master.tar.gz", "https://github.com/{}/archive/refs/tags/v{}.tar.gz",
repo repo, pob_version
); );
let mut response = http_get_with_backoff(&url)?; let mut response = http_get_with_backoff(&url)?;
@@ -302,6 +370,7 @@ fn set_branch_and_platform<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()>
Ok(()) Ok(())
} }
/// Downloads file and saves it to given path
fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()> { fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()> {
let mut response = http_get_with_backoff(url)?; let mut response = http_get_with_backoff(url)?;
@@ -311,7 +380,19 @@ fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()>
copy(&mut body.as_reader(), &mut file)?; copy(&mut body.as_reader(), &mut file)?;
Ok(()) Ok(())
} else { } else {
bail!("Unable to download: {}", url); anyhow::bail!("Unable to download: {}", url);
}
}
/// Downloads file and returns contents as string
fn download_file_contents(url: &str) -> anyhow::Result<String> {
let mut response = http_get_with_backoff(url)?;
if response.status().is_success() {
let body = response.body_mut();
Ok(body.read_to_string()?)
} else {
anyhow::bail!("Unable to download: {}", url);
} }
} }
@@ -432,3 +513,128 @@ fn http_get_with_backoff(url: &str) -> anyhow::Result<Response<ureq::Body>> {
return Ok(resp); return Ok(resp);
} }
} }
/// Compares two SemVer versions and returns true if v2 is higher or equal than v1
fn is_higher_version(v1: &str, v2: &str) -> anyhow::Result<bool> {
let re = Regex::new(r"^(\d+)\.(\d+)\.(\d+)$").unwrap();
let parse_version = |v: &str| -> anyhow::Result<(u32, u32, u32)> {
let caps = re
.captures(v)
.ok_or_else(|| anyhow::anyhow!("Invalid semver format: {}", v))?;
let major = caps[1].parse::<u32>().unwrap();
let minor = caps[2].parse::<u32>().unwrap();
let patch = caps[3].parse::<u32>().unwrap();
Ok((major, minor, patch))
};
let (major1, minor1, patch1) = parse_version(v1)?;
let (major2, minor2, patch2) = parse_version(v2)?;
Ok(major2 > major1
|| (major2 == major1 && minor2 > minor1)
|| (major2 == major1 && minor2 == minor1 && patch2 >= patch1))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_major_version() {
assert_eq!(is_higher_version("1.0.0", "2.0.0").unwrap(), true);
assert_eq!(is_higher_version("2.0.0", "1.0.0").unwrap(), false);
}
#[test]
fn test_minor_version() {
assert_eq!(is_higher_version("1.5.0", "1.6.0").unwrap(), true);
assert_eq!(is_higher_version("1.10.0", "1.9.0").unwrap(), false);
}
#[test]
fn test_patch_version() {
assert_eq!(is_higher_version("1.0.3", "1.0.4").unwrap(), true);
assert_eq!(is_higher_version("1.0.10", "1.0.9").unwrap(), false);
}
#[test]
fn test_same_version() {
assert_eq!(is_higher_version("1.5.3", "1.5.3").unwrap(), true);
}
#[test]
fn test_invalid_semver_format() {
assert!(is_higher_version("1.0", "2.0.0").is_err());
assert!(is_higher_version("1.0.0", "2.0").is_err());
assert!(is_higher_version("invalid", "2.0.0").is_err());
assert!(is_higher_version("1.0.0", "a.bb.ccc").is_err());
}
#[test]
fn test_highest_supported_pob_ver() {
let compat_info = vec![
VersionReq {
pob_ver: String::from("2.56.0"),
min_rpob_ver: String::from("0.1.0"),
},
// compat info might not be sorted by pob_version
VersionReq {
pob_ver: String::from("2.58.0"),
min_rpob_ver: String::from("0.2.6"),
},
VersionReq {
pob_ver: String::from("2.57.0"),
min_rpob_ver: String::from("0.2.6"),
},
VersionReq {
pob_ver: String::from("2.58.1"),
min_rpob_ver: String::from("0.2.8"),
},
VersionReq {
pob_ver: String::from("2.59.0"),
min_rpob_ver: String::from("0.2.9"),
},
VersionReq {
pob_ver: String::from("2.59.1"),
min_rpob_ver: String::from("0.2.10"),
},
VersionReq {
pob_ver: String::from("2.59.2"),
min_rpob_ver: String::from("0.2.10"),
},
];
assert_eq!(highest_supported_pob_version(&compat_info, "0.0.2"), None);
assert_eq!(highest_supported_pob_version(&compat_info, "a.b.c"), None);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.1.0"),
Some("2.56.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.0"),
Some("2.56.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.6"),
Some("2.58.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.7"),
Some("2.58.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.8"),
Some("2.58.1")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.9"),
Some("2.59.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.10"),
Some("2.59.2")
);
}
}
+31 -14
View File
@@ -12,9 +12,8 @@ use crate::{
util::change_working_directory, util::change_working_directory,
window::WindowState, window::WindowState,
}; };
use arboard::Clipboard;
use clap::Parser; use clap::Parser;
use mlua::{Lua, Result as LuaResult, Table}; use mlua::{Function, Lua, Result as LuaResult, Table, ThreadStatus};
use std::{ use std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
path::PathBuf, path::PathBuf,
@@ -45,11 +44,10 @@ macro_rules! ctx_accessor {
/// Before executing any lua code, we need to "plug" the references into /// Before executing any lua code, we need to "plug" the references into
/// the Context and "unplug" them afterwards. /// the Context and "unplug" them afterwards.
pub struct Context { pub struct Context {
window: Cell<*const WindowState>, window: Cell<*mut WindowState>,
input: Cell<*const InputState>, input: Cell<*const InputState>,
fonts: Cell<*mut Fonts>, fonts: Cell<*mut Fonts>,
texture_manager: Cell<*mut WrappedTextureManager>, texture_manager: Cell<*mut WrappedTextureManager>,
clipboard: Cell<*mut Clipboard>,
current_working_dir: Cell<*mut PathBuf>, current_working_dir: Cell<*mut PathBuf>,
layers: Cell<*mut Layers>, layers: Cell<*mut Layers>,
needs_restart: Cell<*mut bool>, needs_restart: Cell<*mut bool>,
@@ -59,11 +57,10 @@ pub struct Context {
impl Context { impl Context {
pub fn new() -> &'static Self { pub fn new() -> &'static Self {
Box::leak(Box::new(Self { Box::leak(Box::new(Self {
window: Cell::new(std::ptr::null()), window: Cell::new(std::ptr::null_mut()),
input: Cell::new(std::ptr::null()), input: Cell::new(std::ptr::null()),
fonts: Cell::new(std::ptr::null_mut()), fonts: Cell::new(std::ptr::null_mut()),
texture_manager: Cell::new(std::ptr::null_mut()), texture_manager: Cell::new(std::ptr::null_mut()),
clipboard: Cell::new(std::ptr::null_mut()),
current_working_dir: Cell::new(std::ptr::null_mut()), current_working_dir: Cell::new(std::ptr::null_mut()),
layers: Cell::new(std::ptr::null_mut()), layers: Cell::new(std::ptr::null_mut()),
needs_restart: Cell::new(std::ptr::null_mut()), needs_restart: Cell::new(std::ptr::null_mut()),
@@ -72,11 +69,10 @@ impl Context {
} }
pub fn set(&self, ctx: &mut PoBContext) { pub fn set(&self, ctx: &mut PoBContext) {
self.window.set(&ctx.app.window); self.window.set(&mut ctx.app.window);
self.input.set(&ctx.app.input); self.input.set(&ctx.app.input);
self.fonts.set(&mut ctx.app.fonts); self.fonts.set(&mut ctx.app.fonts);
self.texture_manager.set(&mut ctx.app.texture_manager); self.texture_manager.set(&mut ctx.app.texture_manager);
self.clipboard.set(&mut ctx.app.clipboard);
self.current_working_dir self.current_working_dir
.set(&mut ctx.pob.current_working_dir); .set(&mut ctx.pob.current_working_dir);
self.layers.set(&mut ctx.pob.layers); self.layers.set(&mut ctx.pob.layers);
@@ -85,22 +81,20 @@ impl Context {
} }
pub fn clear(&self) { pub fn clear(&self) {
self.window.set(std::ptr::null()); self.window.set(std::ptr::null_mut());
self.input.set(std::ptr::null()); self.input.set(std::ptr::null());
self.fonts.set(std::ptr::null_mut()); self.fonts.set(std::ptr::null_mut());
self.texture_manager.set(std::ptr::null_mut()); self.texture_manager.set(std::ptr::null_mut());
self.clipboard.set(std::ptr::null_mut());
self.current_working_dir.set(std::ptr::null_mut()); self.current_working_dir.set(std::ptr::null_mut());
self.layers.set(std::ptr::null_mut()); self.layers.set(std::ptr::null_mut());
self.needs_restart.set(std::ptr::null_mut()); self.needs_restart.set(std::ptr::null_mut());
self.is_dpi_aware.set(std::ptr::null_mut()); self.is_dpi_aware.set(std::ptr::null_mut());
} }
ctx_accessor!(window: &WindowState); ctx_accessor!(window: &mut WindowState);
ctx_accessor!(input: &InputState); ctx_accessor!(input: &InputState);
ctx_accessor!(fonts: &mut Fonts); ctx_accessor!(fonts: &mut Fonts);
ctx_accessor!(texture_manager: &mut WrappedTextureManager); ctx_accessor!(texture_manager: &mut WrappedTextureManager);
ctx_accessor!(clipboard: &mut Clipboard);
ctx_accessor!(current_working_dir: &mut PathBuf); ctx_accessor!(current_working_dir: &mut PathBuf);
ctx_accessor!(layers: &mut Layers); ctx_accessor!(layers: &mut Layers);
ctx_accessor!(needs_restart: &mut bool); ctx_accessor!(needs_restart: &mut bool);
@@ -176,9 +170,9 @@ impl LuaInstance {
// SAFETY: use `unsafe_new` to allow loading of C modules // SAFETY: use `unsafe_new` to allow loading of C modules
let lua = unsafe { Lua::unsafe_new() }; let lua = unsafe { Lua::unsafe_new() };
// expose build arg to lua // expose import url to lua
let args = Args::parse(); let args = Args::parse();
let args_table = lua.create_sequence_from(std::iter::once(args.build_path))?; let args_table = lua.create_sequence_from(std::iter::once(args.import_url))?;
lua.globals().set("arg", args_table)?; lua.globals().set("arg", args_table)?;
Self::register_package_paths(&lua)?; Self::register_package_paths(&lua)?;
@@ -234,6 +228,29 @@ impl LuaInstance {
} }
} }
pub fn has_running_subscripts(&self) -> bool {
self.subscript_manager.borrow().has_running_subscripts()
}
pub fn has_active_coroutine(&self) -> bool {
self.get_coroutines().is_ok_and(|coroutines| {
coroutines.pairs::<mlua::Thread, bool>().any(|pair| {
pair.is_ok_and(|(thread, _)| {
matches!(
thread.status(),
ThreadStatus::Resumable | ThreadStatus::Running
)
})
})
})
}
fn get_coroutines(&self) -> LuaResult<Table> {
let coroutine_module: Table = self.lua.globals().get("coroutine")?;
let list_func: Function = coroutine_module.get("_list")?;
list_func.call::<Table>(())
}
pub fn handle_event(&self, event: PoBEvent, pob_ctx: &mut PoBContext) -> LuaResult<()> { pub fn handle_event(&self, event: PoBEvent, pob_ctx: &mut PoBContext) -> LuaResult<()> {
profiling::scope!("handle_event", format!("{}", event)); profiling::scope!("handle_event", format!("{}", event));
+1
View File
@@ -8,6 +8,7 @@ use winit::event_loop::EventLoop;
mod api; mod api;
mod app; mod app;
mod args; mod args;
mod clipboard;
mod color; mod color;
mod dpi; mod dpi;
mod fonts; mod fonts;
+3
View File
@@ -34,6 +34,9 @@ pub enum ModeTransition {
pub struct ModeFrameOutput { pub struct ModeFrameOutput {
pub primitives: Box<dyn Iterator<Item = ClippedPrimitive>>, pub primitives: Box<dyn Iterator<Item = ClippedPrimitive>>,
pub can_elide: bool, pub can_elide: bool,
/// Indicates that this should be redrawn again next frame even if user is not interacting with
/// window
pub should_continue: bool,
} }
pub enum AppMode { pub enum AppMode {
+6
View File
@@ -68,9 +68,14 @@ impl PoBMode {
let identical = layers_hash == self.previous_layers_hash; let identical = layers_hash == self.previous_layers_hash;
self.previous_layers_hash = layers_hash; self.previous_layers_hash = layers_hash;
let has_active_subscript = self.lua_instance.has_running_subscripts();
let has_active_coroutine = self.lua_instance.has_active_coroutine();
let should_continue = has_active_subscript || has_active_coroutine;
Ok(ModeFrameOutput { Ok(ModeFrameOutput {
primitives: self.state.layers.consume_layers(), primitives: self.state.layers.consume_layers(),
can_elide: identical, can_elide: identical,
should_continue,
}) })
} }
@@ -133,6 +138,7 @@ impl PoBMode {
} }
} }
AppEvent::CharacterInput { ch } => { AppEvent::CharacterInput { ch } => {
let ch = if ch.is_ascii() { ch } else { '?' };
self.lua_instance self.lua_instance
.handle_event(PoBEvent::Char(ch), &mut ctx)?; .handle_event(PoBEvent::Char(ch), &mut ctx)?;
} }
+5 -1
View File
@@ -74,6 +74,10 @@ impl SubscriptManager {
results results
} }
pub fn has_running_subscripts(&self) -> bool {
!self.scripts.is_empty()
}
} }
enum SubscriptCall { enum SubscriptCall {
@@ -305,7 +309,7 @@ pub fn register_subscript_globals(
"IsSubScriptRunning", "IsSubScriptRunning",
lua.create_function(is_subscript_running)?, lua.create_function(is_subscript_running)?,
)?; )?;
globals.set("IsSubScriptRunning", lua.create_function(abort_subscript)?)?; globals.set("AbortSubScript", lua.create_function(abort_subscript)?)?;
Ok(()) Ok(())
} }
+47 -5
View File
@@ -1,14 +1,21 @@
use crate::{
clipboard::Clipboard,
dpi::{ConvertToLogical, LogicalSize, PhysicalSize},
};
use raw_window_handle::HasDisplayHandle;
use std::sync::Arc; use std::sync::Arc;
use winit::window::Window; use winit::window::Window;
use crate::dpi::{ConvertToLogical, LogicalSize, PhysicalSize};
pub struct WindowState { pub struct WindowState {
// NOTE: clipboard needs to be destroyed before window
clipboard: Option<Clipboard>,
pub window: Option<Arc<Window>>, pub window: Option<Arc<Window>>,
pub size: PhysicalSize<u32>, pub size: PhysicalSize<u32>,
pub scale_factor: f32, scale_factor: f32,
pub scale_factor_override: Option<f32>,
pending_window_title: std::cell::Cell<Option<String>>, pending_window_title: std::cell::Cell<Option<String>>,
pub is_hovered: bool,
pub is_focused: bool,
} }
impl Default for WindowState { impl Default for WindowState {
@@ -17,7 +24,11 @@ impl Default for WindowState {
window: None, window: None,
size: Default::default(), size: Default::default(),
scale_factor: 1.0, scale_factor: 1.0,
scale_factor_override: None,
pending_window_title: std::cell::Cell::new(None), pending_window_title: std::cell::Cell::new(None),
clipboard: None,
is_hovered: true,
is_focused: true,
} }
} }
} }
@@ -31,6 +42,9 @@ impl WindowState {
let winit::dpi::PhysicalSize { width, height } = window.inner_size(); let winit::dpi::PhysicalSize { width, height } = window.inner_size();
self.size = PhysicalSize::new(width, height); self.size = PhysicalSize::new(width, height);
self.scale_factor = window.scale_factor() as f32; self.scale_factor = window.scale_factor() as f32;
let raw_display_handle = window.display_handle().ok().map(|h| h.as_raw());
self.clipboard = Some(Clipboard::new(raw_display_handle));
self.window = Some(window); self.window = Some(window);
} }
@@ -43,7 +57,15 @@ impl WindowState {
} }
pub fn logical_size(&self) -> LogicalSize<u32> { pub fn logical_size(&self) -> LogicalSize<u32> {
self.size.to_logical(self.scale_factor) self.size.to_logical(self.scale_factor())
}
pub fn scale_factor(&self) -> f32 {
self.scale_factor_override.unwrap_or(self.scale_factor)
}
pub fn set_scale_factor(&mut self, scale_factor: f32) {
self.scale_factor = scale_factor;
} }
pub fn focus(&self) { pub fn focus(&self) {
@@ -51,4 +73,24 @@ impl WindowState {
window.focus_window(); window.focus_window();
} }
} }
pub fn set_clipboard_text(&mut self, text: String) {
if let Some(clipboard) = &mut self.clipboard {
clipboard.set_text(text);
}
}
pub fn get_clipboard_text(&mut self) -> Option<String> {
if let Some(clipboard) = &mut self.clipboard {
clipboard.get_text()
} else {
None
}
}
pub fn request_redraw(&self) {
if let Some(ref window) = self.window {
window.request_redraw();
}
}
} }