Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert e471f0a and then replace onInstalled event with check for exis…
…ting localStore (#21447) ## **Description** The purpose of e471f0a was to fix the background.js script so that the following code is run when then extension is first installed: ``` addAppInstalledEvent(); platform.openExtensionInBrowser(); ``` Prior to e471f0a, these function were being call in the handler of the `browser.runtime.onInstalled` listener. However, #21015 caused that listener to stop working. Because the listener needs to be created in the first javascript event loop, but that PR caused a delay to the background.js script being run, so the listener would be created after the first javascript event loop. The solution in e471f0a was to write a property to state during the first time background.js is run, and then use the absence of that property to decide we were in a scenario where the extension was being installed. When doing final QA on v11.3.0, I realized that this solution doesn't account for users who already have MetaMask installed. These users won't have the property in state, and so after MetaMask updates the logic of e471f0a would treat them as if they were first installing MetaMask, even though they are not. To prevent that we could write a data migration, but this PR opts for an even simpler approach. First, this PR reverts e471f0a. Next, it modifies the background.js script so that the `browser.runtime.onInstalled` listener is run every time background.js is run, but it only calls the `addAppInstalledEvent` and `platform.openExtensionInBrowser()` functions if there is no data existing in storage (which will only be the case if the user is just installing and running background.js for the first time). This PR is most easily reviewed by looking at each commit separately. The first is a pure revert, and so doesn't really require review, and then second commit is where the new code is. ## **Manual testing steps** 1. Download the build from the comment in this PR 2. Install the build. MetaMask should automatically open 3. Open the background console to the network tab 4. Go through onboarding, selecting that you want to participate in MetaMetrics 5. There should be a segment network request with an `'App Installed'` event Then: 1. Install v11.2.0 and subsequently install v11.3.0, causing a version update. 2. MetaMask should not automatically open. 3. There should be no 'App Installed' metrics event ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained: - [ ] What problem this PR is solving. - [ ] How this problem was solved. - [ ] How reviewers can test my changes. - [ ] I’ve indicated what issue this PR is linked to: Fixes #??? - [ ] I’ve included tests if applicable. - [x] I’ve documented any added code. - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). - [x] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information