chore: removed snapshot, fixed cargo, periodic fetch in glue

Co-authored-by: alemi <me@alemi.dev>
This commit is contained in:
zaaarf 2024-02-01 01:47:49 +01:00
parent 5a42577a1f
commit 0719ac84f4
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
3 changed files with 20 additions and 13 deletions

View file

@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public class WorkspaceFileOpenedListener implements FileOpenedSyncListener {
private final WorkspaceHandler handler;
private final BufferEventAwaiterTask task;

View file

@ -24,10 +24,8 @@ public class FileUtil {
public static Editor getActiveEditorByPath(Project project, String path) {
return Arrays.stream(FileEditorManager.getInstance(project).getAllEditors())
.filter(fe -> fe instanceof TextEditor)
.map(fe -> {
TextEditor te = (TextEditor) fe;
return te.getEditor();
}).filter(editor -> path.equals(FileUtil.getRelativePath(editor.getProject(), editor.getVirtualFile())))
.map(fe -> ((TextEditor) fe).getEditor())
.filter(editor -> path.equals(FileUtil.getRelativePath(editor.getProject(), editor.getVirtualFile())))
.findFirst()
.orElse(null);
}

View file

@ -38,14 +38,20 @@ impl ClientHandler {
/// create a new workspace
fn create_workspace(&mut self, workspace_id: &str) -> CodempResult<WorkspaceHandler> {
RT.block_on(self.client.create_workspace(workspace_id))
.map(|workspace| WorkspaceHandler { workspace })
.map(|workspace| {
Self::spawn_updater(workspace.clone());
WorkspaceHandler { workspace }
})
}
#[generate_interface]
/// join a workspace by name
fn join_workspace(&mut self, workspace_id: &str) -> CodempResult<WorkspaceHandler> {
RT.block_on(self.client.join_workspace(workspace_id))
.map(|workspace| WorkspaceHandler { workspace })
.map(|workspace| {
Self::spawn_updater(workspace.clone());
WorkspaceHandler { workspace }
})
}
#[generate_interface]
@ -54,6 +60,16 @@ impl ClientHandler {
RT.block_on(self.client.leave_workspace(workspace_id))
}
fn spawn_updater(workspace: Arc<RwLock<CodempWorkspace>>) {
tokio::spawn(async move {
loop {
tokio::time::sleep(Duration::from_secs(60)).await;
workspace.write().await.fetch_buffers().await.unwrap();
workspace.write().await.fetch_users().await.unwrap();
}
});
}
#[generate_interface]
/// get the url you are currently connected to
fn get_url(&self) -> String {
@ -88,12 +104,6 @@ impl WorkspaceHandler {
.map(|buffer| BufferHandler { buffer })
}
#[generate_interface]
/// get a buffer's contents as a flat string
fn get_buffer_snapshot(&self , path: &str) -> CodempResult<String> {
RT.block_on(RT.block_on(self.workspace.read()).snapshot(path))
}
#[generate_interface]
/// updates the local list of the workspace's buffers
fn fetch_buffers(&mut self) -> CodempResult<()> {