use std::path::Path; use std::sync::Arc; use gpui::{App, Entity, Global, prelude::*}; use crate::{JujutsuRepository, RealJujutsuRepository}; /// Note: We won't ultimately be storing the jj store in a global, we're just doing this for exploration purposes. struct GlobalJujutsuStore(Entity); impl Global for GlobalJujutsuStore {} pub struct JujutsuStore { repository: Arc, } impl JujutsuStore { pub fn init_global(cx: &mut App) { let Some(repository) = RealJujutsuRepository::new(&Path::new(".")).ok() else { return; }; let repository = Arc::new(repository); let jj_store = cx.new(|cx| JujutsuStore::new(repository, cx)); cx.set_global(GlobalJujutsuStore(jj_store)); } pub fn try_global(cx: &App) -> Option> { cx.try_global::() .map(|global| global.0.clone()) } pub fn new(repository: Arc, _cx: &mut Context) -> Self { Self { repository } } pub fn repository(&self) -> &Arc { &self.repository } }