Skip to content

Commit

Permalink
Output more debuggable log
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 30, 2024
1 parent 9530ca7 commit 306eb60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 0 additions & 2 deletions webextensions/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { RecipientClassifier } from '/common/recipient-classifier.js';

import * as ListUtils from './list-utils.js';

Dialog.setLogger(log);

const TYPE_NEWLY_COMPOSED = 'new-message';
const TYPE_REPLY = 'reply';
const TYPE_DRAFT = 'draft';
Expand Down
6 changes: 5 additions & 1 deletion webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Configs from '/extlib/Configs.js';
import * as Constants from './constants.js';
import * as Dialog from '/extlib/dialog.js';

const OVERRIDE_DEFAULT_CONFIGS = {}; /* Replace this for more customization on an enterprise use. */

Expand Down Expand Up @@ -258,9 +259,12 @@ export function log(message, ...args) {
for (let i = 0; i < nest; i++) {
indent += ' ';
}
console.log(`flex-confirm-mail: ${indent}${message}`, ...args);
const timestamp = new Date().toLocaleString();
console.log(`${timestamp} flex-confirm-mail: ${indent}${message}`, ...args);
}

Dialog.setLogger(log);

export async function sendToHost(message) {
try {
message.logging = message.logging && configs.debug;
Expand Down
15 changes: 12 additions & 3 deletions webextensions/dialog/countdown/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import '/extlib/l10n.js';
import * as Dialog from '/extlib/dialog.js';

import {
configs
configs,
log,
} from '/common/common.js';

const mCounter = document.getElementById('count');
Expand Down Expand Up @@ -41,10 +42,18 @@ configs.$loaded.then(async () => {
});

const start = Date.now();
window.setInterval(() => {
const timer = window.setInterval(() => {
const rest = Math.ceil(configs.countdownSeconds - ((Date.now() - start) / 1000));
mCounter.textContent = rest;
if (rest <= 0)
if (rest > 0)
return;
window.clearInterval(timer);
try {
Dialog.accept();
}
catch(error) {
log('failed to accept countdown dialog: ', error);
window.close();
}
}, 250);
});

0 comments on commit 306eb60

Please sign in to comment.