Skip to content

Commit 7840715

Browse files
authored
Merge pull request #1474 from Hirobreak/backup-log
Backup Fix and Log
2 parents 12c1fdb + 40182a3 commit 7840715

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-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/database/DBEmodel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const Model = Sequelize.Model;
1010
const Op = Sequelize.Op;
1111
const { parseDate, formatDate } = require('./../utils/TimeUtils');
1212
const { DEFAULT_PIN } = require('./../utils/const');
13+
const logger = require('../logger');
1314

1415
let sequelize;
1516

@@ -609,7 +610,7 @@ const initDatabaseEncrypted = async (
609610
}
610611
);
611612
} catch (ex) {
612-
console.error(ex);
613+
logger.error(ex);
613614
}
614615
};
615616

electron_app/src/ipc/backup.js

Lines changed: 24 additions & 14 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,11 @@ 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+
APP_DOMAIN}`
75+
);
76+
7177
handleProgressCallback(
7278
-1,
7379
'starting_backup',
@@ -133,6 +139,7 @@ ipc.answerRenderer('export-backup-encrypted', async params => {
133139
await simulatePause(2000);
134140
globalManager.windowsEvents.enable();
135141
commitBackupStatus('local-backup-enable-events', 2);
142+
logger.info(`Encrypted Backup Started for Path: ${backupPath}`);
136143
const backupSize = await exportBackupEncrypted({
137144
backupPath,
138145
password
@@ -222,7 +229,7 @@ const initAutoBackupMonitor = () => {
222229
!autoBackupNextDate ||
223230
account.id === currentAutobackup
224231
)
225-
return;
232+
continue;
226233

227234
const now = moment();
228235
const pendingDate = moment(autoBackupNextDate);
@@ -235,6 +242,8 @@ const initAutoBackupMonitor = () => {
235242
}
236243

237244
if (!currentAutobackup) checkNextBackup();
245+
246+
logger.debug(`Backups : ${JSON.stringify(autoBackupsTime)}`);
238247
};
239248

240249
const checkNextBackup = () => {
@@ -246,24 +255,29 @@ const checkNextBackup = () => {
246255
return 0;
247256
});
248257

258+
logger.debug(
259+
`Next Backup : ${autoBackupsTime[0].accountId} : $ ${
260+
autoBackupsTime[0].username
261+
} in ${autoBackupsTime[0].triggerTimer} miliseconds`
262+
);
249263
if (nextBackupTimer) clearTimeout(nextBackupTimer);
250264
nextBackupTimer = setTimeout(() => {
251265
initAutoBackup(autoBackupsTime[0].accountId);
252266
}, autoBackupsTime[0].triggerTimer);
253267
};
254268

255269
const initAutoBackup = async accountId => {
270+
currentAutobackup = accountId;
256271
autoBackupsTime = autoBackupsTime.filter(timer => {
257272
return timer.accountId !== accountId;
258273
});
259-
currentAutobackup = accountId;
260274

261275
const account = myAccount.loggedAccounts.find(acc => acc.id === accountId);
262276
if (!account) {
263277
backupDone();
264278
return;
265279
}
266-
280+
logger.info(`Backup Started For Account: ${account.recipientId}`);
267281
const {
268282
autoBackupEnable,
269283
autoBackupPath,
@@ -278,6 +292,7 @@ const initAutoBackup = async accountId => {
278292
try {
279293
const backupFileName = defineBackupFileName('db');
280294
const backupSize = await doExportBackupUnencrypted({
295+
accountObj: account,
281296
backupPath: `${autoBackupPath}/${backupFileName}`,
282297
progressCallback: data => {
283298
send('backup-progress', data);
@@ -295,19 +310,20 @@ const initAutoBackup = async accountId => {
295310
autoBackupLastSize: backupSize,
296311
autoBackupNextDate: nextDate.format(backupDateFormat)
297312
});
313+
logger.debug(`Backup Finished : ${accountId}`);
298314
const timeDiff = nextDate.diff(today);
299315
autoBackupsTime.push({
300316
username: account.recipientId,
301-
accountId,
317+
id: accountId,
302318
triggerTimer: timeDiff <= 0 ? 1 : timeDiff
303319
});
304320

305321
backupDone();
306322
} catch (backupErr) {
307-
log(
323+
logger.error(
308324
`Failed to do scheduled backup for account ${account.recipientId} : ${
309325
account.name
310-
}`
326+
} => ${backupErr}`
311327
);
312328
backupFail();
313329
}
@@ -316,7 +332,7 @@ const initAutoBackup = async accountId => {
316332
const backupDone = () => {
317333
currentAutobackup = null;
318334
nextBackupTimer = null;
319-
checkNextBackup();
335+
initAutoBackupMonitor();
320336
};
321337

322338
const backupFail = () => {
@@ -340,15 +356,9 @@ ipc.answerRenderer('disable-auto-backup', accountId => {
340356
return timer.accountId !== accountId;
341357
});
342358

343-
if (!currentAutobackup) checkNextBackup();
359+
if (!currentAutobackup) initAutoBackupMonitor();
344360
});
345361

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

email_mailbox/src/components/popuphoc.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
}
66

77
.popup-container{
8-
box-shadow: 0 1px 16px 0 rgba(143, 143, 143, 0.56);
98
border: solid 1px transparent;
109
border-radius: 15px;
1110
position: absolute;

email_mailbox/src/components/threads.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
.threads-content{
5656
overflow-y: auto;
57-
height: calc(100% - 125px);
57+
height: calc(100% - 124px);
5858
padding: 44px 20px 20px 20px;
5959
position: relative;
6060
width: calc(100% - 40px);

0 commit comments

Comments
 (0)