edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! The notice queue, and the toasts it draws (DESIGN §8). |
| 2 | |
| 3 | use crate::*; |
| 4 | use Cell; |
| 5 | use VecDeque; |
| 6 | use Deref; |
| 7 | use PathBuf; |
| 8 | |
| 9 | /// `n` of a thing in words: "1 silence", "2 silences". One door, so no |
| 10 | /// message ships a "(s)" or a "1 silences". |
| 11 | pub |
| 12 | |
| 13 | |
| 14 | |
| 15 | /// How many messages wait in the queue before the oldest is dropped. A queue |
| 16 | /// with no ceiling is a way for a stuck loop to eat the heap; eight is more than |
| 17 | /// a user will ever answer in a row. Only the newest is drawn, in the status bar, |
| 18 | /// and a new message replaces it, so in practice the queue holds one line plus |
| 19 | /// any questions still waiting for an answer. |
| 20 | pub const NOTICES_MAX: usize = 8; |
| 21 | |
| 22 | /// How long an info or warn toast stays before it hides itself (DESIGN §8). |
| 23 | /// Errors have no such timer: they name a remedy and wait for a ✕. |
| 24 | pub const TOAST_HIDE: Duration = from_secs; |
| 25 | |
| 26 | /// How many buttons one toast can carry. Two is what an export's outcome needs |
| 27 | /// (Play, and Show in folder); a third would crowd the message off the bar. |
| 28 | pub const TOAST_ACTIONS_MAX: usize = 2; |
| 29 | |
| 30 | /// How loud a toast is. The tone picks the stripe colour and whether the toast |
| 31 | /// times out at all. |
| 32 | |
| 33 | pub |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | /// What a toast's button does. The action is the toast's own: the button acts on |
| 77 | /// the thing the message is about, and the toast goes with the click. |
| 78 | |
| 79 | pub |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | /// One notice on screen or waiting behind the ones on screen. `Deref`s to its |
| 108 | /// text, so a reader that only wants the words reads them as it always did. |
| 109 | |
| 110 | pub |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | /// The whole of the queue's policy, where it can be read at once and tested |
| 167 | /// without a window: dedupe against the back, a ceiling, oldest out first. |
| 168 | /// [`Player::notify_user`] is the door every message comes through; this is |
| 169 | /// what the door does for a message with no action. |
| 170 | pub |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | /// [`push_notice`] with its buttons attached, for the door that takes them. |
| 176 | pub |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | /// [`push_toast`] for a question that stays on screen until it is answered |
| 186 | /// ([`Toast::sticky`]). |
| 187 | pub |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | /// The toast the status bar draws: the newest sticky one (a question still |
| 229 | /// waiting for its answer), else the newest notice of all. |
| 230 | pub |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | /// Takes one toast out of the queue by id. `true` when there was one to take. |
| 239 | /// Every way a toast leaves -- its timer, its ✕, its action -- comes through |
| 240 | /// here, and matching on the id is what keeps a late timer from taking a newer |
| 241 | /// toast with the same words. |
| 242 | pub |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | /// The tail an open/load notice grows when the file has sound the engine cannot |
| 249 | /// decode: it plays perfectly, in silence, and that is the one thing the window |
| 250 | /// would otherwise never say (the engine's own word for it, verbatim). |
| 251 | pub |
| 252 | |
| 253 | |
| 254 | |
| 255 | /// [`audio_notice`]'s own tail, for a reason already read -- the one place the |
| 256 | /// engine's word is spelled into a line, so the open path and the mid-session |
| 257 | /// one cannot drift apart. |
| 258 | pub |
| 259 | |
| 260 | |
| 261 | |
| 262 | /// The same fact said on its own, for a device that dies *after* a file was |
| 263 | /// opened: [`audio_notice`] is a tail to append to "OPENED x", and a death |
| 264 | /// mid-session has no line to hang off -- so it leads with the state word the |
| 265 | /// strip reads first, and the tail is the same one. |
| 266 | pub |
| 267 | |
| 268 | |
| 269 | |
| 270 | /// A decode failure that arrives *after* a file was opened, said on its own |
| 271 | /// line: the same shape as [`audio_lost_line`] and for the same reason -- a |
| 272 | /// death mid-session has no open line to hang a tail off, so it leads with the |
| 273 | /// state word the strip reads first. |
| 274 | /// |
| 275 | /// The picture twin of the sound line above, and it exists because a decode |
| 276 | /// failure used to reach nobody at all: the worker printed it to stderr and |
| 277 | /// dropped the channel, and a closed channel is what a finished film looks like |
| 278 | /// from the app's side. A file with a damaged middle froze on its last good |
| 279 | /// picture and the transport said ENDED. The reason is the engine's own words, |
| 280 | /// verbatim -- the app spells none of them. |
| 281 | pub |
| 282 | |
| 283 | |
| 284 | |
| 285 | /// What a frame of a reason watch decides, as a pure value: the cache's own |
| 286 | /// session generation against the frame's says whether the two are even talking |
| 287 | /// about the same session, and only then what the reason did. |
| 288 | /// |
| 289 | /// One type for every reason the engine states, not one per source: the sound |
| 290 | /// device and the decode worker both write a string the app has to notice |
| 291 | /// changed, and the thing that decides is the same comparison in both cases. |
| 292 | |
| 293 | pub |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | /// [`Player::watch_audio`]'s and [`Player::watch_decode`]'s whole decision, |
| 307 | /// pure: `cached_gen` is the session |
| 308 | /// generation the cache describes, `session_gen` the one the frame is serving, and |
| 309 | /// two reasons are what the engine says the sound is (`None` for sound that is |
| 310 | /// up). |
| 311 | /// |
| 312 | /// The generation is what keeps another session's reason out of this session's |
| 313 | /// cache: `pump` serves the preview while one is up and the timeline otherwise, |
| 314 | /// so a flip reads a reason that was never about the cached session at all -- a |
| 315 | /// live device on one side and a dead one on the other is not a change, it is |
| 316 | /// two different questions. |
| 317 | pub |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | /// What a *change* in the engine's sound reason does to the notice queue, as a |
| 335 | /// pure step: the line pushed when a reason arrives, the same line taken back |
| 336 | /// when the reason clears. [`Player::watch_audio`] is the only caller and owns |
| 337 | /// the caching; this owns the queue, so a test can drive both directions without |
| 338 | /// a window and without a device that dies on cue. |
| 339 | /// |
| 340 | /// The reason is the engine's to write, and the engine's writer is the wave |
| 341 | /// branch's: `tick`'s dead branch sets the lost-device reason and `rearm_audio` |
| 342 | /// clears it (its own test observes both). This side is the reader and never |
| 343 | /// spells the engine's words, so the end-to-end flip is asserted on the merged |
| 344 | /// tree while this lane drives the same step through the seam below -- on this |
| 345 | /// lane's base engine no path flips the reason at all. |
| 346 | pub |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | /// What a *change* in the engine's **decode** reason does to the notice queue: |
| 374 | /// the line pushed when a reason arrives, the same line taken back when the |
| 375 | /// reason clears. [`audio_change_notice`]'s twin, step for step, because the |
| 376 | /// thing that changed is the same kind of thing -- a reason the engine started |
| 377 | /// or stopped stating between two frames. |
| 378 | /// |
| 379 | /// The retraction is what keeps this from becoming noise: a decode that fails, |
| 380 | /// is seeked away from and succeeds has to take its line back, or the strip |
| 381 | /// keeps saying DECODE FAILED over a film that plays. |
| 382 | pub |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | /// A toast's line is one line: what a too-long line must never do is lose its |
| 405 | /// *state* word, which sits at the front, or stop mid-word with nothing saying |
| 406 | /// it stopped (user report, `OPENED he_is_not_the_only_one.mp4 — 1 subtitle |
| 407 | /// track(s) in `). Every message is a handful of words plus a file name, so the |
| 408 | /// one part long enough to overflow alone is the name -- elided through its |
| 409 | /// middle here, head and tail kept, before gpui's own end ellipsis |
| 410 | /// ([`crate::ui::stance`]) ever has to cut a word. |
| 411 | pub const LEDGER_WORD_MAX: usize = 28; |
| 412 | |
| 413 | pub |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 |