Use window.log in browser context, turn on console eslint rule

This commit is contained in:
Scott Nonnenberg 2018-07-21 12:00:08 -07:00
parent 4320b125dd
commit 5933a34a18
71 changed files with 816 additions and 559 deletions

View file

@ -129,7 +129,7 @@
// this.initialLoadComplete. An example of this: on a phone-pairing setup.
_.defaults(options, { initialLoadComplete: this.initialLoadComplete });
console.log('open inbox');
window.log.info('open inbox');
this.closeInstaller();
if (!this.inboxView) {

View file

@ -29,15 +29,17 @@
this.remove();
},
async onDeleteAllData() {
console.log('Deleting everything!');
window.log.info('Deleting everything!');
this.step = CLEAR_DATA_STEPS.DELETING;
this.render();
try {
await Database.close();
console.log('All database connections closed. Starting delete.');
window.log.info('All database connections closed. Starting delete.');
} catch (error) {
console.log('Something went wrong closing all database connections.');
window.log.error(
'Something went wrong closing all database connections.'
);
}
this.clearAllData();
@ -46,7 +48,7 @@
try {
await Promise.all([Logs.deleteAll(), Database.drop()]);
} catch (error) {
console.log(
window.log.error(
'Something went wrong deleting all data:',
error && error.stack ? error.stack : error
);

View file

@ -13,14 +13,14 @@
const $el = this.$(`.${conversation.cid}`);
if (!$el || !$el.length) {
console.log(
window.log.warn(
'updateLocation: did not find element for conversation',
conversation.idForLogging()
);
return;
}
if ($el.length > 1) {
console.log(
window.log.warn(
'updateLocation: found more than one element for conversation',
conversation.idForLogging()
);
@ -33,7 +33,7 @@
const elIndex = $allConversations.index($el);
if (elIndex < 0) {
console.log(
window.log.warn(
'updateLocation: did not find index for conversation',
conversation.idForLogging()
);

View file

@ -259,7 +259,7 @@
},
unload(reason) {
console.log(
window.log.info(
'unloading conversation',
this.model.idForLogging(),
'due to:',
@ -329,7 +329,7 @@
return;
}
console.log(
window.log.info(
'trimming conversation',
this.model.idForLogging(),
'of',
@ -482,7 +482,7 @@
const view = this.loadingScreen;
if (view) {
const openDelta = Date.now() - this.openStart;
console.log(
window.log.info(
'Conversation',
this.model.idForLogging(),
'took',
@ -507,7 +507,7 @@
this.model.updateVerified().then(() => {
this.onVerifiedChange();
this.statusFetch = null;
console.log('done with status fetch');
window.log.info('done with status fetch');
})
);
@ -786,10 +786,10 @@
},
fetchMessages() {
console.log('fetchMessages');
window.log.info('fetchMessages');
this.$('.bar-container').show();
if (this.inProgressFetch) {
console.log('Multiple fetchMessage calls!');
window.log.warn('Multiple fetchMessage calls!');
}
// Avoiding await, since we want to capture the promise and make it available via
@ -806,7 +806,7 @@
this.inProgressFetch = null;
})
.catch(error => {
console.log(
window.log.error(
'fetchMessages error:',
error && error.stack ? error.stack : error
);
@ -1195,7 +1195,7 @@
this.showSendConfirmationDialog(e, contacts);
} catch (error) {
this.focusMessageFieldAndClearDisabled();
console.log(
window.log.error(
'checkUnverifiedSendMessage error:',
error && error.stack ? error.stack : error
);
@ -1221,7 +1221,7 @@
this.showSendConfirmationDialog(e, contacts);
} catch (error) {
this.focusMessageFieldAndClearDisabled();
console.log(
window.log.error(
'checkUntrustedSendMessage error:',
error && error.stack ? error.stack : error
);
@ -1290,7 +1290,6 @@
if (message) {
const quote = await this.model.makeQuote(this.quotedMessage);
console.log('DEBUG', { quote });
this.quote = quote;
this.focusMessageFieldAndClearDisabled();
@ -1371,7 +1370,7 @@
const attachments = await this.fileInput.getFiles();
const sendDelta = Date.now() - this.sendStart;
console.log('Send pre-checks took', sendDelta, 'milliseconds');
window.log.info('Send pre-checks took', sendDelta, 'milliseconds');
this.model.sendMessage(message, attachments, this.quote);
@ -1381,7 +1380,7 @@
this.forceUpdateMessageFieldSize(e);
this.fileInput.deleteFiles();
} catch (error) {
console.log(
window.log.error(
'Error pulling attached files before send',
error && error.stack ? error.stack : error
);

View file

@ -67,7 +67,7 @@
.focus()
.select();
} catch (error) {
console.log(
window.log.error(
'DebugLogView error:',
error && error.stack ? error.stack : error
);

View file

@ -161,10 +161,11 @@
// we use the variable on this here to ensure cleanup if we're interrupted
this.previewObjectUrl = URL.createObjectURL(file);
const type = 'image/png';
const thumbnail = await VisualAttachment.makeVideoScreenshot(
this.previewObjectUrl,
type
);
const thumbnail = await VisualAttachment.makeVideoScreenshot({
objectUrl: this.previewObjectUrl,
contentType: type,
logger: window.log,
});
URL.revokeObjectURL(this.previewObjectUrl);
const data = await VisualAttachment.blobToArrayBuffer(thumbnail);
@ -197,7 +198,7 @@
this.addThumb('images/file.svg');
}
} catch (e) {
console.log(
window.log.error(
`Was unable to generate thumbnail for file type ${contentType}`,
e && e.stack ? e.stack : e
);
@ -297,10 +298,11 @@
const objectUrl = URL.createObjectURL(file);
const arrayBuffer = await VisualAttachment.makeImageThumbnail(
const arrayBuffer = await VisualAttachment.makeImageThumbnail({
size,
objectUrl
);
objectUrl,
logger: window.log,
});
URL.revokeObjectURL(objectUrl);
return this.readFile(arrayBuffer);

View file

@ -112,7 +112,7 @@
},
error => {
if (error.name !== 'ChooseError') {
console.log(
window.log.error(
'Error choosing directory:',
error && error.stack ? error.stack : error
);
@ -158,7 +158,7 @@
return this.finishLightImport(directory);
})
.catch(error => {
console.log(
window.log.error(
'Error importing:',
error && error.stack ? error.stack : error
);

View file

@ -193,7 +193,7 @@
this.onEmpty();
break;
default:
console.log(
window.log.error(
'Whisper.InboxView::startConnectionListener:',
'Unknown web socket status:',
status

View file

@ -104,19 +104,22 @@
)
.catch(this.handleDisconnect.bind(this));
},
handleDisconnect(e) {
console.log('provisioning failed', e.stack);
handleDisconnect(error) {
window.log.error(
'provisioning failed',
error && error.stack ? error.stack : error
);
this.error = e;
this.error = error;
this.render();
if (e.message === 'websocket closed') {
if (error.message === 'websocket closed') {
this.trigger('disconnected');
} else if (
e.name !== 'HTTPError' ||
(e.code !== CONNECTION_ERROR && e.code !== TOO_MANY_DEVICES)
error.name !== 'HTTPError' ||
(error.code !== CONNECTION_ERROR && error.code !== TOO_MANY_DEVICES)
) {
throw e;
throw error;
}
},
reconnect() {
@ -134,7 +137,7 @@
},
setProvisioningUrl(url) {
if ($('#qr').length === 0) {
console.log('Did not find #qr element in the DOM!');
window.log.error('Did not find #qr element in the DOM!');
return;
}
@ -186,7 +189,7 @@
}
return tsp.removeAllData().then(finish, error => {
console.log(
window.log.error(
'confirmNumber: error clearing database',
error && error.stack ? error.stack : error
);

View file

@ -81,7 +81,10 @@
if (result.name === 'OutgoingIdentityKeyError') {
this.onSafetyNumberChanged();
} else {
console.log('failed to toggle verified:', result.stack);
window.log.error(
'failed to toggle verified:',
result && result.stack ? result.stack : result
);
}
} else {
const keyError = _.some(
@ -92,7 +95,10 @@
this.onSafetyNumberChanged();
} else {
_.forEach(result.errors, error => {
console.log('failed to toggle verified:', error.stack);
window.log.error(
'failed to toggle verified:',
error && error.stack ? error.stack : error
);
});
}
}

View file

@ -51,7 +51,7 @@
if (this.context) {
this.context.close().then(() => {
console.log('audio context closed');
window.log.info('audio context closed');
});
}
this.context = null;
@ -97,10 +97,12 @@
this.close();
if (error && error.name === 'PermissionDeniedError') {
console.log('RecorderView.onError: Microphone access is not allowed!');
window.log.warn(
'RecorderView.onError: Microphone access is not allowed!'
);
window.showPermissionsPopup();
} else {
console.log(
window.log.error(
'RecorderView.onError:',
error && error.stack ? error.stack : error
);

View file

@ -23,7 +23,7 @@
change(e) {
const value = e.target.checked;
this.setFn(value);
console.log(this.name, 'changed to', value);
window.log.info(this.name, 'changed to', value);
},
populate() {
this.$('input').prop('checked', !!this.value);
@ -42,7 +42,7 @@
change(e) {
this.value = e.target.checked;
this.setFn(this.value);
console.log('media-permissions changed to', this.value);
window.log.info('media-permissions changed to', this.value);
},
populate() {
this.$('input').prop('checked', Boolean(this.value));
@ -62,7 +62,7 @@
change(e) {
const value = this.$(e.target).val();
this.setFn(value);
console.log(this.name, 'changed to', value);
window.log.info(this.name, 'changed to', value);
},
populate() {
this.$(`#${this.name}-${this.value}`).attr('checked', 'checked');
@ -177,12 +177,12 @@
onsuccess() {
window.setLastSyncTime(Date.now());
this.lastSyncTime = Date.now();
console.log('sync successful');
window.log.info('sync successful');
this.enable();
this.render();
},
ontimeout() {
console.log('sync timed out');
window.log.error('sync timed out');
this.$('.synced_at').hide();
this.$('.sync_failed').show();
this.enable();
@ -190,7 +190,7 @@
async sync() {
this.$('.sync_failed').hide();
if (window.initialData.isPrimary) {
console.log('Tried to sync from device 1');
window.log.warn('Tried to sync from device 1');
return;
}

View file

@ -46,7 +46,7 @@
.catch(this.log.bind(this));
},
log(s) {
console.log(s);
window.log.info(s);
this.$('#status').text(s);
},
validateCode() {