-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
open PDF viewer above the chat webview
- Loading branch information
1 parent
1160438
commit 7964add
Showing
8 changed files
with
137 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import { BrowserWindow } from 'electron'; | ||
|
||
import { handle } from '../ipc/main'; | ||
import { SERVER_DOCUMENT_VIEWER_OPEN_URL } from '../servers/actions'; | ||
import { dispatch, select } from '../store'; | ||
|
||
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; | ||
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 server = select(({ servers }) => | ||
servers.find( | ||
(s) => new URL(s.url).origin === new URL(event.getURL()).origin | ||
) | ||
); | ||
if (!server) { | ||
return; | ||
} | ||
|
||
dispatch({ | ||
type: SERVER_DOCUMENT_VIEWER_OPEN_URL, | ||
payload: { server: server.url, documentUrl: url }, | ||
}); | ||
} | ||
const documentViewerWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
session: event.session, | ||
plugins: true, | ||
}, | ||
}); | ||
documentViewerWindow.loadURL(url); | ||
documentViewerWindow.on('ready-to-show', () => { | ||
documentViewerWindow.show(); | ||
}); | ||
}); | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Box, IconButton } from '@rocket.chat/fuselage'; | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
const DynamicWebview = ({ | ||
url, | ||
isActive, | ||
partition, | ||
closeDocumentViewer, | ||
}: { | ||
url: string; | ||
isActive: boolean; | ||
partition: string; | ||
closeDocumentViewer: () => void; | ||
}) => { | ||
const [webView, setWebView] = useState<JSX.Element | null>(null); | ||
|
||
useEffect(() => { | ||
if (isActive && url) { | ||
setWebView( | ||
<webview | ||
src={url} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
position: 'absolute', | ||
left: 0, | ||
top: 64, | ||
right: 0, | ||
bottom: 0, | ||
}} | ||
partition={partition} | ||
/> | ||
); | ||
} else { | ||
setWebView(null); | ||
} | ||
}, [url, isActive, partition]); | ||
|
||
return ( | ||
<> | ||
{isActive && ( | ||
<Box | ||
bg='light' | ||
width='100%' | ||
height='100%' | ||
position='absolute' | ||
content='center' | ||
alignItems='center' | ||
> | ||
<Box padding={5} display='flex'> | ||
<IconButton icon='arrow-back' onClick={closeDocumentViewer} /> | ||
<h2>PDF Viewer</h2> | ||
</Box> | ||
|
||
<div>{webView}</div> | ||
</Box> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default DynamicWebview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters