From bd0ce5c316afc75831382b864ffd6e36ffcc667b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 16 Jan 2018 00:03:17 -0500 Subject: [PATCH] checkOnInstalled for safari --- src/background/runtime.background.ts | 53 +++++++++++++++++++++------- 1 file changed, 40 insertions(+), 13 deletions(-) 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') {