Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: prevent editor saves before the project finishes loading
Richie McIlroybc9a4bd44e5c
diff --git a/apps/desktop-gpui/src/app_windows.rs b/apps/desktop-gpui/src/app_windows.rsindex 8d1212dd8..65b0204fc 100644--- a/apps/desktop-gpui/src/app_windows.rs+++ b/apps/desktop-gpui/src/app_windows.rs@@ -4463,10 +4463,7 @@ fn load_editor_project(path: PathBuf, handle: WindowHandle<EditorWindow>, cx: &m);log_timeline_model(&summary.timeline);let recordings = summary.recordings.clone();- if handle- .update(cx, |view, window, cx| view.set_summary(summary, window, cx))- .is_err()- {+ if handle.update(cx, |_, _, _| ()).is_err() {return;}@@ -4548,8 +4545,35 @@ fn load_editor_project(path: PathBuf, handle: WindowHandle<EditorWindow>, cx: &m};tracing::info!(path = %path.display(), "editor instance ready");+ let (total, config) = {+ let config = instance.project_config.1.borrow().clone();+ let total = config+ .timeline+ .as_ref()+ .map_or(0.0, |timeline| timeline.duration());+ (total, config)+ };+ let has_camera = instance+ .recordings+ .segments+ .iter()+ .any(|segment| segment.camera.is_some());+ let multiple_clips = instance.recordings.segments.len() > 1;+ log_timeline_model(&editor_timeline::TimelineModel::build(+ &config,+ has_camera,+ multiple_clips,+ ));if handle- .update(cx, |view, _window, _cx| view.set_instance(instance.clone()))+ .update(cx, |view, window, cx| {+ // Loading controls can queue a save before the engine is ready.+ // Publish the loaded config and instance together so those edits+ // cannot replace the saved project with the initial defaults.+ view.pending_save().borrow_mut().discard();+ view.set_summary(summary, window, cx);+ view.set_project(config, window, cx);+ view.set_instance(instance.clone());+ }).is_err(){instance.dispose().await;@@ -4659,44 +4683,6 @@ fn load_editor_project(path: PathBuf, handle: WindowHandle<EditorWindow>, cx: &m}).detach();- // `totalDuration()` (`context.ts:1374-1380`). Read off the instance- // rather than the pre-flight, because `EditorInstance::new`- // synthesises a timeline for a raw bundle -- and `timeline.duration()`- // is exactly what the playback engine stops at- // (`playback.rs:560-570`).- //- // The whole track model comes from the same read: the config the- // instance actually loaded is the one being rendered, holds, clip- // offsets and all. E4 hands the window the config itself rather than- // the derived model, because it is what every edit mutates and what- // the debounced save writes back.- let (total, config) = {- let config = instance.project_config.1.borrow().clone();- let total = config- .timeline- .as_ref()- .map_or(0.0, |timeline| timeline.duration());- (total, config)- };- {- let has_camera = instance- .recordings- .segments- .iter()- .any(|segment| segment.camera.is_some());- let multiple_clips = instance.recordings.segments.len() > 1;- log_timeline_model(&editor_timeline::TimelineModel::build(- &config,- has_camera,- multiple_clips,- ));- }- if handle- .update(cx, |view, window, cx| view.set_project(config, window, cx))- .is_err()- {- return;- }load_editor_waveforms(instance.clone(), handle, cx);if handlediff --git a/apps/desktop-gpui/src/editor_clips.rs b/apps/desktop-gpui/src/editor_clips.rsindex 0ce3cf575..26e739bb1 100644--- a/apps/desktop-gpui/src/editor_clips.rs+++ b/apps/desktop-gpui/src/editor_clips.rs@@ -408,12 +408,16 @@ impl EditorWindow {ui::Button::plain(&self.theme, "clips-pill", variant, ui::ButtonSize::Md).icon("icons/clapperboard.svg").label("Clips")+ .disabled(!self.project_ready()).height(px(40.)).font_weight(FontWeight::MEDIUM).on_click(cx.listener(|this, _, window, cx| this.toggle_clips(window, cx)))}pub(crate) fn toggle_clips(&mut self, window: &mut Window, cx: &mut Context<Self>) {+ if !self.project_ready() {+ return;+ }self.set_selection(None, cx);if self.clips.open {self.close_clips(window, cx);@@ -1200,7 +1204,7 @@ impl EditorWindow {}fn begin_editor_recording(&mut self, cx: &mut Context<Self>) -> bool {- if self.clips.importing {+ if !self.project_ready() || self.clips.importing {return false;}let session = RecordingSession::global(cx);@@ -1252,6 +1256,13 @@ impl EditorWindow {_window: &mut Window,cx: &mut Context<Self>,) {+ if !self.project_ready() {+ tracing::warn!(+ recording = %recording_dir.display(),+ "the editor is not ready; leaving the recording in the library"+ );+ return;+ }if self.clips.importing {// A concurrent import owns the bundle merge; the capture stays in// the library and can be pulled in through "Existing recording".@@ -1506,7 +1517,7 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {- if self.clips.importing {+ if !self.project_ready() || self.clips.importing {return;}if self.playing {diff --git a/apps/desktop-gpui/src/editor_sidebar.rs b/apps/desktop-gpui/src/editor_sidebar.rsindex 9bb5c454d..45a1ffbe7 100644--- a/apps/desktop-gpui/src/editor_sidebar.rs+++ b/apps/desktop-gpui/src/editor_sidebar.rs@@ -1043,6 +1043,9 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {+ if !self.project_ready() {+ return;+ }// An edit that is not the open colour panel's closes its bracket// first: the panel is a system window and stays up while the user// does other things, and an unrelated change must not be swallowed@@ -1070,6 +1073,9 @@ impl EditorWindow {cx: &mut Context<Self>,change: impl FnOnce(&mut ProjectConfiguration) -> bool,) {+ if !self.project_ready() {+ return;+ }self.end_color_history();if !change(&mut self.project) {return;diff --git a/apps/desktop-gpui/src/editor_window.rs b/apps/desktop-gpui/src/editor_window.rsindex b5579e57b..f05119b69 100644--- a/apps/desktop-gpui/src/editor_window.rs+++ b/apps/desktop-gpui/src/editor_window.rs@@ -652,25 +652,30 @@ impl Render for EditorSectionView {let Some(editor) = self.editor.upgrade() else {return div().into_any_element();};- editor.update(cx, |editor, cx| match self.section {- EditorSection::Header => editor.render_header(window, cx).into_any_element(),- EditorSection::Toolbar => editor.render_player_toolbar(cx).into_any_element(),- EditorSection::Transport => editor.render_transport(cx).into_any_element(),- // The Clips layout mode swaps the config sidebar's column for the- // clips sidebar; the config sidebar is hidden, not destroyed- // (`Editor.tsx:728-747`).- EditorSection::Sidebar => {- if editor.clips.open {- editor.render_clips_sidebar(cx).into_any_element()- } else {- editor.render_sidebar(cx).into_any_element()- }+ editor.update(cx, |editor, cx| {+ if !editor.project_ready() && !matches!(self.section, EditorSection::Header) {+ return div().size_full().into_any_element();}- EditorSection::Timeline => {- let viewport_width: f32 = window.viewport_size().width.into();- editor- .render_timeline(viewport_width, cx)- .into_any_element()+ match self.section {+ EditorSection::Header => editor.render_header(window, cx).into_any_element(),+ EditorSection::Toolbar => editor.render_player_toolbar(cx).into_any_element(),+ EditorSection::Transport => editor.render_transport(cx).into_any_element(),+ // The Clips layout mode swaps the config sidebar's column for the+ // clips sidebar; the config sidebar is hidden, not destroyed+ // (`Editor.tsx:728-747`).+ EditorSection::Sidebar => {+ if editor.clips.open {+ editor.render_clips_sidebar(cx).into_any_element()+ } else {+ editor.render_sidebar(cx).into_any_element()+ }+ }+ EditorSection::Timeline => {+ let viewport_width: f32 = window.viewport_size().width.into();+ editor+ .render_timeline(viewport_width, cx)+ .into_any_element()+ }}})}@@ -1570,7 +1575,11 @@ impl EditorWindow {}).detach();- let name_input = cx.new(|cx| ui::TextInputState::single_line(window, cx));+ let name_input = cx.new(|cx| {+ let mut input = ui::TextInputState::single_line(window, cx);+ input.set_disabled(true, cx);+ input+ });let hex_targets = [crate::editor_sidebar::ColorTarget::BackgroundColor,crate::editor_sidebar::ColorTarget::GradientFrom,@@ -1822,7 +1831,8 @@ impl EditorWindow {// the timeline's width.self.view.transform = Transform::initial(summary.duration);self.name_input.update(cx, |input, cx| {- input.set_text(summary.pretty_name.clone(), cx)+ input.set_text(summary.pretty_name.clone(), cx);+ input.set_disabled(false, cx);});self.state = LoadState::Ready(Box::new(summary));cx.notify();@@ -1966,6 +1976,9 @@ impl EditorWindow {}pub(crate) fn project_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {+ if !self.project_ready() {+ return;+ }// Before `history.record`, so the re-projected caption track is part// of the same undo entry as the edit that moved it.self.rederive_caption_track();@@ -1978,6 +1991,9 @@ impl EditorWindow {}pub(crate) fn project_changed_live(&mut self, cx: &mut Context<Self>) {+ if !self.project_ready() {+ return;+ }self.publish_project();cx.notify();}@@ -2058,6 +2074,9 @@ impl EditorWindow {/// the re-render is skipped while playing exactly as `emitRenderFrame`'s/// `if (!editorState.playing)` gate does (`:493`).pub(crate) fn publish_project(&self) {+ if !self.project_ready() {+ return;+ }let Some(instance) = &self.instance else {return;};@@ -2076,6 +2095,9 @@ impl EditorWindow {/// executor. A later edit drops this task, which is `clearTimeout` plus a/// fresh `setTimeout`.pub(crate) fn schedule_save(&mut self, window: &mut Window, cx: &mut Context<Self>) {+ if !self.project_ready() {+ return;+ }self.pending_save.borrow_mut().config = Some(self.project.clone());let pending = self.pending_save.clone();self.save_task = Some(cx.spawn_in(window, async move |_, cx| {@@ -2164,6 +2186,10 @@ impl EditorWindow {self.selection.as_ref()}+ pub(crate) fn project_ready(&self) -> bool {+ self.instance.is_some() && matches!(&self.state, LoadState::Ready(_))+ }+#[allow(dead_code)]/// The live project config, for the units that render from it (the config/// sidebar's controls) or serialise it (export).@@ -2464,6 +2490,9 @@ impl EditorWindow {/// (`useEditorShortcuts.ts:10`) and `e.repeat` is ignored there/// (`:42`) as `is_held` is here.fn on_key(&mut self, event: &gpui::KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {+ if !self.project_ready() {+ return;+ }if self.frame_controls.is_open() && event.keystroke.key == "escape" {self.close_frame_controls(window, cx);cx.stop_propagation();@@ -5330,7 +5359,7 @@ impl EditorWindow {} else {self.history.can_redo()};- let enabled = can || self.selection.is_some();+ let enabled = self.project_ready() && (can || self.selection.is_some());ui::EditorButton::plain(&theme, id).left_icon(icon).disabled(!enabled)@@ -5615,6 +5644,9 @@ impl EditorWindow {window: &mut Window,cx: &mut Context<Self>,) {+ if !self.project_ready() {+ return;+ }if self.presets_menu.is_some() {self.presets_menu = None;cx.notify();@@ -7279,6 +7311,7 @@ impl EditorWindow {ui::EditorButton::plain(&theme, "presets").left_icon("icons/presets.svg").label("Presets")+ .disabled(!self.project_ready()).right_icon("icons/chevron-down.svg").pressed(self.presets_menu.is_some()).on_click(cx.listener(|this, event: &gpui::ClickEvent, window, cx| {@@ -7399,7 +7432,8 @@ impl EditorWindow {.h(px(40.)).flex_none().rounded(px(12.))- .cursor_pointer()+ .when(self.project_ready(), |button| button.cursor_pointer())+ .when(!self.project_ready(), |button| button.opacity(0.5)).bg(gpui::linear_gradient(180.,gpui::linear_color_stop(gpui::rgb(0x3b82f6), 0.),@@ -7430,7 +7464,13 @@ impl EditorWindow {.text_color(gpui::white()),).child("Export")- .on_click(cx.listener(|this, _, window, cx| this.open_export(window, cx)))+ .when(self.project_ready(), |button| {+ button.on_click(cx.listener(|this, _, window, cx| {+ if this.project_ready() {+ this.open_export(window, cx);+ }+ }))+ })}// -- Player --------------------------------------------------------------