Skip to content

Commit d3c2faf

Browse files
committed
Notify when errors occur in the app
Related to #27.
1 parent a5ecf0c commit d3c2faf

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src/assets/img/logo/error.png

1.71 KB
Loading

src/browser/extension/background/messaging.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import syncOptions from '../options/syncOptions';
33
import createMenu from './contextMenus';
44
import openDevToolsWindow from './openWindow';
55
let connections = {};
6+
let catchedErrors = {};
67

78
window.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

6790
onMessage(messaging);
6891
chrome.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+
7098
export function toContentScript(action) {
7199
if (store.id in connections) {
72100
connections[ store.id ].postMessage({action: action});

src/browser/extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"externally_connectable": {
6666
"ids": ["*"]
6767
},
68-
"permissions": [ "contextMenus", "tabs", "storage", "<all_urls>" ],
68+
"permissions": [ "notifications", "contextMenus", "tabs", "storage", "<all_urls>" ],
6969
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'; style-src * 'unsafe-inline'; img-src 'self' data:;",
7070
"update_url": "https://clients2.google.com/service/update2/crx",
7171
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdJEPwY92xUACA9CcDBDBmbdbp8Ap3cKQ0DJTUuVQvqb4FQAv8RtKY3iUjGvdwuAcSJQIZwHXcP2aNDH3TiFik/NhRK2GRW8X3OZyTdkuDueABGP2KEX8q1WQDgjX/rPIinGYztUrvoICw/UerMPwNW62jwGoVU3YhAGf+15CgX2Y6a4tppnf/+1mPedKPidh0RsM+aJY98rX+r1SPAHPcGzMjocLkqcT75DZBXer8VQN14tOOzRCd6T6oy7qm7eWru8lJwcY66qMQvhk0osqEod2G3nA7aTWpmqPFS66VEiecP9PgZlp8gQdgZ3dFhA62exydlD55JuRhiMIR63yQIDAQAB"

src/browser/extension/options/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ chrome.runtime.getBackgroundPage( background => {
7070
<span className="caption">Pages urls to inject DevTools in (regex from new line):</span>
7171
<textarea onChange={saveUrls} id="urls" defaultValue={items.urls}/>
7272
</div>
73+
<div className="input">
74+
<span className="caption">Show errors:</span>
75+
<input id="notifyErrors" type="checkbox" defaultChecked={items.notifyErrors} onChange={saveOption}/>
76+
<span className="comment">(will notify when errors occur in the app)</span>
77+
</div>
7378
</div>,
7479
document.getElementById('root')
7580
);

src/browser/extension/options/syncOptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const get = callback => {
1919
blacklist: '',
2020
timeout: 1,
2121
serialize: true,
22+
notifyErrors: true,
2223
inject: true,
2324
urls: '^https?://localhost|0\\.0\\.0\\.0:\\d+\n^https?://.+\\.github\\.io'
2425
}, function(items) {

0 commit comments

Comments
 (0)