Clearwake / app / commits / 50233c80
App source: current code new
written by Branchwell · 50233c80eae1be554eda84594e30c13efcafb9d4
47 files changed
.gitignore added
| 1 | + /target | |
| 2 | + /crates/*/target | |
| 3 | + /crates/clearwake-fetch/build/.tmp | |
| 4 | + /dist | |
| 5 | + *.ppm | |
| 6 | + /web/clearwake.js | |
| 7 | + /web/clearwake_bg.wasm | |
| 8 | + /crates/clearwake-fetch/build |
Cargo.lock added
| 1 | + # This file is automatically @generated by Cargo. | |
| 2 | + # It is not intended for manual editing. | |
| 3 | + version = 4 | |
| 4 | + | |
| 5 | + [[package]] | |
| 6 | + name = "ab_glyph" | |
| 7 | + version = "0.2.32" | |
| 8 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | + checksum = "01c0457472c38ea5bd1c3b5ada5e368271cb550be7a4ca4a0b4634e9913f6cc2" | |
| 10 | + dependencies = [ | |
| 11 | + "ab_glyph_rasterizer", | |
| 12 | + "owned_ttf_parser", | |
| 13 | + ] | |
| 14 | + | |
| 15 | + [[package]] | |
| 16 | + name = "ab_glyph_rasterizer" | |
| 17 | + version = "0.1.10" | |
| 18 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 19 | + checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618" | |
| 20 | + | |
| 21 | + [[package]] | |
| 22 | + name = "accesskit" | |
| 23 | + version = "0.25.2" | |
| 24 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 25 | + checksum = "4e883d1d28c5fd5568c79ed2d2bd48d9f2fd3945c8974ed0f53690ceddb051be" | |
| 26 | + dependencies = [ | |
| 27 | + "enumn", | |
| 28 | + "serde", | |
| 29 | + "uuid", | |
| 30 | + ] | |
| 31 | + | |
| 32 | + [[package]] | |
| 33 | + name = "accesskit_atspi_common" | |
| 34 | + version = "0.21.1" | |
| 35 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 36 | + checksum = "24f5baf62e34a4a6c30e3d697e4782f821a7337049c44c3b40576a27dfbb580d" | |
| 37 | + dependencies = [ | |
| 38 | + "accesskit", | |
| 39 | + "accesskit_consumer", | |
| 40 | + "atspi-common", | |
| 41 | + "phf", | |
| 42 | + "serde", | |
| 43 | + "zvariant", | |
| 44 | + ] | |
| 45 | + | |
| 46 | + [[package]] | |
| 47 | + name = "accesskit_consumer" | |
| 48 | + version = "0.39.2" | |
| 49 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 50 | + checksum = "f3da8f27636015191b2264ee1df681503170a632cafd832fdc1edfdd4e3a2fd3" | |
| 51 | + dependencies = [ | |
| 52 | + "accesskit", | |
| 53 | + "hashbrown 0.17.2", | |
| 54 | + ] | |
| 55 | + | |
| 56 | + [[package]] | |
| 57 | + name = "accesskit_ios" | |
| 58 | + version = "0.2.2" | |
| 59 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 60 | + checksum = "a5280724673bbfa8b30a838c013500b719392989be3b97c5a9964062c252c232" | |
| 61 | + dependencies = [ | |
| 62 | + "accesskit", | |
| 63 | + "accesskit_consumer", | |
| 64 | + "hashbrown 0.17.2", | |
| 65 | + "objc2 0.5.3", | |
| 66 | + "objc2-foundation 0.2.2", | |
| 67 | + "objc2-ui-kit 0.2.2", | |
| 68 | + ] | |
| 69 | + | |
| 70 | + [[package]] | |
| 71 | + name = "accesskit_macos" | |
| 72 | + version = "0.27.2" | |
| 73 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 74 | + checksum = "123828ceeec755b05255e3976cb0852993202de98a0626c97dd8d34246991f84" | |
| 75 | + dependencies = [ | |
| 76 | + "accesskit", | |
| 77 | + "accesskit_consumer", | |
| 78 | + "hashbrown 0.17.2", | |
| 79 | + "objc2 0.5.3", | |
| 80 | + "objc2-app-kit 0.2.2", | |
| 81 | + "objc2-foundation 0.2.2", | |
| 82 | + ] | |
| 83 | + | |
| 84 | + [[package]] | |
| 85 | + name = "accesskit_unix" | |
| 86 | + version = "0.24.1" | |
| 87 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 88 | + checksum = "30d5192871228c54f1b0fb4a85cef000e11a3804f25d2165f14afa0daa67f3f6" | |
| 89 | + dependencies = [ | |
| 90 | + "accesskit", | |
| 91 | + "accesskit_atspi_common", | |
| 92 | + "async-channel", | |
| 93 | + "async-executor", | |
| 94 | + "async-task", | |
| 95 | + "atspi", | |
| 96 | + "futures-lite", | |
| 97 | + "futures-util", | |
| 98 | + "serde", | |
| 99 | + "zbus", | |
| 100 | + ] | |
| 101 | + | |
| 102 | + [[package]] | |
| 103 | + name = "accesskit_windows" | |
| 104 | + version = "0.35.2" | |
| 105 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 106 | + checksum = "498668b90da9995302a0055aaecad4756932333da2ddef6baee1c00844c430fc" | |
| 107 | + dependencies = [ | |
| 108 | + "accesskit", | |
| 109 | + "accesskit_consumer", | |
| 110 | + "hashbrown 0.17.2", | |
| 111 | + "static_assertions", | |
| 112 | + "windows", | |
| 113 | + "windows-core", | |
| 114 | + ] | |
| 115 | + | |
| 116 | + [[package]] | |
| 117 | + name = "accesskit_winit" | |
| 118 | + version = "0.34.2" | |
| 119 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 120 | + checksum = "cd4ab4437b520ff03088fbe48676a11e7d44a929535e64b31432c1073e48dbcc" | |
| 121 | + dependencies = [ | |
| 122 | + "accesskit", | |
| 123 | + "accesskit_ios", | |
| 124 | + "accesskit_macos", | |
| 125 | + "accesskit_unix", | |
| 126 | + "accesskit_windows", | |
| 127 | + "raw-window-handle", | |
| 128 | + "winit", | |
| 129 | + ] | |
| 130 | + | |
| 131 | + [[package]] | |
| 132 | + name = "adler2" | |
| 133 | + version = "2.0.1" | |
| 134 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 135 | + checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" | |
| 136 | + | |
| 137 | + [[package]] | |
| 138 | + name = "ahash" | |
| 139 | + version = "0.8.15" | |
| 140 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 141 | + checksum = "3019c0b8d883a8a17df3129e417ef463c087807d245e8881a31d583dee1c0519" | |
| 142 | + dependencies = [ | |
| 143 | + "cfg-if", | |
| 144 | + "getrandom 0.4.3", | |
| 145 | + "once_cell", | |
| 146 | + "serde", | |
| 147 | + "version_check", | |
| 148 | + "zerocopy", | |
| 149 | + ] | |
| 150 | + | |
| 151 | + [[package]] | |
| 152 | + name = "android-activity" | |
| 153 | + version = "0.6.1" | |
| 154 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 155 | + checksum = "0f2a1bb052857d5dd49572219344a7332b31b76405648eabac5bc68978251bcd" | |
| 156 | + dependencies = [ | |
| 157 | + "android-properties", | |
| 158 | + "bitflags 2.13.2", | |
| 159 | + "cc", | |
| 160 | + "jni", | |
| 161 | + "libc", | |
| 162 | + "log", | |
| 163 | + "ndk", | |
| 164 | + "ndk-context", | |
| 165 | + "ndk-sys", | |
| 166 | + "num_enum", | |
| 167 | + "thiserror 2.0.21", | |
| 168 | + ] | |
| 169 | + | |
| 170 | + [[package]] | |
| 171 | + name = "android-properties" | |
| 172 | + version = "0.2.2" | |
| 173 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 174 | + checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" | |
| 175 | + | |
| 176 | + [[package]] | |
| 177 | + name = "arboard" | |
| 178 | + version = "3.7.0" | |
| 179 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 180 | + checksum = "aeb9553e62312c8756a5979254fc6d7da8bbeb5986a1e17037fab932f7037917" | |
| 181 | + dependencies = [ | |
| 182 | + "clipboard-win", | |
| 183 | + "image", | |
| 184 | + "log", | |
| 185 | + "objc2 0.6.5", | |
| 186 | + "objc2-app-kit 0.3.2", | |
| 187 | + "objc2-core-foundation", | |
| 188 | + "objc2-core-graphics", | |
| 189 | + "objc2-foundation 0.3.2", | |
| 190 | + "parking_lot", | |
| 191 | + "percent-encoding", | |
| 192 | + "windows-sys 0.52.0", | |
| 193 | + "wl-clipboard-rs", | |
| 194 | + "x11rb", | |
| 195 | + ] | |
| 196 | + | |
| 197 | + [[package]] | |
| 198 | + name = "arrayref" | |
| 199 | + version = "0.3.9" | |
| 200 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 201 | + checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" | |
| 202 | + | |
| 203 | + [[package]] | |
| 204 | + name = "arrayvec" | |
| 205 | + version = "0.7.9" | |
| 206 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 207 | + checksum = "47a64a0fd06e123e9e3cf3ad01432af17dcab8185e8023edcf184fe696f9675d" | |
| 208 | + | |
| 209 | + [[package]] | |
| 210 | + name = "as-raw-xcb-connection" | |
| 211 | + version = "1.0.1" | |
| 212 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 213 | + checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b" | |
| 214 | + | |
| 215 | + [[package]] | |
| 216 | + name = "async-broadcast" | |
| 217 | + version = "0.7.2" | |
| 218 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 219 | + checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" | |
| 220 | + dependencies = [ | |
| 221 | + "event-listener", | |
| 222 | + "event-listener-strategy", | |
| 223 | + "futures-core", | |
| 224 | + "pin-project-lite", | |
| 225 | + ] | |
| 226 | + | |
| 227 | + [[package]] | |
| 228 | + name = "async-channel" | |
| 229 | + version = "2.5.0" | |
| 230 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 231 | + checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" | |
| 232 | + dependencies = [ | |
| 233 | + "concurrent-queue", | |
| 234 | + "event-listener-strategy", | |
| 235 | + "futures-core", | |
| 236 | + "pin-project-lite", | |
| 237 | + ] | |
| 238 | + | |
| 239 | + [[package]] | |
| 240 | + name = "async-executor" | |
| 241 | + version = "1.14.1" | |
| 242 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 243 | + checksum = "f426a31126c735126297bc5ea7a521263c9faff4f63ca415267ee625651c4f37" | |
| 244 | + dependencies = [ | |
| 245 | + "async-task", | |
| 246 | + "concurrent-queue", | |
| 247 | + "fastrand", | |
| 248 | + "futures-lite", | |
| 249 | + "pin-project-lite", | |
| 250 | + "slab", | |
| 251 | + ] | |
| 252 | + | |
| 253 | + [[package]] | |
| 254 | + name = "async-io" | |
| 255 | + version = "2.6.0" | |
| 256 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 257 | + checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" | |
| 258 | + dependencies = [ | |
| 259 | + "autocfg", | |
| 260 | + "cfg-if", | |
| 261 | + "concurrent-queue", | |
| 262 | + "futures-io", | |
| 263 | + "futures-lite", | |
| 264 | + "parking", | |
| 265 | + "polling", | |
| 266 | + "rustix 1.1.6", | |
| 267 | + "slab", | |
| 268 | + "windows-sys 0.61.2", | |
| 269 | + ] | |
| 270 | + | |
| 271 | + [[package]] | |
| 272 | + name = "async-lock" | |
| 273 | + version = "3.5.0" | |
| 274 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 275 | + checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f" | |
| 276 | + dependencies = [ | |
| 277 | + "event-listener", | |
| 278 | + "event-listener-strategy", | |
| 279 | + "pin-project-lite", | |
| 280 | + ] | |
| 281 | + | |
| 282 | + [[package]] | |
| 283 | + name = "async-process" | |
| 284 | + version = "2.5.0" | |
| 285 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 286 | + checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75" | |
| 287 | + dependencies = [ | |
| 288 | + "async-channel", | |
| 289 | + "async-io", | |
| 290 | + "async-lock", | |
| 291 | + "async-signal", | |
| 292 | + "async-task", | |
| 293 | + "blocking", | |
| 294 | + "cfg-if", | |
| 295 | + "event-listener", | |
| 296 | + "futures-lite", | |
| 297 | + "rustix 1.1.6", | |
| 298 | + ] | |
| 299 | + | |
| 300 | + [[package]] | |
| 301 | + name = "async-recursion" | |
| 302 | + version = "1.2.0" | |
| 303 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 304 | + checksum = "4f8abc12baad266b1c8cec146854c195b5864b4221d4b2ca7296a7ae82d9e451" | |
| 305 | + dependencies = [ | |
| 306 | + "proc-macro2", | |
| 307 | + "quote", | |
| 308 | + "syn 3.0.10", | |
| 309 | + ] | |
| 310 | + | |
| 311 | + [[package]] | |
| 312 | + name = "async-signal" | |
| 313 | + version = "0.2.14" | |
| 314 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 315 | + checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485" | |
| 316 | + dependencies = [ | |
| 317 | + "async-io", | |
| 318 | + "async-lock", | |
| 319 | + "atomic-waker", | |
| 320 | + "cfg-if", | |
| 321 | + "futures-core", | |
| 322 | + "futures-io", | |
| 323 | + "rustix 1.1.6", | |
| 324 | + "signal-hook-registry", | |
| 325 | + "slab", | |
| 326 | + "windows-sys 0.61.2", | |
| 327 | + ] | |
| 328 | + | |
| 329 | + [[package]] | |
| 330 | + name = "async-task" | |
| 331 | + version = "4.7.1" | |
| 332 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 333 | + checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" | |
| 334 | + | |
| 335 | + [[package]] | |
| 336 | + name = "async-trait" | |
| 337 | + version = "0.1.92" | |
| 338 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 339 | + checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" | |
| 340 | + dependencies = [ | |
| 341 | + "proc-macro2", | |
| 342 | + "quote", | |
| 343 | + "syn 3.0.10", | |
| 344 | + ] | |
| 345 | + | |
| 346 | + [[package]] | |
| 347 | + name = "atomic-waker" | |
| 348 | + version = "1.1.2" | |
| 349 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 350 | + checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" | |
| 351 | + | |
| 352 | + [[package]] | |
| 353 | + name = "atspi" | |
| 354 | + version = "0.29.0" | |
| 355 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 356 | + checksum = "c77886257be21c9cd89a4ae7e64860c6f0eefca799bb79127913052bd0eefb3d" | |
| 357 | + dependencies = [ | |
| 358 | + "atspi-common", | |
| 359 | + "atspi-proxies", | |
| 360 | + ] | |
| 361 | + | |
| 362 | + [[package]] | |
| 363 | + name = "atspi-common" | |
| 364 | + version = "0.13.0" | |
| 365 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 366 | + checksum = "20c5617155740c98003016429ad13fe43ce7a77b007479350a9f8bf95a29f63d" | |
| 367 | + dependencies = [ | |
| 368 | + "enumflags2", | |
| 369 | + "serde", | |
| 370 | + "static_assertions", | |
| 371 | + "zbus", | |
| 372 | + "zbus-lockstep", | |
| 373 | + "zbus-lockstep-macros", | |
| 374 | + "zbus_names", | |
| 375 | + "zvariant", | |
| 376 | + ] | |
| 377 | + | |
| 378 | + [[package]] | |
| 379 | + name = "atspi-proxies" | |
| 380 | + version = "0.13.0" | |
| 381 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 382 | + checksum = "2230e48787ed3eb4088996eab66a32ca20c0b67bbd4fd6cdfe79f04f1f04c9fc" | |
| 383 | + dependencies = [ | |
| 384 | + "atspi-common", | |
| 385 | + "serde", | |
| 386 | + "zbus", | |
| 387 | + ] | |
| 388 | + | |
| 389 | + [[package]] | |
| 390 | + name = "autocfg" | |
| 391 | + version = "1.5.1" | |
| 392 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 393 | + checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" | |
| 394 | + | |
| 395 | + [[package]] | |
| 396 | + name = "base64" | |
| 397 | + version = "0.23.1" | |
| 398 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 399 | + checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" | |
| 400 | + | |
| 401 | + [[package]] | |
| 402 | + name = "bit-set" | |
| 403 | + version = "0.10.0" | |
| 404 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 405 | + checksum = "09ec2f926cc3060f09db9ebc5b52823d85268d24bb917e472c0c4bea35780a7d" | |
| 406 | + dependencies = [ | |
| 407 | + "bit-vec", | |
| 408 | + ] | |
| 409 | + | |
| 410 | + [[package]] | |
| 411 | + name = "bit-vec" | |
| 412 | + version = "0.9.1" | |
| 413 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 414 | + checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51" | |
| 415 | + | |
| 416 | + [[package]] | |
| 417 | + name = "bitflags" | |
| 418 | + version = "1.3.2" | |
| 419 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 420 | + checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | |
| 421 | + | |
| 422 | + [[package]] | |
| 423 | + name = "bitflags" | |
| 424 | + version = "2.13.2" | |
| 425 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 426 | + checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" | |
| 427 | + dependencies = [ | |
| 428 | + "serde_core", | |
| 429 | + ] | |
| 430 | + | |
| 431 | + [[package]] | |
| 432 | + name = "block2" | |
| 433 | + version = "0.5.1" | |
| 434 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 435 | + checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" | |
| 436 | + dependencies = [ | |
| 437 | + "objc2 0.5.3", | |
| 438 | + ] | |
| 439 | + | |
| 440 | + [[package]] | |
| 441 | + name = "block2" | |
| 442 | + version = "0.6.2" | |
| 443 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 444 | + checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" | |
| 445 | + dependencies = [ | |
| 446 | + "objc2 0.6.5", | |
| 447 | + ] | |
| 448 | + | |
| 449 | + [[package]] | |
| 450 | + name = "blocking" | |
| 451 | + version = "1.7.0" | |
| 452 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 453 | + checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa" | |
| 454 | + dependencies = [ | |
| 455 | + "async-channel", | |
| 456 | + "async-task", | |
| 457 | + "futures-io", | |
| 458 | + "futures-lite", | |
| 459 | + "piper", | |
| 460 | + ] | |
| 461 | + | |
| 462 | + [[package]] | |
| 463 | + name = "bumpalo" | |
| 464 | + version = "3.20.4" | |
| 465 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 466 | + checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db" | |
| 467 | + | |
| 468 | + [[package]] | |
| 469 | + name = "bytemuck" | |
| 470 | + version = "1.25.2" | |
| 471 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 472 | + checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" | |
| 473 | + dependencies = [ | |
| 474 | + "bytemuck_derive", | |
| 475 | + ] | |
| 476 | + | |
| 477 | + [[package]] | |
| 478 | + name = "bytemuck_derive" | |
| 479 | + version = "1.12.1" | |
| 480 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 481 | + checksum = "6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c" | |
| 482 | + dependencies = [ | |
| 483 | + "proc-macro2", | |
| 484 | + "quote", | |
| 485 | + "syn 3.0.10", | |
| 486 | + ] | |
| 487 | + | |
| 488 | + [[package]] | |
| 489 | + name = "byteorder-lite" | |
| 490 | + version = "0.1.0" | |
| 491 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 492 | + checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" | |
| 493 | + | |
| 494 | + [[package]] | |
| 495 | + name = "bytes" | |
| 496 | + version = "1.12.2" | |
| 497 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 498 | + checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" | |
| 499 | + | |
| 500 | + [[package]] | |
| 501 | + name = "calloop" | |
| 502 | + version = "0.13.0" | |
| 503 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 504 | + checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" | |
| 505 | + dependencies = [ | |
| 506 | + "bitflags 2.13.2", | |
| 507 | + "log", | |
| 508 | + "polling", | |
| 509 | + "rustix 0.38.44", | |
| 510 | + "slab", | |
| 511 | + "thiserror 1.0.69", | |
| 512 | + ] | |
| 513 | + | |
| 514 | + [[package]] | |
| 515 | + name = "calloop" | |
| 516 | + version = "0.14.5" | |
| 517 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 518 | + checksum = "43b32313e937c8721c9d17ee9bf60699a6402b4b7c2cb6ac1bee0ffcaa4b4e5e" | |
| 519 | + dependencies = [ | |
| 520 | + "bitflags 2.13.2", | |
| 521 | + "polling", | |
| 522 | + "rustix 1.1.6", | |
| 523 | + "tracing", | |
| 524 | + ] | |
| 525 | + | |
| 526 | + [[package]] | |
| 527 | + name = "calloop-wayland-source" | |
| 528 | + version = "0.3.0" | |
| 529 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 530 | + checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" | |
| 531 | + dependencies = [ | |
| 532 | + "calloop 0.13.0", | |
| 533 | + "rustix 0.38.44", | |
| 534 | + "wayland-backend", | |
| 535 | + "wayland-client", | |
| 536 | + ] | |
| 537 | + | |
| 538 | + [[package]] | |
| 539 | + name = "calloop-wayland-source" | |
| 540 | + version = "0.4.1" | |
| 541 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 542 | + checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa" | |
| 543 | + dependencies = [ | |
| 544 | + "calloop 0.14.5", | |
| 545 | + "rustix 1.1.6", | |
| 546 | + "wayland-backend", | |
| 547 | + "wayland-client", | |
| 548 | + ] | |
| 549 | + | |
| 550 | + [[package]] | |
| 551 | + name = "cc" | |
| 552 | + version = "1.12.0" | |
| 553 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 554 | + checksum = "95e45cf2980b2d467be49a9ed942c9179b701063a7ca3d037de7ee9bd67f8d66" | |
| 555 | + dependencies = [ | |
| 556 | + "find-msvc-tools", | |
| 557 | + "jobserver", | |
| 558 | + "libc", | |
| 559 | + "shlex", | |
| 560 | + ] | |
| 561 | + | |
| 562 | + [[package]] | |
| 563 | + name = "cfg-if" | |
| 564 | + version = "1.0.5" | |
| 565 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 566 | + checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" | |
| 567 | + | |
| 568 | + [[package]] | |
| 569 | + name = "cfg_aliases" | |
| 570 | + version = "0.2.2" | |
| 571 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 572 | + checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" | |
| 573 | + | |
| 574 | + [[package]] | |
| 575 | + name = "cgl" | |
| 576 | + version = "0.3.2" | |
| 577 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 578 | + checksum = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff" | |
| 579 | + dependencies = [ | |
| 580 | + "libc", | |
| 581 | + ] | |
| 582 | + | |
| 583 | + [[package]] | |
| 584 | + name = "clearwake" | |
| 585 | + version = "0.1.0" | |
| 586 | + dependencies = [ | |
| 587 | + "clearwake-core", | |
| 588 | + "eframe", | |
| 589 | + "egui", | |
| 590 | + "ehttp", | |
| 591 | + "image", | |
| 592 | + "log", | |
| 593 | + "ureq", | |
| 594 | + "wasm-bindgen", | |
| 595 | + "wasm-bindgen-futures", | |
| 596 | + "web-sys", | |
| 597 | + "winit", | |
| 598 | + ] | |
| 599 | + | |
| 600 | + [[package]] | |
| 601 | + name = "clearwake-core" | |
| 602 | + version = "0.1.0" | |
| 603 | + | |
| 604 | + [[package]] | |
| 605 | + name = "clipboard-win" | |
| 606 | + version = "5.4.3" | |
| 607 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 608 | + checksum = "052af7878466feccda12ba7a6a67d019d712f296809559b47c12c8cc196d3a9a" | |
| 609 | + dependencies = [ | |
| 610 | + "error-code", | |
| 611 | + ] | |
| 612 | + | |
| 613 | + [[package]] | |
| 614 | + name = "codespan-reporting" | |
| 615 | + version = "0.13.1" | |
| 616 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 617 | + checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681" | |
| 618 | + dependencies = [ | |
| 619 | + "unicode-width", | |
| 620 | + ] | |
| 621 | + | |
| 622 | + [[package]] | |
| 623 | + name = "color" | |
| 624 | + version = "0.3.3" | |
| 625 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 626 | + checksum = "2ec7c5eb7a16992b1904d76c517d170ab353b0e0b3d5a0c81a8a0cd1037893cf" | |
| 627 | + dependencies = [ | |
| 628 | + "bytemuck", | |
| 629 | + ] | |
| 630 | + | |
| 631 | + [[package]] | |
| 632 | + name = "color_quant" | |
| 633 | + version = "1.1.0" | |
| 634 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 635 | + checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" | |
| 636 | + | |
| 637 | + [[package]] | |
| 638 | + name = "combine" | |
| 639 | + version = "4.6.9" | |
| 640 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 641 | + checksum = "4356eba6976435498d05a311ee9fc486da3bc81c200d3f0d7dd9703b41913f92" | |
| 642 | + dependencies = [ | |
| 643 | + "bytes", | |
| 644 | + "memchr", | |
| 645 | + ] | |
| 646 | + | |
| 647 | + [[package]] | |
| 648 | + name = "concurrent-queue" | |
| 649 | + version = "2.5.0" | |
| 650 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 651 | + checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" | |
| 652 | + dependencies = [ | |
| 653 | + "crossbeam-utils", | |
| 654 | + ] | |
| 655 | + | |
| 656 | + [[package]] | |
| 657 | + name = "core-foundation" | |
| 658 | + version = "0.9.4" | |
| 659 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 660 | + checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" | |
| 661 | + dependencies = [ | |
| 662 | + "core-foundation-sys", | |
| 663 | + "libc", | |
| 664 | + ] | |
| 665 | + | |
| 666 | + [[package]] | |
| 667 | + name = "core-foundation" | |
| 668 | + version = "0.10.1" | |
| 669 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 670 | + checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" | |
| 671 | + dependencies = [ | |
| 672 | + "core-foundation-sys", | |
| 673 | + "libc", | |
| 674 | + ] | |
| 675 | + | |
| 676 | + [[package]] | |
| 677 | + name = "core-foundation-sys" | |
| 678 | + version = "0.8.7" | |
| 679 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 680 | + checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" | |
| 681 | + | |
| 682 | + [[package]] | |
| 683 | + name = "core-graphics" | |
| 684 | + version = "0.23.2" | |
| 685 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 686 | + checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" | |
| 687 | + dependencies = [ | |
| 688 | + "bitflags 1.3.2", | |
| 689 | + "core-foundation 0.9.4", | |
| 690 | + "core-graphics-types", | |
| 691 | + "foreign-types", | |
| 692 | + "libc", | |
| 693 | + ] | |
| 694 | + | |
| 695 | + [[package]] | |
| 696 | + name = "core-graphics-types" | |
| 697 | + version = "0.1.3" | |
| 698 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 699 | + checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" | |
| 700 | + dependencies = [ | |
| 701 | + "bitflags 1.3.2", | |
| 702 | + "core-foundation 0.9.4", | |
| 703 | + "libc", | |
| 704 | + ] | |
| 705 | + | |
| 706 | + [[package]] | |
| 707 | + name = "crc32fast" | |
| 708 | + version = "1.5.6" | |
| 709 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 710 | + checksum = "fd9ae8fcb3ea71b0b26338b4ffb13006bb175de8fd07921089a906ce7e5e6945" | |
| 711 | + dependencies = [ | |
| 712 | + "cfg-if", | |
| 713 | + ] | |
| 714 | + | |
| 715 | + [[package]] | |
| 716 | + name = "crossbeam-utils" | |
| 717 | + version = "0.8.23" | |
| 718 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 719 | + checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" | |
| 720 | + | |
| 721 | + [[package]] | |
| 722 | + name = "crunchy" | |
| 723 | + version = "0.2.4" | |
| 724 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 725 | + checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" | |
| 726 | + | |
| 727 | + [[package]] | |
| 728 | + name = "cursor-icon" | |
| 729 | + version = "1.2.0" | |
| 730 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 731 | + checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" | |
| 732 | + | |
| 733 | + [[package]] | |
| 734 | + name = "dispatch" | |
| 735 | + version = "0.2.0" | |
| 736 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 737 | + checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" | |
| 738 | + | |
| 739 | + [[package]] | |
| 740 | + name = "dispatch2" | |
| 741 | + version = "0.3.1" | |
| 742 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 743 | + checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" | |
| 744 | + dependencies = [ | |
| 745 | + "bitflags 2.13.2", | |
| 746 | + "objc2 0.6.5", | |
| 747 | + ] | |
| 748 | + | |
| 749 | + [[package]] | |
| 750 | + name = "displaydoc" | |
| 751 | + version = "0.2.7" | |
| 752 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 753 | + checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" | |
| 754 | + dependencies = [ | |
| 755 | + "proc-macro2", | |
| 756 | + "quote", | |
| 757 | + "syn 3.0.10", | |
| 758 | + ] | |
| 759 | + | |
| 760 | + [[package]] | |
| 761 | + name = "dlib" | |
| 762 | + version = "0.5.3" | |
| 763 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 764 | + checksum = "ab8ecd87370524b461f8557c119c405552c396ed91fc0a8eec68679eab26f94a" | |
| 765 | + dependencies = [ | |
| 766 | + "libloading", | |
| 767 | + ] | |
| 768 | + | |
| 769 | + [[package]] | |
| 770 | + name = "document-features" | |
| 771 | + version = "0.2.12" | |
| 772 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 773 | + checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" | |
| 774 | + dependencies = [ | |
| 775 | + "litrs", | |
| 776 | + ] | |
| 777 | + | |
| 778 | + [[package]] | |
| 779 | + name = "downcast-rs" | |
| 780 | + version = "1.2.1" | |
| 781 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 782 | + checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" | |
| 783 | + | |
| 784 | + [[package]] | |
| 785 | + name = "dpi" | |
| 786 | + version = "0.1.2" | |
| 787 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 788 | + checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" | |
| 789 | + | |
| 790 | + [[package]] | |
| 791 | + name = "ecolor" | |
| 792 | + version = "0.38.0" | |
| 793 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 794 | + checksum = "aa37fe156f296ffe69bb2a132b513cbe06075b3f8f8157179c06f9ea7b274c05" | |
| 795 | + dependencies = [ | |
| 796 | + "bytemuck", | |
| 797 | + "emath", | |
| 798 | + "serde", | |
| 799 | + ] | |
| 800 | + | |
| 801 | + [[package]] | |
| 802 | + name = "eframe" | |
| 803 | + version = "0.38.0" | |
| 804 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 805 | + checksum = "3b97e2e4b2c3b6322927d71869d13046eccaf0e7c8dd6f41da503a4d5aca5278" | |
| 806 | + dependencies = [ | |
| 807 | + "ahash", | |
| 808 | + "bytemuck", | |
| 809 | + "document-features", | |
| 810 | + "egui", | |
| 811 | + "egui-wgpu", | |
| 812 | + "egui-winit", | |
| 813 | + "egui_glow", | |
| 814 | + "glow", | |
| 815 | + "glutin", | |
| 816 | + "glutin-winit", | |
| 817 | + "image", | |
| 818 | + "js-sys", | |
| 819 | + "log", | |
| 820 | + "objc2 0.6.5", | |
| 821 | + "objc2-app-kit 0.3.2", | |
| 822 | + "objc2-foundation 0.3.2", | |
| 823 | + "parking_lot", | |
| 824 | + "percent-encoding", | |
| 825 | + "profiling", | |
| 826 | + "raw-window-handle", | |
| 827 | + "ron", | |
| 828 | + "send_wrapper", | |
| 829 | + "serde", | |
| 830 | + "static_assertions", | |
| 831 | + "wasm-bindgen", | |
| 832 | + "web-sys", | |
| 833 | + "web-time", | |
| 834 | + "windows-sys 0.61.2", | |
| 835 | + "winit", | |
| 836 | + ] | |
| 837 | + | |
| 838 | + [[package]] | |
| 839 | + name = "egui" | |
| 840 | + version = "0.38.0" | |
| 841 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 842 | + checksum = "e31ec8afef9124ff0d878187fc02023e61af8823e328bbefd4a4c2b112ca438b" | |
| 843 | + dependencies = [ | |
| 844 | + "accesskit", | |
| 845 | + "ahash", | |
| 846 | + "bitflags 2.13.2", | |
| 847 | + "emath", | |
| 848 | + "epaint", | |
| 849 | + "itertools", | |
| 850 | + "log", | |
| 851 | + "nohash-hasher", | |
| 852 | + "profiling", | |
| 853 | + "ron", | |
| 854 | + "serde", | |
| 855 | + "smallvec", | |
| 856 | + "unicode-segmentation", | |
| 857 | + "web-sys", | |
| 858 | + ] | |
| 859 | + | |
| 860 | + [[package]] | |
| 861 | + name = "egui-wgpu" | |
| 862 | + version = "0.38.0" | |
| 863 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 864 | + checksum = "aa5855839e41b3c9728fe509daa35e0c4f765216d60f93eef9c5b48290eaf63e" | |
| 865 | + dependencies = [ | |
| 866 | + "ahash", | |
| 867 | + "bytemuck", | |
| 868 | + "document-features", | |
| 869 | + "egui", | |
| 870 | + "epaint", | |
| 871 | + "log", | |
| 872 | + "profiling", | |
| 873 | + "thiserror 2.0.21", | |
| 874 | + "type-map", | |
| 875 | + "web-time", | |
| 876 | + "wgpu", | |
| 877 | + "winit", | |
| 878 | + ] | |
| 879 | + | |
| 880 | + [[package]] | |
| 881 | + name = "egui-winit" | |
| 882 | + version = "0.38.0" | |
| 883 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 884 | + checksum = "716ad746afba4b2d6ce5983692f33289f0b2d262fcf9a6ba08f10a420c0aa8bf" | |
| 885 | + dependencies = [ | |
| 886 | + "accesskit_winit", | |
| 887 | + "arboard", | |
| 888 | + "block2 0.6.2", | |
| 889 | + "bytemuck", | |
| 890 | + "egui", | |
| 891 | + "log", | |
| 892 | + "objc2 0.6.5", | |
| 893 | + "objc2-app-kit 0.3.2", | |
| 894 | + "objc2-foundation 0.3.2", | |
| 895 | + "objc2-ui-kit 0.3.2", | |
| 896 | + "profiling", | |
| 897 | + "raw-window-handle", | |
| 898 | + "serde", | |
| 899 | + "smithay-clipboard", | |
| 900 | + "web-time", | |
| 901 | + "webbrowser", | |
| 902 | + "windows-sys 0.61.2", | |
| 903 | + "winit", | |
| 904 | + ] | |
| 905 | + | |
| 906 | + [[package]] | |
| 907 | + name = "egui_glow" | |
| 908 | + version = "0.38.0" | |
| 909 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 910 | + checksum = "b9a5431dcfd4e6df7a1fe48c2f00ecb7b82c330eb13ce38f0acc1f00bf53b696" | |
| 911 | + dependencies = [ | |
| 912 | + "bytemuck", | |
| 913 | + "egui", | |
| 914 | + "glow", | |
| 915 | + "log", | |
| 916 | + "profiling", | |
| 917 | + "winit", | |
| 918 | + ] | |
| 919 | + | |
| 920 | + [[package]] | |
| 921 | + name = "ehttp" | |
| 922 | + version = "0.7.3" | |
| 923 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 924 | + checksum = "4d1c51126a4e8242c5b3bcd4c5b350ed3540f0c13c10e0c3c840a3833fa3474c" | |
| 925 | + dependencies = [ | |
| 926 | + "document-features", | |
| 927 | + "js-sys", | |
| 928 | + "ureq", | |
| 929 | + "wasm-bindgen", | |
| 930 | + "wasm-bindgen-futures", | |
| 931 | + "web-sys", | |
| 932 | + ] | |
| 933 | + | |
| 934 | + [[package]] | |
| 935 | + name = "either" | |
| 936 | + version = "1.19.0" | |
| 937 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 938 | + checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" | |
| 939 | + | |
| 940 | + [[package]] | |
| 941 | + name = "emath" | |
| 942 | + version = "0.38.0" | |
| 943 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 944 | + checksum = "38818ee44b05cd130535c99758d0c991286c052ffaccf4104d2a096698c7c906" | |
| 945 | + dependencies = [ | |
| 946 | + "bytemuck", | |
| 947 | + "serde", | |
| 948 | + ] | |
| 949 | + | |
| 950 | + [[package]] | |
| 951 | + name = "endi" | |
| 952 | + version = "1.1.1" | |
| 953 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 954 | + checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099" | |
| 955 | + | |
| 956 | + [[package]] | |
| 957 | + name = "enumflags2" | |
| 958 | + version = "0.7.12" | |
| 959 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 960 | + checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef" | |
| 961 | + dependencies = [ | |
| 962 | + "enumflags2_derive", | |
| 963 | + "serde", | |
| 964 | + ] | |
| 965 | + | |
| 966 | + [[package]] | |
| 967 | + name = "enumflags2_derive" | |
| 968 | + version = "0.7.12" | |
| 969 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 970 | + checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" | |
| 971 | + dependencies = [ | |
| 972 | + "proc-macro2", | |
| 973 | + "quote", | |
| 974 | + "syn 2.0.119", | |
| 975 | + ] | |
| 976 | + | |
| 977 | + [[package]] | |
| 978 | + name = "enumn" | |
| 979 | + version = "0.1.14" | |
| 980 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 981 | + checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" | |
| 982 | + dependencies = [ | |
| 983 | + "proc-macro2", | |
| 984 | + "quote", | |
| 985 | + "syn 2.0.119", | |
| 986 | + ] | |
| 987 | + | |
| 988 | + [[package]] | |
| 989 | + name = "epaint" | |
| 990 | + version = "0.38.0" | |
| 991 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 992 | + checksum = "21e2d10b3623c6d8f717d1aade61137eda2a4c40d99d4ddb06395712d3a560ac" | |
| 993 | + dependencies = [ | |
| 994 | + "ahash", | |
| 995 | + "bytemuck", | |
| 996 | + "ecolor", | |
| 997 | + "emath", | |
| 998 | + "epaint_default_fonts", | |
| 999 | + "font-types", | |
| 1000 | + "harfrust", | |
| 1001 | + "log", | |
| 1002 | + "nohash-hasher", | |
| 1003 | + "parking_lot", | |
| 1004 | + "profiling", | |
| 1005 | + "self_cell", | |
| 1006 | + "serde", | |
| 1007 | + "skrifa", | |
| 1008 | + "smallvec", | |
| 1009 | + "unicode-general-category", | |
| 1010 | + "unicode-properties", | |
| 1011 | + "unicode-segmentation", | |
| 1012 | + "vello_cpu", | |
| 1013 | + ] | |
| 1014 | + | |
| 1015 | + [[package]] | |
| 1016 | + name = "epaint_default_fonts" | |
| 1017 | + version = "0.38.0" | |
| 1018 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1019 | + checksum = "d0ae6efb3ef44405ea764cb736c6886414b9b9dc4cc0ffb6fb0fb68dbc42da64" | |
| 1020 | + | |
| 1021 | + [[package]] | |
| 1022 | + name = "equivalent" | |
| 1023 | + version = "1.0.3" | |
| 1024 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1025 | + checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" | |
| 1026 | + | |
| 1027 | + [[package]] | |
| 1028 | + name = "errno" | |
| 1029 | + version = "0.3.15" | |
| 1030 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1031 | + checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776" | |
| 1032 | + dependencies = [ | |
| 1033 | + "libc", | |
| 1034 | + "windows-sys 0.61.2", | |
| 1035 | + ] | |
| 1036 | + | |
| 1037 | + [[package]] | |
| 1038 | + name = "error-code" | |
| 1039 | + version = "3.4.0" | |
| 1040 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1041 | + checksum = "0b5343afd4a8365a643ac588dab4cf234a190c7f6c88c9f6dd6ffe00837661b7" | |
| 1042 | + | |
| 1043 | + [[package]] | |
| 1044 | + name = "euclid" | |
| 1045 | + version = "0.22.14" | |
| 1046 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1047 | + checksum = "f1a05365e3b1c6d1650318537c7460c6923f1abdd272ad6842baa2b509957a06" | |
| 1048 | + dependencies = [ | |
| 1049 | + "num-traits", | |
| 1050 | + ] | |
| 1051 | + | |
| 1052 | + [[package]] | |
| 1053 | + name = "event-listener" | |
| 1054 | + version = "5.4.2" | |
| 1055 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1056 | + checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" | |
| 1057 | + dependencies = [ | |
| 1058 | + "parking", | |
| 1059 | + "pin-project-lite", | |
| 1060 | + ] | |
| 1061 | + | |
| 1062 | + [[package]] | |
| 1063 | + name = "event-listener-strategy" | |
| 1064 | + version = "0.5.4" | |
| 1065 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1066 | + checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" | |
| 1067 | + dependencies = [ | |
| 1068 | + "event-listener", | |
| 1069 | + "pin-project-lite", | |
| 1070 | + ] | |
| 1071 | + | |
| 1072 | + [[package]] | |
| 1073 | + name = "fastrand" | |
| 1074 | + version = "2.5.0" | |
| 1075 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1076 | + checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" | |
| 1077 | + | |
| 1078 | + [[package]] | |
| 1079 | + name = "fax" | |
| 1080 | + version = "0.2.7" | |
| 1081 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1082 | + checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a" | |
| 1083 | + | |
| 1084 | + [[package]] | |
| 1085 | + name = "fdeflate" | |
| 1086 | + version = "0.3.7" | |
| 1087 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1088 | + checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" | |
| 1089 | + dependencies = [ | |
| 1090 | + "simd-adler32", | |
| 1091 | + ] | |
| 1092 | + | |
| 1093 | + [[package]] | |
| 1094 | + name = "fearless_simd" | |
| 1095 | + version = "1.3.0" | |
| 1096 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1097 | + checksum = "6a7107516a8be9a4ffe92495f3dbfe04348be0ad18f17c67a1d846511f99e599" | |
| 1098 | + | |
| 1099 | + [[package]] | |
| 1100 | + name = "fearless_simd_macros" | |
| 1101 | + version = "0.1.0" | |
| 1102 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1103 | + checksum = "3e91d94c6885390b81782d7ee60fd6583b33907333a8b340de25ccf468353315" | |
| 1104 | + dependencies = [ | |
| 1105 | + "proc-macro2", | |
| 1106 | + "quote", | |
| 1107 | + "syn 3.0.10", | |
| 1108 | + ] | |
| 1109 | + | |
| 1110 | + [[package]] | |
| 1111 | + name = "find-msvc-tools" | |
| 1112 | + version = "0.1.16" | |
| 1113 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1114 | + checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8" | |
| 1115 | + | |
| 1116 | + [[package]] | |
| 1117 | + name = "fixedbitset" | |
| 1118 | + version = "0.5.9" | |
| 1119 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1120 | + checksum = "5905ec755cc8386d7928353e4d356d2be3e89e81e5ca01fe630a1ca4d08dc175" | |
| 1121 | + | |
| 1122 | + [[package]] | |
| 1123 | + name = "flate2" | |
| 1124 | + version = "1.1.11" | |
| 1125 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1126 | + checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4" | |
| 1127 | + dependencies = [ | |
| 1128 | + "crc32fast", | |
| 1129 | + "miniz_oxide 0.9.1", | |
| 1130 | + "zlib-rs", | |
| 1131 | + ] | |
| 1132 | + | |
| 1133 | + [[package]] | |
| 1134 | + name = "foldhash" | |
| 1135 | + version = "0.1.5" | |
| 1136 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1137 | + checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" | |
| 1138 | + | |
| 1139 | + [[package]] | |
| 1140 | + name = "foldhash" | |
| 1141 | + version = "0.2.0" | |
| 1142 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1143 | + checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" | |
| 1144 | + | |
| 1145 | + [[package]] | |
| 1146 | + name = "font-types" | |
| 1147 | + version = "0.12.7" | |
| 1148 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1149 | + checksum = "835ae9d781464a79026cde387f9cbc650c9a4909d7cf7e658b127e3c35d2f35d" | |
| 1150 | + dependencies = [ | |
| 1151 | + "bytemuck", | |
| 1152 | + "serde", | |
| 1153 | + ] | |
| 1154 | + | |
| 1155 | + [[package]] | |
| 1156 | + name = "foreign-types" | |
| 1157 | + version = "0.5.0" | |
| 1158 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1159 | + checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" | |
| 1160 | + dependencies = [ | |
| 1161 | + "foreign-types-macros", | |
| 1162 | + "foreign-types-shared", | |
| 1163 | + ] | |
| 1164 | + | |
| 1165 | + [[package]] | |
| 1166 | + name = "foreign-types-macros" | |
| 1167 | + version = "0.2.4" | |
| 1168 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1169 | + checksum = "ea5190182e6915eb873ddbc16e23b711b6eb1f9c00a0d0a3a91b5f6228475225" | |
| 1170 | + dependencies = [ | |
| 1171 | + "proc-macro2", | |
| 1172 | + "quote", | |
| 1173 | + "syn 3.0.10", | |
| 1174 | + ] | |
| 1175 | + | |
| 1176 | + [[package]] | |
| 1177 | + name = "foreign-types-shared" | |
| 1178 | + version = "0.3.1" | |
| 1179 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1180 | + checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" | |
| 1181 | + | |
| 1182 | + [[package]] | |
| 1183 | + name = "form_urlencoded" | |
| 1184 | + version = "1.2.3" | |
| 1185 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1186 | + checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" | |
| 1187 | + dependencies = [ | |
| 1188 | + "percent-encoding", | |
| 1189 | + ] | |
| 1190 | + | |
| 1191 | + [[package]] | |
| 1192 | + name = "futures-core" | |
| 1193 | + version = "0.3.34" | |
| 1194 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1195 | + checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" | |
| 1196 | + | |
| 1197 | + [[package]] | |
| 1198 | + name = "futures-io" | |
| 1199 | + version = "0.3.34" | |
| 1200 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1201 | + checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" | |
| 1202 | + | |
| 1203 | + [[package]] | |
| 1204 | + name = "futures-lite" | |
| 1205 | + version = "2.6.1" | |
| 1206 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1207 | + checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" | |
| 1208 | + dependencies = [ | |
| 1209 | + "fastrand", | |
| 1210 | + "futures-core", | |
| 1211 | + "futures-io", | |
| 1212 | + "parking", | |
| 1213 | + "pin-project-lite", | |
| 1214 | + ] | |
| 1215 | + | |
| 1216 | + [[package]] | |
| 1217 | + name = "futures-macro" | |
| 1218 | + version = "0.3.34" | |
| 1219 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1220 | + checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" | |
| 1221 | + dependencies = [ | |
| 1222 | + "proc-macro2", | |
| 1223 | + "quote", | |
| 1224 | + "syn 3.0.10", | |
| 1225 | + ] | |
| 1226 | + | |
| 1227 | + [[package]] | |
| 1228 | + name = "futures-task" | |
| 1229 | + version = "0.3.34" | |
| 1230 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1231 | + checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" | |
| 1232 | + | |
| 1233 | + [[package]] | |
| 1234 | + name = "futures-util" | |
| 1235 | + version = "0.3.34" | |
| 1236 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1237 | + checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" | |
| 1238 | + dependencies = [ | |
| 1239 | + "futures-core", | |
| 1240 | + "futures-macro", | |
| 1241 | + "futures-task", | |
| 1242 | + "pin-project-lite", | |
| 1243 | + "slab", | |
| 1244 | + ] | |
| 1245 | + | |
| 1246 | + [[package]] | |
| 1247 | + name = "gethostname" | |
| 1248 | + version = "1.1.0" | |
| 1249 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1250 | + checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" | |
| 1251 | + dependencies = [ | |
| 1252 | + "rustix 1.1.6", | |
| 1253 | + "windows-link", | |
| 1254 | + ] | |
| 1255 | + | |
| 1256 | + [[package]] | |
| 1257 | + name = "getrandom" | |
| 1258 | + version = "0.2.17" | |
| 1259 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1260 | + checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" | |
| 1261 | + dependencies = [ | |
| 1262 | + "cfg-if", | |
| 1263 | + "libc", | |
| 1264 | + "wasi", | |
| 1265 | + ] | |
| 1266 | + | |
| 1267 | + [[package]] | |
| 1268 | + name = "getrandom" | |
| 1269 | + version = "0.4.3" | |
| 1270 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1271 | + checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" | |
| 1272 | + dependencies = [ | |
| 1273 | + "cfg-if", | |
| 1274 | + "js-sys", | |
| 1275 | + "libc", | |
| 1276 | + "r-efi", | |
| 1277 | + "wasm-bindgen", | |
| 1278 | + ] | |
| 1279 | + | |
| 1280 | + [[package]] | |
| 1281 | + name = "gif" | |
| 1282 | + version = "0.14.2" | |
| 1283 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1284 | + checksum = "ee8cfcc411d9adbbaba82fb72661cc1bcca13e8bba98b364e62b2dba8f960159" | |
| 1285 | + dependencies = [ | |
| 1286 | + "color_quant", | |
| 1287 | + "weezl", | |
| 1288 | + ] | |
| 1289 | + | |
| 1290 | + [[package]] | |
| 1291 | + name = "gl_generator" | |
| 1292 | + version = "0.14.0" | |
| 1293 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1294 | + checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" | |
| 1295 | + dependencies = [ | |
| 1296 | + "khronos_api", | |
| 1297 | + "log", | |
| 1298 | + "xml-rs", | |
| 1299 | + ] | |
| 1300 | + | |
| 1301 | + [[package]] | |
| 1302 | + name = "glifo" | |
| 1303 | + version = "0.5.0" | |
| 1304 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1305 | + checksum = "9ae2e3b09ea1cc45c994a405e4d4154901d4caa867d3e1be3a02be641f62fefa" | |
| 1306 | + dependencies = [ | |
| 1307 | + "bytemuck", | |
| 1308 | + "foldhash 0.2.0", | |
| 1309 | + "hashbrown 0.17.2", | |
| 1310 | + "log", | |
| 1311 | + "peniko", | |
| 1312 | + "skrifa", | |
| 1313 | + "smallvec", | |
| 1314 | + "vello_common", | |
| 1315 | + ] | |
| 1316 | + | |
| 1317 | + [[package]] | |
| 1318 | + name = "glow" | |
| 1319 | + version = "0.17.0" | |
| 1320 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1321 | + checksum = "29038e1c483364cc6bb3cf78feee1816002e127c331a1eec55a4d202b9e1adb5" | |
| 1322 | + dependencies = [ | |
| 1323 | + "js-sys", | |
| 1324 | + "slotmap", | |
| 1325 | + "wasm-bindgen", | |
| 1326 | + "web-sys", | |
| 1327 | + ] | |
| 1328 | + | |
| 1329 | + [[package]] | |
| 1330 | + name = "glutin" | |
| 1331 | + version = "0.32.3" | |
| 1332 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1333 | + checksum = "12124de845cacfebedff80e877bb37b5b75c34c5a4c89e47e1cdd67fb6041325" | |
| 1334 | + dependencies = [ | |
| 1335 | + "bitflags 2.13.2", | |
| 1336 | + "cfg_aliases", | |
| 1337 | + "cgl", | |
| 1338 | + "dispatch2", | |
| 1339 | + "glutin_egl_sys", | |
| 1340 | + "glutin_glx_sys", | |
| 1341 | + "glutin_wgl_sys", | |
| 1342 | + "libloading", | |
| 1343 | + "objc2 0.6.5", | |
| 1344 | + "objc2-app-kit 0.3.2", | |
| 1345 | + "objc2-core-foundation", | |
| 1346 | + "objc2-foundation 0.3.2", | |
| 1347 | + "once_cell", | |
| 1348 | + "raw-window-handle", | |
| 1349 | + "wayland-sys", | |
| 1350 | + "windows-sys 0.52.0", | |
| 1351 | + "x11-dl", | |
| 1352 | + ] | |
| 1353 | + | |
| 1354 | + [[package]] | |
| 1355 | + name = "glutin-winit" | |
| 1356 | + version = "0.5.0" | |
| 1357 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1358 | + checksum = "85edca7075f8fc728f28cb8fbb111a96c3b89e930574369e3e9c27eb75d3788f" | |
| 1359 | + dependencies = [ | |
| 1360 | + "cfg_aliases", | |
| 1361 | + "glutin", | |
| 1362 | + "raw-window-handle", | |
| 1363 | + "winit", | |
| 1364 | + ] | |
| 1365 | + | |
| 1366 | + [[package]] | |
| 1367 | + name = "glutin_egl_sys" | |
| 1368 | + version = "0.7.1" | |
| 1369 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1370 | + checksum = "4c4680ba6195f424febdc3ba46e7a42a0e58743f2edb115297b86d7f8ecc02d2" | |
| 1371 | + dependencies = [ | |
| 1372 | + "gl_generator", | |
| 1373 | + "windows-sys 0.52.0", | |
| 1374 | + ] | |
| 1375 | + | |
| 1376 | + [[package]] | |
| 1377 | + name = "glutin_glx_sys" | |
| 1378 | + version = "0.6.1" | |
| 1379 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1380 | + checksum = "8a7bb2938045a88b612499fbcba375a77198e01306f52272e692f8c1f3751185" | |
| 1381 | + dependencies = [ | |
| 1382 | + "gl_generator", | |
| 1383 | + "x11-dl", | |
| 1384 | + ] | |
| 1385 | + | |
| 1386 | + [[package]] | |
| 1387 | + name = "glutin_wgl_sys" | |
| 1388 | + version = "0.6.1" | |
| 1389 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1390 | + checksum = "2c4ee00b289aba7a9e5306d57c2d05499b2e5dc427f84ac708bd2c090212cf3e" | |
| 1391 | + dependencies = [ | |
| 1392 | + "gl_generator", | |
| 1393 | + ] | |
| 1394 | + | |
| 1395 | + [[package]] | |
| 1396 | + name = "guillotiere" | |
| 1397 | + version = "0.7.0" | |
| 1398 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1399 | + checksum = "6b17e70c989c36bad147b27a58d148c0741c51448aa5653436547323e524d0ab" | |
| 1400 | + dependencies = [ | |
| 1401 | + "euclid", | |
| 1402 | + ] | |
| 1403 | + | |
| 1404 | + [[package]] | |
| 1405 | + name = "half" | |
| 1406 | + version = "2.7.1" | |
| 1407 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1408 | + checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" | |
| 1409 | + dependencies = [ | |
| 1410 | + "cfg-if", | |
| 1411 | + "crunchy", | |
| 1412 | + "num-traits", | |
| 1413 | + "zerocopy", | |
| 1414 | + ] | |
| 1415 | + | |
| 1416 | + [[package]] | |
| 1417 | + name = "harfrust" | |
| 1418 | + version = "0.15.0" | |
| 1419 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1420 | + checksum = "865dcc4105d51c323d8fedbb2d75b5e9c8ecddf5613f74c82f851d0afbc97114" | |
| 1421 | + dependencies = [ | |
| 1422 | + "bitflags 2.13.2", | |
| 1423 | + "bytemuck", | |
| 1424 | + "read-fonts", | |
| 1425 | + "smallvec", | |
| 1426 | + "yoke", | |
| 1427 | + ] | |
| 1428 | + | |
| 1429 | + [[package]] | |
| 1430 | + name = "hashbrown" | |
| 1431 | + version = "0.15.5" | |
| 1432 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1433 | + checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" | |
| 1434 | + dependencies = [ | |
| 1435 | + "foldhash 0.1.5", | |
| 1436 | + ] | |
| 1437 | + | |
| 1438 | + [[package]] | |
| 1439 | + name = "hashbrown" | |
| 1440 | + version = "0.17.2" | |
| 1441 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1442 | + checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc" | |
| 1443 | + dependencies = [ | |
| 1444 | + "foldhash 0.2.0", | |
| 1445 | + ] | |
| 1446 | + | |
| 1447 | + [[package]] | |
| 1448 | + name = "hermit-abi" | |
| 1449 | + version = "0.5.3" | |
| 1450 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1451 | + checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" | |
| 1452 | + | |
| 1453 | + [[package]] | |
| 1454 | + name = "hex" | |
| 1455 | + version = "0.4.3" | |
| 1456 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1457 | + checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" | |
| 1458 | + | |
| 1459 | + [[package]] | |
| 1460 | + name = "http" | |
| 1461 | + version = "1.6.0" | |
| 1462 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1463 | + checksum = "a07dc2d082802d1782faa5b3c8ac252f3a4fc89f51e76c3f37dc2d1a5b857c05" | |
| 1464 | + dependencies = [ | |
| 1465 | + "bytes", | |
| 1466 | + "itoa", | |
| 1467 | + ] | |
| 1468 | + | |
| 1469 | + [[package]] | |
| 1470 | + name = "httparse" | |
| 1471 | + version = "1.10.1" | |
| 1472 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1473 | + checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" | |
| 1474 | + | |
| 1475 | + [[package]] | |
| 1476 | + name = "icu_collections" | |
| 1477 | + version = "2.4.0" | |
| 1478 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1479 | + checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" | |
| 1480 | + dependencies = [ | |
| 1481 | + "displaydoc", | |
| 1482 | + "potential_utf", | |
| 1483 | + "utf8_iter", | |
| 1484 | + "yoke", | |
| 1485 | + "zerofrom", | |
| 1486 | + "zerovec", | |
| 1487 | + ] | |
| 1488 | + | |
| 1489 | + [[package]] | |
| 1490 | + name = "icu_locale_core" | |
| 1491 | + version = "2.4.0" | |
| 1492 | + source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1493 | + checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" | |
| 1494 | + dependencies = [ | |
| 1495 | + "displaydoc", | |
| 1496 | + "litemap", | |
| 1497 | + "tinystr", | |
| 1498 | + "writeable", | |
| 1499 | + "zerovec", | |
| 1500 | + ] | |
| 1501 | + |
Cargo.toml added
| 1 | + [workspace] | |
| 2 | + resolver = "2" | |
| 3 | + members = ["crates/clearwake-core", "crates/clearwake-app"] | |
| 4 | + # clearwake-glimmer builds for the Glimmer kernel target; see its README. | |
| 5 | + exclude = ["crates/clearwake-glimmer"] | |
| 6 | + | |
| 7 | + [workspace.package] | |
| 8 | + version = "0.1.0" | |
| 9 | + edition = "2021" | |
| 10 | + license = "Unlicense" | |
| 11 | + | |
| 12 | + [profile.release] | |
| 13 | + opt-level = 3 | |
| 14 | + lto = "thin" | |
| 15 | + codegen-units = 1 | |
| 16 | + strip = true | |
| 17 | + | |
| 18 | + [profile.release.package.clearwake-core] | |
| 19 | + opt-level = 3 |
LICENSE added
| 1 | + This is free and unencumbered software released into the public domain. | |
| 2 | + | |
| 3 | + Anyone is free to copy, modify, publish, use, compile, sell, or | |
| 4 | + distribute this software, either in source code form or as a compiled | |
| 5 | + binary, for any purpose, commercial or non-commercial, and by any | |
| 6 | + means. | |
| 7 | + | |
| 8 | + In jurisdictions that recognize copyright laws, the author or authors | |
| 9 | + of this software dedicate any and all copyright interest in the | |
| 10 | + software to the public domain. We make this dedication for the benefit | |
| 11 | + of the public at large and to the detriment of our heirs and | |
| 12 | + successors. We intend this dedication to be an overt act of | |
| 13 | + relinquishment in perpetuity of all present and future rights to this | |
| 14 | + software under copyright law. | |
| 15 | + | |
| 16 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| 17 | + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| 18 | + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
| 19 | + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
| 20 | + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
| 21 | + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
| 22 | + OTHER DEALINGS IN THE SOFTWARE. | |
| 23 | + | |
| 24 | + For more information, please refer to <https://unlicense.org> |
README.md added
| 1 | + # Clearwake | |
| 2 | + | |
| 3 | + A quieter browser, written entirely in Rust. | |
| 4 | + | |
| 5 | + Clearwake reads web pages into clean text, links and pictures. Scripts never run. Ads and trackers are blocked before they load, with no off switch, no allowlist and no exceptions. Bookmarks stay on your device. There is no account. | |
| 6 | + | |
| 7 | + ## Where it runs | |
| 8 | + | |
| 9 | + | Platform | Build | How | | |
| 10 | + |---|---|---| | |
| 11 | + | Mac (Apple Silicon and Intel) | `scripts/package-mac.sh` | egui window | | |
| 12 | + | Windows (x64) | `scripts/package-windows.sh` | egui window | | |
| 13 | + | Linux (x86-64, glibc 2.28+) | `scripts/package-linux.sh` | egui window | | |
| 14 | + | Android (8.0+) | `scripts/package-android.sh` | egui on NativeActivity | | |
| 15 | + | Web | `scripts/build-web.sh` | egui in WebAssembly, pages loaded through clearwake.ai/fetch | | |
| 16 | + | Glimmer | `crates/clearwake-glimmer` | native Glimmer window, drawn by Glimmer's own kernel | | |
| 17 | + | |
| 18 | + ## Layout | |
| 19 | + | |
| 20 | + - `crates/clearwake-core`: the engine. Web addresses, the HTML reader and the always-on filter (`filters.txt`). `no_std` with integer math only, so it also runs inside the Glimmer kernel. | |
| 21 | + - `crates/clearwake-app`: the app for Mac, Windows, Linux, Android and the web ([egui](https://github.com/emilk/egui)). | |
| 22 | + - `crates/clearwake-glimmer`: Clearwake as a Glimmer window (`glimmer-ui`). Builds for `x86_64-unknown-none`. The kernel loads pages and hands them over; until its network stack is wired in, the window shows its welcome page. | |
| 23 | + - `crates/clearwake-fetch`: the filter behind clearwake.ai/fetch, the page loader for the web version (a web page can't read other sites directly). A tiny WebAssembly module with no imports; `pages/` holds the Pages Function that asks it about every address and redirect. | |
| 24 | + | |
| 25 | + ## Build and test | |
| 26 | + | |
| 27 | + ```sh | |
| 28 | + cargo test -p clearwake-core | |
| 29 | + cargo run -p clearwake --release -- https://example.com | |
| 30 | + cargo build -p clearwake-core --release --target x86_64-unknown-none # Glimmer target | |
| 31 | + (cd crates/clearwake-glimmer && cargo build --release --target x86_64-unknown-none) | |
| 32 | + (cd crates/clearwake-fetch && cargo build --release --target wasm32-unknown-unknown) | |
| 33 | + ``` | |
| 34 | + | |
| 35 | + ## What it does not do yet | |
| 36 | + | |
| 37 | + Clearwake does not run JavaScript or apply page styles, so pages that only work with scripts show less, and logins that need scripts won't work. Pictures are shown; video and audio are not. There are no tabs yet. | |
| 38 | + | |
| 39 | + Released into the public domain under the Unlicense. |
assets/icon-1024.png added
Not a text file.
assets/icon-128.png added
Not a text file.
assets/icon-256.png added
Not a text file.
assets/icon-32.png added
Not a text file.
assets/icon-512.png added
Not a text file.
crates/clearwake-app/Cargo.toml added
| 1 | + [package] | |
| 2 | + name = "clearwake" | |
| 3 | + description = "Clearwake, a quieter browser." | |
| 4 | + version.workspace = true | |
| 5 | + edition.workspace = true | |
| 6 | + license.workspace = true | |
| 7 | + | |
| 8 | + [lib] | |
| 9 | + crate-type = ["rlib", "cdylib"] | |
| 10 | + | |
| 11 | + [[bin]] | |
| 12 | + name = "clearwake" | |
| 13 | + path = "src/main.rs" | |
| 14 | + | |
| 15 | + [dependencies] | |
| 16 | + clearwake-core = { path = "../clearwake-core", features = ["std"] } | |
| 17 | + eframe = { version = "0.38", default-features = false, features = ["default_fonts", "glow", "persistence"] } | |
| 18 | + egui = "0.38" | |
| 19 | + image = { version = "0.25", default-features = false, features = ["png", "jpeg", "gif", "webp", "bmp", "ico"] } | |
| 20 | + log = "0.4" | |
| 21 | + | |
| 22 | + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] | |
| 23 | + ureq = { version = "3", default-features = false, features = ["rustls", "gzip"] } | |
| 24 | + | |
| 25 | + [target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))'.dependencies] | |
| 26 | + ureq = { version = "3", default-features = false, features = ["rustls", "gzip", "platform-verifier"] } | |
| 27 | + | |
| 28 | + [target.'cfg(target_arch = "wasm32")'.dependencies] | |
| 29 | + eframe = { version = "0.38", default-features = false, features = ["accesskit"] } | |
| 30 | + ehttp = "0.7" | |
| 31 | + wasm-bindgen = "0.2" | |
| 32 | + wasm-bindgen-futures = "0.4" | |
| 33 | + web-sys = { version = "0.3", features = ["Window", "Document", "HtmlCanvasElement", "Location", "History", "Element"] } | |
| 34 | + | |
| 35 | + [target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))'.dependencies] | |
| 36 | + eframe = { version = "0.38", default-features = false, features = ["accesskit", "clipboard", "links", "wayland", "x11"] } | |
| 37 | + winit = { version = "0.30.13", default-features = false, features = ["rwh_06", "x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] } | |
| 38 | + | |
| 39 | + [target.'cfg(target_os = "android")'.dependencies] | |
| 40 | + eframe = { version = "0.38", default-features = false, features = ["android-native-activity"] } | |
| 41 | + winit = { version = "0.30.13", default-features = false, features = ["rwh_06", "android-native-activity"] } | |
| 42 | + | |
| 43 | + [package.metadata.android] | |
| 44 | + package = "ai.clearwake.browser" | |
| 45 | + apk_name = "Clearwake" | |
| 46 | + build_targets = ["aarch64-linux-android", "armv7-linux-androideabi", "x86_64-linux-android"] | |
| 47 | + resources = "android/res" | |
| 48 | + assets = "android/assets" | |
| 49 | + | |
| 50 | + [package.metadata.android.sdk] | |
| 51 | + min_sdk_version = 26 | |
| 52 | + target_sdk_version = 35 | |
| 53 | + | |
| 54 | + [[package.metadata.android.uses_permission]] | |
| 55 | + name = "android.permission.INTERNET" | |
| 56 | + | |
| 57 | + [package.metadata.android.application] | |
| 58 | + label = "Clearwake" | |
| 59 | + icon = "@mipmap/ic_launcher" | |
| 60 | + theme = "@android:style/Theme.DeviceDefault.NoActionBar" | |
| 61 | + | |
| 62 | + [package.metadata.android.application.activity] | |
| 63 | + config_changes = "orientation|screenSize|screenLayout|keyboardHidden|keyboard|uiMode" | |
| 64 | + launch_mode = "singleTop" | |
| 65 | + orientation = "unspecified" |
crates/clearwake-app/android/assets/.keep added
No text changes.
crates/clearwake-app/android/res/mipmap-hdpi/ic_launcher.png added
Not a text file.
crates/clearwake-app/android/res/mipmap-mdpi/ic_launcher.png added
Not a text file.
crates/clearwake-app/android/res/mipmap-xhdpi/ic_launcher.png added
Not a text file.
crates/clearwake-app/android/res/mipmap-xxhdpi/ic_launcher.png added
Not a text file.
crates/clearwake-app/android/res/mipmap-xxxhdpi/ic_launcher.png added
Not a text file.
crates/clearwake-app/src/lib.rs added
| 1 | + //! Clearwake: a quieter browser. | |
| 2 | + //! | |
| 3 | + //! One Rust program for Mac, Windows, Linux, Android and the web. Pages are | |
| 4 | + //! read by `clearwake-core` into clean text, links and pictures. Scripts | |
| 5 | + //! never run, ads and trackers are never loaded, and there is no switch to | |
| 6 | + //! turn that off. | |
| 7 | + | |
| 8 | + mod net; | |
| 9 | + mod ui; | |
| 10 | + | |
| 11 | + use clearwake_core::bookmarks::Bookmarks; | |
| 12 | + use clearwake_core::history::History; | |
| 13 | + use clearwake_core::html::{self, Document}; | |
| 14 | + use clearwake_core::{Filter, Url}; | |
| 15 | + use egui::TextureHandle; | |
| 16 | + use net::{Body, Done, Inbox, Job, Kind, Loader}; | |
| 17 | + use std::collections::HashMap; | |
| 18 | + use std::sync::{Arc, Mutex}; | |
| 19 | + | |
| 20 | + pub const VERSION: &str = env!("CARGO_PKG_VERSION"); | |
| 21 | + | |
| 22 | + pub enum Page { | |
| 23 | + Home, | |
| 24 | + Loading { url: String }, | |
| 25 | + Doc(Document), | |
| 26 | + Picture { url: String }, | |
| 27 | + Text { url: String, text: String }, | |
| 28 | + Error { url: String, message: String }, | |
| 29 | + } | |
| 30 | + | |
| 31 | + pub enum Picture { | |
| 32 | + Loading, | |
| 33 | + Ready(TextureHandle), | |
| 34 | + Failed, | |
| 35 | + } | |
| 36 | + | |
| 37 | + pub struct Clearwake { | |
| 38 | + filter: Arc<Filter>, | |
| 39 | + loader: Loader, | |
| 40 | + inbox: Inbox, | |
| 41 | + generation: u64, | |
| 42 | + page: Page, | |
| 43 | + history: History, | |
| 44 | + bookmarks: Bookmarks, | |
| 45 | + pictures: HashMap<String, Picture>, | |
| 46 | + address: String, | |
| 47 | + address_focus: bool, | |
| 48 | + forms: HashMap<usize, String>, | |
| 49 | + home_search: String, | |
| 50 | + hover: Option<String>, | |
| 51 | + blocked_total: u64, | |
| 52 | + text_scale: f32, | |
| 53 | + dark: Option<bool>, | |
| 54 | + show_bookmarks: bool, | |
| 55 | + scroll_to_top: bool, | |
| 56 | + #[cfg(target_os = "android")] | |
| 57 | + keyboard_shown: bool, | |
| 58 | + } | |
| 59 | + | |
| 60 | + impl Clearwake { | |
| 61 | + pub fn new(cc: &eframe::CreationContext<'_>, start: Option<String>) -> Clearwake { | |
| 62 | + let filter = Arc::new(Filter::new()); | |
| 63 | + let inbox: Inbox = Arc::new(Mutex::new(Vec::new())); | |
| 64 | + let loader = Loader::new(inbox.clone(), cc.egui_ctx.clone(), filter.clone()); | |
| 65 | + let mut app = Clearwake { | |
| 66 | + filter, | |
| 67 | + loader, | |
| 68 | + inbox, | |
| 69 | + generation: 0, | |
| 70 | + page: Page::Home, | |
| 71 | + history: History::default(), | |
| 72 | + bookmarks: Bookmarks::default(), | |
| 73 | + pictures: HashMap::new(), | |
| 74 | + address: String::new(), | |
| 75 | + address_focus: true, | |
| 76 | + forms: HashMap::new(), | |
| 77 | + home_search: String::new(), | |
| 78 | + hover: None, | |
| 79 | + blocked_total: 0, | |
| 80 | + text_scale: 1.0, | |
| 81 | + dark: None, | |
| 82 | + show_bookmarks: false, | |
| 83 | + scroll_to_top: false, | |
| 84 | + #[cfg(target_os = "android")] | |
| 85 | + keyboard_shown: false, | |
| 86 | + }; | |
| 87 | + if let Some(storage) = cc.storage { | |
| 88 | + if let Some(t) = storage.get_string("bookmarks") { | |
| 89 | + app.bookmarks = Bookmarks::from_text(&t); | |
| 90 | + } | |
| 91 | + if let Some(s) = storage.get_string("text_scale").and_then(|s| s.parse::<f32>().ok()) { | |
| 92 | + app.text_scale = s.clamp(0.7, 2.0); | |
| 93 | + } | |
| 94 | + app.dark = match storage.get_string("look").as_deref() { | |
| 95 | + Some("dark") => Some(true), | |
| 96 | + Some("light") => Some(false), | |
| 97 | + _ => None, | |
| 98 | + }; | |
| 99 | + if let Some(n) = storage.get_string("blocked_total").and_then(|s| s.parse().ok()) { | |
| 100 | + app.blocked_total = n; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + ui::install_style(&cc.egui_ctx, app.dark); | |
| 104 | + app.history.visit(String::from("about:home")); | |
| 105 | + if let Some(s) = start { | |
| 106 | + app.address_focus = false; | |
| 107 | + app.open_input(&s); | |
| 108 | + } | |
| 109 | + app | |
| 110 | + } | |
| 111 | + | |
| 112 | + /// Open what the person typed in the address bar or the home search. | |
| 113 | + pub fn open_input(&mut self, input: &str) { | |
| 114 | + if let Some(u) = clearwake_core::resolve_input(input) { | |
| 115 | + self.open(u.to_string(), true); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + /// Open an address. `record` adds it to back/forward history. | |
| 120 | + pub fn open(&mut self, url: String, record: bool) { | |
| 121 | + self.generation += 1; | |
| 122 | + self.forms.clear(); | |
| 123 | + self.pictures.clear(); | |
| 124 | + self.hover = None; | |
| 125 | + self.show_bookmarks = false; | |
| 126 | + self.scroll_to_top = true; | |
| 127 | + if record { | |
| 128 | + self.history.visit(url.clone()); | |
| 129 | + } | |
| 130 | + self.address = if url == "about:home" { String::new() } else { url.clone() }; | |
| 131 | + if url == "about:home" { | |
| 132 | + self.page = Page::Home; | |
| 133 | + return; | |
| 134 | + } | |
| 135 | + match Url::parse(&url) { | |
| 136 | + Some(u) if self.filter.blocks(&u) => { | |
| 137 | + self.blocked_total += 1; | |
| 138 | + self.page = Page::Error { url, message: String::from("Clearwake blocked this address because it serves ads or tracking.") }; | |
| 139 | + } | |
| 140 | + Some(_) => { | |
| 141 | + self.page = Page::Loading { url: url.clone() }; | |
| 142 | + self.loader.load(Job { generation: self.generation, kind: Kind::Page, url }); | |
| 143 | + } | |
| 144 | + None => { | |
| 145 | + self.page = Page::Error { url, message: String::from("Clearwake only opens web addresses (http and https).") }; | |
| 146 | + } | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + pub fn back(&mut self) { | |
| 151 | + if let Some(u) = self.history.back() { | |
| 152 | + self.open(u, false); | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + pub fn forward(&mut self) { | |
| 157 | + if let Some(u) = self.history.forward() { | |
| 158 | + self.open(u, false); | |
| 159 | + } | |
| 160 | + } | |
| 161 | + | |
| 162 | + pub fn reload(&mut self) { | |
| 163 | + if let Some(u) = self.history.current().map(|s| s.to_string()) { | |
| 164 | + self.open(u, false); | |
| 165 | + } | |
| 166 | + } | |
| 167 | + | |
| 168 | + pub fn current_url(&self) -> Option<String> { | |
| 169 | + match &self.page { | |
| 170 | + Page::Home => None, | |
| 171 | + Page::Loading { url } | Page::Picture { url } | Page::Text { url, .. } | Page::Error { url, .. } => Some(url.clone()), | |
| 172 | + Page::Doc(d) => Some(d.url.to_string()), | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 176 | + pub fn current_title(&self) -> String { | |
| 177 | + match &self.page { | |
| 178 | + Page::Doc(d) if !d.title.is_empty() => d.title.clone(), | |
| 179 | + _ => self.current_url().unwrap_or_default(), | |
| 180 | + } | |
| 181 | + } | |
| 182 | + | |
| 183 | + fn receive(&mut self, ctx: &egui::Context) { | |
| 184 | + let done: Vec<Done> = std::mem::take(&mut *self.inbox.lock().unwrap()); | |
| 185 | + for d in done { | |
| 186 | + if d.job.generation != self.generation { | |
| 187 | + continue; | |
| 188 | + } | |
| 189 | + match d.job.kind { | |
| 190 | + Kind::Page => self.page_arrived(ctx, d.job.url, d.result), | |
| 191 | + Kind::Image => { | |
| 192 | + let pic = match d.result { | |
| 193 | + Ok(Body::Image { width, height, rgba }) => { | |
| 194 | + let img = egui::ColorImage::from_rgba_unmultiplied([width, height], &rgba); | |
| 195 | + Picture::Ready(ctx.load_texture(d.job.url.clone(), img, egui::TextureOptions::LINEAR)) | |
| 196 | + } | |
| 197 | + Err(e) if e.contains("blocked") => { | |
| 198 | + self.blocked_total += 1; | |
| 199 | + Picture::Failed | |
| 200 | + } | |
| 201 | + _ => Picture::Failed, | |
| 202 | + }; | |
| 203 | + self.pictures.insert(d.job.url, pic); | |
| 204 | + } | |
| 205 | + } | |
| 206 | + } | |
| 207 | + } | |
| 208 | + | |
| 209 | + fn page_arrived(&mut self, ctx: &egui::Context, asked: String, result: Result<Body, String>) { | |
| 210 | + match result { | |
| 211 | + Err(message) => { | |
| 212 | + if message.contains("blocked") { | |
| 213 | + self.blocked_total += 1; | |
| 214 | + } | |
| 215 | + self.page = Page::Error { url: asked, message }; | |
| 216 | + } | |
| 217 | + Ok(Body::Image { .. }) => {} | |
| 218 | + Ok(Body::Page { url, content_type, bytes }) => { | |
| 219 | + if url != asked { | |
| 220 | + self.history.replace(url.clone()); | |
| 221 | + } | |
| 222 | + self.address = url.clone(); | |
| 223 | + let ct = content_type.to_ascii_lowercase(); | |
| 224 | + let sniff_html = { | |
| 225 | + let head = String::from_utf8_lossy(&bytes[..bytes.len().min(512)]).to_ascii_lowercase(); | |
| 226 | + head.contains("<html") || head.contains("<!doctype html") || head.contains("<head") || head.contains("<body") | |
| 227 | + }; | |
| 228 | + if ct.starts_with("image/") { | |
| 229 | + self.page = Page::Picture { url: url.clone() }; | |
| 230 | + match net::decode_image(&bytes, 4096) { | |
| 231 | + Ok(Body::Image { width, height, rgba }) => { | |
| 232 | + let img = egui::ColorImage::from_rgba_unmultiplied([width, height], &rgba); | |
| 233 | + self.pictures.insert(url.clone(), Picture::Ready(ctx.load_texture(url, img, egui::TextureOptions::LINEAR))); | |
| 234 | + } | |
| 235 | + _ => { | |
| 236 | + self.pictures.insert(url, Picture::Failed); | |
| 237 | + } | |
| 238 | + } | |
| 239 | + } else if ct.contains("html") || ct.contains("xml") || (ct.is_empty() && sniff_html) || sniff_html { | |
| 240 | + let text = html::decode_bytes(&bytes, &content_type); | |
| 241 | + let base = Url::parse(&url).unwrap_or_else(|| Url::parse("about:blank").unwrap()); | |
| 242 | + let doc = html::parse(&text, &base, &self.filter); | |
| 243 | + self.blocked_total += doc.stats.blocked as u64; | |
| 244 | + for (i, src) in doc.image_urls().into_iter().enumerate() { | |
| 245 | + if i >= 80 { | |
| 246 | + break; | |
| 247 | + } | |
| 248 | + self.pictures.insert(src.clone(), Picture::Loading); | |
| 249 | + self.loader.load(Job { generation: self.generation, kind: Kind::Image, url: src }); | |
| 250 | + } | |
| 251 | + self.page = Page::Doc(doc); | |
| 252 | + } else if ct.starts_with("text/") || ct.contains("json") || ct.is_empty() { | |
| 253 | + self.page = Page::Text { url, text: String::from_utf8_lossy(&bytes).into_owned() }; | |
| 254 | + } else { | |
| 255 | + self.page = Page::Error { | |
| 256 | + url, | |
| 257 | + message: String::from("This is a file, not a page. Clearwake doesn't download files."), | |
| 258 | + }; | |
| 259 | + } | |
| 260 | + } | |
| 261 | + } | |
| 262 | + } | |
| 263 | + } | |
| 264 | + | |
| 265 | + impl eframe::App for Clearwake { | |
| 266 | + fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) { | |
| 267 | + let ctx = ui.ctx().clone(); | |
| 268 | + self.receive(&ctx); | |
| 269 | + ui::shortcuts(self, &ctx); | |
| 270 | + ui::toolbar(self, ui); | |
| 271 | + ui::status_bar(self, ui); | |
| 272 | + ui::content(self, ui); | |
| 273 | + let title = match &self.page { | |
| 274 | + Page::Home => String::from("Clearwake"), | |
| 275 | + _ => { | |
| 276 | + let t = self.current_title(); | |
| 277 | + if t.is_empty() { String::from("Clearwake") } else { format!("{t} — Clearwake") } | |
| 278 | + } | |
| 279 | + }; | |
| 280 | + ctx.send_viewport_cmd(egui::ViewportCommand::Title(title)); | |
| 281 | + #[cfg(target_os = "android")] | |
| 282 | + android_keyboard(&ctx, &mut self.keyboard_shown); | |
| 283 | + } | |
| 284 | + | |
| 285 | + fn save(&mut self, storage: &mut dyn eframe::Storage) { | |
| 286 | + storage.set_string("bookmarks", self.bookmarks.to_text()); | |
| 287 | + storage.set_string("text_scale", self.text_scale.to_string()); | |
| 288 | + storage.set_string( | |
| 289 | + "look", | |
| 290 | + match self.dark { | |
| 291 | + Some(true) => "dark", | |
| 292 | + Some(false) => "light", | |
| 293 | + None => "system", | |
| 294 | + } | |
| 295 | + .to_string(), | |
| 296 | + ); | |
| 297 | + storage.set_string("blocked_total", self.blocked_total.to_string()); | |
| 298 | + } | |
| 299 | + } | |
| 300 | + | |
| 301 | + /// Window options shared by the computer and phone builds. | |
| 302 | + #[cfg(not(target_arch = "wasm32"))] | |
| 303 | + pub fn native_options() -> eframe::NativeOptions { | |
| 304 | + let icon = ui::app_icon(); | |
| 305 | + eframe::NativeOptions { | |
| 306 | + viewport: egui::ViewportBuilder::default() | |
| 307 | + .with_title("Clearwake") | |
| 308 | + .with_app_id("ai.clearwake.Clearwake") | |
| 309 | + .with_inner_size([1180.0, 820.0]) | |
| 310 | + .with_min_inner_size([360.0, 420.0]) | |
| 311 | + .with_icon(icon), | |
| 312 | + ..Default::default() | |
| 313 | + } | |
| 314 | + } | |
| 315 | + | |
| 316 | + #[cfg(target_os = "android")] | |
| 317 | + static ANDROID: std::sync::OnceLock<winit::platform::android::activity::AndroidApp> = std::sync::OnceLock::new(); | |
| 318 | + | |
| 319 | + /// Show the phone's keyboard while a text field is being typed in. | |
| 320 | + #[cfg(target_os = "android")] | |
| 321 | + fn android_keyboard(ctx: &egui::Context, shown: &mut bool) { | |
| 322 | + let want = ctx.egui_wants_keyboard_input(); | |
| 323 | + if want != *shown { | |
| 324 | + if let Some(app) = ANDROID.get() { | |
| 325 | + if want { | |
| 326 | + app.show_soft_input(true); | |
| 327 | + } else { | |
| 328 | + app.hide_soft_input(true); | |
| 329 | + } | |
| 330 | + } | |
| 331 | + *shown = want; | |
| 332 | + } | |
| 333 | + } | |
| 334 | + | |
| 335 | + #[cfg(target_os = "android")] | |
| 336 | + #[unsafe(no_mangle)] | |
| 337 | + fn android_main(app: winit::platform::android::activity::AndroidApp) { | |
| 338 | + let _ = ANDROID.set(app.clone()); | |
| 339 | + let mut options = native_options(); | |
| 340 | + options.android_app = Some(app); | |
| 341 | + let _ = eframe::run_native("Clearwake", options, Box::new(|cc| Ok(Box::new(Clearwake::new(cc, None))))); | |
| 342 | + } | |
| 343 | + | |
| 344 | + #[cfg(target_arch = "wasm32")] | |
| 345 | + mod web_start { | |
| 346 | + use super::*; | |
| 347 | + use wasm_bindgen::prelude::*; | |
| 348 | + use wasm_bindgen::JsCast; | |
| 349 | + | |
| 350 | + #[wasm_bindgen(start)] | |
| 351 | + pub fn start() { | |
| 352 | + let window = web_sys::window().expect("window"); | |
| 353 | + let document = window.document().expect("document"); | |
| 354 | + let canvas = document | |
| 355 | + .get_element_by_id("clearwake") | |
| 356 | + .expect("canvas") | |
| 357 | + .dyn_into::<web_sys::HtmlCanvasElement>() | |
| 358 | + .expect("canvas element"); | |
| 359 | + let start = window.location().hash().ok().and_then(|h| { | |
| 360 | + let h = h.trim_start_matches('#'); | |
| 361 | + if h.is_empty() { None } else { Some(clearwake_core::url::decode_component(h)) } | |
| 362 | + }); | |
| 363 | + wasm_bindgen_futures::spawn_local(async move { | |
| 364 | + let runner = eframe::WebRunner::new(); | |
| 365 | + let _ = runner | |
| 366 | + .start(canvas, eframe::WebOptions::default(), Box::new(move |cc| Ok(Box::new(Clearwake::new(cc, start))))) | |
| 367 | + .await; | |
| 368 | + if let Some(el) = web_sys::window().and_then(|w| w.document()).and_then(|d| d.get_element_by_id("loading")) { | |
| 369 | + el.remove(); | |
| 370 | + } | |
| 371 | + }); | |
| 372 | + } | |
| 373 | + } |
crates/clearwake-app/src/main.rs added
| 1 | + // Hide the console window on Windows. | |
| 2 | + #![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")] | |
| 3 | + | |
| 4 | + #[cfg(not(target_arch = "wasm32"))] | |
| 5 | + fn main() -> eframe::Result { | |
| 6 | + let start = std::env::args().nth(1); | |
| 7 | + eframe::run_native( | |
| 8 | + "Clearwake", | |
| 9 | + clearwake::native_options(), | |
| 10 | + Box::new(move |cc| Ok(Box::new(clearwake::Clearwake::new(cc, start)))), | |
| 11 | + ) | |
| 12 | + } | |
| 13 | + | |
| 14 | + #[cfg(target_arch = "wasm32")] | |
| 15 | + fn main() {} |
crates/clearwake-app/src/net.rs added
| 1 | + //! Loading pages and pictures. Every address, including each redirect, is | |
| 2 | + //! checked against the filter before anything is requested. | |
| 3 | + //! | |
| 4 | + //! On computers and phones Clearwake talks to sites directly. In a web | |
| 5 | + //! browser it can't (sites don't allow other pages to read them), so the web | |
| 6 | + //! version asks clearwake.ai/fetch, which applies the same filter. | |
| 7 | + | |
| 8 | + use clearwake_core::{Filter, Url}; | |
| 9 | + use std::sync::{Arc, Mutex}; | |
| 10 | + | |
| 11 | + #[allow(dead_code)] | |
| 12 | + pub const MAX_PAGE: u64 = 12 * 1024 * 1024; | |
| 13 | + #[allow(dead_code)] | |
| 14 | + pub const MAX_IMAGE: u64 = 8 * 1024 * 1024; | |
| 15 | + #[allow(dead_code)] | |
| 16 | + pub const USER_AGENT: &str = "Mozilla/5.0 (compatible; Clearwake/0.1; +https://clearwake.ai)"; | |
| 17 | + | |
| 18 | + #[derive(Clone, Copy, PartialEq, Eq, Debug)] | |
| 19 | + pub enum Kind { | |
| 20 | + Page, | |
| 21 | + Image, | |
| 22 | + } | |
| 23 | + | |
| 24 | + #[derive(Clone, Debug)] | |
| 25 | + pub struct Job { | |
| 26 | + pub generation: u64, | |
| 27 | + pub kind: Kind, | |
| 28 | + pub url: String, | |
| 29 | + } | |
| 30 | + | |
| 31 | + pub enum Body { | |
| 32 | + /// A page or text, with its final address after redirects. | |
| 33 | + Page { url: String, content_type: String, bytes: Vec<u8> }, | |
| 34 | + /// A decoded picture, RGBA. | |
| 35 | + Image { width: usize, height: usize, rgba: Vec<u8> }, | |
| 36 | + } | |
| 37 | + | |
| 38 | + pub struct Done { | |
| 39 | + pub job: Job, | |
| 40 | + pub result: Result<Body, String>, | |
| 41 | + } | |
| 42 | + | |
| 43 | + pub type Inbox = Arc<Mutex<Vec<Done>>>; | |
| 44 | + | |
| 45 | + /// Decode a picture and shrink it to at most `max` pixels wide. | |
| 46 | + pub fn decode_image(bytes: &[u8], max: u32) -> Result<Body, String> { | |
| 47 | + let img = image::load_from_memory(bytes).map_err(|_| String::from("This picture could not be read."))?; | |
| 48 | + let img = if img.width() > max { | |
| 49 | + let h = (img.height() as u64 * max as u64 / img.width() as u64).max(1) as u32; | |
| 50 | + img.resize_exact(max, h, image::imageops::FilterType::Triangle) | |
| 51 | + } else { | |
| 52 | + img | |
| 53 | + }; | |
| 54 | + let mut rgba = img.to_rgba8(); | |
| 55 | + lay_on_paper(&mut rgba); | |
| 56 | + Ok(Body::Image { width: rgba.width() as usize, height: rgba.height() as usize, rgba: rgba.into_raw() }) | |
| 57 | + } | |
| 58 | + | |
| 59 | + /// Web pictures with see-through parts (logos, diagrams) are drawn for a white page. On | |
| 60 | + /// Clearwake's dark page their dark lines would vanish, so pictures bigger than an icon get | |
| 61 | + /// a white backing, the way every page author expects them to be seen. | |
| 62 | + fn lay_on_paper(rgba: &mut image::RgbaImage) { | |
| 63 | + if rgba.width() <= 32 || rgba.height() <= 32 || rgba.pixels().all(|p| p[3] == 255) { | |
| 64 | + return; | |
| 65 | + } | |
| 66 | + for p in rgba.pixels_mut() { | |
| 67 | + let a = p[3] as u32; | |
| 68 | + for c in 0..3 { | |
| 69 | + p[c] = ((p[c] as u32 * a + 255 * (255 - a)) / 255) as u8; | |
| 70 | + } | |
| 71 | + p[3] = 255; | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + fn blocked_message() -> String { | |
| 76 | + String::from("Clearwake blocked this address because it serves ads or tracking.") | |
| 77 | + } | |
| 78 | + | |
| 79 | + #[cfg(not(target_arch = "wasm32"))] | |
| 80 | + mod native { | |
| 81 | + use super::*; | |
| 82 | + use std::collections::VecDeque; | |
| 83 | + use std::io::Read; | |
| 84 | + use std::sync::Condvar; | |
| 85 | + | |
| 86 | + pub struct Loader { | |
| 87 | + queue: Arc<(Mutex<VecDeque<Job>>, Condvar)>, | |
| 88 | + } | |
| 89 | + | |
| 90 | + impl Loader { | |
| 91 | + pub fn new(inbox: Inbox, ctx: egui::Context, filter: Arc<Filter>) -> Loader { | |
| 92 | + let queue: Arc<(Mutex<VecDeque<Job>>, Condvar)> = Arc::new((Mutex::new(VecDeque::new()), Condvar::new())); | |
| 93 | + #[allow(unused_mut)] | |
| 94 | + let mut config = ureq::Agent::config_builder(); | |
| 95 | + #[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))] | |
| 96 | + { | |
| 97 | + // Trust the same certificates the computer itself trusts. | |
| 98 | + config = config.tls_config(ureq::tls::TlsConfig::builder().root_certs(ureq::tls::RootCerts::PlatformVerifier).build()); | |
| 99 | + } | |
| 100 | + let agent: ureq::Agent = config | |
| 101 | + .max_redirects(0) | |
| 102 | + .http_status_as_error(false) | |
| 103 | + .timeout_global(Some(std::time::Duration::from_secs(30))) | |
| 104 | + .user_agent(USER_AGENT) | |
| 105 | + .build() | |
| 106 | + .into(); | |
| 107 | + for _ in 0..6 { | |
| 108 | + let queue = queue.clone(); | |
| 109 | + let inbox = inbox.clone(); | |
| 110 | + let ctx = ctx.clone(); | |
| 111 | + let filter = filter.clone(); | |
| 112 | + let agent = agent.clone(); | |
| 113 | + std::thread::spawn(move || loop { | |
| 114 | + let job = { | |
| 115 | + let (lock, cv) = &*queue; | |
| 116 | + let mut q = lock.lock().unwrap(); | |
| 117 | + loop { | |
| 118 | + if let Some(j) = q.pop_front() { | |
| 119 | + break j; | |
| 120 | + } | |
| 121 | + q = cv.wait(q).unwrap(); | |
| 122 | + } | |
| 123 | + }; | |
| 124 | + let result = fetch(&agent, &filter, &job); | |
| 125 | + inbox.lock().unwrap().push(Done { job, result }); | |
| 126 | + ctx.request_repaint(); | |
| 127 | + }); | |
| 128 | + } | |
| 129 | + Loader { queue } | |
| 130 | + } | |
| 131 | + | |
| 132 | + pub fn load(&self, job: Job) { | |
| 133 | + let (lock, cv) = &*self.queue; | |
| 134 | + let mut q = lock.lock().unwrap(); | |
| 135 | + if job.kind == Kind::Page { | |
| 136 | + // A new page makes every queued job for older pages pointless. | |
| 137 | + q.retain(|j| j.generation >= job.generation); | |
| 138 | + q.push_front(job); | |
| 139 | + } else { | |
| 140 | + q.push_back(job); | |
| 141 | + } | |
| 142 | + cv.notify_one(); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + fn fetch(agent: &ureq::Agent, filter: &Filter, job: &Job) -> Result<Body, String> { | |
| 147 | + let mut url = Url::parse(&job.url).ok_or_else(|| String::from("That address doesn't look right."))?; | |
| 148 | + for _ in 0..10 { | |
| 149 | + if filter.blocks(&url) { | |
| 150 | + return Err(blocked_message()); | |
| 151 | + } | |
| 152 | + let accept = match job.kind { | |
| 153 | + Kind::Page => "text/html,application/xhtml+xml,text/plain;q=0.9,image/*;q=0.8", | |
| 154 | + Kind::Image => "image/png,image/jpeg,image/gif,image/webp,image/*;q=0.8", | |
| 155 | + }; | |
| 156 | + let mut resp = agent | |
| 157 | + .get(url.to_string()) | |
| 158 | + .header("Accept", accept) | |
| 159 | + .header("Accept-Language", "en-US,en;q=0.8") | |
| 160 | + .call() | |
| 161 | + .map_err(|e| friendly(&e.to_string()))?; | |
| 162 | + let status = resp.status().as_u16(); | |
| 163 | + if (300..400).contains(&status) { | |
| 164 | + let loc = resp.headers().get("location").and_then(|v| v.to_str().ok()).unwrap_or(""); | |
| 165 | + url = url.join(loc).ok_or_else(|| String::from("The site sent Clearwake somewhere it won't go."))?; | |
| 166 | + continue; | |
| 167 | + } | |
| 168 | + if status >= 400 { | |
| 169 | + return Err(format!("The site answered with an error ({status}).")); | |
| 170 | + } | |
| 171 | + let content_type = resp.headers().get("content-type").and_then(|v| v.to_str().ok()).unwrap_or("").to_string(); | |
| 172 | + let limit = if job.kind == Kind::Page { MAX_PAGE } else { MAX_IMAGE }; | |
| 173 | + let mut bytes = Vec::new(); | |
| 174 | + resp.body_mut() | |
| 175 | + .as_reader() | |
| 176 | + .take(limit) | |
| 177 | + .read_to_end(&mut bytes) | |
| 178 | + .map_err(|e| friendly(&e.to_string()))?; | |
| 179 | + return match job.kind { | |
| 180 | + Kind::Image => decode_image(&bytes, 1600), | |
| 181 | + Kind::Page => Ok(Body::Page { url: url.to_string(), content_type, bytes }), | |
| 182 | + }; | |
| 183 | + } | |
| 184 | + Err(String::from("The site redirected too many times.")) | |
| 185 | + } | |
| 186 | + | |
| 187 | + fn friendly(e: &str) -> String { | |
| 188 | + let l = e.to_ascii_lowercase(); | |
| 189 | + if l.contains("dns") || l.contains("resolve") || l.contains("lookup") { | |
| 190 | + String::from("Clearwake couldn't find that site. Check the address and your connection.") | |
| 191 | + } else if l.contains("timed out") || l.contains("timeout") { | |
| 192 | + String::from("The site took too long to answer.") | |
| 193 | + } else if l.contains("certificate") || l.contains("tls") { | |
| 194 | + String::from("This site's security certificate isn't valid, so Clearwake won't open it.") | |
| 195 | + } else { | |
| 196 | + format!("The page couldn't be loaded. ({e})") | |
| 197 | + } | |
| 198 | + } | |
| 199 | + } | |
| 200 | + | |
| 201 | + #[cfg(not(target_arch = "wasm32"))] | |
| 202 | + pub use native::Loader; | |
| 203 | + | |
| 204 | + #[cfg(target_arch = "wasm32")] | |
| 205 | + mod web { | |
| 206 | + use super::*; | |
| 207 | + | |
| 208 | + pub struct Loader { | |
| 209 | + inbox: Inbox, | |
| 210 | + ctx: egui::Context, | |
| 211 | + filter: Arc<Filter>, | |
| 212 | + } | |
| 213 | + | |
| 214 | + impl Loader { | |
| 215 | + pub fn new(inbox: Inbox, ctx: egui::Context, filter: Arc<Filter>) -> Loader { | |
| 216 | + Loader { inbox, ctx, filter } | |
| 217 | + } | |
| 218 | + | |
| 219 | + pub fn load(&self, job: Job) { | |
| 220 | + let inbox = self.inbox.clone(); | |
| 221 | + let ctx = self.ctx.clone(); | |
| 222 | + if let Some(u) = Url::parse(&job.url) { | |
| 223 | + if self.filter.blocks(&u) { | |
| 224 | + inbox.lock().unwrap().push(Done { job, result: Err(blocked_message()) }); | |
| 225 | + ctx.request_repaint(); | |
| 226 | + return; | |
| 227 | + } | |
| 228 | + } | |
| 229 | + let proxied = format!("/fetch?url={}", clearwake_core::url::encode_component(&job.url)); | |
| 230 | + let req = ehttp::Request::get(proxied); | |
| 231 | + ehttp::fetch(req, move |res| { | |
| 232 | + let result = match res { | |
| 233 | + Err(e) => Err(format!("The page couldn't be loaded. ({e})")), | |
| 234 | + Ok(r) if !r.ok => { | |
| 235 | + let msg = String::from_utf8_lossy(&r.bytes).to_string(); | |
| 236 | + Err(if msg.trim().is_empty() || msg.len() > 300 { format!("The site answered with an error ({}).", r.status) } else { msg }) | |
| 237 | + } | |
| 238 | + Ok(r) => match job.kind { | |
| 239 | + Kind::Image => decode_image(&r.bytes, 1200), | |
| 240 | + Kind::Page => Ok(Body::Page { | |
| 241 | + url: r.headers.get("x-clearwake-url").map(|s| s.to_string()).unwrap_or_else(|| job.url.clone()), | |
| 242 | + content_type: r.headers.get("content-type").unwrap_or("").to_string(), | |
| 243 | + bytes: r.bytes, | |
| 244 | + }), | |
| 245 | + }, | |
| 246 | + }; | |
| 247 | + inbox.lock().unwrap().push(Done { job, result }); | |
| 248 | + ctx.request_repaint(); | |
| 249 | + }); | |
| 250 | + } | |
| 251 | + } | |
| 252 | + } | |
| 253 | + | |
| 254 | + #[cfg(target_arch = "wasm32")] | |
| 255 | + pub use web::Loader; |
crates/clearwake-app/src/ui.rs added
| 1 | + //! Drawing: the address bar, the page, and the home screen. | |
| 2 | + | |
| 3 | + use crate::{Clearwake, Page, Picture}; | |
| 4 | + use clearwake_core::html::{Block, Form, Inline}; | |
| 5 | + use egui::{Color32, CornerRadius, FontFamily, FontId, Key, RichText, Stroke, TextStyle, Vec2}; | |
| 6 | + | |
| 7 | + const COLUMN: f32 = 740.0; | |
| 8 | + | |
| 9 | + pub struct Palette { | |
| 10 | + pub bg: Color32, | |
| 11 | + pub bar: Color32, | |
| 12 | + pub ink: Color32, | |
| 13 | + pub soft: Color32, | |
| 14 | + pub line: Color32, | |
| 15 | + pub accent: Color32, | |
| 16 | + pub link: Color32, | |
| 17 | + pub field: Color32, | |
| 18 | + } | |
| 19 | + | |
| 20 | + pub fn palette(dark: bool) -> Palette { | |
| 21 | + if dark { | |
| 22 | + Palette { | |
| 23 | + bg: Color32::from_rgb(0x12, 0x16, 0x18), | |
| 24 | + bar: Color32::from_rgb(0x19, 0x1e, 0x21), | |
| 25 | + ink: Color32::from_rgb(0xe8, 0xec, 0xea), | |
| 26 | + soft: Color32::from_rgb(0x9a, 0xa6, 0xa3), | |
| 27 | + line: Color32::from_rgb(0x2a, 0x32, 0x35), | |
| 28 | + accent: Color32::from_rgb(0x6f, 0xc7, 0xb8), | |
| 29 | + link: Color32::from_rgb(0x8c, 0xc8, 0xf0), | |
| 30 | + field: Color32::from_rgb(0x22, 0x29, 0x2c), | |
| 31 | + } | |
| 32 | + } else { | |
| 33 | + Palette { | |
| 34 | + bg: Color32::from_rgb(0xfa, 0xf9, 0xf6), | |
| 35 | + bar: Color32::from_rgb(0xf1, 0xf0, 0xeb), | |
| 36 | + ink: Color32::from_rgb(0x1c, 0x22, 0x21), | |
| 37 | + soft: Color32::from_rgb(0x66, 0x70, 0x6d), | |
| 38 | + line: Color32::from_rgb(0xdd, 0xdb, 0xd3), | |
| 39 | + accent: Color32::from_rgb(0x1f, 0x7a, 0x6c), | |
| 40 | + link: Color32::from_rgb(0x1a, 0x5f, 0xa8), | |
| 41 | + field: Color32::from_rgb(0xff, 0xff, 0xff), | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + fn is_dark(ctx: &egui::Context) -> bool { | |
| 47 | + ctx.global_style().visuals.dark_mode | |
| 48 | + } | |
| 49 | + | |
| 50 | + pub fn install_style(ctx: &egui::Context, dark: Option<bool>) { | |
| 51 | + let theme = match dark { | |
| 52 | + Some(true) => egui::ThemePreference::Dark, | |
| 53 | + Some(false) => egui::ThemePreference::Light, | |
| 54 | + None => egui::ThemePreference::System, | |
| 55 | + }; | |
| 56 | + ctx.set_theme(theme); | |
| 57 | + for d in [true, false] { | |
| 58 | + let p = palette(d); | |
| 59 | + let style_theme = if d { egui::Theme::Dark } else { egui::Theme::Light }; | |
| 60 | + ctx.style_mut_of(style_theme, |s| { | |
| 61 | + s.visuals.panel_fill = p.bg; | |
| 62 | + s.visuals.window_fill = p.bar; | |
| 63 | + s.visuals.extreme_bg_color = p.field; | |
| 64 | + s.visuals.hyperlink_color = p.link; | |
| 65 | + s.visuals.selection.bg_fill = p.accent.gamma_multiply(0.35); | |
| 66 | + s.visuals.widgets.noninteractive.fg_stroke = Stroke::new(1.0, p.ink); | |
| 67 | + s.visuals.widgets.inactive.corner_radius = CornerRadius::same(18); | |
| 68 | + s.visuals.widgets.hovered.corner_radius = CornerRadius::same(18); | |
| 69 | + s.visuals.widgets.active.corner_radius = CornerRadius::same(18); | |
| 70 | + s.spacing.button_padding = Vec2::new(12.0, 6.0); | |
| 71 | + s.text_styles.insert(TextStyle::Body, FontId::new(17.0, FontFamily::Proportional)); | |
| 72 | + s.text_styles.insert(TextStyle::Button, FontId::new(15.0, FontFamily::Proportional)); | |
| 73 | + s.text_styles.insert(TextStyle::Monospace, FontId::new(14.5, FontFamily::Monospace)); | |
| 74 | + s.text_styles.insert(TextStyle::Small, FontId::new(12.5, FontFamily::Proportional)); | |
| 75 | + s.text_styles.insert(TextStyle::Heading, FontId::new(30.0, FontFamily::Proportional)); | |
| 76 | + }); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + pub fn shortcuts(app: &mut Clearwake, ctx: &egui::Context) { | |
| 81 | + let (back, fwd, reload, focus, mark, home) = ctx.input_mut(|i| { | |
| 82 | + let cmd = egui::Modifiers::COMMAND; | |
| 83 | + ( | |
| 84 | + i.consume_key(egui::Modifiers::ALT, Key::ArrowLeft) || i.consume_key(cmd, Key::OpenBracket) || i.consume_key(egui::Modifiers::NONE, Key::BrowserBack), | |
| 85 | + i.consume_key(egui::Modifiers::ALT, Key::ArrowRight) || i.consume_key(cmd, Key::CloseBracket), | |
| 86 | + i.consume_key(cmd, Key::R) || i.consume_key(egui::Modifiers::NONE, Key::F5), | |
| 87 | + i.consume_key(cmd, Key::L), | |
| 88 | + i.consume_key(cmd, Key::D), | |
| 89 | + i.consume_key(cmd | egui::Modifiers::SHIFT, Key::H), | |
| 90 | + ) | |
| 91 | + }); | |
| 92 | + if back { | |
| 93 | + app.back(); | |
| 94 | + } | |
| 95 | + if fwd { | |
| 96 | + app.forward(); | |
| 97 | + } | |
| 98 | + if reload { | |
| 99 | + app.reload(); | |
| 100 | + } | |
| 101 | + if focus { | |
| 102 | + app.address_focus = true; | |
| 103 | + } | |
| 104 | + if mark { | |
| 105 | + toggle_bookmark(app); | |
| 106 | + } | |
| 107 | + if home { | |
| 108 | + app.open(String::from("about:home"), true); | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 112 | + fn toggle_bookmark(app: &mut Clearwake) { | |
| 113 | + if let Some(u) = app.current_url() { | |
| 114 | + let t = app.current_title(); | |
| 115 | + app.bookmarks.toggle(&u, &t); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + #[derive(Clone, Copy)] | |
| 120 | + enum Icon { | |
| 121 | + Back, | |
| 122 | + Forward, | |
| 123 | + Reload, | |
| 124 | + Stop, | |
| 125 | + Home, | |
| 126 | + Star(bool), | |
| 127 | + Menu, | |
| 128 | + } | |
| 129 | + | |
| 130 | + /// A borderless toolbar button with an icon drawn in code (no icon font). | |
| 131 | + fn pill(ui: &mut egui::Ui, icon: Icon, enabled: bool, tip: &str) -> bool { | |
| 132 | + let (rect, resp) = ui.allocate_exact_size(Vec2::new(36.0, 32.0), if enabled { egui::Sense::click() } else { egui::Sense::hover() }); | |
| 133 | + let p = palette(is_dark(ui.ctx())); | |
| 134 | + let color = if !enabled { p.soft.gamma_multiply(0.45) } else if resp.hovered() { p.accent } else { p.ink }; | |
| 135 | + if enabled && resp.hovered() { | |
| 136 | + ui.painter().rect_filled(rect.shrink(1.0), 16.0, p.line.gamma_multiply(0.6)); | |
| 137 | + } | |
| 138 | + draw_icon(ui.painter(), rect.center(), icon, color); | |
| 139 | + let resp = resp.on_hover_text(tip); | |
| 140 | + enabled && resp.clicked() | |
| 141 | + } | |
| 142 | + | |
| 143 | + fn draw_icon(painter: &egui::Painter, c: egui::Pos2, icon: Icon, color: Color32) { | |
| 144 | + use egui::pos2; | |
| 145 | + let st = Stroke::new(1.8, color); | |
| 146 | + match icon { | |
| 147 | + Icon::Back | Icon::Forward => { | |
| 148 | + let d = if matches!(icon, Icon::Back) { -1.0 } else { 1.0 }; | |
| 149 | + painter.line_segment([pos2(c.x - 7.0 * d, c.y), pos2(c.x + 7.0 * d, c.y)], st); | |
| 150 | + painter.line_segment([pos2(c.x + 7.0 * d, c.y), pos2(c.x + 2.0 * d, c.y - 5.0)], st); | |
| 151 | + painter.line_segment([pos2(c.x + 7.0 * d, c.y), pos2(c.x + 2.0 * d, c.y + 5.0)], st); | |
| 152 | + } | |
| 153 | + Icon::Reload => { | |
| 154 | + let r = 7.0; | |
| 155 | + let pts: Vec<egui::Pos2> = (0..=20) | |
| 156 | + .map(|i| { | |
| 157 | + let a = -1.2 + i as f32 / 20.0 * 5.0; | |
| 158 | + pos2(c.x + r * a.cos(), c.y + r * a.sin()) | |
| 159 | + }) | |
| 160 | + .collect(); | |
| 161 | + let end = *pts.last().unwrap(); | |
| 162 | + painter.add(egui::Shape::line(pts, st)); | |
| 163 | + let a: f32 = -1.2 + 5.0; | |
| 164 | + let tip = pos2(end.x + 4.0 * (a + 1.2).cos(), end.y + 4.0 * (a + 1.2).sin()); | |
| 165 | + painter.line_segment([end, pos2(end.x + 4.5, end.y - 1.0)], st); | |
| 166 | + let _ = tip; | |
| 167 | + painter.line_segment([end, pos2(end.x + 0.5, end.y + 4.5)], st); | |
| 168 | + } | |
| 169 | + Icon::Stop => { | |
| 170 | + painter.line_segment([pos2(c.x - 6.0, c.y - 6.0), pos2(c.x + 6.0, c.y + 6.0)], st); | |
| 171 | + painter.line_segment([pos2(c.x + 6.0, c.y - 6.0), pos2(c.x - 6.0, c.y + 6.0)], st); | |
| 172 | + } | |
| 173 | + Icon::Home => { | |
| 174 | + let pts = vec![ | |
| 175 | + pos2(c.x - 7.0, c.y - 0.5), | |
| 176 | + pos2(c.x, c.y - 7.5), | |
| 177 | + pos2(c.x + 7.0, c.y - 0.5), | |
| 178 | + ]; | |
| 179 | + painter.add(egui::Shape::line(pts, st)); | |
| 180 | + let body = vec![pos2(c.x - 5.0, c.y - 2.0), pos2(c.x - 5.0, c.y + 7.0), pos2(c.x + 5.0, c.y + 7.0), pos2(c.x + 5.0, c.y - 2.0)]; | |
| 181 | + painter.add(egui::Shape::line(body, st)); | |
| 182 | + } | |
| 183 | + Icon::Star(filled) => { | |
| 184 | + let pts: Vec<egui::Pos2> = (0..10) | |
| 185 | + .map(|i| { | |
| 186 | + let r = if i % 2 == 0 { 8.0 } else { 3.6 }; | |
| 187 | + let a = -std::f32::consts::FRAC_PI_2 + i as f32 * std::f32::consts::PI / 5.0; | |
| 188 | + pos2(c.x + r * a.cos(), c.y + 0.6 + r * a.sin()) | |
| 189 | + }) | |
| 190 | + .collect(); | |
| 191 | + if filled { | |
| 192 | + painter.add(egui::Shape::convex_polygon(vec![c], color, Stroke::NONE)); | |
| 193 | + for i in 0..10 { | |
| 194 | + painter.add(egui::Shape::convex_polygon(vec![pos2(c.x, c.y + 0.6), pts[i], pts[(i + 1) % 10]], color, Stroke::NONE)); | |
| 195 | + } | |
| 196 | + } else { | |
| 197 | + painter.add(egui::Shape::closed_line(pts, st)); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + Icon::Menu => { | |
| 201 | + for dy in [-5.0, 0.0, 5.0] { | |
| 202 | + painter.line_segment([pos2(c.x - 7.0, c.y + dy), pos2(c.x + 7.0, c.y + dy)], st); | |
| 203 | + } | |
| 204 | + } | |
| 205 | + } | |
| 206 | + } | |
| 207 | + | |
| 208 | + /// A small shield, drawn before the status line. | |
| 209 | + fn shield(ui: &mut egui::Ui, color: Color32) { | |
| 210 | + use egui::pos2; | |
| 211 | + let (rect, _) = ui.allocate_exact_size(Vec2::new(14.0, 14.0), egui::Sense::hover()); | |
| 212 | + let c = rect.center(); | |
| 213 | + let pts = vec![ | |
| 214 | + pos2(c.x, c.y - 6.0), | |
| 215 | + pos2(c.x + 5.0, c.y - 4.0), | |
| 216 | + pos2(c.x + 4.5, c.y + 1.5), | |
| 217 | + pos2(c.x, c.y + 6.0), | |
| 218 | + pos2(c.x - 4.5, c.y + 1.5), | |
| 219 | + pos2(c.x - 5.0, c.y - 4.0), | |
| 220 | + ]; | |
| 221 | + ui.painter().add(egui::Shape::convex_polygon(pts, color, Stroke::NONE)); | |
| 222 | + } | |
| 223 | + | |
| 224 | + pub fn toolbar(app: &mut Clearwake, ui: &mut egui::Ui) { | |
| 225 | + let p = palette(is_dark(ui.ctx())); | |
| 226 | + egui::Panel::top("toolbar") | |
| 227 | + .frame(egui::Frame::new().fill(p.bar).inner_margin(egui::Margin::symmetric(10, 8)).stroke(Stroke::new(1.0, p.line))) | |
| 228 | + .show(ui, |ui| { | |
| 229 | + ui.horizontal(|ui| { | |
| 230 | + ui.spacing_mut().item_spacing.x = 4.0; | |
| 231 | + if pill(ui, Icon::Back, app.history.can_back(), "Back") { | |
| 232 | + app.back(); | |
| 233 | + } | |
| 234 | + if pill(ui, Icon::Forward, app.history.can_forward(), "Forward") { | |
| 235 | + app.forward(); | |
| 236 | + } | |
| 237 | + let loading = matches!(app.page, Page::Loading { .. }); | |
| 238 | + if loading { | |
| 239 | + if pill(ui, Icon::Stop, true, "Stop") { | |
| 240 | + app.generation += 1; | |
| 241 | + let url = app.current_url().unwrap_or_default(); | |
| 242 | + app.page = Page::Error { url, message: String::from("Stopped.") }; | |
| 243 | + } | |
| 244 | + } else if pill(ui, Icon::Reload, !matches!(app.page, Page::Home), "Reload") { | |
| 245 | + app.reload(); | |
| 246 | + } | |
| 247 | + if pill(ui, Icon::Home, true, "Home") { | |
| 248 | + app.open(String::from("about:home"), true); | |
| 249 | + } | |
| 250 | + | |
| 251 | + let right = 110.0; | |
| 252 | + let w = (ui.available_width() - right).max(120.0); | |
| 253 | + let edit = egui::TextEdit::singleline(&mut app.address) | |
| 254 | + .hint_text("Search or type a web address") | |
| 255 | + .desired_width(w) | |
| 256 | + .margin(egui::Margin::symmetric(14, 7)) | |
| 257 | + .font(FontId::new(15.5, FontFamily::Proportional)); | |
| 258 | + let resp = ui.add(edit); | |
| 259 | + if app.address_focus { | |
| 260 | + resp.request_focus(); | |
| 261 | + app.address_focus = false; | |
| 262 | + } | |
| 263 | + if resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)) { | |
| 264 | + let typed = app.address.clone(); | |
| 265 | + app.open_input(&typed); | |
| 266 | + } | |
| 267 | + | |
| 268 | + let saved = app.current_url().is_some_and(|u| app.bookmarks.contains(&u)); | |
| 269 | + if pill(ui, Icon::Star(saved), app.current_url().is_some(), if saved { "Remove bookmark" } else { "Bookmark this page" }) { | |
| 270 | + toggle_bookmark(app); | |
| 271 | + } | |
| 272 | + if pill(ui, Icon::Menu, true, "Bookmarks and settings") { | |
| 273 | + app.show_bookmarks = !app.show_bookmarks; | |
| 274 | + } | |
| 275 | + }); | |
| 276 | + if let Page::Loading { .. } = app.page { | |
| 277 | + let t = ui.input(|i| i.time) as f32; | |
| 278 | + let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.available_width(), 2.0), egui::Sense::hover()); | |
| 279 | + let x = rect.left() + (t * 0.6).fract() * rect.width(); | |
| 280 | + ui.painter().rect_filled(egui::Rect::from_min_size(egui::pos2(x - 60.0, rect.top()), Vec2::new(120.0, 2.0)).intersect(rect), 1.0, p.accent); | |
| 281 | + ui.ctx().request_repaint(); | |
| 282 | + } | |
| 283 | + }); | |
| 284 | + if app.show_bookmarks { | |
| 285 | + menu_panel(app, ui); | |
| 286 | + } | |
| 287 | + } | |
| 288 | + | |
| 289 | + fn menu_panel(app: &mut Clearwake, ui: &mut egui::Ui) { | |
| 290 | + let p = palette(is_dark(ui.ctx())); | |
| 291 | + egui::Panel::right("menu") | |
| 292 | + .resizable(false) | |
| 293 | + .exact_size(300.0) | |
| 294 | + .frame(egui::Frame::new().fill(p.bar).inner_margin(16).stroke(Stroke::new(1.0, p.line))) | |
| 295 | + .show(ui, |ui| { | |
| 296 | + ui.label(RichText::new("Bookmarks").size(20.0).strong()); | |
| 297 | + ui.add_space(6.0); | |
| 298 | + if app.bookmarks.items.is_empty() { | |
| 299 | + ui.label(RichText::new("Pages you bookmark show up here. They stay on this device.").color(p.soft)); | |
| 300 | + } | |
| 301 | + let mut open = None; | |
| 302 | + let mut remove = None; | |
| 303 | + egui::ScrollArea::vertical().max_height(ui.available_height() - 190.0).show(ui, |ui| { | |
| 304 | + for b in &app.bookmarks.items { | |
| 305 | + ui.horizontal(|ui| { | |
| 306 | + if ui.add(egui::Link::new(RichText::new(&b.title).color(p.link))).on_hover_text(&b.url).clicked() { | |
| 307 | + open = Some(b.url.clone()); | |
| 308 | + } | |
| 309 | + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { | |
| 310 | + if ui.small_button("Remove").clicked() { | |
| 311 | + remove = Some(b.url.clone()); | |
| 312 | + } | |
| 313 | + }); | |
| 314 | + }); | |
| 315 | + } | |
| 316 | + }); | |
| 317 | + if let Some(u) = remove { | |
| 318 | + app.bookmarks.remove(&u); | |
| 319 | + } | |
| 320 | + if let Some(u) = open { | |
| 321 | + app.open(u, true); | |
| 322 | + } | |
| 323 | + ui.add_space(12.0); | |
| 324 | + ui.separator(); | |
| 325 | + ui.label(RichText::new("Text size").strong()); | |
| 326 | + ui.horizontal(|ui| { | |
| 327 | + if ui.button("A−").clicked() { | |
| 328 | + app.text_scale = (app.text_scale - 0.1).max(0.7); | |
| 329 | + } | |
| 330 | + ui.label(format!("{}%", (app.text_scale * 100.0).round())); | |
| 331 | + if ui.button("A+").clicked() { | |
| 332 | + app.text_scale = (app.text_scale + 0.1).min(2.0); | |
| 333 | + } | |
| 334 | + }); | |
| 335 | + ui.label(RichText::new("Look").strong()); | |
| 336 | + ui.horizontal(|ui| { | |
| 337 | + for (label, v) in [("System", None), ("Light", Some(false)), ("Dark", Some(true))] { | |
| 338 | + if ui.selectable_label(app.dark == v, label).clicked() { | |
| 339 | + app.dark = v; | |
| 340 | + install_style(ui.ctx(), v); | |
| 341 | + } | |
| 342 | + } | |
| 343 | + }); | |
| 344 | + ui.add_space(8.0); | |
| 345 | + ui.label(RichText::new(format!("Clearwake {} · {} ads and trackers blocked so far", crate::VERSION, app.blocked_total)).small().color(p.soft)); | |
| 346 | + }); | |
| 347 | + } | |
| 348 | + | |
| 349 | + pub fn status_bar(app: &mut Clearwake, ui: &mut egui::Ui) { | |
| 350 | + let p = palette(is_dark(ui.ctx())); | |
| 351 | + egui::Panel::bottom("status") | |
| 352 | + .frame(egui::Frame::new().fill(p.bar).inner_margin(egui::Margin::symmetric(14, 4)).stroke(Stroke::new(1.0, p.line))) | |
| 353 | + .show(ui, |ui| { | |
| 354 | + ui.horizontal(|ui| { | |
| 355 | + if let Some(h) = &app.hover { | |
| 356 | + ui.label(RichText::new(h).small().color(p.soft)); | |
| 357 | + } else { | |
| 358 | + let msg = match &app.page { | |
| 359 | + Page::Doc(d) => { | |
| 360 | + let n = d.stats.blocked + d.stats.hidden; | |
| 361 | + if n > 0 || d.stats.scripts_skipped > 0 { | |
| 362 | + format!("Blocked {} ads and trackers · {} scripts never ran", n, d.stats.scripts_skipped) | |
| 363 | + } else { | |
| 364 | + String::from("No ads found on this page") | |
| 365 | + } | |
| 366 | + } | |
| 367 | + Page::Loading { .. } => String::from("Loading…"), | |
| 368 | + _ => String::from("Ad blocking is always on"), | |
| 369 | + }; | |
| 370 | + shield(ui, p.accent); | |
| 371 | + ui.label(RichText::new(msg).small().color(p.soft)); | |
| 372 | + } | |
| 373 | + }); | |
| 374 | + }); | |
| 375 | + app.hover = None; | |
| 376 | + } | |
| 377 | + | |
| 378 | + pub fn content(app: &mut Clearwake, ui: &mut egui::Ui) { | |
| 379 | + let p = palette(is_dark(ui.ctx())); | |
| 380 | + egui::CentralPanel::default().frame(egui::Frame::new().fill(p.bg)).show(ui, |ui| { | |
| 381 | + let mut scroll = egui::ScrollArea::vertical().auto_shrink([false, false]); | |
| 382 | + if app.scroll_to_top { | |
| 383 | + scroll = scroll.vertical_scroll_offset(0.0); | |
| 384 | + app.scroll_to_top = false; | |
| 385 | + } | |
| 386 | + scroll.show(ui, |ui| { | |
| 387 | + let full = ui.available_width(); | |
| 388 | + let col = full.min(COLUMN); | |
| 389 | + let side = ((full - col) / 2.0).max(0.0); | |
| 390 | + ui.horizontal(|ui| { | |
| 391 | + ui.add_space(side); | |
| 392 | + ui.vertical(|ui| { | |
| 393 | + ui.set_width(col - 24.0); | |
| 394 | + ui.add_space(28.0); | |
| 395 | + page(app, ui, &p); | |
| 396 | + ui.add_space(64.0); | |
| 397 | + }); | |
| 398 | + }); | |
| 399 | + }); | |
| 400 | + }); | |
| 401 | + } | |
| 402 | + | |
| 403 | + enum Action { | |
| 404 | + Open(String), | |
| 405 | + Search(String), | |
| 406 | + } | |
| 407 | + | |
| 408 | + fn page(app: &mut Clearwake, ui: &mut egui::Ui, p: &Palette) { | |
| 409 | + let mut action: Option<Action> = None; | |
| 410 | + let scale = app.text_scale; | |
| 411 | + match &app.page { | |
| 412 | + Page::Home => home(app, ui, p, &mut action), | |
| 413 | + Page::Loading { url } => { | |
| 414 | + ui.add_space(80.0); | |
| 415 | + ui.vertical_centered(|ui| { | |
| 416 | + ui.spinner(); | |
| 417 | + ui.label(RichText::new(short(url)).color(p.soft)); | |
| 418 | + }); | |
| 419 | + } | |
| 420 | + Page::Error { url, message } => { | |
| 421 | + ui.add_space(60.0); | |
| 422 | + ui.label(RichText::new("This page didn't open").size(26.0 * scale).strong().color(p.ink)); | |
| 423 | + ui.add_space(8.0); | |
| 424 | + ui.label(RichText::new(message).size(17.0 * scale).color(p.ink)); | |
| 425 | + ui.add_space(4.0); | |
| 426 | + ui.label(RichText::new(short(url)).small().color(p.soft)); | |
| 427 | + ui.add_space(14.0); | |
| 428 | + if ui.button("Try again").clicked() { | |
| 429 | + action = Some(Action::Open(url.clone())); | |
| 430 | + } | |
| 431 | + } | |
| 432 | + Page::Text { text, .. } => { | |
| 433 | + ui.add(egui::Label::new(RichText::new(text).monospace().size(14.5 * scale).color(p.ink)).wrap()); | |
| 434 | + } | |
| 435 | + Page::Picture { url } => { | |
| 436 | + picture(ui, app.pictures.get(url), "", None, None, &mut action, p); | |
| 437 | + } | |
| 438 | + Page::Doc(doc) => { | |
| 439 | + if !doc.title.is_empty() { | |
| 440 | + ui.label(RichText::new(doc.url.display_host()).small().color(p.soft)); | |
| 441 | + ui.add_space(2.0); | |
| 442 | + } | |
| 443 | + if doc.blocks.is_empty() { | |
| 444 | + ui.add_space(20.0); | |
| 445 | + ui.label(RichText::new("This page has nothing Clearwake can show without running its scripts.").color(p.soft)); | |
| 446 | + } | |
| 447 | + for (i, block) in doc.blocks.iter().enumerate() { | |
| 448 | + match block { | |
| 449 | + Block::Heading { level, spans } => { | |
| 450 | + let size = match level { | |
| 451 | + 1 => 32.0, | |
| 452 | + 2 => 25.0, | |
| 453 | + 3 => 21.0, | |
| 454 | + _ => 18.5, | |
| 455 | + } * scale; | |
| 456 | + ui.add_space(if *level <= 2 { 18.0 } else { 12.0 }); | |
| 457 | + spans_ui(ui, spans, size, true, false, p, &mut app.hover, &mut action); | |
| 458 | + ui.add_space(4.0); | |
| 459 | + } | |
| 460 | + Block::Paragraph { spans, quote } => { | |
| 461 | + ui.add_space(6.0); | |
| 462 | + if *quote { | |
| 463 | + egui::Frame::new() | |
| 464 | + .inner_margin(egui::Margin { left: 14, right: 0, top: 2, bottom: 2 }) | |
| 465 | + .show(ui, |ui| { | |
| 466 | + let r = ui.max_rect(); | |
| 467 | + ui.painter().vline(r.left() - 12.0, r.y_range(), Stroke::new(3.0, p.line)); | |
| 468 | + spans_ui(ui, spans, 17.0 * scale, false, true, p, &mut app.hover, &mut action); | |
| 469 | + }); | |
| 470 | + } else { | |
| 471 | + spans_ui(ui, spans, 17.0 * scale, false, false, p, &mut app.hover, &mut action); | |
| 472 | + } | |
| 473 | + ui.add_space(6.0); | |
| 474 | + } | |
| 475 | + Block::ListItem { depth, marker, spans } => { | |
| 476 | + ui.horizontal_top(|ui| { | |
| 477 | + ui.add_space(8.0 + 20.0 * (*depth as f32 - 1.0).clamp(0.0, 6.0)); | |
| 478 | + ui.add_sized([22.0, 20.0 * scale], egui::Label::new(RichText::new(marker).size(17.0 * scale).color(p.soft))); | |
| 479 | + ui.vertical(|ui| { | |
| 480 | + spans_ui(ui, spans, 17.0 * scale, false, false, p, &mut app.hover, &mut action); | |
| 481 | + }); | |
| 482 | + }); | |
| 483 | + ui.add_space(3.0); | |
| 484 | + } | |
| 485 | + Block::Code(code) => { | |
| 486 | + ui.add_space(6.0); | |
| 487 | + egui::Frame::new().fill(p.bar).corner_radius(8).inner_margin(12).show(ui, |ui| { | |
| 488 | + egui::ScrollArea::horizontal().id_salt(("code", i)).show(ui, |ui| { | |
| 489 | + ui.add(egui::Label::new(RichText::new(code).monospace().size(14.0 * scale).color(p.ink)).extend()); | |
| 490 | + }); | |
| 491 | + }); | |
| 492 | + ui.add_space(6.0); | |
| 493 | + } | |
| 494 | + Block::Image { src, alt, width, link, .. } => { | |
| 495 | + ui.add_space(6.0); | |
| 496 | + picture(ui, app.pictures.get(src), alt, *width, link.as_deref(), &mut action, p); | |
| 497 | + ui.add_space(6.0); | |
| 498 | + } | |
| 499 | + Block::Rule => { | |
| 500 | + ui.add_space(8.0); | |
| 501 | + ui.separator(); | |
| 502 | + ui.add_space(8.0); | |
| 503 | + } | |
| 504 | + Block::Form(form) => { | |
| 505 | + let text = app.forms.entry(i).or_insert_with(|| form.value.clone()); | |
| 506 | + if let Some(t) = form_ui(ui, form, text, p) { | |
| 507 | + action = Some(Action::Open(form.target(&t))); | |
| 508 | + } | |
| 509 | + } | |
| 510 | + } | |
| 511 | + } | |
| 512 | + } | |
| 513 | + } | |
| 514 | + match action { | |
| 515 | + Some(Action::Open(u)) => app.open(u, true), | |
| 516 | + Some(Action::Search(s)) => app.open_input(&s), | |
| 517 | + None => {} | |
| 518 | + } | |
| 519 | + } | |
| 520 | + | |
| 521 | + fn home(app: &mut Clearwake, ui: &mut egui::Ui, p: &Palette, action: &mut Option<Action>) { | |
| 522 | + ui.add_space(70.0); | |
| 523 | + ui.vertical_centered(|ui| { | |
| 524 | + let (rect, _) = ui.allocate_exact_size(Vec2::splat(64.0), egui::Sense::hover()); | |
| 525 | + draw_mark(ui.painter(), rect, p); | |
| 526 | + ui.add_space(10.0); | |
| 527 | + ui.label(RichText::new("Clearwake").size(40.0).strong().color(p.ink)); | |
| 528 | + ui.label(RichText::new("Less noise. More web.").size(18.0).color(p.soft)); | |
| 529 | + ui.add_space(24.0); | |
| 530 | + let resp = ui.add( | |
| 531 | + egui::TextEdit::singleline(&mut app.home_search) | |
| 532 | + .hint_text("Search the web or type an address") | |
| 533 | + .desired_width(ui.available_width().min(520.0)) | |
| 534 | + .margin(egui::Margin::symmetric(18, 11)) | |
| 535 | + .font(FontId::new(17.0, FontFamily::Proportional)), | |
| 536 | + ); | |
| 537 | + let go = resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)); | |
| 538 | + ui.add_space(10.0); | |
| 539 | + let clicked = ui.add(egui::Button::new(RichText::new("Search").color(Color32::WHITE)).fill(p.accent).min_size(Vec2::new(120.0, 36.0))).clicked(); | |
| 540 | + if (go || clicked) && !app.home_search.trim().is_empty() { | |
| 541 | + *action = Some(Action::Search(app.home_search.trim().to_string())); | |
| 542 | + } | |
| 543 | + ui.add_space(26.0); | |
| 544 | + ui.label( | |
| 545 | + RichText::new(format!( | |
| 546 | + "Ads and trackers are blocked before they load. Scripts never run. {} built-in rules, always on.", | |
| 547 | + app.filter.rule_count() | |
| 548 | + )) | |
| 549 | + .color(p.soft), | |
| 550 | + ); | |
| 551 | + }); | |
| 552 | + if !app.bookmarks.items.is_empty() { | |
| 553 | + ui.add_space(36.0); | |
| 554 | + ui.label(RichText::new("Bookmarks").size(20.0).strong().color(p.ink)); | |
| 555 | + ui.add_space(6.0); | |
| 556 | + for b in &app.bookmarks.items { | |
| 557 | + if ui.add(egui::Link::new(RichText::new(&b.title).size(17.0).color(p.link))).on_hover_text(&b.url).clicked() { | |
| 558 | + *action = Some(Action::Open(b.url.clone())); | |
| 559 | + } | |
| 560 | + ui.add_space(2.0); | |
| 561 | + } | |
| 562 | + } | |
| 563 | + } | |
| 564 | + | |
| 565 | + #[allow(clippy::too_many_arguments)] | |
| 566 | + fn spans_ui(ui: &mut egui::Ui, spans: &[Inline], size: f32, heading: bool, quote: bool, p: &Palette, hover: &mut Option<String>, action: &mut Option<Action>) { | |
| 567 | + ui.horizontal_wrapped(|ui| { | |
| 568 | + ui.spacing_mut().item_spacing = Vec2::new(0.0, 3.0); | |
| 569 | + for sp in spans { | |
| 570 | + for (n, piece) in sp.text.split('\n').enumerate() { | |
| 571 | + if n > 0 { | |
| 572 | + ui.end_row(); | |
| 573 | + } | |
| 574 | + if piece.is_empty() { | |
| 575 | + continue; | |
| 576 | + } | |
| 577 | + let mut rt = RichText::new(piece).size(size); | |
| 578 | + if sp.code { | |
| 579 | + rt = rt.monospace().size(size * 0.88).background_color(p.bar); | |
| 580 | + } | |
| 581 | + if heading || sp.bold { | |
| 582 | + rt = rt.strong(); | |
| 583 | + } | |
| 584 | + if sp.italic || quote { | |
| 585 | + rt = rt.italics(); | |
| 586 | + } | |
| 587 | + match &sp.link { | |
| 588 | + Some(href) => { | |
| 589 | + let r = ui.add(egui::Link::new(rt.color(p.link))); | |
| 590 | + if r.hovered() { | |
| 591 | + *hover = Some(href.clone()); | |
| 592 | + } | |
| 593 | + if r.clicked() { | |
| 594 | + *action = Some(Action::Open(href.clone())); | |
| 595 | + } | |
| 596 | + } | |
| 597 | + None => { | |
| 598 | + let color = if heading { p.ink } else if quote { p.soft } else { p.ink }; | |
| 599 | + ui.add(egui::Label::new(rt.color(color)).wrap()); | |
| 600 | + } | |
| 601 | + } | |
| 602 | + } | |
| 603 | + } | |
| 604 | + }); | |
| 605 | + } | |
| 606 | + | |
| 607 | + fn picture(ui: &mut egui::Ui, pic: Option<&Picture>, alt: &str, width: Option<u32>, link: Option<&str>, action: &mut Option<Action>, p: &Palette) { | |
| 608 | + let max_w = ui.available_width(); | |
| 609 | + match pic { | |
| 610 | + Some(Picture::Ready(tex)) => { | |
| 611 | + let [w, h] = tex.resolution(); | |
| 612 | + let mut want = w as f32; | |
| 613 | + if let Some(attr) = width { | |
| 614 | + want = want.min(attr as f32 * 1.0); | |
| 615 | + } | |
| 616 | + let scale = (want.min(max_w)) / w as f32; | |
| 617 | + let size = Vec2::new(w as f32 * scale, h as f32 * scale); | |
| 618 | + let mut img = egui::Image::new(egui::load::SizedTexture::new(tex.id(), size)).corner_radius(6); | |
| 619 | + if link.is_some() { | |
| 620 | + img = img.sense(egui::Sense::click()); | |
| 621 | + } | |
| 622 | + let r = ui.add(img); | |
| 623 | + let r = if alt.is_empty() { r } else { r.on_hover_text(alt) }; | |
| 624 | + if let Some(l) = link { | |
| 625 | + if r.clicked() { | |
| 626 | + *action = Some(Action::Open(l.to_string())); | |
| 627 | + } | |
| 628 | + } | |
| 629 | + } | |
| 630 | + Some(Picture::Loading) => { | |
| 631 | + let h = 120.0_f32.min(max_w * 0.4); | |
| 632 | + let (rect, _) = ui.allocate_exact_size(Vec2::new(max_w.min(width.map(|w| w as f32).unwrap_or(max_w)), h), egui::Sense::hover()); | |
| 633 | + ui.painter().rect_filled(rect, 6.0, p.bar); | |
| 634 | + if !alt.is_empty() { | |
| 635 | + ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, short(alt), FontId::proportional(14.0), p.soft); | |
| 636 | + } | |
| 637 | + } | |
| 638 | + _ => { | |
| 639 | + if !alt.is_empty() { | |
| 640 | + ui.label(RichText::new(format!("[{alt}]")).italics().color(p.soft)); | |
| 641 | + } | |
| 642 | + } | |
| 643 | + } | |
| 644 | + } | |
| 645 | + | |
| 646 | + fn form_ui(ui: &mut egui::Ui, form: &Form, text: &mut String, p: &Palette) -> Option<String> { | |
| 647 | + let mut out = None; | |
| 648 | + ui.add_space(6.0); | |
| 649 | + ui.horizontal(|ui| { | |
| 650 | + let hint = if form.placeholder.is_empty() { "Search" } else { form.placeholder.as_str() }; | |
| 651 | + let r = ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width((ui.available_width() - 110.0).max(120.0)).margin(egui::Margin::symmetric(12, 6))); | |
| 652 | + let enter = r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)); | |
| 653 | + let label = if form.submit.is_empty() { "Search" } else { form.submit.as_str() }; | |
| 654 | + let click = ui.add(egui::Button::new(RichText::new(label).color(Color32::WHITE)).fill(p.accent)).clicked(); | |
| 655 | + if enter || click { | |
| 656 | + out = Some(text.clone()); | |
| 657 | + } | |
| 658 | + }); | |
| 659 | + ui.add_space(6.0); | |
| 660 | + out | |
| 661 | + } | |
| 662 | + | |
| 663 | + fn short(s: &str) -> String { | |
| 664 | + if s.chars().count() > 90 { | |
| 665 | + let mut t: String = s.chars().take(88).collect(); | |
| 666 | + t.push('…'); | |
| 667 | + t | |
| 668 | + } else { | |
| 669 | + s.to_string() | |
| 670 | + } | |
| 671 | + } | |
| 672 | + | |
| 673 | + /// The Clearwake mark: a calm circle with a wake line through it. | |
| 674 | + fn draw_mark(painter: &egui::Painter, rect: egui::Rect, p: &Palette) { | |
| 675 | + let c = rect.center(); | |
| 676 | + let r = rect.width() / 2.0; | |
| 677 | + painter.circle_filled(c, r, p.accent); | |
| 678 | + let wave = |y: f32, amp: f32| -> Vec<egui::Pos2> { | |
| 679 | + (0..=24).map(|i| { | |
| 680 | + let t = i as f32 / 24.0; | |
| 681 | + let x = c.x - r * 0.62 + t * r * 1.24; | |
| 682 | + egui::pos2(x, y + (t * std::f32::consts::TAU).sin() * amp) | |
| 683 | + }).collect() | |
| 684 | + }; | |
| 685 | + painter.add(egui::Shape::line(wave(c.y - r * 0.12, r * 0.12), Stroke::new(r * 0.11, Color32::WHITE))); | |
| 686 | + painter.add(egui::Shape::line(wave(c.y + r * 0.22, r * 0.08), Stroke::new(r * 0.08, Color32::from_white_alpha(170)))); | |
| 687 | + } | |
| 688 | + | |
| 689 | + /// The window icon, drawn in code so every platform shares it. | |
| 690 | + #[allow(dead_code)] | |
| 691 | + pub fn app_icon() -> egui::IconData { | |
| 692 | + let n = 128usize; | |
| 693 | + let mut rgba = vec![0u8; n * n * 4]; | |
| 694 | + let (cr, cg, cb) = (0x1f_u8, 0x7a_u8, 0x6c_u8); | |
| 695 | + let c = n as f32 / 2.0; | |
| 696 | + let r = c - 4.0; | |
| 697 | + for y in 0..n { | |
| 698 | + for x in 0..n { | |
| 699 | + let (fx, fy) = (x as f32 + 0.5 - c, y as f32 + 0.5 - c); | |
| 700 | + let d = (fx * fx + fy * fy).sqrt(); | |
| 701 | + let a = (r + 0.5 - d).clamp(0.0, 1.0); | |
| 702 | + if a <= 0.0 { | |
| 703 | + continue; | |
| 704 | + } | |
| 705 | + let t = (fx + r * 0.62) / (r * 1.24); | |
| 706 | + let mut px = (cr, cg, cb); | |
| 707 | + if (0.0..=1.0).contains(&t) { | |
| 708 | + let w1 = -r * 0.12 + (t * std::f32::consts::TAU).sin() * r * 0.12; | |
| 709 | + let w2 = r * 0.22 + (t * std::f32::consts::TAU).sin() * r * 0.08; | |
| 710 | + if (fy - w1).abs() < r * 0.055 { | |
| 711 | + px = (255, 255, 255); | |
| 712 | + } else if (fy - w2).abs() < r * 0.04 { | |
| 713 | + px = (190, 222, 216); | |
| 714 | + } | |
| 715 | + } | |
| 716 | + let i = (y * n + x) * 4; | |
| 717 | + rgba[i] = px.0; | |
| 718 | + rgba[i + 1] = px.1; | |
| 719 | + rgba[i + 2] = px.2; | |
| 720 | + rgba[i + 3] = (a * 255.0) as u8; | |
| 721 | + } | |
| 722 | + } | |
| 723 | + egui::IconData { rgba, width: n as u32, height: n as u32 } | |
| 724 | + } |
crates/clearwake-core/Cargo.toml added
| 1 | + [package] | |
| 2 | + name = "clearwake-core" | |
| 3 | + description = "Clearwake's page engine: URLs, an HTML reader and always-on ad blocking. no_std + alloc, integer math only, so it runs on the Glimmer kernel too." | |
| 4 | + version.workspace = true | |
| 5 | + edition.workspace = true | |
| 6 | + license.workspace = true | |
| 7 | + | |
| 8 | + [dependencies] | |
| 9 | + | |
| 10 | + [features] | |
| 11 | + default = [] | |
| 12 | + std = [] |
crates/clearwake-core/src/bookmarks.rs added
| 1 | + //! Bookmarks, kept on this device only. No account, no sync. | |
| 2 | + | |
| 3 | + use alloc::string::{String, ToString}; | |
| 4 | + use alloc::vec::Vec; | |
| 5 | + | |
| 6 | + #[derive(Clone, Debug, PartialEq, Eq)] | |
| 7 | + pub struct Bookmark { | |
| 8 | + pub title: String, | |
| 9 | + pub url: String, | |
| 10 | + } | |
| 11 | + | |
| 12 | + #[derive(Clone, Debug, Default, PartialEq, Eq)] | |
| 13 | + pub struct Bookmarks { | |
| 14 | + pub items: Vec<Bookmark>, | |
| 15 | + } | |
| 16 | + | |
| 17 | + impl Bookmarks { | |
| 18 | + pub fn contains(&self, url: &str) -> bool { | |
| 19 | + self.items.iter().any(|b| b.url == url) | |
| 20 | + } | |
| 21 | + | |
| 22 | + /// Add the page, or remove it when it is already saved. Returns true | |
| 23 | + /// when the page is saved afterwards. | |
| 24 | + pub fn toggle(&mut self, url: &str, title: &str) -> bool { | |
| 25 | + if let Some(i) = self.items.iter().position(|b| b.url == url) { | |
| 26 | + self.items.remove(i); | |
| 27 | + false | |
| 28 | + } else { | |
| 29 | + let title = if title.trim().is_empty() { url } else { title.trim() }; | |
| 30 | + self.items.push(Bookmark { title: title.to_string(), url: url.to_string() }); | |
| 31 | + true | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + pub fn remove(&mut self, url: &str) { | |
| 36 | + self.items.retain(|b| b.url != url); | |
| 37 | + } | |
| 38 | + | |
| 39 | + /// One bookmark per line: address, a tab, then the title. | |
| 40 | + pub fn to_text(&self) -> String { | |
| 41 | + let mut s = String::new(); | |
| 42 | + for b in &self.items { | |
| 43 | + s.push_str(&b.url); | |
| 44 | + s.push('\t'); | |
| 45 | + s.push_str(&b.title.replace(['\t', '\n'], " ")); | |
| 46 | + s.push('\n'); | |
| 47 | + } | |
| 48 | + s | |
| 49 | + } | |
| 50 | + | |
| 51 | + pub fn from_text(text: &str) -> Bookmarks { | |
| 52 | + let items = text | |
| 53 | + .lines() | |
| 54 | + .filter_map(|l| { | |
| 55 | + let mut p = l.splitn(2, '\t'); | |
| 56 | + let url = p.next()?.trim(); | |
| 57 | + if url.is_empty() { | |
| 58 | + return None; | |
| 59 | + } | |
| 60 | + let title = p.next().unwrap_or(url).trim(); | |
| 61 | + Some(Bookmark { title: title.to_string(), url: url.to_string() }) | |
| 62 | + }) | |
| 63 | + .collect(); | |
| 64 | + Bookmarks { items } | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + #[cfg(test)] | |
| 69 | + mod tests { | |
| 70 | + use super::*; | |
| 71 | + #[test] | |
| 72 | + fn round_trip() { | |
| 73 | + let mut b = Bookmarks::default(); | |
| 74 | + assert!(b.toggle("https://a.example/", "A\tpage")); | |
| 75 | + assert!(b.toggle("https://b.example/", "")); | |
| 76 | + let back = Bookmarks::from_text(&b.to_text()); | |
| 77 | + assert_eq!(back.items[0].title, "A page"); | |
| 78 | + assert_eq!(back.items[1].title, "https://b.example/"); | |
| 79 | + assert!(!b.toggle("https://a.example/", "A")); | |
| 80 | + assert!(!b.contains("https://a.example/")); | |
| 81 | + } | |
| 82 | + } |
crates/clearwake-core/src/filter.rs added
| 1 | + //! The ad and tracker filter. Always on: there is no off switch, no | |
| 2 | + //! allowlist and no exception rule. Every address Clearwake would load | |
| 3 | + //! (pages, pictures) is checked first; a blocked one is never fetched. | |
| 4 | + | |
| 5 | + use crate::url::Url; | |
| 6 | + use alloc::collections::BTreeSet; | |
| 7 | + use alloc::string::String; | |
| 8 | + use alloc::vec::Vec; | |
| 9 | + | |
| 10 | + /// Built-in rules shipped inside every Clearwake. | |
| 11 | + pub const BUILT_IN: &str = include_str!("filters.txt"); | |
| 12 | + | |
| 13 | + pub struct Filter { | |
| 14 | + hosts: BTreeSet<String>, | |
| 15 | + paths: Vec<String>, | |
| 16 | + } | |
| 17 | + | |
| 18 | + impl Filter { | |
| 19 | + /// The built-in list. | |
| 20 | + pub fn new() -> Filter { | |
| 21 | + Filter::from_rules(BUILT_IN) | |
| 22 | + } | |
| 23 | + | |
| 24 | + /// Parse a list. Supported: `||host^`, a bare `host`, and `/path text/`. | |
| 25 | + /// Exception rules (`@@`) and cosmetic rules (`##`) are ignored on purpose. | |
| 26 | + pub fn from_rules(text: &str) -> Filter { | |
| 27 | + let mut hosts = BTreeSet::new(); | |
| 28 | + let mut paths = Vec::new(); | |
| 29 | + for line in text.lines() { | |
| 30 | + let l = line.trim(); | |
| 31 | + if l.is_empty() || l.starts_with('!') || l.starts_with('[') || l.starts_with("@@") || l.contains("##") || l.contains("#@#") { | |
| 32 | + continue; | |
| 33 | + } | |
| 34 | + let l = l.split('$').next().unwrap_or(""); | |
| 35 | + if let Some(h) = l.strip_prefix("||") { | |
| 36 | + let h = h.trim_end_matches('^').trim_end_matches('/'); | |
| 37 | + if !h.is_empty() && !h.contains(['/', '*']) { | |
| 38 | + hosts.insert(h.to_ascii_lowercase()); | |
| 39 | + } | |
| 40 | + } else if l.starts_with('/') { | |
| 41 | + let p = l.trim_end_matches('/'); | |
| 42 | + if p.len() > 3 { | |
| 43 | + paths.push(p.to_ascii_lowercase()); | |
| 44 | + } | |
| 45 | + } else if l.contains('.') && !l.contains(['/', '*', '^']) { | |
| 46 | + hosts.insert(l.to_ascii_lowercase()); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + Filter { hosts, paths } | |
| 50 | + } | |
| 51 | + | |
| 52 | + pub fn rule_count(&self) -> usize { | |
| 53 | + self.hosts.len() + self.paths.len() | |
| 54 | + } | |
| 55 | + | |
| 56 | + /// True when Clearwake must not load this address. | |
| 57 | + pub fn blocks(&self, url: &Url) -> bool { | |
| 58 | + if url.is_about() { | |
| 59 | + return false; | |
| 60 | + } | |
| 61 | + if self.blocks_host(&url.host) { | |
| 62 | + return true; | |
| 63 | + } | |
| 64 | + if self.paths.is_empty() { | |
| 65 | + return false; | |
| 66 | + } | |
| 67 | + let mut p = url.path.to_ascii_lowercase(); | |
| 68 | + if let Some(q) = &url.query { | |
| 69 | + p.push('?'); | |
| 70 | + p.push_str(&q.to_ascii_lowercase()); | |
| 71 | + } | |
| 72 | + self.paths.iter().any(|r| p.contains(r.as_str())) | |
| 73 | + } | |
| 74 | + | |
| 75 | + /// True when the host or any parent domain is on the list. | |
| 76 | + pub fn blocks_host(&self, host: &str) -> bool { | |
| 77 | + let mut h = host; | |
| 78 | + loop { | |
| 79 | + if self.hosts.contains(h) { | |
| 80 | + return true; | |
| 81 | + } | |
| 82 | + match h.find('.') { | |
| 83 | + Some(i) => h = &h[i + 1..], | |
| 84 | + None => return false, | |
| 85 | + } | |
| 86 | + } | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + impl Default for Filter { | |
| 91 | + fn default() -> Self { | |
| 92 | + Filter::new() | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + #[cfg(test)] | |
| 97 | + mod tests { | |
| 98 | + use super::*; | |
| 99 | + | |
| 100 | + fn b(f: &Filter, s: &str) -> bool { | |
| 101 | + f.blocks(&Url::parse(s).unwrap()) | |
| 102 | + } | |
| 103 | + | |
| 104 | + #[test] | |
| 105 | + fn built_in() { | |
| 106 | + let f = Filter::new(); | |
| 107 | + assert!(f.rule_count() > 150); | |
| 108 | + assert!(b(&f, "https://securepubads.g.doubleclick.net/tag/js/gpt.js")); | |
| 109 | + assert!(b(&f, "https://www.googletagmanager.com/gtm.js?id=1")); | |
| 110 | + assert!(b(&f, "https://news.example/pagead/show_ads.js")); | |
| 111 | + assert!(!b(&f, "https://en.wikipedia.org/wiki/Rust")); | |
| 112 | + assert!(!b(&f, "https://notdoubleclick.net/")); | |
| 113 | + assert!(!b(&f, "https://example.com/headlines/")); | |
| 114 | + } | |
| 115 | + | |
| 116 | + #[test] | |
| 117 | + fn exceptions_are_ignored() { | |
| 118 | + let f = Filter::from_rules("||ads.example^\n@@||ads.example^\nexample.org##.ad"); | |
| 119 | + assert!(b(&f, "https://ads.example/x")); | |
| 120 | + assert!(!b(&f, "https://example.org/")); | |
| 121 | + } | |
| 122 | + } |
crates/clearwake-core/src/filters.txt added
| 1 | + ! Clearwake built-in rules. Always on. No exception rules, no allowlist. | |
| 2 | + ! Syntax: ||host^ blocks a host and everything under it. | |
| 3 | + ! /text/ blocks any address whose path contains the text. | |
| 4 | + ! Ad networks | |
| 5 | + ||doubleclick.net^ | |
| 6 | + ||googlesyndication.com^ | |
| 7 | + ||googleadservices.com^ | |
| 8 | + ||adservice.google.com^ | |
| 9 | + ||pagead2.googlesyndication.com^ | |
| 10 | + ||adnxs.com^ | |
| 11 | + ||adsrvr.org^ | |
| 12 | + ||taboola.com^ | |
| 13 | + ||outbrain.com^ | |
| 14 | + ||criteo.com^ | |
| 15 | + ||criteo.net^ | |
| 16 | + ||pubmatic.com^ | |
| 17 | + ||openx.net^ | |
| 18 | + ||rubiconproject.com^ | |
| 19 | + ||casalemedia.com^ | |
| 20 | + ||smartadserver.com^ | |
| 21 | + ||adform.net^ | |
| 22 | + ||advertising.com^ | |
| 23 | + ||amazon-adsystem.com^ | |
| 24 | + ||media.net^ | |
| 25 | + ||yieldmo.com^ | |
| 26 | + ||sharethrough.com^ | |
| 27 | + ||triplelift.com^ | |
| 28 | + ||3lift.com^ | |
| 29 | + ||indexexchange.com^ | |
| 30 | + ||teads.tv^ | |
| 31 | + ||spotxchange.com^ | |
| 32 | + ||spotx.tv^ | |
| 33 | + ||springserve.com^ | |
| 34 | + ||sovrn.com^ | |
| 35 | + ||lijit.com^ | |
| 36 | + ||gumgum.com^ | |
| 37 | + ||kargo.com^ | |
| 38 | + ||adroll.com^ | |
| 39 | + ||revcontent.com^ | |
| 40 | + ||mgid.com^ | |
| 41 | + ||zergnet.com^ | |
| 42 | + ||nativo.com^ | |
| 43 | + ||bidswitch.net^ | |
| 44 | + ||contextweb.com^ | |
| 45 | + ||districtm.io^ | |
| 46 | + ||emxdgt.com^ | |
| 47 | + ||33across.com^ | |
| 48 | + ||yieldlab.net^ | |
| 49 | + ||adkernel.com^ | |
| 50 | + ||adtech.de^ | |
| 51 | + ||admixer.net^ | |
| 52 | + ||adition.com^ | |
| 53 | + ||adblade.com^ | |
| 54 | + ||adcolony.com^ | |
| 55 | + ||applovin.com^ | |
| 56 | + ||unityads.unity3d.com^ | |
| 57 | + ||inmobi.com^ | |
| 58 | + ||smaato.net^ | |
| 59 | + ||mopub.com^ | |
| 60 | + ||chartboost.com^ | |
| 61 | + ||vungle.com^ | |
| 62 | + ||propellerads.com^ | |
| 63 | + ||popads.net^ | |
| 64 | + ||popcash.net^ | |
| 65 | + ||exoclick.com^ | |
| 66 | + ||juicyads.com^ | |
| 67 | + ||trafficjunky.net^ | |
| 68 | + ||adsterra.com^ | |
| 69 | + ||hilltopads.net^ | |
| 70 | + ||adcash.com^ | |
| 71 | + ||infolinks.com^ | |
| 72 | + ||bidvertiser.com^ | |
| 73 | + ||buysellads.com^ | |
| 74 | + ||carbonads.com^ | |
| 75 | + ||servedby-buysellads.com^ | |
| 76 | + ||adzerk.net^ | |
| 77 | + ||adbutler.com^ | |
| 78 | + ||serving-sys.com^ | |
| 79 | + ||flashtalking.com^ | |
| 80 | + ||sizmek.com^ | |
| 81 | + ||adsafeprotected.com^ | |
| 82 | + ||moatads.com^ | |
| 83 | + ||doubleverify.com^ | |
| 84 | + ||imrworldwide.com^ | |
| 85 | + ||ads.linkedin.com^ | |
| 86 | + ||ads-twitter.com^ | |
| 87 | + ||ads.yahoo.com^ | |
| 88 | + ||yieldmanager.com^ | |
| 89 | + ||ad.turn.com^ | |
| 90 | + ||mathtag.com^ | |
| 91 | + ||rlcdn.com^ | |
| 92 | + ||bluekai.com^ | |
| 93 | + ||demdex.net^ | |
| 94 | + ||krxd.net^ | |
| 95 | + ||exelator.com^ | |
| 96 | + ||eyeota.net^ | |
| 97 | + ||tapad.com^ | |
| 98 | + ||agkn.com^ | |
| 99 | + ||adsymptotic.com^ | |
| 100 | + ||zemanta.com^ | |
| 101 | + ||plista.com^ | |
| 102 | + ||ligatus.com^ | |
| 103 | + ||adhigh.net^ | |
| 104 | + ||adskeeper.com^ | |
| 105 | + ||steepto.com^ | |
| 106 | + ||lockerdome.com^ | |
| 107 | + ||connatix.com^ | |
| 108 | + ||primis.tech^ | |
| 109 | + ||vidoomy.com^ | |
| 110 | + ||aniview.com^ | |
| 111 | + ||ad.plus^ | |
| 112 | + ||adpushup.com^ | |
| 113 | + ||ezoic.net^ | |
| 114 | + ||ezojs.com^ | |
| 115 | + ||mediavine.com^ | |
| 116 | + ||adthrive.com^ | |
| 117 | + ||raptive.com^ | |
| 118 | + ||freestar.io^ | |
| 119 | + ||pubfig.io^ | |
| 120 | + ||confiant-integrations.net^ | |
| 121 | + ||prebid.org^ | |
| 122 | + ! Trackers and analytics | |
| 123 | + ||google-analytics.com^ | |
| 124 | + ||googletagmanager.com^ | |
| 125 | + ||googletagservices.com^ | |
| 126 | + ||analytics.google.com^ | |
| 127 | + ||scorecardresearch.com^ | |
| 128 | + ||quantserve.com^ | |
| 129 | + ||quantcount.com^ | |
| 130 | + ||chartbeat.com^ | |
| 131 | + ||chartbeat.net^ | |
| 132 | + ||hotjar.com^ | |
| 133 | + ||hotjar.io^ | |
| 134 | + ||mouseflow.com^ | |
| 135 | + ||fullstory.com^ | |
| 136 | + ||crazyegg.com^ | |
| 137 | + ||clarity.ms^ | |
| 138 | + ||newrelic.com^ | |
| 139 | + ||nr-data.net^ | |
| 140 | + ||segment.io^ | |
| 141 | + ||segment.com^ | |
| 142 | + ||mixpanel.com^ | |
| 143 | + ||amplitude.com^ | |
| 144 | + ||heap.io^ | |
| 145 | + ||heapanalytics.com^ | |
| 146 | + ||kissmetrics.com^ | |
| 147 | + ||optimizely.com^ | |
| 148 | + ||omtrdc.net^ | |
| 149 | + ||2o7.net^ | |
| 150 | + ||everesttech.net^ | |
| 151 | + ||parsely.com^ | |
| 152 | + ||parse.ly^ | |
| 153 | + ||comscore.com^ | |
| 154 | + ||branch.io^ | |
| 155 | + ||app-measurement.com^ | |
| 156 | + ||connect.facebook.net^ | |
| 157 | + ||pixel.facebook.com^ | |
| 158 | + ||analytics.tiktok.com^ | |
| 159 | + ||ads.tiktok.com^ | |
| 160 | + ||analytics.twitter.com^ | |
| 161 | + ||static.ads-twitter.com^ | |
| 162 | + ||px.ads.linkedin.com^ | |
| 163 | + ||snap.licdn.com^ | |
| 164 | + ||bat.bing.com^ | |
| 165 | + ||ads.pinterest.com^ | |
| 166 | + ||ct.pinterest.com^ | |
| 167 | + ||sc-static.net^ | |
| 168 | + ||tr.snapchat.com^ | |
| 169 | + ||adsappier.com^ | |
| 170 | + ||omnitagjs.com^ | |
| 171 | + ||cdn.permutive.com^ | |
| 172 | + ||permutive.app^ | |
| 173 | + ||cxense.com^ | |
| 174 | + ||piano.io^ | |
| 175 | + ||tinypass.com^ | |
| 176 | + ||onesignal.com^ | |
| 177 | + ||pushcrew.com^ | |
| 178 | + ||pushwoosh.com^ | |
| 179 | + ||cookielaw.org^ | |
| 180 | + ||onetrust.com^ | |
| 181 | + ||trustarc.com^ | |
| 182 | + ||quantcast.com^ | |
| 183 | + ||consensu.org^ | |
| 184 | + ||usercentrics.eu^ | |
| 185 | + ||cookiebot.com^ | |
| 186 | + ! Paths that are ads on any site | |
| 187 | + /adserver/ | |
| 188 | + /adsbygoogle | |
| 189 | + /pagead/ | |
| 190 | + /ad-banner | |
| 191 | + /advertisement/ | |
| 192 | + /ads/banner | |
| 193 | + /prebid | |
| 194 | + /doubleclick/ | |
| 195 | + /googleads/ |
crates/clearwake-core/src/history.rs added
| 1 | + //! Back and forward. | |
| 2 | + | |
| 3 | + use alloc::string::String; | |
| 4 | + use alloc::vec::Vec; | |
| 5 | + | |
| 6 | + #[derive(Default, Clone, Debug)] | |
| 7 | + pub struct History { | |
| 8 | + back: Vec<String>, | |
| 9 | + current: Option<String>, | |
| 10 | + forward: Vec<String>, | |
| 11 | + } | |
| 12 | + | |
| 13 | + impl History { | |
| 14 | + /// A new page was opened by the person (not back or forward). | |
| 15 | + pub fn visit(&mut self, url: String) { | |
| 16 | + if self.current.as_deref() == Some(url.as_str()) { | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + if let Some(c) = self.current.take() { | |
| 20 | + self.back.push(c); | |
| 21 | + if self.back.len() > 500 { | |
| 22 | + self.back.remove(0); | |
| 23 | + } | |
| 24 | + } | |
| 25 | + self.current = Some(url); | |
| 26 | + self.forward.clear(); | |
| 27 | + } | |
| 28 | + | |
| 29 | + /// After a redirect, the page that opened has a different address. | |
| 30 | + pub fn replace(&mut self, url: String) { | |
| 31 | + self.current = Some(url); | |
| 32 | + } | |
| 33 | + | |
| 34 | + pub fn current(&self) -> Option<&str> { | |
| 35 | + self.current.as_deref() | |
| 36 | + } | |
| 37 | + pub fn can_back(&self) -> bool { | |
| 38 | + !self.back.is_empty() | |
| 39 | + } | |
| 40 | + pub fn can_forward(&self) -> bool { | |
| 41 | + !self.forward.is_empty() | |
| 42 | + } | |
| 43 | + | |
| 44 | + pub fn back(&mut self) -> Option<String> { | |
| 45 | + let prev = self.back.pop()?; | |
| 46 | + if let Some(c) = self.current.replace(prev.clone()) { | |
| 47 | + self.forward.push(c); | |
| 48 | + } | |
| 49 | + Some(prev) | |
| 50 | + } | |
| 51 | + | |
| 52 | + pub fn forward(&mut self) -> Option<String> { | |
| 53 | + let next = self.forward.pop()?; | |
| 54 | + if let Some(c) = self.current.replace(next.clone()) { | |
| 55 | + self.back.push(c); | |
| 56 | + } | |
| 57 | + Some(next) | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + #[cfg(test)] | |
| 62 | + mod tests { | |
| 63 | + use super::*; | |
| 64 | + #[test] | |
| 65 | + fn back_and_forward() { | |
| 66 | + let mut h = History::default(); | |
| 67 | + h.visit("a".into()); | |
| 68 | + h.visit("b".into()); | |
| 69 | + h.visit("c".into()); | |
| 70 | + assert_eq!(h.back().as_deref(), Some("b")); | |
| 71 | + assert_eq!(h.back().as_deref(), Some("a")); | |
| 72 | + assert!(h.back().is_none()); | |
| 73 | + assert_eq!(h.forward().as_deref(), Some("b")); | |
| 74 | + h.visit("d".into()); | |
| 75 | + assert!(!h.can_forward()); | |
| 76 | + assert_eq!(h.current(), Some("d")); | |
| 77 | + } | |
| 78 | + } |
crates/clearwake-core/src/html.rs added
| 1 | + //! The page reader. Turns HTML into a calm list of blocks: headings, | |
| 2 | + //! paragraphs, lists, quotes, code, pictures and simple search forms. | |
| 3 | + //! | |
| 4 | + //! Scripts never run and are never fetched. Styles are not applied. Hidden | |
| 5 | + //! elements and anything labelled as an ad are left out. When a page marks | |
| 6 | + //! its main content (`<main>` or `<article>`), site menus, side bars and | |
| 7 | + //! footers are left out too. | |
| 8 | + | |
| 9 | + use crate::filter::Filter; | |
| 10 | + use crate::url::Url; | |
| 11 | + use alloc::string::{String, ToString}; | |
| 12 | + use alloc::vec::Vec; | |
| 13 | + | |
| 14 | + #[derive(Clone, Debug, PartialEq, Eq, Default)] | |
| 15 | + pub struct Inline { | |
| 16 | + pub text: String, | |
| 17 | + /// Absolute address when this run is a link. | |
| 18 | + pub link: Option<String>, | |
| 19 | + pub bold: bool, | |
| 20 | + pub italic: bool, | |
| 21 | + pub code: bool, | |
| 22 | + } | |
| 23 | + | |
| 24 | + #[derive(Clone, Debug, PartialEq, Eq)] | |
| 25 | + pub struct Form { | |
| 26 | + /// Absolute address the search goes to. | |
| 27 | + pub action: String, | |
| 28 | + pub hidden: Vec<(String, String)>, | |
| 29 | + pub field: String, | |
| 30 | + pub placeholder: String, | |
| 31 | + pub value: String, | |
| 32 | + pub submit: String, | |
| 33 | + } | |
| 34 | + | |
| 35 | + impl Form { | |
| 36 | + /// The address to open when the person submits `text`. | |
| 37 | + pub fn target(&self, text: &str) -> String { | |
| 38 | + let mut s = self.action.clone(); | |
| 39 | + s.push(if s.contains('?') { '&' } else { '?' }); | |
| 40 | + let mut first = true; | |
| 41 | + for (k, v) in self.hidden.iter().chain(core::iter::once(&(self.field.clone(), String::from(text)))) { | |
| 42 | + if !first { | |
| 43 | + s.push('&'); | |
| 44 | + } | |
| 45 | + first = false; | |
| 46 | + s.push_str(&crate::url::encode_component(k)); | |
| 47 | + s.push('='); | |
| 48 | + s.push_str(&crate::url::encode_component(v)); | |
| 49 | + } | |
| 50 | + s | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + #[derive(Clone, Debug, PartialEq, Eq)] | |
| 55 | + pub enum Block { | |
| 56 | + Heading { level: u8, spans: Vec<Inline> }, | |
| 57 | + Paragraph { spans: Vec<Inline>, quote: bool }, | |
| 58 | + ListItem { depth: u8, marker: String, spans: Vec<Inline> }, | |
| 59 | + Code(String), | |
| 60 | + Image { src: String, alt: String, width: Option<u32>, height: Option<u32>, link: Option<String> }, | |
| 61 | + Rule, | |
| 62 | + Form(Form), | |
| 63 | + } | |
| 64 | + | |
| 65 | + #[derive(Clone, Debug, Default)] | |
| 66 | + pub struct Stats { | |
| 67 | + /// Scripts that the page asked for and Clearwake never loaded. | |
| 68 | + pub scripts_skipped: u32, | |
| 69 | + /// Pictures and frames from ad or tracker addresses. | |
| 70 | + pub blocked: u32, | |
| 71 | + /// Elements labelled as ads or hidden. | |
| 72 | + pub hidden: u32, | |
| 73 | + } | |
| 74 | + | |
| 75 | + #[derive(Clone, Debug)] | |
| 76 | + pub struct Document { | |
| 77 | + pub url: Url, | |
| 78 | + pub title: String, | |
| 79 | + pub blocks: Vec<Block>, | |
| 80 | + pub stats: Stats, | |
| 81 | + } | |
| 82 | + | |
| 83 | + impl Document { | |
| 84 | + /// All picture addresses on the page, in order, without repeats. | |
| 85 | + pub fn image_urls(&self) -> Vec<String> { | |
| 86 | + let mut v: Vec<String> = Vec::new(); | |
| 87 | + for b in &self.blocks { | |
| 88 | + if let Block::Image { src, .. } = b { | |
| 89 | + if !v.contains(src) { | |
| 90 | + v.push(src.clone()); | |
| 91 | + } | |
| 92 | + } | |
| 93 | + } | |
| 94 | + v | |
| 95 | + } | |
| 96 | + | |
| 97 | + /// The page as plain text, one block per paragraph. | |
| 98 | + pub fn plain_text(&self) -> String { | |
| 99 | + let mut s = String::new(); | |
| 100 | + for b in &self.blocks { | |
| 101 | + match b { | |
| 102 | + Block::Heading { spans, .. } | Block::Paragraph { spans, .. } | Block::ListItem { spans, .. } => { | |
| 103 | + for sp in spans { | |
| 104 | + s.push_str(&sp.text); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + Block::Code(c) => s.push_str(c), | |
| 108 | + Block::Image { alt, .. } => s.push_str(alt), | |
| 109 | + Block::Rule => s.push_str("---"), | |
| 110 | + Block::Form(f) => s.push_str(&f.submit), | |
| 111 | + } | |
| 112 | + s.push('\n'); | |
| 113 | + } | |
| 114 | + s | |
| 115 | + } | |
| 116 | + } | |
| 117 | + | |
| 118 | + const MAX_BLOCKS: usize = 20_000; | |
| 119 | + | |
| 120 | + const VOID: &[&str] = &[ | |
| 121 | + "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr", "keygen", | |
| 122 | + ]; | |
| 123 | + | |
| 124 | + /// Elements that never show: their whole contents are dropped. | |
| 125 | + const DROP: &[&str] = &[ | |
| 126 | + "head", "script", "style", "template", "svg", "math", "iframe", "object", "canvas", "video", "audio", "select", "button", | |
| 127 | + "dialog", "map", "frameset", "textarea", "datalist", "portal", | |
| 128 | + ]; | |
| 129 | + | |
| 130 | + /// Dropped only when the page marks its main content. | |
| 131 | + const CHROME: &[&str] = &["nav", "footer", "aside", "header"]; | |
| 132 | + | |
| 133 | + const BLOCKS: &[&str] = &[ | |
| 134 | + "address", "article", "aside", "blockquote", "body", "center", "dd", "details", "dialog", "dir", "div", "dl", "dt", | |
| 135 | + "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", | |
| 136 | + "html", "li", "main", "menu", "nav", "ol", "p", "pre", "section", "summary", "table", "tbody", "td", "tfoot", "th", | |
| 137 | + "thead", "tr", "ul", "caption", "legend", "label", | |
| 138 | + ]; | |
| 139 | + | |
| 140 | + const AD_WORDS: &[&str] = &[ | |
| 141 | + "ad", "ads", "advert", "adverts", "advertisement", "advertising", "adsbygoogle", "ad-slot", "ad-container", "ad-wrapper", | |
| 142 | + "ad-banner", "ad-unit", "adunit", "ad_unit", "dfp-ad", "google-ad", "sponsored", "sponsored-content", "promoted", | |
| 143 | + "taboola", "outbrain", "cookie-banner", "cookie-consent", "newsletter-popup", "paywall-overlay", | |
| 144 | + ]; | |
| 145 | + | |
| 146 | + struct Tag { | |
| 147 | + name: String, | |
| 148 | + attrs: Vec<(String, String)>, | |
| 149 | + end: bool, | |
| 150 | + self_closing: bool, | |
| 151 | + } | |
| 152 | + | |
| 153 | + impl Tag { | |
| 154 | + fn attr(&self, n: &str) -> Option<&str> { | |
| 155 | + self.attrs.iter().find(|(k, _)| k == n).map(|(_, v)| v.as_str()) | |
| 156 | + } | |
| 157 | + } | |
| 158 | + | |
| 159 | + struct Open { | |
| 160 | + name: String, | |
| 161 | + link: Option<String>, | |
| 162 | + } | |
| 163 | + | |
| 164 | + struct Builder<'f> { | |
| 165 | + base: Url, | |
| 166 | + filter: &'f Filter, | |
| 167 | + drop_chrome: bool, | |
| 168 | + blocks: Vec<Block>, | |
| 169 | + spans: Vec<Inline>, | |
| 170 | + stack: Vec<Open>, | |
| 171 | + /// Depth of the stack at which a dropped element began. | |
| 172 | + skip_at: Option<usize>, | |
| 173 | + heading: u8, | |
| 174 | + list: Vec<(bool, u32)>, | |
| 175 | + item: Option<(u8, String)>, | |
| 176 | + quote: u32, | |
| 177 | + pre: Option<String>, | |
| 178 | + form: Option<Form>, | |
| 179 | + title: String, | |
| 180 | + stats: Stats, | |
| 181 | + } | |
| 182 | + | |
| 183 | + /// Read a page. `url` is the address it came from (used to resolve links). | |
| 184 | + pub fn parse(source: &str, url: &Url, filter: &Filter) -> Document { | |
| 185 | + let lower_has = |needle: &str| find_ci(source, needle).is_some(); | |
| 186 | + let drop_chrome = lower_has("<main") || lower_has("<article"); | |
| 187 | + let mut b = Builder { | |
| 188 | + base: url.clone(), | |
| 189 | + filter, | |
| 190 | + drop_chrome, | |
| 191 | + blocks: Vec::new(), | |
| 192 | + spans: Vec::new(), | |
| 193 | + stack: Vec::new(), | |
| 194 | + skip_at: None, | |
| 195 | + heading: 0, | |
| 196 | + list: Vec::new(), | |
| 197 | + item: None, | |
| 198 | + quote: 0, | |
| 199 | + pre: None, | |
| 200 | + form: None, | |
| 201 | + title: String::new(), | |
| 202 | + stats: Stats::default(), | |
| 203 | + }; | |
| 204 | + tokenize(source, &mut b); | |
| 205 | + b.flush(); | |
| 206 | + let title = collapse(&b.title).trim().to_string(); | |
| 207 | + Document { url: url.clone(), title, blocks: b.blocks, stats: b.stats } | |
| 208 | + } | |
| 209 | + | |
| 210 | + fn tokenize(src: &str, b: &mut Builder) { | |
| 211 | + let bytes = src.as_bytes(); | |
| 212 | + let mut i = 0; | |
| 213 | + let mut text_start = 0; | |
| 214 | + while i < bytes.len() { | |
| 215 | + if bytes[i] != b'<' { | |
| 216 | + i += 1; | |
| 217 | + continue; | |
| 218 | + } | |
| 219 | + let rest = &src[i..]; | |
| 220 | + if rest.starts_with("<!--") { | |
| 221 | + b.text(&src[text_start..i]); | |
| 222 | + let end = rest.find("-->").map(|e| i + e + 3).unwrap_or(src.len()); | |
| 223 | + i = end; | |
| 224 | + text_start = i; | |
| 225 | + continue; | |
| 226 | + } | |
| 227 | + if rest.starts_with("<!") || rest.starts_with("<?") { | |
| 228 | + b.text(&src[text_start..i]); | |
| 229 | + let end = rest.find('>').map(|e| i + e + 1).unwrap_or(src.len()); | |
| 230 | + i = end; | |
| 231 | + text_start = i; | |
| 232 | + continue; | |
| 233 | + } | |
| 234 | + let next = bytes.get(i + 1).copied().unwrap_or(0); | |
| 235 | + let is_tag = next.is_ascii_alphabetic() || (next == b'/' && bytes.get(i + 2).is_some_and(|c| c.is_ascii_alphabetic())); | |
| 236 | + if !is_tag { | |
| 237 | + i += 1; | |
| 238 | + continue; | |
| 239 | + } | |
| 240 | + b.text(&src[text_start..i]); | |
| 241 | + let (tag, end) = read_tag(src, i); | |
| 242 | + i = end; | |
| 243 | + text_start = i; | |
| 244 | + // Raw text elements: skip straight to their end tag. | |
| 245 | + if !tag.end && !tag.self_closing && (tag.name == "script" || tag.name == "style" || tag.name == "textarea" || tag.name == "title" || tag.name == "xmp" || tag.name == "plaintext") { | |
| 246 | + let close = { | |
| 247 | + let mut c = String::from("</"); | |
| 248 | + c.push_str(&tag.name); | |
| 249 | + c | |
| 250 | + }; | |
| 251 | + let body_end = find_ci(&src[i..], &close).map(|e| i + e).unwrap_or(src.len()); | |
| 252 | + let body = &src[i..body_end]; | |
| 253 | + match tag.name.as_str() { | |
| 254 | + "title" => { | |
| 255 | + if b.title.is_empty() && !b.has_open(&["svg"]) { | |
| 256 | + b.title = decode_entities(body); | |
| 257 | + } | |
| 258 | + } | |
| 259 | + "script" => b.stats.scripts_skipped += 1, | |
| 260 | + _ => {} | |
| 261 | + } | |
| 262 | + i = src[body_end..].find('>').map(|e| body_end + e + 1).unwrap_or(src.len()); | |
| 263 | + text_start = i; | |
| 264 | + continue; | |
| 265 | + } | |
| 266 | + b.tag(tag); | |
| 267 | + if b.blocks.len() > MAX_BLOCKS { | |
| 268 | + return; | |
| 269 | + } | |
| 270 | + } | |
| 271 | + b.text(&src[text_start..]); | |
| 272 | + } | |
| 273 | + | |
| 274 | + fn read_tag(src: &str, start: usize) -> (Tag, usize) { | |
| 275 | + let bytes = src.as_bytes(); | |
| 276 | + let mut i = start + 1; | |
| 277 | + let end = bytes.get(i) == Some(&b'/'); | |
| 278 | + if end { | |
| 279 | + i += 1; | |
| 280 | + } | |
| 281 | + let ns = i; | |
| 282 | + while i < bytes.len() && !bytes[i].is_ascii_whitespace() && bytes[i] != b'>' && bytes[i] != b'/' { | |
| 283 | + i += 1; | |
| 284 | + } | |
| 285 | + let name = src[ns..i].to_ascii_lowercase(); | |
| 286 | + let mut attrs = Vec::new(); | |
| 287 | + let mut self_closing = false; | |
| 288 | + loop { | |
| 289 | + while i < bytes.len() && (bytes[i].is_ascii_whitespace() || (bytes[i] == b'/' && bytes.get(i + 1) != Some(&b'>'))) { | |
| 290 | + i += 1; | |
| 291 | + } | |
| 292 | + if i >= bytes.len() { | |
| 293 | + break; | |
| 294 | + } | |
| 295 | + if bytes[i] == b'>' { | |
| 296 | + i += 1; | |
| 297 | + break; | |
| 298 | + } | |
| 299 | + if bytes[i] == b'/' { | |
| 300 | + self_closing = true; | |
| 301 | + i += 1; | |
| 302 | + continue; | |
| 303 | + } | |
| 304 | + let ks = i; | |
| 305 | + while i < bytes.len() && !bytes[i].is_ascii_whitespace() && bytes[i] != b'=' && bytes[i] != b'>' && !(bytes[i] == b'/' && bytes.get(i + 1) == Some(&b'>')) { | |
| 306 | + i += 1; | |
| 307 | + } | |
| 308 | + let key = src[ks..i].to_ascii_lowercase(); | |
| 309 | + while i < bytes.len() && bytes[i].is_ascii_whitespace() { | |
| 310 | + i += 1; | |
| 311 | + } | |
| 312 | + let mut val = String::new(); | |
| 313 | + if bytes.get(i) == Some(&b'=') { | |
| 314 | + i += 1; | |
| 315 | + while i < bytes.len() && bytes[i].is_ascii_whitespace() { | |
| 316 | + i += 1; | |
| 317 | + } | |
| 318 | + match bytes.get(i) { | |
| 319 | + Some(&q) if q == b'"' || q == b'\'' => { | |
| 320 | + let vs = i + 1; | |
| 321 | + let ve = src[vs..].find(q as char).map(|e| vs + e).unwrap_or(src.len()); | |
| 322 | + val = decode_entities(&src[vs..ve]); | |
| 323 | + i = (ve + 1).min(src.len()); | |
| 324 | + } | |
| 325 | + _ => { | |
| 326 | + let vs = i; | |
| 327 | + while i < bytes.len() && !bytes[i].is_ascii_whitespace() && bytes[i] != b'>' { | |
| 328 | + i += 1; | |
| 329 | + } | |
| 330 | + val = decode_entities(&src[vs..i]); | |
| 331 | + } | |
| 332 | + } | |
| 333 | + } | |
| 334 | + if !key.is_empty() && attrs.len() < 64 { | |
| 335 | + attrs.push((key, val)); | |
| 336 | + } | |
| 337 | + } | |
| 338 | + (Tag { name, attrs, end, self_closing }, i) | |
| 339 | + } | |
| 340 | + | |
| 341 | + impl<'f> Builder<'f> { | |
| 342 | + fn skipping(&self) -> bool { | |
| 343 | + self.skip_at.is_some() | |
| 344 | + } | |
| 345 | + | |
| 346 | + fn current_link(&self) -> Option<String> { | |
| 347 | + self.stack.iter().rev().find_map(|o| o.link.clone()) | |
| 348 | + } | |
| 349 | + | |
| 350 | + fn has_open(&self, names: &[&str]) -> bool { | |
| 351 | + self.stack.iter().any(|o| names.contains(&o.name.as_str())) | |
| 352 | + } | |
| 353 | + | |
| 354 | + fn text(&mut self, raw: &str) { | |
| 355 | + if raw.is_empty() || self.skipping() { | |
| 356 | + return; | |
| 357 | + } | |
| 358 | + if let Some(pre) = &mut self.pre { | |
| 359 | + pre.push_str(&decode_entities(raw)); | |
| 360 | + return; | |
| 361 | + } | |
| 362 | + let t = collapse(&decode_entities(raw)); | |
| 363 | + if t.is_empty() || (t == " " && self.spans.is_empty()) { | |
| 364 | + return; | |
| 365 | + } | |
| 366 | + let link = self.current_link(); | |
| 367 | + let bold = self.heading == 0 && self.has_open(&["b", "strong"]); | |
| 368 | + let italic = self.has_open(&["i", "em", "cite", "var"]); | |
| 369 | + let code = self.has_open(&["code", "kbd", "samp", "tt"]); | |
| 370 | + let mut t = t; | |
| 371 | + if self.spans.last().is_some_and(|s| s.text.ends_with(' ') || s.text.ends_with('\n')) && t.starts_with(' ') { | |
| 372 | + t.remove(0); | |
| 373 | + if t.is_empty() { | |
| 374 | + return; | |
| 375 | + } | |
| 376 | + } | |
| 377 | + if let Some(last) = self.spans.last_mut() { | |
| 378 | + if last.link == link && last.bold == bold && last.italic == italic && last.code == code { | |
| 379 | + last.text.push_str(&t); | |
| 380 | + return; | |
| 381 | + } | |
| 382 | + } | |
| 383 | + self.spans.push(Inline { text: t, link, bold, italic, code }); | |
| 384 | + } | |
| 385 | + | |
| 386 | + fn flush(&mut self) { | |
| 387 | + let mut spans = core::mem::take(&mut self.spans); | |
| 388 | + // Trim the ends. | |
| 389 | + while spans.first().is_some_and(|s| s.text.trim().is_empty()) { | |
| 390 | + spans.remove(0); | |
| 391 | + } | |
| 392 | + while spans.last().is_some_and(|s| s.text.trim().is_empty()) { | |
| 393 | + spans.pop(); | |
| 394 | + } | |
| 395 | + if let Some(f) = spans.first_mut() { | |
| 396 | + f.text = f.text.trim_start().to_string(); | |
| 397 | + } | |
| 398 | + if let Some(l) = spans.last_mut() { | |
| 399 | + l.text = l.text.trim_end().to_string(); | |
| 400 | + } | |
| 401 | + if spans.is_empty() { | |
| 402 | + return; | |
| 403 | + } | |
| 404 | + let block = if self.heading > 0 { | |
| 405 | + Block::Heading { level: self.heading, spans } | |
| 406 | + } else if let Some((depth, marker)) = self.item.take() { | |
| 407 | + Block::ListItem { depth, marker, spans } | |
| 408 | + } else { | |
| 409 | + Block::Paragraph { spans, quote: self.quote > 0 } | |
| 410 | + }; | |
| 411 | + self.blocks.push(block); | |
| 412 | + } | |
| 413 | + | |
| 414 | + fn is_hidden(&self, t: &Tag) -> bool { | |
| 415 | + if t.attr("hidden").is_some() || t.attr("aria-hidden") == Some("true") { | |
| 416 | + return true; | |
| 417 | + } | |
| 418 | + if let Some(st) = t.attr("style") { | |
| 419 | + let s: String = st.chars().filter(|c| !c.is_whitespace()).collect::<String>().to_ascii_lowercase(); | |
| 420 | + if s.contains("display:none") || s.contains("visibility:hidden") { | |
| 421 | + return true; | |
| 422 | + } | |
| 423 | + } | |
| 424 | + for key in ["class", "id"] { | |
| 425 | + if let Some(v) = t.attr(key) { | |
| 426 | + for word in v.split_ascii_whitespace() { | |
| 427 | + let w = word.to_ascii_lowercase(); | |
| 428 | + if AD_WORDS.contains(&w.as_str()) || w.starts_with("ad-slot") || w.starts_with("google_ads") || w.starts_with("div-gpt-ad") { | |
| 429 | + return true; | |
| 430 | + } | |
| 431 | + } | |
| 432 | + } | |
| 433 | + } | |
| 434 | + false | |
| 435 | + } | |
| 436 | + | |
| 437 | + fn resolve(&self, href: &str) -> Option<Url> { | |
| 438 | + self.base.join(href) | |
| 439 | + } | |
| 440 | + | |
| 441 | + fn tag(&mut self, t: Tag) { | |
| 442 | + let name = t.name.as_str(); | |
| 443 | + if t.end { | |
| 444 | + self.end_tag(name); | |
| 445 | + return; | |
| 446 | + } | |
| 447 | + let void = VOID.contains(&name); | |
| 448 | + | |
| 449 | + if self.skipping() { | |
| 450 | + if !void && !t.self_closing { | |
| 451 | + self.stack.push(Open { name: t.name.clone(), link: None }); | |
| 452 | + } | |
| 453 | + return; | |
| 454 | + } | |
| 455 | + | |
| 456 | + if name == "base" { | |
| 457 | + if let Some(u) = t.attr("href").and_then(|h| self.base.join(h)) { | |
| 458 | + self.base = u; | |
| 459 | + } | |
| 460 | + return; | |
| 461 | + } | |
| 462 | + | |
| 463 | + let dropped = DROP.contains(&name) || (self.drop_chrome && CHROME.contains(&name)) || self.is_hidden(&t); | |
| 464 | + if dropped { | |
| 465 | + if name == "iframe" { | |
| 466 | + if let Some(u) = t.attr("src").and_then(|s| self.resolve(s)) { | |
| 467 | + if self.filter.blocks(&u) { | |
| 468 | + self.stats.blocked += 1; | |
| 469 | + } | |
| 470 | + } | |
| 471 | + } else if !DROP.contains(&name) && !CHROME.contains(&name) { | |
| 472 | + self.stats.hidden += 1; | |
| 473 | + } | |
| 474 | + if !void && !t.self_closing { | |
| 475 | + self.skip_at = Some(self.stack.len()); | |
| 476 | + self.stack.push(Open { name: t.name.clone(), link: None }); | |
| 477 | + } | |
| 478 | + return; | |
| 479 | + } | |
| 480 | + | |
| 481 | + if BLOCKS.contains(&name) { | |
| 482 | + self.flush(); | |
| 483 | + } | |
| 484 | + | |
| 485 | + match name { | |
| 486 | + "br" => { | |
| 487 | + if let Some(p) = &mut self.pre { | |
| 488 | + p.push('\n'); | |
| 489 | + } else if !self.spans.is_empty() { | |
| 490 | + let link = self.current_link(); | |
| 491 | + self.spans.push(Inline { text: String::from("\n"), link, ..Default::default() }); | |
| 492 | + } | |
| 493 | + } | |
| 494 | + "hr" => { | |
| 495 | + self.blocks.push(Block::Rule); | |
| 496 | + } | |
| 497 | + "h1" | "h2" | "h3" | "h4" | "h5" | "h6" => { | |
| 498 | + self.heading = name.as_bytes()[1] - b'0'; | |
| 499 | + } | |
| 500 | + "blockquote" => self.quote += 1, | |
| 501 | + "pre" => { | |
| 502 | + self.pre = Some(String::new()); | |
| 503 | + } | |
| 504 | + "ul" | "menu" | "dir" => self.list.push((false, 0)), | |
| 505 | + "ol" => { | |
| 506 | + let start = t.attr("start").and_then(|s| s.trim().parse::<u32>().ok()).unwrap_or(1); | |
| 507 | + self.list.push((true, start.saturating_sub(1))); | |
| 508 | + } | |
| 509 | + "li" => { | |
| 510 | + let depth = self.list.len().max(1) as u8; | |
| 511 | + let marker = match self.list.last_mut() { | |
| 512 | + Some((true, n)) => { | |
| 513 | + *n += 1; | |
| 514 | + let mut m = n.to_string(); | |
| 515 | + m.push('.'); | |
| 516 | + m | |
| 517 | + } | |
| 518 | + _ => String::from("•"), | |
| 519 | + }; | |
| 520 | + self.item = Some((depth, marker)); | |
| 521 | + } | |
| 522 | + "img" => self.image(&t), | |
| 523 | + "form" => { | |
| 524 | + let method = t.attr("method").unwrap_or("get").to_ascii_lowercase(); | |
| 525 | + let action = t.attr("action").unwrap_or(""); | |
| 526 | + let target = if action.trim().is_empty() { Some(self.base.clone()) } else { self.resolve(action) }; | |
| 527 | + self.form = match (method.as_str(), target) { | |
| 528 | + ("get", Some(u)) => { | |
| 529 | + let mut a = u.clone(); | |
| 530 | + a.query = None; | |
| 531 | + let mut hidden = Vec::new(); | |
| 532 | + if let Some(q) = &u.query { | |
| 533 | + for pair in q.split('&') { | |
| 534 | + let mut kv = pair.splitn(2, '='); | |
| 535 | + let k = crate::url::decode_component(kv.next().unwrap_or("")); | |
| 536 | + let v = crate::url::decode_component(kv.next().unwrap_or("")); | |
| 537 | + if !k.is_empty() { | |
| 538 | + hidden.push((k, v)); | |
| 539 | + } | |
| 540 | + } | |
| 541 | + } | |
| 542 | + Some(Form { action: a.to_string(), hidden, field: String::new(), placeholder: String::new(), value: String::new(), submit: String::new() }) | |
| 543 | + } | |
| 544 | + _ => None, | |
| 545 | + }; | |
| 546 | + } | |
| 547 | + "input" => { | |
| 548 | + if let Some(f) = &mut self.form { | |
| 549 | + let ty = t.attr("type").unwrap_or("text").to_ascii_lowercase(); | |
| 550 | + let n = t.attr("name").unwrap_or("").to_string(); | |
| 551 | + let v = t.attr("value").unwrap_or("").to_string(); | |
| 552 | + match ty.as_str() { | |
| 553 | + "hidden" if !n.is_empty() => f.hidden.push((n, v)), | |
| 554 | + "text" | "search" | "" if !n.is_empty() && f.field.is_empty() => { | |
| 555 | + f.field = n; | |
| 556 | + f.value = v; | |
| 557 | + f.placeholder = t.attr("placeholder").or(t.attr("aria-label")).unwrap_or("").to_string(); | |
| 558 | + } | |
| 559 | + "submit" if f.submit.is_empty() => f.submit = v, | |
| 560 | + _ => {} | |
| 561 | + } | |
| 562 | + } | |
| 563 | + } | |
| 564 | + _ => {} | |
| 565 | + } | |
| 566 | + | |
| 567 | + if !void && !t.self_closing { | |
| 568 | + let link = if name == "a" { | |
| 569 | + t.attr("href").and_then(|h| self.resolve(h)).map(|u| u.to_string()) | |
| 570 | + } else { | |
| 571 | + None | |
| 572 | + }; | |
| 573 | + self.stack.push(Open { name: t.name.clone(), link }); | |
| 574 | + } | |
| 575 | + } | |
| 576 | + | |
| 577 | + fn image(&mut self, t: &Tag) { | |
| 578 | + let mut src = t.attr("src").unwrap_or("").trim().to_string(); | |
| 579 | + if src.is_empty() || src.starts_with("data:") { | |
| 580 | + for k in ["data-src", "data-lazy-src", "data-original"] { | |
| 581 | + if let Some(v) = t.attr(k) { | |
| 582 | + if !v.trim().is_empty() { | |
| 583 | + src = v.trim().to_string(); | |
| 584 | + break; | |
| 585 | + } | |
| 586 | + } | |
| 587 | + } | |
| 588 | + } | |
| 589 | + if src.is_empty() || src.starts_with("data:") { | |
| 590 | + if let Some(set) = t.attr("srcset").or(t.attr("data-srcset")) { | |
| 591 | + if let Some(first) = set.split(',').next() { | |
| 592 | + src = first.split_ascii_whitespace().next().unwrap_or("").to_string(); | |
| 593 | + } | |
| 594 | + } | |
| 595 | + } | |
| 596 | + let dim = |k: &str| t.attr(k).and_then(|v| v.trim().trim_end_matches("px").parse::<u32>().ok()); | |
| 597 | + let (w, h) = (dim("width"), dim("height")); | |
| 598 | + if w.is_some_and(|w| w <= 2) || h.is_some_and(|h| h <= 2) { | |
| 599 | + // Tracking pixel. | |
| 600 | + self.stats.blocked += 1; | |
| 601 | + return; | |
| 602 | + } | |
| 603 | + let Some(u) = self.resolve(&src) else { return }; | |
| 604 | + if u.scheme != "http" && u.scheme != "https" { | |
| 605 | + return; | |
| 606 | + } | |
| 607 | + if self.filter.blocks(&u) { | |
| 608 | + self.stats.blocked += 1; | |
| 609 | + return; | |
| 610 | + } | |
| 611 | + let alt = collapse(t.attr("alt").unwrap_or("")).trim().to_string(); | |
| 612 | + let link = self.current_link(); | |
| 613 | + self.flush(); | |
| 614 | + self.blocks.push(Block::Image { src: u.to_string(), alt, width: w, height: h, link }); | |
| 615 | + } | |
| 616 | + | |
| 617 | + fn end_tag(&mut self, name: &str) { | |
| 618 | + let Some(pos) = self.stack.iter().rposition(|o| o.name == name) else { | |
| 619 | + return; | |
| 620 | + }; | |
| 621 | + if let Some(at) = self.skip_at { | |
| 622 | + if pos < at { | |
| 623 | + // A stray end tag for something outside the dropped element. | |
| 624 | + return; | |
| 625 | + } | |
| 626 | + self.stack.truncate(pos); | |
| 627 | + if pos == at { | |
| 628 | + self.skip_at = None; | |
| 629 | + } | |
| 630 | + return; | |
| 631 | + } | |
| 632 | + // Close everything opened inside this element too. | |
| 633 | + let closing: Vec<String> = self.stack[pos..].iter().map(|o| o.name.clone()).collect(); | |
| 634 | + for n in closing.iter().rev() { | |
| 635 | + self.close(n); | |
| 636 | + } | |
| 637 | + self.stack.truncate(pos); | |
| 638 | + } | |
| 639 | + | |
| 640 | + fn close(&mut self, name: &str) { | |
| 641 | + if BLOCKS.contains(&name) && name != "pre" { | |
| 642 | + self.flush(); | |
| 643 | + } | |
| 644 | + match name { | |
| 645 | + "h1" | "h2" | "h3" | "h4" | "h5" | "h6" => self.heading = 0, | |
| 646 | + "blockquote" => self.quote = self.quote.saturating_sub(1), | |
| 647 | + "pre" => { | |
| 648 | + if let Some(p) = self.pre.take() { | |
| 649 | + let p = p.trim_matches('\n').to_string(); | |
| 650 | + if !p.trim().is_empty() { | |
| 651 | + self.blocks.push(Block::Code(p)); | |
| 652 | + } | |
| 653 | + } | |
| 654 | + } | |
| 655 | + "ul" | "ol" | "menu" | "dir" => { | |
| 656 | + self.list.pop(); | |
| 657 | + self.item = None; | |
| 658 | + } | |
| 659 | + "li" => self.item = None, | |
| 660 | + "form" => { | |
| 661 | + if let Some(f) = self.form.take() { | |
| 662 | + if !f.field.is_empty() { | |
| 663 | + self.blocks.push(Block::Form(f)); | |
| 664 | + } | |
| 665 | + } | |
| 666 | + } | |
| 667 | + _ => {} | |
| 668 | + } | |
| 669 | + } | |
| 670 | + } | |
| 671 | + | |
| 672 | + /// Collapse every run of whitespace into one space. | |
| 673 | + fn collapse(s: &str) -> String { | |
| 674 | + let mut out = String::with_capacity(s.len()); | |
| 675 | + let mut space = false; | |
| 676 | + for c in s.chars() { | |
| 677 | + if c.is_whitespace() && c != '\u{a0}' { | |
| 678 | + if !space { | |
| 679 | + out.push(' '); | |
| 680 | + space = true; | |
| 681 | + } | |
| 682 | + } else { | |
| 683 | + out.push(if c == '\u{a0}' { ' ' } else { c }); | |
| 684 | + space = false; | |
| 685 | + } | |
| 686 | + } | |
| 687 | + out | |
| 688 | + } | |
| 689 | + | |
| 690 | + /// Case-insensitive search for an ASCII needle. | |
| 691 | + fn find_ci(hay: &str, needle: &str) -> Option<usize> { | |
| 692 | + let h = hay.as_bytes(); | |
| 693 | + let n = needle.as_bytes(); | |
| 694 | + if n.is_empty() || h.len() < n.len() { | |
| 695 | + return None; | |
| 696 | + } | |
| 697 | + (0..=h.len() - n.len()).find(|&i| h[i..i + n.len()].eq_ignore_ascii_case(n)) | |
| 698 | + } | |
| 699 | + | |
| 700 | + /// Decode character references like `&`, `’` and `—`. | |
| 701 | + pub fn decode_entities(s: &str) -> String { | |
| 702 | + if !s.contains('&') { | |
| 703 | + return s.to_string(); | |
| 704 | + } | |
| 705 | + let mut out = String::with_capacity(s.len()); | |
| 706 | + let mut rest = s; | |
| 707 | + while let Some(i) = rest.find('&') { | |
| 708 | + out.push_str(&rest[..i]); | |
| 709 | + rest = &rest[i..]; | |
| 710 | + let end = rest[1..].find(|c: char| c == ';' || c == '&' || c.is_whitespace() || c == '<').map(|e| e + 1); | |
| 711 | + let (name, consumed) = match end { | |
| 712 | + Some(e) if rest.as_bytes()[e] == b';' && e <= 33 => (&rest[1..e], e + 1), | |
| 713 | + Some(e) if e <= 33 => (&rest[1..e], e), | |
| 714 | + None if rest.len() <= 33 => (&rest[1..], rest.len()), | |
| 715 | + _ => ("", 0), | |
| 716 | + }; | |
| 717 | + let decoded = if let Some(num) = name.strip_prefix('#') { | |
| 718 | + let v = if let Some(hex) = num.strip_prefix(['x', 'X']) { u32::from_str_radix(hex, 16).ok() } else { num.parse::<u32>().ok() }; | |
| 719 | + v.map(|v| char::from_u32(v).unwrap_or('\u{fffd}')) | |
| 720 | + } else { | |
| 721 | + named_entity(name) | |
| 722 | + }; | |
| 723 | + match decoded { | |
| 724 | + Some(c) if consumed > 0 => { | |
| 725 | + out.push(c); | |
| 726 | + rest = &rest[consumed..]; | |
| 727 | + } | |
| 728 | + _ => { | |
| 729 | + out.push('&'); | |
| 730 | + rest = &rest[1..]; | |
| 731 | + } | |
| 732 | + } | |
| 733 | + } | |
| 734 | + out.push_str(rest); | |
| 735 | + out | |
| 736 | + } | |
| 737 | + | |
| 738 | + fn named_entity(n: &str) -> Option<char> { | |
| 739 | + Some(match n { | |
| 740 | + "amp" | "AMP" => '&', | |
| 741 | + "lt" | "LT" => '<', | |
| 742 | + "gt" | "GT" => '>', | |
| 743 | + "quot" | "QUOT" => '"', | |
| 744 | + "apos" => '\'', | |
| 745 | + "nbsp" => '\u{a0}', | |
| 746 | + "ndash" => '–', | |
| 747 | + "mdash" => '—', | |
| 748 | + "hellip" => '…', | |
| 749 | + "lsquo" => '‘', | |
| 750 | + "rsquo" => '’', | |
| 751 | + "ldquo" => '“', | |
| 752 | + "rdquo" => '”', | |
| 753 | + "laquo" => '«', | |
| 754 | + "raquo" => '»', | |
| 755 | + "middot" => '·', | |
| 756 | + "bull" => '•', | |
| 757 | + "copy" => '©', | |
| 758 | + "reg" => '®', | |
| 759 | + "trade" => '™', | |
| 760 | + "deg" => '°', | |
| 761 | + "times" => '×', | |
| 762 | + "divide" => '÷', | |
| 763 | + "plusmn" => '±', | |
| 764 | + "frac12" => '½', | |
| 765 | + "frac14" => '¼', | |
| 766 | + "frac34" => '¾', | |
| 767 | + "eacute" => 'é', | |
| 768 | + "egrave" => 'è', | |
| 769 | + "aacute" => 'á', | |
| 770 | + "agrave" => 'à', | |
| 771 | + "iacute" => 'í', | |
| 772 | + "oacute" => 'ó', | |
| 773 | + "uacute" => 'ú', | |
| 774 | + "ntilde" => 'ñ', | |
| 775 | + "ccedil" => 'ç', | |
| 776 | + "uuml" => 'ü', | |
| 777 | + "ouml" => 'ö', | |
| 778 | + "auml" => 'ä', | |
| 779 | + "szlig" => 'ß', | |
| 780 | + "euro" => '€', | |
| 781 | + "pound" => '£', | |
| 782 | + "yen" => '¥', | |
| 783 | + "cent" => '¢', | |
| 784 | + "sect" => '§', | |
| 785 | + "para" => '¶', | |
| 786 | + "larr" => '←', | |
| 787 | + "rarr" => '→', | |
| 788 | + "uarr" => '↑', | |
| 789 | + "darr" => '↓', | |
| 790 | + "thinsp" | "ensp" | "emsp" => ' ', | |
| 791 | + "zwj" | "zwnj" | "shy" => '\u{200b}', | |
| 792 | + _ => return None, | |
| 793 | + }) | |
| 794 | + } | |
| 795 | + | |
| 796 | + /// Turn downloaded bytes into text, honouring the declared character set | |
| 797 | + /// for the common Western single-byte encodings. Everything else is read as | |
| 798 | + /// UTF-8. | |
| 799 | + pub fn decode_bytes(bytes: &[u8], content_type: &str) -> String { | |
| 800 | + let mut charset = content_type.to_ascii_lowercase(); | |
| 801 | + if !charset.contains("charset=") { | |
| 802 | + let head = &bytes[..bytes.len().min(2048)]; | |
| 803 | + let head = String::from_utf8_lossy(head).to_ascii_lowercase(); | |
| 804 | + if let Some(i) = head.find("charset=") { | |
| 805 | + charset = head[i..].to_string(); | |
| 806 | + } | |
| 807 | + } | |
| 808 | + let latin = ["charset=iso-8859-1", "charset=\"iso-8859-1", "charset=windows-1252", "charset=\"windows-1252", "charset=latin1", "charset=us-ascii"]; | |
| 809 | + if latin.iter().any(|l| charset.contains(l)) { | |
| 810 | + return bytes.iter().map(|&b| cp1252(b)).collect(); | |
| 811 | + } | |
| 812 | + String::from_utf8_lossy(bytes).into_owned() | |
| 813 | + } | |
| 814 | + | |
| 815 | + fn cp1252(b: u8) -> char { | |
| 816 | + const HI: [char; 32] = [ | |
| 817 | + '€', '\u{81}', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '\u{8d}', 'Ž', '\u{8f}', '\u{90}', '‘', '’', '“', | |
| 818 | + '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', '\u{9d}', 'ž', 'Ÿ', | |
| 819 | + ]; | |
| 820 | + if (0x80..0xa0).contains(&b) { HI[(b - 0x80) as usize] } else { b as char } | |
| 821 | + } | |
| 822 | + | |
| 823 | + #[cfg(test)] | |
| 824 | + mod tests { | |
| 825 | + use super::*; | |
| 826 | + | |
| 827 | + fn doc(html: &str) -> Document { | |
| 828 | + parse(html, &Url::parse("https://site.example/a/page.html").unwrap(), &Filter::new()) | |
| 829 | + } | |
| 830 | + | |
| 831 | + #[test] | |
| 832 | + fn basic_page() { | |
| 833 | + let d = doc("<!doctype html><html><head><title>Hi & bye</title><script>alert(1)</script><style>p{}</style></head>\ | |
| 834 | + <body><h1>Head <b>line</b></h1><p>Hello <a href=\"/x\">world</a>, <em>friend</em>.</p><ul><li>one<li>two</ul>\ | |
| 835 | + <ol start=3><li>c</li></ol><pre> a\n b</pre><hr><blockquote>q</blockquote></body></html>"); | |
| 836 | + assert_eq!(d.title, "Hi & bye"); | |
| 837 | + assert_eq!(d.stats.scripts_skipped, 1); | |
| 838 | + assert_eq!(d.blocks[0], Block::Heading { level: 1, spans: vec![Inline { text: "Head line".into(), ..Default::default() }] }); | |
| 839 | + match &d.blocks[1] { | |
| 840 | + Block::Paragraph { spans, quote: false } => { | |
| 841 | + assert_eq!(spans[0].text, "Hello "); | |
| 842 | + assert_eq!(spans[1].text, "world"); | |
| 843 | + assert_eq!(spans[1].link.as_deref(), Some("https://site.example/x")); | |
| 844 | + assert!(spans[3].italic); | |
| 845 | + } | |
| 846 | + b => panic!("{:?}", b), | |
| 847 | + } | |
| 848 | + assert!(matches!(&d.blocks[2], Block::ListItem { marker, .. } if marker == "•")); | |
| 849 | + assert!(matches!(&d.blocks[3], Block::ListItem { spans, .. } if spans[0].text == "two")); | |
| 850 | + assert!(matches!(&d.blocks[4], Block::ListItem { marker, .. } if marker == "3.")); | |
| 851 | + assert_eq!(d.blocks[5], Block::Code(" a\n b".into())); | |
| 852 | + assert_eq!(d.blocks[6], Block::Rule); | |
| 853 | + assert!(matches!(&d.blocks[7], Block::Paragraph { quote: true, .. })); | |
| 854 | + } | |
| 855 | + | |
| 856 | + #[test] | |
| 857 | + fn ads_and_hidden_are_dropped() { | |
| 858 | + let d = doc("<p>Keep</p><div class=\"ad-slot top\"><p>Buy now</p></div><div id=ads><p>x</p></div>\ | |
| 859 | + <p hidden>h</p><p style=\"display: none\">n</p><img src=\"https://securepubads.g.doubleclick.net/x.gif\">\ | |
| 860 | + <img src=\"/t.gif\" width=1 height=1><img src=\"pic.jpg\" alt=\"A cat\"><iframe src=\"https://ads.adnxs.com/\"></iframe><p>End</p>"); | |
| 861 | + let text = d.plain_text(); | |
| 862 | + assert!(text.contains("Keep") && text.contains("End") && text.contains("A cat")); | |
| 863 | + assert!(!text.contains("Buy now")); | |
| 864 | + assert!(!text.lines().any(|l| l == "h" || l == "n" || l == "x")); | |
| 865 | + assert_eq!(d.image_urls(), vec!["https://site.example/a/pic.jpg".to_string()]); | |
| 866 | + assert_eq!(d.stats.blocked, 3); | |
| 867 | + } | |
| 868 | + | |
| 869 | + #[test] | |
| 870 | + fn main_content_wins() { | |
| 871 | + let d = doc("<header><a href=/>Logo</a></header><nav>Menu</nav><main><p>Story</p></main><footer>Foot</footer>"); | |
| 872 | + assert_eq!(d.plain_text(), "Story\n"); | |
| 873 | + } | |
| 874 | + | |
| 875 | + #[test] | |
| 876 | + fn search_form() { | |
| 877 | + let d = doc("<form action=\"/search?lang=en\"><input type=hidden name=src value=web><input name=q placeholder=Search><input type=submit value=Go></form>"); | |
| 878 | + match &d.blocks[0] { | |
| 879 | + Block::Form(f) => { | |
| 880 | + assert_eq!(f.target("red fox"), "https://site.example/search?lang=en&src=web&q=red+fox"); | |
| 881 | + assert_eq!(f.submit, "Go"); | |
| 882 | + } | |
| 883 | + b => panic!("{:?}", b), | |
| 884 | + } | |
| 885 | + } | |
| 886 | + | |
| 887 | + #[test] | |
| 888 | + fn entities_and_charsets() { | |
| 889 | + assert_eq!(decode_entities("a <b> ’ — &bogus; & x"), "a <b> ’ — &bogus; & x"); | |
| 890 | + assert_eq!(decode_bytes(b"caf\xe9", "text/html; charset=ISO-8859-1"), "café"); | |
| 891 | + assert_eq!(decode_bytes("café".as_bytes(), "text/html"), "café"); | |
| 892 | + } | |
| 893 | + | |
| 894 | + #[test] | |
| 895 | + fn broken_markup_does_not_panic() { | |
| 896 | + for s in ["<", "<a", "<a href='", "<p>&", "</div></div><p>x", "<!--", "<script>", "<b><i>x</b></i>", "<img src=>", "�"] { | |
| 897 | + let _ = doc(s); | |
| 898 | + } | |
| 899 | + } | |
| 900 | + } |
crates/clearwake-core/src/lib.rs added
| 1 | + //! Clearwake's engine. | |
| 2 | + //! | |
| 3 | + //! Everything a Clearwake window needs that is not drawing: web addresses, | |
| 4 | + //! the always-on ad and tracker filter, and a reader that turns a web page | |
| 5 | + //! into clean blocks of text, links and pictures. No scripts ever run. | |
| 6 | + //! | |
| 7 | + //! The crate is `no_std` + `alloc` and uses integer math only, so the same | |
| 8 | + //! code runs in the desktop, Android and web apps and inside the Glimmer | |
| 9 | + //! kernel, which has no floating point unit. | |
| 10 | + | |
| 11 | + #![cfg_attr(not(any(feature = "std", test)), no_std)] | |
| 12 | + | |
| 13 | + extern crate alloc; | |
| 14 | + | |
| 15 | + pub mod bookmarks; | |
| 16 | + pub mod filter; | |
| 17 | + pub mod history; | |
| 18 | + pub mod html; | |
| 19 | + pub mod url; | |
| 20 | + | |
| 21 | + pub use filter::Filter; | |
| 22 | + pub use html::{Block, Document, Inline}; | |
| 23 | + pub use url::Url; | |
| 24 | + | |
| 25 | + /// What the address bar should open for what the person typed. | |
| 26 | + /// | |
| 27 | + /// A web address opens directly. Anything else becomes a search. | |
| 28 | + pub fn resolve_input(input: &str) -> Option<Url> { | |
| 29 | + let s = input.trim(); | |
| 30 | + if s.is_empty() { | |
| 31 | + return None; | |
| 32 | + } | |
| 33 | + if s == "home" || s == "about:home" { | |
| 34 | + return Url::parse("about:home"); | |
| 35 | + } | |
| 36 | + if let Some(u) = Url::parse(s) { | |
| 37 | + if u.scheme == "http" || u.scheme == "https" || u.scheme == "about" { | |
| 38 | + return Some(u); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + let looks_like_host = !s.contains(' ') | |
| 42 | + && (s.contains('.') || s.starts_with("localhost")) | |
| 43 | + && !s.starts_with('.') | |
| 44 | + && !s.ends_with('.'); | |
| 45 | + if looks_like_host { | |
| 46 | + let mut full = alloc::string::String::from("https://"); | |
| 47 | + full.push_str(s); | |
| 48 | + if let Some(u) = Url::parse(&full) { | |
| 49 | + return Some(u); | |
| 50 | + } | |
| 51 | + } | |
| 52 | + let mut q = alloc::string::String::from("https://html.duckduckgo.com/html/?q="); | |
| 53 | + q.push_str(&url::encode_component(s)); | |
| 54 | + Url::parse(&q) | |
| 55 | + } | |
| 56 | + | |
| 57 | + #[cfg(test)] | |
| 58 | + mod tests { | |
| 59 | + use super::*; | |
| 60 | + | |
| 61 | + #[test] | |
| 62 | + fn address_bar() { | |
| 63 | + assert_eq!(resolve_input("example.com").unwrap().to_string(), "https://example.com/"); | |
| 64 | + assert_eq!(resolve_input("http://a.b/c?d").unwrap().to_string(), "http://a.b/c?d"); | |
| 65 | + assert!(resolve_input("rust language").unwrap().to_string().starts_with("https://html.duckduckgo.com/html/?q=rust+language")); | |
| 66 | + assert_eq!(resolve_input("home").unwrap().to_string(), "about:home"); | |
| 67 | + assert!(resolve_input(" ").is_none()); | |
| 68 | + } | |
| 69 | + } |
crates/clearwake-core/src/url.rs added
| 1 | + //! Web addresses: parsing, joining links to the page they sit on, and | |
| 2 | + //! percent-encoding. Only what a browser that never runs scripts needs. | |
| 3 | + | |
| 4 | + use alloc::string::{String, ToString}; | |
| 5 | + use alloc::vec::Vec; | |
| 6 | + use core::fmt; | |
| 7 | + | |
| 8 | + #[derive(Clone, Debug, PartialEq, Eq)] | |
| 9 | + pub struct Url { | |
| 10 | + /// Lower-case: "https", "http" or "about". | |
| 11 | + pub scheme: String, | |
| 12 | + /// Lower-case host name, without the port. Empty for "about:". | |
| 13 | + pub host: String, | |
| 14 | + pub port: Option<u16>, | |
| 15 | + /// Starts with "/" for web addresses; the page name for "about:". | |
| 16 | + pub path: String, | |
| 17 | + /// Without the leading "?". | |
| 18 | + pub query: Option<String>, | |
| 19 | + } | |
| 20 | + | |
| 21 | + impl Url { | |
| 22 | + pub fn parse(input: &str) -> Option<Url> { | |
| 23 | + let s = input.trim(); | |
| 24 | + let colon = s.find(':')?; | |
| 25 | + let scheme = s[..colon].to_ascii_lowercase(); | |
| 26 | + if scheme.is_empty() || !scheme.chars().all(|c| c.is_ascii_alphanumeric() || c == '+' || c == '-' || c == '.') { | |
| 27 | + return None; | |
| 28 | + } | |
| 29 | + let rest = &s[colon + 1..]; | |
| 30 | + if scheme == "about" { | |
| 31 | + let page = rest.split(['?', '#']).next().unwrap_or(""); | |
| 32 | + return Some(Url { scheme, host: String::new(), port: None, path: page.to_ascii_lowercase(), query: None }); | |
| 33 | + } | |
| 34 | + if scheme != "http" && scheme != "https" { | |
| 35 | + return None; | |
| 36 | + } | |
| 37 | + let rest = rest.strip_prefix("//")?; | |
| 38 | + let rest = rest.split('#').next().unwrap_or(""); | |
| 39 | + let auth_end = rest.find(['/', '?']).unwrap_or(rest.len()); | |
| 40 | + let authority = &rest[..auth_end]; | |
| 41 | + // Drop any user:password@ part; Clearwake never sends it. | |
| 42 | + let hostport = authority.rsplit('@').next().unwrap_or(""); | |
| 43 | + let (host, port) = split_host_port(hostport)?; | |
| 44 | + if host.is_empty() || host.contains(' ') { | |
| 45 | + return None; | |
| 46 | + } | |
| 47 | + let after = &rest[auth_end..]; | |
| 48 | + let (path, query) = match after.find('?') { | |
| 49 | + Some(q) => (&after[..q], Some(after[q + 1..].to_string())), | |
| 50 | + None => (after, None), | |
| 51 | + }; | |
| 52 | + let path = if path.is_empty() { "/".to_string() } else { remove_dots(path) }; | |
| 53 | + let port = match (scheme.as_str(), port) { | |
| 54 | + ("http", Some(80)) | ("https", Some(443)) => None, | |
| 55 | + (_, p) => p, | |
| 56 | + }; | |
| 57 | + Some(Url { scheme, host: host.to_ascii_lowercase(), port, path, query }) | |
| 58 | + } | |
| 59 | + | |
| 60 | + /// Resolve a link found on this page. Returns None for links Clearwake | |
| 61 | + /// does not follow (scripts, mail, data, phone, page-internal anchors). | |
| 62 | + pub fn join(&self, href: &str) -> Option<Url> { | |
| 63 | + let h = href.trim(); | |
| 64 | + if h.is_empty() || h.starts_with('#') { | |
| 65 | + return None; | |
| 66 | + } | |
| 67 | + if let Some(colon) = h.find(':') { | |
| 68 | + let before = &h[..colon]; | |
| 69 | + if !before.is_empty() && !before.contains(['/', '?', '#']) { | |
| 70 | + return Url::parse(h); | |
| 71 | + } | |
| 72 | + } | |
| 73 | + if self.scheme == "about" { | |
| 74 | + return None; | |
| 75 | + } | |
| 76 | + if let Some(rest) = h.strip_prefix("//") { | |
| 77 | + let mut s = self.scheme.clone(); | |
| 78 | + s.push_str("://"); | |
| 79 | + s.push_str(rest); | |
| 80 | + return Url::parse(&s); | |
| 81 | + } | |
| 82 | + let h = h.split('#').next().unwrap_or(""); | |
| 83 | + let mut out = self.clone(); | |
| 84 | + if let Some(q) = h.strip_prefix('?') { | |
| 85 | + out.query = Some(q.to_string()); | |
| 86 | + return Some(out); | |
| 87 | + } | |
| 88 | + let (p, q) = match h.find('?') { | |
| 89 | + Some(i) => (&h[..i], Some(h[i + 1..].to_string())), | |
| 90 | + None => (h, None), | |
| 91 | + }; | |
| 92 | + out.query = q; | |
| 93 | + if p.starts_with('/') { | |
| 94 | + out.path = remove_dots(p); | |
| 95 | + } else { | |
| 96 | + let dir = match self.path.rfind('/') { | |
| 97 | + Some(i) => &self.path[..=i], | |
| 98 | + None => "/", | |
| 99 | + }; | |
| 100 | + let mut joined = String::from(dir); | |
| 101 | + joined.push_str(p); | |
| 102 | + out.path = remove_dots(&joined); | |
| 103 | + } | |
| 104 | + Some(out) | |
| 105 | + } | |
| 106 | + | |
| 107 | + pub fn origin(&self) -> String { | |
| 108 | + let mut s = self.scheme.clone(); | |
| 109 | + s.push_str("://"); | |
| 110 | + s.push_str(&self.host); | |
| 111 | + if let Some(p) = self.port { | |
| 112 | + s.push(':'); | |
| 113 | + s.push_str(&p.to_string()); | |
| 114 | + } | |
| 115 | + s | |
| 116 | + } | |
| 117 | + | |
| 118 | + pub fn is_about(&self) -> bool { | |
| 119 | + self.scheme == "about" | |
| 120 | + } | |
| 121 | + | |
| 122 | + /// The host without a leading "www.", for showing in the address bar. | |
| 123 | + pub fn display_host(&self) -> &str { | |
| 124 | + self.host.strip_prefix("www.").unwrap_or(&self.host) | |
| 125 | + } | |
| 126 | + | |
| 127 | + /// Ends with one of the given extensions (".png" etc.), ignoring case. | |
| 128 | + pub fn path_ends_with_any(&self, exts: &[&str]) -> bool { | |
| 129 | + let p = self.path.to_ascii_lowercase(); | |
| 130 | + exts.iter().any(|e| p.ends_with(e)) | |
| 131 | + } | |
| 132 | + } | |
| 133 | + | |
| 134 | + impl fmt::Display for Url { | |
| 135 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 136 | + if self.scheme == "about" { | |
| 137 | + return write!(f, "about:{}", self.path); | |
| 138 | + } | |
| 139 | + write!(f, "{}{}", self.origin(), self.path)?; | |
| 140 | + if let Some(q) = &self.query { | |
| 141 | + write!(f, "?{}", q)?; | |
| 142 | + } | |
| 143 | + Ok(()) | |
| 144 | + } | |
| 145 | + } | |
| 146 | + | |
| 147 | + fn split_host_port(s: &str) -> Option<(&str, Option<u16>)> { | |
| 148 | + if let Some(rest) = s.strip_prefix('[') { | |
| 149 | + // IPv6 literal. | |
| 150 | + let end = rest.find(']')?; | |
| 151 | + let host = &s[..end + 2]; | |
| 152 | + let after = &rest[end + 1..]; | |
| 153 | + let port = match after.strip_prefix(':') { | |
| 154 | + Some(p) if !p.is_empty() => Some(p.parse().ok()?), | |
| 155 | + _ => None, | |
| 156 | + }; | |
| 157 | + return Some((host, port)); | |
| 158 | + } | |
| 159 | + match s.rfind(':') { | |
| 160 | + Some(i) => { | |
| 161 | + let p = &s[i + 1..]; | |
| 162 | + let port = if p.is_empty() { None } else { Some(p.parse().ok()?) }; | |
| 163 | + Some((&s[..i], port)) | |
| 164 | + } | |
| 165 | + None => Some((s, None)), | |
| 166 | + } | |
| 167 | + } | |
| 168 | + | |
| 169 | + /// Remove "." and ".." path segments. | |
| 170 | + fn remove_dots(path: &str) -> String { | |
| 171 | + let mut out: Vec<&str> = Vec::new(); | |
| 172 | + let segs: Vec<&str> = path.split('/').collect(); | |
| 173 | + let last = segs.len().saturating_sub(1); | |
| 174 | + let mut trailing = false; | |
| 175 | + for (i, seg) in segs.iter().enumerate() { | |
| 176 | + match *seg { | |
| 177 | + "." => trailing = i == last, | |
| 178 | + ".." => { | |
| 179 | + if out.len() > 1 { | |
| 180 | + out.pop(); | |
| 181 | + } | |
| 182 | + trailing = i == last; | |
| 183 | + } | |
| 184 | + "" if i == 0 => out.push(""), | |
| 185 | + s => { | |
| 186 | + out.push(s); | |
| 187 | + trailing = false; | |
| 188 | + } | |
| 189 | + } | |
| 190 | + } | |
| 191 | + if out.first() != Some(&"") { | |
| 192 | + out.insert(0, ""); | |
| 193 | + } | |
| 194 | + let mut s = out.join("/"); | |
| 195 | + if trailing || s.is_empty() { | |
| 196 | + s.push('/'); | |
| 197 | + } | |
| 198 | + s | |
| 199 | + } | |
| 200 | + | |
| 201 | + /// Percent-encode for a query value (spaces become "+"). | |
| 202 | + pub fn encode_component(s: &str) -> String { | |
| 203 | + let mut out = String::new(); | |
| 204 | + for b in s.bytes() { | |
| 205 | + match b { | |
| 206 | + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => out.push(b as char), | |
| 207 | + b' ' => out.push('+'), | |
| 208 | + _ => { | |
| 209 | + const HEX: &[u8; 16] = b"0123456789ABCDEF"; | |
| 210 | + out.push('%'); | |
| 211 | + out.push(HEX[(b >> 4) as usize] as char); | |
| 212 | + out.push(HEX[(b & 15) as usize] as char); | |
| 213 | + } | |
| 214 | + } | |
| 215 | + } | |
| 216 | + out | |
| 217 | + } | |
| 218 | + | |
| 219 | + /// Decode a percent-encoded query value ("+" becomes a space). | |
| 220 | + pub fn decode_component(s: &str) -> String { | |
| 221 | + let b = s.as_bytes(); | |
| 222 | + let mut out = Vec::with_capacity(b.len()); | |
| 223 | + let mut i = 0; | |
| 224 | + while i < b.len() { | |
| 225 | + match b[i] { | |
| 226 | + b'+' => out.push(b' '), | |
| 227 | + b'%' if i + 2 < b.len() => { | |
| 228 | + let hv = |c: u8| (c as char).to_digit(16); | |
| 229 | + match (hv(b[i + 1]), hv(b[i + 2])) { | |
| 230 | + (Some(h), Some(l)) => { | |
| 231 | + out.push((h * 16 + l) as u8); | |
| 232 | + i += 2; | |
| 233 | + } | |
| 234 | + _ => out.push(b'%'), | |
| 235 | + } | |
| 236 | + } | |
| 237 | + c => out.push(c), | |
| 238 | + } | |
| 239 | + i += 1; | |
| 240 | + } | |
| 241 | + String::from_utf8_lossy(&out).into_owned() | |
| 242 | + } | |
| 243 | + | |
| 244 | + #[cfg(test)] | |
| 245 | + mod tests { | |
| 246 | + use super::*; | |
| 247 | + | |
| 248 | + fn j(base: &str, href: &str) -> String { | |
| 249 | + Url::parse(base).unwrap().join(href).map(|u| u.to_string()).unwrap_or_default() | |
| 250 | + } | |
| 251 | + | |
| 252 | + #[test] | |
| 253 | + fn parse_and_print() { | |
| 254 | + assert_eq!(Url::parse("HTTPS://Example.COM").unwrap().to_string(), "https://example.com/"); | |
| 255 | + assert_eq!(Url::parse("https://a.com:443/x?y=1#z").unwrap().to_string(), "https://a.com/x?y=1"); | |
| 256 | + assert_eq!(Url::parse("http://a.com:8080/").unwrap().to_string(), "http://a.com:8080/"); | |
| 257 | + assert_eq!(Url::parse("https://u:p@a.com/").unwrap().host, "a.com"); | |
| 258 | + assert!(Url::parse("javascript:alert(1)").is_none()); | |
| 259 | + assert!(Url::parse("file:///etc/passwd").is_none()); | |
| 260 | + } | |
| 261 | + | |
| 262 | + #[test] | |
| 263 | + fn joins() { | |
| 264 | + assert_eq!(j("https://a.com/b/c.html", "d.html"), "https://a.com/b/d.html"); | |
| 265 | + assert_eq!(j("https://a.com/b/c.html", "../d"), "https://a.com/d"); | |
| 266 | + assert_eq!(j("https://a.com/b/", "./"), "https://a.com/b/"); | |
| 267 | + assert_eq!(j("https://a.com/b/c", "/x?y"), "https://a.com/x?y"); | |
| 268 | + assert_eq!(j("https://a.com/b/c", "?q=1"), "https://a.com/b/c?q=1"); | |
| 269 | + assert_eq!(j("https://a.com/b/c", "//cdn.b.com/i.png"), "https://cdn.b.com/i.png"); | |
| 270 | + assert_eq!(j("https://a.com/", "http://c.com"), "http://c.com/"); | |
| 271 | + assert_eq!(j("https://a.com/", "#top"), ""); | |
| 272 | + assert_eq!(j("https://a.com/", "javascript:void(0)"), ""); | |
| 273 | + assert_eq!(j("https://a.com/", "mailto:x@y.z"), ""); | |
| 274 | + } | |
| 275 | + | |
| 276 | + #[test] | |
| 277 | + fn encoding() { | |
| 278 | + assert_eq!(encode_component("a b&c"), "a+b%26c"); | |
| 279 | + assert_eq!(decode_component("a+b%26c%"), "a b&c%"); | |
| 280 | + } | |
| 281 | + } |
crates/clearwake-fetch/Cargo.lock added
| 1 | + # This file is automatically @generated by Cargo. | |
| 2 | + # It is not intended for manual editing. | |
| 3 | + version = 4 | |
| 4 | + | |
| 5 | + [[package]] | |
| 6 | + name = "clearwake-core" | |
| 7 | + version = "0.1.0" | |
| 8 | + | |
| 9 | + [[package]] | |
| 10 | + name = "clearwake-fetch" | |
| 11 | + version = "0.1.0" | |
| 12 | + dependencies = [ | |
| 13 | + "clearwake-core", | |
| 14 | + ] |
crates/clearwake-fetch/Cargo.toml added
| 1 | + [package] | |
| 2 | + name = "clearwake-fetch" | |
| 3 | + description = "Clearwake's filter for the web version's page loader, as a tiny WebAssembly module with no imports. The loader (clearwake.ai/fetch) asks it about every address and redirect." | |
| 4 | + version = "0.1.0" | |
| 5 | + edition = "2021" | |
| 6 | + license = "Unlicense" | |
| 7 | + | |
| 8 | + [lib] | |
| 9 | + crate-type = ["cdylib"] | |
| 10 | + | |
| 11 | + [dependencies] | |
| 12 | + clearwake-core = { path = "../clearwake-core" } | |
| 13 | + | |
| 14 | + [profile.release] | |
| 15 | + opt-level = "s" | |
| 16 | + lto = true | |
| 17 | + codegen-units = 1 | |
| 18 | + strip = true | |
| 19 | + panic = "abort" | |
| 20 | + | |
| 21 | + [workspace] |
crates/clearwake-fetch/pages/clearwake-fetch.js added
| 1 | + // clearwake.ai/fetch: loads a page or picture for Clearwake on the web. | |
| 2 | + // Every address and every redirect is checked by Clearwake's own filter | |
| 3 | + // (Rust, compiled to clearwake_fetch.wasm) before it is requested. Only | |
| 4 | + // pages, text and pictures come back. No cookies are sent or kept. | |
| 5 | + import filterModule from './clearwake_fetch.wasm'; | |
| 6 | + | |
| 7 | + const MAX_BYTES = 10 * 1024 * 1024; | |
| 8 | + const USER_AGENT = 'Mozilla/5.0 (compatible; Clearwake/0.1; +https://clearwake.ai)'; | |
| 9 | + const ORIGINS = ['https://clearwake.ai', 'https://www.clearwake.ai']; | |
| 10 | + const enc = new TextEncoder(); | |
| 11 | + | |
| 12 | + function check(url) { | |
| 13 | + const f = new WebAssembly.Instance(filterModule, {}).exports; | |
| 14 | + const b = enc.encode(url); | |
| 15 | + const p = f.cw_alloc(b.length); | |
| 16 | + new Uint8Array(f.memory.buffer, p, b.length).set(b); | |
| 17 | + return f.cw_check(p, b.length); | |
| 18 | + } | |
| 19 | + | |
| 20 | + function reply(status, text, extra = {}) { | |
| 21 | + return new Response(text, { | |
| 22 | + status, | |
| 23 | + headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff', ...extra }, | |
| 24 | + }); | |
| 25 | + } | |
| 26 | + | |
| 27 | + export async function clearwakeFetch(request) { | |
| 28 | + const origin = request.headers.get('origin') || ''; | |
| 29 | + const site = request.headers.get('sec-fetch-site') || ''; | |
| 30 | + if (!(site === 'same-origin' || ORIGINS.includes(origin))) return reply(403, 'This loader only works inside Clearwake.'); | |
| 31 | + if (request.method !== 'GET') return reply(405, 'Only pages can be loaded.'); | |
| 32 | + let target = new URL(request.url).searchParams.get('url') || ''; | |
| 33 | + for (let hop = 0; hop < 8; hop++) { | |
| 34 | + const verdict = check(target); | |
| 35 | + if (verdict === 1) return reply(403, 'Clearwake blocked this address because it serves ads or tracking.'); | |
| 36 | + if (verdict === 2) return reply(400, "That address doesn't look right."); | |
| 37 | + if (verdict === 3) return reply(400, 'Clearwake on the web can only open public sites.'); | |
| 38 | + let res; | |
| 39 | + try { | |
| 40 | + res = await fetch(target, { | |
| 41 | + redirect: 'manual', | |
| 42 | + headers: { 'user-agent': USER_AGENT, accept: 'text/html,application/xhtml+xml,text/plain;q=0.9,image/*;q=0.8', 'accept-language': 'en-US,en;q=0.8' }, | |
| 43 | + }); | |
| 44 | + } catch { | |
| 45 | + return reply(502, "Clearwake couldn't reach that site."); | |
| 46 | + } | |
| 47 | + if (res.status >= 300 && res.status < 400) { | |
| 48 | + const loc = res.headers.get('location'); | |
| 49 | + if (!loc) return reply(502, 'The site sent Clearwake somewhere it won\'t go.'); | |
| 50 | + target = new URL(loc, target).toString(); | |
| 51 | + continue; | |
| 52 | + } | |
| 53 | + if (res.status >= 400) return reply(502, `The site answered with an error (${res.status}).`); | |
| 54 | + const ct = res.headers.get('content-type') || ''; | |
| 55 | + const l = ct.toLowerCase(); | |
| 56 | + if (!(l === '' || l.includes('html') || l.includes('xml') || l.startsWith('text/') || l.startsWith('image/') || l.includes('json'))) { | |
| 57 | + return reply(415, "This is a file, not a page. Clearwake doesn't download files."); | |
| 58 | + } | |
| 59 | + const body = await res.arrayBuffer(); | |
| 60 | + if (body.byteLength > MAX_BYTES) return reply(413, 'This page is too large to open.'); | |
| 61 | + return new Response(body, { | |
| 62 | + status: 200, | |
| 63 | + headers: { 'content-type': ct || 'application/octet-stream', 'x-clearwake-url': target, 'cache-control': 'no-store', 'x-content-type-options': 'nosniff' }, | |
| 64 | + }); | |
| 65 | + } | |
| 66 | + return reply(508, 'The site redirected too many times.'); | |
| 67 | + } |
crates/clearwake-fetch/pages/clearwake_fetch.wasm added
Not a text file.
crates/clearwake-fetch/src/lib.rs added
| 1 | + //! The filter behind clearwake.ai/fetch, the page loader for Clearwake on | |
| 2 | + //! the web (a web page can't read other sites directly). | |
| 3 | + //! | |
| 4 | + //! Built as a WebAssembly module with no imports. The loader writes an | |
| 5 | + //! address into memory from `cw_alloc` and asks `cw_check` before every | |
| 6 | + //! request and every redirect: | |
| 7 | + //! 0 = may load, 1 = ad or tracker (blocked), 2 = not a web address, | |
| 8 | + //! 3 = a private or local address. | |
| 9 | + | |
| 10 | + #![no_std] | |
| 11 | + | |
| 12 | + extern crate alloc; | |
| 13 | + | |
| 14 | + use alloc::vec::Vec; | |
| 15 | + use clearwake_core::{Filter, Url}; | |
| 16 | + use core::cell::UnsafeCell; | |
| 17 | + | |
| 18 | + struct Bump; | |
| 19 | + | |
| 20 | + /// A small allocator: WebAssembly memory only grows, and each request | |
| 21 | + /// runs in a fresh instance, so freeing is a no-op. | |
| 22 | + unsafe impl core::alloc::GlobalAlloc for Bump { | |
| 23 | + unsafe fn alloc(&self, layout: core::alloc::Layout) -> *mut u8 { | |
| 24 | + static mut NEXT: usize = 0; | |
| 25 | + static mut END: usize = 0; | |
| 26 | + unsafe { | |
| 27 | + let align = layout.align(); | |
| 28 | + let mut start = (NEXT + align - 1) & !(align - 1); | |
| 29 | + if start == 0 || start + layout.size() > END { | |
| 30 | + let pages = layout.size() / 65536 + 1; | |
| 31 | + let old = core::arch::wasm32::memory_grow(0, pages); | |
| 32 | + if old == usize::MAX { | |
| 33 | + return core::ptr::null_mut(); | |
| 34 | + } | |
| 35 | + if start == 0 || old * 65536 != END { | |
| 36 | + start = (old * 65536 + align - 1) & !(align - 1); | |
| 37 | + } | |
| 38 | + END = (old + pages) * 65536; | |
| 39 | + } | |
| 40 | + NEXT = start + layout.size(); | |
| 41 | + start as *mut u8 | |
| 42 | + } | |
| 43 | + } | |
| 44 | + unsafe fn dealloc(&self, _: *mut u8, _: core::alloc::Layout) {} | |
| 45 | + } | |
| 46 | + | |
| 47 | + #[global_allocator] | |
| 48 | + static ALLOC: Bump = Bump; | |
| 49 | + | |
| 50 | + #[panic_handler] | |
| 51 | + fn panic(_: &core::panic::PanicInfo) -> ! { | |
| 52 | + core::arch::wasm32::unreachable() | |
| 53 | + } | |
| 54 | + | |
| 55 | + struct Once(UnsafeCell<Option<Filter>>); | |
| 56 | + unsafe impl Sync for Once {} | |
| 57 | + static FILTER: Once = Once(UnsafeCell::new(None)); | |
| 58 | + | |
| 59 | + fn filter() -> &'static Filter { | |
| 60 | + // Single-threaded WebAssembly. | |
| 61 | + unsafe { (*FILTER.0.get()).get_or_insert_with(Filter::new) } | |
| 62 | + } | |
| 63 | + | |
| 64 | + #[unsafe(no_mangle)] | |
| 65 | + pub extern "C" fn cw_alloc(len: usize) -> *mut u8 { | |
| 66 | + let mut v: Vec<u8> = Vec::with_capacity(len.max(1)); | |
| 67 | + let p = v.as_mut_ptr(); | |
| 68 | + core::mem::forget(v); | |
| 69 | + p | |
| 70 | + } | |
| 71 | + | |
| 72 | + fn private_host(h: &str) -> bool { | |
| 73 | + h == "localhost" | |
| 74 | + || h.ends_with(".localhost") | |
| 75 | + || h.ends_with(".local") | |
| 76 | + || h.ends_with(".internal") | |
| 77 | + || h.starts_with('[') | |
| 78 | + || h.starts_with("127.") | |
| 79 | + || h.starts_with("10.") | |
| 80 | + || h.starts_with("192.168.") | |
| 81 | + || h.starts_with("169.254.") | |
| 82 | + || h.starts_with("0.") | |
| 83 | + || h.starts_with("100.64.") | |
| 84 | + || (h.starts_with("172.") && h.split('.').nth(1).and_then(|s| s.parse::<u8>().ok()).is_some_and(|n| (16..=31).contains(&n))) | |
| 85 | + } | |
| 86 | + | |
| 87 | + #[unsafe(no_mangle)] | |
| 88 | + pub extern "C" fn cw_check(ptr: *const u8, len: usize) -> i32 { | |
| 89 | + let bytes = unsafe { core::slice::from_raw_parts(ptr, len) }; | |
| 90 | + let Ok(s) = core::str::from_utf8(bytes) else { return 2 }; | |
| 91 | + let Some(u) = Url::parse(s) else { return 2 }; | |
| 92 | + if u.is_about() { | |
| 93 | + return 2; | |
| 94 | + } | |
| 95 | + if private_host(&u.host) { | |
| 96 | + return 3; | |
| 97 | + } | |
| 98 | + if filter().blocks(&u) { | |
| 99 | + return 1; | |
| 100 | + } | |
| 101 | + 0 | |
| 102 | + } |
crates/clearwake-glimmer/Cargo.lock added
| 1 | + # This file is automatically @generated by Cargo. | |
| 2 | + # It is not intended for manual editing. | |
| 3 | + version = 4 | |
| 4 | + | |
| 5 | + [[package]] | |
| 6 | + name = "clearwake-core" | |
| 7 | + version = "0.1.0" | |
| 8 | + | |
| 9 | + [[package]] | |
| 10 | + name = "clearwake-glimmer" | |
| 11 | + version = "0.1.0" | |
| 12 | + dependencies = [ | |
| 13 | + "clearwake-core", | |
| 14 | + "glimmer-ui", | |
| 15 | + ] | |
| 16 | + | |
| 17 | + [[package]] | |
| 18 | + name = "glimmer-ui" | |
| 19 | + version = "0.1.0" | |
| 20 | + source = "git+https://github.com/projectatomai/atom-platform?branch=main#3cc0d3e8c9d444f06be8ccdc2d2c81fe3afb26f4" |
crates/clearwake-glimmer/Cargo.toml added
| 1 | + [package] | |
| 2 | + name = "clearwake-glimmer" | |
| 3 | + description = "Clearwake as a native Glimmer window, drawn by Glimmer's own kernel. no_std + alloc, integer math only." | |
| 4 | + version = "0.1.0" | |
| 5 | + edition = "2024" | |
| 6 | + license = "Unlicense" | |
| 7 | + | |
| 8 | + [dependencies] | |
| 9 | + clearwake-core = { path = "../clearwake-core" } | |
| 10 | + glimmer-ui = { git = "https://github.com/projectatomai/atom-platform", branch = "main" } | |
| 11 | + | |
| 12 | + [features] | |
| 13 | + default = [] | |
| 14 | + std = ["glimmer-ui/std", "clearwake-core/std"] | |
| 15 | + | |
| 16 | + [[example]] | |
| 17 | + name = "shot" | |
| 18 | + required-features = ["std"] | |
| 19 | + | |
| 20 | + [workspace] |
crates/clearwake-glimmer/examples/shot.rs added
| 1 | + //! Draw Clearwake inside the Glimmer desktop on the host and save a PPM. | |
| 2 | + //! cargo run --release --features std --example shot -- OUT.ppm [page.html URL] | |
| 3 | + | |
| 4 | + use clearwake_glimmer::ClearwakeWindow; | |
| 5 | + use glimmer_ui::theme; | |
| 6 | + use glimmer_ui::wm::{Desktop, WindowSpec}; | |
| 7 | + use std::io::Write; | |
| 8 | + | |
| 9 | + fn main() { | |
| 10 | + let args: Vec<String> = std::env::args().collect(); | |
| 11 | + let out = args.get(1).cloned().unwrap_or_else(|| "clearwake-glimmer.ppm".into()); | |
| 12 | + let (w, h) = (1600, 1000); | |
| 13 | + let mut win = ClearwakeWindow::new(); | |
| 14 | + if let (Some(file), Some(url)) = (args.get(2), args.get(3)) { | |
| 15 | + let src = std::fs::read_to_string(file).expect("page"); | |
| 16 | + win.show_page(url, &src); | |
| 17 | + } | |
| 18 | + let mut d = Desktop::new(w, h, theme::DARK); | |
| 19 | + d.open(WindowSpec::window("Clearwake", 1180, 860), Box::new(win)); | |
| 20 | + d.render(); | |
| 21 | + let cv = &d.screen; | |
| 22 | + let mut f = std::fs::File::create(&out).unwrap(); | |
| 23 | + write!(f, "P6\n{} {}\n255\n", cv.w, cv.h).unwrap(); | |
| 24 | + let mut buf = Vec::with_capacity((cv.w * cv.h * 3) as usize); | |
| 25 | + for p in &cv.px { | |
| 26 | + buf.extend_from_slice(&[(p >> 16) as u8, (p >> 8) as u8, *p as u8]); | |
| 27 | + } | |
| 28 | + f.write_all(&buf).unwrap(); | |
| 29 | + println!("{out}"); | |
| 30 | + } |
crates/clearwake-glimmer/src/lib.rs added
| 1 | + //! Clearwake on Glimmer: the same page engine as every other Clearwake, | |
| 2 | + //! drawn as a native Glimmer window by Glimmer's own kernel. | |
| 3 | + //! | |
| 4 | + //! The kernel owns the network. When the person opens an address, the | |
| 5 | + //! window asks for it ([`ClearwakeWindow::take_request`]); the kernel loads | |
| 6 | + //! it (after the same filter check) and hands the page back with | |
| 7 | + //! [`ClearwakeWindow::show_page`]. Until the kernel's network stack is | |
| 8 | + //! wired in, the window shows its built-in welcome page. | |
| 9 | + | |
| 10 | + #![no_std] | |
| 11 | + | |
| 12 | + extern crate alloc; | |
| 13 | + | |
| 14 | + use alloc::string::{String, ToString}; | |
| 15 | + use alloc::vec::Vec; | |
| 16 | + use clearwake_core::html::{self, Block, Document, Inline}; | |
| 17 | + use clearwake_core::{Filter, Url}; | |
| 18 | + use glimmer_ui::canvas::{Canvas, Rect}; | |
| 19 | + use glimmer_ui::font::{self, Font}; | |
| 20 | + use glimmer_ui::input::Key; | |
| 21 | + use glimmer_ui::theme::Theme; | |
| 22 | + use glimmer_ui::wm::{App, Ctx, WinEvent}; | |
| 23 | + | |
| 24 | + const BAR_H: i32 = 64; | |
| 25 | + const COLUMN: i32 = 760; | |
| 26 | + | |
| 27 | + pub const WELCOME: &str = "<html><head><title>Clearwake</title></head><body><main>\ | |
| 28 | + <h1>Clearwake</h1><p><em>Less noise. More web.</em></p>\ | |
| 29 | + <p>This is Clearwake running natively on Glimmer, drawn by Glimmer's own kernel. \ | |
| 30 | + It reads pages into clean text, links and pictures. Scripts never run, and ads and trackers are blocked before they load.</p>\ | |
| 31 | + <h2>Always on</h2><ul><li>No ad blocking switch and no exceptions.</li><li>No account. Bookmarks stay on this machine.</li>\ | |
| 32 | + <li>The same Rust engine as Clearwake for Mac, Windows, Linux, Android and the web.</li></ul>\ | |
| 33 | + <p>Type an address above and press Enter.</p></main></body></html>"; | |
| 34 | + | |
| 35 | + struct Hit { | |
| 36 | + rect: Rect, | |
| 37 | + href: String, | |
| 38 | + } | |
| 39 | + | |
| 40 | + pub struct ClearwakeWindow { | |
| 41 | + filter: Filter, | |
| 42 | + doc: Document, | |
| 43 | + address: String, | |
| 44 | + editing: bool, | |
| 45 | + scroll: i32, | |
| 46 | + content_h: i32, | |
| 47 | + hits: Vec<Hit>, | |
| 48 | + request: Option<String>, | |
| 49 | + status: String, | |
| 50 | + view_h: i32, | |
| 51 | + } | |
| 52 | + | |
| 53 | + impl ClearwakeWindow { | |
| 54 | + pub fn new() -> ClearwakeWindow { | |
| 55 | + let filter = Filter::new(); | |
| 56 | + let url = Url::parse("about:home").unwrap(); | |
| 57 | + let doc = html::parse(WELCOME, &url, &filter); | |
| 58 | + ClearwakeWindow { | |
| 59 | + filter, | |
| 60 | + doc, | |
| 61 | + address: String::new(), | |
| 62 | + editing: false, | |
| 63 | + scroll: 0, | |
| 64 | + content_h: 0, | |
| 65 | + hits: Vec::new(), | |
| 66 | + request: None, | |
| 67 | + status: String::from("Ad blocking is always on"), | |
| 68 | + view_h: 600, | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + /// The address the person asked for, if any. The kernel loads it. | |
| 73 | + pub fn take_request(&mut self) -> Option<String> { | |
| 74 | + self.request.take() | |
| 75 | + } | |
| 76 | + | |
| 77 | + /// Show a page the kernel loaded. | |
| 78 | + pub fn show_page(&mut self, url: &str, source: &str) { | |
| 79 | + let u = Url::parse(url).unwrap_or_else(|| Url::parse("about:blank").unwrap()); | |
| 80 | + self.doc = html::parse(source, &u, &self.filter); | |
| 81 | + self.address = url.to_string(); | |
| 82 | + self.scroll = 0; | |
| 83 | + let s = &self.doc.stats; | |
| 84 | + self.status = alloc::format!("Blocked {} ads and trackers · {} scripts never ran", s.blocked + s.hidden, s.scripts_skipped); | |
| 85 | + } | |
| 86 | + | |
| 87 | + /// The kernel couldn't load the page. | |
| 88 | + pub fn show_error(&mut self, url: &str, message: &str) { | |
| 89 | + let page = alloc::format!("<h1>This page didn't open</h1><p>{}</p>", message); | |
| 90 | + self.show_page(url, &page); | |
| 91 | + self.status = String::from(message); | |
| 92 | + } | |
| 93 | + | |
| 94 | + fn open(&mut self, input: &str) { | |
| 95 | + match clearwake_core::resolve_input(input) { | |
| 96 | + Some(u) if self.filter.blocks(&u) => { | |
| 97 | + let s = u.to_string(); | |
| 98 | + self.show_error(&s, "Clearwake blocked this address because it serves ads or tracking."); | |
| 99 | + } | |
| 100 | + Some(u) if u.is_about() => { | |
| 101 | + *self = ClearwakeWindow::new(); | |
| 102 | + } | |
| 103 | + Some(u) => { | |
| 104 | + self.address = u.to_string(); | |
| 105 | + self.status = alloc::format!("Loading {}", u.display_host()); | |
| 106 | + self.request = Some(u.to_string()); | |
| 107 | + } | |
| 108 | + None => {} | |
| 109 | + } | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + impl Default for ClearwakeWindow { | |
| 114 | + fn default() -> Self { | |
| 115 | + ClearwakeWindow::new() | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + /// Lay out and draw a run of styled words, wrapping at `max`. Returns the | |
| 120 | + /// height used. Link words are recorded as click targets. | |
| 121 | + #[allow(clippy::too_many_arguments)] | |
| 122 | + fn flow(cv: &mut Canvas, hits: &mut Vec<Hit>, spans: &[Inline], x: i32, y: i32, max: i32, f: &Font, bold: &Font, th: &Theme, color: u32) -> i32 { | |
| 123 | + let line_h = f.line() + 6; | |
| 124 | + let space = f.width(" "); | |
| 125 | + let (mut cx, mut cy) = (x, y); | |
| 126 | + for sp in spans { | |
| 127 | + let face = if sp.bold { bold } else { f }; | |
| 128 | + let c = if sp.link.is_some() { th.link } else { color }; | |
| 129 | + let dy = f.ascent() - face.ascent(); | |
| 130 | + for (n, para) in sp.text.split('\n').enumerate() { | |
| 131 | + if n > 0 { | |
| 132 | + cx = x; | |
| 133 | + cy += line_h; | |
| 134 | + } | |
| 135 | + let lead = para.starts_with(' '); | |
| 136 | + if lead && cx > x { | |
| 137 | + cx += space; | |
| 138 | + } | |
| 139 | + for word in para.split(' ').filter(|w| !w.is_empty()) { | |
| 140 | + let w = face.width(word); | |
| 141 | + if cx > x && cx + w > x + max { | |
| 142 | + cx = x; | |
| 143 | + cy += line_h; | |
| 144 | + } | |
| 145 | + face.draw_top(cv, cx, cy + dy, word, c); | |
| 146 | + if let Some(h) = &sp.link { | |
| 147 | + hits.push(Hit { rect: Rect::new(cx, cy, w + space, line_h), href: h.clone() }); | |
| 148 | + cv.fill(Rect::new(cx, cy + f.line(), w, 1), c); | |
| 149 | + } | |
| 150 | + cx += w + space; | |
| 151 | + } | |
| 152 | + if !para.ends_with(' ') && cx > x { | |
| 153 | + cx -= space; | |
| 154 | + } | |
| 155 | + } | |
| 156 | + } | |
| 157 | + cy - y + line_h | |
| 158 | + } | |
| 159 | + | |
| 160 | + impl App for ClearwakeWindow { | |
| 161 | + fn draw(&mut self, cv: &mut Canvas, th: &Theme) { | |
| 162 | + let (w, h) = (cv.w, cv.h); | |
| 163 | + self.view_h = h - BAR_H - 34; | |
| 164 | + cv.clear(th.bg); | |
| 165 | + self.hits.clear(); | |
| 166 | + | |
| 167 | + // Page. | |
| 168 | + let col = (w - 48).min(COLUMN); | |
| 169 | + let x = (w - col) / 2; | |
| 170 | + let top = BAR_H; | |
| 171 | + let old = cv.push_clip(Rect::new(0, top, w, h - top - 34)); | |
| 172 | + let mut y = top + 28 - self.scroll; | |
| 173 | + let body = &font::SERIF_21; | |
| 174 | + for b in &self.doc.blocks { | |
| 175 | + match b { | |
| 176 | + Block::Heading { level, spans } => { | |
| 177 | + let f = match level { | |
| 178 | + 1 => &font::SERIF_36_SEMI, | |
| 179 | + 2 => &font::SERIF_26_SEMI, | |
| 180 | + _ => &font::SANS_20_SEMI, | |
| 181 | + }; | |
| 182 | + y += if *level <= 2 { 18 } else { 10 }; | |
| 183 | + y += flow(cv, &mut self.hits, spans, x, y, col, f, f, th, th.ink) + 4; | |
| 184 | + } | |
| 185 | + Block::Paragraph { spans, quote } => { | |
| 186 | + y += 8; | |
| 187 | + if *quote { | |
| 188 | + let hgt = flow(cv, &mut self.hits, spans, x + 18, y, col - 18, &font::SERIF_21_ITALIC, &font::SERIF_21_ITALIC, th, th.ink2); | |
| 189 | + cv.fill(Rect::new(x, y, 3, hgt), th.line); | |
| 190 | + y += hgt; | |
| 191 | + } else { | |
| 192 | + y += flow(cv, &mut self.hits, spans, x, y, col, body, &font::SANS_17_SEMI, th, th.ink); | |
| 193 | + } | |
| 194 | + } | |
| 195 | + Block::ListItem { depth, marker, spans } => { | |
| 196 | + let indent = 22 * (*depth as i32).clamp(1, 6); | |
| 197 | + font::SANS_17.draw_top(cv, x + indent - 18, y + 2, marker, th.ink3); | |
| 198 | + y += flow(cv, &mut self.hits, spans, x + indent + 8, y, col - indent - 8, body, &font::SANS_17_SEMI, th, th.ink) + 2; | |
| 199 | + } | |
| 200 | + Block::Code(code) => { | |
| 201 | + y += 8; | |
| 202 | + let lines: Vec<&str> = code.lines().collect(); | |
| 203 | + let lh = font::MONO_16.line() + 4; | |
| 204 | + let box_h = lines.len() as i32 * lh + 24; | |
| 205 | + cv.rrect(Rect::new(x, y, col, box_h), 10, th.inset); | |
| 206 | + for (i, l) in lines.iter().enumerate() { | |
| 207 | + font::MONO_16.draw_top(cv, x + 14, y + 12 + i as i32 * lh, l, th.ink); | |
| 208 | + } | |
| 209 | + y += box_h + 8; | |
| 210 | + } | |
| 211 | + Block::Image { alt, width, height, .. } => { | |
| 212 | + // Pictures need a decoder the kernel doesn't have yet; show where they go. | |
| 213 | + let iw = width.map(|v| (v as i32).min(col)).unwrap_or(col); | |
| 214 | + let ih = match (width, height) { | |
| 215 | + (Some(w0), Some(h0)) if *w0 > 0 => (*h0 as i32) * iw / (*w0 as i32), | |
| 216 | + _ => 160, | |
| 217 | + } | |
| 218 | + .clamp(60, 420); | |
| 219 | + y += 8; | |
| 220 | + cv.rrect(Rect::new(x, y, iw, ih), 10, th.card); | |
| 221 | + cv.rrect_stroke(Rect::new(x, y, iw, ih), 10, 1, th.line); | |
| 222 | + let label = if alt.is_empty() { "Picture" } else { alt.as_str() }; | |
| 223 | + font::SANS_15.draw_centered(cv, x, iw, y + ih / 2 + 5, &font::SANS_15.ellipsize(label, iw - 24), th.ink3); | |
| 224 | + y += ih + 8; | |
| 225 | + } | |
| 226 | + Block::Rule => { | |
| 227 | + y += 12; | |
| 228 | + cv.fill(Rect::new(x, y, col, 1), th.line); | |
| 229 | + y += 12; | |
| 230 | + } | |
| 231 | + Block::Form(f) => { | |
| 232 | + y += 8; | |
| 233 | + let label = if f.placeholder.is_empty() { "Search" } else { f.placeholder.as_str() }; | |
| 234 | + cv.rrect(Rect::new(x, y, col, 40), 20, th.card); | |
| 235 | + cv.rrect_stroke(Rect::new(x, y, col, 40), 20, 1, th.line); | |
| 236 | + font::SANS_17.draw_top(cv, x + 18, y + 10, label, th.ink3); | |
| 237 | + y += 48; | |
| 238 | + } | |
| 239 | + } | |
| 240 | + } | |
| 241 | + self.content_h = y + self.scroll - top + 40; | |
| 242 | + cv.set_clip(old); | |
| 243 | + | |
| 244 | + // Address bar. | |
| 245 | + cv.fill(Rect::new(0, 0, w, BAR_H), th.sidebar); | |
| 246 | + cv.fill(Rect::new(0, BAR_H - 1, w, 1), th.sidebar_line); | |
| 247 | + let field = Rect::new(20, 12, w - 40, 40); | |
| 248 | + cv.rrect(field, 20, th.card); | |
| 249 | + cv.rrect_stroke(field, 20, if self.editing { 2 } else { 1 }, if self.editing { th.accent } else { th.line }); | |
| 250 | + let shown = if self.address.is_empty() { "Search or type a web address" } else { self.address.as_str() }; | |
| 251 | + let tc = if self.address.is_empty() { th.ink3 } else { th.ink }; | |
| 252 | + let text = font::SANS_17.ellipsize(shown, field.w - 40); | |
| 253 | + let end = font::SANS_17.draw_top(cv, field.x + 20, field.y + 10, &text, tc); | |
| 254 | + if self.editing { | |
| 255 | + let cx = if self.address.is_empty() { field.x + 20 } else { end + 1 }; | |
| 256 | + cv.fill(Rect::new(cx, field.y + 9, 2, 22), th.accent); | |
| 257 | + } | |
| 258 | + | |
| 259 | + // Status line. | |
| 260 | + cv.fill(Rect::new(0, h - 34, w, 34), th.sidebar); | |
| 261 | + cv.fill(Rect::new(0, h - 34, w, 1), th.sidebar_line); | |
| 262 | + cv.circle(26, h - 17, 5, th.good); | |
| 263 | + font::SANS_15.draw_top(cv, 40, h - 27, &self.status, th.ink2); | |
| 264 | + } | |
| 265 | + | |
| 266 | + fn event(&mut self, ev: &WinEvent, _cx: &mut Ctx) -> bool { | |
| 267 | + let max_scroll = (self.content_h - self.view_h).max(0); | |
| 268 | + match *ev { | |
| 269 | + WinEvent::Press { x, y, button: 0 } => { | |
| 270 | + if y < BAR_H { | |
| 271 | + self.editing = true; | |
| 272 | + return true; | |
| 273 | + } | |
| 274 | + self.editing = false; | |
| 275 | + if let Some(h) = self.hits.iter().find(|h| h.rect.contains(x, y)) { | |
| 276 | + let href = h.href.clone(); | |
| 277 | + self.open(&href); | |
| 278 | + } | |
| 279 | + true | |
| 280 | + } | |
| 281 | + WinEvent::Scroll { dy, .. } => { | |
| 282 | + self.scroll = (self.scroll + dy * 40).clamp(0, max_scroll); | |
| 283 | + true | |
| 284 | + } | |
| 285 | + WinEvent::Key { key, mods } => { | |
| 286 | + if self.editing { | |
| 287 | + match key { | |
| 288 | + Key::Char(c) if !mods.ctrl && !mods.meta => self.address.push(c), | |
| 289 | + Key::Backspace => { | |
| 290 | + self.address.pop(); | |
| 291 | + } | |
| 292 | + Key::Enter => { | |
| 293 | + self.editing = false; | |
| 294 | + let a = self.address.clone(); | |
| 295 | + self.open(&a); | |
| 296 | + } | |
| 297 | + Key::Escape => self.editing = false, | |
| 298 | + _ => return false, | |
| 299 | + } | |
| 300 | + return true; | |
| 301 | + } | |
| 302 | + let step = match key { | |
| 303 | + Key::Down => 40, | |
| 304 | + Key::Up => -40, | |
| 305 | + Key::PageDown | Key::Char(' ') => self.view_h - 60, | |
| 306 | + Key::PageUp => -(self.view_h - 60), | |
| 307 | + Key::Home => -self.scroll, | |
| 308 | + Key::End => max_scroll, | |
| 309 | + Key::Char('l') if mods.ctrl || mods.meta => { | |
| 310 | + self.editing = true; | |
| 311 | + return true; | |
| 312 | + } | |
| 313 | + _ => return false, | |
| 314 | + }; | |
| 315 | + self.scroll = (self.scroll + step).clamp(0, max_scroll); | |
| 316 | + true | |
| 317 | + } | |
| 318 | + _ => false, | |
| 319 | + } | |
| 320 | + } | |
| 321 | + | |
| 322 | + fn wants_ticks(&self) -> bool { | |
| 323 | + false | |
| 324 | + } | |
| 325 | + } |
fixtures/article.html added
| 1 | + <!doctype html> | |
| 2 | + <html lang="en"><head><meta charset="utf-8"><title>Morning on the Harbor</title> | |
| 3 | + <script src="https://www.googletagmanager.com/gtm.js?id=GTM-1"></script> | |
| 4 | + <script>window.dataLayer=[];</script> | |
| 5 | + <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> | |
| 6 | + <style>body{font-family:serif}</style></head> | |
| 7 | + <body> | |
| 8 | + <header><a href="/">The Daily Tide</a><nav><a href="/news">News</a> <a href="/sports">Sports</a></nav></header> | |
| 9 | + <div class="cookie-banner">We value your privacy. Accept all cookies?</div> | |
| 10 | + <main><article> | |
| 11 | + <h1>Morning on the Harbor</h1> | |
| 12 | + <p><em>By the newsroom</em> · December 1</p> | |
| 13 | + <img src="harbor.png" alt="Boats at sunrise" width="900" height="360"> | |
| 14 | + <p>The fishing boats left before dawn, the way they have for <strong>ninety years</strong>. Harbor master Ana Ruiz says the season has been <a href="/stories/season">the best in a decade</a>.</p> | |
| 15 | + <div class="ad-slot"><p>BUY NOW! Limited offer!</p><img src="https://securepubads.g.doubleclick.net/ad.gif"></div> | |
| 16 | + <h2>What changed</h2> | |
| 17 | + <ul><li>Cleaner water after the new filters</li><li>More shade at the docks</li><li>A shorter wait at the fuel pier</li></ul> | |
| 18 | + <blockquote>We don’t rush the morning. The water tells you when to go.</blockquote> | |
| 19 | + <iframe src="https://ads.adnxs.com/ttj?id=1" width="300" height="250"></iframe> | |
| 20 | + <h3>Tide table</h3> | |
| 21 | + <pre>High 06:12 2.1 m | |
| 22 | + Low 12:30 0.4 m</pre> | |
| 23 | + <p>Read more in <a href="https://example.org/tides">the full tide guide</a>.</p> | |
| 24 | + <div id="taboola"><p>You won't believe these 12 boats</p></div> | |
| 25 | + <img src="https://example.com/p.gif" width="1" height="1"> | |
| 26 | + </article></main> | |
| 27 | + <aside>Trending now: 10 celebrity yachts</aside> | |
| 28 | + <footer>© The Daily Tide</footer> | |
| 29 | + </body></html> |
fixtures/harbor.png added
Not a text file.
scripts/build-web.sh added
| 1 | + #!/bin/sh | |
| 2 | + # Web version: WebAssembly + a small page. Needs wasm-bindgen-cli 0.2.130. | |
| 3 | + set -e | |
| 4 | + cd "$(dirname "$0")/.." | |
| 5 | + cargo build -p clearwake --lib --release --target wasm32-unknown-unknown | |
| 6 | + wasm-bindgen target/wasm32-unknown-unknown/release/clearwake.wasm --target web --no-typescript --out-dir web/ | |
| 7 | + echo web/ |
scripts/package-android.sh added
| 1 | + #!/bin/sh | |
| 2 | + # Android APK (arm64, arm, x86-64). Needs ANDROID_HOME with build-tools and | |
| 3 | + # platform 35, ANDROID_NDK_ROOT, and: cargo install cargo-apk. | |
| 4 | + # Release signing: set CARGO_APK_RELEASE_KEYSTORE and CARGO_APK_RELEASE_KEYSTORE_PASSWORD. | |
| 5 | + set -e | |
| 6 | + cd "$(dirname "$0")/../crates/clearwake-app" | |
| 7 | + rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android >/dev/null | |
| 8 | + cargo apk build --release --lib | |
| 9 | + mkdir -p ../../dist | |
| 10 | + cp ../../target/release/apk/Clearwake.apk ../../dist/Clearwake-android.apk | |
| 11 | + echo dist/Clearwake-android.apk |
scripts/package-linux.sh added
| 1 | + #!/bin/sh | |
| 2 | + # Linux x86-64 build that runs on glibc 2.28 and newer (needs: pip install ziglang cargo-zigbuild). | |
| 3 | + set -e | |
| 4 | + cd "$(dirname "$0")/.." | |
| 5 | + cargo zigbuild -p clearwake --release --target x86_64-unknown-linux-gnu.2.28 | |
| 6 | + out=dist/clearwake-linux-x86_64 | |
| 7 | + rm -rf "$out" && mkdir -p "$out" | |
| 8 | + cp target/x86_64-unknown-linux-gnu/release/clearwake "$out/" | |
| 9 | + cp assets/icon-256.png "$out/clearwake.png" | |
| 10 | + cat > "$out/clearwake.desktop" <<DESK | |
| 11 | + [Desktop Entry] | |
| 12 | + Type=Application | |
| 13 | + Name=Clearwake | |
| 14 | + Comment=A quieter browser | |
| 15 | + Exec=clearwake %u | |
| 16 | + Icon=clearwake | |
| 17 | + Categories=Network;WebBrowser; | |
| 18 | + MimeType=x-scheme-handler/http;x-scheme-handler/https;text/html; | |
| 19 | + DESK | |
| 20 | + cat > "$out/install.sh" <<'INST' | |
| 21 | + #!/bin/sh | |
| 22 | + # Installs Clearwake for this user (no root needed). | |
| 23 | + set -e | |
| 24 | + here="$(cd "$(dirname "$0")" && pwd)" | |
| 25 | + mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications" "$HOME/.local/share/icons/hicolor/256x256/apps" | |
| 26 | + cp "$here/clearwake" "$HOME/.local/bin/clearwake" | |
| 27 | + cp "$here/clearwake.png" "$HOME/.local/share/icons/hicolor/256x256/apps/clearwake.png" | |
| 28 | + cp "$here/clearwake.desktop" "$HOME/.local/share/applications/clearwake.desktop" | |
| 29 | + echo "Clearwake is installed. Open it from your apps, or run: clearwake" | |
| 30 | + INST | |
| 31 | + chmod +x "$out/install.sh" "$out/clearwake" | |
| 32 | + tar -C dist -czf dist/Clearwake-linux-x86_64.tar.gz clearwake-linux-x86_64 | |
| 33 | + echo dist/Clearwake-linux-x86_64.tar.gz |
scripts/package-mac.sh added
| 1 | + #!/bin/sh | |
| 2 | + # Mac app (Apple Silicon + Intel), signed with Developer ID and notarized when | |
| 3 | + # SIGN_ID and NOTARY_PROFILE are set. Run on a Mac. | |
| 4 | + set -e | |
| 5 | + cd "$(dirname "$0")/.." | |
| 6 | + rustup target add aarch64-apple-darwin x86_64-apple-darwin >/dev/null | |
| 7 | + MACOSX_DEPLOYMENT_TARGET=11.0 cargo build -p clearwake --release --target aarch64-apple-darwin | |
| 8 | + MACOSX_DEPLOYMENT_TARGET=11.0 cargo build -p clearwake --release --target x86_64-apple-darwin | |
| 9 | + app=dist/Clearwake.app | |
| 10 | + rm -rf "$app" && mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" | |
| 11 | + lipo -create -output "$app/Contents/MacOS/Clearwake" target/aarch64-apple-darwin/release/clearwake target/x86_64-apple-darwin/release/clearwake | |
| 12 | + version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) | |
| 13 | + cat > "$app/Contents/Info.plist" <<PLIST | |
| 14 | + <?xml version="1.0" encoding="UTF-8"?> | |
| 15 | + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| 16 | + <plist version="1.0"><dict> | |
| 17 | + <key>CFBundleName</key><string>Clearwake</string> | |
| 18 | + <key>CFBundleDisplayName</key><string>Clearwake</string> | |
| 19 | + <key>CFBundleIdentifier</key><string>ai.clearwake.Clearwake</string> | |
| 20 | + <key>CFBundleExecutable</key><string>Clearwake</string> | |
| 21 | + <key>CFBundleIconFile</key><string>Clearwake</string> | |
| 22 | + <key>CFBundlePackageType</key><string>APPL</string> | |
| 23 | + <key>CFBundleShortVersionString</key><string>$version</string> | |
| 24 | + <key>CFBundleVersion</key><string>$version</string> | |
| 25 | + <key>LSMinimumSystemVersion</key><string>11.0</string> | |
| 26 | + <key>NSHighResolutionCapable</key><true/> | |
| 27 | + <key>LSApplicationCategoryType</key><string>public.app-category.productivity</string> | |
| 28 | + </dict></plist> | |
| 29 | + PLIST | |
| 30 | + iconset=dist/Clearwake.iconset | |
| 31 | + rm -rf "$iconset" && mkdir -p "$iconset" | |
| 32 | + for s in 16 32 128 256 512; do | |
| 33 | + sips -z $s $s assets/icon-1024.png --out "$iconset/icon_${s}x${s}.png" >/dev/null | |
| 34 | + d=$((s*2)); sips -z $d $d assets/icon-1024.png --out "$iconset/icon_${s}x${s}@2x.png" >/dev/null | |
| 35 | + done | |
| 36 | + iconutil -c icns "$iconset" -o "$app/Contents/Resources/Clearwake.icns" | |
| 37 | + if [ -n "$SIGN_ID" ]; then | |
| 38 | + codesign --force --options runtime --timestamp --sign "$SIGN_ID" "$app" | |
| 39 | + else | |
| 40 | + codesign --force --sign - "$app" | |
| 41 | + fi | |
| 42 | + rm -f dist/Clearwake-mac.zip | |
| 43 | + ditto -c -k --keepParent "$app" dist/Clearwake-mac.zip | |
| 44 | + if [ -n "$SIGN_ID" ] && [ -n "$NOTARY_PROFILE" ]; then | |
| 45 | + xcrun notarytool submit dist/Clearwake-mac.zip --keychain-profile "$NOTARY_PROFILE" --wait | |
| 46 | + xcrun stapler staple "$app" | |
| 47 | + rm -f dist/Clearwake-mac.zip | |
| 48 | + ditto -c -k --keepParent "$app" dist/Clearwake-mac.zip | |
| 49 | + fi | |
| 50 | + echo dist/Clearwake-mac.zip |
scripts/package-windows.sh added
| 1 | + #!/bin/sh | |
| 2 | + # Windows x86-64 build, cross-compiled from Linux (needs mingw-w64). | |
| 3 | + set -e | |
| 4 | + cd "$(dirname "$0")/.." | |
| 5 | + cargo build -p clearwake --release --target x86_64-pc-windows-gnu | |
| 6 | + rm -rf dist/Clearwake-windows && mkdir -p dist/Clearwake-windows | |
| 7 | + cp target/x86_64-pc-windows-gnu/release/clearwake.exe dist/Clearwake-windows/Clearwake.exe | |
| 8 | + (cd dist && rm -f Clearwake-windows-x64.zip && zip -qr Clearwake-windows-x64.zip Clearwake-windows) | |
| 9 | + echo dist/Clearwake-windows-x64.zip |
web/icon.png added
Not a text file.
web/index.html added
| 1 | + <!doctype html> | |
| 2 | + <html lang="en"> | |
| 3 | + <head> | |
| 4 | + <meta charset="utf-8"> | |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | |
| 6 | + <title>Clearwake</title> | |
| 7 | + <meta name="description" content="Clearwake in your browser. Less noise, more web."> | |
| 8 | + <meta name="theme-color" content="#121618"> | |
| 9 | + <link rel="icon" href="icon.png"> | |
| 10 | + <style> | |
| 11 | + html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #faf9f6; } | |
| 12 | + @media (prefers-color-scheme: dark) { html, body { background: #121618; } } | |
| 13 | + canvas#clearwake { position: fixed; inset: 0; width: 100%; height: 100%; display: block; } | |
| 14 | + #loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; | |
| 15 | + font: 17px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: #66706d; } | |
| 16 | + </style> | |
| 17 | + </head> | |
| 18 | + <body> | |
| 19 | + <canvas id="clearwake"></canvas> | |
| 20 | + <div id="loading">Opening Clearwake…</div> | |
| 21 | + <script type="module"> | |
| 22 | + import init from "./clearwake.js"; | |
| 23 | + init().catch((e) => { | |
| 24 | + document.getElementById("loading").textContent = "Clearwake needs a newer browser to run here."; | |
| 25 | + console.error(e); | |
| 26 | + }); | |
| 27 | + </script> | |
| 28 | + </body> | |
| 29 | + </html> |