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 {
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');
class Tab extends BaseComponent {
constructor(params) {
super();
constructor(params) {
super();
const {url, icon, name, type, $root, onClick} = params;
this.url = url;
this.name = name;
this.icon = icon;
this.type = type;
this.$root = $root;
this.onClick = onClick;
const {url, icon, name, type, $root, onClick} = params;
this.url = url;
this.name = name;
this.icon = icon;
this.type = type;
this.$root = $root;
this.onClick = onClick;
this.init();
}
this.init();
}
template() {
if (this.type == Tab.SERVER_TAB) {
return `<div class="tab" domain="${this.url}">
<div class="server-tab-badge"></div>
<div class="server-tab" style="background-image: url(${this.icon});"></div>
</div>`;
} else {
return `<div class="tab" domain="${this.url}">
<div class="server-tab-badge"></div>
<div class="server-tab settings-tab">
<i class="material-icons md-48">settings</i>
</div>
</div>`;
}
}
template() {
if (this.type === Tab.SERVER_TAB) {
return `<div class="tab" domain="${this.url}">
<div class="server-tab-badge"></div>
<div class="server-tab" style="background-image: url(${this.icon});"></div>
</div>`;
} else {
return `<div class="tab" domain="${this.url}">
<div class="server-tab-badge"></div>
<div class="server-tab settings-tab">
<i class="material-icons md-48">settings</i>
</div>
</div>`;
}
}
init() {
this.$el = this.generateNodeFromTemplate(this.template());
this.$badge = this.$el.getElementsByClassName('server-tab-badge')[0];
init() {
this.$el = this.generateNodeFromTemplate(this.template());
this.$badge = this.$el.getElementsByClassName('server-tab-badge')[0];
this.$root.appendChild(this.$el);
this.registerListeners();
}
this.registerListeners();
}
updateBadge(count) {
if (count > 0) {
const formattedCount = count > 999? '1K+': count;
updateBadge(count) {
if (count > 0) {
const formattedCount = count > 999 ? '1K+' : count;
this.$badge.innerHTML = formattedCount;
this.$badge.classList.add('active');
} else {
this.$badge.classList.remove('active');
}
}
this.$badge.innerHTML = formattedCount;
this.$badge.classList.add('active');
} else {
this.$badge.classList.remove('active');
}
}
registerListeners() {
registerListeners() {
this.$el.addEventListener('click', this.onClick);
}
}
activate() {
this.$el.classList.add('active');
}
activate() {
this.$el.classList.add('active');
}
deactivate() {
this.$el.classList.remove('active');
}
deactivate() {
this.$el.classList.remove('active');
}
}
Tab.SERVER_TAB = 0;
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 SystemUtil = require(__dirname + '/../utils/system-util.js');
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 BaseComponent = require(__dirname + '/../components/base.js');
@@ -11,34 +11,34 @@ const BaseComponent = require(__dirname + '/../components/base.js');
class WebView extends BaseComponent {
constructor(params) {
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;
this.zoomFactor = 1.0;
this.loading = false;
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;
this.zoomFactor = 1.0;
this.loading = false;
this.isActive = isActive;
this.domainUtil = new DomainUtil();
this.systemUtil = new SystemUtil();
this.badgeCount = 0;
this.domainUtil = new DomainUtil();
this.systemUtil = new SystemUtil();
this.badgeCount = 0;
}
template() {
return `<webview
id="webview-${this.index}"
class="disabled"
src="${this.url}"
${this.nodeIntegration ? 'nodeIntegration' : ''}
disablewebsecurity
preload="js/preload.js"
webpreferences="allowRunningInsecureContent, javascript=yes">
</webview>`;
}
id="webview-${this.index}"
class="disabled"
src="${this.url}"
${this.nodeIntegration ? 'nodeIntegration' : ''}
disablewebsecurity
preload="js/preload.js"
webpreferences="allowRunningInsecureContent, javascript=yes">
</webview>`;
}
init() {
this.$el = this.generateNodeFromTemplate(this.template());
@@ -56,21 +56,21 @@ class WebView extends BaseComponent {
event.preventDefault();
this.$el.loadURL(url);
} else {
event.preventDefault();
shell.openExternal(url);
}
event.preventDefault();
shell.openExternal(url);
}
});
this.$el.addEventListener('page-title-updated', event => {
const {title} = event;
this.badgeCount = this.getBadgeCount(title);
this.onTitleChange();
this.$el.addEventListener('page-title-updated', event => {
const {title} = event;
this.badgeCount = this.getBadgeCount(title);
this.onTitleChange();
});
this.$el.addEventListener('dom-ready', this.show.bind(this));
this.$el.addEventListener('did-fail-load', (event) => {
const {errorCode, errorDescription, validatedURL} = event;
this.$el.addEventListener('did-fail-load', event => {
const {errorDescription} = event;
const hasConnectivityErr = (this.systemUtil.connectivityERR.indexOf(errorDescription) >= 0);
if (hasConnectivityErr) {
console.error('error', errorDescription);
@@ -88,38 +88,40 @@ class WebView extends BaseComponent {
});
}
getBadgeCount(title) {
let messageCountInTitle = (/\(([0-9]+)\)/).exec(title);
getBadgeCount(title) {
const messageCountInTitle = (/\(([0-9]+)\)/).exec(title);
return messageCountInTitle ? Number(messageCountInTitle[1]) : 0;
}
}
show() {
show() {
// 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.focus()
this.loading = false;
this.onTitleChange(this.$el.getTitle());
}
this.$el.classList.remove('disabled');
this.focus();
this.loading = false;
this.onTitleChange(this.$el.getTitle());
}
focus() {
this.$el.focus();
}
focus() {
this.$el.focus();
}
hide() {
this.$el.classList.add('disabled');
}
hide() {
this.$el.classList.add('disabled');
}
load() {
load() {
if (this.$el) {
this.show();
} else {
this.init();
this.init();
}
}
}
checkConnectivity() {
checkConnectivity() {
return dialog.showMessageBox({
title: 'Internet connection problem',
message: 'No internet available! Try again?',
@@ -138,49 +140,49 @@ class WebView extends BaseComponent {
});
}
zoomIn() {
this.zoomFactor += 0.1;
this.$el.setZoomFactor(this.zoomFactor);
}
zoomIn() {
this.zoomFactor += 0.1;
this.$el.setZoomFactor(this.zoomFactor);
}
zoomOut() {
this.zoomFactor -= 0.1;
this.$el.setZoomFactor(this.zoomFactor);
}
zoomOut() {
this.zoomFactor -= 0.1;
this.$el.setZoomFactor(this.zoomFactor);
}
zoomActualSize() {
this.zoomFactor = 1.0;
this.$el.setZoomFactor(this.zoomFactor);
}
zoomActualSize() {
this.zoomFactor = 1.0;
this.$el.setZoomFactor(this.zoomFactor);
}
logOut() {
this.$el.executeJavaScript('logout()');
}
logOut() {
this.$el.executeJavaScript('logout()');
}
showShortcut() {
this.$el.executeJavaScript('shortcut()');
}
showShortcut() {
this.$el.executeJavaScript('shortcut()');
}
openDevTools() {
this.$el.openDevTools();
}
openDevTools() {
this.$el.openDevTools();
}
back() {
if (this.$el.canGoBack()) {
back() {
if (this.$el.canGoBack()) {
this.$el.goBack();
}
}
}
}
forward() {
if (this.$el.canGoForward()) {
forward() {
if (this.$el.canGoForward()) {
this.$el.goForward();
}
}
}
}
reload() {
this.hide();
this.$el.reload();
}
reload() {
this.hide();
this.$el.reload();
}
}
module.exports = WebView;
module.exports = WebView;

View File

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