Skip to content

Commit

Permalink
Add update notification
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck committed May 11, 2016
1 parent 4d5ac3e commit 320b3e8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/gh-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ export function showTooltip($target, msg) {
$target.attr('aria-label', msg);
}

export function showNotification(message, headline = 'New Octo Linker improvements') {
function getUserName() {
const el = window.document.querySelector('.header .css-truncate-target');
if (el && el.innerHTML.length) {
return ' ' + el.innerHTML;
}
return '';
}

export function showNotification() {
const containerEl = document.getElementById('js-flash-container');
const username = getUserName();

const html = `<div class="flash flash-full">
<div class="container">
<a href="https://octo-linker.github.io/" class="btn btn-sm flash-action">Read more</a>
<strong>${headline}</strong><br>
${message}
<a href="https://github.com/OctoLinker/browser-extension/releases" class="btn btn-sm flash-action">Read more</a>
<strong>Hello${username},</strong><br>
A new version of the OctoLinker extension has been released!
</div>
</div>`;

Expand Down
17 changes: 17 additions & 0 deletions lib/notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { showNotification } from './gh-interface';

let isNewVersion = false;
const pkgVersion = require('../package.json').version.split('.').slice(0, -1).join('.');

const installedVersion = window.localStorage.getItem('OctoLinkerVersion');
window.localStorage.setItem('OctoLinkerVersion', pkgVersion);

if (installedVersion && installedVersion !== pkgVersion) {
isNewVersion = true;
}

export default function () {
if (isNewVersion) {
showNotification();
}
}
2 changes: 2 additions & 0 deletions lib/octo-linker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import injection from 'github-injection';
import notification from './notification';
import BlobReader from '../packages/blob-reader';
import clickHandler from './click-handler';
import PluginManager from './plugin-manager.js';
Expand All @@ -13,6 +14,7 @@ import Ruby from './plugins/ruby';
function initialize(self) {
debugMode(false);
clickHandler();
notification();

self._blobReader = new BlobReader();
self._pluginManager = new PluginManager([
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "OctoLinker",
"version": "4.0.0",
"engines": {
"node": ">=4.0.0"
},
Expand Down

0 comments on commit 320b3e8

Please sign in to comment.