Skip to content

Restore user preferences#456

Merged
HowardWolosky merged 6 commits intomicrosoft:masterfrom
TurtleShip:restore-user-preferences
Jul 29, 2019
Merged

Restore user preferences#456
HowardWolosky merged 6 commits intomicrosoft:masterfrom
TurtleShip:restore-user-preferences

Conversation

@TurtleShip
Copy link
Copy Markdown
Contributor

Fixes #445.

Description of the changes:

1) Do not set units to default values if they already have valid values
This fixes the actual issue. UnitConverter::InitializeSelectedUnits() ( this function resets all units to their default units if available for the current category ) gets called after UnitConverterViewModel::RestoreUserPreferences() ( this function restores user preferences ).
So Calculator has been restoring saved values, and then overriding the restored values with default values.
I modified InitializeSelectedUnits() so that we only initialize units only when they are not already set to valid units for the current category.

2) Removed m_isFirstTime
I noticed that we are calling RestoreUserPreferences() twice when Calculator starts up, and the function is restoring the same value both times

The below happens when Calculator starts up

  1. On startup, in UnitConverterViewModel::InitializeView(), RestoreUserPreferences() is called.
  2. RestoreUserPreferences() in turn triggers OnUnitChanged()
  3. During the first call to OnUnitChanged(), m_IsFirstTime is True, so we call RestoreUserPreferences() again while also setting m_IsFirstTime to False.
  4. RestoreUserPreference() again triggers OnUnitChanged()
  5. During the second call to OnUnitChanged(), m_IsFirstTime is False, so we call SaveUserPreferences()

I think we should only call SaveUserPreferences() inside OnUnitChanged() since we already restored user preferences during view initialization. I can't really think of a reason to restore units after view has been initialized. This led me to just delete m_isFirstTime.

How changes were validated:

Manually tested that units and the current category are properly selected when you quit and start Calculator.

GifMaker_20190414182150911

GifMaker_20190414183403644

@rudyhuyn
Copy link
Copy Markdown
Contributor

rudyhuyn commented Apr 15, 2019

It really improves the user experience! Thank you for taking care of that!

I added 2 NIT comments, let me know what you think.

AhmedTammaa
AhmedTammaa previously approved these changes Apr 21, 2019
@TurtleShip
Copy link
Copy Markdown
Contributor Author

Hi, gentle bump on this.
It looks like I need a review from a reviewer with write access.
Could such a reviewer take a look please?

Thanks!

@HowardWolosky
Copy link
Copy Markdown
Contributor

Sorry for the delay, @TurtleShip. I am looking at this, but I'm also looking through the archived history of the code around this. The code wasn't exactly this way when it was initially written, and so I'm trying to review the history to see if there were other bugs/cases that were trying to be corrected along the way that we'd be regressing by taking this change. I should have feedback on this PR next week. Thanks for your patience.

@TurtleShip
Copy link
Copy Markdown
Contributor Author

Hi, @HowardWolosky
I was wondering if you have updates on this 🙂

@HowardWolosky
Copy link
Copy Markdown
Contributor

HowardWolosky commented May 15, 2019

Hi, @HowardWolosky
I was wondering if you have updates on this 🙂

Hey there -- apologies for the delay. Preparation for this year's BUILD conference took up a bit more time than anticipated. I should have my investigation into the history around this code completed this week. I appreciate your continued patience here.

@TurtleShip
Copy link
Copy Markdown
Contributor Author

TurtleShip commented Jun 17, 2019

Hi, a gentle bump on this... 🙂 @HowardWolosky

@HowardWolosky
Copy link
Copy Markdown
Contributor

You're totally right on this @TurtleShip -- I apologize for the delay and radio silence here. Other things came up preventing me from finishing that investigation. I'll be prioritizing this soon and hope that we can get this merged in within the next two weeks. I apologize again and appreciate your patience here.

@grochocki grochocki removed the Bug Issue is a bug label Jul 13, 2019
ghost
ghost previously approved these changes Jul 21, 2019
Copy link
Copy Markdown
Contributor

@HowardWolosky HowardWolosky left a comment

Choose a reason for hiding this comment

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

@TurtleShip -- I really appreciate your patience here.

The code was first introduced back in November 2014. The broken logic that you uncovered was unfortunately introduced back in May 2017 when Currency Converter was being worked on (at the time, UnitConverter::Reset() got split into UnitConverter::Reset() and UnitConverter::InitializeSelectedUnits()).

When looking through the code, I had originally expected that it would save and restore all of the last-used units across all the converters, and would therefore need to keep that Restore during OnUnitsChanged, but upon looking how SaveUserPreferences works, it only acts on the current one, which makes needing to track m_IsFirstTime irrelevant (and buggy as we've seen).

I think if you make those minor requested updates, we can get this merged in and improve the experience for all of our converter users.

Thanks so much for looking into this!

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
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.

Please revert the whitespace change here.

@TurtleShip TurtleShip dismissed stale reviews from ghost and AhmedTammaa via 2ee9a41 July 27, 2019 06:53
@ghost ghost removed the needs author feedback label Jul 27, 2019
@TurtleShip TurtleShip force-pushed the restore-user-preferences branch 2 times, most recently from 438651f to 760e5ac Compare July 27, 2019 06:58
@TurtleShip
Copy link
Copy Markdown
Contributor Author

Hi, @HowardWolosky

I've addressed your comments.
Thanks for taking time to look at my PR and I look forward to see it being merged to the master!
😄

@rudyhuyn
Copy link
Copy Markdown
Contributor

Good job Seulgi!

Copy link
Copy Markdown
Contributor

@HowardWolosky HowardWolosky left a comment

Choose a reason for hiding this comment

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

Excellent! Thanks for this change, and for your patience during its investigation and validation! I look forward to seeing more contributions from you in the future.

@HowardWolosky HowardWolosky merged commit af83226 into microsoft:master Jul 29, 2019
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.

User preferences are not restored between sessions.

5 participants