<commit_before>#include "onair/okui/Application.h"

#include "onair/okui/Window.h"

#include "scraps/thread.h"
#include "scraps/net/curl.h"
#include "scraps/net/HTTPRequest.h"

namespace onair {
namespace okui {

Application::Application() {
    scraps::net::InitCURLThreadSafety();
}

Application::~Application() {
    for (auto& task : _backgroundTasks) {
        task.wait();
    }
}

Responder* Application::firstResponder() {
    return activeWindow() ? activeWindow()->firstResponder() : this;
}

void Application::command(Command command, CommandContext context) {
    if (chainCanHandleCommand(command)) {
        firstResponder()->handleCommand(command, context);
    }
}

std::future<std::shared_ptr<const std::string>> Application::download(const std::string& url, bool useCache) {
    auto it = _downloads.find(url);
    auto download = it == _downloads.end() ? (_downloads[url] = std::make_shared<DownloadInfo>()) : _downloads[url];
    std::lock_guard<std::mutex> lock(download->mutex);

    if (useCache) {
        if (download->result) {
            std::promise<std::shared_ptr<const std::string>> promise;
            promise.set_value(download->result);
            return promise.get_future();
        } else if (download->inProgress) {<commit_msg>fix previous commit<commit_after>#include "onair/okui/Application.h"

#include "onair/okui/Window.h"

#include "scraps/thread.h"
#include "scraps/net/curl.h"
#include "scraps/net/HTTPRequest.h"

namespace onair {
namespace okui {

Application::Application() {
    scraps::net::InitCURLThreadSafety();
}

Application::~Application() {
    for (auto& task : _backgroundTasks) {
        task.wait();
    }
}

Responder* Application::firstResponder() {
    return activeWindow() ? activeWindow()->firstResponder() : this;
}

void Application::command(Command command, CommandContext context) {
    if (firstResponder()->chainCanHandleCommand(command)) {
        firstResponder()->handleCommand(command, context);
    }
}

std::future<std::shared_ptr<const std::string>> Application::download(const std::string& url, bool useCache) {
    auto it = _downloads.find(url);
    auto download = it == _downloads.end() ? (_downloads[url] = std::make_shared<DownloadInfo>()) : _downloads[url];
    std::lock_guard<std::mutex> lock(download->mutex);

    if (useCache) {
        if (download->result) {
            std::promise<std::shared_ptr<const std::string>> promise;
            promise.set_value(download->result);
            return promise.get_future();
        } else if (download->inProgress) {
{'fraction_non_alphanumeric': 0.15390625, 'fraction_numerical': 0.0, 'mean_word_length': 4.335416666666666, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1958487', 'n_tokens_mistral': 804, 'n_tokens_neox': 794, 'n_words': 140}