mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-03 21:43:18 +00:00 
			
		
		
		
	Put LinkUtil to renderer-side.
This commit is contained in:
		@@ -1,16 +0,0 @@
 | 
			
		||||
const wurl = require('wurl');
 | 
			
		||||
 | 
			
		||||
// Check link if it's internal/external
 | 
			
		||||
function linkIsInternal(currentUrl, newUrl) {
 | 
			
		||||
	const currentDomain = wurl('hostname', currentUrl);
 | 
			
		||||
	const newDomain = wurl('hostname', newUrl);
 | 
			
		||||
	return currentDomain === newDomain;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// We'll be needing this to open images in default browser
 | 
			
		||||
const skipImages = '.jpg|.gif|.png|.jpeg|.JPG|.PNG';
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
	linkIsInternal,
 | 
			
		||||
	skipImages
 | 
			
		||||
};
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
const DomainUtil = require(__dirname + '/../utils/domain-util.js');
 | 
			
		||||
const SystemUtil = require(__dirname + '/../utils/system-util.js');
 | 
			
		||||
const {linkIsInternal, skipImages} = require(__dirname + '/../../../main/link-helper');
 | 
			
		||||
const LinkUtil = require(__dirname + '/../utils/link-util.js');
 | 
			
		||||
const {app, dialog, shell} = require('electron').remote;
 | 
			
		||||
const {ipcRenderer} = require('electron');
 | 
			
		||||
 | 
			
		||||
@@ -25,6 +25,7 @@ class WebView extends BaseComponent {
 | 
			
		||||
		this.isActive = isActive;
 | 
			
		||||
		this.domainUtil = new DomainUtil();
 | 
			
		||||
		this.systemUtil = new SystemUtil();
 | 
			
		||||
		this.linkUtil = new LinkUtil();
 | 
			
		||||
		this.badgeCount = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -52,7 +53,7 @@ class WebView extends BaseComponent {
 | 
			
		||||
			const {url} = event;
 | 
			
		||||
			const domainPrefix = this.domainUtil.getDomain(this.index).url;
 | 
			
		||||
 | 
			
		||||
			if (linkIsInternal(domainPrefix, url) && url.match(skipImages) === null) {
 | 
			
		||||
			if (this.linkUtil.isInternal(domainPrefix, url)) {
 | 
			
		||||
				event.preventDefault();
 | 
			
		||||
				this.$el.loadURL(url);
 | 
			
		||||
			} else {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								app/renderer/js/utils/link-util.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/renderer/js/utils/link-util.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
const wurl = require('wurl');
 | 
			
		||||
 | 
			
		||||
let instance = null;
 | 
			
		||||
 | 
			
		||||
class LinkUtil {
 | 
			
		||||
	constructor() {
 | 
			
		||||
		if (instance) {
 | 
			
		||||
			return instance;
 | 
			
		||||
		} else {
 | 
			
		||||
			instance = this;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    isInternal(currentUrl, newUrl) {
 | 
			
		||||
        const currentDomain = wurl('hostname', currentUrl);
 | 
			
		||||
        const newDomain = wurl('hostname', newUrl);
 | 
			
		||||
 | 
			
		||||
        const skipImages = '.jpg|.gif|.png|.jpeg|.JPG|.PNG';
 | 
			
		||||
 | 
			
		||||
        // We'll be needing this to open images in default browser
 | 
			
		||||
        return (currentDomain === newDomain) || newUrl.match(skipImages);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = LinkUtil;
 | 
			
		||||
		Reference in New Issue
	
	Block a user