mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-10-31 03:53:34 +00:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			v5.9.3
			...
			pdf-viewer
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 018b977880 | ||
|  | 99c227a5f0 | 
| @@ -196,6 +196,29 @@ app.on('ready', () => { | ||||
| 		app.quit(); | ||||
| 	}); | ||||
|  | ||||
| 	// Show pdf in a new BrowserWindow | ||||
| 	ipcMain.on('pdf-view', (event, url) => { | ||||
| 		// Paddings for pdfWindow so that it fits into the main browserWindow | ||||
| 		const paddingWidth = 55; | ||||
| 		const paddingHeight = 22; | ||||
|  | ||||
| 		// Get the config of main browserWindow | ||||
| 		const mainWindowState = global.mainWindowState; | ||||
|  | ||||
| 		// Window to view the pdf file | ||||
| 		const pdfWindow = new electron.BrowserWindow({ | ||||
| 			x: mainWindowState.x + paddingWidth, | ||||
| 			y: mainWindowState.y + paddingHeight, | ||||
| 			width: mainWindowState.width - paddingWidth, | ||||
| 			height: mainWindowState.height - paddingHeight, | ||||
| 			webPreferences: { | ||||
| 				plugins: true, | ||||
| 				partition: 'persist:webviewsession' | ||||
| 			} | ||||
| 		}); | ||||
| 		pdfWindow.loadURL(url); | ||||
| 	}); | ||||
|  | ||||
| 	// Reload full app not just webview, useful in debugging | ||||
| 	ipcMain.on('reload-full-app', () => { | ||||
| 		mainWindow.reload(); | ||||
| @@ -249,7 +272,7 @@ app.on('ready', () => { | ||||
| 			item.setSavePath(filePath); | ||||
| 			item.on('updated', (event, state) => { | ||||
| 				switch (state) { | ||||
| 					case 'interrupted' : { | ||||
| 					case 'interrupted': { | ||||
| 						// Can interrupted to due to network error, cancel download then | ||||
| 						console.log('Download interrupted, cancelling and fallback to dialog download.'); | ||||
| 						item.cancel(); | ||||
|   | ||||
| @@ -21,11 +21,19 @@ function handleExternalLink(event) { | ||||
| 	if (isWhiteListURL) { | ||||
| 		event.preventDefault(); | ||||
|  | ||||
| 		// download txt, pdf, mp3, mp4 etc.. by using downloadURL in the | ||||
| 		// Show pdf attachments in a new window | ||||
|  | ||||
| 		if (LinkUtil.isPDF(url) && isUploadsURL) { | ||||
| 			ipcRenderer.send('pdf-view', url); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		// download txt, mp3, mp4 etc.. by using downloadURL in the | ||||
| 		// main process which allows the user to save the files to their desktop | ||||
| 		// and not trigger webview reload while image in webview will | ||||
| 		// do nothing and will not save it | ||||
| 		if (!LinkUtil.isImage(url) && isUploadsURL) { | ||||
|  | ||||
| 		if (!LinkUtil.isImage(url) && !LinkUtil.isPDF(url) && isUploadsURL) { | ||||
| 			ipcRenderer.send('downloadFile', url, downloadPath); | ||||
| 			ipcRenderer.once('downloadFileCompleted', (event, filePath, fileName) => { | ||||
| 				const downloadNotification = new Notification('Download Complete', { | ||||
|   | ||||
| @@ -34,6 +34,12 @@ class LinkUtil { | ||||
| 		const isImageUrl = /\.(bmp|gif|jpg|jpeg|png|webp)\?*.*$/i; | ||||
| 		return isImageUrl.test(url); | ||||
| 	} | ||||
|  | ||||
| 	isPDF(url) { | ||||
| 		// test for pdf extension | ||||
| 		const isPDFUrl = /\.(pdf)\?*.*$/i; | ||||
| 		return isPDFUrl.test(url); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| module.exports = new LinkUtil(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user