Skip to content

feat: preserve the last selected account between runs - #9061

Merged
mgallien merged 2 commits into
nextcloud:masterfrom
DmySyz:preserve-selected-account-between-runs
Nov 24, 2025
Merged

feat: preserve the last selected account between runs#9061
mgallien merged 2 commits into
nextcloud:masterfrom
DmySyz:preserve-selected-account-between-runs

Conversation

@DmySyz

@DmySyz DmySyz commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

Description

Implements #8986 and #9035

This PR implements the feature to remember and restore the last selected account after the client restarts. Previously, the client would always select the first account on startup, which was frustrating for users with multiple accounts.

Changes Made

  1. ConfigFile (src/libsync/configfile.h and configfile.cpp):

    • Added lastSelectedAccountC constant for the settings key
    • Added lastSelectedAccount() getter method
    • Added setLastSelectedAccount() setter method
  2. UserModel (src/gui/tray/usermodel.cpp):

    • Modified buildUserList() to restore the last selected account on startup
    • Modified setCurrentUserId() to save the account id when user changes accounts
    • If the account written in the settings is unavailable - choses the first one (provided that it exists)

How It Works

  • On account selection: When a user manually selects an account, the selection is saved to nextcloud.cfg
  • On startup: buildUserList() attempts to restore the last selected account
  • Fallback: If the saved account doesn't exist or the id was corrupted, it falls back to the first account

Technical Details

  • Handles edge cases: deleted accounts, empty account lists, etc.

Testing

The fix has been manually tested. Unit test has not been added as an appropriate existing test for the relevant component was not found and creating it was deemed out of scope for this PR.

Screenshots

feat_preserve_acc.mp4

Notes

As account IDs are not randomly generated it is possible that a wrong account will be selected if somehow the original one was deleted and another one was created in its place outside the client.

@DmySyz

DmySyz commented Nov 13, 2025

Copy link
Copy Markdown
Contributor Author

Sorry, it seems I've borked my github setup (haven't used github in a long time).
Does someone know if it is possible to remove the merge commit with the github cli (gh)?

@i2h3 i2h3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does someone know if it is possible to remove the merge commit with the github cli (gh)?

I do not know about gh but in Git it would be an git rebase --interactive on master in which the merge commit is just dropped then. 🤔

Comment thread src/gui/tray/usermodel.cpp Outdated
@DmySyz

DmySyz commented Nov 17, 2025

Copy link
Copy Markdown
Contributor Author

Does someone know if it is possible to remove the merge commit with the github cli (gh)?

I do not know about gh but in Git it would be an git rebase --interactive on master in which the merge commit is just dropped then. 🤔

Was overthinking it a bit 😅

@DmySyz

DmySyz commented Nov 17, 2025

Copy link
Copy Markdown
Contributor Author

@Aiiaiiio Seems you have been reviewing the previous attempt at implementing this thingy. Could you take a look at this one as well if you have some time?

@DmySyz
DmySyz requested a review from i2h3 November 17, 2025 09:20
@DmySyz

DmySyz commented Nov 17, 2025

Copy link
Copy Markdown
Contributor Author

Not entirely sure what is wrong with the SonarCloud check. If someone could clarify whether the issue is on my side, I'd be grateful 👍

@mgallien mgallien left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DmySyz can you solve the conflicts ?
sorry that you have to do it

@DmySyz

DmySyz commented Nov 18, 2025

Copy link
Copy Markdown
Contributor Author

@DmySyz can you solve the conflicts ? sorry that you have to do it

No worries. Should be ok now

@DmySyz
DmySyz requested a review from mgallien November 18, 2025 15:53
@mgallien
mgallien enabled auto-merge November 19, 2025 09:03

@Aiiaiiio Aiiaiiio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! See my change request please. We can discuss if you disagree.

Comment thread src/gui/tray/usermodel.cpp
@DmySyz
DmySyz requested a review from Aiiaiiio November 19, 2025 09:57
@DmySyz

DmySyz commented Nov 19, 2025

Copy link
Copy Markdown
Contributor Author

Not entirely sure what is wrong with the SonarCloud check. If someone could clarify whether the issue is on my side, I'd be grateful 👍

Still broken unfortunately.

"Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator to check the permissions of the user the token belongs to"

auto-merge was automatically disabled November 20, 2025 07:55

Head branch was pushed to by a user without write access

Comment thread src/gui/tray/usermodel.cpp
@DmySyz

DmySyz commented Nov 21, 2025

Copy link
Copy Markdown
Contributor Author

@Aiiaiiio sorry for dragging this thing on, but I think this version is the cleanest solution for now.
Could you take a look one more time? 😄

@DmySyz
DmySyz requested a review from Aiiaiiio November 21, 2025 06:44

@Aiiaiiio Aiiaiiio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Thank you!

Added an extra setting in the config that contains an account id to
  store the last one selected

Modified usermodel logic to auto select the account using the id from
  the config

Modified the account manager and user model to init user list after account
  restoration completes

Signed-off-by: Dmytro Syzov <sizovdmitrij@gmail.com>
Signed-off-by: dsyzov <sizovdmitrij@gmail.com>
@mgallien
mgallien enabled auto-merge November 24, 2025 12:37
@mgallien mgallien added this to the 4.1.0 milestone Nov 24, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Artifact containing the AppImage: nextcloud-appimage-pr-9061.zip

Digest: sha256:2d88c86a3feccb1086a0387c14047dbdc965db8c0e5c06a281b81be8311e4b0c

To test this change/fix you can download the above artifact file, unzip it, and run it.

Please make sure to quit your existing Nextcloud app and backup your data.

@mgallien
mgallien merged commit 80a3b86 into nextcloud:master Nov 24, 2025
18 of 19 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When the client starts up, the last used account should be restored After client restart last selected account should be selected

4 participants