From 835cedb0a5b5d33146a2234e9f70ad8ed5f54f6c Mon Sep 17 00:00:00 2001 From: Kepi Date: Thu, 7 May 2020 03:07:10 +0200 Subject: [PATCH] [bg] Use Chrome native way to open page after extension is installed This should resolve rare cases when welcome page was opened again and again for some users. Fixes #128. --- src/background.ts | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/background.ts b/src/background.ts index 28e9ef5..bdde737 100644 --- a/src/background.ts +++ b/src/background.ts @@ -172,6 +172,19 @@ var bg = { } }) }) + + /** + * When Eye Dropper is just installed, we want to display nice + * page to user with some instructions + */ + chrome.runtime.onInstalled.addListener((object: chrome.runtime.InstalledDetails) => { + if (object.reason === 'install') { + chrome.tabs.create({ + url: '/installed.html', + selected: true, + }) + } + }) }, setBadgeColor: function(color: string) { console.info('Setting badge color to ' + color) @@ -415,25 +428,6 @@ var bg = { }) } }, - /** - * When Eye Dropper is just installed, we want to display nice - * page to user with some instructions - */ - pageInstalled: function() { - // only if we have support for localStorage - if (window.localStorage != null) { - // show installed or updated page - // do not display if localStorage is not supported - we don't want to spam user - if (window.localStorage && !window.localStorage.seenInstalledPage) { - console.info('Just installed: opening installed page in new tab.') - window.localStorage.seenInstalledPage = true - chrome.tabs.create({ - url: '/installed.html', - selected: true, - }) - } - } - }, /** * Load history from storage on extension start */ @@ -681,7 +675,6 @@ var bg = { }, init: function() { console.group('init') - bg.pageInstalled() bg.edCb = document.getElementById('edClipboard') bg.loadSettings() bg.loadHistory()