From a05a39afad68a66c5c6fdd8d7ab012436e2e6459 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 7 Dec 2024 15:27:20 +0100 Subject: [PATCH 1/6] Get text changes from the TextView --- src/window.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/window.rs b/src/window.rs index f9b7444..b2a6207 100644 --- a/src/window.rs +++ b/src/window.rs @@ -48,7 +48,17 @@ mod imp { } } - impl ObjectImpl for AardvarkWindow {} + impl ObjectImpl for AardvarkWindow { + fn constructed(&self) { + self.parent_constructed(); + let buffer = self.text_view.buffer(); + buffer.connect_changed(|buffer| { + let s = buffer.text(&buffer.start_iter(), &buffer.end_iter(), false); + println!("{}", s.as_str()); + }); + } + } + impl WidgetImpl for AardvarkWindow {} impl WindowImpl for AardvarkWindow {} impl ApplicationWindowImpl for AardvarkWindow {} From 64a1e833fff652ccf4d062227a1c81df23474b05 Mon Sep 17 00:00:00 2001 From: "Silvio Tomatis (aider)" Date: Sat, 7 Dec 2024 13:17:17 +0100 Subject: [PATCH 2/6] Build the flatpack in github Actions CI --- .github/workflows/build.yml | 27 +++++++++++++++++++++++++++ org.p2panda.aardvark.json | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2b02486 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,27 @@ +on: + push: + # branches: [main] + pull_request: +name: CI +jobs: + flatpak: + name: "Flatpak" + runs-on: ubuntu-24.04 + container: + image: bilelmoussaoui/flatpak-github-actions:gnome-47 + options: --privileged + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: flatpak/flatpak-github-actions/flatpak-builder@v6 + with: + bundle: aardvark.flatpak + manifest-path: org.p2panda.aardvark.json + cache-key: flatpak-builder-${{ github.sha }} +# The above job will build the application as a flatpack and +# publish it as an artifact. To test it locally you can download +# the zip artifact, extract it, install the flatpack and run it. +# unzip aardvark-x86_64.zip +# flatpak --user install aardvark.flatpak +# flatpak run org.p2panda.aardvark diff --git a/org.p2panda.aardvark.json b/org.p2panda.aardvark.json index b43f739..72b2986 100644 --- a/org.p2panda.aardvark.json +++ b/org.p2panda.aardvark.json @@ -1,7 +1,7 @@ { "id" : "org.p2panda.aardvark", "runtime" : "org.gnome.Platform", - "runtime-version" : "master", + "runtime-version" : "47", "sdk" : "org.gnome.Sdk", "sdk-extensions" : [ "org.freedesktop.Sdk.Extension.rust-stable" @@ -44,7 +44,7 @@ { "type" : "git", "url" : "./", - "branch" : "main" + "branch" : "HEAD" } ] } From c6a56c800f66c501d4c8de524dd2309933a1a6d6 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 7 Dec 2024 16:03:41 +0100 Subject: [PATCH 3/6] Get text changes to App --- src/application.rs | 13 +++++++++++++ src/window.rs | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/application.rs b/src/application.rs index 33a19ed..b98a6ce 100644 --- a/src/application.rs +++ b/src/application.rs @@ -27,6 +27,7 @@ use gtk::{gio, glib}; use crate::config::VERSION; use crate::network; use crate::AardvarkWindow; +use crate::glib::closure_local; mod imp { use super::*; @@ -67,6 +68,14 @@ mod imp { // Get the current window or create one if necessary let window = application.active_window().unwrap_or_else(|| { let window = AardvarkWindow::new(&*application); + let app = application.clone(); + window.connect_closure( + "text-changed", + false, + closure_local!(|_window: AardvarkWindow, text: &str| { + app.update_text(text); + }), + ); window.upcast() }); @@ -120,4 +129,8 @@ impl AardvarkApplication { about.present(Some(&window)); } + + fn update_text(&self, text: &str) { + println!("app: {}", text); + } } diff --git a/src/window.rs b/src/window.rs index b2a6207..8577784 100644 --- a/src/window.rs +++ b/src/window.rs @@ -21,6 +21,8 @@ use gtk::prelude::*; use adw::subclass::prelude::*; use gtk::{gio, glib}; +use glib::subclass::Signal; +use std::sync::OnceLock; mod imp { use super::*; @@ -52,11 +54,21 @@ mod imp { fn constructed(&self) { self.parent_constructed(); let buffer = self.text_view.buffer(); - buffer.connect_changed(|buffer| { + let obj = self.obj().clone(); + buffer.connect_changed(move |buffer| { let s = buffer.text(&buffer.start_iter(), &buffer.end_iter(), false); - println!("{}", s.as_str()); + obj.emit_by_name::<()>("text-changed", &[&s.as_str()]); }); } + + fn signals() -> &'static [Signal] { + static SIGNALS: OnceLock> = OnceLock::new(); + SIGNALS.get_or_init(|| { + vec![Signal::builder("text-changed") + .param_types([str::static_type()]) + .build()] + }) + } } impl WidgetImpl for AardvarkWindow {} From 793abaa850e3b5abc8f6aea5c9987671a22df304 Mon Sep 17 00:00:00 2001 From: Silvio Tomatis Date: Sat, 7 Dec 2024 15:53:06 +0100 Subject: [PATCH 4/6] Also build for aarch64 --- .github/workflows/build.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2b02486..fa3c7c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,18 +10,35 @@ jobs: container: image: bilelmoussaoui/flatpak-github-actions:gnome-47 options: --privileged + strategy: + matrix: + arch: [x86_64, aarch64] + # Don't fail the whole workflow if one architecture fails + fail-fast: false steps: - uses: actions/checkout@v4 + # Install docker for ARM64 builds + - name: Install deps + if: ${{ matrix.arch != 'x86_64' }} + run: | + dnf -y install docker + # Set up QEMU for ARM64 builds + - name: Set up QEMU + if: ${{ matrix.arch != 'x86_64' }} + id: qemu + uses: docker/setup-qemu-action@v2 with: - fetch-depth: 0 + platforms: arm64 - uses: flatpak/flatpak-github-actions/flatpak-builder@v6 with: bundle: aardvark.flatpak manifest-path: org.p2panda.aardvark.json cache-key: flatpak-builder-${{ github.sha }} + arch: ${{ matrix.arch }} + # The above job will build the application as a flatpack and # publish it as an artifact. To test it locally you can download # the zip artifact, extract it, install the flatpack and run it. # unzip aardvark-x86_64.zip # flatpak --user install aardvark.flatpak -# flatpak run org.p2panda.aardvark +# flatpak run org.p2panda.aardvark \ No newline at end of file From 7de167f75c7641b6f5f2eda2141ef235ff63d7d1 Mon Sep 17 00:00:00 2001 From: Tobias Bernard Date: Sat, 7 Dec 2024 17:13:20 +0100 Subject: [PATCH 5/6] ui: add initial share popover --- src/aardvark.gresource.xml | 1 + src/style.css | 4 +++ src/window.ui | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/style.css diff --git a/src/aardvark.gresource.xml b/src/aardvark.gresource.xml index 0b132e0..fc6e8c7 100644 --- a/src/aardvark.gresource.xml +++ b/src/aardvark.gresource.xml @@ -3,5 +3,6 @@ window.ui gtk/help-overlay.ui + style.css diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..8591759 --- /dev/null +++ b/src/style.css @@ -0,0 +1,4 @@ +.invite-code { + font-size: 20px; + font-style: bold; +} diff --git a/src/window.ui b/src/window.ui index 756869d..df7e578 100644 --- a/src/window.ui +++ b/src/window.ui @@ -18,6 +18,13 @@ primary_menu + + + folder-publicshare-symbolic + Share Document + share_popover + + @@ -39,6 +46,59 @@ + + true + share_popover + + + 18 + 18 + 18 + 18 + vertical + 12 + 100 + share-popover-box + + + Share Document + + + + + + Give others access to this document by sharing this invite code with them: + + + + + sdf032jbn39aw0y23l0nd9dkeb200b21m289he + + + + + + center + 12 + + + + Copy to Clipboard + + + + + + + +
From 0806adaee464ca8bed0bba82715e8985638c03ee Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 7 Dec 2024 17:37:32 +0100 Subject: [PATCH 6/6] Feed automerge with text --- src/application.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/application.rs b/src/application.rs index b98a6ce..5ae6a33 100644 --- a/src/application.rs +++ b/src/application.rs @@ -28,13 +28,26 @@ use crate::config::VERSION; use crate::network; use crate::AardvarkWindow; use crate::glib::closure_local; +use automerge::transaction::Transactable; +use automerge::ObjType; +use std::cell::RefCell; +use automerge::ObjId; mod imp { use super::*; - #[derive(Debug, Default)] + #[derive(Debug)] pub struct AardvarkApplication { - automerge: AutoCommit, + automerge: RefCell, + root: ObjId, + } + + impl AardvarkApplication { + fn update_text(&self, text: &str) { + println!("app: {}", text); + let mut doc = self.automerge.borrow_mut(); + doc.update_text(&self.root, text).unwrap(); + } } #[glib::object_subclass] @@ -44,8 +57,13 @@ mod imp { type ParentType = adw::Application; fn new() -> Self { - let automerge = AutoCommit::new(); - AardvarkApplication { automerge } + let mut am = AutoCommit::new(); + let root = am.put_object(automerge::ROOT, "root", ObjType::Text).unwrap(); + let automerge = RefCell::new(am); + AardvarkApplication { + automerge, + root, + } } } @@ -73,7 +91,7 @@ mod imp { "text-changed", false, closure_local!(|_window: AardvarkWindow, text: &str| { - app.update_text(text); + app.imp().update_text(text); }), ); window.upcast() @@ -129,8 +147,4 @@ impl AardvarkApplication { about.present(Some(&window)); } - - fn update_text(&self, text: &str) { - println!("app: {}", text); - } }