mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-23 20:54:50 +03:00
cargo fmt
This commit is contained in:
parent
ecf3194125
commit
e79c4f9f5f
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
tauri_build::build()
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
use std::{collections::HashMap, sync, ops};
|
||||
use std::{collections::HashMap, ops, sync};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use crossbeam_channel::{bounded, Sender};
|
||||
|
||||
use crate::{events, projects, search, storage, users, database, watcher, sessions, deltas, pty, project_repository::{self, activity}, files, bookmarks, gb_repository};
|
||||
use crate::{
|
||||
bookmarks, database, deltas, events, files, gb_repository,
|
||||
project_repository::{self, activity},
|
||||
projects, pty, search, sessions, storage, users, watcher,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct App {
|
||||
@ -31,7 +35,7 @@ pub enum AddProjectError {
|
||||
#[error("{0}")]
|
||||
OpenError(projects::CreateError),
|
||||
#[error("{0}")]
|
||||
Other(anyhow::Error)
|
||||
Other(anyhow::Error),
|
||||
}
|
||||
|
||||
impl App {
|
||||
@ -70,14 +74,10 @@ impl App {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn init_project(
|
||||
&self,
|
||||
project: &projects::Project,
|
||||
) -> Result<()> {
|
||||
self.start_watcher(project)
|
||||
.with_context(|| {
|
||||
format!("failed to start watcher for project {}", project.id.clone())
|
||||
})?;
|
||||
pub fn init_project(&self, project: &projects::Project) -> Result<()> {
|
||||
self.start_watcher(project).with_context(|| {
|
||||
format!("failed to start watcher for project {}", project.id.clone())
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -115,21 +115,26 @@ impl App {
|
||||
)
|
||||
.expect("failed to open git repository");
|
||||
|
||||
let iterator = gb_repository.get_sessions_iterator().expect("failed to get sessions iterator");
|
||||
let iterator = gb_repository
|
||||
.get_sessions_iterator()
|
||||
.expect("failed to get sessions iterator");
|
||||
for session in iterator {
|
||||
let session = session.expect("failed to get session");
|
||||
|
||||
if let Err(e) = proxy_watchers.lock().unwrap().get(&project.id).unwrap().send(watcher::Event::Session(session.clone())) {
|
||||
if let Err(e) = proxy_watchers
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(&project.id)
|
||||
.unwrap()
|
||||
.send(watcher::Event::Session(session.clone()))
|
||||
{
|
||||
log::error!("failed to send session event: {:#}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn start_watcher(
|
||||
&self,
|
||||
project: &projects::Project,
|
||||
) -> Result<()> {
|
||||
fn start_watcher(&self, project: &projects::Project) -> Result<()> {
|
||||
let project = project.clone();
|
||||
let users_storage = self.users_storage.clone();
|
||||
let projects_storage = self.projects_storage.clone();
|
||||
@ -186,7 +191,13 @@ impl App {
|
||||
}
|
||||
|
||||
fn send_event(&self, project_id: &str, event: watcher::Event) -> Result<()> {
|
||||
self.proxy_watchers.lock().unwrap().get(project_id).unwrap().send(event).context("failed to send event to proxy")
|
||||
self.proxy_watchers
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(project_id)
|
||||
.unwrap()
|
||||
.send(event)
|
||||
.context("failed to send event to proxy")
|
||||
}
|
||||
|
||||
fn stop_watcher(&self, project_id: &str) -> Result<()> {
|
||||
@ -210,29 +221,27 @@ impl App {
|
||||
self.users_storage.delete()
|
||||
}
|
||||
|
||||
pub fn add_project(
|
||||
&self,
|
||||
path: &str,
|
||||
) -> Result<projects::Project, AddProjectError> {
|
||||
let all_projects = self.projects_storage.list_projects().map_err(AddProjectError::Other
|
||||
)?;
|
||||
pub fn add_project(&self, path: &str) -> Result<projects::Project, AddProjectError> {
|
||||
let all_projects = self
|
||||
.projects_storage
|
||||
.list_projects()
|
||||
.map_err(AddProjectError::Other)?;
|
||||
|
||||
if all_projects.iter().any(|project| project.path == path) {
|
||||
return Err(AddProjectError::ProjectAlreadyExists);
|
||||
}
|
||||
|
||||
let project =
|
||||
projects::Project::from_path(path.to_string()).map_err(AddProjectError::OpenError
|
||||
)?;
|
||||
projects::Project::from_path(path.to_string()).map_err(AddProjectError::OpenError)?;
|
||||
|
||||
self.projects_storage
|
||||
.add_project(&project)
|
||||
.context("failed to add project").map_err(AddProjectError::Other
|
||||
)?;
|
||||
.context("failed to add project")
|
||||
.map_err(AddProjectError::Other)?;
|
||||
|
||||
self.init_project(&project)
|
||||
.context("failed to init project").map_err(AddProjectError::Other
|
||||
)?;
|
||||
.context("failed to init project")
|
||||
.map_err(AddProjectError::Other)?;
|
||||
|
||||
Ok(project)
|
||||
}
|
||||
@ -274,7 +283,6 @@ impl App {
|
||||
log::error!("failed to remove project dir {}: {}", project.id, e);
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
None => Ok(()),
|
||||
@ -286,7 +294,8 @@ impl App {
|
||||
project_id: &str,
|
||||
earliest_timestamp_ms: Option<u128>,
|
||||
) -> Result<Vec<sessions::Session>> {
|
||||
self.sessions_database.list_by_project_id(project_id, earliest_timestamp_ms)
|
||||
self.sessions_database
|
||||
.list_by_project_id(project_id, earliest_timestamp_ms)
|
||||
}
|
||||
|
||||
pub fn list_session_files(
|
||||
@ -295,7 +304,8 @@ impl App {
|
||||
session_id: &str,
|
||||
paths: Option<Vec<&str>>,
|
||||
) -> Result<HashMap<String, String>> {
|
||||
self.files_database.list_by_project_id_session_id(project_id, session_id, paths)
|
||||
self.files_database
|
||||
.list_by_project_id_session_id(project_id, session_id, paths)
|
||||
}
|
||||
|
||||
pub fn upsert_bookmark(&self, bookmark: &bookmarks::Bookmark) -> Result<()> {
|
||||
@ -307,24 +317,40 @@ impl App {
|
||||
)
|
||||
.context("failed to open repository")?;
|
||||
|
||||
|
||||
let session = gb_repository.get_or_create_current_session().context("failed to get or create current session")?;
|
||||
let writer = sessions::Writer::open(&gb_repository, &session).context("failed to open session writer")?;
|
||||
writer.write_bookmark(bookmark).context("failed to write bookmark")?;
|
||||
let session = gb_repository
|
||||
.get_or_create_current_session()
|
||||
.context("failed to get or create current session")?;
|
||||
let writer = sessions::Writer::open(&gb_repository, &session)
|
||||
.context("failed to open session writer")?;
|
||||
writer
|
||||
.write_bookmark(bookmark)
|
||||
.context("failed to write bookmark")?;
|
||||
// let updated = self.bookmarks_database.upsert(bookmark).context("failed to upsert bookmark")?;
|
||||
|
||||
// if let Some(updated) = updated.as_ref() {
|
||||
if let Err(e) = self.proxy_watchers.lock().unwrap().get(&bookmark.project_id).unwrap().send(watcher::Event::Bookmark(bookmark.clone())) {
|
||||
log::error!("failed to send session event: {:#}", e);
|
||||
}
|
||||
if let Err(e) = self
|
||||
.proxy_watchers
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(&bookmark.project_id)
|
||||
.unwrap()
|
||||
.send(watcher::Event::Bookmark(bookmark.clone()))
|
||||
{
|
||||
log::error!("failed to send session event: {:#}", e);
|
||||
}
|
||||
Ok(())
|
||||
// }
|
||||
|
||||
// Ok(updated)
|
||||
}
|
||||
|
||||
pub fn list_bookmarks(&self, project_id: &str, range: Option<ops::Range<u128>>) -> Result<Vec<bookmarks::Bookmark>> {
|
||||
self.bookmarks_database.list_by_project_id(project_id, range)
|
||||
pub fn list_bookmarks(
|
||||
&self,
|
||||
project_id: &str,
|
||||
range: Option<ops::Range<u128>>,
|
||||
) -> Result<Vec<bookmarks::Bookmark>> {
|
||||
self.bookmarks_database
|
||||
.list_by_project_id(project_id, range)
|
||||
}
|
||||
|
||||
pub fn list_session_deltas(
|
||||
@ -333,10 +359,10 @@ impl App {
|
||||
session_id: &str,
|
||||
paths: Option<Vec<&str>>,
|
||||
) -> Result<HashMap<String, Vec<deltas::Delta>>> {
|
||||
self.deltas_database.list_by_project_id_session_id(project_id, session_id, paths)
|
||||
self.deltas_database
|
||||
.list_by_project_id_session_id(project_id, session_id, paths)
|
||||
}
|
||||
|
||||
|
||||
pub fn git_activity(
|
||||
&self,
|
||||
project_id: &str,
|
||||
@ -522,9 +548,12 @@ impl App {
|
||||
}
|
||||
|
||||
pub fn delete_all_data(&self) -> Result<()> {
|
||||
self.searcher.delete_all_data().context("failed to delete search data")?;
|
||||
self.searcher
|
||||
.delete_all_data()
|
||||
.context("failed to delete search data")?;
|
||||
for project in self.list_projects()? {
|
||||
self.delete_project(&project.id).context("failed to delete project")?;
|
||||
self.delete_project(&project.id)
|
||||
.context("failed to delete project")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -808,14 +808,8 @@ fn add_wd_path(
|
||||
// create a new IndexEntry from the file metadata
|
||||
index
|
||||
.add(&git2::IndexEntry {
|
||||
ctime: git2::IndexTime::new(
|
||||
ctime.seconds().try_into()?,
|
||||
ctime.nanoseconds(),
|
||||
),
|
||||
mtime: git2::IndexTime::new(
|
||||
mtime.seconds().try_into()?,
|
||||
mtime.nanoseconds(),
|
||||
),
|
||||
ctime: git2::IndexTime::new(ctime.seconds().try_into()?, ctime.nanoseconds()),
|
||||
mtime: git2::IndexTime::new(mtime.seconds().try_into()?, mtime.nanoseconds()),
|
||||
dev: metadata.dev().try_into()?,
|
||||
ino: metadata.ino().try_into()?,
|
||||
mode: 33188,
|
||||
@ -899,14 +893,8 @@ fn add_log_path(
|
||||
let ctime = FileTime::from_creation_time(&metadata).unwrap_or(mtime);
|
||||
|
||||
index.add(&git2::IndexEntry {
|
||||
ctime: git2::IndexTime::new(
|
||||
ctime.seconds().try_into()?,
|
||||
ctime.nanoseconds(),
|
||||
),
|
||||
mtime: git2::IndexTime::new(
|
||||
mtime.seconds().try_into()?,
|
||||
mtime.nanoseconds(),
|
||||
),
|
||||
ctime: git2::IndexTime::new(ctime.seconds().try_into()?, ctime.nanoseconds()),
|
||||
mtime: git2::IndexTime::new(mtime.seconds().try_into()?, mtime.nanoseconds()),
|
||||
dev: metadata.dev().try_into()?,
|
||||
ino: metadata.ino().try_into()?,
|
||||
mode: metadata.mode(),
|
||||
@ -959,14 +947,8 @@ fn add_session_path(
|
||||
// create a new IndexEntry from the file metadata
|
||||
index
|
||||
.add(&git2::IndexEntry {
|
||||
ctime: git2::IndexTime::new(
|
||||
ctime.seconds().try_into()?,
|
||||
ctime.nanoseconds(),
|
||||
),
|
||||
mtime: git2::IndexTime::new(
|
||||
mtime.seconds().try_into()?,
|
||||
mtime.nanoseconds(),
|
||||
),
|
||||
ctime: git2::IndexTime::new(ctime.seconds().try_into()?, ctime.nanoseconds()),
|
||||
mtime: git2::IndexTime::new(mtime.seconds().try_into()?, mtime.nanoseconds()),
|
||||
dev: metadata.dev().try_into()?,
|
||||
ino: metadata.ino().try_into()?,
|
||||
mode: metadata.mode(),
|
||||
|
@ -67,12 +67,8 @@ fn test_get_current_session_writer_should_use_existing_session() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let current_session_1 = gb_repo.get_or_create_current_session()?;
|
||||
let current_session_2 = gb_repo.get_or_create_current_session()?;
|
||||
@ -90,12 +86,8 @@ fn test_must_not_return_init_session() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
assert!(gb_repo.get_current_session()?.is_none());
|
||||
|
||||
@ -114,12 +106,8 @@ fn test_must_not_flush_without_current_session() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let session = gb_repo.flush()?;
|
||||
assert!(session.is_none());
|
||||
@ -143,12 +131,7 @@ fn test_init_on_non_empty_repository() -> Result<()> {
|
||||
std::fs::write(repository.path().parent().unwrap().join("test.txt"), "test")?;
|
||||
commit_all(&repository)?;
|
||||
|
||||
gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -173,12 +156,8 @@ fn test_flush_on_existing_repository() -> Result<()> {
|
||||
user_store.clone(),
|
||||
)?;
|
||||
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
gb_repo.get_or_create_current_session()?;
|
||||
gb_repo.flush()?;
|
||||
@ -195,12 +174,8 @@ fn test_must_flush_current_session() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
gb_repo.get_or_create_current_session()?;
|
||||
|
||||
@ -221,12 +196,8 @@ fn test_list_deltas_from_current_session() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let current_session = gb_repo.get_or_create_current_session()?;
|
||||
let writer = sessions::Writer::open(&gb_repo, ¤t_session)?;
|
||||
@ -261,12 +232,8 @@ fn test_list_deltas_from_flushed_session() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let current_session = gb_repo.get_or_create_current_session()?;
|
||||
let writer = sessions::Writer::open(&gb_repo, ¤t_session)?;
|
||||
@ -309,12 +276,8 @@ fn test_list_files_from_current_session() -> Result<()> {
|
||||
"Hello World",
|
||||
)?;
|
||||
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let session = gb_repo.get_or_create_current_session()?;
|
||||
|
||||
@ -343,12 +306,8 @@ fn test_list_files_from_flushed_session() -> Result<()> {
|
||||
"Hello World",
|
||||
)?;
|
||||
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
gb_repo.get_or_create_current_session()?;
|
||||
let session = gb_repo.flush()?.unwrap();
|
||||
@ -421,12 +380,8 @@ fn test_remote_syncronization() -> Result<()> {
|
||||
api: Some(api_project),
|
||||
..project_two.clone()
|
||||
})?;
|
||||
let gb_repo_two = gb_repository::Repository::open(
|
||||
gb_repos_path,
|
||||
project_two.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo_two =
|
||||
gb_repository::Repository::open(gb_repos_path, project_two.id, project_store, user_store)?;
|
||||
gb_repo_two.fetch()?;
|
||||
// now it should have the session from the first local project synced
|
||||
let sessions_two = gb_repo_two
|
||||
@ -499,12 +454,8 @@ fn test_remote_sync_order() -> Result<()> {
|
||||
api: Some(api_project),
|
||||
..project_two.clone()
|
||||
})?;
|
||||
let gb_repo_two = gb_repository::Repository::open(
|
||||
gb_repos_path,
|
||||
project_two.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo_two =
|
||||
gb_repository::Repository::open(gb_repos_path, project_two.id, project_store, user_store)?;
|
||||
|
||||
// create session in the first project
|
||||
gb_repo_one.get_or_create_current_session()?;
|
||||
|
@ -5,21 +5,21 @@ mod app;
|
||||
mod bookmarks;
|
||||
mod database;
|
||||
mod deltas;
|
||||
mod sessions;
|
||||
mod events;
|
||||
mod files;
|
||||
mod fs;
|
||||
mod gb_repository;
|
||||
mod project_repository;
|
||||
mod projects;
|
||||
mod pty;
|
||||
mod reader;
|
||||
mod search;
|
||||
mod sessions;
|
||||
mod storage;
|
||||
mod users;
|
||||
mod watcher;
|
||||
mod reader;
|
||||
mod writer;
|
||||
mod zip;
|
||||
mod events;
|
||||
mod fs;
|
||||
mod storage;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
@ -45,7 +45,6 @@ pub enum Error {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
|
||||
impl Serialize for Error {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -68,7 +67,9 @@ impl From<anyhow::Error> for Error {
|
||||
impl From<app::AddProjectError> for Error {
|
||||
fn from(e: app::AddProjectError) -> Self {
|
||||
match e {
|
||||
app::AddProjectError::ProjectAlreadyExists => Error::Message("Project already exists".to_string()),
|
||||
app::AddProjectError::ProjectAlreadyExists => {
|
||||
Error::Message("Project already exists".to_string())
|
||||
}
|
||||
app::AddProjectError::OpenError(e) => Error::Message(e.to_string()),
|
||||
app::AddProjectError::Other(e) => e.into(),
|
||||
}
|
||||
@ -125,9 +126,16 @@ async fn get_project_archive_path(
|
||||
) -> Result<String, Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let project = app
|
||||
.get_project(project_id)?.ok_or_else(|| Error::Message("Project not found".to_string()))?;
|
||||
.get_project(project_id)?
|
||||
.ok_or_else(|| Error::Message("Project not found".to_string()))?;
|
||||
|
||||
let zipper = zip::Zipper::new(handle.path_resolver().app_cache_dir().unwrap().join("archives"));
|
||||
let zipper = zip::Zipper::new(
|
||||
handle
|
||||
.path_resolver()
|
||||
.app_cache_dir()
|
||||
.unwrap()
|
||||
.join("archives"),
|
||||
);
|
||||
let zipped_logs = zipper.zip(project.path)?;
|
||||
Ok(zipped_logs.to_str().unwrap().to_string())
|
||||
}
|
||||
@ -138,18 +146,34 @@ async fn get_project_data_archive_path(
|
||||
handle: tauri::AppHandle,
|
||||
project_id: &str,
|
||||
) -> Result<String, Error> {
|
||||
let zipper = zip::Zipper::new(handle.path_resolver().app_cache_dir().unwrap().join("archives"));
|
||||
let zipped_logs = zipper.zip(handle.path_resolver().app_local_data_dir().unwrap().join("projects").join(project_id))?;
|
||||
let zipper = zip::Zipper::new(
|
||||
handle
|
||||
.path_resolver()
|
||||
.app_cache_dir()
|
||||
.unwrap()
|
||||
.join("archives"),
|
||||
);
|
||||
let zipped_logs = zipper.zip(
|
||||
handle
|
||||
.path_resolver()
|
||||
.app_local_data_dir()
|
||||
.unwrap()
|
||||
.join("projects")
|
||||
.join(project_id),
|
||||
)?;
|
||||
Ok(zipped_logs.to_str().unwrap().to_string())
|
||||
}
|
||||
|
||||
|
||||
#[timed(duration(printer = "debug!"))]
|
||||
#[tauri::command(async)]
|
||||
async fn get_logs_archive_path(
|
||||
handle: tauri::AppHandle,
|
||||
) -> Result<String, Error> {
|
||||
let zipper = zip::Zipper::new(handle.path_resolver().app_cache_dir().unwrap().join("archives"));
|
||||
async fn get_logs_archive_path(handle: tauri::AppHandle) -> Result<String, Error> {
|
||||
let zipper = zip::Zipper::new(
|
||||
handle
|
||||
.path_resolver()
|
||||
.app_cache_dir()
|
||||
.unwrap()
|
||||
.join("archives"),
|
||||
);
|
||||
let zipped_logs = zipper.zip(handle.path_resolver().app_log_dir().unwrap())?;
|
||||
Ok(zipped_logs.to_str().unwrap().to_string())
|
||||
}
|
||||
@ -192,12 +216,7 @@ async fn list_sessions(
|
||||
let app = handle.state::<app::App>();
|
||||
let sessions = app
|
||||
.list_sessions(project_id, earliest_timestamp_ms)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"failed to list sessions for project {}",
|
||||
project_id
|
||||
)
|
||||
})?;
|
||||
.with_context(|| format!("failed to list sessions for project {}", project_id))?;
|
||||
Ok(sessions)
|
||||
}
|
||||
|
||||
@ -263,7 +282,8 @@ async fn update_project(
|
||||
.update_project(&project)
|
||||
.with_context(|| format!("failed to update project {}", project.id))?;
|
||||
if project.api.is_some() {
|
||||
app.git_gb_push(&project.id).with_context(|| format!("failed to push git branch for project {}", &project.id))?;
|
||||
app.git_gb_push(&project.id)
|
||||
.with_context(|| format!("failed to push git branch for project {}", &project.id))?;
|
||||
}
|
||||
Ok(project)
|
||||
}
|
||||
@ -291,7 +311,8 @@ async fn list_projects(handle: tauri::AppHandle) -> Result<Vec<projects::Project
|
||||
async fn delete_project(handle: tauri::AppHandle, id: &str) -> Result<(), Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
|
||||
app.delete_project(id).with_context(|| format!("failed to delete project {}", id))?;
|
||||
app.delete_project(id)
|
||||
.with_context(|| format!("failed to delete project {}", id))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -410,12 +431,9 @@ async fn git_branches(handle: tauri::AppHandle, project_id: &str) -> Result<Vec<
|
||||
#[tauri::command(async)]
|
||||
async fn git_head(handle: tauri::AppHandle, project_id: &str) -> Result<String, Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let head = app.git_head(project_id).with_context(|| {
|
||||
format!(
|
||||
"failed to get git head for project {}",
|
||||
project_id
|
||||
)
|
||||
})?;
|
||||
let head = app
|
||||
.git_head(project_id)
|
||||
.with_context(|| format!("failed to get git head for project {}", project_id))?;
|
||||
Ok(head)
|
||||
}
|
||||
|
||||
@ -487,27 +505,39 @@ async fn upsert_bookmark(
|
||||
project_id: String,
|
||||
timestamp_ms: u64,
|
||||
note: String,
|
||||
deleted: bool
|
||||
deleted: bool,
|
||||
) -> Result<(), Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let now = time::UNIX_EPOCH.elapsed().context("failed to get time")?.as_millis();
|
||||
let now = time::UNIX_EPOCH
|
||||
.elapsed()
|
||||
.context("failed to get time")?
|
||||
.as_millis();
|
||||
let bookmark = bookmarks::Bookmark {
|
||||
project_id,
|
||||
timestamp_ms: timestamp_ms.try_into().context("failed to convert timestamp")?,
|
||||
timestamp_ms: timestamp_ms
|
||||
.try_into()
|
||||
.context("failed to convert timestamp")?,
|
||||
created_timestamp_ms: now,
|
||||
updated_timestamp_ms: now,
|
||||
note,
|
||||
deleted
|
||||
deleted,
|
||||
};
|
||||
app.upsert_bookmark(&bookmark).context("failed to upsert bookmark")?;
|
||||
app.upsert_bookmark(&bookmark)
|
||||
.context("failed to upsert bookmark")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[timed(duration(printer = "debug!"))]
|
||||
#[tauri::command(async)]
|
||||
async fn list_bookmarks(handle: tauri::AppHandle, project_id: &str, range: Option<ops::Range<u128>>) -> Result<Vec<bookmarks::Bookmark>,Error> {
|
||||
async fn list_bookmarks(
|
||||
handle: tauri::AppHandle,
|
||||
project_id: &str,
|
||||
range: Option<ops::Range<u128>>,
|
||||
) -> Result<Vec<bookmarks::Bookmark>, Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let bookmarks = app.list_bookmarks(project_id, range).context("failed to list bookmarks")?;
|
||||
let bookmarks = app
|
||||
.list_bookmarks(project_id, range)
|
||||
.context("failed to list bookmarks")?;
|
||||
Ok(bookmarks)
|
||||
}
|
||||
|
||||
@ -530,7 +560,8 @@ fn main() {
|
||||
|
||||
tauri::Builder::default()
|
||||
.system_tray(tray)
|
||||
.on_system_tray_event(|app_handle, event| if let tauri::SystemTrayEvent::MenuItemClick { id, .. } = event {
|
||||
.on_system_tray_event(|app_handle, event| {
|
||||
if let tauri::SystemTrayEvent::MenuItemClick { id, .. } = event {
|
||||
let app_title = app_handle.package_info().name.clone();
|
||||
let item_handle = app_handle.tray_handle().get_item(&id);
|
||||
match id.as_str() {
|
||||
@ -554,22 +585,24 @@ fn main() {
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_window_event(|event| if let tauri::WindowEvent::CloseRequested { api, .. } = event.event() {
|
||||
hide_window(&event.window().app_handle()).expect("Failed to hide window");
|
||||
api.prevent_close();
|
||||
.on_window_event(|event| {
|
||||
if let tauri::WindowEvent::CloseRequested { api, .. } = event.event() {
|
||||
hide_window(&event.window().app_handle()).expect("Failed to hide window");
|
||||
api.prevent_close();
|
||||
}
|
||||
})
|
||||
.setup(move |tauri_app| {
|
||||
let window = create_window(&tauri_app.handle()).expect("Failed to create window");
|
||||
#[cfg(debug_assertions)]
|
||||
window.open_devtools();
|
||||
|
||||
let app: app::App =
|
||||
app::App::new(
|
||||
tauri_app.path_resolver().app_local_data_dir().unwrap(),
|
||||
events::Sender::new(tauri_app.handle())
|
||||
)
|
||||
.expect("failed to initialize app");
|
||||
let app: app::App = app::App::new(
|
||||
tauri_app.path_resolver().app_local_data_dir().unwrap(),
|
||||
events::Sender::new(tauri_app.handle()),
|
||||
)
|
||||
.expect("failed to initialize app");
|
||||
|
||||
// TODO: REMOVE THIS
|
||||
// debug_test_consistency(&app_state, "fec3d50c-503f-4021-89fb-e7ec2433ceae")
|
||||
@ -649,15 +682,16 @@ fn main() {
|
||||
.build(tauri_context)
|
||||
.expect("Failed to build tauri app")
|
||||
.run(|app_handle, event| match event {
|
||||
tauri::RunEvent::WindowEvent { event: tauri::WindowEvent::Focused(is_focused), .. } => {
|
||||
if is_focused {
|
||||
set_toggle_menu_hide(app_handle)
|
||||
.expect("Failed to set toggle menu hide");
|
||||
} else {
|
||||
set_toggle_menu_show(app_handle)
|
||||
.expect("Failed to set toggle menu show");
|
||||
}
|
||||
tauri::RunEvent::WindowEvent {
|
||||
event: tauri::WindowEvent::Focused(is_focused),
|
||||
..
|
||||
} => {
|
||||
if is_focused {
|
||||
set_toggle_menu_hide(app_handle).expect("Failed to set toggle menu hide");
|
||||
} else {
|
||||
set_toggle_menu_show(app_handle).expect("Failed to set toggle menu show");
|
||||
}
|
||||
}
|
||||
tauri::RunEvent::ExitRequested { api, .. } => {
|
||||
hide_window(app_handle).expect("Failed to hide window");
|
||||
api.prevent_exit();
|
||||
@ -721,7 +755,6 @@ fn set_toggle_menu_hide(handle: &tauri::AppHandle) -> tauri::Result<()> {
|
||||
fn show_window(handle: &tauri::AppHandle) -> tauri::Result<()> {
|
||||
set_toggle_menu_hide(handle)?;
|
||||
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
handle.show()?;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
mod project;
|
||||
mod storage;
|
||||
|
||||
pub use project::{CreateError, Project, ApiProject};
|
||||
pub use project::{ApiProject, CreateError, Project};
|
||||
pub use storage::{Storage, UpdateRequest};
|
||||
|
@ -140,11 +140,9 @@ pub async fn accept_connection(app: app::App, stream: net::TcpStream) -> Result<
|
||||
);
|
||||
}
|
||||
|
||||
if let Err(e) = shared_app.record_pty(
|
||||
&shared_project_id,
|
||||
recorder::Type::Output,
|
||||
data,
|
||||
) {
|
||||
if let Err(e) =
|
||||
shared_app.record_pty(&shared_project_id, recorder::Type::Output, data)
|
||||
{
|
||||
log::error!("{}: error recording data: {:#}", shared_project_id, e);
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,3 @@ mod server;
|
||||
|
||||
pub use recorder::{Record, Type};
|
||||
pub use server::start_server;
|
||||
|
||||
|
@ -107,8 +107,7 @@ impl Searcher {
|
||||
.iter()
|
||||
.map(|(_score, doc_address)| {
|
||||
let doc = &searcher.doc(*doc_address)?;
|
||||
let index_document =
|
||||
index::IndexDocument::from_document(&self.index.schema(), doc);
|
||||
let index_document = index::IndexDocument::from_document(&self.index.schema(), doc);
|
||||
Ok(SearchResult {
|
||||
project_id: index_document.project_id.unwrap(),
|
||||
file_path: index_document.file_path.unwrap(),
|
||||
|
@ -44,12 +44,8 @@ fn test_sorted_by_timestamp() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let index_path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
|
||||
@ -99,12 +95,8 @@ fn search_by_bookmark_note() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let index_path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
|
||||
@ -200,12 +192,8 @@ fn search_by_full_match() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let index_path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
|
||||
@ -246,12 +234,8 @@ fn search_by_diff() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let index_path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
|
||||
@ -370,12 +354,8 @@ fn test_delete_all() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let index_path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
|
||||
@ -424,12 +404,8 @@ fn search_bookmark_by_phrase() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let index_path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
|
||||
@ -485,12 +461,8 @@ fn search_by_filename() -> Result<()> {
|
||||
let project_store = projects::Storage::new(storage.clone());
|
||||
project_store.add_project(&project)?;
|
||||
let user_store = users::Storage::new(storage);
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let index_path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
|
||||
|
@ -44,12 +44,8 @@ fn test_should_not_write_session_with_hash() -> Result<()> {
|
||||
let user_store = users::Storage::new(storage.clone());
|
||||
let project_store = projects::Storage::new(storage);
|
||||
project_store.add_project(&project)?;
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let session = sessions::Session {
|
||||
id: "session_id".to_string(),
|
||||
@ -76,12 +72,8 @@ fn test_should_write_full_session() -> Result<()> {
|
||||
let user_store = users::Storage::new(storage.clone());
|
||||
let project_store = projects::Storage::new(storage);
|
||||
project_store.add_project(&project)?;
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let session = sessions::Session {
|
||||
id: "session_id".to_string(),
|
||||
@ -129,12 +121,8 @@ fn test_should_write_partial_session() -> Result<()> {
|
||||
let user_store = users::Storage::new(storage.clone());
|
||||
let project_store = projects::Storage::new(storage);
|
||||
project_store.add_project(&project)?;
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
gb_repo_path,
|
||||
project.id,
|
||||
project_store,
|
||||
user_store,
|
||||
)?;
|
||||
let gb_repo =
|
||||
gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?;
|
||||
|
||||
let session = sessions::Session {
|
||||
id: "session_id".to_string(),
|
||||
|
@ -66,10 +66,7 @@ impl<'writer> SessionWriter<'writer> {
|
||||
.with_context(|| "failed to write last timestamp")?;
|
||||
|
||||
if current_session_id.is_ok() && current_session_id.as_ref().unwrap().eq(&session.id) {
|
||||
let writer = SessionWriter {
|
||||
repository,
|
||||
writer,
|
||||
};
|
||||
let writer = SessionWriter { repository, writer };
|
||||
return Ok(writer);
|
||||
}
|
||||
|
||||
@ -125,10 +122,7 @@ impl<'writer> SessionWriter<'writer> {
|
||||
.with_context(|| "failed to write commit")?;
|
||||
}
|
||||
|
||||
let writer = SessionWriter {
|
||||
repository,
|
||||
writer,
|
||||
};
|
||||
let writer = SessionWriter { repository, writer };
|
||||
|
||||
Ok(writer)
|
||||
}
|
||||
@ -164,8 +158,7 @@ impl<'writer> SessionWriter<'writer> {
|
||||
|
||||
let path = path.as_ref();
|
||||
self.writer.write_string(
|
||||
self
|
||||
.repository
|
||||
self.repository
|
||||
.session_wd_path()
|
||||
.join(path)
|
||||
.to_str()
|
||||
|
@ -1,5 +1,5 @@
|
||||
mod user;
|
||||
mod storage;
|
||||
mod user;
|
||||
|
||||
pub use user::User;
|
||||
pub use storage::Storage;
|
||||
pub use user::User;
|
||||
|
Loading…
Reference in New Issue
Block a user