summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 718886c..5ee80c2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,8 +1,11 @@
+use std::sync::Arc;
+
 use adw::prelude::*;
 use gtk::GridLayoutChild;
-use relm4::{gtk, ComponentParts, ComponentSender, RelmWidgetExt, Component};
+use relm4::{gtk, prelude::{AsyncComponent, AsyncComponentParts}, AsyncComponentSender, RelmWidgetExt};
 
 mod widgets;
+pub const APPLICATION_ID: &str = "xyz.vikanezrimaya.kittybox.Bowl";
 
 #[tracker::track]
 #[derive(Debug)]
@@ -20,7 +23,7 @@ pub struct PostComposerModel {
 }
 
 impl PostComposerModel {
-    async fn ai_generate_summary(_content: glib::GString, _sender: ComponentSender<Self>) -> PostComposerCommandOutput {
+    async fn ai_generate_summary(_content: glib::GString, _sender: AsyncComponentSender<Self>) -> PostComposerCommandOutput {
         // This is just a UI mock-up. In real-life conditions, this
         // would send a request to a summarizer API of some sort.
         //
@@ -49,8 +52,8 @@ pub enum PostComposerCommandOutput {
     AiSummaryDone(Result<(), ()>)
 }
 
-#[relm4::component(pub)]
-impl Component for PostComposerModel {
+#[relm4::component(pub async)]
+impl AsyncComponent for PostComposerModel {
     /// The type of the messages that this component can receive.
     type Input = PostComposerInput;
     /// The type of the messages that this component can send.
@@ -211,11 +214,11 @@ impl Component for PostComposerModel {
                 
     }
     /// Initialize the UI and model.
-    fn init(
+    async fn init(
         init: Self::Init,
         window: Self::Root,
-        sender: ComponentSender<Self>,
-    ) -> relm4::ComponentParts<Self> {
+        sender: AsyncComponentSender<Self>,
+    ) -> AsyncComponentParts<Self> {
         let model = PostComposerModel {
             ai_summary_busy_guard: None,
 
@@ -256,10 +259,16 @@ impl Component for PostComposerModel {
 
         widgets.content.set_layout_manager(Some(model.narrow_layout.clone()));
 
-        ComponentParts { model, widgets }
+        AsyncComponentParts { model, widgets }
     }
 
-    fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>, _root: &Self::Root) {
+    async fn update_with_view(
+        &mut self,
+        widgets: &mut Self::Widgets,
+        message: Self::Input,
+        sender: AsyncComponentSender<Self>,
+        _root: &Self::Root
+    ) {
         self.reset(); // Reset the tracker
 
         match message {
@@ -287,9 +296,11 @@ impl Component for PostComposerModel {
                 log::warn!("Submitting posts is not yet implemented.");
             },
         }
+
+        self.update_view(widgets, sender);
     }
 
-    fn update_cmd(&mut self, msg: Self::CommandOutput, _sender: ComponentSender<Self>, _root: &Self::Root) {
+    async fn update_cmd(&mut self, msg: Self::CommandOutput, _sender: AsyncComponentSender<Self>, _root: &Self::Root) {
         match msg {
             Self::CommandOutput::AiSummaryDone(res) => {
                 self.set_ai_summary_busy_guard(None);