Skip to content

Commit

Permalink
#5 change tab title color if memory exceeds threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyrne01 committed Mar 28, 2015
1 parent 7852d90 commit 030e907
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Provides user with tab related stats/data
* Memory usage displayed on panel UI (JSON or Plain)
* Preference to include url on memory usage panel UI
* Prepend, append or disable tab memory usage in title
* Change tab title color if memory exceeds specified threshold
* Preference to set interval between memory usage collection
* Top 5 memory consumers drawn on graph
* Graph types include: Line, Bar, Radar and PolarArea
Expand Down
8 changes: 8 additions & 0 deletions addon/data/html/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ <h3 data-l10n-id="ui_title"></h3>
<input id="memoryUrlInUsage" type="checkbox" />
</td>
</tr>
<tr>
<td>
<label data-l10n-id="memoryCautionThreshold_title"></label>
</td>
<td>
<input id="memoryCautionThreshold" type="number" />
</td>
</tr>
<tr>
<td>
<label data-l10n-id="panelWidth_title"></label>
Expand Down
12 changes: 12 additions & 0 deletions addon/data/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ document.getElementById('memoryTracking').addEventListener("change", function (e
document.getElementById('memoryUsageOnTabTitles').disabled = false;
document.getElementById('memoryFormat').disabled = false;
document.getElementById('memoryUrlInUsage').disabled = false;
document.getElementById('memoryCautionThreshold').disabled = false;
document.getElementById('graphType').disabled = false;

} else {
Expand All @@ -25,6 +26,7 @@ document.getElementById('memoryTracking').addEventListener("change", function (e
document.getElementById('memoryUsageOnTabTitles').disabled = true;
document.getElementById('memoryFormat').disabled = true;
document.getElementById('memoryUrlInUsage').disabled = true;
document.getElementById('memoryCautionThreshold').disabled = true;
document.getElementById('graphType').disabled = true;

document.getElementById("memoryDump").textContent = '';
Expand All @@ -36,6 +38,15 @@ document.getElementById('schedulePreciseGC').addEventListener("click", function
self.port.emit("schedulePreciseGC", '');
}, false);

document.getElementById('memoryCautionThreshold').onkeyup = function (event) {
if (parseInt(document.getElementById('memoryCautionThreshold').value) >= 0) {
self.port.emit("memoryCautionThreshold", document.getElementById('memoryCautionThreshold').value);
document.getElementById('memoryCautionThreshold').className = 'green';
} else {
document.getElementById('memoryCautionThreshold').className = 'red';
}
};

tabdata_helper.inputValueChanged('panelHeight', 185);
tabdata_helper.inputValueChanged('panelWidth', 45);
tabdata_helper.inputValueChanged('memoryInterval', 0);
Expand All @@ -60,6 +71,7 @@ self.port.on("stats", function (stats) {
document.getElementById("memoryUsageOnTabTitles").value = parsedStats.memoryUsageOnTabTitles;
document.getElementById("memoryFormat").value = parsedStats.memoryFormat;
document.getElementById("memoryUrlInUsage").checked = parsedStats.memoryUrlInUsage;
document.getElementById("memoryCautionThreshold").value = parsedStats.memoryCautionThreshold;
document.getElementById("panelWidth").value = parsedStats.panelWidth;
document.getElementById("panelHeight").value = parsedStats.panelHeight;
document.getElementById("graphType").value = parsedStats.graphType;
Expand Down
5 changes: 5 additions & 0 deletions addon/lib/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ exports.init = function () {
memoryFormat: Preference.get("memoryFormat"),
memoryUsageOnTabTitles: Preference.get("memoryUsageOnTabTitles"),
memoryUrlInUsage: Preference.get("memoryUrlInUsage"),
memoryCautionThreshold: Preference.get("memoryCautionThreshold"),
panelWidth: Preference.get("panelWidth"),
panelHeight: Preference.get("panelHeight"),
graphType: Preference.get("graphType")
Expand Down Expand Up @@ -73,6 +74,10 @@ exports.init = function () {
Tab.updateMemoryCounters();
});

panel.port.on("memoryCautionThreshold", function (value) {
Preference.set('memoryCautionThreshold', value);
});

panel.port.on("schedulePreciseGC", function (value) {
Chrome.gc(panel);
});
Expand Down
34 changes: 31 additions & 3 deletions addon/lib/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var tabs = require("sdk/tabs"),
Preference = require("./Preference"),
Panel = require("./Panel"),
Chrome = require("./Chrome"),
WindowUtils = require("./WindowUtils"),
sessionCount = 0,
currentCount = 0,
markedTabs = [],
Expand Down Expand Up @@ -243,9 +244,14 @@ function initFinishReporting() {

if (repl.indexOf(tab.url) >= 0) {

/*if (JSON.parse(markedTabs[j]).amount >= (Preference.get('memoryCautionThreshold') * 1000000)) {
console.log('CAUTION! ' + tab.title + ': ' + JSON.parse(markedTabs[j]).amount);
}*/
if (JSON.parse(markedTabs[j]).amount >= (Preference.get('memoryCautionThreshold') * 1000000)) {

styleTab(repl, 'red');

} else {

styleTab(repl, '');
}

// format data for panel
memoryDump.push({
Expand Down Expand Up @@ -377,3 +383,25 @@ function initFinishReporting() {
Panel.get().port.emit("memoryDump", payload);
};
}

function styleTab(currentUrl, color) {

var allWindows = WindowUtils.getWindows();

for (var h = 0; h < allWindows.length; h++) { // loop all windows

if (allWindows[h].gBrowser && allWindows[h].gBrowser.tabContainer) {
var browserTabs = allWindows[h].gBrowser.tabContainer.childNodes;

for (var q = 0; q < browserTabs.length; q++) { // loop all tabs within window

var browser = allWindows[h].gBrowser.getBrowserForTab(browserTabs[q]);

if (currentUrl === browser.currentURI.spec) {

browserTabs[q].style.color = color;
}
}
}
}
}
7 changes: 7 additions & 0 deletions addon/lib/WindowUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var window_utils = require('sdk/window/utils');

exports.getWindows = function () {
return window_utils.windows(null, {
includePrivate: true
});
};
1 change: 1 addition & 0 deletions addon/locale/bg.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Формат на използването на паметт
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=праг Memory повишено внимание? (В мегабайти)
showUrl_title=Show Url на използване на паметта панел?
garbageCollection_title=Извършване на събиране на боклука
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/cs-CZ.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Formát využití paměti na desce?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=Memory práh opatrnost? (V MB)
showUrl_title=Zobrazit URL na využití panelu paměti?
garbageCollection_title=Provést úklid
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/de-DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Format der Speichernutzung auf Holz?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=Speicher Vorsicht Schwelle? (In MB)
showUrl_title=Anzeige URL auf die Speichernutzung Platte?
garbageCollection_title=Führen Sie eine Garbage Collection
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/en-GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ memoryUsageOnTabTitlesPref_options.Disable=Disable
memoryFormat_title=Format of memory usage on panel?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain
memoryCautionThreshold_title=Memory caution threshold? (In megabytes)

showUrl_title=Show Url on memory usage panel?
garbageCollection_title=Perform a garbage collection
Expand Down
1 change: 1 addition & 0 deletions addon/locale/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Format of memory usage on panel?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=Memory caution threshold? (In megabytes)
showUrl_title=Show Url on memory usage panel?
garbageCollection_title=Perform a garbage collection
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/es-ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Formato de uso de memoria en el panel?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Llanura

memoryCautionThreshold_title=umbral de precaución de memoria? (En megabytes)
showUrl_title=Mostrar URL en el panel de uso de la memoria?
garbageCollection_title=Realizar una recolección de basura
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/fr-FR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Format d'utilisation de la mémoire sur le panneau?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plaine
memoryCautionThreshold_title=Mémoire seuil de précaution? (En mégaoctets)
showUrl_title=Montrer URL sur le panneau d'utilisation de la mémoire?
garbageCollection_title=Effectuer une collecte des ordures
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/it-IT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Formato di utilizzo della memoria sul pannello?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=Memoria soglia prudenza? (In megabyte)
showUrl_title=Mostra URL sul pannello di utilizzo della memoria?
garbageCollection_title=Eseguire una garbage collection
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/ja-JP.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=パネル上のメモリ使用量の形式?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=平野

memoryCautionThreshold_title=メモリ注意スレッショルド? (メガバイト単位)
showUrl_title=のURLを表示?
garbageCollection_title=ガベージコレクションを実行します
run_title=ラン
Expand Down
1 change: 1 addition & 0 deletions addon/locale/ko-KR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=패널에 메모리 사용량의 형식?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=일반

memoryCautionThreshold_title=메모리주의 임계 값? (메가 바이트)
showUrl_title=표시메모리 사용량 패널 URL?
garbageCollection_title=가비지 수집을 수행
run_title=실행
Expand Down
1 change: 1 addition & 0 deletions addon/locale/pl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Format zużycia pamięci na panelu?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=Pamięć próg ostrożności? (W megabajtach)
showUrl_title=Pokaż URL na pamięci panelu użytkowania?
garbageCollection_title=Wykonaj wywóz śmieci
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/pt-PT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Formato de uso de memória no painel?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=limiar de cautela de memória? (Em megabytes)
showUrl_title=Mostrar Url no painel uso de memória?
garbageCollection_title=Executar uma coleta de lixo
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/ru-RU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=формат использования памяти на п
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Обычная

memoryCautionThreshold_title=порог осторожность памяти? (В мегабайтах)
showUrl_title=Показать URL на панели использования памяти?
garbageCollection_title=Выполните сборку мусора
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/sv-SE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=Format för minnesanvändning på panelen?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Plain

memoryCautionThreshold_title=Minnes försiktighet tröskel? (I megabyte)
showUrl_title=Visa Url på minnesanvändningen panel?
garbageCollection_title=Utför en sophämtning
run_title=Kör
Expand Down
1 change: 1 addition & 0 deletions addon/locale/uk-UA.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=формат використання пам'яті на па
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=Звичайна
memoryCautionThreshold_title=поріг обережність пам'яті? (В мегабайтах)
showUrl_title=Показати URL на панелі використання пам'яті?
garbageCollection_title=Виконайте збірку сміття
run_title=Run
Expand Down
1 change: 1 addition & 0 deletions addon/locale/zh-CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ memoryFormat_title=內存使用的格式面板上?
memoryFormat_options.JSON=JSON
memoryFormat_options.Plain=平原

memoryCautionThreshold_title=內存謹慎門檻? 兆)
showUrl_title=顯示網址內存使用面板上?
garbageCollection_title=執行垃圾回收
run_title=運行
Expand Down
7 changes: 6 additions & 1 deletion addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"title": "Show Url on memory usage panel?",
"type": "bool",
"value": true
}, {
"name": "memoryCautionThreshold",
"title": "Memory caution threshold? (In megabytes)?",
"type": "string",
"value": "20"
}, {
"name": "panelWidth",
"title": "Width of Panel UI",
Expand All @@ -60,7 +65,7 @@
"name": "panelHeight",
"title": "Height of Panel UI",
"type": "string",
"value": "500"
"value": "525"
}, {
"name": "graphType",
"title": "Graph type?",
Expand Down

0 comments on commit 030e907

Please sign in to comment.