feat(settings): support editor system fonts
This commit is contained in:
1 parent
d6e98c5d67
commit
895c0d58af
15 files changed
+947
-638
No files matched your search
@@ -17,6 +17,7 @@ pub mod saved_sql;
|
||||
pub mod schema;
|
||||
pub mod schema_cache;
|
||||
pub mod sql_file;
|
||||
pub mod system_fonts;
|
||||
pub mod table_import;
|
||||
pub mod transfer;
|
||||
pub mod update;
|
||||
@@ -0,0 +1,36 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use font_kit::source::SystemSource;
|
||||
|
||||
pub fn normalize_font_families(families: Vec<String>) -> Vec<String> {
|
||||
families
|
||||
.into_iter()
|
||||
.map(|family| family.trim().to_string())
|
||||
.filter(|family| !family.is_empty())
|
||||
.collect::<BTreeSet<_>>()
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn list_system_fonts() -> Result<Vec<String>, String> {
|
||||
SystemSource::new().all_families().map(normalize_font_families).map_err(|err| err.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::normalize_font_families;
|
||||
|
||||
#[test]
|
||||
fn normalizes_and_sorts_font_family_names() {
|
||||
assert_eq!(
|
||||
normalize_font_families(vec![
|
||||
"Maple Mono NF CN".to_string(),
|
||||
" ".to_string(),
|
||||
"Arial".to_string(),
|
||||
"Maple Mono NF CN".to_string(),
|
||||
]),
|
||||
vec!["Arial".to_string(), "Maple Mono NF CN".to_string()],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -278,6 +278,7 @@ pub fn run() {
|
||||
commands::agents::invalidate_agent_registry_cache,
|
||||
commands::agents::import_agents_from_zip,
|
||||
commands::agents::import_agent_jar_cmd,
|
||||
commands::system_fonts::list_system_fonts,
|
||||
])
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
|
||||
Reference in new issue
Block a user