mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-23 20:54:50 +03:00
better structure
This commit is contained in:
parent
6f4336ff4c
commit
f53397cf28
@ -1,6 +1,4 @@
|
||||
mod dispatchers;
|
||||
pub mod gb_repository;
|
||||
mod listeners;
|
||||
pub mod project_repository;
|
||||
pub mod reader;
|
||||
mod session;
|
||||
|
@ -1,19 +1,36 @@
|
||||
use std::time;
|
||||
use std::{sync, time};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use crate::app::gb_repository;
|
||||
use crate::{app::gb_repository, events, users};
|
||||
|
||||
use super::flush_session;
|
||||
|
||||
pub struct Listener<'listener> {
|
||||
gb_repository: &'listener gb_repository::Repository,
|
||||
|
||||
flush_session_listener: flush_session::Listener<'listener>,
|
||||
}
|
||||
|
||||
const FIVE_MINUTES: u128 = time::Duration::new(5 * 60, 0).as_millis();
|
||||
const ONE_HOUR: u128 = time::Duration::new(60 * 60, 0).as_millis();
|
||||
|
||||
impl<'listener> Listener<'listener> {
|
||||
pub fn new(gb_repository: &'listener gb_repository::Repository) -> Self {
|
||||
Self { gb_repository }
|
||||
pub fn new(
|
||||
project_id: String,
|
||||
user_store: users::Storage,
|
||||
gb_repository: &'listener gb_repository::Repository,
|
||||
sender: sync::mpsc::Sender<events::Event>,
|
||||
) -> Self {
|
||||
Self {
|
||||
gb_repository,
|
||||
flush_session_listener: flush_session::Listener::new(
|
||||
project_id,
|
||||
user_store,
|
||||
gb_repository,
|
||||
sender,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(&self, ts: time::SystemTime) -> Result<()> {
|
||||
@ -41,6 +58,10 @@ impl<'listener> Listener<'listener> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.flush_session_listener
|
||||
.register(¤t_session)
|
||||
.context("failed to flush session")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -2,24 +2,24 @@ use std::{sync, time};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use crate::{app::gb_repository, events, projects, sessions, users};
|
||||
use crate::{app::gb_repository, events, sessions, users};
|
||||
|
||||
pub struct Listener<'listener> {
|
||||
project_id: String,
|
||||
user_store: &'listener users::Storage,
|
||||
user_store: users::Storage,
|
||||
gb_repository: &'listener gb_repository::Repository,
|
||||
sender: sync::mpsc::Sender<events::Event>,
|
||||
}
|
||||
|
||||
impl<'listener> Listener<'listener> {
|
||||
pub fn new(
|
||||
project: &projects::Project,
|
||||
user_store: &'listener users::Storage,
|
||||
project_id: String,
|
||||
user_store: users::Storage,
|
||||
gb_repository: &'listener gb_repository::Repository,
|
||||
sender: sync::mpsc::Sender<events::Event>,
|
||||
) -> Self {
|
||||
Self {
|
||||
project_id: project.id.clone(),
|
||||
project_id,
|
||||
user_store,
|
||||
gb_repository,
|
||||
sender,
|
5
src-tauri/src/app/watcher/mod.rs
Normal file
5
src-tauri/src/app/watcher/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod dispatchers;
|
||||
mod listeners;
|
||||
mod watcher;
|
||||
|
||||
pub use watcher::Watcher;
|
@ -3,12 +3,9 @@ use std::{sync, time};
|
||||
use anyhow::{Context, Result};
|
||||
use crossbeam_channel::{bounded, select, unbounded};
|
||||
|
||||
use crate::{
|
||||
app::{dispatchers, listeners},
|
||||
events, projects,
|
||||
};
|
||||
use crate::{app::gb_repository, events, projects, users};
|
||||
|
||||
use super::{gb_repository, project_repository};
|
||||
use super::{dispatchers, listeners};
|
||||
|
||||
pub struct Watcher<'watcher> {
|
||||
project_id: String,
|
||||
@ -29,6 +26,7 @@ impl<'watcher> Watcher<'watcher> {
|
||||
pub fn new(
|
||||
project_id: String,
|
||||
project_store: projects::Storage,
|
||||
user_store: users::Storage,
|
||||
gb_repository: &'watcher gb_repository::Repository,
|
||||
events: sync::mpsc::Sender<events::Event>,
|
||||
) -> Result<Self> {
|
||||
@ -52,10 +50,13 @@ impl<'watcher> Watcher<'watcher> {
|
||||
project_id.clone(),
|
||||
project_store,
|
||||
gb_repository,
|
||||
events,
|
||||
events.clone(),
|
||||
),
|
||||
check_current_session_listener: listeners::check_current_session::Listener::new(
|
||||
project_id.clone(),
|
||||
user_store,
|
||||
gb_repository,
|
||||
events,
|
||||
),
|
||||
|
||||
stop: bounded(1),
|
@ -725,15 +725,18 @@ fn init(app_handle: tauri::AppHandle) -> Result<()> {
|
||||
|
||||
let p = project.clone();
|
||||
let ps = app_state.projects_storage.clone();
|
||||
let us = app_state.users_storage.clone();
|
||||
tauri::async_runtime::spawn_blocking(|| {
|
||||
let project = p;
|
||||
let project_storage = ps;
|
||||
let user_storage = us;
|
||||
|
||||
let gb_repo = app::gb_repository::Repository::open(local_data_dir, project.id.clone())
|
||||
.expect("failed to open gb repository");
|
||||
let (tx, _rx) = std::sync::mpsc::channel::<events::Event>();
|
||||
let w = app::watcher::Watcher::new(project.id, project_storage, &gb_repo, tx)
|
||||
.expect("failed to create watcher");
|
||||
let w =
|
||||
app::watcher::Watcher::new(project.id, project_storage, user_storage, &gb_repo, tx)
|
||||
.expect("failed to create watcher");
|
||||
w.start().expect("failed to start watcher");
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user