Parcourir la source

10.6.9 release

Gaudenz Alder il y a 6 ans
Parent
commit
fade0e335d

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+25-MAY-2019: 10.6.9
+
+- Fixes missing VSDX import in stealth mode
+
 22-MAY-2019: 10.6.8
 
 - Add VMware stencils

+ 1 - 1
VERSION

@@ -1 +1 @@
-10.6.8
+10.6.9

+ 1 - 1
src/main/webapp/cache.manifest

@@ -1,7 +1,7 @@
 CACHE MANIFEST
 
 # THIS FILE WAS GENERATED. DO NOT MODIFY!
-# 05/23/2019 11:51 PM
+# 05/25/2019 01:24 PM
 
 app.html
 index.html?offline=1

+ 112 - 19
src/main/webapp/electron.js

@@ -240,17 +240,12 @@ app.on('ready', e =>
 	          click() { shell.openExternal('https://about.draw.io/support'); }
 			},
 			checkForUpdates,
-	        {
-	          type: 'separator'
-	        },
-	        {
-	          label: 'Quit',
-	          accelerator: 'Command+Q',
-	          click() {
-				cmdQPressed = true;
-				app.quit(); 
-			  }
-	        }
+			{ type: 'separator' },
+	        { role: 'hide' },
+	        { role: 'hideothers' },
+	        { role: 'unhide' },
+	        { type: 'separator' },
+	        { role: 'quit' }
 	      ]
 	    }, {
 	      label: 'Edit',
@@ -283,15 +278,16 @@ app.on('ready', e =>
 	{
 		autoUpdater.checkForUpdates()
 	}
-
-	if (process.platform === 'darwin')
-	{
-		globalShortcut.register('Command+H', () => {
-			app.hide()
-		})
-	}
 })
 
+//Quit from the dock context menu should quit the application directly
+if (process.platform === 'darwin') 
+{
+	app.on('before-quit', function() {
+		cmdQPressed = true;
+	});	
+}
+
 // Quit when all windows are closed.
 app.on('window-all-closed', function ()
 {
@@ -440,4 +436,101 @@ autoUpdater.on('update-available', (a, b) =>
 			store.set('dontCheckUpdates', true)
 		}
 	})
-})
+})
+
+//Pdf export
+const MICRON_TO_PIXEL = 264.58 		//264.58 micron = 1 pixel
+
+ipcMain.on('pdf-export', (event, args) =>
+{
+	var browser = null;
+	
+	try
+	{
+		browser = new BrowserWindow({
+			webPreferences: {
+				nodeIntegration: true
+			},
+			show : false,
+			parent: windowsRegistry[0] //set parent to first opened window. Not very accurate, but useful when all visible windows are closed
+		});
+
+		browser.loadURL(`file://${__dirname}/export3.html`);
+
+		const contents = browser.webContents;
+		
+		contents.on('did-finish-load', function()
+	    {
+			browser.webContents.send('render', {
+				xml: args.xml,
+				format: 'pdf',
+				w: args.w,
+				h: args.h,
+				border: args.border || 0,
+				bg: args.bg,
+				"from": args["from"],
+				to: args.to,
+				pageId: args.pageId,
+				allPages: args.allPages,
+				scale: args.scale || 1,
+				extras: args.extras
+			});
+			
+			ipcMain.once('render-finished', (evt, bounds) =>
+			{
+				var pdfOptions = {pageSize: 'A4'};
+
+				if (bounds != null)
+				{
+					//Chrome generates Pdf files larger than requested pixels size and requires scaling
+					var fixingScale = 0.959;
+	
+					var w = Math.ceil(bounds.width * fixingScale);
+					
+					// +0.1 fixes cases where adding 1px below is not enough
+					// Increase this if more cropped PDFs have extra empty pages
+					var h = Math.ceil(bounds.height * fixingScale + 0.1);
+	
+					//page.setViewport({width: w, height: h});
+					
+					pdfOptions = {
+						printBackground: true,
+						pageSize : {
+							width: w * MICRON_TO_PIXEL,
+							height: (h + 1) * MICRON_TO_PIXEL //the extra pixel to prevent adding an extra empty page						
+						},
+						marginsType: 1 // no margin
+					}
+				}
+				
+				contents.printToPDF(pdfOptions, (error, data) => 
+				{
+					if (error)
+					{
+						event.reply('pdf-export-error', error);
+					}
+					else
+					{
+						event.reply('pdf-export-success', data);
+					}
+				})
+				
+				//Destroy the window after 30 sec which is more than enough (test with 1 sec works)
+				setTimeout(function()
+				{
+					browser.destroy();
+				}, 30000);
+			})
+	    });
+	}
+	catch (e)
+	{
+		if (browser != null)
+		{
+			browser.destroy();
+		}
+
+		event.reply('pdf-export-error', e);
+		console.log('pdf-export-error', e);
+	}
+})

