mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
feat: renewal new status logic (#2409)
* fix: renewal add status logic * fix: wakeup activity resumed android
This commit is contained in:
@@ -296,9 +296,25 @@ class AmneziaActivity : QtActivity() {
|
|||||||
hasWindowFocus = hasFocus
|
hasWindowFocus = hasFocus
|
||||||
Log.d(TAG, "Window focus changed: hasFocus=$hasFocus")
|
Log.d(TAG, "Window focus changed: hasFocus=$hasFocus")
|
||||||
|
|
||||||
// Cancel pending operations if window loses focus
|
|
||||||
if (!hasFocus) {
|
if (!hasFocus) {
|
||||||
|
// Cancel pending operations if window loses focus
|
||||||
resumeHandler.removeCallbacksAndMessages(null)
|
resumeHandler.removeCallbacksAndMessages(null)
|
||||||
|
} else if (isActivityResumed && Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
|
window.decorView.apply {
|
||||||
|
invalidate()
|
||||||
|
resumeHandler.postDelayed({
|
||||||
|
if (isActivityResumed && hasWindowFocus && !isFinishing && !isDestroyed) {
|
||||||
|
sendTouch(1f, 1f)
|
||||||
|
}
|
||||||
|
}, 50)
|
||||||
|
resumeHandler.postDelayed({
|
||||||
|
if (isActivityResumed && hasWindowFocus && !isFinishing && !isDestroyed) {
|
||||||
|
sendTouch(2f, 2f)
|
||||||
|
requestLayout()
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
}, 150)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ void CoreController::initControllers()
|
|||||||
|
|
||||||
m_apiConfigsController.reset(new ApiConfigsController(m_serversModel, m_apiServicesModel, m_settings));
|
m_apiConfigsController.reset(new ApiConfigsController(m_serversModel, m_apiServicesModel, m_settings));
|
||||||
m_engine->rootContext()->setContextProperty("ApiConfigsController", m_apiConfigsController.get());
|
m_engine->rootContext()->setContextProperty("ApiConfigsController", m_apiConfigsController.get());
|
||||||
connect(m_apiConfigsController.get(), &ApiConfigsController::subscriptionExpiredOnServer,
|
connect(m_apiConfigsController.get(), &ApiConfigsController::subscriptionRefreshNeeded,
|
||||||
m_apiAccountInfoModel.get(), &ApiAccountInfoModel::setSubscriptionExpiredByServer);
|
this, [this]() { m_apiSettingsController->getAccountInfo(false); });
|
||||||
|
|
||||||
m_apiNewsController.reset(new ApiNewsController(m_newsModel, m_settings, m_serversModel, this));
|
m_apiNewsController.reset(new ApiNewsController(m_newsModel, m_settings, m_serversModel, this));
|
||||||
m_engine->rootContext()->setContextProperty("ApiNewsController", m_apiNewsController.get());
|
m_engine->rootContext()->setContextProperty("ApiNewsController", m_apiNewsController.get());
|
||||||
|
|||||||
@@ -723,6 +723,7 @@ bool ApiConfigsController::updateServiceFromGateway(const int serverIndex, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isTestPurchase = apiConfig.value(apiDefs::key::isTestPurchase).toBool(false);
|
bool isTestPurchase = apiConfig.value(apiDefs::key::isTestPurchase).toBool(false);
|
||||||
|
bool wasSubscriptionExpired = m_serversModel->data(serverIndex, ServersModel::IsSubscriptionExpiredRole).toBool();
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = executeRequest(QString("%1v1/config"), apiPayload, responseBody, isTestPurchase);
|
ErrorCode errorCode = executeRequest(QString("%1v1/config"), apiPayload, responseBody, isTestPurchase);
|
||||||
|
|
||||||
@@ -749,6 +750,11 @@ bool ApiConfigsController::updateServiceFromGateway(const int serverIndex, const
|
|||||||
newServerConfig.insert(config_key::nameOverriddenByUser, true);
|
newServerConfig.insert(config_key::nameOverriddenByUser, true);
|
||||||
}
|
}
|
||||||
m_serversModel->editServer(newServerConfig, serverIndex);
|
m_serversModel->editServer(newServerConfig, serverIndex);
|
||||||
|
|
||||||
|
if (wasSubscriptionExpired) {
|
||||||
|
emit subscriptionRefreshNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
if (reloadServiceConfig) {
|
if (reloadServiceConfig) {
|
||||||
emit reloadServerFromApiFinished(tr("API config reloaded"));
|
emit reloadServerFromApiFinished(tr("API config reloaded"));
|
||||||
} else if (newCountryName.isEmpty()) {
|
} else if (newCountryName.isEmpty()) {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void errorOccurred(ErrorCode errorCode);
|
void errorOccurred(ErrorCode errorCode);
|
||||||
void subscriptionExpiredOnServer();
|
void subscriptionExpiredOnServer();
|
||||||
|
void subscriptionRefreshNeeded();
|
||||||
|
|
||||||
void installServerFromApiFinished(const QString &message);
|
void installServerFromApiFinished(const QString &message);
|
||||||
void changeApiCountryFinished(const QString &message);
|
void changeApiCountryFinished(const QString &message);
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ bool ApiSettingsController::getAccountInfo(bool reload)
|
|||||||
QJsonObject accountInfo = QJsonDocument::fromJson(responseBody).object();
|
QJsonObject accountInfo = QJsonDocument::fromJson(responseBody).object();
|
||||||
m_apiAccountInfoModel->updateModel(accountInfo, serverConfig);
|
m_apiAccountInfoModel->updateModel(accountInfo, serverConfig);
|
||||||
|
|
||||||
|
QString subscriptionEndDate = accountInfo.value(apiDefs::key::subscriptionEndDate).toString();
|
||||||
|
if (!subscriptionEndDate.isEmpty()) {
|
||||||
|
apiConfig.insert(apiDefs::key::subscriptionEndDate, subscriptionEndDate);
|
||||||
|
serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||||
|
m_serversModel->editServer(serverConfig, processedIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (reload) {
|
if (reload) {
|
||||||
updateApiCountryModel();
|
updateApiCountryModel();
|
||||||
updateApiDevicesModel();
|
updateApiDevicesModel();
|
||||||
@@ -115,7 +122,7 @@ void ApiSettingsController::getRenewalLink()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject responseJson = QJsonDocument::fromJson(responseBody).object();
|
QJsonObject responseJson = QJsonDocument::fromJson(responseBody).object();
|
||||||
QString url = responseJson.value("url").toString();
|
QString url = responseJson.value("renewal_url").toString();
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
emit renewalLinkReceived(url);
|
emit renewalLinkReceived(url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ QVariant ApiAccountInfoModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
case IsSubscriptionExpiredRole: {
|
case IsSubscriptionExpiredRole: {
|
||||||
if (m_accountInfoData.configType == apiDefs::ConfigType::AmneziaFreeV3) return false;
|
if (m_accountInfoData.configType == apiDefs::ConfigType::AmneziaFreeV3) return false;
|
||||||
if (m_isSubscriptionExpiredByServer) return true;
|
|
||||||
if (m_accountInfoData.subscriptionEndDate.isEmpty()) return false;
|
if (m_accountInfoData.subscriptionEndDate.isEmpty()) return false;
|
||||||
return apiUtils::isSubscriptionExpired(m_accountInfoData.subscriptionEndDate);
|
return apiUtils::isSubscriptionExpired(m_accountInfoData.subscriptionEndDate);
|
||||||
}
|
}
|
||||||
@@ -87,7 +86,7 @@ QVariant ApiAccountInfoModel::data(const QModelIndex &index, int role) const
|
|||||||
if (m_accountInfoData.subscriptionEndDate.isEmpty()) return false;
|
if (m_accountInfoData.subscriptionEndDate.isEmpty()) return false;
|
||||||
if (apiUtils::isSubscriptionExpired(m_accountInfoData.subscriptionEndDate)) return false;
|
if (apiUtils::isSubscriptionExpired(m_accountInfoData.subscriptionEndDate)) return false;
|
||||||
QDateTime endDate = QDateTime::fromString(m_accountInfoData.subscriptionEndDate, Qt::ISODateWithMs);
|
QDateTime endDate = QDateTime::fromString(m_accountInfoData.subscriptionEndDate, Qt::ISODateWithMs);
|
||||||
return endDate <= QDateTime::currentDateTimeUtc().addDays(30);
|
return endDate <= QDateTime::currentDateTimeUtc().addDays(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,8 +97,6 @@ void ApiAccountInfoModel::updateModel(const QJsonObject &accountInfoObject, cons
|
|||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
m_isSubscriptionExpiredByServer = false;
|
|
||||||
|
|
||||||
AccountInfoData accountInfoData;
|
AccountInfoData accountInfoData;
|
||||||
|
|
||||||
m_availableCountries = accountInfoObject.value(apiDefs::key::availableCountries).toArray();
|
m_availableCountries = accountInfoObject.value(apiDefs::key::availableCountries).toArray();
|
||||||
@@ -124,13 +121,6 @@ void ApiAccountInfoModel::updateModel(const QJsonObject &accountInfoObject, cons
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiAccountInfoModel::setSubscriptionExpiredByServer()
|
|
||||||
{
|
|
||||||
beginResetModel();
|
|
||||||
m_isSubscriptionExpiredByServer = true;
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ApiAccountInfoModel::data(const QString &roleString)
|
QVariant ApiAccountInfoModel::data(const QString &roleString)
|
||||||
{
|
{
|
||||||
QModelIndex modelIndex = index(0);
|
QModelIndex modelIndex = index(0);
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void updateModel(const QJsonObject &accountInfoObject, const QJsonObject &serverConfig);
|
void updateModel(const QJsonObject &accountInfoObject, const QJsonObject &serverConfig);
|
||||||
QVariant data(const QString &roleString);
|
QVariant data(const QString &roleString);
|
||||||
void setSubscriptionExpiredByServer();
|
|
||||||
|
|
||||||
QJsonArray getAvailableCountries();
|
QJsonArray getAvailableCountries();
|
||||||
QJsonArray getIssuedConfigsInfo();
|
QJsonArray getIssuedConfigsInfo();
|
||||||
|
|
||||||
@@ -62,7 +60,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
AccountInfoData m_accountInfoData;
|
AccountInfoData m_accountInfoData;
|
||||||
bool m_isSubscriptionExpiredByServer = false;
|
|
||||||
QJsonArray m_availableCountries;
|
QJsonArray m_availableCountries;
|
||||||
QJsonArray m_issuedConfigsInfo;
|
QJsonArray m_issuedConfigsInfo;
|
||||||
QJsonObject m_supportInfo;
|
QJsonObject m_supportInfo;
|
||||||
|
|||||||
@@ -179,6 +179,20 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
|
|||||||
case AdEndpointRole: {
|
case AdEndpointRole: {
|
||||||
return apiConfig.value(apiDefs::key::serviceInfo).toObject().value(apiDefs::key::adEndpoint).toString();
|
return apiConfig.value(apiDefs::key::serviceInfo).toObject().value(apiDefs::key::adEndpoint).toString();
|
||||||
}
|
}
|
||||||
|
case IsSubscriptionExpiredRole: {
|
||||||
|
if (configVersion != apiDefs::ConfigSource::AmneziaGateway) return false;
|
||||||
|
QString endDate = apiConfig.value(apiDefs::key::subscriptionEndDate).toString();
|
||||||
|
if (endDate.isEmpty()) return false;
|
||||||
|
return apiUtils::isSubscriptionExpired(endDate);
|
||||||
|
}
|
||||||
|
case IsSubscriptionExpiringSoonRole: {
|
||||||
|
if (configVersion != apiDefs::ConfigSource::AmneziaGateway) return false;
|
||||||
|
QString endDate = apiConfig.value(apiDefs::key::subscriptionEndDate).toString();
|
||||||
|
if (endDate.isEmpty()) return false;
|
||||||
|
if (apiUtils::isSubscriptionExpired(endDate)) return false;
|
||||||
|
QDateTime endDateTime = QDateTime::fromString(endDate, Qt::ISODateWithMs);
|
||||||
|
return endDateTime <= QDateTime::currentDateTimeUtc().addDays(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -443,6 +457,9 @@ QHash<int, QByteArray> ServersModel::roleNames() const
|
|||||||
roles[AdDescriptionRole] = "adDescription";
|
roles[AdDescriptionRole] = "adDescription";
|
||||||
roles[AdEndpointRole] = "adEndpoint";
|
roles[AdEndpointRole] = "adEndpoint";
|
||||||
|
|
||||||
|
roles[IsSubscriptionExpiredRole] = "isSubscriptionExpired";
|
||||||
|
roles[IsSubscriptionExpiringSoonRole] = "isSubscriptionExpiringSoon";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ public:
|
|||||||
AdDescriptionRole,
|
AdDescriptionRole,
|
||||||
AdEndpointRole,
|
AdEndpointRole,
|
||||||
|
|
||||||
|
IsSubscriptionExpiredRole,
|
||||||
|
IsSubscriptionExpiringSoonRole,
|
||||||
|
|
||||||
HasAmneziaDns
|
HasAmneziaDns
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,6 @@ ListViewType {
|
|||||||
id: root
|
id: root
|
||||||
|
|
||||||
property int selectedIndex: ServersModel.defaultIndex
|
property int selectedIndex: ServersModel.defaultIndex
|
||||||
property int expiredServerIndex: -1
|
|
||||||
property bool expiringSoon: false
|
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: ApiAccountInfoModel
|
|
||||||
function onModelReset() {
|
|
||||||
root.expiringSoon = ApiAccountInfoModel.data("isSubscriptionExpiringSoon")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
anchors.top: serversMenuHeader.bottom
|
anchors.top: serversMenuHeader.bottom
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
@@ -44,13 +35,6 @@ ListViewType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: ApiConfigsController
|
|
||||||
function onSubscriptionExpiredOnServer() {
|
|
||||||
root.expiredServerIndex = ServersModel.defaultIndex
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
id: menuContentDelegate
|
id: menuContentDelegate
|
||||||
objectName: "menuContentDelegate"
|
objectName: "menuContentDelegate"
|
||||||
@@ -143,14 +127,14 @@ ListViewType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CaptionTextType {
|
CaptionTextType {
|
||||||
visible: isServerFromGatewayApi && (index === root.expiredServerIndex || (root.expiringSoon && index === root.selectedIndex && index !== root.expiredServerIndex))
|
visible: isServerFromGatewayApi && (isSubscriptionExpired || isSubscriptionExpiringSoon)
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: 64
|
Layout.leftMargin: 64
|
||||||
Layout.bottomMargin: 8
|
Layout.bottomMargin: 8
|
||||||
|
|
||||||
text: index === root.expiredServerIndex ? qsTr("Subscription expired. Please renew.") : qsTr("Subscription expiring soon.")
|
text: isSubscriptionExpired ? qsTr("Subscription expired. Please renew.") : qsTr("Subscription expiring soon.")
|
||||||
color: index === root.expiredServerIndex ? AmneziaStyle.color.vibrantRed : AmneziaStyle.color.goldenApricot
|
color: isSubscriptionExpired ? AmneziaStyle.color.vibrantRed : AmneziaStyle.color.goldenApricot
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ pragma ComponentBehavior: Bound
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Qt5Compat.GraphicalEffects
|
|
||||||
|
|
||||||
import PageEnum 1.0
|
import PageEnum 1.0
|
||||||
import Style 1.0
|
import Style 1.0
|
||||||
|
|
||||||
|
|||||||
@@ -21,34 +21,20 @@ PageType {
|
|||||||
property bool subscriptionExpired: false
|
property bool subscriptionExpired: false
|
||||||
property bool subscriptionExpiringSoon: false
|
property bool subscriptionExpiringSoon: false
|
||||||
function updateSubscriptionState() {
|
function updateSubscriptionState() {
|
||||||
root.subscriptionExpiringSoon = ApiAccountInfoModel.data("isSubscriptionExpiringSoon")
|
root.subscriptionExpired = ServersModel.getProcessedServerData("isSubscriptionExpired")
|
||||||
|
root.subscriptionExpiringSoon = ServersModel.getProcessedServerData("isSubscriptionExpiringSoon")
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
root.updateSubscriptionState()
|
root.updateSubscriptionState()
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: ApiAccountInfoModel
|
|
||||||
function onModelReset() {
|
|
||||||
root.updateSubscriptionState()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: ServersModel
|
target: ServersModel
|
||||||
|
|
||||||
function onProcessedServerChanged() {
|
function onProcessedServerChanged() {
|
||||||
root.processedServer = proxyServersModel.get(0)
|
root.processedServer = proxyServersModel.get(0)
|
||||||
}
|
root.updateSubscriptionState()
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: ApiConfigsController
|
|
||||||
|
|
||||||
function onSubscriptionExpiredOnServer() {
|
|
||||||
root.subscriptionExpired = true
|
|
||||||
root.subscriptionExpiringSoon = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user