Initialize IPC channels early

This commit is contained in:
Fedor Indutny 2021-06-01 11:06:38 -07:00 committed by GitHub
parent 8841de17a5
commit 0e19c17160
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View file

@ -19,7 +19,7 @@ const ERASE_TEMP_KEY = 'erase-temp';
const ERASE_DRAFTS_KEY = 'erase-drafts'; const ERASE_DRAFTS_KEY = 'erase-drafts';
const CLEANUP_ORPHANED_ATTACHMENTS_KEY = 'cleanup-orphaned-attachments'; const CLEANUP_ORPHANED_ATTACHMENTS_KEY = 'cleanup-orphaned-attachments';
async function initialize({ configDir, cleanupOrphanedAttachments }) { function initialize({ configDir, cleanupOrphanedAttachments }) {
if (initialized) { if (initialized) {
throw new Error('initialze: Already initialized!'); throw new Error('initialze: Already initialized!');
} }

31
main.js
View file

@ -1247,6 +1247,23 @@ app.on('ready', async () => {
loadingWindow.loadURL(prepareFileUrl([__dirname, 'loading.html'])); loadingWindow.loadURL(prepareFileUrl([__dirname, 'loading.html']));
}); });
try {
await attachments.clearTempPath(userDataPath);
} catch (err) {
logger.error(
'main/ready: Error deleting temp dir:',
err && err.stack ? err.stack : err
);
}
// Initialize IPC channels before creating the window
attachmentChannel.initialize({
configDir: userDataPath,
cleanupOrphanedAttachments,
});
sqlChannels.initialize(sql);
// Run window preloading in parallel with database initialization. // Run window preloading in parallel with database initialization.
await createWindow(); await createWindow();
@ -1282,7 +1299,6 @@ app.on('ready', async () => {
// eslint-disable-next-line more/no-then // eslint-disable-next-line more/no-then
appStartInitialSpellcheckSetting = await getSpellCheckSetting(); appStartInitialSpellcheckSetting = await getSpellCheckSetting();
await sqlChannels.initialize(sql);
try { try {
const IDB_KEY = 'indexeddb-delete-needed'; const IDB_KEY = 'indexeddb-delete-needed';
@ -1330,19 +1346,6 @@ app.on('ready', async () => {
}); });
} }
try {
await attachments.clearTempPath(userDataPath);
} catch (err) {
logger.error(
'main/ready: Error deleting temp dir:',
err && err.stack ? err.stack : err
);
}
await attachmentChannel.initialize({
configDir: userDataPath,
cleanupOrphanedAttachments,
});
ready = true; ready = true;
if (usingTrayIcon) { if (usingTrayIcon) {