Tahinli/forge
public0 watching
★ 0
| 1 | //! The colour theme for a request. A signed-in user's stored preference wins. Anonymous |
| 2 | //! visitors use the `forge_theme` cookie, which the footer form sets. `auto`, or no choice at |
| 3 | //! all, renders no `data-theme`, so the stylesheet follows the operating system. |
| 4 | |
| 5 | use Duration; |
| 6 | |
| 7 | use User; |
| 8 | use Cx; |
| 9 | use ; |
| 10 | |
| 11 | /// Name of the anonymous theme cookie. |
| 12 | pub const THEME_COOKIE: &str = "forge_theme"; |
| 13 | |
| 14 | /// Lifetime of the anonymous theme cookie. |
| 15 | pub const THEME_COOKIE_TTL: Duration = from_secs; |
| 16 | |
| 17 | /// The stored colour preference for this request: `"auto"`, `"light"` or `"dark"`. A signed-in |
| 18 | /// user's stored preference wins. Anonymous visitors use the cookie. Anything else reads as |
| 19 | /// `"auto"`. |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | /// The `data-theme` value for this request: `Some("light")` or `Some("dark")`, or `None` when the |
| 36 | /// page should follow the operating system. |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | /// The preference the top-bar button switches to from `current`: auto, then light, then dark, |
| 45 | /// then back to auto. |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | /// Sets the anonymous theme cookie. The caller has already checked that `theme` is valid. |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 |