restored animation async from request

This commit is contained in:
Santiago Lema 2025-05-07 06:56:46 -03:00
parent c8523bc115
commit 25eb366397
4 changed files with 53 additions and 41 deletions

View file

@ -5,6 +5,7 @@
#include "MainWindow.h"
static int progressAnim = 0;
#include <Application.h>
@ -18,6 +19,7 @@
#include <StringView.h>
#include <View.h>
#include <MessageRunner.h>
#include "Conversation.h"
@ -28,6 +30,8 @@ static const uint32 kMsgNewFile = 'fnew';
static const uint32 kMsgOpenFile = 'fopn';
static const uint32 kMsgSaveFile = 'fsav';
static const uint32 kPulse = 'plse';
static const uint32 kSendPrompt = 'kspt';
static const uint32 kQuestionChanged = 'kqch';
@ -114,6 +118,14 @@ MainWindow::MainWindow()
.SetInsets(5, 5, 5, 5)
.End();
BMessageRunner* runner = new BMessageRunner(
this, // target BHandler
new BMessage(kPulse),
100000 // interval in μs (100ms)
);
}
MainWindow::~MainWindow() {}
@ -122,7 +134,16 @@ void MainWindow::MessageReceived(BMessage *message) {
switch (message->what) {
// case kMsgNewFile: {
case kPulse: {
if (progressAnim >=1 && progressAnim <= 70) {
_progress->SetTo(progressAnim);
progressAnim++;
}
break;
}
// case kMsgNewFile: {
// fSaveMenuItem->SetEnabled(false);
// printf("New\n");
// } break;
@ -139,7 +160,12 @@ void MainWindow::MessageReceived(BMessage *message) {
case kSendPrompt: {
_progress->SetMaxValue(100);
_progress->SetTo(5);
_progress->SetTo(0);
_answerView->SetText("...");
progressAnim = 1;//will trigger animation
printf("Button Pressed\n");
_infoView->SetText("Asking...");
@ -151,6 +177,8 @@ void MainWindow::MessageReceived(BMessage *message) {
printf("Conversation returned!\n");
_infoView->SetText("Answer Received");
progressAnim = 100;
const char* text;
if (message->FindString("text", &text) == B_OK) {