This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
console error indicator for status bar #7639
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9c2112a
error icon for main-toolbar
zaggino 6752ad0
change style
zaggino 4248275
do not override window.onerror handler
zaggino 74a2085
add comments
zaggino 003890e
add debug menu item
zaggino e47dc5b
move to DebugCommands
zaggino 24be428
add space
zaggino 0a858d9
move error icon to the left of other status bar indicators
zaggino 9293591
blink the number when error count is increased
zaggino 74af922
pointer cursor on hover
zaggino 65b3866
clear counter with console.clear
zaggino b081a1a
correct if formatting
zaggino 7f38ad6
add a tooltip
zaggino eb17609
added background fade like ins/ovr
zaggino c25357d
fixed according to comments
zaggino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
src/extensions/default/DebugCommands/ErrorNotification.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /* | ||
| * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a | ||
| * copy of this software and associated documentation files (the "Software"), | ||
| * to deal in the Software without restriction, including without limitation | ||
| * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| * and/or sell copies of the Software, and to permit persons to whom the | ||
| * Software is furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| * DEALINGS IN THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| /*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ | ||
| /*global define, $, brackets, window, document */ | ||
|
|
||
| define(function (require, exports, module) { | ||
| "use strict"; | ||
|
|
||
| var _ = brackets.getModule("thirdparty/lodash"), | ||
| AnimationUtils = brackets.getModule("utils/AnimationUtils"), | ||
| ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), | ||
| Strings = brackets.getModule("strings"); | ||
|
|
||
| var $span = null, | ||
| errorCount = 0, | ||
| _attached = false, | ||
| _windowOnError, | ||
| _consoleError, | ||
| _consoleClear; | ||
|
|
||
| ExtensionUtils.loadStyleSheet(module, "styles.css"); | ||
|
|
||
| function showDeveloperTools() { | ||
| try { | ||
| brackets.app.showDeveloperTools(); | ||
| } catch (err) { | ||
| console.error(err); | ||
| } | ||
| } | ||
|
|
||
| function refreshIndicator() { | ||
| // never show 0 errors | ||
| if (!_attached || errorCount === 0) { | ||
| // hide notifier if it was attached previously | ||
| // but errorCount was cleared or it was disabled | ||
| if ($span) { | ||
| $span.parent().hide(); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // update span if it was created before | ||
| if ($span) { | ||
| $span.text(errorCount).parent().show(); | ||
| return; | ||
| } | ||
|
|
||
| // create the span | ||
| $span = $("<span>").text(errorCount); | ||
| $("<div>") | ||
| .attr("id", "error-counter") | ||
| .attr("title", Strings.CMD_SHOW_DEV_TOOLS + "\u2026") | ||
| .text(Strings.ERRORS + ": ") | ||
| .append($span) | ||
| .on("click", showDeveloperTools) | ||
| .insertBefore("#status-bar .spinner"); | ||
| } | ||
|
|
||
| var blink = _.debounce(function () { | ||
| AnimationUtils.animateUsingClass($span.parent()[0], "flash"); | ||
| }, 100); | ||
|
|
||
| function incErrorCount() { | ||
| errorCount++; | ||
| blink(); | ||
| refreshIndicator(); | ||
| } | ||
|
|
||
| function clearErrorCount() { | ||
| errorCount = 0; | ||
| refreshIndicator(); | ||
| } | ||
|
|
||
| function attachFunctions() { | ||
| if (_attached) { | ||
| return; | ||
| } | ||
|
|
||
| _attached = true; | ||
| _windowOnError = window.onerror; | ||
| _consoleError = window.console.error; | ||
| _consoleClear = window.console.clear; | ||
|
|
||
| // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror | ||
| window.onerror = function (errorMsg, url, lineNumber) { | ||
| incErrorCount(); | ||
| if (_windowOnError) { | ||
| return _windowOnError(errorMsg, url, lineNumber); | ||
| } | ||
| // return false means that we didn't handle this error and it should run the default handler | ||
| return false; | ||
| }; | ||
|
|
||
| window.console.error = function () { | ||
| incErrorCount(); | ||
| return _consoleError.apply(window.console, arguments); | ||
| }; | ||
|
|
||
| window.console.clear = function () { | ||
| clearErrorCount(); | ||
| return _consoleClear.apply(window.console, arguments); | ||
| }; | ||
| } | ||
|
|
||
| function detachFunctions() { | ||
| if (!_attached) { | ||
| return; | ||
| } | ||
|
|
||
| _attached = false; | ||
| window.onerror = _windowOnError; | ||
| window.console.error = _consoleError; | ||
| window.console.clear = _consoleClear; | ||
| } | ||
|
|
||
| function toggle(bool) { | ||
| if (bool) { | ||
| attachFunctions(); | ||
| } else { | ||
| detachFunctions(); | ||
| } | ||
| refreshIndicator(); | ||
| } | ||
|
|
||
| // Public API | ||
| exports.toggle = toggle; | ||
|
|
||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #error-counter { | ||
| cursor: pointer; | ||
| transition: all 3s; | ||
| color: #f74687; | ||
| background-color: transparent; | ||
| } | ||
| #error-counter.flash { | ||
| transition: all 1s; | ||
| background-color: #ffb0cd; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,4 +13,4 @@ | |
| <div id="status-overwrite">{{STATUSBAR_INSERT}}</div> | ||
| <div class="spinner"></div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to do anything here if icon is toggled off, so maybe a quick check: