Skip to content

Commit

Permalink
new window
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanfbrito committed Dec 15, 2023
1 parent 4d5eb17 commit 1160438
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/documentViewer/ipc.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
};
5 changes: 5 additions & 0 deletions src/ipc/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type ChannelToArgsMap = {
'outlook-calendar/has-credentials': () => Promise<boolean>;
'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;
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -98,6 +99,7 @@ const start = async (): Promise<void> => {
handleJitsiDesktopCapturerGetSources();
handleDesktopCapturerGetSources();
startOutlookCalendarUrlHandler();
startDocumentViewerHandler();
checkSupportedVersionServers();

await processDeepLinksInArgs();
Expand Down
3 changes: 3 additions & 0 deletions src/servers/preload/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -72,6 +73,7 @@ export type RocketChatDesktopAPI = {
hasOutlookCredentials: () => Promise<boolean>;
clearOutlookCredentials: () => void;
setUserToken: (token: string, userId: string) => void;
openDocumentViewer: (url: string, format: string, options: any) => void;
};

export const RocketChatDesktop: RocketChatDesktopAPI = {
Expand Down Expand Up @@ -105,4 +107,5 @@ export const RocketChatDesktop: RocketChatDesktopAPI = {
clearOutlookCredentials,
setUserToken,
setSidebarCustomTheme,
openDocumentViewer,
};
10 changes: 10 additions & 0 deletions src/servers/preload/documentViewer.ts
Original file line number Diff line number Diff line change
@@ -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);
};
1 change: 0 additions & 1 deletion src/ui/main/serverView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ export const attachGuestWebContentsEvents = async (): Promise<void> => {
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, {
Expand Down

0 comments on commit 1160438

Please sign in to comment.