mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-25 02:26:14 +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())
|
|
||||||
} else {
|
|
||||||
let sender = Sender {
|
|
||||||
app_handle: app.clone(),
|
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(
|
||||||
|
|
||||||
push_project_to_gitbutler: push_project_to_gitbutler::Handler::from_app(app)?,
|
|
||||||
calculate_vbranches_handler: caltulate_virtual_branches_handler::Handler::from_app(
|
|
||||||
app,
|
app,
|
||||||
)?,
|
&app_data_dir,
|
||||||
calculate_deltas_handler: calculate_deltas_handler::Handler::from_app(app)?,
|
),
|
||||||
filter_ignored_files_handler: filter_ignored_files::Handler::from_app(app)?,
|
calculate_vbranches_handler: caltulate_virtual_branches_handler::Handler::from_app(app),
|
||||||
events_sender: app_events::Sender::from_app(app)?,
|
calculate_deltas_handler: calculate_deltas_handler::Handler::from_app(
|
||||||
};
|
app,
|
||||||
|
&app_data_dir,
|
||||||
app.manage(handler.clone());
|
),
|
||||||
Ok(handler)
|
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 {
|
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())
|
|
||||||
} else {
|
|
||||||
let client = value
|
|
||||||
.try_state::<analytics::Client>()
|
.try_state::<analytics::Client>()
|
||||||
.map_or(analytics::Client::default(), |client| {
|
.map_or(analytics::Client::default(), |client| {
|
||||||
client.inner().clone()
|
client.inner().clone()
|
||||||
});
|
});
|
||||||
let users = value.state::<users::Controller>().inner().clone();
|
let users = app.state::<users::Controller>().inner().clone();
|
||||||
let handler = Handler { users, client };
|
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() {
|
|
||||||
let handler = Self {
|
|
||||||
local_data_dir: app_data_dir,
|
|
||||||
projects: app.state::<projects::Controller>().inner().clone(),
|
projects: app.state::<projects::Controller>().inner().clone(),
|
||||||
users: app.state::<users::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>() {
|
|
||||||
Ok(handler.inner().clone())
|
|
||||||
} else {
|
|
||||||
let vbranches = app.state::<virtual_branches::Controller>().inner().clone();
|
let vbranches = app.state::<virtual_branches::Controller>().inner().clone();
|
||||||
let proxy = app.state::<assets::Proxy>().inner().clone();
|
let proxy = app.state::<assets::Proxy>().inner().clone();
|
||||||
let inner = InnerHandler {
|
Handler::new(InnerHandler {
|
||||||
vbranch_controller: vbranches,
|
vbranch_controller: vbranches,
|
||||||
assets_proxy: proxy,
|
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>() {
|
|
||||||
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 projects = app.state::<projects::Controller>().inner().clone();
|
||||||
let users = app.state::<users::Controller>().inner().clone();
|
let users = app.state::<users::Controller>().inner().clone();
|
||||||
let handler = Handler::new(app_data_dir, projects, users);
|
Handler::new(app_data_dir.into(), 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>() {
|
|
||||||
Ok(handler.inner().clone())
|
|
||||||
} else {
|
|
||||||
let projects = app.state::<projects::Controller>().inner().clone();
|
let projects = app.state::<projects::Controller>().inner().clone();
|
||||||
let inner = InnerHandler { projects };
|
let inner = InnerHandler { projects };
|
||||||
let handler = Handler::new(inner);
|
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>() {
|
|
||||||
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 projects = app.state::<projects::Controller>().inner().clone();
|
||||||
let users = app.state::<users::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
|
// TODO(ST): see if one day this can be more self-contained so all this nesting isn't required
|
||||||
let inner = HandlerInner {
|
let inner = HandlerInner {
|
||||||
local_data_dir: app_data_dir,
|
local_data_dir: app_data_dir.into(),
|
||||||
project_store: projects,
|
project_store: projects,
|
||||||
users,
|
users,
|
||||||
};
|
};
|
||||||
let handler = Handler {
|
Handler {
|
||||||
inner: Arc::new(inner.into()),
|
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>() {
|
|
||||||
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 projects = app.state::<projects::Controller>().inner().clone();
|
||||||
let users = app.state::<users::Controller>().inner().clone();
|
let users = app.state::<users::Controller>().inner().clone();
|
||||||
let sessions_database = app.state::<sessions::Database>().inner().clone();
|
let sessions_database = app.state::<sessions::Database>().inner().clone();
|
||||||
let deltas_database = app.state::<deltas::Database>().inner().clone();
|
let deltas_database = app.state::<deltas::Database>().inner().clone();
|
||||||
let handler = Handler {
|
Handler {
|
||||||
local_data_dir: app_data_dir,
|
local_data_dir: app_data_dir.into(),
|
||||||
projects,
|
projects,
|
||||||
users,
|
users,
|
||||||
sessions_database,
|
sessions_database,
|
||||||
deltas_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 projects = value.state::<projects::Controller>().inner().clone();
|
|
||||||
let users = value.state::<users::Controller>().inner().clone();
|
|
||||||
let inner = HandlerInner {
|
let inner = HandlerInner {
|
||||||
local_data_dir: app_data_dir,
|
local_data_dir: app_data_dir.into(),
|
||||||
projects,
|
projects,
|
||||||
users,
|
users,
|
||||||
};
|
};
|
||||||
let handler = Handler {
|
Handler {
|
||||||
inner: Arc::new(inner.into()),
|
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>() {
|
|
||||||
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 projects = app.state::<projects::Controller>().inner().clone();
|
||||||
let users = app.state::<users::Controller>().inner().clone();
|
let users = app.state::<users::Controller>().inner().clone();
|
||||||
let handler = Handler::new(app_data_dir, projects, users, 1000);
|
Handler::new(app_data_dir.into(), 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