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. The default is light: a |
| 3 | //! visitor with no explicit choice gets light whatever their operating system uses. Only an |
| 4 | //! explicit `auto` renders no `data-theme`, so the stylesheet follows the operating system. |
| 5 | |
| 6 | use Duration; |
| 7 | |
| 8 | use User; |
| 9 | use Cx; |
| 10 | use ; |
| 11 | |
| 12 | /// Name of the anonymous theme cookie. |
| 13 | pub const THEME_COOKIE: &str = "forge_theme"; |
| 14 | |
| 15 | /// Lifetime of the anonymous theme cookie. |
| 16 | pub const THEME_COOKIE_TTL: Duration = from_secs; |
| 17 | |
| 18 | /// The stored colour preference for this request: `"auto"`, `"light"` or `"dark"`. A signed-in |
| 19 | /// user's stored preference wins. Anonymous visitors use the cookie. A missing, empty or |
| 20 | /// unknown value reads as `"light"`, the default. Only an explicit `"auto"` follows the system. |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | /// Maps a stored value to a preference. Only `"auto"` and `"dark"` are kept as they are. Every |
| 33 | /// other value, including the empty string, means the default, `"light"`. |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | /// The `data-theme` value for this request: `Some("light")` or `Some("dark")`, or `None` when the |
| 43 | /// page should follow the operating system. |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | /// The preference the top-bar button switches to from `current`: light, then dark, then auto, |
| 52 | /// then back to light. Anything that is not `"light"` or `"dark"` (including `"auto"`) moves on |
| 53 | /// to light, the first step of the cycle. |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | /// Sets the anonymous theme cookie. The caller has already checked that `theme` is valid. |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 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 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 |