diff --git a/src/js/addUrl.js b/src/js/addUrl.js index 31d216a..718f06b 100644 --- a/src/js/addUrl.js +++ b/src/js/addUrl.js @@ -13,8 +13,6 @@ function main() { const input = document.getElementById('add-input'); if (input.value != '') { - ipcRenderer.send('add-recent-url', input.value); - ipcRenderer.send('open-url', input.value); // Close the window diff --git a/src/js/advancedUser.js b/src/js/advancedUser.js index 03e8751..e4faddd 100644 --- a/src/js/advancedUser.js +++ b/src/js/advancedUser.js @@ -133,7 +133,6 @@ function startServerResp(event, result) { url = url.replace(/(^[ '\^\$\*#&]+)|([ '\^\$\*#&]+$)/g, '') if (url) { - ipcRenderer.send('add-recent-url', url); ipcRenderer.send('open-url', url); var window = remote.getCurrentWindow(); window.close(); diff --git a/src/js/begUser.js b/src/js/begUser.js index f3f1ee9..fcfabf0 100644 --- a/src/js/begUser.js +++ b/src/js/begUser.js @@ -58,7 +58,6 @@ function startServerResp(event, result) { url = url.replace(/(^[ '\^\$\*#&]+)|([ '\^\$\*#&]+$)/g, '') if (url) { - ipcRenderer.send('add-recent-url', url); ipcRenderer.send('open-url', url); var window = remote.getCurrentWindow(); window.close(); diff --git a/src/js/welcome.js b/src/js/welcome.js index a211b96..1f2e117 100644 --- a/src/js/welcome.js +++ b/src/js/welcome.js @@ -6,7 +6,6 @@ const winDecorations = require('../js/modules/winDecorations'); const recentItemClicked = (e) => { console.log(e.target.textContent); - ipcRenderer.send('add-recent-url', e.target.textContent); ipcRenderer.send('open-url', e.target.textContent); } const deleteRecentItemClicked = (e) => { diff --git a/src/main.js b/src/main.js index 809d966..9ee9d9c 100644 --- a/src/main.js +++ b/src/main.js @@ -543,53 +543,70 @@ function showNewServerDialog() { * @param {String} url URL to browse to */ function showEuropaBrowser(e, url) { - // Track for login on the opened url - addTrackingForUrl(url); + try { var urlObj = new URL(url) - - // Create a title for the new window - var windowTitle = 'Europa @ '.concat(url.substring(0, 100)); - if (url.length > 100) { - windowTitle.concat('...'); + } catch (error) { + const props = { + 'type': 'error', + 'title': 'URL Error', + 'content': ` +
Invalid URL entered
+Europa did not understant '${url}' as a valid URL. Please make sure that the URL includes the protocol (e.g., http:// or https://).
`, + 'primaryBtn': 'OK', + 'secondaryBtn': '', } - - var newJupyterWin = new BrowserWindow({ - width: 1080, - height: 768, - preload: path.join(appDir, 'js', 'preload404.js'), - webPreferences: { - nodeIntegration: false - }, - icon: iconPath, - frame: DRAW_FRAME, - title: windowTitle - }) - - windowTracker[urlObj.origin] = newJupyterWin; - newJupyterWin.loadURL(url); + createDialog(mainWindow, props, `${Date.now()}`, (resp) => {}); + return; + } - /* Set did-fail-load listener once */ - newJupyterWin.webContents.on("did-fail-load", show404); - - /* cleanup */ - newJupyterWin.on('closed', () => { - newJupyterWin = null - removeTrackingForUrl(url); - }) + addRecentURL(url); - newJupyterWin.once('ready-to-show', () => { - newJupyterWin.show() - }) + // Track for login on the opened url + addTrackingForUrl(url); + + // Create a title for the new window + var windowTitle = 'Europa @ '.concat(url.substring(0, 100)); + if (url.length > 100) { + windowTitle.concat('...'); + } + + var newJupyterWin = new BrowserWindow({ + width: 1080, + height: 768, + preload: path.join(appDir, 'js', 'preload404.js'), + webPreferences: { + nodeIntegration: false + }, + icon: iconPath, + frame: DRAW_FRAME, + title: windowTitle + }) + + windowTracker[urlObj.origin] = newJupyterWin; + newJupyterWin.loadURL(url); - /* Prevent the title from being updated */ - newJupyterWin.on('page-title-updated', (evt) => { - evt.preventDefault(); - }); + /* Set did-fail-load listener once */ + newJupyterWin.webContents.on("did-fail-load", show404); + + /* cleanup */ + newJupyterWin.on('closed', () => { + newJupyterWin = null + removeTrackingForUrl(url); + }) - /* Register shortcuts */ - electronLocalshortcut.register(newJupyterWin, 'Ctrl+Shift+W', () => { - newJupyterWin.close(); - }); + newJupyterWin.once('ready-to-show', () => { + newJupyterWin.show() + }) + + /* Prevent the title from being updated */ + newJupyterWin.on('page-title-updated', (evt) => { + evt.preventDefault(); + }); + + /* Register shortcuts */ + electronLocalshortcut.register(newJupyterWin, 'Ctrl+Shift+W', () => { + newJupyterWin.close(); + }); } function addMainWindowShortcuts() { @@ -597,15 +614,19 @@ function addMainWindowShortcuts() { electronLocalshortcut.register(mainWindow, 'Ctrl+N', showNewServerDialog); } +/** + * Add a new url to the recent list and update mainWindow + * @param {String} url URL to add to the recent list + */ +function addRecentURL(url) { + const updatedUrls = recentUrlsDb.pushFront(url, MAX_RECENT_ITEMS).urls; + mainWindow.send('recent-urls', updatedUrls); +} + /** * Add listeners for getting and setting recent URL list */ function addRecentURLListeners() { - ipcMain.on('add-recent-url', (event, url) => { - const updatedUrls = recentUrlsDb.pushFront(url, MAX_RECENT_ITEMS).urls; - mainWindow.send('recent-urls', updatedUrls); - }) - ipcMain.on('delete-recent-url', (event, url) => { const updatedUrls = recentUrlsDb.remove(url).urls; mainWindow.send('recent-urls', updatedUrls);