mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 12:28:12 +08:00
Desktop: Move autosave persistence to native (#3134)
* Move autosave persistence to native 1 * Move autosave persistence to native 2 * Reimplement quirky behavior of the web frontend * Code revew * Use select_after_open * fix fmt --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -118,5 +118,27 @@ pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMess
|
||||
let message = AppWindowMessage::AppWindowUpdatePlatform { platform };
|
||||
dispatcher.queue_editor_message(message.into());
|
||||
}
|
||||
DesktopWrapperMessage::LoadDocument {
|
||||
id,
|
||||
document,
|
||||
to_front,
|
||||
select_after_open,
|
||||
} => {
|
||||
let message = PortfolioMessage::OpenDocumentFileWithId {
|
||||
document_id: id,
|
||||
document_name: Some(document.name),
|
||||
document_path: document.path,
|
||||
document_serialized_content: document.content,
|
||||
document_is_auto_saved: true,
|
||||
document_is_saved: document.is_saved,
|
||||
to_front,
|
||||
select_after_open,
|
||||
};
|
||||
dispatcher.queue_editor_message(message.into());
|
||||
}
|
||||
DesktopWrapperMessage::SelectDocument { id } => {
|
||||
let message = PortfolioMessage::SelectDocument { document_id: id };
|
||||
dispatcher.queue_editor_message(message.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::PathBuf;
|
||||
use graphite_editor::messages::prelude::FrontendMessage;
|
||||
|
||||
use super::DesktopWrapperMessageDispatcher;
|
||||
use super::messages::{DesktopFrontendMessage, FileFilter, OpenFileDialogContext, SaveFileDialogContext};
|
||||
use super::messages::{DesktopFrontendMessage, Document, FileFilter, OpenFileDialogContext, SaveFileDialogContext};
|
||||
|
||||
pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageDispatcher, message: FrontendMessage) -> Option<FrontendMessage> {
|
||||
match message {
|
||||
@@ -67,12 +67,46 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
|
||||
FrontendMessage::UpdateWindowState { maximized, minimized } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::UpdateWindowState { maximized, minimized });
|
||||
|
||||
// Forward this to update the ui
|
||||
// Forward this to update the UI
|
||||
return Some(message);
|
||||
}
|
||||
FrontendMessage::CloseWindow => {
|
||||
dispatcher.respond(DesktopFrontendMessage::CloseWindow);
|
||||
}
|
||||
FrontendMessage::TriggerPersistenceWriteDocument { document_id, document, details } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::PersistenceWriteDocument {
|
||||
id: document_id,
|
||||
document: Document {
|
||||
name: details.name,
|
||||
path: None,
|
||||
content: document,
|
||||
is_saved: details.is_saved,
|
||||
},
|
||||
});
|
||||
}
|
||||
FrontendMessage::TriggerPersistenceRemoveDocument { document_id } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::PersistenceDeleteDocument { id: document_id });
|
||||
}
|
||||
FrontendMessage::UpdateActiveDocument { document_id } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::PersistenceUpdateCurrentDocument { id: document_id });
|
||||
|
||||
// Forward this to update the UI
|
||||
return Some(FrontendMessage::UpdateActiveDocument { document_id });
|
||||
}
|
||||
FrontendMessage::UpdateOpenDocumentsList { open_documents } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::PersistenceUpdateDocumentsList {
|
||||
ids: open_documents.iter().map(|document| document.id).collect(),
|
||||
});
|
||||
|
||||
// Forward this to update the UI
|
||||
return Some(FrontendMessage::UpdateOpenDocumentsList { open_documents });
|
||||
}
|
||||
FrontendMessage::TriggerLoadFirstAutoSaveDocument => {
|
||||
dispatcher.respond(DesktopFrontendMessage::PersistenceLoadCurrentDocument);
|
||||
}
|
||||
FrontendMessage::TriggerLoadRestAutoSaveDocuments => {
|
||||
dispatcher.respond(DesktopFrontendMessage::PersistenceLoadRemainingDocuments);
|
||||
}
|
||||
m => return Some(m),
|
||||
}
|
||||
None
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use graphite_editor::messages::prelude::{DocumentId, FrontendMessage};
|
||||
|
||||
pub use graphite_editor::messages::prelude::DocumentId;
|
||||
use graphite_editor::messages::prelude::FrontendMessage;
|
||||
pub(crate) use graphite_editor::messages::prelude::Message as EditorMessage;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub enum DesktopFrontendMessage {
|
||||
ToWeb(Vec<FrontendMessage>),
|
||||
@@ -34,27 +33,81 @@ pub enum DesktopFrontendMessage {
|
||||
maximized: bool,
|
||||
minimized: bool,
|
||||
},
|
||||
PersistenceWriteDocument {
|
||||
id: DocumentId,
|
||||
document: Document,
|
||||
},
|
||||
PersistenceDeleteDocument {
|
||||
id: DocumentId,
|
||||
},
|
||||
PersistenceUpdateCurrentDocument {
|
||||
id: DocumentId,
|
||||
},
|
||||
PersistenceLoadCurrentDocument,
|
||||
PersistenceLoadRemainingDocuments,
|
||||
PersistenceUpdateDocumentsList {
|
||||
ids: Vec<DocumentId>,
|
||||
},
|
||||
CloseWindow,
|
||||
}
|
||||
|
||||
pub enum DesktopWrapperMessage {
|
||||
FromWeb(Box<EditorMessage>),
|
||||
OpenFileDialogResult {
|
||||
path: PathBuf,
|
||||
content: Vec<u8>,
|
||||
context: OpenFileDialogContext,
|
||||
},
|
||||
SaveFileDialogResult {
|
||||
path: PathBuf,
|
||||
context: SaveFileDialogContext,
|
||||
},
|
||||
OpenDocument {
|
||||
path: PathBuf,
|
||||
content: Vec<u8>,
|
||||
},
|
||||
OpenFile {
|
||||
path: PathBuf,
|
||||
content: Vec<u8>,
|
||||
},
|
||||
ImportFile {
|
||||
path: PathBuf,
|
||||
content: Vec<u8>,
|
||||
},
|
||||
ImportSvg {
|
||||
path: PathBuf,
|
||||
content: Vec<u8>,
|
||||
},
|
||||
ImportImage {
|
||||
path: PathBuf,
|
||||
content: Vec<u8>,
|
||||
},
|
||||
PollNodeGraphEvaluation,
|
||||
UpdatePlatform(Platform),
|
||||
LoadDocument {
|
||||
id: DocumentId,
|
||||
document: Document,
|
||||
to_front: bool,
|
||||
select_after_open: bool,
|
||||
},
|
||||
SelectDocument {
|
||||
id: DocumentId,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)]
|
||||
pub struct Document {
|
||||
pub content: String,
|
||||
pub name: String,
|
||||
pub path: Option<PathBuf>,
|
||||
pub is_saved: bool,
|
||||
}
|
||||
|
||||
pub struct FileFilter {
|
||||
pub name: String,
|
||||
pub extensions: Vec<String>,
|
||||
}
|
||||
|
||||
pub enum DesktopWrapperMessage {
|
||||
FromWeb(Box<EditorMessage>),
|
||||
OpenFileDialogResult { path: PathBuf, content: Vec<u8>, context: OpenFileDialogContext },
|
||||
SaveFileDialogResult { path: PathBuf, context: SaveFileDialogContext },
|
||||
OpenDocument { path: PathBuf, content: Vec<u8> },
|
||||
OpenFile { path: PathBuf, content: Vec<u8> },
|
||||
ImportFile { path: PathBuf, content: Vec<u8> },
|
||||
ImportSvg { path: PathBuf, content: Vec<u8> },
|
||||
ImportImage { path: PathBuf, content: Vec<u8> },
|
||||
PollNodeGraphEvaluation,
|
||||
UpdatePlatform(Platform),
|
||||
}
|
||||
|
||||
pub enum OpenFileDialogContext {
|
||||
Document,
|
||||
Import,
|
||||
|
||||
Reference in New Issue
Block a user