From 698632a1df48429d9317893855092a7a9c76f16f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 13 Jan 2018 14:56:38 -0500 Subject: [PATCH] safari tabs apis --- src/background/main.background.ts | 4 ++-- src/background/tabs.background.ts | 21 +++++++++++++++++++-- src/notification/bar.js | 7 +++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 8229ad0442..386df7fb39 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -148,13 +148,13 @@ export default class MainBackground { // Background this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService, this.platformUtilsService, this.storageService); + this.tabsBackground = new TabsBackground(this, this.platformUtilsService); if (!this.isSafari) { this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService); this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService, this.passwordGenerationService); this.idleBackground = new IdleBackground(this, this.lockService, this.storageService); - this.tabsBackground = new TabsBackground(this); this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService); this.windowsBackground = new WindowsBackground(this); } @@ -165,11 +165,11 @@ export default class MainBackground { this.containerService.attachToWindow(window); await this.runtimeBackground.init(); + await this.tabsBackground.init(); if (!this.isSafari) { await this.commandsBackground.init(); await this.contextMenusBackground.init(); await this.idleBackground.init(); - await this.tabsBackground.init(); await this.webRequestBackground.init(); await this.windowsBackground.init(); } diff --git a/src/background/tabs.background.ts b/src/background/tabs.background.ts index 198db0af1a..07734b53b9 100644 --- a/src/background/tabs.background.ts +++ b/src/background/tabs.background.ts @@ -1,10 +1,14 @@ import MainBackground from './main.background'; +import { PlatformUtilsService } from 'jslib/abstractions'; + export default class TabsBackground { private tabs: any; + private isSafari: boolean; - constructor(private main: MainBackground) { - this.tabs = chrome.tabs; + constructor(private main: MainBackground, private platformUtilsService: PlatformUtilsService) { + this.isSafari = this.platformUtilsService.isSafari(); + this.tabs = this.isSafari ? safari.application : chrome.tabs; } async init() { @@ -12,6 +16,19 @@ export default class TabsBackground { return; } + if (this.isSafari) { + this.tabs.addEventListener('activate', async (ev: any) => { + await this.main.refreshBadgeAndMenu(); + }, true); + + this.tabs.addEventListener('navigate', async (ev: any) => { + await this.main.checkLoginsToAdd(); + await this.main.refreshBadgeAndMenu(); + }, true); + + return; + } + this.tabs.onActivated.addListener(async (activeInfo: any) => { await this.main.refreshBadgeAndMenu(); }); diff --git a/src/notification/bar.js b/src/notification/bar.js index 556d509ba3..5140109e75 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -4,6 +4,13 @@ document.addEventListener('DOMContentLoaded', function () { var i18n = {}; if (typeof safari !== 'undefined') { // TODO: load when we get i18n strings + i18n.appName = 'bitwarden'; + i18n.close = 'close'; + i18n.yes = 'Yes'; + i18n.never = 'Never'; + i18n.notificationAddSave = 'Save Site';; + i18n.notificationNeverSave = 'Never Save'; + i18n.notificationAddDesc = 'Want to Save?'; setTimeout(load, 50); } else {