diff --git a/src/documentViewer/ipc.ts b/src/documentViewer/ipc.ts new file mode 100644 index 000000000..ace010e62 --- /dev/null +++ b/src/documentViewer/ipc.ts @@ -0,0 +1,25 @@ +import { BrowserWindow } from 'electron'; + +import { handle } from '../ipc/main'; + +export const startDocumentViewerHandler = (): void => { + handle('document-viewer/open-window', async (event, url, format, options) => { + const validUrl = new URL(url); + const allowedProtocols = ['http:', 'https:']; + if (!allowedProtocols.includes(validUrl.protocol)) { + return; + } + const documentViewerWindow = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + session: event.session, + plugins: true, + }, + }); + documentViewerWindow.loadURL(url); + documentViewerWindow.on('ready-to-show', () => { + documentViewerWindow.show(); + }); + }); +}; diff --git a/src/ipc/channels.ts b/src/ipc/channels.ts index 0c978177e..13a4017be 100644 --- a/src/ipc/channels.ts +++ b/src/ipc/channels.ts @@ -41,6 +41,11 @@ type ChannelToArgsMap = { 'outlook-calendar/has-credentials': () => Promise; 'outlook-calendar/clear-credentials': () => void; 'outlook-calendar/set-user-token': (token: string, userId: string) => void; + 'document-viewer/open-window': ( + url: string, + format: string, + options: any + ) => void; }; export type Channel = keyof ChannelToArgsMap; diff --git a/src/main.ts b/src/main.ts index 1c73801e5..8bb26c6d0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,7 @@ import { } from './app/main/data'; import { setUserDataDirectory } from './app/main/dev'; import { setupDeepLinks, processDeepLinksInArgs } from './deepLinks/main'; +import { startDocumentViewerHandler } from './documentViewer/ipc'; import { setupDownloads } from './downloads/main'; import { setupMainErrorHandling } from './errors'; import i18n from './i18n/main'; @@ -98,6 +99,7 @@ const start = async (): Promise => { handleJitsiDesktopCapturerGetSources(); handleDesktopCapturerGetSources(); startOutlookCalendarUrlHandler(); + startDocumentViewerHandler(); checkSupportedVersionServers(); await processDeepLinksInArgs(); diff --git a/src/servers/preload/api.ts b/src/servers/preload/api.ts index cabf221dc..40c6ee33d 100644 --- a/src/servers/preload/api.ts +++ b/src/servers/preload/api.ts @@ -14,6 +14,7 @@ import { setUserPresenceDetection } from '../../userPresence/preload'; import type { Server } from '../common'; import { setBadge } from './badge'; import { writeTextToClipboard } from './clipboard'; +import { openDocumentViewer } from './documentViewer'; import { setFavicon } from './favicon'; import { setGitCommitHash } from './gitCommitHash'; import type { videoCallWindowOptions } from './internalVideoChatWindow'; @@ -72,6 +73,7 @@ export type RocketChatDesktopAPI = { hasOutlookCredentials: () => Promise; clearOutlookCredentials: () => void; setUserToken: (token: string, userId: string) => void; + openDocumentViewer: (url: string, format: string, options: any) => void; }; export const RocketChatDesktop: RocketChatDesktopAPI = { @@ -105,4 +107,5 @@ export const RocketChatDesktop: RocketChatDesktopAPI = { clearOutlookCredentials, setUserToken, setSidebarCustomTheme, + openDocumentViewer, }; diff --git a/src/servers/preload/documentViewer.ts b/src/servers/preload/documentViewer.ts new file mode 100644 index 000000000..37dc20cc0 --- /dev/null +++ b/src/servers/preload/documentViewer.ts @@ -0,0 +1,10 @@ +import { ipcRenderer } from 'electron'; + +export const openDocumentViewer = ( + url: string, + format: string, + options: any +): void => { + console.log('document-viewer/open-window', url, format, options); + ipcRenderer.invoke('document-viewer/open-window', url, format, options); +}; diff --git a/src/ui/main/serverView/index.ts b/src/ui/main/serverView/index.ts index 1c9cbc7f3..868f38d84 100644 --- a/src/ui/main/serverView/index.ts +++ b/src/ui/main/serverView/index.ts @@ -325,7 +325,6 @@ export const attachGuestWebContentsEvents = async (): Promise => { guestWebContents.session.on( 'will-download', (event, item, _webContents) => { - console.log('will-download', item); const fileName = item.getFilename(); const extension = path.extname(fileName)?.slice(1).toLowerCase(); const savePath = dialog.showSaveDialogSync(rootWindow, {