diff --git a/Cargo.lock b/Cargo.lock index e8154b7e..86878adc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,6 +170,16 @@ dependencies = [ "zbus", ] +[[package]] +name = "assets" +version = "1.0.0" +dependencies = [ + "anyhow", + "gpui", + "log", + "rust-embed", +] + [[package]] name = "async-broadcast" version = "0.7.2" @@ -1073,7 +1083,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "indexmap", "rustc-hash 2.1.1", @@ -1167,6 +1177,7 @@ name = "coop" version = "1.0.0" dependencies = [ "anyhow", + "assets", "auto_update", "client_keys", "common", @@ -1185,7 +1196,6 @@ dependencies = [ "oneshot", "registry", "reqwest_client", - "rust-embed", "rust-i18n", "serde", "serde_json", @@ -1474,7 +1484,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "proc-macro2", "quote", @@ -2326,7 +2336,7 @@ dependencies = [ [[package]] name = "gpui" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "anyhow", "as-raw-xcb-connection", @@ -2419,7 +2429,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -2431,7 +2441,7 @@ dependencies = [ [[package]] name = "gpui_tokio" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "gpui", "tokio", @@ -2441,9 +2451,9 @@ dependencies = [ [[package]] name = "grid" -version = "0.14.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be136d9dacc2a13cc70bb6c8f902b414fb2641f8db1314637c6b7933411a8f82" +checksum = "71b01d27060ad58be4663b9e4ac9e2d4806918e8876af8912afbddd1a91d5eaa" [[package]] name = "h2" @@ -2653,7 +2663,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "anyhow", "bytes", @@ -2671,7 +2681,7 @@ dependencies = [ [[package]] name = "http_client_tls" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "rustls", "rustls-platform-verifier", @@ -3449,7 +3459,7 @@ dependencies = [ [[package]] name = "media" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "anyhow", "bindgen 0.71.1", @@ -3672,7 +3682,7 @@ dependencies = [ [[package]] name = "nostr" version = "0.42.1" -source = "git+https://github.com/rust-nostr/nostr#baeba7bbffe99d2d48a2f79390db089f491b2a86" +source = "git+https://github.com/rust-nostr/nostr#dd8328ded8958c8c1133b293142da94c3e1d6f70" dependencies = [ "aes", "base64", @@ -3695,7 +3705,7 @@ dependencies = [ [[package]] name = "nostr-connect" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#baeba7bbffe99d2d48a2f79390db089f491b2a86" +source = "git+https://github.com/rust-nostr/nostr#dd8328ded8958c8c1133b293142da94c3e1d6f70" dependencies = [ "async-utility", "nostr", @@ -3707,7 +3717,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#baeba7bbffe99d2d48a2f79390db089f491b2a86" +source = "git+https://github.com/rust-nostr/nostr#dd8328ded8958c8c1133b293142da94c3e1d6f70" dependencies = [ "flatbuffers", "lru", @@ -3718,7 +3728,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#baeba7bbffe99d2d48a2f79390db089f491b2a86" +source = "git+https://github.com/rust-nostr/nostr#dd8328ded8958c8c1133b293142da94c3e1d6f70" dependencies = [ "async-utility", "heed", @@ -3731,7 +3741,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#baeba7bbffe99d2d48a2f79390db089f491b2a86" +source = "git+https://github.com/rust-nostr/nostr#dd8328ded8958c8c1133b293142da94c3e1d6f70" dependencies = [ "async-utility", "async-wsocket", @@ -3747,7 +3757,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.42.0" -source = "git+https://github.com/rust-nostr/nostr#baeba7bbffe99d2d48a2f79390db089f491b2a86" +source = "git+https://github.com/rust-nostr/nostr#dd8328ded8958c8c1133b293142da94c3e1d6f70" dependencies = [ "async-utility", "nostr", @@ -4801,7 +4811,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "derive_refineable", "workspace-hack", @@ -4952,7 +4962,7 @@ dependencies = [ [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "anyhow", "bytes", @@ -5478,7 +5488,7 @@ checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749" [[package]] name = "semantic_version" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "anyhow", "serde", @@ -5872,7 +5882,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "arrayvec", "log", @@ -6095,13 +6105,12 @@ dependencies = [ [[package]] name = "taffy" -version = "0.5.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8b61630cba2afd2c851821add2e1bb1b7851a2436e839ab73b56558b009035e" +checksum = "7aaef0ac998e6527d6d0d5582f7e43953bb17221ac75bb8eb2fcc2db3396db1c" dependencies = [ "arrayvec", "grid", - "num-traits", "serde", "slotmap", ] @@ -6846,7 +6855,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#2bc6e18ac913f363e7f75fd12efccc02dc3c05d9" +source = "git+https://github.com/zed-industries/zed#b93e1c736b33615e0b80a8e7fb3a294f40c70862" dependencies = [ "anyhow", "async-fs", diff --git a/assets/fonts/plex-mono/ZedPlexMono-Bold.ttf b/assets/fonts/plex-mono/ZedPlexMono-Bold.ttf new file mode 100644 index 00000000..d5f4b5e2 Binary files /dev/null and b/assets/fonts/plex-mono/ZedPlexMono-Bold.ttf differ diff --git a/assets/fonts/plex-mono/ZedPlexMono-BoldItalic.ttf b/assets/fonts/plex-mono/ZedPlexMono-BoldItalic.ttf new file mode 100644 index 00000000..05eaf7cc Binary files /dev/null and b/assets/fonts/plex-mono/ZedPlexMono-BoldItalic.ttf differ diff --git a/assets/fonts/plex-mono/ZedPlexMono-Italic.ttf b/assets/fonts/plex-mono/ZedPlexMono-Italic.ttf new file mode 100644 index 00000000..3b078217 Binary files /dev/null and b/assets/fonts/plex-mono/ZedPlexMono-Italic.ttf differ diff --git a/assets/fonts/plex-mono/ZedPlexMono-Regular.ttf b/assets/fonts/plex-mono/ZedPlexMono-Regular.ttf new file mode 100644 index 00000000..61dbb583 Binary files /dev/null and b/assets/fonts/plex-mono/ZedPlexMono-Regular.ttf differ diff --git a/assets/fonts/plex-mono/license.txt b/assets/fonts/plex-mono/license.txt new file mode 100644 index 00000000..f72f7650 --- /dev/null +++ b/assets/fonts/plex-mono/license.txt @@ -0,0 +1,92 @@ +Copyright © 2017 IBM Corp. with Reserved Font Name "Plex" + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/assets/fonts/plex-sans/ZedPlexSans-Bold.ttf b/assets/fonts/plex-sans/ZedPlexSans-Bold.ttf new file mode 100644 index 00000000..f1e66392 Binary files /dev/null and b/assets/fonts/plex-sans/ZedPlexSans-Bold.ttf differ diff --git a/assets/fonts/plex-sans/ZedPlexSans-BoldItalic.ttf b/assets/fonts/plex-sans/ZedPlexSans-BoldItalic.ttf new file mode 100644 index 00000000..7612dc51 Binary files /dev/null and b/assets/fonts/plex-sans/ZedPlexSans-BoldItalic.ttf differ diff --git a/assets/fonts/plex-sans/ZedPlexSans-Italic.ttf b/assets/fonts/plex-sans/ZedPlexSans-Italic.ttf new file mode 100644 index 00000000..8769c232 Binary files /dev/null and b/assets/fonts/plex-sans/ZedPlexSans-Italic.ttf differ diff --git a/assets/fonts/plex-sans/ZedPlexSans-Regular.ttf b/assets/fonts/plex-sans/ZedPlexSans-Regular.ttf new file mode 100644 index 00000000..3ea293d5 Binary files /dev/null and b/assets/fonts/plex-sans/ZedPlexSans-Regular.ttf differ diff --git a/assets/fonts/plex-sans/ZedPlexSans-SemiBold.ttf b/assets/fonts/plex-sans/ZedPlexSans-SemiBold.ttf new file mode 100644 index 00000000..aba7b0c3 Binary files /dev/null and b/assets/fonts/plex-sans/ZedPlexSans-SemiBold.ttf differ diff --git a/assets/fonts/plex-sans/ZedPlexSans-SemiBoldItalic.ttf b/assets/fonts/plex-sans/ZedPlexSans-SemiBoldItalic.ttf new file mode 100644 index 00000000..560de369 Binary files /dev/null and b/assets/fonts/plex-sans/ZedPlexSans-SemiBoldItalic.ttf differ diff --git a/assets/fonts/plex-sans/license.txt b/assets/fonts/plex-sans/license.txt new file mode 100644 index 00000000..f72f7650 --- /dev/null +++ b/assets/fonts/plex-sans/license.txt @@ -0,0 +1,92 @@ +Copyright © 2017 IBM Corp. with Reserved Font Name "Plex" + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/crates/assets/Cargo.toml b/crates/assets/Cargo.toml new file mode 100644 index 00000000..3e3d11fd --- /dev/null +++ b/crates/assets/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "assets" +version.workspace = true +edition.workspace = true +publish.workspace = true + +[dependencies] +gpui.workspace = true +anyhow.workspace = true +log.workspace = true +rust-embed.workspace = true diff --git a/crates/assets/src/lib.rs b/crates/assets/src/lib.rs new file mode 100644 index 00000000..2de81bcf --- /dev/null +++ b/crates/assets/src/lib.rs @@ -0,0 +1,59 @@ +use anyhow::Context; +use gpui::{App, AssetSource, Result, SharedString}; +use rust_embed::RustEmbed; + +#[derive(RustEmbed)] +#[folder = "../../assets"] +#[include = "fonts/**/*"] +#[include = "brand/*"] +#[include = "icons/**/*"] +#[exclude = "*.DS_Store"] +pub struct Assets; + +impl AssetSource for Assets { + fn load(&self, path: &str) -> Result>> { + Self::get(path) + .map(|f| Some(f.data)) + .with_context(|| format!("loading asset at path {path:?}")) + } + + fn list(&self, path: &str) -> Result> { + Ok(Self::iter() + .filter_map(|p| { + if p.starts_with(path) { + Some(p.into()) + } else { + None + } + }) + .collect()) + } +} + +impl Assets { + /// Populate the [`TextSystem`] of the given [`AppContext`] with all `.ttf` fonts in the `fonts` directory. + pub fn load_fonts(&self, cx: &App) -> anyhow::Result<()> { + let font_paths = self.list("fonts")?; + let mut embedded_fonts = Vec::new(); + for font_path in font_paths { + if font_path.ends_with(".ttf") { + let font_bytes = cx + .asset_source() + .load(&font_path)? + .expect("Assets should never return None"); + embedded_fonts.push(font_bytes); + } + } + + cx.text_system().add_fonts(embedded_fonts) + } + + pub fn load_test_fonts(&self, cx: &App) { + cx.text_system() + .add_fonts(vec![self + .load("fonts/plex-mono/ZedPlexMono-Regular.ttf") + .unwrap() + .unwrap()]) + .unwrap() + } +} diff --git a/crates/coop/Cargo.toml b/crates/coop/Cargo.toml index f13359a3..efa3bcd7 100644 --- a/crates/coop/Cargo.toml +++ b/crates/coop/Cargo.toml @@ -9,6 +9,7 @@ name = "coop" path = "src/main.rs" [dependencies] +assets = { path = "../assets" } ui = { path = "../ui" } identity = { path = "../identity" } theme = { path = "../theme" } @@ -34,7 +35,6 @@ serde.workspace = true serde_json.workspace = true itertools.workspace = true dirs.workspace = true -rust-embed.workspace = true log.workspace = true smallvec.workspace = true smol.workspace = true diff --git a/crates/coop/src/asset.rs b/crates/coop/src/asset.rs deleted file mode 100644 index e949d327..00000000 --- a/crates/coop/src/asset.rs +++ /dev/null @@ -1,27 +0,0 @@ -use anyhow::anyhow; -use gpui::{AssetSource, Result, SharedString}; -use rust_embed::RustEmbed; - -#[derive(RustEmbed)] -#[folder = "../../assets"] -pub struct Assets; - -impl AssetSource for Assets { - fn load(&self, path: &str) -> Result>> { - Self::get(path) - .map(|f| Some(f.data)) - .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path)) - } - - fn list(&self, path: &str) -> Result> { - Ok(Self::iter() - .filter_map(|p| { - if p.starts_with(path) { - Some(p.into()) - } else { - None - } - }) - .collect()) - } -} diff --git a/crates/coop/src/main.rs b/crates/coop/src/main.rs index 963b8770..9204ef1b 100644 --- a/crates/coop/src/main.rs +++ b/crates/coop/src/main.rs @@ -1,9 +1,9 @@ use std::collections::BTreeSet; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use std::time::Duration; use anyhow::{anyhow, Error}; -use asset::Assets; +use assets::Assets; use auto_update::AutoUpdater; #[cfg(not(target_os = "linux"))] use global::constants::APP_NAME; @@ -27,7 +27,6 @@ use smol::channel::{self, Sender}; use theme::Theme; use ui::Root; -pub(crate) mod asset; pub(crate) mod chatspace; pub(crate) mod views; @@ -183,6 +182,9 @@ fn main() { // Run application app.run(move |cx| { + // Load embedded fonts in assets/fonts + load_embedded_fonts(cx); + // Register the `quit` function cx.on_action(quit); @@ -318,6 +320,30 @@ fn main() { }); } +fn load_embedded_fonts(cx: &App) { + let asset_source = cx.asset_source(); + let font_paths = asset_source.list("fonts").unwrap(); + let embedded_fonts = Mutex::new(Vec::new()); + let executor = cx.background_executor(); + + executor.block(executor.scoped(|scope| { + for font_path in &font_paths { + if !font_path.ends_with(".ttf") { + continue; + } + + scope.spawn(async { + let font_bytes = asset_source.load(font_path).unwrap().unwrap(); + embedded_fonts.lock().unwrap().push(font_bytes); + }); + } + })); + + cx.text_system() + .add_fonts(embedded_fonts.into_inner().unwrap()) + .unwrap(); +} + fn quit(_: &Quit, cx: &mut App) { log::info!("Gracefully quitting the application . . ."); cx.quit(); diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index 7bf8b84e..7e6ab403 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -390,13 +390,7 @@ impl From for Theme { Theme { font_size: px(15.), - font_family: if cfg!(target_os = "macos") { - ".SystemUIFont".into() - } else if cfg!(target_os = "windows") { - "Segoe UI".into() - } else { - "FreeMono".into() - }, + font_family: ".SystemUIFont".into(), radius: px(5.), mode, colors, diff --git a/crates/ui/src/root.rs b/crates/ui/src/root.rs index bfecd60b..3d57d07d 100644 --- a/crates/ui/src/root.rs +++ b/crates/ui/src/root.rs @@ -256,6 +256,7 @@ impl Root { impl Render for Root { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { let base_font_size = cx.theme().font_size; + let font_family = cx.theme().font_family.clone(); window.set_rem_size(base_font_size); window_border().child( @@ -263,7 +264,7 @@ impl Render for Root { .id("root") .relative() .size_full() - .font_family(".SystemUIFont") + .font_family(font_family) .bg(cx.theme().background) .text_color(cx.theme().text) .child(self.view.clone()),