onInstalled listener must be wired up in ctor
This commit is contained in:
parent
4a34f9be59
commit
bdc3eb559c
|
@ -3,4 +3,6 @@ import MainBackground from './background/main.background';
|
||||||
const bitwardenIsBackground = (window as any).bitwardenIsBackground = true;
|
const bitwardenIsBackground = (window as any).bitwardenIsBackground = true;
|
||||||
const bitwardenMain = (window as any).bitwardenMain = new MainBackground();
|
const bitwardenMain = (window as any).bitwardenMain = new MainBackground();
|
||||||
|
|
||||||
bitwardenMain.bootstrap();
|
bitwardenMain.bootstrap().then(() => {
|
||||||
|
// Finished bootstrapping
|
||||||
|
});
|
||||||
|
|
|
@ -20,12 +20,20 @@ export default class RuntimeBackground {
|
||||||
private autofillTimeout: number;
|
private autofillTimeout: number;
|
||||||
private pageDetailsToAutoFill: any[] = [];
|
private pageDetailsToAutoFill: any[] = [];
|
||||||
private isSafari: boolean;
|
private isSafari: boolean;
|
||||||
|
private onInstalledReason: string = null;
|
||||||
|
|
||||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
constructor(private main: MainBackground, private autofillService: AutofillService,
|
||||||
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService,
|
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService,
|
||||||
private storageService: StorageService, private i18nService: any) {
|
private storageService: StorageService, private i18nService: any) {
|
||||||
this.isSafari = this.platformUtilsService.isSafari();
|
this.isSafari = this.platformUtilsService.isSafari();
|
||||||
this.runtime = this.isSafari ? safari.application : chrome.runtime;
|
this.runtime = this.isSafari ? safari.application : chrome.runtime;
|
||||||
|
|
||||||
|
// onInstalled listener must be wired up before anything else, so we do it in the ctor
|
||||||
|
if (!this.isSafari) {
|
||||||
|
this.runtime.onInstalled.addListener((details: any) => {
|
||||||
|
this.onInstalledReason = details.reason;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
@ -250,43 +258,35 @@ export default class RuntimeBackground {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async checkOnInstalled() {
|
private async checkOnInstalled() {
|
||||||
const gettingStartedUrl = 'https://bitwarden.com/browser-start/';
|
|
||||||
|
|
||||||
if (this.isSafari) {
|
if (this.isSafari) {
|
||||||
const installedVersionKey = 'installedVersion';
|
const installedVersionKey = 'installedVersion';
|
||||||
const installedVersion = await this.storageService.get<string>(installedVersionKey);
|
const installedVersion = await this.storageService.get<string>(installedVersionKey);
|
||||||
let reason: string = null;
|
|
||||||
if (installedVersion == null) {
|
if (installedVersion == null) {
|
||||||
reason = 'install';
|
this.onInstalledReason = 'install';
|
||||||
} else if (BrowserApi.getApplicationVersion() !== installedVersion) {
|
} else if (BrowserApi.getApplicationVersion() !== installedVersion) {
|
||||||
reason = 'update';
|
this.onInstalledReason = 'update';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reason != null) {
|
if (this.onInstalledReason != null) {
|
||||||
await this.storageService.save(installedVersionKey, BrowserApi.getApplicationVersion());
|
await this.storageService.save(installedVersionKey, BrowserApi.getApplicationVersion());
|
||||||
(window as any).ga('send', {
|
}
|
||||||
hitType: 'event',
|
|
||||||
eventAction: 'onInstalled ' + reason,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reason === 'install') {
|
setTimeout(async () => {
|
||||||
BrowserApi.createNewTab(gettingStartedUrl);
|
if (this.onInstalledReason != null) {
|
||||||
await this.setDefaultSettings();
|
|
||||||
}
|
|
||||||
} else if (this.runtime.onInstalled) {
|
|
||||||
this.runtime.onInstalled.addListener(async (details: any) => {
|
|
||||||
(window as any).ga('send', {
|
(window as any).ga('send', {
|
||||||
hitType: 'event',
|
hitType: 'event',
|
||||||
eventAction: 'onInstalled ' + details.reason,
|
eventAction: 'onInstalled ' + this.onInstalledReason,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (details.reason === 'install') {
|
if (this.onInstalledReason === 'install') {
|
||||||
BrowserApi.createNewTab(gettingStartedUrl);
|
BrowserApi.createNewTab('https://bitwarden.com/browser-start/');
|
||||||
await this.setDefaultSettings();
|
await this.setDefaultSettings();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
this.onInstalledReason = null;
|
||||||
}
|
}
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setDefaultSettings() {
|
private async setDefaultSettings() {
|
||||||
|
|
Loading…
Reference in New Issue