| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#![forbid(unsafe_code)] |
| 43 |
|
| 44 |
pub mod drift; |
| 45 |
|
| 46 |
use std::path::Path; |
| 47 |
|
| 48 |
pub use drift::{ |
| 49 |
check_breakpoints, check_breakpoints_files, check_touch_density, check_vocabulary, |
| 50 |
check_vocabulary_files, check_vocabulary_use, |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
pub use makeover_webview::Emit; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
pub fn themes(dir: impl AsRef<Path>) { |
| 70 |
let dir = dir.as_ref(); |
| 71 |
std::fs::create_dir_all(dir).expect("create themes dir"); |
| 72 |
|
| 73 |
for entry in std::fs::read_dir(dir).expect("read themes dir").flatten() { |
| 74 |
let path = entry.path(); |
| 75 |
if path.extension().is_some_and(|e| e == "toml") { |
| 76 |
std::fs::remove_file(&path).expect("remove stale theme"); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
for (id, source) in makeover::embedded_themes() { |
| 81 |
std::fs::write(dir.join(format!("{id}.toml")), source).expect("write theme"); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
pub fn layout_css(path: impl AsRef<Path>, opts: &makeover_webview::Emit) { |
| 96 |
std::fs::write(path, makeover_webview::stylesheet(opts)).expect("write layout css"); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
pub fn geometry_css(path: impl AsRef<Path>, explicit_touch: Option<&str>) { |
| 120 |
let mut css = String::from( |
| 121 |
"/* Generated by makeover-build from makeover-geometry. Do not edit.\n \ |
| 122 |
Spacing is named by relationship, not by size. Touch density is a\n \ |
| 123 |
capability question: a narrow desktop window still has a pointer, a\n \ |
| 124 |
full-width tablet still has a finger. Window width is the separate\n \ |
| 125 |
question below it: on a compact window the two shells tighten. */\n", |
| 126 |
); |
| 127 |
css.push_str(&makeover_geometry::density_css(explicit_touch)); |
| 128 |
css.push('\n'); |
| 129 |
css.push_str(&makeover_geometry::size_class_css()); |
| 130 |
std::fs::write(path, css).expect("write geometry css"); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
pub fn tauri_frontend( |
| 144 |
manifest_dir: impl AsRef<Path>, |
| 145 |
opts: &makeover_webview::Emit, |
| 146 |
explicit_touch: Option<&str>, |
| 147 |
) { |
| 148 |
let root = manifest_dir.as_ref(); |
| 149 |
let css = root.join("frontend").join("css"); |
| 150 |
themes(root.join("themes")); |
| 151 |
geometry_css(css.join("geometry.css"), explicit_touch); |
| 152 |
layout_css(css.join("layout.css"), opts); |
| 153 |
} |
| 154 |
|
| 155 |
#[cfg(test)] |
| 156 |
mod tests { |
| 157 |
use super::*; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
fn scratch(name: &str) -> std::path::PathBuf { |
| 163 |
let dir = |
| 164 |
std::env::temp_dir().join(format!("makeover-build-{}-{name}", std::process::id())); |
| 165 |
let _ = std::fs::remove_dir_all(&dir); |
| 166 |
std::fs::create_dir_all(&dir).expect("create scratch"); |
| 167 |
dir |
| 168 |
} |
| 169 |
|
| 170 |
#[test] |
| 171 |
fn themes_are_written_one_file_per_id() { |
| 172 |
let dir = scratch("themes"); |
| 173 |
themes(&dir); |
| 174 |
let count = std::fs::read_dir(&dir).unwrap().count(); |
| 175 |
assert_eq!(count, makeover::embedded_themes().count()); |
| 176 |
assert!(count > 0, "makeover ships no themes?"); |
| 177 |
} |
| 178 |
|
| 179 |
#[test] |
| 180 |
fn a_theme_removed_upstream_does_not_linger() { |
| 181 |
|
| 182 |
let dir = scratch("stale"); |
| 183 |
std::fs::write(dir.join("gone-upstream.toml"), "# stale").unwrap(); |
| 184 |
themes(&dir); |
| 185 |
assert!(!dir.join("gone-upstream.toml").exists()); |
| 186 |
} |
| 187 |
|
| 188 |
#[test] |
| 189 |
fn a_non_theme_file_is_left_alone() { |
| 190 |
|
| 191 |
|
| 192 |
let dir = scratch("keep"); |
| 193 |
std::fs::write(dir.join("README.md"), "not a theme").unwrap(); |
| 194 |
themes(&dir); |
| 195 |
assert!(dir.join("README.md").exists()); |
| 196 |
} |
| 197 |
|
| 198 |
#[test] |
| 199 |
fn the_stylesheet_lands_and_names_no_colour() { |
| 200 |
let dir = scratch("css"); |
| 201 |
let path = dir.join("layout.css"); |
| 202 |
layout_css(&path, &makeover_webview::Emit::default()); |
| 203 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 204 |
assert!(css.contains("--bevel-raised")); |
| 205 |
assert!( |
| 206 |
!css.contains('#'), |
| 207 |
"a colour literal reached a build output" |
| 208 |
); |
| 209 |
} |
| 210 |
|
| 211 |
#[test] |
| 212 |
fn the_geometry_file_carries_the_crates_policy_and_a_banner() { |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
let dir = scratch("geometry"); |
| 217 |
let path = dir.join("geometry.css"); |
| 218 |
geometry_css(&path, Some(".ui-mode-mobile")); |
| 219 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 220 |
assert!(css.starts_with("/* Generated by makeover-build")); |
| 221 |
assert!(css.contains("@media (hover: none), (pointer: coarse)")); |
| 222 |
assert!(css.contains(".ui-mode-mobile")); |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
assert!(css.contains("--gap-pane"), "no compact shell override"); |
| 227 |
let compact = css |
| 228 |
.split("@media (max-width") |
| 229 |
.nth(1) |
| 230 |
.expect("compact block"); |
| 231 |
assert!( |
| 232 |
!compact.contains("--gap-peer"), |
| 233 |
"a control gap crept into a width query" |
| 234 |
); |
| 235 |
} |
| 236 |
|
| 237 |
#[test] |
| 238 |
fn the_tauri_layout_puts_all_three_where_the_apps_look() { |
| 239 |
let root = scratch("tauri"); |
| 240 |
std::fs::create_dir_all(root.join("frontend").join("css")).unwrap(); |
| 241 |
tauri_frontend(&root, &makeover_webview::Emit::default(), None); |
| 242 |
assert!( |
| 243 |
root.join("frontend") |
| 244 |
.join("css") |
| 245 |
.join("geometry.css") |
| 246 |
.exists() |
| 247 |
); |
| 248 |
assert!( |
| 249 |
root.join("frontend") |
| 250 |
.join("css") |
| 251 |
.join("layout.css") |
| 252 |
.exists() |
| 253 |
); |
| 254 |
assert!(root.join("themes").is_dir()); |
| 255 |
} |
| 256 |
} |
| 257 |
|