+ 35 - 0
src/main/webapp/export3.html

@@ -21,6 +21,8 @@
 	<link rel="stylesheet" href="mxgraph/css/common.css" charset="UTF-8" type="text/css">
     <script src="js/app.min.js"></script>
 	<script>
+		var mxIsElectron = navigator.userAgent.toLowerCase().indexOf(' electron/') > -1;
+	
 		Editor.initMath();
 	
 		function render(data)
@@ -141,6 +143,21 @@
 					doneDiv.setAttribute('page-id', pageId);
 					doneDiv.setAttribute('scale', expScale);
 					document.body.appendChild(doneDiv);
+					
+					//Electron pdf export
+					if (mxIsElectron)
+					{
+						try 
+						{
+							const { ipcRenderer } = require('electron');
+							
+							ipcRenderer.send('render-finished', bounds);
+						}
+						catch(e)
+						{
+							console.log(e);
+						}
+					}
 				}
 			};
 			
@@ -528,6 +545,24 @@
 			// Immediate return if not waiting for any content
 			decrementWaitCounter();
 		};
+		
+		//Electron pdf export
+		if (mxIsElectron)
+		{
+			try 
+			{
+				const { ipcRenderer } = require('electron');
+				
+				ipcRenderer.on('render', (event, arg) => 
+				{
+					render(arg);
+				});
+			}
+			catch(e)
+			{
+				console.log(e);
+			}
+		}
 	</script>
 </head>
 <body style="margin:0px;">

+ 5 - 2
src/main/webapp/index.html

@@ -18,6 +18,8 @@
 	<meta name="theme-color" content="#d89000">
 	<script type="text/javascript">
 		var mxIsElectron = (window && window.process && window.process.type) || (navigator.userAgent.toLowerCase().indexOf(' electron/') > -1);
+		
+		var mxIsElectron5 = mxIsElectron && parseInt(process.versions.electron) >= 5;
 		/**
 		 * URL Parameters and protocol description are here:
 		 *
@@ -146,9 +148,10 @@
 			addMeta('apple-mobile-web-app-title', name);
 			addMeta('application-name', name);
 
-			if (mxIsElectron)
+			if (mxIsElectron5)
 			{
-				addMeta(null, 'default-src \'self\' \'unsafe-inline\'; connect-src \'self\' https://*.draw.io; img-src * data:; media-src *; font-src *', 'Content-Security-Policy');
+				//TODO Remove unsafe-eval which requires removing dependency on eval in many parts of the code (stencils, styles, decoder, ...) 
+				addMeta(null, 'default-src \'self\' \'unsafe-inline\' \'unsafe-eval\'; connect-src \'self\' https://*.draw.io; img-src * data:; media-src *; font-src *', 'Content-Security-Policy');
 			}
 		})();
 	</script>

Fichier diff supprimé car celui-ci est trop grand
+ 155 - 155
src/main/webapp/js/app.min.js


+ 21 - 6
src/main/webapp/js/diagramly/EditorUi.js

@@ -433,9 +433,9 @@
 	/**
 	 * Returns true if no external comms allowed or possible
 	 */
