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