Add Aseprite update dialog and fix enter license dialog

This commit is contained in:
Martín Capello 2021-11-25 16:40:33 -03:00 committed by David Capello
parent 1403424f3a
commit 7ec08ca54c
8 changed files with 195 additions and 6 deletions

View File

@ -1077,6 +1077,9 @@ license_key = License Key
activating_message = Activating...
activated_message = Aseprite has been successfully activated!
[aseprite_update]
title = Aseprite update
[tileset_selector]
new_tileset = New Tileset
grid_width = Grid Width:

View File

@ -0,0 +1,23 @@
<!-- Aseprite -->
<!-- Copyright (c) 2021 Igara Studio S.A. -->
<gui>
<window id="aseprite_update" text="@.title" minwidth="300" minheight="200">
<box vertical="true" expansive="true">
<hbox>
<slider min="0" max="100" id="progress" cell_align="horizontal" expansive="true" readonly="true" />
</hbox>
<hbox expansive="true">
<view expansive="true" style="workspace_view">
<listbox id="logitems" />
</view>
</hbox>
<box horizontal="true">
<box horizontal="true" expansive="true" />
<box horizontal="true" homogeneous="true">
<button text="@general.ok" id="ok_button" magnet="true" width="60" />
<button text="@general.cancel" closewindow="true" />
</box>
</box>
</box>
</window>
</gui>

View File

@ -430,6 +430,7 @@ if(ENABLE_UI)
if(ENABLE_DRM)
set(ui_app_files
ui/enter_license.cpp
ui/aseprite_update.cpp
${ui_app_files})
endif()
endif()

View File

@ -22,6 +22,7 @@
#include "app/commands/commands.h"
#include "app/console.h"
#include "app/crash/data_recovery.h"
#include "app/drm.h"
#include "app/extensions.h"
#include "app/file/file.h"
#include "app/file/file_formats_manager.h"
@ -59,7 +60,6 @@
#include "base/scoped_lock.h"
#include "base/split_string.h"
#include "doc/sprite.h"
#include "drm.h"
#include "fmt/format.h"
#include "os/error.h"
#include "os/surface.h"
@ -846,9 +846,13 @@ int app_get_color_to_clear_layer(Layer* layer)
#ifdef ENABLE_DRM
void app_configure_drm() {
ResourceFinder rf;
rf.includeUserDir("");
DRM_CONFIGURE(rf.getFirstOrCreateDefault(), updater::getUserAgent());
ResourceFinder userDirRf, dataDirRf;
userDirRf.includeUserDir("");
dataDirRf.includeDataDir("");
std::map<std::string, std::string> config = {
{"data", dataDirRf.getFirstOrCreateDefault()}
};
DRM_CONFIGURE(get_app_name(), get_app_version(), userDirRf.getFirstOrCreateDefault(), updater::getUserAgent(), config);
}
#endif

View File

