From 80d0bd68f117ff932427972fc50cb4d556e3479c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 13 Aug 2019 15:47:03 -0400 Subject: [PATCH] remove ols safari api dependencies --- src/background/commands.background.ts | 10 ++-------- src/background/main.background.ts | 5 +++++ src/background/runtime.background.ts | 5 ++++- src/background/tabs.background.ts | 4 +++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/background/commands.background.ts b/src/background/commands.background.ts index 087a1cdb66..54a7643ac8 100644 --- a/src/background/commands.background.ts +++ b/src/background/commands.background.ts @@ -9,7 +9,6 @@ import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; export default class CommandsBackground { - private commands: any; private isSafari: boolean; private isEdge: boolean; private isVivaldi: boolean; @@ -20,22 +19,17 @@ export default class CommandsBackground { this.isSafari = this.platformUtilsService.isSafari(); this.isEdge = this.platformUtilsService.isEdge(); this.isVivaldi = this.platformUtilsService.isVivaldi(); - this.commands = this.isSafari ? safari.application : chrome.commands; } async init() { - if (!this.commands && !this.isEdge) { - return; - } - if (this.isSafari || this.isEdge || this.isVivaldi) { BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => { if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) { await this.processCommand(msg.shortcut, sender); } }); - } else { - this.commands.onCommand.addListener(async (command: any) => { + } else if (chrome && chrome.commands && !this.isEdge) { + chrome.commands.onCommand.addListener(async (command: any) => { await this.processCommand(command); }); } diff --git a/src/background/main.background.ts b/src/background/main.background.ts index fa74091202..500918b478 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -367,6 +367,10 @@ export default class MainBackground { async openPopup() { // Chrome APIs cannot open popup + + // TODO: Do we need to open this popup? + + /* if (!this.isSafari || !safari.extension.toolbarItems || !safari.extension.toolbarItems.length) { return; } @@ -378,6 +382,7 @@ export default class MainBackground { if (activeToolBars && activeToolBars.length) { activeToolBars[0].showPopover(); } + */ } async reseedStorage() { diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 60e76cce5d..a5ee4b4a20 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -39,7 +39,7 @@ export default class RuntimeBackground { private analytics: Analytics, private notificationsService: NotificationsService, private systemService: SystemService, private lockService: LockService) { this.isSafari = this.platformUtilsService.isSafari(); - this.runtime = this.isSafari ? safari.application : chrome.runtime; + this.runtime = this.isSafari ? {} : chrome.runtime; // onInstalled listener must be wired up before anything else, so we do it in the ctor if (!this.isSafari) { @@ -56,6 +56,8 @@ export default class RuntimeBackground { if (this.isSafari) { // Reload the popup when it's opened + // TODO + /* this.runtime.addEventListener('popover', (event: any) => { const win: Window = event.target.contentWindow; let href = win.location.href; @@ -69,6 +71,7 @@ export default class RuntimeBackground { win.location.href = href; } }, true); + */ } await this.checkOnInstalled(); diff --git a/src/background/tabs.background.ts b/src/background/tabs.background.ts index b6764d8dd3..29028c93a8 100644 --- a/src/background/tabs.background.ts +++ b/src/background/tabs.background.ts @@ -8,7 +8,7 @@ export default class TabsBackground { constructor(private main: MainBackground, private platformUtilsService: PlatformUtilsService) { this.isSafari = this.platformUtilsService.isSafari(); - this.tabs = this.isSafari ? safari.application : chrome.tabs; + this.tabs = this.isSafari ? null : chrome.tabs; } async init() { @@ -17,6 +17,7 @@ export default class TabsBackground { } if (this.isSafari) { + /* this.tabs.addEventListener('activate', async (ev: any) => { await this.main.refreshBadgeAndMenu(); }, true); @@ -25,6 +26,7 @@ export default class TabsBackground { await this.main.checkNotificationQueue(); await this.main.refreshBadgeAndMenu(); }, true); + */ return; }