mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-23 03:31:56 +00:00
🐛 Internal links open in app
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
node_modules
|
||||
node_modules
|
||||
npm-debug.log
|
27
app/index.js
27
app/index.js
@@ -3,10 +3,16 @@ const path = require('path');
|
||||
const electron = require('electron');
|
||||
const {app, shell} = require('electron');
|
||||
const tray = require('./tray');
|
||||
const link = require ('./link_helper');
|
||||
|
||||
const {linkIsInternal} = link;
|
||||
|
||||
// adds debug features like hotkeys for triggering dev tools and reload
|
||||
require('electron-debug')();
|
||||
|
||||
// Load this url in main window
|
||||
const targetUrl = "https://zulip.com/login"
|
||||
|
||||
// prevent window being garbage collected
|
||||
let mainWindow;
|
||||
|
||||
@@ -27,9 +33,10 @@ function createMainWindow() {
|
||||
minHeight: 600
|
||||
});
|
||||
|
||||
win.loadURL('https://zulip.com/login');
|
||||
win.loadURL(targetUrl);
|
||||
win.on('closed', onClosed);
|
||||
win.setTitle('Zulip');
|
||||
// This will stop page to update it's title
|
||||
|
||||
win.on('page-title-updated',(e) => {
|
||||
e.preventDefault();
|
||||
@@ -55,11 +62,17 @@ app.on('ready', () => {
|
||||
tray.create(mainWindow);
|
||||
|
||||
const page = mainWindow.webContents;
|
||||
page.on('new-window', (e, url) => {
|
||||
e.preventDefault();
|
||||
electron.shell.openExternal(url);
|
||||
});
|
||||
|
||||
|
||||
page.on('new-window', (event, url) => {
|
||||
if (mainWindow.useDefaultWindowBehaviour) {
|
||||
mainWindow.useDefaultWindowBehaviour = false;
|
||||
return;
|
||||
}
|
||||
if (linkIsInternal(targetUrl, url)) {
|
||||
event.preventDefault();
|
||||
return mainWindow.loadURL(url);;
|
||||
}
|
||||
event.preventDefault();
|
||||
electron.shell.openExternal(url);
|
||||
});
|
||||
});
|
||||
|
||||
|
12
app/link_helper.js
Normal file
12
app/link_helper.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const wurl = require('wurl');
|
||||
|
||||
// Check the link if it's inetrnal
|
||||
function linkIsInternal(currentUrl, newUrl) {
|
||||
var currentDomain = wurl('domain', currentUrl);
|
||||
var newDomain = wurl('domain', newUrl);
|
||||
return currentDomain === newDomain;
|
||||
}
|
||||
|
||||
exports = module.exports = {
|
||||
linkIsInternal
|
||||
};
|
@@ -25,12 +25,14 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"electron-debug": "^1.0.0",
|
||||
"electron-dl": "^0.2.0"
|
||||
"electron-dl": "^0.2.0",
|
||||
"wurl": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"devtron": "^1.1.0",
|
||||
"electron-packager": "^7.0.0",
|
||||
"electron-prebuilt": "^1.2.2",
|
||||
"devtron": "^1.1.0",
|
||||
"wurl": "^2.1.0",
|
||||
"xo": "*"
|
||||
},
|
||||
"xo": {
|
||||
|
Reference in New Issue
Block a user