Skip to content

Commit

Permalink
Initialize IPC channels early
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Jun 1, 2021
1 parent 8841de1 commit 0e19c17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/attachment_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
Expand Down
31 changes: 17 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0e19c17

Please sign in to comment.