Skip to content

Commit 99a184f

Browse files
author
Pedro Aim
committed
log backup for errors
1 parent 12c1fdb commit 99a184f

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

electron_app/src/database/DBEexporter.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ const exportLabelTable = async accountId => {
596596
return formatTableRowsToString(Table.LABEL, labelRows);
597597
};
598598

599-
const exportEmailTable = async accountId => {
600-
const username = myAccount.email;
599+
const exportEmailTable = async (accountId, email) => {
601600
let emailRows = [];
602601
let shouldEnd = false;
603602
let offset = 0;
@@ -629,14 +628,14 @@ const exportEmailTable = async accountId => {
629628

630629
const body =
631630
(await getEmailBody({
632-
username,
631+
username: email,
633632
metadataKey: newRow.key,
634633
password: globalManager.databaseKey.get()
635634
})) ||
636635
newRow.content ||
637636
'';
638637
const headers = await getEmailHeaders({
639-
username,
638+
username: email,
640639
metadataKey: newRow.key,
641640
password: globalManager.databaseKey.get()
642641
});
@@ -847,6 +846,7 @@ const exportEncryptDatabaseToFile = async ({
847846
const [recipientId, domain] = accountObj
848847
? accountObj.recipientId.split('@')
849848
: myAccount.recipientId.split('@');
849+
const accountEmail = `${recipientId}@${domain || APP_DOMAIN}`;
850850
const accountId = accountObj ? accountObj.id : myAccount.id;
851851
const signature =
852852
accountObj && accountObj.signature !== undefined
@@ -876,7 +876,7 @@ const exportEncryptDatabaseToFile = async ({
876876
handleProgressCallback(
877877
exportProgress,
878878
'saving_account',
879-
`${recipientId}@${domain || APP_DOMAIN}`,
879+
accountEmail,
880880
progressCallback
881881
);
882882

@@ -926,13 +926,13 @@ const exportEncryptDatabaseToFile = async ({
926926
progressCallback
927927
);
928928

929-
const result = await exportTable.export(accountId);
929+
const result = await exportTable.export(accountId, accountEmail);
930930

931931
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
932932
handleProgressCallback(
933933
exportProgress,
934934
`saving_${exportTable.suffix}`,
935-
`${recipientId}@${domain || APP_DOMAIN}`,
935+
accountEmail,
936936
progressCallback
937937
);
938938

@@ -943,7 +943,7 @@ const exportEncryptDatabaseToFile = async ({
943943
handleProgressCallback(
944944
exportProgress,
945945
'almost_done',
946-
`${recipientId}@${domain || APP_DOMAIN}`,
946+
accountEmail,
947947
progressCallback
948948
);
949949
};

electron_app/src/ipc/backup.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {
2222
const { APP_DOMAIN } = require('../utils/const');
2323
const { updateAccount } = require('./../database');
2424
const myAccount = require('../Account');
25+
const logger = require('../logger');
2526
let autoBackupsTime = [];
2627
let currentAutobackup = null;
2728
let nextBackupTimer = null;
@@ -68,6 +69,10 @@ const doExportBackupUnencrypted = async params => {
6869
? accountObj.recipientId.split('@')
6970
: myAccount.recipientId.split('@');
7071

72+
logger.info(
73+
`Unencrypted Backup Started For Account: ${recipientId}@${domain}`
74+
);
75+
7176
handleProgressCallback(
7277
-1,
7378
'starting_backup',
@@ -133,6 +138,7 @@ ipc.answerRenderer('export-backup-encrypted', async params => {
133138
await simulatePause(2000);
134139
globalManager.windowsEvents.enable();
135140
commitBackupStatus('local-backup-enable-events', 2);
141+
logger.info(`Encrypted Backup Started for Path: ${backupPath}`);
136142
const backupSize = await exportBackupEncrypted({
137143
backupPath,
138144
password
@@ -222,7 +228,7 @@ const initAutoBackupMonitor = () => {
222228
!autoBackupNextDate ||
223229
account.id === currentAutobackup
224230
)
225-
return;
231+
continue;
226232

227233
const now = moment();
228234
const pendingDate = moment(autoBackupNextDate);
@@ -235,6 +241,8 @@ const initAutoBackupMonitor = () => {
235241
}
236242

237243
if (!currentAutobackup) checkNextBackup();
244+
245+
logger.debug(`Backups Started : ${JSON.stringify(autoBackupsTime)}`);
238246
};
239247

240248
const checkNextBackup = () => {
@@ -246,24 +254,29 @@ const checkNextBackup = () => {
246254
return 0;
247255
});
248256

257+
logger.debug(
258+
`Next Account : ${autoBackupsTime[0].accountId} : $ ${
259+
autoBackupsTime[0].username
260+
} in ${autoBackupsTime[0].triggerTimer} miliseconds`
261+
);
249262
if (nextBackupTimer) clearTimeout(nextBackupTimer);
250263
nextBackupTimer = setTimeout(() => {
251264
initAutoBackup(autoBackupsTime[0].accountId);
252265
}, autoBackupsTime[0].triggerTimer);
253266
};
254267

255268
const initAutoBackup = async accountId => {
269+
currentAutobackup = accountId;
256270
autoBackupsTime = autoBackupsTime.filter(timer => {
257271
return timer.accountId !== accountId;
258272
});
259-
currentAutobackup = accountId;
260273

261274
const account = myAccount.loggedAccounts.find(acc => acc.id === accountId);
262275
if (!account) {
263276
backupDone();
264277
return;
265278
}
266-
279+
logger.info(`Backup Started For Account: ${account.recipientId}`);
267280
const {
268281
autoBackupEnable,
269282
autoBackupPath,
@@ -278,6 +291,7 @@ const initAutoBackup = async accountId => {
278291
try {
279292
const backupFileName = defineBackupFileName('db');
280293
const backupSize = await doExportBackupUnencrypted({
294+
accountObj: account,
281295
backupPath: `${autoBackupPath}/${backupFileName}`,
282296
progressCallback: data => {
283297
send('backup-progress', data);
@@ -287,27 +301,28 @@ const initAutoBackup = async accountId => {
287301
const today = moment(Date.now());
288302
const nextDate = moment(autoBackupNextDate);
289303
do {
290-
nextDate.add(1, timeUnit);
304+
nextDate.add(1, 'hours');
291305
} while (nextDate.isBefore(today));
292306
await updateAccount({
293307
id: accountId,
294308
autoBackupLastDate: today.format(backupDateFormat),
295309
autoBackupLastSize: backupSize,
296310
autoBackupNextDate: nextDate.format(backupDateFormat)
297311
});
312+
logger.debug(`Backups Finished : ${accountId}`);
298313
const timeDiff = nextDate.diff(today);
299314
autoBackupsTime.push({
300315
username: account.recipientId,
301-
accountId,
316+
id: accountId,
302317
triggerTimer: timeDiff <= 0 ? 1 : timeDiff
303318
});
304319

305320
backupDone();
306321
} catch (backupErr) {
307-
log(
322+
logger.error(
308323
`Failed to do scheduled backup for account ${account.recipientId} : ${
309324
account.name
310-
}`
325+
} => ${backupErr}`
311326
);
312327
backupFail();
313328
}
@@ -316,7 +331,7 @@ const initAutoBackup = async accountId => {
316331
const backupDone = () => {
317332
currentAutobackup = null;
318333
nextBackupTimer = null;
319-
checkNextBackup();
334+
initAutoBackupMonitor();
320335
};
321336

322337
const backupFail = () => {
@@ -340,15 +355,9 @@ ipc.answerRenderer('disable-auto-backup', accountId => {
340355
return timer.accountId !== accountId;
341356
});
342357

343-
if (!currentAutobackup) checkNextBackup();
358+
if (!currentAutobackup) initAutoBackupMonitor();
344359
});
345360

346-
const log = message => {
347-
if (process.env.NODE_ENV === 'development') {
348-
console.log(`[AutoBackup]: ${message}`);
349-
}
350-
};
351-
352361
process.on('exit', () => {
353362
clearTimeout(nextBackupTimer);
354363
currentAutobackup = null;

electron_app/src/windows/composer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const createComposerWindow = () => {
9191
showCopyImageAddress: false,
9292
prepend: (defaultActions, browserWindow) => {
9393
const checker = new spellChecker.Spellchecker();
94+
checker.setSpellcheckerType(spellChecker.ALWAYS_USE_HUNSPELL);
9495

9596
let options = [];
9697
if (defaultActions.misspelledWord) {

email_composer/src/utils/electronInterface.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const sendEventToMailbox = (name, params) => {
3838
webFrame.setSpellCheckProvider(mySettings.language, {
3939
spellCheck(words, callback) {
4040
const checker = new spellChecker.Spellchecker();
41+
checker.setSpellcheckerType(spellChecker.ALWAYS_USE_HUNSPELL);
4142
const misspelled = words.filter(x => {
4243
return checker.isMisspelled(x);
4344
});

email_mailbox/src/components/PanelWrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class PanelWrapper extends Component {
270270
handleEnableAccountBackup = async backupPath => {
271271
const frequency = 'daily';
272272
const timeUnit = 'days';
273-
const { nextDate } = getAutoBackupDates(Date.now(), 1, timeUnit);
273+
const { nextDate } = getAutoBackupDates(Date.now(), 1, 'hours');
274274

275275
await updateAccount({
276276
autoBackupEnable: true,

email_mailbox/src/components/SettingsAccountBackupWrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class SettingsAccountBackupWrapper extends Component {
396396
updateAutoBackupParams = async backupSize => {
397397
const { selectedFrequency, backupPath } = this.state;
398398
const timeUnit = defineUnitToAppend(selectedFrequency);
399-
const { nowDate, nextDate } = getAutoBackupDates(Date.now(), 1, timeUnit);
399+
const { nowDate, nextDate } = getAutoBackupDates(Date.now(), 1, 'hours');
400400
const autoBackupPath = removeFilenameFromPath(backupPath);
401401
await updateAccount({
402402
autoBackupEnable: true,

0 commit comments

Comments
 (0)