Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

on:
workflow_dispatch:
pull_request:
paths-ignore:
- 'alfs/**'
Expand Down Expand Up @@ -125,6 +126,7 @@ jobs:

- name: Set up git lfs
run: |
echo "GPG_TTY=`tty`" >> $GITHUB_ENV
git lfs install
git config --global user.email "mega@github.com"
git config --global user.name "Mega"
Expand Down Expand Up @@ -172,4 +174,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo clippy --manifest-path scorpio/Cargo.toml --all-targets --all-features -- -D warnings
- run: cargo clippy --manifest-path scorpio/Cargo.toml --all-targets --all-features -- -D warnings
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Cargo.lock
.idea
.vscode
.zed
.trae

# Mac
.DS_Store
Expand All @@ -33,4 +34,4 @@ buck-out
monobean/resources/lib

# Temporary test cache dir
/tests/.cache_tmp
/tests/.cache_tmp
2 changes: 1 addition & 1 deletion ceres/src/model/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl From<TreeItem> for TreeCommitItem {
}
}

#[derive(Serialize, Deserialize, ToSchema)]
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct TreeBriefItem {
pub name: String,
pub path: String,
Expand Down
2 changes: 1 addition & 1 deletion libra/src/command/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ mod test {
let index = Index::from_file(crate_path.join("../tests/data/index/index-760")).unwrap();
println!("{:?}", index.tracked_entries(0).len());
let storage = ClientStorage::init(path::objects());
let tree = create_tree(&index, &storage, temp_path.into_path()).await;
let tree = create_tree(&index, &storage, temp_path.keep()).await;

assert!(storage.get(&tree.id).is_ok());
for item in tree.tree_items.iter() {
Expand Down
2 changes: 1 addition & 1 deletion libra/src/utils/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ mod test {
gitignore_file.write_all(b"*.bar").unwrap();

let target = temp_path.path().join("tmp/foo.bar");
assert!(check_gitignore(&temp_path.into_path(), &target));
assert!(check_gitignore(&temp_path.keep(), &target));
}

#[test]
Expand Down
16 changes: 8 additions & 8 deletions libra/tests/command/init_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn verify_init(base_dir: &Path) {
#[serial]
/// Test the init function with no parameters
async fn test_init() {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();
// let _guard = ChangeDirGuard::new(target_dir.clone());

let args = InitArgs {
Expand All @@ -48,7 +48,7 @@ async fn test_init() {
#[serial]
/// Test the init function with the --bare flag
async fn test_init_bare() {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();
// let _guard = ChangeDirGuard::new(target_dir.clone());

// Run the init function with --bare flag
Expand All @@ -68,7 +68,7 @@ async fn test_init_bare() {
#[serial]
/// Test the init function with the --bare flag and an existing repository
async fn test_init_bare_with_existing_repo() {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();

// Initialize a bare repository
let init_args = InitArgs {
Expand Down Expand Up @@ -151,7 +151,7 @@ async fn test_init_with_invalid_branch() {
}

async fn test_invalid_branch_name(branch_name: &str) {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();
let args = InitArgs {
bare: false,
initial_branch: Some(branch_name.to_string()),
Expand All @@ -170,7 +170,7 @@ async fn test_invalid_branch_name(branch_name: &str) {
#[serial]
/// Test the init function with [directory] parameter
async fn test_init_with_directory() {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();

// Create a test directory
let test_dir = target_dir.join("test");
Expand All @@ -196,7 +196,7 @@ async fn test_init_with_directory() {
#[serial]
/// Test the init function with invalid [directory] parameter
async fn test_init_with_invalid_directory() {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();

// Create a test file instead of a directory
let test_dir = target_dir.join("test.txt");
Expand Down Expand Up @@ -225,7 +225,7 @@ async fn test_init_with_invalid_directory() {
#[serial]
/// Tests that repository initialization fails when lacking write permissions in the target directory
async fn test_init_with_unauthorized_directory() {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();

// Create a test directory
let test_dir = target_dir.join("test");
Expand Down Expand Up @@ -265,7 +265,7 @@ async fn test_init_with_unauthorized_directory() {
#[serial]
/// Test the init function with the --quiet flag by using --show-output
async fn test_init_quiet() {
let target_dir = tempdir().unwrap().into_path();
let target_dir = tempdir().unwrap().keep();

let args = InitArgs {
bare: false,
Expand Down
6 changes: 4 additions & 2 deletions monobean/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ common = { path = "../common" }
jupiter = { path = "../jupiter" }
vault = { path = "../vault" }
gateway = { path = "../gateway" }
ceres = { path = "../ceres" }
mercury = { path = "../mercury" }

thiserror = { version = "2.0.11", features = ["default"] }
tracing-subscriber = { version = "0.3.19", features = ["default", "env-filter"] }
tokio = "1.43.0"
tokio = "1.45.0"
russh = "0.52"
axum = "0.8.1"
axum-server = "0.7.1"
bytes = "1.10.0"
async-channel = "2.3.1"
tracing = "0.1.41"
rustls = "0.23.23"
gix-config = "0.43.0"
gix-config = "0.45.1"
home = "0.5.11"
smallvec = "1.14.0"
directories = "6.0.0"
Expand Down
4 changes: 2 additions & 2 deletions monobean/resources/gtk/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<child type="title">
<object class="AdwViewSwitcher" id="view_switcher">
<property name="policy">wide</property>
<property name="stack">stack</property>
<property name="stack">content_stack</property>
</object>
</child>

Expand All @@ -100,7 +100,7 @@
<property name="name">main_page</property>
<property name="title" translatable="true">Main</property>
<property name="child">
<object class="AdwViewStack" id="stack">
<object class="AdwViewStack" id="content_stack">
<child>
<object class="AdwViewStackPage">
<property name="name">mega_tab</property>
Expand Down
14 changes: 8 additions & 6 deletions monobean/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use gtk::{gio, glib};
use std::cell::{OnceCell, RefCell};
use std::fmt::Debug;
use std::net::{IpAddr, SocketAddr};
use std::path::PathBuf;
use tokio::sync::oneshot;
use tracing_subscriber::fmt::writer::MakeWriterExt;

Expand All @@ -44,7 +43,10 @@ pub enum Action {
ShowHelloPage,
ShowMainPage,
MountRepo,
OpenEditorOn(PathBuf),
OpenEditorOn{
hash: String,
name: String,
},
}

mod imp {
Expand Down Expand Up @@ -107,17 +109,17 @@ mod imp {
let obj = self.obj();

let app = obj.downcast_ref::<super::MonobeanApplication>().unwrap();
app.setup_log();

if let Some(weak_window) = self.window.get() {
weak_window.upgrade().unwrap().present();
tracing::error!("Window already exists.");
return;
}

let window = app.create_window();
self.window.set(window.downgrade()).unwrap();

app.setup_log();

// Setup action channel
let receiver = self.receiver.borrow_mut().take().unwrap();
CONTEXT.spawn_local_with_priority(
Expand Down Expand Up @@ -443,11 +445,11 @@ impl MonobeanApplication {
window.show_main_page();
}
Action::MountRepo => todo!(),
Action::OpenEditorOn(path) => {
Action::OpenEditorOn{hash, name} => {
CONTEXT.spawn_local(async move {
let window = window.imp();
let code_page = window.code_page.get();
code_page.show_editor(path);
code_page.show_editor_on(hash, name);
});
}
}
Expand Down
102 changes: 54 additions & 48 deletions monobean/src/components/code_page.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::path::Path;

use async_channel::Sender;
use gtk::glib::clone;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate};
use scv::{prelude::*, Buffer};
use tokio::sync::oneshot;

use crate::application::Action;
use crate::config::monobean_base;
use crate::core::mega_core::MegaCommands;
use crate::CONTEXT;

mod imp {
use adw::subclass::prelude::BinImpl;
Expand Down Expand Up @@ -86,11 +89,9 @@ impl CodePage {
.expect("Code Page sender can only be set once");
// self.setup_action();

let mount_point = monobean_base().join("mounts");

self.setup_paned();
self.setup_source_view(opened_file);
self.setup_file_tree(mount_point);
self.setup_file_tree();
}

fn setup_paned(&self) {
Expand All @@ -106,11 +107,12 @@ impl CodePage {
code_stack.set_size_request(50, -1);
}

fn setup_file_tree(&self, mount_point: impl AsRef<Path>) {
fn setup_file_tree(&self) {
let imp = self.imp();
let sender = imp.sender.get().unwrap().clone();
let file_tree_view = imp.file_tree_view.get();

let file_tree_view = self.imp().file_tree_view.get();
file_tree_view.setup_file_tree(imp.sender.get().unwrap().clone(), mount_point);
file_tree_view.setup_file_tree(sender);
}

fn setup_source_view(&self, opened_file: Option<&Path>) {
Expand All @@ -120,55 +122,59 @@ impl CodePage {
source_view.set_editable(false);

match opened_file {
Some(path) => {
self.show_editor(path);
Some(_path) => {
// self.show_editor_on(path);
}
None => {
self.hide_editor();
}
}
}

pub fn show_editor(&self, path: impl AsRef<Path>) {
pub fn show_editor_on(&self, hash: String, name: String) {
let imp = self.imp();
let path = path.as_ref();
if !path.exists() || !path.is_file() {
tracing::warn!("file not exists: {:?}", path);
return;
}

let buf = Buffer::new(None);
let file_name = path.file_name().unwrap().to_str();
let language_manager = scv::LanguageManager::new();
let file = adw::gio::File::for_path(path);
let file = scv::File::builder().location(&file).build();
let loader = scv::FileLoader::new(&buf, &file);

buf.set_highlight_syntax(true);
if let Some(ref language) = language_manager.guess_language(file_name, None) {
tracing::debug!("Guessed language: {:?}", language);
buf.set_language(Some(language));
}
if let Some(ref scheme) = scv::StyleSchemeManager::new().scheme("Adwaita-dark") {
buf.set_style_scheme(Some(scheme));
}

loader.load_async_with_callback(
glib::Priority::default(),
adw::gio::Cancellable::NONE,
move |current_num_bytes, total_num_bytes| {
tracing::debug!(
"loading: {:?}",
(current_num_bytes as f32 / total_num_bytes as f32) * 100f32,
);
},
|res| {
tracing::debug!("loaded: {}", res.is_ok());
},
);

imp.source_view.set_buffer(Some(&buf));
imp.code_stack.set_visible_child_name("source_view");
let sender = imp.sender.get().unwrap().clone();

CONTEXT.spawn_local(clone!(
#[weak(rename_to=page)]
self,
async move {
let buf = Buffer::new(None);
let language_manager = scv::LanguageManager::new();
let (tx, rx) = oneshot::channel();

sender
.send(Action::MegaCore(MegaCommands::LoadFileContent {
chan: tx,
id: hash,
}))
.await
.unwrap();

match rx.await.unwrap() {
Ok(content) => {
buf.set_text(content.as_str());
}
Err(e) => {
tracing::error!("load file content error: {:?}", e);
return;
}
}

buf.set_highlight_syntax(true);
if let Some(ref language) = language_manager.guess_language(Some(name), None) {
tracing::debug!("Guessed language: {:?}", language);
buf.set_language(Some(language));
}
if let Some(ref scheme) = scv::StyleSchemeManager::new().scheme("Adwaita-dark") {
buf.set_style_scheme(Some(scheme));
}

let imp = page.imp();
imp.source_view.set_buffer(Some(&buf));
imp.code_stack.set_visible_child_name("source_view");
}
));
}

pub fn hide_editor(&self) {
Expand Down
Loading