signal-desktop/js/views/debug_log_view.js
Scott Nonnenberg ffbcb4ecb5 Load debug log dialog immediately, then populate log data (#1540)
An immediate response to the user request to see the log, and then we
show the real data as soon as we've loaded it from disk.

Changes:
  - the IPC exchange to get the log data is now async
  - the API to fetch the log on the client side now returns a Promise
  - in the main process, the only disk access done synchronoously is
    reading the contents of the log directory. The JSON parsing of the
    resultant log data is now split up into three chunks.
  - We only send three keys from each log item to the renderer process:
    msg, time, level. Previously we sent the entire log entry with extra
    keys: hostname, pid, name.

FREEBIE
2017-10-04 14:40:35 -07:00

66 lines
1.9 KiB
JavaScript

/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
window.Whisper = window.Whisper || {};
Whisper.DebugLogLinkView = Whisper.View.extend({
templateName: 'debug-log-link',
initialize: function(options) {
this.url = options.url;
},
render_attributes: function() {
return {
url: this.url,
reportIssue: i18n('reportIssue')
};
}
});
Whisper.DebugLogView = Whisper.View.extend({
templateName: 'debug-log',
className: 'debug-log modal',
initialize: function() {
this.render();
this.$('textarea').val(i18n('loading'));
window.log.fetch().then(function(text) {
this.$('textarea').val(text);
}.bind(this));
},
events: {
'click .submit': 'submit',
'click .close': 'close'
},
render_attributes: {
title: i18n('submitDebugLog'),
cancel: i18n('cancel'),
submit: i18n('submit'),
close: i18n('gotIt'),
debugLogExplanation: i18n('debugLogExplanation')
},
close: function(e) {
e.preventDefault();
this.remove();
},
submit: function(e) {
e.preventDefault();
var text = this.$('textarea').val();
if (text.length === 0) {
return;
}
log.publish(text).then(function(url) {
var view = new Whisper.DebugLogLinkView({
url: url,
el: this.$('.result')
});
this.$('.loading').removeClass('loading');
view.render();
this.$('.link').focus().select();
}.bind(this));
this.$('.buttons, textarea').remove();
this.$('.result').addClass('loading');
}
});
})();