diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 9409e40610..7dfc405c9b 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -48,21 +48,10 @@ export default class RuntimeBackground { win.location.href = href; } }, true); - } else { - if (this.runtime.onInstalled) { - this.runtime.onInstalled.addListener((details: any) => { - (window as any).ga('send', { - hitType: 'event', - eventAction: 'onInstalled ' + details.reason, - }); - - if (details.reason === 'install') { - chrome.tabs.create({ url: 'https://bitwarden.com/browser-start/' }); - } - }); - } } + await this.checkOnInstalled(); + BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => { await this.processMessage(msg, sender, sendResponse); }); @@ -260,6 +249,44 @@ export default class RuntimeBackground { } } + private async checkOnInstalled() { + const gettingStartedUrl = 'https://bitwarden.com/browser-start/'; + + if (this.isSafari) { + const installedVersionKey = 'installedVersion'; + const installedVersion = await this.storageService.get(installedVersionKey); + let reason: string = null; + if (installedVersion == null) { + reason = 'install'; + } else if (BrowserApi.getApplicationVersion() !== installedVersion) { + reason = 'update'; + } + + if (reason != null) { + await this.storageService.save(installedVersionKey, BrowserApi.getApplicationVersion()); + (window as any).ga('send', { + hitType: 'event', + eventAction: 'onInstalled ' + reason, + }); + } + + if (reason === 'install') { + BrowserApi.createNewTab(gettingStartedUrl); + } + } else if (this.runtime.onInstalled) { + this.runtime.onInstalled.addListener((details: any) => { + (window as any).ga('send', { + hitType: 'event', + eventAction: 'onInstalled ' + details.reason, + }); + + if (details.reason === 'install') { + BrowserApi.createNewTab(gettingStartedUrl); + } + }); + } + } + private async getDataForTab(tab: any, responseCommand: string) { const responseData: any = {}; if (responseCommand === 'notificationBarDataResponse') {