Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ e2e = ["eframe/inspection", "platform/e2e", "ui/e2e"]
profiling = ["dep:profiling", "dep:puffin", "dep:puffin_http", "profiling/profile-with-puffin"]

[dependencies]
brand.workspace = true
engine.workspace = true
platform.workspace = true
ui.workspace = true
Expand Down
7 changes: 2 additions & 5 deletions crates/app/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ use platform::tray::{NoTray, Picture, Tray};
use platform::updater::{Source, Updater};
use ui::{Inbox, Input, Preferences, Settings};

/// Who sends a toast on Windows.
const IDENTIFIER: &str = "com.devnotes.app";

/// The address and the key the published versions already use (D26).
const UPDATES: Source<'_> = Source {
version: env!("CARGO_PKG_VERSION"),
endpoint: "https://github.com/vmillet-dev/devnotes-rs/releases/latest/download/latest.json",
endpoint: concat!(env!("CARGO_PKG_REPOSITORY"), "/releases/latest/download/latest.json"),
public_key: "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEZBMjJGNDA1RkVGMEEzNkYKUldSdm8vRCtCZlFpK3IzSFdQSFZ0YlM3VTh5eXNpVDhueWp2SzNPYyt6VmVHQVJ6eWs1ZDBzeE4K",
};

Expand All @@ -29,7 +26,7 @@ pub(crate) fn start(preferences: &Preferences, inbox: &Inbox) -> ui::Desktop {
tray: start_tray(preferences, inbox.clone()),
shortcuts: take_shortcuts(preferences, inbox.clone()),
autostart: autostart(),
notifier: platform::notify::system(METADATA.name, IDENTIFIER),
notifier: platform::notify::system(METADATA.name, brand::IDENTIFIER),
dialog: dialog(inbox.clone()),
updater: updater(),
clipboard: platform::clipboard::system(),
Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn start_as(directory: &Path, build: Build) -> Option<LoggerHandle> {
};
let file = FileSpec::default()
.directory(directory)
.basename("devnotes")
.basename(brand::SLUG)
.suppress_timestamp();
let handle = FileLogWriter::builder(file)
.append()
Expand All @@ -98,7 +98,7 @@ fn start_as(directory: &Path, build: Build) -> Option<LoggerHandle> {
.format_for_stderr(line)
.start()
})
.inspect_err(|error| eprintln!("devnotes: no log file: {error}"))
.inspect_err(|error| eprintln!("{}: no log file: {error}", brand::SLUG))
.ok()?;
if unreadable {
log::warn!("{LEVELS} is no log specification: the levels of the build apply");
Expand Down
8 changes: 4 additions & 4 deletions crates/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() -> ExitCode {
.map(Locations::inside)
.or_else(|| Locations::installed(paths::DEFAULT_PROFILE))
else {
eprintln!("devnotes: the system names no directory for the profile");
eprintln!("{}: the system names no directory for the profile", brand::SLUG);
return ExitCode::FAILURE;
};
// Before the log: a second launch writes nothing of its own.
Expand All @@ -55,7 +55,7 @@ fn main() -> ExitCode {
Ok(Claim::Taken) => return hand_over(&locations.profile, arguments.action),
Err(error) => {
// Fails closed: a second writer would make the index silently wrong.
eprintln!("devnotes: the profile could not be claimed: {error}");
eprintln!("{}: the profile could not be claimed: {error}", brand::SLUG);
return ExitCode::FAILURE;
}
};
Expand Down Expand Up @@ -116,7 +116,7 @@ fn hand_over(profile: &Path, action: Option<String>) -> ExitCode {
match instance::send(profile, &message) {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
eprintln!("devnotes: the running instance did not answer: {error}");
eprintln!("{}: the running instance did not answer: {error}", brand::SLUG);
ExitCode::FAILURE
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ fn profiler() -> Option<puffin_http::Server> {
fn options(restored: Option<Geometry>) -> eframe::NativeOptions {
let viewport = egui::ViewportBuilder::default()
.with_title(METADATA.name)
.with_app_id("devnotes")
.with_app_id(brand::SLUG)
.with_inner_size([1_100.0, 720.0])
.with_min_inner_size([640.0, 480.0])
.with_visible(false);
Expand Down
13 changes: 10 additions & 3 deletions crates/brand/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! The only reader of `[workspace.metadata]` in the root `Cargo.toml` (D36): Cargo hands no
//! metadata to a crate, so the values are read here and handed over as environment variables.
//! metadata to a crate, so the values are read here and written as macros that expand to them.

use std::fmt::Write as _;
use std::path::Path;

const MANIFEST: &str = "../../Cargo.toml";
Expand Down Expand Up @@ -36,13 +37,19 @@ fn main() {
.and_then(|workspace| workspace.get("metadata"))
.expect("the root manifest has [workspace.metadata]");

let mut macros = String::new();
for (key, holds) in VALUES {
let value = values
.get(key)
.and_then(toml::Value::as_str)
.unwrap_or_else(|| panic!("[workspace.metadata] {key} is a string"));
assert!(holds(value), "[workspace.metadata] {key} = {value:?} cannot be used");
let name = key.to_uppercase().replace('-', "_");
println!("cargo::rustc-env=BRAND_{name}={value}");
let name = key.replace('-', "_");
let _ = writeln!(
macros,
"#[macro_export]\nmacro_rules! {name} {{\n () => {{\n {value:?}\n }};\n}}"
);
}
let out = std::env::var("OUT_DIR").expect("cargo sets OUT_DIR");
std::fs::write(Path::new(&out).join("values.rs"), macros).expect("values.rs is written");
}
17 changes: 11 additions & 6 deletions crates/brand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
//! The application's names, written once in the root `Cargo.toml`'s `[workspace.metadata]` and
//! read here alone (D36). Every name in the code, on the disk and in the packages is one of these,
//! or made from one.
//!
//! Each is also a macro that expands to its literal (`brand::slug!()`), for a constant another
//! crate builds with `concat!`: `concat!(brand::slug!(), ".sqlite3")`.

include!(concat!(env!("OUT_DIR"), "/values.rs"));

/// What a person is shown: the window, the menus, the request header.
pub const NAME: &str = env!("BRAND_DISPLAY_NAME");
pub const NAME: &str = display_name!();

/// The author's handle, on the about card.
pub const AUTHOR_HANDLE: &str = env!("BRAND_AUTHOR_HANDLE");
pub const AUTHOR_HANDLE: &str = author_handle!();

/// The technical name: the binary, the library's file, the preference keys, the system's names.
pub const SLUG: &str = env!("BRAND_SLUG");
pub const SLUG: &str = slug!();

/// The profile's folder, and the packages' bundle identifier.
pub const IDENTIFIER: &str = env!("BRAND_IDENTIFIER");
pub const IDENTIFIER: &str = identifier!();

/// The extension of an exported library, without its dot.
pub const EXTENSION: &str = env!("BRAND_FILE_EXTENSION");
pub const EXTENSION: &str = file_extension!();

/// The website, without a trailing slash.
pub const SITE: &str = env!("BRAND_SITE");
pub const SITE: &str = site!();
2 changes: 1 addition & 1 deletion crates/engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum StorageError {
ImportFormat(String),
#[error("Note \"{id}\" unreadable: field \"{field}\" is out of format")]
CorruptRow { id: String, field: &'static str },
#[error("Database carrying migration \"{0}\", unknown to this version of DevNotes")]
#[error("Database carrying migration \"{0}\", unknown to this version")]
SchemaTooRecent(String),
#[error("Migration failed: {0}")]
Migration(String),
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/http/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ mod tests {
vec![
header("Authorization", &format!("Bearer {MASK}")),
header("Content-Type", "application/json; charset=utf-8"),
header("User-Agent", "DevNotes/1.3.0"),
header("User-Agent", concat!(brand::display_name!(), "/1.3.0")),
header("Accept", "*/*"),
header("X-Trace", "1"),
],
Expand Down
9 changes: 6 additions & 3 deletions crates/engine/src/http/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ use super::{variables, websocket};
use crate::notes::language::Language;

/// What a request says it comes from when it says nothing: many APIs refuse one that is silent.
pub const USER_AGENT: &str = concat!("DevNotes/", env!("CARGO_PKG_VERSION"));
pub const USER_AGENT: &str = concat!(brand::display_name!(), "/", env!("CARGO_PKG_VERSION"));
const ACCEPT_ANYTHING: &str = "*/*";

/// Whether a header that left is one the application writes by itself, whatever its version:
/// what is rebuilt from the history leaves it out, and it is written again when sent.
pub fn is_default(name: &str, value: &str) -> bool {
(name.eq_ignore_ascii_case("user-agent") && value.starts_with("DevNotes/"))
(name.eq_ignore_ascii_case("user-agent") && value.starts_with(concat!(brand::display_name!(), "/")))
|| (name.eq_ignore_ascii_case("accept") && value == ACCEPT_ANYTHING)
}

Expand Down Expand Up @@ -1392,7 +1392,10 @@ mod tests {
);
assert_eq!(value(&silenced, "User-Agent"), None);
assert_eq!(value(&silenced_above, "User-Agent"), None);
assert!(is_default("user-agent", "DevNotes/0.1.0") && is_default("Accept", "*/*"));
assert!(
is_default("user-agent", concat!(brand::display_name!(), "/0.1.0"))
&& is_default("Accept", "*/*")
);
assert!(!is_default("User-Agent", "curl/8") && !is_default("Accept", "text/html"));
}

Expand Down
14 changes: 8 additions & 6 deletions crates/engine/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chrono::{DateTime, NaiveDateTime, Utc};
/// Spelled once, so the sidecars below cannot drift from it.
macro_rules! database {
() => {
"devnotes.sqlite3"
concat!(brand::slug!(), ".sqlite3")
};
}

Expand Down Expand Up @@ -70,14 +70,16 @@ pub(crate) fn parse_stamp(name: &str) -> Option<DateTime<Utc>> {
mod tests {
use super::*;

/// ⚠️ Each name is where an installed copy looks: spelled out here, a rename fails a test
/// before it sends anyone's application looking for files under a new name.
/// ⚠️ Each name is where an installed copy looks: spelled out here, a change other than of
/// the slug (D36) fails a test before it sends anyone's application looking for new files.
#[test]
fn every_name_on_disk_is_spelled_as_installed_copies_wrote_it() {
let database = format!("{}.sqlite3", brand::SLUG);
assert_eq!(
[DATABASE, DATABASE_SIDECARS[0], DATABASE_SIDECARS[1]],
[database.clone(), format!("{database}-wal"), format!("{database}-shm")]
);
let names = [
(DATABASE, "devnotes.sqlite3"),
(DATABASE_SIDECARS[0], "devnotes.sqlite3-wal"),
(DATABASE_SIDECARS[1], "devnotes.sqlite3-shm"),
(KEY_FILE, "vault.json"),
(ATTACHMENTS, "attachments"),
(BACKUPS, "backups"),
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/transfer/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn read_bundle(json: &str) -> Result<IncomingBundle, StorageError> {

if version > u64::from(FORMAT_VERSION) {
return Err(StorageError::ImportFormat(format!(
"format version {version}, this version of DevNotes reads up to {FORMAT_VERSION}"
"format version {version}, this version reads up to {FORMAT_VERSION}"
)));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/transfer/protect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ pub fn seal_with(passphrase: &str) -> Result<(Vault, Recipe), StorageError> {
pub fn open_with(passphrase: &str, recipe: &Recipe) -> Result<Vault, StorageError> {
if recipe.version > FORMAT_VERSION {
return Err(StorageError::ImportFormat(format!(
"protected with format version {}, this version of DevNotes reads up to {FORMAT_VERSION}",
"protected with format version {}, this version reads up to {FORMAT_VERSION}",
recipe.version
)));
}
if recipe.algorithm != "argon2id" {
return Err(StorageError::ImportFormat(format!(
"protected with \"{}\", which this version of DevNotes cannot reproduce",
"protected with \"{}\", which this version cannot reproduce",
recipe.algorithm
)));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/vault/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ pub fn unlock(directory: &Path, passphrase: &str) -> Result<Vault, StorageError>

if file.version > FORMAT_VERSION {
return Err(StorageError::Vault(format!(
"key file version {}, this version of DevNotes reads up to {FORMAT_VERSION}",
"key file version {}, this version reads up to {FORMAT_VERSION}",
file.version
)));
}
if file.kdf.algorithm != "argon2id" {
return Err(StorageError::Vault(format!(
"key derived with \"{}\", which this version of DevNotes cannot reproduce",
"key derived with \"{}\", which this version cannot reproduce",
file.kdf.algorithm
)));
}
Expand Down
3 changes: 1 addition & 2 deletions crates/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
"source": "TypeScript / Prettier"
},
"tags": {
"devnotes": "devnotes",
"example": "example",
"database": "sql",
"json": "json",
Expand Down Expand Up @@ -1151,7 +1150,7 @@
"reset": "Reset",
"globalNote": "These three work everywhere, window closed included, so each needs at least one modifier — without one the key would be swallowed in every application you use. A combination another application already holds is reported under its field, and cannot be typed there: Windows hands it to that application.",
"globalPortalNote": "Under Wayland, these three are handed to the desktop, which asked you to accept them in its own window: it may have changed one, and shows them in its shortcut settings. They work everywhere, window closed included.",
"globalDesktopNote": "Under Wayland, these three are written into GNOME’s custom shortcuts (Settings, Keyboard), each running “devnotes --action …”: they work everywhere, window closed included, and stay there if the application is uninstalled.",
"globalDesktopNote": "Under Wayland, these three are written into GNOME’s custom shortcuts (Settings, Keyboard), each running “{{binary}} --action …”: they work everywhere, window closed included, and stay there if the application is uninstalled.",
"globalNobodyNote": "Under Wayland, this desktop lets no application listen to the keyboard outside its windows, and offers no way to hand them over: bind these commands yourself in its shortcut settings. A second launch hands the action to the running one.",
"canvasNote": "These only act on the canvas, never while typing, so a bare letter is enough. Click the field, then press the combination.",
"areasNote": "This one acts in the three areas — Notes, Tools and HTTP — and, with Ctrl or Alt, while typing too.",
Expand Down
3 changes: 1 addition & 2 deletions crates/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
"source": "TypeScript / Prettier"
},
"tags": {
"devnotes": "devnotes",
"example": "exemple",
"database": "sql",
"json": "json",
Expand Down Expand Up @@ -1151,7 +1150,7 @@
"reset": "Rétablir",
"globalNote": "Ces trois-là agissent partout, fenêtre fermée comprise : ils demandent donc au moins un modificateur, sans quoi la touche serait avalée dans toutes vos applications. Une combinaison qu’une autre application tient déjà est signalée sous son champ, et ne peut pas y être saisie : Windows la lui remet.",
"globalPortalNote": "Sous Wayland, ces trois-là sont confiés au bureau, qui vous a demandé de les accepter dans sa propre fenêtre : il peut en avoir changé un, et les montre dans ses réglages de raccourcis. Ils agissent partout, fenêtre fermée comprise.",
"globalDesktopNote": "Sous Wayland, ces trois-là sont écrits dans les raccourcis personnalisés de GNOME (Paramètres, Clavier), chacun lançant « devnotes --action … » : ils agissent partout, fenêtre fermée comprise, et y restent si l’application est désinstallée.",
"globalDesktopNote": "Sous Wayland, ces trois-là sont écrits dans les raccourcis personnalisés de GNOME (Paramètres, Clavier), chacun lançant « {{binary}} --action … » : ils agissent partout, fenêtre fermée comprise, et y restent si l’application est désinstallée.",
"globalNobodyNote": "Sous Wayland, ce bureau ne laisse aucune application écouter le clavier hors de ses fenêtres, et n’offre pas de quoi les lui confier : liez vous-même ces commandes dans ses réglages de raccourcis. Une seconde instance remet l’action à celle qui tourne.",
"canvasNote": "Ceux-ci n’agissent que sur le canevas, jamais pendant une saisie : une lettre nue suffit. Cliquez dans le champ puis composez la combinaison.",
"areasNote": "Celui-ci agit dans les trois zones — Notes, Outils et HTTP — et, avec Ctrl ou Alt, pendant une saisie aussi.",
Expand Down
1 change: 1 addition & 0 deletions crates/platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ publish = false
e2e = []

[dependencies]
brand.workspace = true
arboard.workspace = true
dirs.workspace = true
interprocess.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/platform/src/autostart/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use auto_launch::{AutoLaunch, AutoLaunchBuilder};

use super::{Autostart, NoAutostart};

const ENTRY: &str = "devnotes";
const ENTRY: &str = brand::SLUG;

struct System(AutoLaunch);

Expand Down
2 changes: 1 addition & 1 deletion crates/platform/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn socket_name(profile: &Path) -> io::Result<String> {
let _ = write!(hex, "{byte:02x}");
hex
});
Ok(format!("devnotes-{hex}"))
Ok(format!("{}-{hex}", brand::SLUG))
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions crates/platform/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use std::path::PathBuf;

/// The installed profile, named after the packages' identifier (`[package.metadata.packager]`).
/// Until 1.0.0 it was `com.devnotes.app.dev`, kept apart from the Angular application (D16).
pub const DEFAULT_PROFILE: &str = "com.devnotes.app";
/// The installed profile, named after the packages' identifier (D36). Until 1.0.0 it was the
/// identifier with `.dev`, kept apart from the Angular application (D16).
pub const DEFAULT_PROFILE: &str = brand::IDENTIFIER;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Locations {
Expand Down
2 changes: 1 addition & 1 deletion crates/platform/src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn command(global: Global) -> String {
let executable = std::env::var_os("APPIMAGE")
.map(std::path::PathBuf::from)
.or_else(|| std::env::current_exe().ok())
.map_or_else(|| "devnotes".to_owned(), |path| path.display().to_string());
.map_or_else(|| brand::SLUG.to_owned(), |path| path.display().to_string());
format!("{} --action {}", shell_quoted(&executable), global.name())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/platform/src/shortcuts/system/gnome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const LIST: &str = "org.gnome.settings-daemon.plugins.media-keys";
const ENTRY: &str = "org.gnome.settings-daemon.plugins.media-keys.custom-keybinding";
const BASE: &str = "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/";
/// Ours, among the person's: rewritten or removed with the preference, theirs left alone.
const OURS: &str = "devnotes-";
const OURS: &str = concat!(brand::slug!(), "-");

/// A GNOME session whose settings take custom shortcuts.
pub(super) fn offered() -> bool {
Expand Down Expand Up @@ -44,7 +44,7 @@ pub(super) fn bind(wanted: &[(Global, String)], described: &[(Global, String)])
.iter()
.find(|(named, _)| *named == global)
.map_or(global.name(), |(_, words)| words.as_str());
let name = format!("DevNotes — {words}");
let name = format!("{} — {words}", brand::NAME);
gsettings(&["set", &entry, "name", &notation::gvariant(&name)])?;
let command = super::super::command(global);
gsettings(&["set", &entry, "command", &notation::gvariant(&command)])?;
Expand Down
Loading