mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-08 10:58:33 +03:00
chore: refactor Controller initialization to use from
method instead of try_from
for improved code readability and consistency
This commit is contained in:
parent
fff966a063
commit
7dc9f45d1a
@ -22,7 +22,7 @@ impl App {
|
|||||||
|
|
||||||
let storage = storage::Storage::from(&local_data_dir);
|
let storage = storage::Storage::from(&local_data_dir);
|
||||||
let users_storage = users::Controller::from(&storage);
|
let users_storage = users::Controller::from(&storage);
|
||||||
let projects_storage = projects::Controller::try_from(&local_data_dir)?;
|
let projects_storage = projects::Controller::from(&local_data_dir);
|
||||||
let projects = projects_storage.list().context("failed to list projects")?;
|
let projects = projects_storage.list().context("failed to list projects")?;
|
||||||
|
|
||||||
let project = projects
|
let project = projects
|
||||||
|
@ -46,13 +46,13 @@ impl TryFrom<&AppHandle> for App {
|
|||||||
fn try_from(value: &AppHandle) -> std::result::Result<Self, Self::Error> {
|
fn try_from(value: &AppHandle) -> std::result::Result<Self, Self::Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_data_dir: DataDir::try_from(value)?,
|
local_data_dir: DataDir::try_from(value)?,
|
||||||
keys: keys::Controller::try_from(value)?,
|
keys: keys::Controller::from(value),
|
||||||
projects: projects::Controller::try_from(value)?,
|
projects: projects::Controller::try_from(value)?,
|
||||||
users: users::Controller::try_from(value)?,
|
users: users::Controller::from(value),
|
||||||
watchers: value.state::<watcher::Watchers>().inner().clone(),
|
watchers: value.state::<watcher::Watchers>().inner().clone(),
|
||||||
sessions_database: sessions::Database::try_from(value)?,
|
sessions_database: sessions::Database::from(value),
|
||||||
deltas_database: deltas::Database::try_from(value)?,
|
deltas_database: deltas::Database::from(value),
|
||||||
bookmarks_database: bookmarks::Database::try_from(value)?,
|
bookmarks_database: bookmarks::Database::from(value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,12 +127,10 @@ fn main() {
|
|||||||
.expect("failed to initialize virtual branches controller");
|
.expect("failed to initialize virtual branches controller");
|
||||||
app_handle.manage(vbranch_contoller);
|
app_handle.manage(vbranch_contoller);
|
||||||
|
|
||||||
let keys_controller = keys::Controller::try_from(&app_handle)
|
let keys_controller = keys::Controller::from(&app_handle);
|
||||||
.expect("failed to initialize keys controller");
|
|
||||||
app_handle.manage(keys_controller);
|
app_handle.manage(keys_controller);
|
||||||
|
|
||||||
let users_controller = users::Controller::try_from(&app_handle)
|
let users_controller = users::Controller::from(&app_handle);
|
||||||
.expect("failed to initialize users controller");
|
|
||||||
if let Some(user) = users_controller.get_user().context("failed to get user")? {
|
if let Some(user) = users_controller.get_user().context("failed to get user")? {
|
||||||
sentry::configure_scope(|scope| scope.set_user(Some(user.clone().into())));
|
sentry::configure_scope(|scope| scope.set_user(Some(user.clone().into())));
|
||||||
}
|
}
|
||||||
|
@ -174,9 +174,7 @@ pub async fn upsert_bookmark(
|
|||||||
})?;
|
})?;
|
||||||
let bookmark = bookmarks::Bookmark {
|
let bookmark = bookmarks::Bookmark {
|
||||||
project_id,
|
project_id,
|
||||||
timestamp_ms: timestamp_ms
|
timestamp_ms: timestamp_ms.into(),
|
||||||
.try_into()
|
|
||||||
.context("failed to convert timestamp")?,
|
|
||||||
created_timestamp_ms: now,
|
created_timestamp_ms: now,
|
||||||
updated_timestamp_ms: now,
|
updated_timestamp_ms: now,
|
||||||
note,
|
note,
|
||||||
|
@ -114,11 +114,11 @@ impl From<git2::IndexEntry> for IndexEntry {
|
|||||||
fn from(value: git2::IndexEntry) -> Self {
|
fn from(value: git2::IndexEntry) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ctime: FileTime::from_unix_time(
|
ctime: FileTime::from_unix_time(
|
||||||
i64::try_from(value.ctime.seconds()).unwrap(),
|
i64::from(value.ctime.seconds()),
|
||||||
value.ctime.nanoseconds(),
|
value.ctime.nanoseconds(),
|
||||||
),
|
),
|
||||||
mtime: FileTime::from_unix_time(
|
mtime: FileTime::from_unix_time(
|
||||||
i64::try_from(value.mtime.seconds()).unwrap(),
|
i64::from(value.mtime.seconds()),
|
||||||
value.mtime.nanoseconds(),
|
value.mtime.nanoseconds(),
|
||||||
),
|
),
|
||||||
dev: value.dev,
|
dev: value.dev,
|
||||||
|
@ -55,7 +55,7 @@ impl TryFrom<&AppHandle> for HandlerInner {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_data_dir,
|
local_data_dir,
|
||||||
projects: projects::Controller::try_from(value)?,
|
projects: projects::Controller::try_from(value)?,
|
||||||
users: users::Controller::try_from(value)?,
|
users: users::Controller::from(value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,9 @@ impl TryFrom<&AppHandle> for HandlerInner {
|
|||||||
fn try_from(value: &AppHandle) -> std::result::Result<Self, Self::Error> {
|
fn try_from(value: &AppHandle) -> std::result::Result<Self, Self::Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_data_dir: DataDir::try_from(value)?,
|
local_data_dir: DataDir::try_from(value)?,
|
||||||
keys: keys::Controller::try_from(value)?,
|
keys: keys::Controller::from(value),
|
||||||
projects: projects::Controller::try_from(value)?,
|
projects: projects::Controller::try_from(value)?,
|
||||||
users: users::Controller::try_from(value)?,
|
users: users::Controller::from(value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ impl TryFrom<&AppHandle> for Handler {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_data_dir: DataDir::try_from(value)?,
|
local_data_dir: DataDir::try_from(value)?,
|
||||||
projects: projects::Controller::try_from(value)?,
|
projects: projects::Controller::try_from(value)?,
|
||||||
users: users::Controller::try_from(value)?,
|
users: users::Controller::from(value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ impl TryFrom<&AppHandle> for Handler {
|
|||||||
local_data_dir: DataDir::try_from(value)?,
|
local_data_dir: DataDir::try_from(value)?,
|
||||||
projects: projects::Controller::try_from(value)?,
|
projects: projects::Controller::try_from(value)?,
|
||||||
users: users::Controller::from(value),
|
users: users::Controller::from(value),
|
||||||
sessions_database: sessions::Database::try_from(value)?,
|
sessions_database: sessions::Database::from(value),
|
||||||
deltas_database: deltas::Database::try_from(value)?,
|
deltas_database: deltas::Database::from(value),
|
||||||
bookmarks_database: bookmarks::Database::try_from(value)?,
|
bookmarks_database: bookmarks::Database::from(value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ impl TryFrom<&AppHandle> for Handler {
|
|||||||
push_gitbutler_handler: push_gitbutler_data::Handler::try_from(value)?,
|
push_gitbutler_handler: push_gitbutler_data::Handler::try_from(value)?,
|
||||||
fetch_project_handler: fetch_project_data::Handler::try_from(value)?,
|
fetch_project_handler: fetch_project_data::Handler::try_from(value)?,
|
||||||
fetch_gitbutler_handler: fetch_gitbutler_data::Handler::try_from(value)?,
|
fetch_gitbutler_handler: fetch_gitbutler_data::Handler::try_from(value)?,
|
||||||
analytics_handler: analytics_handler::Handler::try_from(value)?,
|
analytics_handler: analytics_handler::Handler::from(value),
|
||||||
push_project_to_gitbutler: push_project_to_gitbutler::Handler::try_from(value)?,
|
push_project_to_gitbutler: push_project_to_gitbutler::Handler::try_from(value)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ impl TryFrom<&AppHandle> for Handler {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_data_dir: DataDir::try_from(value)?,
|
local_data_dir: DataDir::try_from(value)?,
|
||||||
projects: projects::Controller::try_from(value)?,
|
projects: projects::Controller::try_from(value)?,
|
||||||
users: users::Controller::try_from(value)?,
|
users: users::Controller::from(value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ impl TryFrom<&AppHandle> for HandlerInner {
|
|||||||
Ok(Self::new(
|
Ok(Self::new(
|
||||||
DataDir::try_from(value)?,
|
DataDir::try_from(value)?,
|
||||||
projects::Controller::try_from(value)?,
|
projects::Controller::try_from(value)?,
|
||||||
users::Controller::try_from(value)?,
|
users::Controller::from(value),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ impl TryFrom<&AppHandle> for Handler {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_data_dir: DataDir::try_from(value)?,
|
local_data_dir: DataDir::try_from(value)?,
|
||||||
projects: projects::Controller::try_from(value)?,
|
projects: projects::Controller::try_from(value)?,
|
||||||
users: users::Controller::try_from(value)?,
|
users: users::Controller::from(value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user