checkOnInstalled for safari

This commit is contained in:
Kyle Spearrin 2018-01-16 00:03:17 -05:00
parent 869446f7e7
commit bd0ce5c316
1 changed files with 40 additions and 13 deletions

View File

@ -48,20 +48,9 @@ export default class RuntimeBackground {
win.location.href = href; win.location.href = href;
} }
}, true); }, 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') { await this.checkOnInstalled();
chrome.tabs.create({ url: 'https://bitwarden.com/browser-start/' });
}
});
}
}
BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => { BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => {
await this.processMessage(msg, sender, sendResponse); 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<string>(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) { private async getDataForTab(tab: any, responseCommand: string) {
const responseData: any = {}; const responseData: any = {};
if (responseCommand === 'notificationBarDataResponse') { if (responseCommand === 'notificationBarDataResponse') {