Compare commits

...
22 changed files with 209 additions and 109 deletions

No files matched your search

Generated
+12 -12
View File
@@ -2746,8 +2746,9 @@ dependencies = [
"fd-lock",
"futures",
"glam",
"graphite-desktop-ui",
"graphite-desktop-ui-cef",
"graphite-desktop-wrapper",
"graphite-wasm-wrapper",
"interprocess",
"lzma-rust2",
"muda",
@@ -2778,13 +2779,6 @@ dependencies = [
"serde",
]
[[package]]
name = "graphite-desktop-embedded-resources"
version = "0.0.0"
dependencies = [
"include_dir",
]
[[package]]
name = "graphite-desktop-platform-linux"
version = "0.0.0"
@@ -2797,7 +2791,7 @@ name = "graphite-desktop-platform-mac"
version = "0.0.0"
dependencies = [
"graphite-desktop",
"graphite-desktop-ui",
"graphite-desktop-ui-cef",
]
[[package]]
@@ -2809,14 +2803,14 @@ dependencies = [
]
[[package]]
name = "graphite-desktop-ui"
name = "graphite-desktop-ui-cef"
version = "0.0.0"
dependencies = [
"ash",
"bytemuck",
"cef",
"dirs",
"graphite-desktop-embedded-resources",
"graphite-desktop-ui-cef-embedded-resources",
"ipc-channel",
"libc",
"mach2",
@@ -2836,6 +2830,13 @@ dependencies = [
"winit",
]
[[package]]
name = "graphite-desktop-ui-cef-embedded-resources"
version = "0.0.0"
dependencies = [
"include_dir",
]
[[package]]
name = "graphite-desktop-wrapper"
version = "0.0.0"
@@ -2843,7 +2844,6 @@ dependencies = [
"base64 0.23.1",
"graph-craft",
"graphite-editor",
"graphite-wasm-wrapper",
"image",
"keyboard-types",
"serde",
+1 -1
View File
@@ -3,7 +3,7 @@ members = [
"desktop",
"desktop/wrapper",
"desktop/ui",
"desktop/embedded-resources",
"desktop/ui/embedded-resources",
"desktop/bundle",
"desktop/platform/linux",
"desktop/platform/mac",
+4 -3
View File
@@ -21,13 +21,14 @@ path = "src/main.rs"
[features]
default = ["recommended", "embedded_resources"]
recommended = ["accelerated_paint"]
embedded_resources = ["graphite-desktop-ui/embedded_resources"]
accelerated_paint = ["graphite-desktop-ui/accelerated_paint"]
embedded_resources = ["graphite-desktop-ui-cef/embedded_resources"]
accelerated_paint = ["graphite-desktop-ui-cef/accelerated_paint"]
[dependencies]
# Local dependencies
graphite-desktop-wrapper = { path = "wrapper" }
graphite-desktop-ui = { path = "ui" }
graphite-desktop-ui-cef = { path = "ui" }
graphite-wasm-wrapper = { path = "../frontend/wrapper", default-features = false, features = ["editor"] }
wgpu = { workspace = true }
winit = { workspace = true, features = [
+2 -2
View File
@@ -16,7 +16,7 @@ workspace = true
[features]
main = ["dep:graphite-desktop"]
helper = ["dep:graphite-desktop-ui"]
helper = ["dep:graphite-desktop-ui-cef"]
[[bin]]
name = "graphite"
@@ -30,4 +30,4 @@ required-features = ["helper"]
[dependencies]
graphite-desktop = { path = "../..", optional = true }
graphite-desktop-ui = { path = "../../ui", optional = true }
graphite-desktop-ui-cef = { path = "../../ui", optional = true }
+1 -1
View File
@@ -1,3 +1,3 @@
fn main() -> std::process::ExitCode {
graphite_desktop_ui::run_helper()
graphite_desktop_ui_cef::run_helper()
}
+11 -18
View File
@@ -20,13 +20,13 @@ use crate::dirs;
use crate::event::{AppEvent, AppEventScheduler};
use crate::input::InputState;
use crate::persist;
use crate::preferences;
use crate::preferences::{self, Acceleration};
use crate::render::{RenderError, RenderState};
use crate::spawner::TokioSpawner;
use crate::ui::{Acceleration, InputEvent, UiCommand, UiConfig, UiInstance};
use crate::ui::{InputEvent, Ui, UiBackend, UiCommand};
use crate::window::Window;
use crate::wrapper::messages::{DataTransfer, DesktopFrontendMessage, DesktopWrapperMessage, IngestAction};
use crate::wrapper::{DesktopWrapper, FolderStore, MmapResourceStorage, WgpuContext, WgpuExecutor, serialize_frontend_messages};
use crate::wrapper::messages::{DataTransfer, DesktopFrontendMessage, DesktopWrapperMessage, FrontendMessage, IngestAction};
use crate::wrapper::{DesktopWrapper, FolderStore, MmapResourceStorage, WgpuContext, WgpuExecutor};
pub(crate) struct App {
render_state: Option<RenderState>,
@@ -43,10 +43,10 @@ pub(crate) struct App {
app_event_scheduler: AppEventScheduler,
desktop_wrapper: DesktopWrapper,
runtime_command_sender: Sender<RuntimeCommand>,
ui: UiInstance,
ui: Ui,
ui_initialized: Option<Instant>,
ui_frame_received: bool,
ui_startup_buffer: Vec<Vec<u8>>,
ui_startup_buffer: Vec<Vec<FrontendMessage>>,
preferences: preferences::DesktopPreferences,
launch_documents: Option<Vec<PathBuf>>,
exiting: bool,
@@ -59,7 +59,7 @@ impl App {
}
pub(crate) fn new(
ui: UiInstance,
ui: Ui,
wgpu_context: WgpuContext,
app_event_receiver: Receiver<AppEvent>,
app_event_scheduler: AppEventScheduler,
@@ -181,8 +181,7 @@ impl App {
}
fn restart_ui(&mut self) {
let acceleration = self.preferences.acceleration;
if let Err(error) = self.ui.restart(UiConfig { acceleration }) {
if let Err(error) = self.ui.restart(&self.preferences) {
tracing::error!("Failed to restart the UI: {error}");
self.exit(Some(ExitReason::Shutdown));
return;
@@ -248,13 +247,7 @@ impl App {
fn handle_desktop_frontend_message(&mut self, message: DesktopFrontendMessage, responses: &mut Vec<DesktopWrapperMessage>) {
match message {
DesktopFrontendMessage::ToWeb(messages) => {
let Some(bytes) = serialize_frontend_messages(messages) else {
tracing::error!("Failed to serialize frontend messages");
return;
};
self.send_or_queue_web_message(bytes);
}
DesktopFrontendMessage::ToUi(messages) => self.send_or_queue_ui_message(messages),
DesktopFrontendMessage::OpenFileDialog { title, options, action } => {
let app_event_scheduler = self.app_event_scheduler.clone();
let _ = thread::spawn(move || {
@@ -465,7 +458,7 @@ impl App {
self.handle_desktop_frontend_messages(responses);
}
fn send_or_queue_web_message(&mut self, message: Vec<u8>) {
fn send_or_queue_ui_message(&mut self, message: Vec<FrontendMessage>) {
if self.ui_initialized.is_some() {
self.ui.send(UiCommand::Message(message));
} else {
@@ -475,7 +468,7 @@ impl App {
fn user_event(&mut self, event_loop: &dyn ActiveEventLoop, event: AppEvent) {
match event {
AppEvent::WebCommunicationInitialized => {
AppEvent::UiInitialized => {
self.ui_initialized = Some(Instant::now());
self.ui_frame_received = false;
for message in self.ui_startup_buffer.drain(..) {
-19
View File
@@ -9,25 +9,6 @@ pub(crate) fn ensure_dir_exists(path: &PathBuf) {
}
}
pub(crate) fn clear_dir(path: &PathBuf) {
let Ok(entries) = fs::read_dir(path) else {
tracing::error!("Failed to read directory at {path:?}");
return;
};
for entry in entries.flatten() {
let entry_path = entry.path();
if entry_path.is_dir() {
if let Err(e) = fs::remove_dir_all(&entry_path) {
tracing::error!("Failed to remove directory at {:?}: {}", entry_path, e);
}
} else if entry_path.is_file()
&& let Err(e) = fs::remove_file(&entry_path)
{
tracing::error!("Failed to remove file at {:?}: {}", entry_path, e);
}
}
}
pub(crate) fn app_data_dir() -> PathBuf {
let path = dirs::data_dir().expect("Failed to get data directory").join(APP_DIRECTORY_NAME);
ensure_dir_exists(&path);
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::wrapper::messages::{DataTransfer, DesktopWrapperMessage};
pub(crate) enum AppEvent {
UiUpdate(wgpu::Texture),
CursorChange(Cursor),
WebCommunicationInitialized,
UiInitialized,
DesktopWrapperMessage(DesktopWrapperMessage),
ViewportTexture(Option<Texture>),
ClipboardRead,
+9 -29
View File
@@ -3,13 +3,13 @@ use crate::cli::Cli;
use crate::consts::APP_LOCK_FILE_NAME;
use crate::event::{AppEvent, CreateAppEventSchedulerEventLoopExt};
use clap::Parser;
use preferences::Acceleration;
use std::io::Write;
use std::process::ExitCode;
use tracing_subscriber::EnvFilter;
use ui::{Acceleration, UiConfig, UiContext, UiEvent, UiSetupResult};
use ui::{Ui, UiBackend, UiEvent};
use winit::event_loop::EventLoop;
pub(crate) use graphite_desktop_ui as ui;
pub(crate) use graphite_desktop_wrapper as wrapper;
mod app;
@@ -24,6 +24,7 @@ mod preferences;
mod render;
mod socket;
mod spawner;
mod ui;
mod window;
pub(crate) mod consts;
@@ -31,14 +32,9 @@ pub(crate) mod consts;
pub fn start() -> ExitCode {
tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init();
let ui_context = match UiContext::setup() {
UiSetupResult::Ready(context) => context,
UiSetupResult::Helper(code) => return code,
UiSetupResult::Failed => {
tracing::error!("Failed to set up the UI runtime");
return ExitCode::FAILURE;
}
};
if let Some(code) = ui::setup() {
return code;
}
let cli = Cli::parse();
@@ -73,8 +69,6 @@ pub fn start() -> ExitCode {
}
};
dirs::clear_dir(&ui::temp_dir_root());
// Must be called before event loop initialization or native window integrations will break
App::init();
@@ -98,14 +92,7 @@ pub fn start() -> ExitCode {
println!("UI acceleration is disabled");
}
let ui_context = match ui_context.start(UiConfig { acceleration: prefs.acceleration }) {
Ok(context) => context,
Err(error) => {
tracing::error!("Failed to start the UI runtime: {error}");
return ExitCode::FAILURE;
}
};
let ui = match ui_context.instance(&wgpu_context.device, &wgpu_context.queue) {
let ui = match Ui::start(&prefs, &wgpu_context) {
Ok(ui) => ui,
Err(error) => {
tracing::error!("Failed to start the UI: {error}");
@@ -120,17 +107,10 @@ pub fn start() -> ExitCode {
let spawned = std::thread::Builder::new().name("ui-events".to_string()).spawn(move || {
while let Some(event) = ui.recv() {
match event {
UiEvent::Ready => scheduler.schedule(AppEvent::WebCommunicationInitialized),
UiEvent::Ready => scheduler.schedule(AppEvent::UiInitialized),
UiEvent::Frame(texture) => scheduler.schedule(AppEvent::UiUpdate(texture)),
UiEvent::Cursor(cursor) => scheduler.schedule(AppEvent::CursorChange(cursor)),
UiEvent::Message(message) => match wrapper::deserialize_editor_message(&message) {
Some(message) => scheduler.schedule(AppEvent::DesktopWrapperMessage(message)),
None => tracing::error!("Failed to deserialize web message"),
},
UiEvent::Failure(error) => {
tracing::error!("UI failure: {error}");
scheduler.schedule(AppEvent::UiCrashed);
}
UiEvent::Message(message) => scheduler.schedule(AppEvent::DesktopWrapperMessage(message)),
UiEvent::Crashed => scheduler.schedule(AppEvent::UiCrashed),
}
}
+5 -1
View File
@@ -1,7 +1,11 @@
use graphite_desktop_wrapper::messages::Preferences;
use wgpu::PresentMode;
use crate::ui::Acceleration;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Acceleration {
Auto,
Disabled,
}
#[derive(Clone, PartialEq)]
pub(crate) struct DesktopPreferences {
+32
View File
@@ -0,0 +1,32 @@
use crate::preferences::DesktopPreferences;
use crate::wrapper::WgpuContext;
use crate::wrapper::messages::{DesktopWrapperMessage, FrontendMessage};
mod cef;
pub(crate) use cef::*;
pub(crate) trait UiBackend: Sized {
fn start(preferences: &DesktopPreferences, wgpu_context: &WgpuContext) -> Result<Self, UiError>;
fn send(&self, command: UiCommand);
fn recv(&self) -> Option<UiEvent>;
fn restart(&self, preferences: &DesktopPreferences) -> Result<(), UiError>;
fn shutdown(&self);
}
pub(crate) type UiError = Box<dyn std::error::Error + Send + Sync>;
pub(crate) enum UiCommand {
Input(InputEvent),
Resized { width: u32, height: u32 },
ScaleChanged(f64),
Refresh,
Message(Vec<FrontendMessage>),
}
pub(crate) enum UiEvent {
Ready,
Frame(wgpu::Texture),
Cursor(Cursor),
Message(DesktopWrapperMessage),
Crashed,
}
+120
View File
@@ -0,0 +1,120 @@
use super::{UiBackend, UiCommand, UiError, UiEvent};
use crate::preferences::{Acceleration, DesktopPreferences};
use crate::wrapper::WgpuContext;
use crate::wrapper::messages::DesktopWrapperMessage;
use graphite_desktop_ui_cef as cef;
use graphite_wasm_wrapper::native_communication::{decode_editor_command, encode_frontend_messages};
use std::fs;
use std::path::PathBuf;
use std::process::ExitCode;
use std::sync::Mutex;
pub(crate) use cef::{Cursor, InputEvent, InputEventBuilder, MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, PINCH_ZOOM_SPEED, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCROLL_SPEED_X, SCROLL_SPEED_Y};
#[derive(Clone)]
pub(crate) struct Ui {
instance: cef::UiInstance,
}
static SETUP: Mutex<Option<cef::UiContext<cef::Setup>>> = Mutex::new(None);
pub(crate) fn setup() -> Option<ExitCode> {
match cef::UiContext::setup() {
cef::UiSetupResult::Ready(context) => {
*SETUP.lock().unwrap() = Some(context);
None
}
cef::UiSetupResult::Failed => {
tracing::error!("Failed to set up the UI runtime");
Some(ExitCode::FAILURE)
}
cef::UiSetupResult::Helper(code) => Some(code),
}
}
impl UiBackend for Ui {
fn start(preferences: &DesktopPreferences, wgpu_context: &WgpuContext) -> Result<Self, UiError> {
let setup = SETUP.lock().unwrap().take().ok_or("The UI was started before it was set up")?;
clear_dir(&cef::temp_dir_root());
let context = setup.start(config(preferences))?;
let instance = context.instance(&wgpu_context.device, &wgpu_context.queue)?;
Ok(Self { instance })
}
fn send(&self, command: UiCommand) {
let command = match command {
UiCommand::Input(event) => cef::UiCommand::Input(event),
UiCommand::Resized { width, height } => cef::UiCommand::Resized { width, height },
UiCommand::ScaleChanged(scale) => cef::UiCommand::ScaleChanged(scale),
UiCommand::Refresh => cef::UiCommand::Refresh,
UiCommand::Message(messages) => {
let Some(bytes) = encode_frontend_messages(messages) else {
tracing::error!("Failed to serialize frontend messages");
return;
};
cef::UiCommand::Message(bytes)
}
};
self.instance.send(command);
}
fn recv(&self) -> Option<UiEvent> {
loop {
let event = match self.instance.recv()? {
cef::UiEvent::Ready => UiEvent::Ready,
cef::UiEvent::Frame(texture) => UiEvent::Frame(texture),
cef::UiEvent::Cursor(cursor) => UiEvent::Cursor(cursor),
cef::UiEvent::Message(bytes) => {
let Some(message) = decode_editor_command(&bytes) else {
tracing::error!("Failed to deserialize web message");
continue;
};
UiEvent::Message(DesktopWrapperMessage::FromUi(message.into()))
}
cef::UiEvent::Failure(error) => {
tracing::error!("UI failure: {error}");
UiEvent::Crashed
}
cef::UiEvent::Crashed => UiEvent::Crashed,
};
return Some(event);
}
}
fn restart(&self, preferences: &DesktopPreferences) -> Result<(), UiError> {
Ok(self.instance.restart(config(preferences))?)
}
fn shutdown(&self) {
self.instance.shutdown();
}
}
fn config(preferences: &DesktopPreferences) -> cef::UiConfig {
let acceleration = match preferences.acceleration {
Acceleration::Auto => cef::Acceleration::Auto,
Acceleration::Disabled => cef::Acceleration::Disabled,
};
cef::UiConfig { acceleration }
}
fn clear_dir(path: &PathBuf) {
let Ok(entries) = fs::read_dir(path) else {
tracing::error!("Failed to read directory at {path:?}");
return;
};
for entry in entries.flatten() {
let entry_path = entry.path();
if entry_path.is_dir() {
if let Err(e) = fs::remove_dir_all(&entry_path) {
tracing::error!("Failed to remove directory at {:?}: {}", entry_path, e);
}
} else if entry_path.is_file()
&& let Err(e) = fs::remove_file(&entry_path)
{
tracing::error!("Failed to remove file at {:?}: {}", entry_path, e);
}
}
}
+3 -3
View File
@@ -1,5 +1,5 @@
[package]
name = "graphite-desktop-ui"
name = "graphite-desktop-ui-cef"
description = "Renders the Graphite editor frontend UI into wgpu textures"
version.workspace = true
license.workspace = true
@@ -16,12 +16,12 @@ workspace = true
[features]
default = []
embedded_resources = ["dep:graphite-desktop-embedded-resources"]
embedded_resources = ["dep:graphite-desktop-ui-cef-embedded-resources"]
accelerated_paint = ["dep:ash", "dep:bytemuck", "dep:objc2-io-surface", "dep:objc2-metal", "dep:mach2"]
[dependencies]
# Local dependencies
graphite-desktop-embedded-resources = { path = "../embedded-resources", optional = true }
graphite-desktop-ui-cef-embedded-resources = { path = "embedded-resources", optional = true }
wgpu = { workspace = true }
wgpu-sync = { workspace = true }
@@ -1,5 +1,5 @@
[package]
name = "graphite-desktop-embedded-resources"
name = "graphite-desktop-ui-cef-embedded-resources"
description = "Graphite Desktop Embedded Resources"
version.workspace = true
license.workspace = true
@@ -1,5 +1,5 @@
const EMBEDDED_RESOURCES_ENV: &str = "EMBEDDED_RESOURCES";
const DEFAULT_RESOURCES_DIR: &str = "../../frontend/dist";
const DEFAULT_RESOURCES_DIR: &str = "../../../frontend/dist";
fn main() {
let mut embedded_resources: Option<String> = None;
+1 -1
View File
@@ -78,7 +78,7 @@ pub(crate) fn load(path: PathBuf) -> Option<Resource> {
WebResources::Embedded => {
#[cfg(feature = "embedded_resources")]
{
if let Some(resources) = &graphite_desktop_embedded_resources::EMBEDDED_RESOURCES
if let Some(resources) = &graphite_desktop_ui_cef_embedded_resources::EMBEDDED_RESOURCES
&& let Some(file) = resources.get_file(&path)
{
return Some(Resource {
-1
View File
@@ -17,7 +17,6 @@ workspace = true
[dependencies]
# Local dependencies
graphite-editor = { workspace = true }
graphite-wasm-wrapper = { path = "../../frontend/wrapper", default-features = false, features = ["editor"] }
graph-craft = { workspace = true }
wgpu-executor = { workspace = true }
@@ -5,7 +5,7 @@ use super::messages::{DesktopFrontendMessage, DesktopWrapperMessage, EditorMessa
pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMessageDispatcher, message: DesktopWrapperMessage) {
match message {
DesktopWrapperMessage::FromWeb(message) => {
DesktopWrapperMessage::FromUi(message) => {
dispatcher.queue_editor_message(*message);
}
DesktopWrapperMessage::Wake => {
-10
View File
@@ -2,7 +2,6 @@ use graph_craft::application_io::PlatformApplicationIo;
use graph_craft::application_io::resource::ResourceStorage;
use graphite_editor::application::{Editor, Environment, Host, Platform};
use graphite_editor::builder::{Builder, EditorBuilder, RuntimeBuilder};
use graphite_editor::messages::frontend::FrontendMessage;
use graphite_editor::node_graph_executor::NodeRuntime;
use message_dispatcher::DesktopWrapperMessageDispatcher;
@@ -80,12 +79,3 @@ impl DesktopWrapper {
executor.execute()
}
}
pub fn deserialize_editor_message(data: &[u8]) -> Option<DesktopWrapperMessage> {
let message = graphite_wasm_wrapper::native_communication::decode_editor_command(data)?;
Some(DesktopWrapperMessage::FromWeb(message.into()))
}
pub fn serialize_frontend_messages(messages: Vec<FrontendMessage>) -> Option<Vec<u8>> {
graphite_wasm_wrapper::native_communication::encode_frontend_messages(messages)
}
+1 -1
View File
@@ -60,7 +60,7 @@ impl<'a> DesktopWrapperMessageDispatcher<'a> {
}
if !frontend_messages.is_empty() {
self.respond(DesktopFrontendMessage::ToWeb(frontend_messages));
self.respond(DesktopFrontendMessage::ToUi(frontend_messages));
}
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
use graphite_editor::messages::prelude::FrontendMessage;
pub use graphite_editor::messages::prelude::FrontendMessage;
use std::path::PathBuf;
pub(crate) use graphite_editor::messages::prelude::Message as EditorMessage;
@@ -12,7 +12,7 @@ pub use graphite_editor::messages::prelude::InputPreprocessorMessage as InputMes
pub use graphite_editor::messages::prelude::PreferencesMessageHandler as Preferences;
pub enum DesktopFrontendMessage {
ToWeb(Vec<FrontendMessage>),
ToUi(Vec<FrontendMessage>),
OpenLaunchDocuments,
OpenFileDialog {
title: String,
@@ -69,7 +69,7 @@ pub enum DesktopFrontendMessage {
}
pub enum DesktopWrapperMessage {
FromWeb(Box<EditorMessage>),
FromUi(Box<EditorMessage>),
Wake,
Input(InputMessage),
Ingest { content: DataTransfer, action: IngestAction },