diff --git a/editor/build.rs b/editor/build.rs new file mode 100644 index 00000000..69da33b9 --- /dev/null +++ b/editor/build.rs @@ -0,0 +1,22 @@ +use std::process::Command; + +const GRAPHITE_RELEASE_SERIES: &str = "Alpha Milestone 1"; + +fn main() { + // Execute a Git command for its stdout. Early exit if it fails for any of the possible reasons. + let try_git_command = |args: &[&str]| -> Option { + let git_output = Command::new("git").args(args).output().ok()?; + let maybe_empty = String::from_utf8(git_output.stdout).ok()?; + let command_result = (!maybe_empty.is_empty()).then(|| maybe_empty)?; + Some(command_result) + }; + // Execute a Git command for its output. Return "unknown" if it fails for any of the possible reasons. + let git_command = |args| -> String { try_git_command(args).unwrap_or_else(|| String::from("unknown")) }; + + // Rather than printing to any terminal, these commands set environment variables in the Cargo toolchain. + // They are accessed with the `env!("...")` macro in the codebase. + println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={}", git_command(&["log", "-1", "--format=%cd"])); + println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={}", git_command(&["rev-parse", "HEAD"])); + println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={}", git_command(&["rev-parse", "--abbrev-ref", "HEAD"])); + println!("cargo:rustc-env=GRAPHITE_RELEASE_SERIES={}", GRAPHITE_RELEASE_SERIES); +} diff --git a/editor/src/communication/build_metadata.rs b/editor/src/communication/build_metadata.rs deleted file mode 100644 index da79a84e..00000000 --- a/editor/src/communication/build_metadata.rs +++ /dev/null @@ -1,45 +0,0 @@ -use serde::{Deserialize, Serialize}; - -/// Provides metadata about the build environment. -/// -/// This data is viewable in the editor via the [`crate::dialog::AboutGraphite`] dialog. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct BuildMetadata { - pub release: String, - pub timestamp: String, - pub hash: String, - pub branch: String, -} - -impl Default for BuildMetadata { - fn default() -> Self { - Self { - release: "unknown".to_string(), - timestamp: "unknown".to_string(), - hash: "unknown".to_string(), - branch: "unknown".to_string(), - } - } -} - -impl BuildMetadata { - pub fn release_series(&self) -> String { - format!("Release Series: {}", self.release) - } - - pub fn commit_info(&self) -> String { - format!("{}\n{}\n{}", self.commit_timestamp(), self.commit_hash(), self.commit_branch()) - } - - pub fn commit_timestamp(&self) -> String { - format!("Date: {}", self.timestamp) - } - - pub fn commit_hash(&self) -> String { - format!("Hash: {}", self.hash) - } - - pub fn commit_branch(&self) -> String { - format!("Branch: {}", self.branch) - } -} diff --git a/editor/src/communication/dispatcher.rs b/editor/src/communication/dispatcher.rs index e2f2af12..9ab383bb 100644 --- a/editor/src/communication/dispatcher.rs +++ b/editor/src/communication/dispatcher.rs @@ -8,14 +8,11 @@ use crate::workspace::WorkspaceMessageHandler; use std::collections::VecDeque; -use super::BuildMetadata; - #[derive(Debug, Default)] pub struct Dispatcher { message_queue: VecDeque, pub responses: Vec, message_handlers: DispatcherMessageHandlers, - build_metadata: BuildMetadata, } #[remain::sorted] @@ -75,7 +72,7 @@ impl Dispatcher { Dialog(message) => { self.message_handlers .dialog_message_handler - .process_action(message, (&self.build_metadata, &self.message_handlers.portfolio_message_handler), &mut self.message_queue); + .process_action(message, &self.message_handlers.portfolio_message_handler, &mut self.message_queue); } Frontend(message) => { // Image and font loading should be immediately handled @@ -120,9 +117,6 @@ impl Dispatcher { .workspace_message_handler .process_action(message, &self.message_handlers.input_preprocessor_message_handler, &mut self.message_queue); } - - #[remain::unsorted] - PopulateBuildMetadata { new } => self.build_metadata = new, } } } diff --git a/editor/src/communication/message.rs b/editor/src/communication/message.rs index 7be45c44..4c6eaa89 100644 --- a/editor/src/communication/message.rs +++ b/editor/src/communication/message.rs @@ -1,4 +1,3 @@ -use super::BuildMetadata; use crate::message_prelude::*; use graphite_proc_macros::*; @@ -41,9 +40,6 @@ pub enum Message { Tool(ToolMessage), #[child] Workspace(WorkspaceMessage), - - #[remain::unsorted] - PopulateBuildMetadata { new: BuildMetadata }, } impl Message { diff --git a/editor/src/communication/mod.rs b/editor/src/communication/mod.rs index 0633cff9..6392653b 100644 --- a/editor/src/communication/mod.rs +++ b/editor/src/communication/mod.rs @@ -1,11 +1,9 @@ -mod build_metadata; pub mod dispatcher; pub mod message; pub mod message_handler; pub use crate::communication::dispatcher::*; pub use crate::input::InputPreprocessorMessageHandler; -pub use build_metadata::BuildMetadata; use rand_chacha::rand_core::{RngCore, SeedableRng}; use rand_chacha::ChaCha20Rng; diff --git a/editor/src/dialog/dialog_message.rs b/editor/src/dialog/dialog_message.rs index 6d2d2fa0..7066854d 100644 --- a/editor/src/dialog/dialog_message.rs +++ b/editor/src/dialog/dialog_message.rs @@ -7,14 +7,15 @@ use super::{ExportDialogUpdate, NewDocumentDialogUpdate}; #[impl_message(Message, Dialog)] #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub enum DialogMessage { + // Sub-messages #[remain::unsorted] #[child] ExportDialog(ExportDialogUpdate), - #[remain::unsorted] #[child] NewDocumentDialog(NewDocumentDialogUpdate), + // Messages CloseAllDocumentsWithConfirmation, CloseDialogAndThen { followup: Box, @@ -24,6 +25,9 @@ pub enum DialogMessage { description: String, }, RequestAboutGraphiteDialog, + RequestAboutGraphiteDialogWithLocalizedCommitDate { + localized_commit_date: String, + }, RequestComingSoonDialog { issue: Option, }, diff --git a/editor/src/dialog/dialog_message_handler.rs b/editor/src/dialog/dialog_message_handler.rs index a6699acf..f3b13e41 100644 --- a/editor/src/dialog/dialog_message_handler.rs +++ b/editor/src/dialog/dialog_message_handler.rs @@ -1,4 +1,3 @@ -use crate::communication::BuildMetadata; use crate::document::PortfolioMessageHandler; use crate::layout::{layout_message::LayoutTarget, widgets::PropertyHolder}; use crate::message_prelude::*; @@ -11,9 +10,9 @@ pub struct DialogMessageHandler { new_document_dialog: NewDocument, } -impl MessageHandler for DialogMessageHandler { +impl MessageHandler for DialogMessageHandler { #[remain::check] - fn process_action(&mut self, message: DialogMessage, (build_metadata, portfolio): (&BuildMetadata, &PortfolioMessageHandler), responses: &mut VecDeque) { + fn process_action(&mut self, message: DialogMessage, portfolio: &PortfolioMessageHandler, responses: &mut VecDeque) { #[remain::sorted] match message { #[remain::unsorted] @@ -36,9 +35,16 @@ impl MessageHandler f responses.push_back(FrontendMessage::DisplayDialog { icon: "Warning".to_string() }.into()); } DialogMessage::RequestAboutGraphiteDialog => { - let about_graphite = AboutGraphite { - build_metadata: build_metadata.clone(), - }; + responses.push_back( + FrontendMessage::TriggerAboutGraphiteLocalizedCommitDate { + commit_date: env!("GRAPHITE_GIT_COMMIT_DATE").into(), + } + .into(), + ); + } + DialogMessage::RequestAboutGraphiteDialogWithLocalizedCommitDate { localized_commit_date } => { + let about_graphite = AboutGraphite { localized_commit_date }; + about_graphite.register_properties(responses, LayoutTarget::DialogDetails); responses.push_back(FrontendMessage::DisplayDialog { icon: "GraphiteLogo".to_string() }.into()); } diff --git a/editor/src/dialog/dialogs/about_dialog.rs b/editor/src/dialog/dialogs/about_dialog.rs index 71c93a37..61ad6489 100644 --- a/editor/src/dialog/dialogs/about_dialog.rs +++ b/editor/src/dialog/dialogs/about_dialog.rs @@ -1,8 +1,10 @@ -use crate::{communication::BuildMetadata, layout::widgets::*, message_prelude::FrontendMessage}; +use crate::layout::widgets::*; +use crate::message_prelude::FrontendMessage; +use crate::misc::build_metadata::{commit_info_localized, release_series}; -/// A dialog for displaying information on [`BuildMetadata`] viewable via `help -> about graphite` in the menu bar. +/// A dialog for displaying information on [`BuildMetadata`] viewable via *Help* > *About Graphite* in the menu bar. pub struct AboutGraphite { - pub build_metadata: BuildMetadata, + pub localized_commit_date: String, } impl PropertyHolder for AboutGraphite { @@ -33,13 +35,13 @@ impl PropertyHolder for AboutGraphite { }, LayoutRow::Row { widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel { - value: self.build_metadata.release_series(), + value: release_series(), ..Default::default() }))], }, LayoutRow::Row { widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel { - value: self.build_metadata.commit_info(), + value: commit_info_localized(self.localized_commit_date.as_str()), multiline: true, ..Default::default() }))], diff --git a/editor/src/frontend/frontend_message.rs b/editor/src/frontend/frontend_message.rs index 39630467..bc2139ad 100644 --- a/editor/src/frontend/frontend_message.rs +++ b/editor/src/frontend/frontend_message.rs @@ -20,6 +20,7 @@ pub enum FrontendMessage { DisplayRemoveEditableTextbox, // Trigger prefix: cause a browser API to do something + TriggerAboutGraphiteLocalizedCommitDate { commit_date: String }, TriggerFileDownload { document: String, name: String }, TriggerFileUpload, TriggerFontLoad { font_file_url: String }, diff --git a/editor/src/misc/build_metadata.rs b/editor/src/misc/build_metadata.rs new file mode 100644 index 00000000..2a3c4a50 --- /dev/null +++ b/editor/src/misc/build_metadata.rs @@ -0,0 +1,31 @@ +/// Provides metadata about the build environment. +/// +/// This data is viewable in the editor via the [`crate::dialog::AboutGraphite`] dialog. + +pub fn release_series() -> String { + format!("Release Series: {}", env!("GRAPHITE_RELEASE_SERIES")) +} + +pub fn commit_info() -> String { + format!("{}\n{}\n{}", commit_timestamp(), commit_hash(), commit_branch()) +} + +pub fn commit_info_localized(localized_commit_date: &str) -> String { + format!("{}\n{}\n{}", commit_timestamp_localized(localized_commit_date), commit_hash(), commit_branch()) +} + +pub fn commit_timestamp() -> String { + format!("Date: {}", env!("GRAPHITE_GIT_COMMIT_DATE")) +} + +pub fn commit_timestamp_localized(localized_commit_date: &str) -> String { + format!("Date: {}", localized_commit_date) +} + +pub fn commit_hash() -> String { + format!("Hash: {}", &env!("GRAPHITE_GIT_COMMIT_HASH")[..8]) +} + +pub fn commit_branch() -> String { + format!("Branch: {}", env!("GRAPHITE_GIT_COMMIT_BRANCH")) +} diff --git a/editor/src/misc/mod.rs b/editor/src/misc/mod.rs index bc412fe4..c2a13994 100644 --- a/editor/src/misc/mod.rs +++ b/editor/src/misc/mod.rs @@ -1,11 +1,12 @@ #[macro_use] pub mod macros; - +pub mod build_metadata; pub mod derivable_custom_traits; pub mod hints; pub mod test_utils; + +mod error; + pub use error::EditorError; pub use hints::*; pub use macros::*; - -mod error; diff --git a/frontend/src/App.vue b/frontend/src/App.vue index f92cd141..6f8bdaf6 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -258,10 +258,10 @@ img {