From 0e19c1716095c1e2f4315e4535281878e0f04f99 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 1 Jun 2021 11:06:38 -0700 Subject: [PATCH] Initialize IPC channels early --- app/attachment_channel.js | 2 +- main.js | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/attachment_channel.js b/app/attachment_channel.js index 8d25de162..fbb101054 100644 --- a/app/attachment_channel.js +++ b/app/attachment_channel.js @@ -19,7 +19,7 @@ const ERASE_TEMP_KEY = 'erase-temp'; const ERASE_DRAFTS_KEY = 'erase-drafts'; const CLEANUP_ORPHANED_ATTACHMENTS_KEY = 'cleanup-orphaned-attachments'; -async function initialize({ configDir, cleanupOrphanedAttachments }) { +function initialize({ configDir, cleanupOrphanedAttachments }) { if (initialized) { throw new Error('initialze: Already initialized!'); } diff --git a/main.js b/main.js index 5b76a3315..398877a1d 100644 --- a/main.js +++ b/main.js @@ -1247,6 +1247,23 @@ app.on('ready', async () => { 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. await createWindow(); @@ -1282,7 +1299,6 @@ app.on('ready', async () => { // eslint-disable-next-line more/no-then appStartInitialSpellcheckSetting = await getSpellCheckSetting(); - await sqlChannels.initialize(sql); try { 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; if (usingTrayIcon) {