Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 81 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { app } from 'electron';
import electronDl from 'electron-dl';
import { app, shell } from 'electron';

import { performElectronStartup, setupApp } from './app/main/app';
import {
performElectronStartup,
setupApp,
initializeScreenCaptureFallbackState,
setupGpuCrashHandler,
markMainWindowStable,
} from './app/main/app';
import {
mergePersistableValues,
watchAndPersistChanges,
Expand All @@ -10,12 +15,26 @@ import { setUserDataDirectory } from './app/main/dev';
import { setupDeepLinks, processDeepLinksInArgs } from './deepLinks/main';
import { startDocumentViewerHandler } from './documentViewer/ipc';
import { setupDownloads } from './downloads/main';
import { setupElectronDlWithTracking } from './downloads/main/setup';
import { setupMainErrorHandling } from './errors';
import i18n from './i18n/main';
import { handle } from './ipc/main';
import { handleJitsiDesktopCapturerGetSources } from './jitsi/ipc';
import { startLogViewerWindowHandler } from './logViewerWindow/ipc';
import {
logger,
setupWebContentsLogging,
cleanupOldLogs,
setupDebugLoggingWatch,
} from './logging';
import { setupNavigation } from './navigation/main';
import attentionDrawing from './notifications/attentionDrawing';
import { setupNotifications } from './notifications/main';
import { startOutlookCalendarUrlHandler } from './outlookCalendar/ipc';
import {
startOutlookCalendarUrlHandler,
stopOutlookCalendarSync,
} from './outlookCalendar/ipc';
import { setupOutlookLogger } from './outlookCalendar/logger';
import { setupScreenSharing } from './screenSharing/main';
import { handleClearCacheDialog } from './servers/cache';
import { setupServers } from './servers/main';
Expand All @@ -36,22 +55,40 @@ import touchBar from './ui/main/touchBar';
import trayIcon from './ui/main/trayIcon';
import { setupUpdates } from './updates/main';
import { setupPowerMonitor } from './userPresence/main';
import { openExternal } from './utils/browserLauncher';
import {
handleDesktopCapturerGetSources,
startVideoCallWindowHandler,
cleanupVideoCallResources,
} from './videoCallWindow/ipc';

electronDl({ saveAs: true });

const start = async (): Promise<void> => {
setUserDataDirectory();

logger.info('Starting Rocket.Chat Desktop application');

setupWebContentsLogging();

performElectronStartup();

// Set up GPU crash handler BEFORE whenReady to catch early GPU failures
setupGpuCrashHandler();

await app.whenReady();

cleanupOldLogs();

createMainReduxStore();

setupOutlookLogger();
setupDebugLoggingWatch();

// Initialize screen capture fallback state after store is available
initializeScreenCaptureFallbackState();

// Set up electron-dl with our download tracking callbacks
setupElectronDlWithTracking();

const localStorage = await exportLocalStorage();
await mergePersistableValues(localStorage);
await setupServers(localStorage);
Expand All @@ -68,14 +105,14 @@ const start = async (): Promise<void> => {
attachGuestWebContentsEvents();
await showRootWindow();

// React DevTools is currently incompatible with Electron 10
// if (process.env.NODE_ENV === 'development') {
// installDevTools();
// }
// Mark main window as stable - GPU crashes after this won't trigger fallback
markMainWindowStable();
watchMachineTheme();
setupNotifications();
attentionDrawing.setUp();
setupScreenSharing();
startVideoCallWindowHandler();
startLogViewerWindowHandler();

await setupSpellChecking();

Expand All @@ -96,6 +133,9 @@ const start = async (): Promise<void> => {
menuBar.tearDown();
touchBar.tearDown();
trayIcon.tearDown();
attentionDrawing.tearDown();
stopOutlookCalendarSync();
cleanupVideoCallResources();
});

watchAndPersistChanges();
Expand All @@ -105,7 +145,37 @@ const start = async (): Promise<void> => {
startDocumentViewerHandler();
checkSupportedVersionServers();

handle('open-external', async (_webContents, rawUrl) => {
let url: URL;

try {
url = new URL(rawUrl);
} catch {
console.warn('Blocked malformed external URL');
return;
}

const { isProtocolAllowed } = await import('./navigation/main');

if (!(await isProtocolAllowed(url.toString()))) {
console.warn('Blocked external URL with disallowed protocol');
return;
}

if (url.protocol === 'http:' || url.protocol === 'https:') {
await openExternal(url.toString());
return;
}

await shell.openExternal(url.toString());
});

await processDeepLinksInArgs();

console.info('Application initialization completed successfully');
};

start();
start().catch((error) => {
logger.error('Failed to start application', error);
app.exit(1);
});
Loading