2015-09-16 01:48:49 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
2016-02-03 01:55:27 +00:00
|
|
|
|
|
|
|
var LogEntry = Backbone.Model.extend({
|
|
|
|
database: Whisper.Database,
|
|
|
|
storeName: 'debug',
|
|
|
|
printTime: function() {
|
|
|
|
try {
|
|
|
|
return new Date(this.get('time')).toISOString();
|
|
|
|
} catch(e) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
printValue: function() {
|
|
|
|
return this.get('value') || '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var DebugLog = Backbone.Collection.extend({
|
|
|
|
database: Whisper.Database,
|
|
|
|
storeName: 'debug',
|
|
|
|
model: LogEntry,
|
|
|
|
comparator: 'time',
|
|
|
|
initialize: function() {
|
|
|
|
this.fetch({remove: false});
|
|
|
|
},
|
|
|
|
log: function(str) {
|
|
|
|
this.add({time: Date.now(), value: str}).save();
|
2016-02-13 02:34:06 +00:00
|
|
|
while (this.length > MAX_MESSAGES) {
|
2016-02-03 01:55:27 +00:00
|
|
|
this.at(0).destroy();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
print: function() {
|
|
|
|
return this.map(function(entry) {
|
|
|
|
return entry.printTime() + ' ' + entry.printValue();
|
|
|
|
}).join('\n');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-21 21:46:30 +00:00
|
|
|
var MAX_MESSAGES = 5000;
|
2015-09-16 01:48:49 +00:00
|
|
|
var PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
|
2016-02-03 01:55:27 +00:00
|
|
|
var log = new DebugLog();
|
2015-09-16 01:48:49 +00:00
|
|
|
if (window.console) {
|
|
|
|
console._log = console.log;
|
2016-02-18 01:08:50 +00:00
|
|
|
console.log = function() {
|
2015-09-16 18:09:16 +00:00
|
|
|
console._log.apply(this, arguments);
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
var str = args.join(' ').replace(PHONE_REGEX, "+[REDACTED]$1");
|
2016-02-03 01:55:27 +00:00
|
|
|
log.log(str);
|
2015-09-16 01:48:49 +00:00
|
|
|
};
|
|
|
|
console.get = function() {
|
2016-02-03 01:55:27 +00:00
|
|
|
return window.navigator.userAgent +
|
|
|
|
' Signal-Desktop/' + chrome.runtime.getManifest().version +
|
|
|
|
'\n' + log.print();
|
2015-09-16 01:48:49 +00:00
|
|
|
};
|
|
|
|
console.post = function(log) {
|
|
|
|
if (log === undefined) {
|
|
|
|
log = console.get();
|
|
|
|
}
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
$.post('https://api.github.com/gists', textsecure.utils.jsonThing({
|
|
|
|
"files": { "debugLog.txt": { "content": log } }
|
|
|
|
})).then(function(response) {
|
|
|
|
console._log('Posted debug log to ', response.html_url);
|
|
|
|
resolve(response.html_url);
|
|
|
|
}).fail(resolve);
|
|
|
|
});
|
|
|
|
};
|
2015-12-07 21:42:19 +00:00
|
|
|
|
|
|
|
window.onerror = function(message, script, line, col, error) {
|
2017-06-20 23:12:30 +00:00
|
|
|
console.log(error.stack);
|
2015-12-07 21:42:19 +00:00
|
|
|
};
|
2015-09-16 01:48:49 +00:00
|
|
|
}
|
|
|
|
})();
|