Skip to content

Commit e86a5f5

Browse files
author
Pedro Aim
committed
showing background progress of backup
1 parent 708585c commit e86a5f5

File tree

13 files changed

+660
-97
lines changed

13 files changed

+660
-97
lines changed

electron_app/src/BackupManager.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ const getFileSizeInBytes = filename => {
142142

143143
/* Export Backup
144144
----------------------------- */
145-
const exportBackupUnencrypted = async ({ backupPath, accountObj }) => {
145+
const exportBackupUnencrypted = async ({
146+
backupPath,
147+
accountObj,
148+
progressCallback
149+
}) => {
146150
try {
147151
try {
148152
await exportEncryptDatabaseToFile({
149153
outputPath: ExportUnencryptedFilename,
150-
accountObj
154+
accountObj,
155+
progressCallback
151156
});
152157
} catch (dbErr) {
153158
throw new Error('Failed to export database');

electron_app/src/database/DBEexporter.js

Lines changed: 115 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -614,38 +614,40 @@ const exportEmailTable = async accountId => {
614614
}
615615
)
616616
.then(async rows => {
617-
return await Promise.all(
618-
rows.map(async row => {
619-
let newRow = row.toJSON();
620-
if (!newRow.unsentDate) delete newRow.unsentDate;
621-
if (!newRow.trashDate) delete newRow.trashDate;
622-
if (newRow.replyTo === null) newRow = { ...newRow, replyTo: '' };
623-
if (!newRow.boundary) delete newRow.boundary;
624-
625-
const body =
626-
(await getEmailBody({
627-
username,
628-
metadataKey: newRow.key,
629-
password: globalManager.databaseKey.get()
630-
})) ||
631-
newRow.content ||
632-
'';
633-
const headers = await getEmailHeaders({
617+
const emailRows = [];
618+
619+
for (const emailRow of rows) {
620+
let newRow = emailRow.toJSON();
621+
if (!newRow.unsentDate) delete newRow.unsentDate;
622+
if (!newRow.trashDate) delete newRow.trashDate;
623+
if (newRow.replyTo === null) newRow = { ...newRow, replyTo: '' };
624+
if (!newRow.boundary) delete newRow.boundary;
625+
626+
const body =
627+
(await getEmailBody({
634628
username,
635629
metadataKey: newRow.key,
636630
password: globalManager.databaseKey.get()
637-
});
638-
639-
const key = parseInt(newRow.key);
640-
return {
641-
...newRow,
642-
content: body,
643-
key,
644-
date: parseOutgoingDate(newRow.date),
645-
headers: headers || undefined
646-
};
647-
})
648-
);
631+
})) ||
632+
newRow.content ||
633+
'';
634+
const headers = await getEmailHeaders({
635+
username,
636+
metadataKey: newRow.key,
637+
password: globalManager.databaseKey.get()
638+
});
639+
640+
const key = parseInt(newRow.key);
641+
emailRows.push({
642+
...newRow,
643+
content: body,
644+
key,
645+
date: parseOutgoingDate(newRow.date),
646+
headers: headers || undefined
647+
});
648+
}
649+
650+
return emailRows;
649651
});
650652
emailRows = [...emailRows, ...result];
651653
if (result.length < SELECT_ALL_BATCH) {
@@ -820,8 +822,23 @@ const exportCustomDomainsTable = async accountId => {
820822
return formatTableRowsToString(Table.CUSTOM_DOMAIN, customDomainsRows);
821823
};
822824

823-
const exportEncryptDatabaseToFile = async ({ outputPath, accountObj }) => {
825+
const handleProgressCallback = (progress, message, email, progressCallback) => {
826+
if (!progressCallback) return;
827+
progressCallback({
828+
progress: parseInt(progress),
829+
message,
830+
email
831+
});
832+
};
833+
834+
const exportEncryptDatabaseToFile = async ({
835+
outputPath,
836+
accountObj,
837+
progressCallback
838+
}) => {
824839
const filepath = outputPath;
840+
const PROGRESS_TOTAL_STEPS = 19;
841+
let exportProgress = 0;
825842

826843
const [recipientId, domain] = accountObj
827844
? accountObj.recipientId.split('@')
@@ -832,31 +849,81 @@ const exportEncryptDatabaseToFile = async ({ outputPath, accountObj }) => {
832849
recipientId: recipientId,
833850
domain: domain || APP_DOMAIN
834851
});
835-
await saveToFile({ data: fileInformation, filepath, mode: 'w' }, true);
836852

837-
const contacts = await exportContactTable(accountId);
838-
await saveToFile({ data: contacts, filepath, mode: 'a' });
839-
840-
const labels = await exportLabelTable(accountId);
841-
await saveToFile({ data: labels, filepath, mode: 'a' });
853+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
854+
handleProgressCallback(
855+
exportProgress,
856+
'saving_account',
857+
`${recipientId}@${domain || APP_DOMAIN}`,
858+
progressCallback
859+
);
842860

843-
const emails = await exportEmailTable(accountId);
844-
await saveToFile({ data: emails, filepath, mode: 'a' });
861+
await saveToFile({ data: fileInformation, filepath, mode: 'w' }, true);
845862

846-
const emailContacts = await exportEmailContactTable(accountId);
847-
await saveToFile({ data: emailContacts, filepath, mode: 'a' });
863+
const exportTables = [
864+
{
865+
export: exportContactTable,
866+
suffix: 'contacts'
867+
},
868+
{
869+
export: exportLabelTable,
870+
suffix: 'labels'
871+
},
872+
{
873+
export: exportEmailTable,
874+
suffix: 'emails'
875+
},
876+
{
877+
export: exportEmailContactTable,
878+
suffix: 'email_contacts'
879+
},
880+
{
881+
export: exportEmailLabelTable,
882+
suffix: 'email_labels'
883+
},
884+
{
885+
export: exportFileTable,
886+
suffix: 'files'
887+
},
888+
{
889+
export: exportAliasTable,
890+
suffix: 'aliases'
891+
},
892+
{
893+
export: exportCustomDomainsTable,
894+
suffix: 'domains'
895+
}
896+
];
897+
898+
for (const exportTable of exportTables) {
899+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
900+
handleProgressCallback(
901+
exportProgress,
902+
`exporting_${exportTable.suffix}`,
903+
`${recipientId}@${domain || APP_DOMAIN}`,
904+
progressCallback
905+
);
848906

849-
const emailLabels = await exportEmailLabelTable(accountId);
850-
await saveToFile({ data: emailLabels, filepath, mode: 'a' });
907+
const result = await exportTable.export(accountId);
851908

852-
const files = await exportFileTable(accountId);
853-
await saveToFile({ data: files, filepath, mode: 'a' });
909+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
910+
handleProgressCallback(
911+
exportProgress,
912+
`saving_${exportTable.suffix}`,
913+
`${recipientId}@${domain || APP_DOMAIN}`,
914+
progressCallback
915+
);
854916

855-
const aliases = await exportAliasTable(accountId);
856-
await saveToFile({ data: aliases, filepath, mode: 'a' });
917+
await saveToFile({ data: result, filepath, mode: 'a' });
918+
}
857919

858-
const customDomains = await exportCustomDomainsTable(accountId);
859-
await saveToFile({ data: customDomains, filepath, mode: 'a' });
920+
exportProgress = 99;
921+
handleProgressCallback(
922+
exportProgress,
923+
'almost_done',
924+
`${recipientId}@${domain || APP_DOMAIN}`,
925+
progressCallback
926+
);
860927
};
861928

862929
const importDatabaseFromFile = async ({

0 commit comments

Comments
 (0)