mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-24 18:12:48 +03:00
Avoid managing every piece of the watcher, only manage what's currently needed
This commit is contained in:
parent
efe03a9b3a
commit
1476ff01ee
@ -14,15 +14,9 @@ pub struct Sender {
|
||||
}
|
||||
|
||||
impl Sender {
|
||||
pub fn from_app(app: &AppHandle) -> Result<Self, anyhow::Error> {
|
||||
if let Some(sender) = app.try_state::<Sender>() {
|
||||
Ok(sender.inner().clone())
|
||||
} else {
|
||||
let sender = Sender {
|
||||
app_handle: app.clone(),
|
||||
};
|
||||
app.manage(sender.clone());
|
||||
Ok(sender)
|
||||
pub fn from_app(app: &AppHandle) -> Self {
|
||||
Sender {
|
||||
app_handle: app.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub mod push_project_to_gitbutler;
|
||||
use std::time;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use tauri::{AppHandle, Manager};
|
||||
use tauri::AppHandle;
|
||||
use tracing::instrument;
|
||||
|
||||
use super::events;
|
||||
@ -36,31 +36,29 @@ pub struct Handler {
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
// TODO(ST): figure out of this protections are necessary - is this happening?
|
||||
// `.manage()` can deal with duplication, but maybe there is side-effects?
|
||||
Ok(handler.inner().clone())
|
||||
} else {
|
||||
let handler = Handler {
|
||||
git_file_change_handler: git_file_change::Handler::from_app(app)?,
|
||||
flush_session_handler: flush_session::Handler::from_app(app)?,
|
||||
fetch_gitbutler_handler: fetch_gitbutler_data::Handler::from_app(app)?,
|
||||
push_gitbutler_handler: push_gitbutler_data::Handler::from_app(app)?,
|
||||
analytics_handler: analytics_handler::Handler::from_app(app)?,
|
||||
index_handler: index_handler::Handler::from_app(app)?,
|
||||
|
||||
push_project_to_gitbutler: push_project_to_gitbutler::Handler::from_app(app)?,
|
||||
calculate_vbranches_handler: caltulate_virtual_branches_handler::Handler::from_app(
|
||||
app,
|
||||
)?,
|
||||
calculate_deltas_handler: calculate_deltas_handler::Handler::from_app(app)?,
|
||||
filter_ignored_files_handler: filter_ignored_files::Handler::from_app(app)?,
|
||||
events_sender: app_events::Sender::from_app(app)?,
|
||||
};
|
||||
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
}
|
||||
let app_data_dir = app
|
||||
.path_resolver()
|
||||
.app_data_dir()
|
||||
.context("failed to get app data dir")?;
|
||||
Ok(Handler {
|
||||
git_file_change_handler: git_file_change::Handler::from_app(app, &app_data_dir),
|
||||
flush_session_handler: flush_session::Handler::from_app(app, &app_data_dir),
|
||||
fetch_gitbutler_handler: fetch_gitbutler_data::Handler::from_app(app, &app_data_dir),
|
||||
push_gitbutler_handler: push_gitbutler_data::Handler::from_app(app, &app_data_dir),
|
||||
analytics_handler: analytics_handler::Handler::from_app(app),
|
||||
index_handler: index_handler::Handler::from_app(app, &app_data_dir),
|
||||
push_project_to_gitbutler: push_project_to_gitbutler::Handler::from_app(
|
||||
app,
|
||||
&app_data_dir,
|
||||
),
|
||||
calculate_vbranches_handler: caltulate_virtual_branches_handler::Handler::from_app(app),
|
||||
calculate_deltas_handler: calculate_deltas_handler::Handler::from_app(
|
||||
app,
|
||||
&app_data_dir,
|
||||
),
|
||||
filter_ignored_files_handler: filter_ignored_files::Handler::from_app(app),
|
||||
events_sender: app_events::Sender::from_app(app),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,20 +12,14 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(value: &AppHandle) -> Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = value.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else {
|
||||
let client = value
|
||||
.try_state::<analytics::Client>()
|
||||
.map_or(analytics::Client::default(), |client| {
|
||||
client.inner().clone()
|
||||
});
|
||||
let users = value.state::<users::Controller>().inner().clone();
|
||||
let handler = Handler { users, client };
|
||||
value.manage(handler.clone());
|
||||
Ok(handler)
|
||||
}
|
||||
pub fn from_app(app: &AppHandle) -> Self {
|
||||
let client = app
|
||||
.try_state::<analytics::Client>()
|
||||
.map_or(analytics::Client::default(), |client| {
|
||||
client.inner().clone()
|
||||
});
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
Handler { users, client }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{path, vec};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
@ -18,19 +19,11 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else if let Some(app_data_dir) = app.path_resolver().app_data_dir() {
|
||||
let handler = Self {
|
||||
local_data_dir: app_data_dir,
|
||||
projects: app.state::<projects::Controller>().inner().clone(),
|
||||
users: app.state::<users::Controller>().inner().clone(),
|
||||
};
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("failed to get app data dir"))
|
||||
pub fn from_app(app: &AppHandle, app_data_dir: impl Into<PathBuf>) -> Self {
|
||||
Self {
|
||||
local_data_dir: app_data_dir.into(),
|
||||
projects: app.state::<projects::Controller>().inner().clone(),
|
||||
users: app.state::<users::Controller>().inner().clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,20 +24,13 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> std::result::Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else {
|
||||
let vbranches = app.state::<virtual_branches::Controller>().inner().clone();
|
||||
let proxy = app.state::<assets::Proxy>().inner().clone();
|
||||
let inner = InnerHandler {
|
||||
vbranch_controller: vbranches,
|
||||
assets_proxy: proxy,
|
||||
};
|
||||
let handler = Handler::new(inner);
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
}
|
||||
pub fn from_app(app: &AppHandle) -> Self {
|
||||
let vbranches = app.state::<virtual_branches::Controller>().inner().clone();
|
||||
let proxy = app.state::<assets::Proxy>().inner().clone();
|
||||
Handler::new(InnerHandler {
|
||||
vbranch_controller: vbranches,
|
||||
assets_proxy: proxy,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{path, sync::Arc, time};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
@ -13,18 +14,10 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> std::result::Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else if let Some(app_data_dir) = app.path_resolver().app_data_dir() {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
let handler = Handler::new(app_data_dir, projects, users);
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("failed to get app data dir"))
|
||||
}
|
||||
pub fn from_app(app: &AppHandle, app_data_dir: impl Into<PathBuf>) -> Self {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
Handler::new(app_data_dir.into(), projects, users)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,16 +22,10 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> std::result::Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let inner = InnerHandler { projects };
|
||||
let handler = Handler::new(inner);
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
}
|
||||
pub fn from_app(app: &AppHandle) -> Self {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let inner = InnerHandler { projects };
|
||||
Handler::new(inner)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{path, sync::Arc};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
@ -15,25 +16,17 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> std::result::Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else if let Some(app_data_dir) = app.path_resolver().app_data_dir() {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
// TODO(ST): see if one day this can be more self-contained so all this nesting isn't required
|
||||
let inner = HandlerInner {
|
||||
local_data_dir: app_data_dir,
|
||||
project_store: projects,
|
||||
users,
|
||||
};
|
||||
let handler = Handler {
|
||||
inner: Arc::new(inner.into()),
|
||||
};
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("failed to get app data dir"))
|
||||
pub fn from_app(app: &AppHandle, app_data_dir: impl Into<PathBuf>) -> Self {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
// TODO(ST): see if one day this can be more self-contained so all this nesting isn't required
|
||||
let inner = HandlerInner {
|
||||
local_data_dir: app_data_dir.into(),
|
||||
project_store: projects,
|
||||
users,
|
||||
};
|
||||
Handler {
|
||||
inner: Arc::new(inner.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use gitbutler_core::{
|
||||
@ -19,18 +20,10 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(value: &AppHandle) -> Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = value.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else if let Some(app_data_dir) = value.path_resolver().app_data_dir() {
|
||||
let projects = value.state::<projects::Controller>().inner().clone();
|
||||
let users = value.state::<users::Controller>().inner().clone();
|
||||
let handler = Handler::new(app_data_dir, projects, users);
|
||||
value.manage(handler.clone());
|
||||
Ok(handler)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("failed to get app data dir"))
|
||||
}
|
||||
pub fn from_app(app: &AppHandle, app_data_dir: impl Into<PathBuf>) -> Self {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
Handler::new(app_data_dir.into(), projects, users)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use gitbutler_core::{
|
||||
@ -22,25 +23,17 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else if let Some(app_data_dir) = app.path_resolver().app_data_dir() {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
let sessions_database = app.state::<sessions::Database>().inner().clone();
|
||||
let deltas_database = app.state::<deltas::Database>().inner().clone();
|
||||
let handler = Handler {
|
||||
local_data_dir: app_data_dir,
|
||||
projects,
|
||||
users,
|
||||
sessions_database,
|
||||
deltas_database,
|
||||
};
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("failed to get app data dir"))
|
||||
pub fn from_app(app: &AppHandle, app_data_dir: impl Into<PathBuf>) -> Self {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
let sessions_database = app.state::<sessions::Database>().inner().clone();
|
||||
let deltas_database = app.state::<deltas::Database>().inner().clone();
|
||||
Handler {
|
||||
local_data_dir: app_data_dir.into(),
|
||||
projects,
|
||||
users,
|
||||
sessions_database,
|
||||
deltas_database,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{
|
||||
path,
|
||||
sync::{Arc, Mutex, TryLockError},
|
||||
@ -18,24 +19,16 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(value: &AppHandle) -> std::result::Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = value.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else if let Some(app_data_dir) = value.path_resolver().app_data_dir() {
|
||||
let projects = value.state::<projects::Controller>().inner().clone();
|
||||
let users = value.state::<users::Controller>().inner().clone();
|
||||
let inner = HandlerInner {
|
||||
local_data_dir: app_data_dir,
|
||||
projects,
|
||||
users,
|
||||
};
|
||||
let handler = Handler {
|
||||
inner: Arc::new(inner.into()),
|
||||
};
|
||||
value.manage(handler.clone());
|
||||
Ok(handler)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("failed to get app data dir"))
|
||||
pub fn from_app(app: &AppHandle, app_data_dir: impl Into<PathBuf>) -> Self {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
let inner = HandlerInner {
|
||||
local_data_dir: app_data_dir.into(),
|
||||
projects,
|
||||
users,
|
||||
};
|
||||
Handler {
|
||||
inner: Arc::new(inner.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{path, sync::Arc, time};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
@ -20,18 +21,10 @@ pub struct Handler {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn from_app(app: &AppHandle) -> std::result::Result<Self, anyhow::Error> {
|
||||
if let Some(handler) = app.try_state::<Handler>() {
|
||||
Ok(handler.inner().clone())
|
||||
} else if let Some(app_data_dir) = app.path_resolver().app_data_dir() {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
let handler = Handler::new(app_data_dir, projects, users, 1000);
|
||||
app.manage(handler.clone());
|
||||
Ok(handler)
|
||||
} else {
|
||||
Err(anyhow::anyhow!("failed to get app data dir"))
|
||||
}
|
||||
pub fn from_app(app: &AppHandle, app_data_dir: impl Into<PathBuf>) -> Self {
|
||||
let projects = app.state::<projects::Controller>().inner().clone();
|
||||
let users = app.state::<users::Controller>().inner().clone();
|
||||
Handler::new(app_data_dir.into(), projects, users, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user