mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 06:32:42 +00:00
Abort loading news file if the application is being closed
This commit is contained in:
parent
d495c4d18a
commit
1ce74d3c5a
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -28,7 +28,7 @@ namespace app {
|
||||
HttpLoader::HttpLoader(const std::string& url)
|
||||
: m_url(url)
|
||||
, m_done(false)
|
||||
, m_cancel(false)
|
||||
, m_request(nullptr)
|
||||
, m_thread(base::Bind<void>(&HttpLoader::threadHttpRequest, this))
|
||||
{
|
||||
}
|
||||
@ -38,9 +38,10 @@ HttpLoader::~HttpLoader()
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
void HttpLoader::cancel()
|
||||
void HttpLoader::abort()
|
||||
{
|
||||
m_cancel = true;
|
||||
if (m_request)
|
||||
m_request->abort();
|
||||
}
|
||||
|
||||
void HttpLoader::threadHttpRequest()
|
||||
@ -61,12 +62,12 @@ void HttpLoader::threadHttpRequest()
|
||||
fn = base::join_path(dir, fn);
|
||||
|
||||
std::ofstream output(FSTREAM_PATH(fn), std::ofstream::binary);
|
||||
net::HttpRequest http(m_url);
|
||||
m_request = new net::HttpRequest(m_url);
|
||||
net::HttpResponse response(&output);
|
||||
http.send(response);
|
||||
|
||||
if (response.status() == 200)
|
||||
if (m_request->send(response) &&
|
||||
response.status() == 200) {
|
||||
m_filename = fn;
|
||||
}
|
||||
|
||||
LOG("Response: %d\n", response.status());
|
||||
}
|
||||
@ -76,6 +77,9 @@ void HttpLoader::threadHttpRequest()
|
||||
catch (...) {
|
||||
LOG("Unexpected unknown exception sending http request\n");
|
||||
}
|
||||
|
||||
delete m_request;
|
||||
m_request = nullptr;
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -12,6 +12,10 @@
|
||||
#include "base/thread.h"
|
||||
#include <string>
|
||||
|
||||
namespace net {
|
||||
class HttpRequest;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
|
||||
class HttpLoader {
|
||||
@ -19,7 +23,7 @@ namespace app {
|
||||
HttpLoader(const std::string& url);
|
||||
~HttpLoader();
|
||||
|
||||
void cancel();
|
||||
void abort();
|
||||
bool isDone() const { return m_done; }
|
||||
std::string filename() const { return m_filename; }
|
||||
|
||||
@ -28,7 +32,7 @@ namespace app {
|
||||
|
||||
std::string m_url;
|
||||
bool m_done;
|
||||
bool m_cancel;
|
||||
net::HttpRequest* m_request;
|
||||
base::thread m_thread;
|
||||
std::string m_filename;
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -21,6 +21,7 @@
|
||||
#include "base/string.h"
|
||||
#include "base/time.h"
|
||||
#include "ui/link_label.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/paint_event.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/view.h"
|
||||
@ -219,6 +220,19 @@ void NewsListBox::reload()
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
bool NewsListBox::onProcessMessage(ui::Message* msg)
|
||||
{
|
||||
switch (msg->type()) {
|
||||
|
||||
case kCloseMessage:
|
||||
if (m_loader)
|
||||
m_loader->abort();
|
||||
break;
|
||||
}
|
||||
|
||||
return ListBox::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void NewsListBox::onTick()
|
||||
{
|
||||
if (!m_loader || !m_loader->isDone())
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -26,6 +26,7 @@ namespace app {
|
||||
void reload();
|
||||
|
||||
private:
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
void onTick();
|
||||
void parseFile(const std::string& filename);
|
||||
bool validCache(const std::string& filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user