Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 38 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

# As `rustfmt.toml` writes it.
[*.rs]
indent_size = 4
max_line_length = 110

[*.{toml,sql,py}]
indent_size = 4

# Two spaces at the end of a line break it.
[*.md]
trim_trailing_whitespace = false

# Compared byte for byte, or kept as published.
[{golden,crates/engine/tests/corpus,crates/engine/sandbox/dist,crates/text/prettier,docs/recette}/**]
charset = unset
end_of_line = unset
indent_size = unset
indent_style = unset
insert_final_newline = unset
trim_trailing_whitespace = unset

[.claude/skills/{accessibility,core-web-vitals,frontend-design,rust-guidelines,seo,webapp-testing}/**]
charset = unset
end_of_line = unset
indent_size = unset
indent_style = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
6 changes: 2 additions & 4 deletions crates/app/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ mod windows {
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}
let manifest_dir =
env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set by cargo");
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set by cargo");
let manifest_dir = Path::new(&manifest_dir);
let name = product_name(manifest_dir);
let icon = manifest_dir.join("icons/icon.ico");
Expand All @@ -34,8 +33,7 @@ mod windows {
/// The name the packages give the application, `[package.metadata.packager] product-name`;
/// the version is the workspace's, which `winresource` reads from Cargo itself.
fn product_name(manifest_dir: &Path) -> String {
let text =
fs::read_to_string(manifest_dir.join("Cargo.toml")).expect("Cargo.toml is readable");
let text = fs::read_to_string(manifest_dir.join("Cargo.toml")).expect("Cargo.toml is readable");
let manifest: toml::Table = toml::from_str(&text).expect("Cargo.toml is valid TOML");
manifest
.get("package")
Expand Down
26 changes: 5 additions & 21 deletions crates/app/examples/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ fn main() {
let icons = Path::new(env!("CARGO_MANIFEST_DIR")).join("icons");
let master = icons.join("devnotes.svg");
for (name, size) in PNGS {
let source = if HINTED.contains(&size) {
hinted(&icons, size)
} else {
master.clone()
};
let source = if HINTED.contains(&size) { hinted(&icons, size) } else { master.clone() };
write(&icons.join(name), &render(&source, size));
}
let entries: Vec<(u32, Vec<u8>)> = HINTED
Expand All @@ -38,21 +34,13 @@ fn hinted(icons: &Path, size: u32) -> PathBuf {

/// The drawing at `size` × `size` px, as a PNG.
fn render(source: &Path, size: u32) -> Vec<u8> {
let data =
std::fs::read(source).unwrap_or_else(|error| panic!("{}: {error}", source.display()));
let data = std::fs::read(source).unwrap_or_else(|error| panic!("{}: {error}", source.display()));
let tree = usvg::Tree::from_data(&data, &usvg::Options::default())
.unwrap_or_else(|error| panic!("{}: {error}", source.display()));
let mut pixmap = tiny_skia::Pixmap::new(size, size).expect("a non-empty size");
#[allow(
clippy::cast_precision_loss,
reason = "an icon is a few hundred pixels wide"
)]
#[allow(clippy::cast_precision_loss, reason = "an icon is a few hundred pixels wide")]
let scale = size as f32 / tree.size().width().max(tree.size().height());
resvg::render(
&tree,
tiny_skia::Transform::from_scale(scale, scale),
&mut pixmap.as_mut(),
);
resvg::render(&tree, tiny_skia::Transform::from_scale(scale, scale), &mut pixmap.as_mut());
pixmap.encode_png().expect("a PNG of a pixmap")
}

Expand All @@ -70,11 +58,7 @@ fn ico(entries: &[(u32, Vec<u8>)]) -> Vec<u8> {
header.extend_from_slice(&[side, side, 0, 0]);
header.extend_from_slice(&1u16.to_le_bytes());
header.extend_from_slice(&32u16.to_le_bytes());
header.extend_from_slice(
&u32::try_from(data.len())
.expect("a small PNG")
.to_le_bytes(),
);
header.extend_from_slice(&u32::try_from(data.len()).expect("a small PNG").to_le_bytes());
header.extend_from_slice(&u32::try_from(offset).expect("a small file").to_le_bytes());
offset += data.len();
}
Expand Down
17 changes: 3 additions & 14 deletions crates/app/examples/tours.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ const TOURS: [(&str, &[&str]); 3] = [
),
(
"http",
&[
"http-home",
"http-request",
"http-graphql",
"http-websocket",
"http-environments",
"http-code",
],
&["http-home", "http-request", "http-graphql", "http-websocket", "http-environments", "http-code"],
),
];

Expand Down Expand Up @@ -99,14 +92,10 @@ fn write(path: &Path, frames: &[RgbaImage]) {
for frame in frames {
let mut reduced = frame.clone();
for pixel in reduced.pixels_mut() {
*pixel = *nearest
.entry(*pixel)
.or_insert_with(|| closest(&palette, *pixel));
*pixel = *nearest.entry(*pixel).or_insert_with(|| closest(&palette, *pixel));
}
let delay = Delay::from_saturating_duration(SHOWN);
encoder
.encode_frame(Frame::from_parts(reduced, 0, 0, delay))
.expect("a frame");
encoder.encode_frame(Frame::from_parts(reduced, 0, 0, delay)).expect("a frame");
}
}

Expand Down
26 changes: 4 additions & 22 deletions crates/app/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ mod tests {

#[test]
fn a_profile_directory_is_read_after_its_flag() {
assert_eq!(
of(&["--profile", "/tmp/run-1"]).profile,
Some(PathBuf::from("/tmp/run-1"))
);
assert_eq!(of(&["--profile", "/tmp/run-1"]).profile, Some(PathBuf::from("/tmp/run-1")));
}

#[test]
Expand All @@ -50,32 +47,17 @@ mod tests {

#[test]
fn an_action_is_read_after_its_flag() {
assert_eq!(
of(&["--action", "palette"]).action,
Some("palette".to_string())
);
assert_eq!(of(&["--action", "palette"]).action, Some("palette".to_string()));
}

#[test]
fn an_unknown_argument_is_left_alone() {
assert_eq!(
of(&["--minimized", "--profile", "p"]).profile,
Some(PathBuf::from("p"))
);
assert_eq!(of(&["--minimized", "--profile", "p"]).profile, Some(PathBuf::from("p")));
}

#[test]
fn both_are_read_in_any_order_and_the_last_of_each_wins() {
let read = of(&[
"--action",
"quit",
"--profile",
"a",
"--profile",
"b",
"--action",
"palette",
]);
let read = of(&["--action", "quit", "--profile", "a", "--profile", "b", "--action", "palette"]);

assert_eq!(read.profile, Some(PathBuf::from("b")));
assert_eq!(read.action.as_deref(), Some("palette"));
Expand Down
16 changes: 4 additions & 12 deletions crates/app/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,11 @@ fn start_tray(preferences: &Preferences, inbox: Inbox) -> Box<dyn Tray> {
let Ok(icon) = eframe::icon_data::from_png_bytes(include_bytes!("../icons/32x32.png")) else {
return Box::new(NoTray);
};
let picture = Picture {
rgba: icon.rgba,
width: icon.width,
height: icon.height,
};
let picture = Picture { rgba: icon.rgba, width: icon.width, height: icon.height };
let language = Settings::read(preferences).locale.language();
platform::tray::system(
picture,
&ui::services::tray::labels(language),
move |asked| {
inbox.post(ui::inputs::Input::Tray(asked));
},
)
platform::tray::system(picture, &ui::services::tray::labels(language), move |asked| {
inbox.post(ui::inputs::Input::Tray(asked));
})
}

/// Named in the language of the launch where a Wayland desktop lists them.
Expand Down
46 changes: 10 additions & 36 deletions crates/app/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ pub(crate) fn start(directory: &Path) -> Option<LoggerHandle> {
logger
.log_to_file(file)
.append()
.rotate(
Criterion::Size(5_000_000),
Naming::Numbers,
Cleanup::KeepLogFiles(3),
)
.rotate(Criterion::Size(5_000_000), Naming::Numbers, Cleanup::KeepLogFiles(3))
.duplicate_to_stderr(Duplicate::Error)
.start()
})
Expand Down Expand Up @@ -74,11 +70,7 @@ fn notice(language: i18n::Language, logs: &Path) -> (String, String) {
let app = || Value::from(engine::app_info::METADATA.name.to_owned());
let title = i18n::translate(language, keys::crash::TITLE, &[("app", app())]);
let folder = Value::from(logs.display().to_string());
let words = i18n::translate(
language,
keys::crash::BODY,
&[("app", app()), ("folder", folder)],
);
let words = i18n::translate(language, keys::crash::BODY, &[("app", app()), ("folder", folder)]);
(title, words)
}

Expand All @@ -87,12 +79,7 @@ fn report(info: &PanicHookInfo<'_>) -> String {
let thread = std::thread::current();
let name = thread.name().unwrap_or("unnamed");
match info.location() {
Some(at) => format!(
"Panicked at {}:{}:{} on thread {name}",
at.file(),
at.line(),
at.column()
),
Some(at) => format!("Panicked at {}:{}:{} on thread {name}", at.file(), at.line(), at.column()),
None => format!("Panicked on thread {name}"),
}
}
Expand Down Expand Up @@ -182,9 +169,7 @@ mod tests {
logger();
let profile = tempfile::tempdir().unwrap();
let runtime = tokio::runtime::Runtime::new().unwrap();
let paths = engine::Paths {
profile: profile.path().to_path_buf(),
};
let paths = engine::Paths { profile: profile.path().to_path_buf() };
let sink = Arc::new(engine::RecordingSink::default());
let closed = engine::Engine::new(paths, sink, runtime.handle().clone());
let patch = NotePatch {
Expand All @@ -193,9 +178,8 @@ mod tests {
..Default::default()
};

let failed = engine::db::run_here(&closed, |engine| {
engine::notes::update_note(engine, "note-id", &patch)
});
let failed =
engine::db::run_here(&closed, |engine| engine::notes::update_note(engine, "note-id", &patch));
ui::services::errors::ErrorNotifier::default()
.report(i18n::keys::errors::NOTE_GONE, &failed.unwrap_err());

Expand All @@ -210,14 +194,10 @@ mod tests {
logger();
let profile = tempfile::tempdir().unwrap();
let runtime = tokio::runtime::Runtime::new().unwrap();
let paths = engine::Paths {
profile: profile.path().to_path_buf(),
};
let paths = engine::Paths { profile: profile.path().to_path_buf() };
let sink = Arc::new(engine::RecordingSink::default());
let engine = engine::Engine::new(paths, sink, runtime.handle().clone());
let draft = || engine::spaces::model::SpaceDraft {
name: "Clients Dupont-Aignan".to_owned(),
};
let draft = || engine::spaces::model::SpaceDraft { name: "Clients Dupont-Aignan".to_owned() };
let duplicate = engine::db::run_here(&engine, |engine| {
let phrase = engine::vault::secret("correct horse battery staple".to_owned());
engine::vault::create_vault(engine, phrase)?;
Expand Down Expand Up @@ -275,10 +255,7 @@ mod tests {
assert!(title.contains(engine::app_info::METADATA.name), "{title}");
assert!(words.contains("C:/profil/logs"), "{words}");
assert_ne!(words, english);
assert!(
!words.contains("{{") && !english.contains("{{"),
"{words} {english}"
);
assert!(!words.contains("{{") && !english.contains("{{"), "{words} {english}");
}

/// Where the process that panics for the test below writes its log.
Expand All @@ -295,10 +272,7 @@ mod tests {
let directory = tempfile::tempdir().unwrap();

let ended = std::process::Command::new(std::env::current_exe().unwrap())
.args([
"--exact",
"logging::tests::a_panic_ends_the_process_once_its_place_is_in_the_log",
])
.args(["--exact", "logging::tests::a_panic_ends_the_process_once_its_place_is_in_the_log"])
.env(PANIC_IN, directory.path())
.output()
.unwrap();
Expand Down
Loading
Loading