Skip to content

Commit 20b6b92

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

File tree

13 files changed

+600
-11
lines changed

13 files changed

+600
-11
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: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,23 @@ const exportCustomDomainsTable = async accountId => {
820820
return formatTableRowsToString(Table.CUSTOM_DOMAIN, customDomainsRows);
821821
};
822822

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

826841
const [recipientId, domain] = accountObj
827842
? accountObj.recipientId.split('@')
@@ -832,31 +847,184 @@ const exportEncryptDatabaseToFile = async ({ outputPath, accountObj }) => {
832847
recipientId: recipientId,
833848
domain: domain || APP_DOMAIN
834849
});
850+
851+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
852+
handleProgressCallback(
853+
exportProgress,
854+
'saving_account',
855+
`${recipientId}@${domain || APP_DOMAIN}`,
856+
progressCallback
857+
);
858+
835859
await saveToFile({ data: fileInformation, filepath, mode: 'w' }, true);
836860

861+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
862+
handleProgressCallback(
863+
exportProgress,
864+
'exporting_contacts',
865+
`${recipientId}@${domain || APP_DOMAIN}`,
866+
progressCallback
867+
);
868+
837869
const contacts = await exportContactTable(accountId);
870+
871+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
872+
handleProgressCallback(
873+
exportProgress,
874+
'saving_contacts',
875+
`${recipientId}@${domain || APP_DOMAIN}`,
876+
progressCallback
877+
);
878+
838879
await saveToFile({ data: contacts, filepath, mode: 'a' });
839880

881+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
882+
handleProgressCallback(
883+
exportProgress,
884+
'exporting_labels',
885+
`${recipientId}@${domain || APP_DOMAIN}`,
886+
progressCallback
887+
);
888+
840889
const labels = await exportLabelTable(accountId);
890+
891+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
892+
handleProgressCallback(
893+
exportProgress,
894+
'saving_labels',
895+
`${recipientId}@${domain || APP_DOMAIN}`,
896+
progressCallback
897+
);
898+
841899
await saveToFile({ data: labels, filepath, mode: 'a' });
842900

901+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
902+
handleProgressCallback(
903+
exportProgress,
904+
'exporting_emails',
905+
`${recipientId}@${domain || APP_DOMAIN}`,
906+
progressCallback
907+
);
908+
843909
const emails = await exportEmailTable(accountId);
910+
911+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
912+
handleProgressCallback(
913+
exportProgress,
914+
'saving_emails',
915+
`${recipientId}@${domain || APP_DOMAIN}`,
916+
progressCallback
917+
);
918+
844919
await saveToFile({ data: emails, filepath, mode: 'a' });
845920

921+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
922+
handleProgressCallback(
923+
exportProgress,
924+
'exporting_email_contacts',
925+
`${recipientId}@${domain || APP_DOMAIN}`,
926+
progressCallback
927+
);
928+
846929
const emailContacts = await exportEmailContactTable(accountId);
930+
931+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
932+
handleProgressCallback(
933+
exportProgress,
934+
'saving_email_contacts',
935+
`${recipientId}@${domain || APP_DOMAIN}`,
936+
progressCallback
937+
);
938+
847939
await saveToFile({ data: emailContacts, filepath, mode: 'a' });
848940

941+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
942+
handleProgressCallback(
943+
exportProgress,
944+
'exporting_email_labels',
945+
`${recipientId}@${domain || APP_DOMAIN}`,
946+
progressCallback
947+
);
948+
849949
const emailLabels = await exportEmailLabelTable(accountId);
950+
951+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
952+
handleProgressCallback(
953+
exportProgress,
954+
'saving_email_labels',
955+
`${recipientId}@${domain || APP_DOMAIN}`,
956+
progressCallback
957+
);
958+
850959
await saveToFile({ data: emailLabels, filepath, mode: 'a' });
851960

961+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
962+
handleProgressCallback(
963+
exportProgress,
964+
'exporting_files',
965+
`${recipientId}@${domain || APP_DOMAIN}`,
966+
progressCallback
967+
);
968+
852969
const files = await exportFileTable(accountId);
970+
971+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
972+
handleProgressCallback(
973+
exportProgress,
974+
'saving_files',
975+
`${recipientId}@${domain || APP_DOMAIN}`,
976+
progressCallback
977+
);
978+
853979
await saveToFile({ data: files, filepath, mode: 'a' });
854980

981+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
982+
handleProgressCallback(
983+
exportProgress,
984+
'exporting_aliases',
985+
`${recipientId}@${domain || APP_DOMAIN}`,
986+
progressCallback
987+
);
988+
855989
const aliases = await exportAliasTable(accountId);
990+
991+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
992+
handleProgressCallback(
993+
exportProgress,
994+
'saving_aliases',
995+
`${recipientId}@${domain || APP_DOMAIN}`,
996+
progressCallback
997+
);
998+
856999
await saveToFile({ data: aliases, filepath, mode: 'a' });
8571000