-	EditorUi.prototype.isOffline = function()
+	EditorUi.prototype.isOffline = function(ignoreStealth)
 	{
-		return this.isOfflineApp() || !navigator.onLine || urlParams['stealth'] == '1';
+		return this.isOfflineApp() || !navigator.onLine || (!ignoreStealth && urlParams['stealth'] == '1');
 	};
 
 	/**
@@ -6634,9 +6634,14 @@
 					}
 				}
 			}
+			else
+			{
+				this.spinner.stop();
+				this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
+			}
 		});
 		
-		if (!this.doImportVisio && !this.loadingExtensions && !this.isOffline())
+		if (!this.doImportVisio && !this.loadingExtensions && !this.isOffline(true))
 		{
 			this.loadingExtensions = true;
 			mxscript('js/extensions.min.js', delayed);
@@ -6673,9 +6678,14 @@
 					onerror(e);
 				}
 			}
+			else
+			{
+				this.spinner.stop();
+				this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
+			}
 		});
 		
-		if (!this.doImportGraphML && !this.loadingExtensions && !this.isOffline())
+		if (!this.doImportGraphML && !this.loadingExtensions && !this.isOffline(true))
 		{
 			this.loadingExtensions = true;
 			mxscript('js/extensions.min.js', delayed);
@@ -6711,9 +6721,14 @@
 					this.handleError(e);
 				}
 			}
+			else
+			{
+				this.spinner.stop();
+				this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
+			}
 		});
 		
-		if (typeof VsdxExport === 'undefined' && !this.loadingExtensions && !this.isOffline())
+		if (typeof VsdxExport === 'undefined' && !this.loadingExtensions && !this.isOffline(true))
 		{
 			this.loadingExtensions = true;
 			mxscript('js/extensions.min.js', delayed);
@@ -6754,7 +6769,7 @@
 		});
 		
 		if (typeof window.LucidImporter === 'undefined' &&
-			!this.loadingExtensions && !this.isOffline())
+			!this.loadingExtensions && !this.isOffline(true))
 		{
 			this.loadingExtensions = true;
 			

+ 121 - 0
src/main/webapp/js/diagramly/ElectronApp.js

@@ -1014,6 +1014,127 @@ FeedbackDialog.feedbackUrl = 'https://log.draw.io/email';
 			});
 		}
 	};
+
+	function mxElectronRequest(reqType, reqObj)
+	{
+		this.reqType = reqType;
+		this.reqObj = reqObj;
+	};
+
+	//Extends mxXmlRequest
+	mxUtils.extend(mxElectronRequest, mxXmlRequest);
+	
+	mxElectronRequest.prototype.send = function(callback, error)
+	{
+		const ipcRenderer = require('electron').ipcRenderer;
+		ipcRenderer.send(this.reqType, this.reqObj);
+		
+		ipcRenderer.once(this.reqType + '-success', (event, data) => 
+		{
+			this.response = data;
+			callback();
+		})
+
+		ipcRenderer.once(this.reqType + '-error', (event, err) => 
+		{
+			this.hasError = true;
+			error(err);
+		})
+	};
+	
+	mxElectronRequest.prototype.getStatus = function()
+	{
+		return this.hasError? 500 : 200; 
+	}
+	
+	mxElectronRequest.prototype.getText = function()
+	{
+		return this.response;
+	}
+	
+	if (mxIsElectron5)
+	{
+		//Direct export to pdf
+		var origCreateDownloadRequest = EditorUi.prototype.createDownloadRequest;
+		
+		EditorUi.prototype.createDownloadRequest = function(filename, format, ignoreSelection, base64, transparent, currentPage)
+		{
+			if (format == 'pdf')
+			{
+				var bounds = this.editor.graph.getGraphBounds();
+				
+				// Exports only current page for images that does not contain file data, but for
+				// the other formats with XML included or pdf with all pages, we need to send the complete data and use
+				// the from/to URL parameters to specify the page to be exported.
+				var data = this.getFileData(true, null, null, null, ignoreSelection, currentPage == false? false : format != 'xmlpng');
+				var allPages = null;
+				
+				if (bounds.width * bounds.height > MAX_AREA || data.length > MAX_REQUEST_SIZE)
+				{
+					throw {message: mxResources.get('drawingTooLarge')};
+				}
+				
+				if (currentPage == false)
+				{
+					allPages = '1';
+				}
+				
+				var bg = this.editor.graph.background;
+				
+				return new mxElectronRequest('pdf-export', {
+					xml: data,
+					bg: (bg != null) ? bg : mxConstants.NONE,
+					filename: (filename != null) ? filename : null,
+					allPages: allPages
+				});
+			}
+			else
+			{
+				return origCreateDownloadRequest.apply(this, arguments);
+			}
+		};
+		
+		//Export Dialog Pdf case
+		var origExportFile = ExportDialog.exportFile;
+		
+		ExportDialog.exportFile = function(editorUi, name, format, bg, s, b)
+		{
+			var graph = editorUi.editor.graph;
+			
+			if (format == 'pdf')
+			{
+				var data = editorUi.getFileData(true, null, null, null, null, true);
+	    		var bounds = graph.getGraphBounds();
+				var w = Math.floor(bounds.width * s / graph.view.scale);
+				var h = Math.floor(bounds.height * s / graph.view.scale);
+				
+				if (data.length <= MAX_REQUEST_SIZE && w * h < MAX_AREA)
+				{
+					editorUi.hideDialog();
+					editorUi.saveRequest(name, format,
+						function(newTitle, base64)
+						{
+							return new mxElectronRequest('pdf-export', {
+								xml: data,
+								bg: (bg != null) ? bg : mxConstants.NONE,
+								filename: (newTitle != null) ? newTitle : null,
+								w: w,
+								h: h,
+								border: b
+							}); 
+						});
+				}
+				else
+				{
+					mxUtils.alert(mxResources.get('drawingTooLarge'));
+				}
+			}
+			else
+			{
+				return origExportFile.apply(this, arguments);
+			}
+		};
+	}
 	
 	EditorUi.prototype.saveData = function(filename, format, data, mimeType, base64Encoded)
 	{

Fichier diff supprimé car celui-ci est trop grand
+ 154 - 154
src/main/webapp/js/viewer.min.js