Fix sync button not appearing when opening popup after clicking away

This was achieved by adding an IDLE state, which is the default state
when opening the account management popup. The state is now reseted
when the popup opens instead of when it closes. In addition, now either
the "You are in sync with your account" label or the "Check account for
updates" button will appear in the popup based on the state, not both.

Finally, with theses changes, if the popup is open and an autosync
occurs, the user will be informed that the account is synced and he/she
will have to close and reopen the popup in order to trigger a manual
update.

CURA-7290
This commit is contained in:
Kostas Karmas 2020-05-26 09:49:58 +02:00
parent 7388829fc1
commit fad02193ab
3 changed files with 14 additions and 5 deletions

View file

@ -23,6 +23,7 @@ class SyncState:
SYNCING = 0 SYNCING = 0
SUCCESS = 1 SUCCESS = 1
ERROR = 2 ERROR = 2
IDLE = 3
## The account API provides a version-proof bridge to use Ultimaker Accounts ## The account API provides a version-proof bridge to use Ultimaker Accounts
@ -59,7 +60,7 @@ class Account(QObject):
self._error_message = None # type: Optional[Message] self._error_message = None # type: Optional[Message]
self._logged_in = False self._logged_in = False
self._sync_state = SyncState.SUCCESS self._sync_state = SyncState.IDLE
self._manual_sync_enabled = False self._manual_sync_enabled = False
self._last_sync_str = "-" self._last_sync_str = "-"
@ -116,11 +117,13 @@ class Account(QObject):
if any(val == SyncState.SYNCING for val in self._sync_services.values()): if any(val == SyncState.SYNCING for val in self._sync_services.values()):
self._sync_state = SyncState.SYNCING self._sync_state = SyncState.SYNCING
self._setManualSyncEnabled(False)
elif any(val == SyncState.ERROR for val in self._sync_services.values()): elif any(val == SyncState.ERROR for val in self._sync_services.values()):
self._sync_state = SyncState.ERROR self._sync_state = SyncState.ERROR
self._setManualSyncEnabled(True) self._setManualSyncEnabled(True)
else: else:
self._sync_state = SyncState.SUCCESS self._sync_state = SyncState.SUCCESS
self._setManualSyncEnabled(False)
if self._sync_state != prev_state: if self._sync_state != prev_state:
self.syncStateChanged.emit(self._sync_state) self.syncStateChanged.emit(self._sync_state)
@ -238,8 +241,10 @@ class Account(QObject):
self._sync() self._sync()
@pyqtSlot() @pyqtSlot()
def popupClosed(self) -> None: def popupOpened(self) -> None:
self._setManualSyncEnabled(True) self._setManualSyncEnabled(True)
self._sync_state = SyncState.IDLE
self.syncStateChanged.emit(self._sync_state)
@pyqtSlot() @pyqtSlot()
def logout(self) -> None: def logout(self) -> None:

View file

@ -112,8 +112,8 @@ Item
if (popup.opened) if (popup.opened)
{ {
popup.close() popup.close()
Cura.API.account.popupClosed()
} else { } else {
Cura.API.account.popupOpened()
popup.open() popup.open()
} }
} }
@ -127,6 +127,7 @@ Item
x: parent.width - width x: parent.width - width
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
onOpened: Cura.API.account.popupOpened()
opacity: opened ? 1 : 0 opacity: opened ? 1 : 0
Behavior on opacity { NumberAnimation { duration: 100 } } Behavior on opacity { NumberAnimation { duration: 100 } }

View file

@ -19,7 +19,7 @@ Row // sync state icon + message
width: 20 * screenScaleFactor width: 20 * screenScaleFactor
height: width height: width
source: UM.Theme.getIcon("update") source: Cura.API.account.manualSyncEnabled ? UM.Theme.getIcon("update") : UM.Theme.getIcon("checked")
color: palette.text color: palette.text
RotationAnimator RotationAnimator
@ -54,6 +54,7 @@ Row // sync state icon + message
color: UM.Theme.getColor("text") color: UM.Theme.getColor("text")
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
renderType: Text.NativeRendering renderType: Text.NativeRendering
visible: !Cura.API.account.manualSyncEnabled
} }
Label Label
@ -80,7 +81,9 @@ Row // sync state icon + message
signal syncStateChanged(string newState) signal syncStateChanged(string newState)
onSyncStateChanged: { onSyncStateChanged: {
if(newState == Cura.AccountSyncState.SYNCING){ if(newState == Cura.AccountSyncState.IDLE){
icon.source = UM.Theme.getIcon("update")
} else if(newState == Cura.AccountSyncState.SYNCING){
icon.source = UM.Theme.getIcon("update") icon.source = UM.Theme.getIcon("update")
stateLabel.text = catalog.i18nc("@label", "Checking...") stateLabel.text = catalog.i18nc("@label", "Checking...")
} else if (newState == Cura.AccountSyncState.SUCCESS) { } else if (newState == Cura.AccountSyncState.SUCCESS) {