Desktop set cef data and cache directory (#2927)

This commit is contained in:
Timon
2025-07-24 16:56:57 +00:00
committed by GitHub
parent e7b8b5a3b6
commit 9f4f3681c3
8 changed files with 85 additions and 10 deletions
+1
View File
@@ -2,6 +2,7 @@ use crate::FrameBuffer;
use std::time::Instant;
mod context;
mod dirs;
mod input;
mod internal;
mod scheme_handler;
+4
View File
@@ -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};
@@ -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()
};
+17
View File
@@ -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
View File
@@ -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
View File
@@ -15,6 +15,8 @@ use render::{FrameBuffer, GraphicsState};
mod app;
use app::WinitApp;
mod dirs;
#[derive(Debug)]
pub(crate) enum CustomEvent {
UiUpdate,