diff --git a/app/main/menu.js b/app/main/menu.js index 920c6ff8..0ee205aa 100644 --- a/app/main/menu.js +++ b/app/main/menu.js @@ -9,8 +9,6 @@ const BrowserWindow = electron.BrowserWindow; const shell = electron.shell; const appName = app.getName(); -// const {about} = require('./windowmanager'); - function sendAction(action) { const win = BrowserWindow.getAllWindows()[0]; diff --git a/app/renderer/css/main.css b/app/renderer/css/main.css index a873e360..a18c2943 100644 --- a/app/renderer/css/main.css +++ b/app/renderer/css/main.css @@ -116,11 +116,11 @@ html, body { opacity: 0.8; } -.tab .settings-tab { +.tab .functional-tab { background: #eee; } -.tab .settings-tab i { +.tab .functional-tab i { font-size: 28px; line-height: 36px; } diff --git a/app/renderer/js/components/functional-tab.js b/app/renderer/js/components/functional-tab.js new file mode 100644 index 00000000..a6184c9f --- /dev/null +++ b/app/renderer/js/components/functional-tab.js @@ -0,0 +1,20 @@ +'use strict'; + +const Tab = require(__dirname + '/../components/tab.js'); + +class FunctionalTab extends Tab { + constructor(props) { + super(props); + } + + template() { + return `
+
+
+ ${this.props.materialIcon} +
+
`; + } +} + +module.exports = FunctionalTab; diff --git a/app/renderer/js/components/server-tab.js b/app/renderer/js/components/server-tab.js new file mode 100644 index 00000000..35a789c3 --- /dev/null +++ b/app/renderer/js/components/server-tab.js @@ -0,0 +1,18 @@ +'use strict'; + +const Tab = require(__dirname + '/../components/tab.js'); + +class ServerTab extends Tab { + constructor(props) { + super(props); + } + + template() { + return `
+
+
+
`; + } +} + +module.exports = ServerTab; diff --git a/app/renderer/js/components/tab.js b/app/renderer/js/components/tab.js index 5fe1e142..ab5f7b61 100644 --- a/app/renderer/js/components/tab.js +++ b/app/renderer/js/components/tab.js @@ -11,22 +11,6 @@ class Tab extends BaseComponent { this.init(); } - template() { - if (this.props.type === Tab.SERVER_TAB) { - return `
-
-
-
`; - } else { - return `
-
-
- settings -
-
`; - } - } - init() { this.$el = this.generateNodeFromTemplate(this.template()); this.$badge = this.$el.getElementsByClassName('server-tab-badge')[0]; diff --git a/app/renderer/js/main.js b/app/renderer/js/main.js index 9b9d3714..68ca19b9 100644 --- a/app/renderer/js/main.js +++ b/app/renderer/js/main.js @@ -5,7 +5,8 @@ const {ipcRenderer} = require('electron'); const DomainUtil = require(__dirname + '/js/utils/domain-util.js'); const WebView = require(__dirname + '/js/components/webview.js'); -const Tab = require(__dirname + '/js/components/tab.js'); +const ServerTab = require(__dirname + '/js/components/server-tab.js'); +const FunctionalTab = require(__dirname + '/js/components/functional-tab.js'); class ServerManagerView { constructor() { @@ -17,11 +18,10 @@ class ServerManagerView { this.$settingsButton = $actionsContainer.querySelector('#settings-action'); this.$content = document.getElementById('content'); - this.settingsTabIndex = -1; - this.aboutTabIndex = -1; this.activeTabIndex = -1; this.webviews = []; this.tabs = []; + this.functionalTabs = {}; } init() { @@ -43,11 +43,8 @@ class ServerManagerView { } initServer(server, index) { - this.tabs.push(new Tab({ - url: server.url, - name: server.alias, + this.tabs.push(new ServerTab({ icon: server.icon, - type: Tab.SERVER_TAB, $root: this.$tabsContainer, onClick: this.activateTab.bind(this, index) })); @@ -71,69 +68,51 @@ class ServerManagerView { this.$addServerButton.addEventListener('click', this.openSettings.bind(this)); this.$settingsButton.addEventListener('click', this.openSettings.bind(this)); } - - openSettings() { - if (this.settingsTabIndex !== -1) { - this.activateTab(this.settingsTabIndex); + + openFunctionalTab(tabProps) { + const {name, materialIcon, url} = tabProps; + if (this.functionalTabs.hasOwnProperty(name)) { + this.activateTab(this.functionalTabs[name]); return; } - const url = 'file://' + __dirname + '/preference.html'; - this.settingsTabIndex = this.webviews.length; + this.functionalTabs[name] = this.webviews.length; - this.tabs.push(new Tab({ - url, - name: 'Settings', - type: Tab.SETTINGS_TAB, + this.tabs.push(new FunctionalTab({ + materialIcon: tabProps.materialIcon, $root: this.$tabsContainer, - onClick: this.activateTab.bind(this, this.settingsTabIndex) + onClick: this.activateTab.bind(this, this.functionalTabs[name]) })); this.webviews.push(new WebView({ $root: this.$content, - index: this.settingsTabIndex, - url, - name: 'Settings', + index: this.functionalTabs[name], + url: tabProps.url, + name: tabProps.name, isActive: () => { - return this.settingsTabIndex === this.activeTabIndex; + return this.functionalTabs[name] === this.activeTabIndex; }, onTitleChange: this.updateBadge.bind(this), nodeIntegration: true })); - this.activateTab(this.settingsTabIndex); + this.activateTab(this.functionalTabs[name]); + } + + openSettings() { + this.openFunctionalTab({ + name: 'Settings', + materialIcon: 'settings', + url: `file://${__dirname}/preference.html` + }); } openAbout() { - if (this.aboutTabIndex !== -1) { - this.activateTab(this.aboutTabIndex); - return; - } - const url = 'file://' + __dirname + '/about.html'; - - this.aboutTabIndex = this.webviews.length; - - this.tabs.push(new Tab({ - url, - name: 'About', - type: Tab.SETTINGS_TAB, - $root: this.$tabsContainer, - onClick: this.activateTab.bind(this, this.aboutTabIndex) - })); - - this.webviews.push(new WebView({ - $root: this.$content, - index: this.aboutTabIndex, - url, - name: 'About', - isActive: () => { - return this.activeTabIndex === this.aboutTabIndex; - }, - onTitleChange: this.updateBadge.bind(this), - nodeIntegration: true - })); - - this.activateTab(this.aboutTabIndex); + this.openFunctionalTab({ + name: 'About', + materialIcon: 'sentiment_very_satisfied', + url: `file://${__dirname}/about.html` + }); } activateTab(index) { diff --git a/app/renderer/preference.html b/app/renderer/preference.html index dd2588c8..a6c19183 100644 --- a/app/renderer/preference.html +++ b/app/renderer/preference.html @@ -41,5 +41,5 @@ - +