mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-01 01:20:25 +00:00
Refactor EnterLicense dialog and add license activation handling
This commit is contained in:
parent
2639c36b2f
commit
776b97deef
@ -1075,6 +1075,7 @@ title = Enter License
|
|||||||
default_message = If you need a license key, go to
|
default_message = If you need a license key, go to
|
||||||
license_key = License Key
|
license_key = License Key
|
||||||
activating_message = Activating...
|
activating_message = Activating...
|
||||||
|
activated_message = Aseprite has been successfully activated!
|
||||||
|
|
||||||
[tileset_selector]
|
[tileset_selector]
|
||||||
new_tileset = New Tileset
|
new_tileset = New Tileset
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<box horizontal="true" expansive="true" />
|
<box horizontal="true" expansive="true" />
|
||||||
<box horizontal="true" homogeneous="true">
|
<box horizontal="true" homogeneous="true">
|
||||||
<button text="@general.ok" id="ok_button" magnet="true" width="60" />
|
<button text="@general.ok" id="ok_button" magnet="true" width="60" />
|
||||||
<button text="@general.cancel" closewindow="true" />
|
<button text="@general.close" closewindow="true" />
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "app/i18n/strings.h"
|
#include "app/i18n/strings.h"
|
||||||
|
#include "app/resource_finder.h"
|
||||||
|
#include "base/fs.h"
|
||||||
#include "enter_license.h"
|
#include "enter_license.h"
|
||||||
#include "enter_license.xml.h"
|
#include "enter_license.xml.h"
|
||||||
#include "ui/message.h"
|
#include "ui/message.h"
|
||||||
@ -32,43 +34,83 @@ EnterLicense::EnterLicense() : m_timer(500, this), m_activationInProgress(false)
|
|||||||
|
|
||||||
okButton()->setEnabled(false);
|
okButton()->setEnabled(false);
|
||||||
okButton()->Click.connect([this](ui::Event&) {
|
okButton()->Click.connect([this](ui::Event&) {
|
||||||
icon()->setVisible(false);
|
startActivation();
|
||||||
message()->setText(app::Strings::instance()->enter_license_activating_message());
|
|
||||||
layout();
|
|
||||||
setEnabled(false);
|
|
||||||
std::string key = licenseKey()->text();
|
|
||||||
m_activationInProgress = true;
|
|
||||||
m_activation = std::thread([this, key]() {
|
|
||||||
drm::LicenseManager::instance()->activate(key, get_app_name(), get_app_version());
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_activatedConn = drm::LicenseManager::instance()->Activated.connect(
|
||||||
|
[this](drm::ActivatedEvent& ev) { onActivated(ev); });
|
||||||
|
|
||||||
m_activationFailedConn = drm::LicenseManager::instance()->ActivationFailed.connect(
|
m_activationFailedConn = drm::LicenseManager::instance()->ActivationFailed.connect(
|
||||||
[this](drm::LicenseManager::Exception& e) { onActivationFailed(e); });
|
[this](drm::LicenseManager::Exception& e) { onActivationFailed(e); });
|
||||||
|
|
||||||
Close.connect([this]() {
|
Close.connect([this]() {
|
||||||
|
m_activatedConn.disconnect();
|
||||||
m_activationFailedConn.disconnect();
|
m_activationFailedConn.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnterLicense::onBeforeClose(ui::CloseEvent& ev) {
|
void EnterLicense::onBeforeClose(ui::CloseEvent& ev)
|
||||||
|
{
|
||||||
if (m_activationInProgress) {
|
if (m_activationInProgress) {
|
||||||
ev.cancel();
|
ev.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnterLicense::onActivationFailed(drm::LicenseManager::Exception& e) {
|
void EnterLicense::onActivationFailed(drm::LicenseManager::Exception& e)
|
||||||
|
{
|
||||||
ui::execute_from_ui_thread([this, e]() {
|
ui::execute_from_ui_thread([this, e]() {
|
||||||
if (m_activation.joinable())
|
showError(e.what());
|
||||||
m_activation.join();
|
});
|
||||||
setEnabled(true);
|
}
|
||||||
icon()->setVisible(true);
|
|
||||||
message()->setText(e.what());
|
void EnterLicense::onActivated(drm::ActivatedEvent& ev)
|
||||||
layout();
|
{
|
||||||
m_activationInProgress = false;
|
drm::LicenseManager::instance()->save(ev.getToken());
|
||||||
|
|
||||||
|
ui::execute_from_ui_thread([this, ev]() {
|
||||||
|
showSuccess();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnterLicense::startActivation()
|
||||||
|
{
|
||||||
|
icon()->setVisible(false);
|
||||||
|
message()->setText(app::Strings::instance()->enter_license_activating_message());
|
||||||
|
layout();
|
||||||
|
setEnabled(false);
|
||||||
|
std::string key = licenseKey()->text();
|
||||||
|
m_activationInProgress = true;
|
||||||
|
m_activation = std::thread([this, key]() {
|
||||||
|
drm::LicenseManager::instance()->activate(key, get_app_name(), get_app_version());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EnterLicense::showError(const std::string& msg)
|
||||||
|
{
|
||||||
|
if (m_activation.joinable())
|
||||||
|
m_activation.join();
|
||||||
|
|
||||||
|
setEnabled(true);
|
||||||
|
icon()->setVisible(true);
|
||||||
|
message()->setText(msg);
|
||||||
|
layout();
|
||||||
|
m_activationInProgress = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnterLicense::showSuccess()
|
||||||
|
{
|
||||||
|
if (m_activation.joinable())
|
||||||
|
m_activation.join();
|
||||||
|
|
||||||
|
setEnabled(true);
|
||||||
|
icon()->setVisible(false);
|
||||||
|
message()->setText(app::Strings::instance()->enter_license_activated_message());
|
||||||
|
layout();
|
||||||
|
okButton()->setEnabled(false);
|
||||||
|
m_activationInProgress = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -20,12 +20,18 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void onBeforeClose(ui::CloseEvent& ev) override;
|
void onBeforeClose(ui::CloseEvent& ev) override;
|
||||||
void onActivationFailed(drm::LicenseManager::Exception& e);
|
void onActivationFailed(drm::LicenseManager::Exception& e);
|
||||||
|
void onActivated(drm::ActivatedEvent& ev);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::thread m_activation;
|
std::thread m_activation;
|
||||||
ui::Timer m_timer;
|
ui::Timer m_timer;
|
||||||
bool m_activationInProgress;
|
bool m_activationInProgress;
|
||||||
obs::connection m_activationFailedConn;
|
obs::connection m_activationFailedConn;
|
||||||
|
obs::connection m_activatedConn;
|
||||||
|
|
||||||
|
void startActivation();
|
||||||
|
void showError(const std::string& msg);
|
||||||
|
void showSuccess();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user