Skip to content

Commit

Permalink
#115 | 'NEW' badge flag to inform about new version
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-null committed Dec 7, 2017
1 parent 9659cf7 commit b9f99b7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
33 changes: 24 additions & 9 deletions app/chrome/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,35 @@

chrome.runtime.onInstalled.addListener(details => {
console.log('previousVersion', details.previousVersion);
console.log('currentVersion', chrome.runtime.getManifest().version);
});

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {

chrome.browserAction.setBadgeText({tabId: sender.tab.id, text: request.modulesCount, });
chrome.browserAction.setBadgeBackgroundColor({ color: '#666' });

chrome.browserAction.setIcon({
path: request.newIconPath,
tabId: sender.tab.id
});

if (request.sc_ext_setBadgeText_request) {
chrome.browserAction.setBadgeText({ tabId: sender.tab.id, text: request.modulesCount, });
}
if (request.sc_ext_setIcon_request) {
chrome.browserAction.setIcon({
path: request.newIconPath,
tabId: sender.tab.id
});
}
chrome.browserAction.setPopup({
tabId: sender.tab.id,
popup: 'chrome/popup/popup.html'
});
chrome.browserAction.setBadgeBackgroundColor({ color: '#666' });

if (request.sc_ext_checkVersion_request) {
console.log(chrome.runtime.getManifest().version);
console.log(request.version);

if (request.version == null || request.version != chrome.runtime.getManifest().version) {
chrome.browserAction.setBadgeText({ tabId: sender.tab.id, text: "NEW", });
chrome.browserAction.setPopup({
tabId: sender.tab.id,
popup: 'chrome/popup/popup-new-version.html'
});
}
}
});
19 changes: 19 additions & 0 deletions app/chrome/contentscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

'use strict';

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.sc_ext_setVersion_request) {
if (chrome.storage) {
SitecoreExtensions.Common.GlobalStorage.set("sc-ext::version", request.version);
}
}
});

window.addEventListener('message', function (event) {
var Communication = SitecoreExtensions.Common.Communication;
var OptionsProvider = SitecoreExtensions.Options.OptionsProvider;
Expand Down Expand Up @@ -75,10 +83,21 @@ window.addEventListener('message', function (event) {
if (event.data.sc_ext_enabled) {
if (event.data.sc_ext_seticon_request) {
chrome.runtime.sendMessage({
sc_ext_setIcon_request: true,
sc_ext_setBadgeText_request: true,
newIconPath: 'chrome/images/icon-128.png',
modulesCount: event.data.sc_ext_badgetext
});
}
if (chrome.storage) {
(async () => {
let currentVersion = await SitecoreExtensions.Common.GlobalStorage.get("sc-ext::version");
chrome.runtime.sendMessage({
sc_ext_checkVersion_request: true,
version: currentVersion
});
})();
}
}
});

Expand Down
9 changes: 9 additions & 0 deletions app/chrome/popup/popup-new-version.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>

<body>
<a id="link" href="https://alan-null.github.io/redirect/sc-ext-update" target="_blank"></a>
<script src="scripts/popup-new-version.js"></script>
</body>

</html>
16 changes: 16 additions & 0 deletions app/chrome/popup/scripts/popup-new-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path='../../../../typings/chrome/chrome.d.ts'/>
/// <reference path='../../../options/providers/OptionsProvider.ts'/>
/// <reference path='../../../options/models/LinkItem.ts'/>


'use strict';

chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {
sc_ext_setVersion_request: true,
version: chrome.runtime.getManifest().version
},()=>{
document.getElementById("link").click();
});
});

0 comments on commit b9f99b7

Please sign in to comment.