avoid chrome refs

This commit is contained in:
Kyle Spearrin 2018-01-11 22:36:22 -05:00
parent 625ae961c4
commit 6b507c9071
2 changed files with 20 additions and 20 deletions

View File

@ -100,6 +100,7 @@ export default class MainBackground {
private buildingContextMenu: boolean;
private menuOptionsLoaded: any[] = [];
private syncTimeout: number;
private isSafari: boolean;
constructor() {
// Services
@ -136,7 +137,8 @@ export default class MainBackground {
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
// Other fields
this.sidebarAction = (typeof opr !== 'undefined') && opr.sidebarAction ?
this.isSafari = this.platformUtilsService.isSafari();
this.sidebarAction = this.isSafari ? null : (typeof opr !== 'undefined') && opr.sidebarAction ?
opr.sidebarAction : (window as any).chrome.sidebarAction;
// Background
@ -154,13 +156,15 @@ export default class MainBackground {
async bootstrap() {
this.containerService.attachToWindow(window);
await this.commandsBackground.init();
await this.contextMenusBackground.init();
await this.idleBackground.init();
await this.runtimeBackground.init();
await this.tabsBackground.init();
await this.webRequestBackground.init();
await this.windowsBackground.init();
if (!this.isSafari) {
await this.commandsBackground.init();
await this.contextMenusBackground.init();
await this.idleBackground.init();
await this.runtimeBackground.init();
await this.tabsBackground.init();
await this.webRequestBackground.init();
await this.windowsBackground.init();
}
await this.environmentService.setUrlsFromStorage();
await this.setIcon();
@ -169,7 +173,7 @@ export default class MainBackground {
}
async setIcon() {
if (!chrome.browserAction && !this.sidebarAction) {
if (this.isSafari || (!chrome.browserAction && !this.sidebarAction)) {
return;
}
@ -188,7 +192,7 @@ export default class MainBackground {
}
async refreshBadgeAndMenu() {
if (!chrome.windows || !chrome.contextMenus) {
if (this.isSafari || !chrome.windows || !chrome.contextMenus) {
return;
}
@ -265,7 +269,7 @@ export default class MainBackground {
}
private async buildContextMenu() {
if (!chrome.contextMenus || this.buildingContextMenu) {
if (this.isSafari || !chrome.contextMenus || this.buildingContextMenu) {
return;
}

View File

@ -15,7 +15,7 @@ angular
$urlRouterProvider.otherwise(function ($injector, $location) {
var $state = $injector.get('$state');
if (!chrome.extension.getBackgroundPage()) {
if ((typeof chrome !== 'undefined') && !chrome.extension.getBackgroundPage()) {
$state.go('privateMode');
return;
}
@ -250,9 +250,8 @@ angular
params: { animation: null }
});
})
.run(function ($trace, $transitions, userService, $state, constantsService, stateService) {
//$trace.enable('TRANSITION');
.run(function ($trace, $transitions, userService, $state, constantsService, stateService,
storageService, messagingService) {
stateService.init();
$transitions.onStart({}, function (trans) {
@ -265,17 +264,14 @@ angular
}
const userService = trans.injector().get('userService');
const messagingService = trans.injector().get('messagingService');
if (!userService || !messagingService) {
if (!userService) {
return;
}
userService.isAuthenticated().then((isAuthenticated) => {
if (isAuthenticated) {
var obj = {};
obj[constantsService.lastActiveKey] = (new Date()).getTime();
chrome.storage.local.set(obj, function () { });
storageService.save(constantsService.lastActiveKey, (new Date()).getTime());
}
else if (toState.data && toState.data.authorize) {
event.preventDefault();