1001+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
1002+
handleProgressCallback(
1003+
exportProgress,
1004+
'exporting_domains',
1005+
`${recipientId}@${domain || APP_DOMAIN}`,
1006+
progressCallback
1007+
);
1008+
8581009
const customDomains = await exportCustomDomainsTable(accountId);
1010+
1011+
exportProgress += 100 / PROGRESS_TOTAL_STEPS;
1012+
handleProgressCallback(
1013+
exportProgress,
1014+
'saving_domains',
1015+
`${recipientId}@${domain || APP_DOMAIN}`,
1016+
progressCallback
1017+
);
1018+
8591019
await saveToFile({ data: customDomains, filepath, mode: 'a' });
1020+
1021+
exportProgress = 99;
1022+
handleProgressCallback(
1023+
exportProgress,
1024+
'almost_done',
1025+
`${recipientId}@${domain || APP_DOMAIN}`,
1026+
progressCallback
1027+
);
8601028
};
8611029

8621030
const importDatabaseFromFile = async ({

electron_app/src/ipc/backup.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
const globalManager = require('./../globalManager');
1414
const { showNotification } = require('./../notificationManager');
1515
const { sendEventToAllWindows } = require('./../windows/windowUtils');
16+
const { send } = require('./../windows/mailbox');
1617
const {
1718
defineBackupFileName,
1819
defineUnitToAppend,
@@ -37,31 +38,51 @@ ipc.answerRenderer('create-default-backup-folder', () =>
3738
createDefaultBackupFolder()
3839
);
3940

41+
const handleProgressCallback = (progress, message, email, progressCallback) => {
42+
if (!progressCallback) return;
43+
progressCallback({
44+
progress,
45+
message,
46+
email
47+
});
48+
};
49+
4050
const doExportBackupUnencrypted = async params => {
4151
const {
4252
backupPath,
4353
notificationParams,
4454
isAutoBackup = true,
45-
accountObj
55+
accountObj,
56+
progressCallback
4657
} = params;
4758
try {
48-
globalManager.windowsEvents.disable();
59+
const [recipientId, domain] = accountObj
60+
? accountObj.recipientId.split('@')
61+
: myAccount.recipientId.split('@');
62+
63+
handleProgressCallback(
64+
-1,
65+
'starting_backup',
66+
`${recipientId}@${domain}`,
67+
progressCallback
68+
);
69+
4970
commitBackupStatus('local-backup-disable-events', 1);
5071
prepareBackupFiles();
51-
await simulatePause(2000);
52-
globalManager.windowsEvents.enable();
5372
commitBackupStatus('local-backup-enable-events', 2);
73+
5474
const backupSize = await exportBackupUnencrypted({
5575
backupPath,
56-
accountObj
76+
accountObj,
77+
progressCallback
5778
});
79+
5880
commitBackupStatus('local-backup-export-finished', 3, {
5981
backupSize,
6082
isAutoBackup
6183
});
62-
await simulatePause(2000);
84+
6385
commitBackupStatus('local-backup-success', null);
64-
await simulatePause(2000);
6586
if (notificationParams) {
6687
showNotification({
6788
title: notificationParams.success.title,
@@ -74,8 +95,10 @@ const doExportBackupUnencrypted = async params => {
7495
}
7596
return backupSize;
7697
} catch (error) {
98+
console.error(error);
7799
globalManager.windowsEvents.enable();
78100
commitBackupStatus('local-backup-enable-events', null, { error });
101+
commitBackupStatus('local-backup-failed', null, null);
79102
if (notificationParams) {
80103
showNotification({
81104
title: notificationParams.error.title,
@@ -203,7 +226,10 @@ const startBackupMonitor = account => {
203226
try {
204227
const backupFileName = defineBackupFileName('db');
205228
const backupSize = await doExportBackupUnencrypted({
206-
backupPath: `${autoBackupPath}/${backupFileName}`
229+
backupPath: `${autoBackupPath}/${backupFileName}`,
230+
progressCallback: data => {
231+
send('backup-progress', data);
232+
}
207233
});
208234
const timeUnit = defineUnitToAppend(autoBackupFrequency);
209235
const today = moment(Date.now());

email_mailbox/src/components/Panel.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import UpdatePopup from './UpdatePopup';
1616
import { MAILBOX_POPUP_TYPES } from './PanelWrapper';
1717
import { mySettings } from '../utils/electronInterface';
1818
import UserGuide from './UserGuide';
19+
import Snackbar from './Snackbar';
1920
import './panel.scss';
2021

2122
const Panel = props => (
@@ -56,6 +57,13 @@ const Panel = props => (
5657
...props
5758
})}
5859
<UserGuide />
60+
{props.backupSnackbar &&
61+
!props.backupSnackbar.hide && (
62+
<Snackbar
63+
{...props.backupSnackbar}
64+
onDismissSnackbar={props.onDismissSnackbar}
65+
/>
66+
)}
5967
</div>
6068
);
6169

@@ -178,6 +186,7 @@ renderMailboxPopup.propTypes = {
178186
};
179187

180188
Panel.propTypes = {
189+
backupSnackbar: PropTypes.object,
181190
isHiddenMailboxPopup: PropTypes.bool,
182191
isOpenActivityPanel: PropTypes.bool,
183192
isOpenSideBar: PropTypes.bool,
@@ -187,6 +196,7 @@ Panel.propTypes = {
187196
onClickCloseWelcome: PropTypes.func,
188197
onClickThreadBack: PropTypes.func,
189198
onClickSection: PropTypes.func,
199+
onDismissSnackbar: PropTypes.func,
190200
onToggleActivityPanel: PropTypes.func,
191201
onToggleSideBar: PropTypes.func,
192202
onUpdateApp: PropTypes.func,

0 commit comments

Comments
 (0)