Skip to content

Commit acdd7dc

Browse files
committed
Use globals rather than session storage to track first install
1 parent 36fba3e commit acdd7dc

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

app/scripts/app-init.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ const registerInPageContentScript = async () => {
186186

187187
chrome.runtime.onInstalled.addListener(function (details) {
188188
if (details.reason === 'install') {
189-
chrome.storage.session.set({ isFirstTimeInstall: true });
189+
if (globalThis.__metamaskTriggerOnInstall) {
190+
globalThis.__metamaskTriggerOnInstall();
191+
} else {
192+
globalThis.__metamaskWasJustInstalled = true;
193+
}
190194
}
191195
});
192196

app/scripts/background.js

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ export const statePersistenceEvents = new EventEmitter();
144144
if (isFirefox || !isManifestV3) {
145145
browser.runtime.onInstalled.addListener(function (details) {
146146
if (details.reason === 'install') {
147-
browser.storage.session.set({ isFirstTimeInstall: true });
147+
onFirstInstall();
148148
}
149149
});
150+
} else if (globalThis.__metamaskWasJustInstalled) {
151+
onFirstInstall();
152+
} else {
153+
globalThis.__metamaskTriggerOnInstall = () => onFirstInstall();
150154
}
151155

152156
/**
@@ -1270,32 +1274,6 @@ const addAppInstalledEvent = () => {
12701274
}, 500);
12711275
};
12721276

1273-
async function checkOnFirstInstall() {
1274-
log.debug('Checking whether the extension was just installed');
1275-
let firstInstallTriggered = false;
1276-
const onSessionUpdate = (changes) => {
1277-
if (changes?.isFirstTimeInstall?.newValue) {
1278-
firstInstallTriggered = true;
1279-
browser.storage.session.onChanged.removeListener(onSessionUpdate);
1280-
onFirstInstall();
1281-
}
1282-
};
1283-
browser.storage.session.onChanged.addListener(onSessionUpdate);
1284-
const sessionData =
1285-
isManifestV3 || isFirefox
1286-
? await browser.storage.session.get(['isFirstTimeInstall'])
1287-
: await global.sessionStorage.getItem('isFirstTimeInstall');
1288-
1289-
if (firstInstallTriggered) {
1290-
return;
1291-
}
1292-
if (sessionData?.isFirstTimeInstall) {
1293-
firstInstallTriggered = true;
1294-
browser.storage.session.onChanged.removeListener(onSessionUpdate);
1295-
onFirstInstall();
1296-
}
1297-
}
1298-
12991277
// On first install, open a new tab with MetaMask
13001278
function onFirstInstall() {
13011279
log.debug('First install detected');
@@ -1338,7 +1316,6 @@ function setupSentryGetStateGlobal(store) {
13381316
}
13391317

13401318
async function initBackground() {
1341-
checkOnFirstInstall();
13421319
try {
13431320
await initialize();
13441321
if (process.env.IN_TEST) {

0 commit comments

Comments
 (0)