Fix lint errors.

This commit is contained in:
Zhongyi Tong
2017-06-16 21:07:48 +08:00
parent 743d689281
commit 7f8d933ab7
4 changed files with 159 additions and 155 deletions

View File

@@ -1,4 +1,4 @@
"use strict"; 'use strict';
class BaseComponent { class BaseComponent {
generateNodeFromTemplate(template) { generateNodeFromTemplate(template) {
@@ -8,4 +8,4 @@ class BaseComponent {
} }
} }
module.exports = BaseComponent; module.exports = BaseComponent;

View File

@@ -3,69 +3,69 @@
const BaseComponent = require(__dirname + '/../components/base.js'); const BaseComponent = require(__dirname + '/../components/base.js');
class Tab extends BaseComponent { class Tab extends BaseComponent {
constructor(params) { constructor(params) {
super(); super();
const {url, icon, name, type, $root, onClick} = params; const {url, icon, name, type, $root, onClick} = params;
this.url = url; this.url = url;
this.name = name; this.name = name;
this.icon = icon; this.icon = icon;
this.type = type; this.type = type;
this.$root = $root; this.$root = $root;
this.onClick = onClick; this.onClick = onClick;
this.init(); this.init();
} }
template() { template() {
if (this.type == Tab.SERVER_TAB) { if (this.type === Tab.SERVER_TAB) {
return `<div class="tab" domain="${this.url}"> return `<div class="tab" domain="${this.url}">
<div class="server-tab-badge"></div> <div class="server-tab-badge"></div>
<div class="server-tab" style="background-image: url(${this.icon});"></div> <div class="server-tab" style="background-image: url(${this.icon});"></div>
</div>`; </div>`;
} else { } else {
return `<div class="tab" domain="${this.url}"> return `<div class="tab" domain="${this.url}">
<div class="server-tab-badge"></div> <div class="server-tab-badge"></div>
<div class="server-tab settings-tab"> <div class="server-tab settings-tab">
<i class="material-icons md-48">settings</i> <i class="material-icons md-48">settings</i>
</div> </div>
</div>`; </div>`;
} }
} }
init() { init() {
this.$el = this.generateNodeFromTemplate(this.template()); this.$el = this.generateNodeFromTemplate(this.template());
this.$badge = this.$el.getElementsByClassName('server-tab-badge')[0]; this.$badge = this.$el.getElementsByClassName('server-tab-badge')[0];
this.$root.appendChild(this.$el); this.$root.appendChild(this.$el);
this.registerListeners(); this.registerListeners();
} }
updateBadge(count) { updateBadge(count) {
if (count > 0) { if (count > 0) {
const formattedCount = count > 999? '1K+': count; const formattedCount = count > 999 ? '1K+' : count;
this.$badge.innerHTML = formattedCount; this.$badge.innerHTML = formattedCount;
this.$badge.classList.add('active'); this.$badge.classList.add('active');
} else { } else {
this.$badge.classList.remove('active'); this.$badge.classList.remove('active');
} }
} }
registerListeners() { registerListeners() {
this.$el.addEventListener('click', this.onClick); this.$el.addEventListener('click', this.onClick);
} }
activate() { activate() {
this.$el.classList.add('active'); this.$el.classList.add('active');
} }
deactivate() { deactivate() {
this.$el.classList.remove('active'); this.$el.classList.remove('active');
} }
} }
Tab.SERVER_TAB = 0; Tab.SERVER_TAB = 0;
Tab.SETTINGS_TAB = 1; Tab.SETTINGS_TAB = 1;
module.exports = Tab; module.exports = Tab;

View File

@@ -3,7 +3,7 @@
const DomainUtil = require(__dirname + '/../utils/domain-util.js'); const DomainUtil = require(__dirname + '/../utils/domain-util.js');
const SystemUtil = require(__dirname + '/../utils/system-util.js'); const SystemUtil = require(__dirname + '/../utils/system-util.js');
const {linkIsInternal, skipImages} = require(__dirname + '/../../../main/link-helper'); const {linkIsInternal, skipImages} = require(__dirname + '/../../../main/link-helper');
const {app, dialog} = require('electron').remote; const {app, dialog, shell} = require('electron').remote;
const {ipcRenderer} = require('electron'); const {ipcRenderer} = require('electron');
const BaseComponent = require(__dirname + '/../components/base.js'); const BaseComponent = require(__dirname + '/../components/base.js');
@@ -11,34 +11,34 @@ const BaseComponent = require(__dirname + '/../components/base.js');
class WebView extends BaseComponent { class WebView extends BaseComponent {
constructor(params) { constructor(params) {
super(); super();
const {$root, url, index, name, isActive, onTitleChange, nodeIntegration} = params;
this.$root = $root;
this.index = index;
this.name = name;
this.url = url;
this.nodeIntegration = nodeIntegration;
this.onTitleChange = onTitleChange; const {$root, url, index, name, isActive, onTitleChange, nodeIntegration} = params;
this.zoomFactor = 1.0; this.$root = $root;
this.loading = false; this.index = index;
this.name = name;
this.url = url;
this.nodeIntegration = nodeIntegration;
this.onTitleChange = onTitleChange;
this.zoomFactor = 1.0;
this.loading = false;
this.isActive = isActive; this.isActive = isActive;
this.domainUtil = new DomainUtil(); this.domainUtil = new DomainUtil();
this.systemUtil = new SystemUtil(); this.systemUtil = new SystemUtil();
this.badgeCount = 0; this.badgeCount = 0;
} }
template() { template() {
return `<webview return `<webview
id="webview-${this.index}" id="webview-${this.index}"
class="disabled" class="disabled"
src="${this.url}" src="${this.url}"
${this.nodeIntegration ? 'nodeIntegration' : ''} ${this.nodeIntegration ? 'nodeIntegration' : ''}
disablewebsecurity disablewebsecurity
preload="js/preload.js" preload="js/preload.js"
webpreferences="allowRunningInsecureContent, javascript=yes"> webpreferences="allowRunningInsecureContent, javascript=yes">
</webview>`; </webview>`;
} }
init() { init() {
this.$el = this.generateNodeFromTemplate(this.template()); this.$el = this.generateNodeFromTemplate(this.template());
@@ -56,21 +56,21 @@ class WebView extends BaseComponent {
event.preventDefault(); event.preventDefault();
this.$el.loadURL(url); this.$el.loadURL(url);
} else { } else {
event.preventDefault(); event.preventDefault();
shell.openExternal(url); shell.openExternal(url);
} }
}); });
this.$el.addEventListener('page-title-updated', event => { this.$el.addEventListener('page-title-updated', event => {
const {title} = event; const {title} = event;
this.badgeCount = this.getBadgeCount(title); this.badgeCount = this.getBadgeCount(title);
this.onTitleChange(); this.onTitleChange();
}); });
this.$el.addEventListener('dom-ready', this.show.bind(this)); this.$el.addEventListener('dom-ready', this.show.bind(this));
this.$el.addEventListener('did-fail-load', (event) => { this.$el.addEventListener('did-fail-load', event => {
const {errorCode, errorDescription, validatedURL} = event; const {errorDescription} = event;
const hasConnectivityErr = (this.systemUtil.connectivityERR.indexOf(errorDescription) >= 0); const hasConnectivityErr = (this.systemUtil.connectivityERR.indexOf(errorDescription) >= 0);
if (hasConnectivityErr) { if (hasConnectivityErr) {
console.error('error', errorDescription); console.error('error', errorDescription);
@@ -88,38 +88,40 @@ class WebView extends BaseComponent {
}); });
} }
getBadgeCount(title) { getBadgeCount(title) {
let messageCountInTitle = (/\(([0-9]+)\)/).exec(title); const messageCountInTitle = (/\(([0-9]+)\)/).exec(title);
return messageCountInTitle ? Number(messageCountInTitle[1]) : 0; return messageCountInTitle ? Number(messageCountInTitle[1]) : 0;
} }
show() { show() {
// Do not show WebView if another tab was selected and this tab should be in background. // Do not show WebView if another tab was selected and this tab should be in background.
if (!this.isActive()) return; if (!this.isActive()) {
return;
}
this.$el.classList.remove('disabled'); this.$el.classList.remove('disabled');
this.focus() this.focus();
this.loading = false; this.loading = false;
this.onTitleChange(this.$el.getTitle()); this.onTitleChange(this.$el.getTitle());
} }
focus() { focus() {
this.$el.focus(); this.$el.focus();
} }
hide() { hide() {
this.$el.classList.add('disabled'); this.$el.classList.add('disabled');
} }
load() { load() {
if (this.$el) { if (this.$el) {
this.show(); this.show();
} else { } else {
this.init(); this.init();
} }
} }
checkConnectivity() { checkConnectivity() {
return dialog.showMessageBox({ return dialog.showMessageBox({
title: 'Internet connection problem', title: 'Internet connection problem',
message: 'No internet available! Try again?', message: 'No internet available! Try again?',
@@ -138,49 +140,49 @@ class WebView extends BaseComponent {
}); });
} }
zoomIn() { zoomIn() {
this.zoomFactor += 0.1; this.zoomFactor += 0.1;
this.$el.setZoomFactor(this.zoomFactor); this.$el.setZoomFactor(this.zoomFactor);
} }
zoomOut() { zoomOut() {
this.zoomFactor -= 0.1; this.zoomFactor -= 0.1;
this.$el.setZoomFactor(this.zoomFactor); this.$el.setZoomFactor(this.zoomFactor);
} }
zoomActualSize() { zoomActualSize() {
this.zoomFactor = 1.0; this.zoomFactor = 1.0;
this.$el.setZoomFactor(this.zoomFactor); this.$el.setZoomFactor(this.zoomFactor);
} }
logOut() { logOut() {
this.$el.executeJavaScript('logout()'); this.$el.executeJavaScript('logout()');
} }
showShortcut() { showShortcut() {
this.$el.executeJavaScript('shortcut()'); this.$el.executeJavaScript('shortcut()');
} }
openDevTools() { openDevTools() {
this.$el.openDevTools(); this.$el.openDevTools();
} }
back() { back() {
if (this.$el.canGoBack()) { if (this.$el.canGoBack()) {
this.$el.goBack(); this.$el.goBack();
} }
} }
forward() { forward() {
if (this.$el.canGoForward()) { if (this.$el.canGoForward()) {
this.$el.goForward(); this.$el.goForward();
} }
} }
reload() { reload() {
this.hide(); this.hide();
this.$el.reload(); this.$el.reload();
} }
} }
module.exports = WebView; module.exports = WebView;

