Skip to content

Commit 9f4f368

Browse files
Desktop set cef data and cache directory (#2927)
1 parent e7b8b5a commit 9f4f368

File tree

8 files changed

+85
-10
lines changed

8 files changed

+85
-10
lines changed

Cargo.lock

Lines changed: 43 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ criterion = { version = "0.5", features = ["html_reports"] }
155155
iai-callgrind = { version = "0.12.3" }
156156
ndarray = "0.16.1"
157157
strum = { version = "0.26.3", features = ["derive"] }
158+
dirs = "6.0"
158159

159160
[profile.dev]
160161
opt-level = 1

desktop/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
3030
tracing = "0.1.41"
3131
bytemuck = { version = "1.23.1", features = ["derive"] }
3232
include_dir = "0.7.4"
33+
dirs.workspace = true

desktop/src/cef.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::FrameBuffer;
22
use std::time::Instant;
33

44
mod context;
5+
mod dirs;
56
mod input;
67
mod internal;
78
mod scheme_handler;

desktop/src/cef/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use cef::{Browser, CefString, Settings, api_hash, args::Args, execute_process};
44
use thiserror::Error;
55
use winit::event::WindowEvent;
66

7+
use crate::cef::dirs::{cef_cache_dir, cef_data_dir};
8+
79
use super::input::InputState;
810
use super::scheme_handler::{FRONTEND_DOMAIN, GRAPHITE_SCHEME};
911
use super::{CefEventHandler, input};
@@ -62,6 +64,8 @@ impl Context<Setup> {
6264
windowless_rendering_enabled: 1,
6365
multi_threaded_message_loop: 0,
6466
external_message_pump: 1,
67+
root_cache_path: cef_data_dir().to_str().map(CefString::from).unwrap(),
68+
cache_path: cef_cache_dir().to_str().map(CefString::from).unwrap(),
6569
..Default::default()
6670
};
6771

desktop/src/cef/dirs.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::path::PathBuf;
2+
3+
use crate::dirs::{ensure_dir_exists, graphite_data_dir};
4+
5+
static CEF_DIR_NAME: &str = "browser";
6+
7+
pub(crate) fn cef_data_dir() -> PathBuf {
8+
let path = graphite_data_dir().join(CEF_DIR_NAME);
9+
ensure_dir_exists(&path);
10+
path
11+
}
12+
13+
pub(crate) fn cef_cache_dir() -> PathBuf {
14+
let path = cef_data_dir().join("cache");
15+
ensure_dir_exists(&path);
16+
path
17+
}

desktop/src/dirs.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::fs::create_dir_all;
2+
use std::path::PathBuf;
3+
4+
static APP_NAME: &str = "graphite-desktop";
5+
6+
pub(crate) fn ensure_dir_exists(path: &PathBuf) {
7+
if !path.exists() {
8+
create_dir_all(path).unwrap_or_else(|_| panic!("Failed to create directory at {path:?}"));
9+
}
10+
}
11+
12+
pub(crate) fn graphite_data_dir() -> PathBuf {
13+
let path = dirs::data_dir().expect("Failed to get data directory").join(APP_NAME);
14+
ensure_dir_exists(&path);
15+
path
16+
}

desktop/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use render::{FrameBuffer, GraphicsState};
1515
mod app;
1616
use app::WinitApp;
1717

18+
mod dirs;
19+
1820
#[derive(Debug)]
1921
pub(crate) enum CustomEvent {
2022
UiUpdate,

0 commit comments

Comments
 (0)