@@ -3,6 +3,7 @@ import syncOptions from '../options/syncOptions';
33import createMenu from './contextMenus' ;
44import openDevToolsWindow from './openWindow' ;
55let connections = { } ;
6+ let catchedErrors = { } ;
67
78window . syncOptions = syncOptions ; // Used in the options page
89
@@ -60,13 +61,40 @@ function messaging(request, sender, sendResponse) {
6061 if ( tabId in connections ) {
6162 connections [ tabId ] . postMessage ( { payload : payload } ) ;
6263 }
64+
65+ // Notify when errors occur in the app
66+ syncOptions . get ( options => {
67+ if ( ! options . notifyErrors ) return ;
68+ const error = payload . computedStates [ payload . currentStateIndex ] . error ;
69+ if ( error ) {
70+ chrome . notifications . create ( 'redux-error' , {
71+ type : 'basic' ,
72+ title : 'An error occurred in the app' ,
73+ message : error ,
74+ iconUrl : 'img/logo/48x48.png' ,
75+ isClickable : true
76+ } ) ;
77+ if ( typeof store . id === 'number' ) {
78+ chrome . pageAction . setIcon ( { tabId : store . id , path : 'img/logo/error.png' } ) ;
79+ catchedErrors . tab = store . id ;
80+ }
81+ } else if ( catchedErrors . last && typeof store . id === 'number' && catchedErrors . tab === store . id ) {
82+ chrome . pageAction . setIcon ( { tabId : store . id , path : 'img/logo/38x38.png' } ) ;
83+ }
84+ catchedErrors . last = error ;
85+ } ) ;
6386 }
6487 return true ;
6588}
6689
6790onMessage ( messaging ) ;
6891chrome . runtime . onMessageExternal . addListener ( messaging ) ;
6992
93+ chrome . notifications . onClicked . addListener ( id => {
94+ chrome . notifications . clear ( id ) ;
95+ if ( id === 'redux-error' ) openDevToolsWindow ( 'devtools-right' ) ;
96+ } ) ;
97+
7098export function toContentScript ( action ) {
7199 if ( store . id in connections ) {
72100 connections [ store . id ] . postMessage ( { action : action } ) ;
0 commit comments