Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ criterion = { version = "0.5", features = ["html_reports"] }
iai-callgrind = { version = "0.12.3" }
ndarray = "0.16.1"
strum = { version = "0.26.3", features = ["derive"] }
dirs = "6.0"

[profile.dev]
opt-level = 1
Expand Down
1 change: 1 addition & 0 deletions desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
tracing = "0.1.41"
bytemuck = { version = "1.23.1", features = ["derive"] }
include_dir = "0.7.4"
dirs.workspace = true
1 change: 1 addition & 0 deletions desktop/src/cef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::FrameBuffer;
use std::time::Instant;

mod context;
mod dirs;
mod input;
mod internal;
mod scheme_handler;
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/cef/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use cef::{Browser, CefString, Settings, api_hash, args::Args, execute_process};
use thiserror::Error;
use winit::event::WindowEvent;

use crate::cef::dirs::{cef_cache_dir, cef_data_dir};

use super::input::InputState;
use super::scheme_handler::{FRONTEND_DOMAIN, GRAPHITE_SCHEME};
use super::{CefEventHandler, input};
Expand Down Expand Up @@ -62,6 +64,8 @@ impl Context<Setup> {
windowless_rendering_enabled: 1,
multi_threaded_message_loop: 0,
external_message_pump: 1,
root_cache_path: cef_data_dir().to_str().map(CefString::from).unwrap(),
cache_path: cef_cache_dir().to_str().map(CefString::from).unwrap(),
..Default::default()
};

Expand Down
17 changes: 17 additions & 0 deletions desktop/src/cef/dirs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::path::PathBuf;

use crate::dirs::{ensure_dir_exists, graphite_data_dir};

static CEF_DIR_NAME: &str = "browser";

pub(crate) fn cef_data_dir() -> PathBuf {
let path = graphite_data_dir().join(CEF_DIR_NAME);
ensure_dir_exists(&path);
path
}

pub(crate) fn cef_cache_dir() -> PathBuf {
let path = cef_data_dir().join("cache");
ensure_dir_exists(&path);
path
}
16 changes: 16 additions & 0 deletions desktop/src/dirs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::fs::create_dir_all;
use std::path::PathBuf;

static APP_NAME: &str = "graphite-desktop";

pub(crate) fn ensure_dir_exists(path: &PathBuf) {
if !path.exists() {
create_dir_all(path).unwrap_or_else(|_| panic!("Failed to create directory at {path:?}"));
}
}

pub(crate) fn graphite_data_dir() -> PathBuf {
let path = dirs::data_dir().expect("Failed to get data directory").join(APP_NAME);
ensure_dir_exists(&path);
path
}
2 changes: 2 additions & 0 deletions desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use render::{FrameBuffer, GraphicsState};
mod app;
use app::WinitApp;

mod dirs;

#[derive(Debug)]
pub(crate) enum CustomEvent {
UiUpdate,
Expand Down
Loading