View File

@@ -1,11 +1,9 @@
'use strict'; 'use strict';
require(__dirname + '/js/tray.js'); require(__dirname + '/js/tray.js');
const {ipcRenderer} = require('electron');
const DomainUtil = require(__dirname + '/js/utils/domain-util.js'); const DomainUtil = require(__dirname + '/js/utils/domain-util.js');
const SystemUtil = require(__dirname + '/js/utils/system-util.js');
const {linkIsInternal, skipImages} = require(__dirname + '/../main/link-helper');
const {shell, ipcRenderer} = require('electron');
const WebView = require(__dirname + '/js/components/webview.js'); const WebView = require(__dirname + '/js/components/webview.js');
const Tab = require(__dirname + '/js/components/tab.js'); const Tab = require(__dirname + '/js/components/tab.js');
@@ -36,7 +34,7 @@ class ServerManagerView {
const servers = this.domainUtil.getDomains(); const servers = this.domainUtil.getDomains();
if (servers.length > 0) { if (servers.length > 0) {
for (let i = 0; i < servers.length; i++) { for (let i = 0; i < servers.length; i++) {
this.initServer(servers[i], i) this.initServer(servers[i], i);
} }
this.activateTab(0); this.activateTab(0);
} else { } else {
@@ -55,10 +53,12 @@ class ServerManagerView {
})); }));
this.webviews.push(new WebView({ this.webviews.push(new WebView({
$root: this.$content, $root: this.$content,
index: index, index,
url: server.url, url: server.url,
name: server.alias, name: server.alias,
isActive: () => {return index == this.activeTabIndex}, isActive: () => {
return index === this.activeTabIndex;
},
onTitleChange: this.updateBadge.bind(this), onTitleChange: this.updateBadge.bind(this),
nodeIntegration: false nodeIntegration: false
})); }));
@@ -82,7 +82,7 @@ class ServerManagerView {
this.settingsTabIndex = this.webviews.length; this.settingsTabIndex = this.webviews.length;
this.tabs.push(new Tab({ this.tabs.push(new Tab({
url: url, url,
name: 'Settings', name: 'Settings',
type: Tab.SETTINGS_TAB, type: Tab.SETTINGS_TAB,
$root: this.$tabsContainer, $root: this.$tabsContainer,
@@ -92,9 +92,11 @@ class ServerManagerView {
this.webviews.push(new WebView({ this.webviews.push(new WebView({
$root: this.$content, $root: this.$content,
index: this.settingsTabIndex, index: this.settingsTabIndex,
url: url, url,
name: "Settings", name: 'Settings',
isActive: () => {return this.settingsTabIndex == this.activeTabIndex}, isActive: () => {
return this.settingsTabIndex === this.activeTabIndex;
},
onTitleChange: this.updateBadge.bind(this), onTitleChange: this.updateBadge.bind(this),
nodeIntegration: true nodeIntegration: true
})); }));
@@ -137,16 +139,16 @@ class ServerManagerView {
registerIpcs() { registerIpcs() {
const webviewListeners = { const webviewListeners = {
'webview-reload': 'reload', 'webview-reload': 'reload',
'back': 'back', back: 'back',
'focus': 'focus', focus: 'focus',
'forward': 'forward', forward: 'forward',
'zoomIn': 'zoomIn', zoomIn: 'zoomIn',
'zoomOut': 'zoomOut', zoomOut: 'zoomOut',
'zoomActualSize': 'zoomActualSize', zoomActualSize: 'zoomActualSize',
'log-out': 'logOut', 'log-out': 'logOut',
'shortcut': 'showShortcut', shortcut: 'showShortcut',
'tab-devtools': 'openDevTools' 'tab-devtools': 'openDevTools'
} };
for (const key in webviewListeners) { for (const key in webviewListeners) {
ipcRenderer.on(key, () => { ipcRenderer.on(key, () => {