Skip to content

Commit

Permalink
Add warning on malformed URL
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashmahar committed Sep 2, 2020
1 parent d0c3196 commit bc939c7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 51 deletions.
2 changes: 0 additions & 2 deletions src/js/addUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/js/advancedUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/js/begUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/js/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
113 changes: 67 additions & 46 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,69 +543,90 @@ 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': `
<p>Invalid URL entered</p>
<p class="text-secondary">Europa did not understant '${url}' as a valid URL. Please make sure that the URL includes the protocol (e.g., http:// or https://).</p>`,
'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() {
electronLocalshortcut.register(mainWindow, 'Ctrl+O', showOpenURLDialog);
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);
Expand Down

0 comments on commit bc939c7

Please sign in to comment.