@ -0,0 +1,101 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "aseprite_update.h"
#include "base/time.h"
#include "base/trim_string.h"
#include "ui/label.h"
#include "ui/system.h"
#include "ver/info.h"
namespace app {
AsepriteUpdate::AsepriteUpdate(std::string version) : m_timer(500, this), m_download(get_app_name(), version)
{
okButton()->setEnabled(false);
okButton()->Click.connect([this](ui::Event&) {
});
m_timer.Tick.connect([this] { this->onTimerTick(); });
log(base::string_printf("Downloading Aseprite %s...", version.c_str()));
m_download.DataReceived.connect(
[this](long total, long now) {
onDataReceived(total, now);
}
);
m_download.DownloadFailed.connect(
[this](drm::LicenseManager::DownloadException& e) {
onDownloadFailed(e);
}
);
m_download.DownloadFinished.connect(
[this](drm::Package& package) {
onDownloadFinished(package);
}
);
m_download.start();
m_timer.start();
}
void AsepriteUpdate::onBeforeClose(ui::CloseEvent& ev)
{
if (m_download.status() != drm::DownloadThread::Status::FINISHED) {
log("Stopping, please wait...");
ev.cancel();
}
if (!m_closing) {
m_download.shutdown();
}
m_closing = true;
}
void AsepriteUpdate::onDataReceived(long total, long now)
{
ui::execute_from_ui_thread([this, total, now] {
progress()->setValue(100 * now / total);
});
}
void AsepriteUpdate::onDownloadFailed(drm::LicenseManager::DownloadException& e)
{
ui::execute_from_ui_thread([this, e] {
log(e.what());
});
}
void AsepriteUpdate::onDownloadFinished(drm::Package& package)
{
ui::execute_from_ui_thread([this, package] {
log("Download finished!");
drm::LicenseManager::instance()->installPackage(package);
});
}
void AsepriteUpdate::onTimerTick()
{
if (m_closing && m_download.status() == drm::DownloadThread::Status::FINISHED) {
this->closeWindow(this);
}
}
void AsepriteUpdate::log(std::string text)
{
if (m_closing) return;
base::trim_string(text, text);
auto now = base::current_time();
auto strNow = base::string_printf("%d-%02d-%02d %02d:%02d:%02d", now.year, now.month, now.day, now.hour, now.minute, now.second);
logitems()->addChild(new ui::Label(strNow + " " + text));
layout();
}
}

View File

@ -0,0 +1,39 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_UI_ASEPRITE_UPDATE_H_INCLUDED
#define APP_UI_ASEPRITE_UPDATE_H_INCLUDED
#pragma once
#include <drm/download_thread.h>
#include "aseprite_update.xml.h"
#include "ui/timer.h"
namespace app {
class AsepriteUpdate : public app::gen::AsepriteUpdate {
public:
AsepriteUpdate(std::string version);
protected:
void onBeforeClose(ui::CloseEvent& ev) override;
void onDataReceived(long total, long now);
void onDownloadFailed(drm::LicenseManager::DownloadException& e);
void onDownloadFinished(drm::Package& package);
void onTimerTick();
private:
drm::DownloadThread m_download;
ui::Timer m_timer;
bool m_closing = false;
void log(std::string text);
};
}
#endif

View File

@ -56,7 +56,7 @@ void EnterLicense::onActivationFailed(drm::LicenseManager::ActivationException&
void EnterLicense::onActivated(std::string token)
{
drm::LicenseManager::instance()->save(token);
drm::LicenseManager::instance()->saveToken(token);
ui::execute_from_ui_thread([this]() {
showSuccess();
@ -73,7 +73,7 @@ void EnterLicense::startActivation()
m_activationInProgress = true;
m_activation = std::thread([this, key]() {
try {
auto token = drm::LicenseManager::instance()->activate(key, get_app_name(), get_app_version());
auto token = drm::LicenseManager::instance()->activate(key);
onActivated(token);
}
catch (drm::LicenseManager::ActivationException& e) {

View File

@ -42,6 +42,11 @@
#include "app/sentry_wrapper.h"
#endif
#ifdef ENABLE_DRM
#include "drm/drm.h"
#include "aseprite_update.h"
#endif
namespace app {
using namespace ui;
@ -234,7 +239,20 @@ void HomeView::onNewUpdate(const std::string& url, const std::string& version)
checkUpdate()->setText(
fmt::format(Strings::home_view_new_version_available(),
get_app_name(), version));
#ifdef ENABLE_DRM
DRM_INVALID {
checkUpdate()->setUrl(url);
}
else {
checkUpdate()->setUrl("");
checkUpdate()->Click.connect([version] {
app::AsepriteUpdate dlg(version);
dlg.openWindowInForeground();
});
}
#else
checkUpdate()->setUrl(url);
#endif
checkUpdate()->setVisible(true);
checkUpdate()->InitTheme.connect(
[this]{