Merge pull request #241 from Razzeee/Change-title

Change window title to the one thats set from the platform for the current channel
This commit is contained in:
Yuya Ochiai
2016-08-21 15:22:01 +09:00
committed by GitHub
6 changed files with 120 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ Release date: TBD
### Improvements
#### All platforms
- Show current channel/team in window title
- Changed display of unread messages on the team tabbar, they are now shown as bold text
- Reload only the selected tab and keep its URL on "Reload" and "Clear Cache and Reload".
- Disabled `eval()` function for security improvements.

View File

@@ -3,7 +3,6 @@
<head>
<meta charset="UTF-8">
<title>Mattermost</title>
<link rel="stylesheet" href="modules/bootstrap/css/bootstrap.min.css">
</head>

View File

@@ -94,6 +94,11 @@ var MainPage = React.createClass({
key: newKey
});
this.handleOnTeamFocused(key);
var webview = document.getElementById('mattermostView' + key);
ipcRenderer.send('update-title', {
title: webview.getTitle()
});
},
handleUnreadCountChange: function(index, unreadCount, mentionCount, isUnread, isMentioned) {
var unreadCounts = this.state.unreadCounts;
@@ -196,8 +201,9 @@ var MainPage = React.createClass({
thisObj.handleSelect(index);
}
var id = 'mattermostView' + index;
return (<MattermostView key={ id } id={ id } style={ thisObj.visibleStyle(thisObj.state.key === index) } src={ team.url } name={ team.name } onUnreadCountChange={ handleUnreadCountChange }
onNotificationClick={ handleNotificationClick } ref={ id } />)
var is_active = thisObj.state.key === index;
return (<MattermostView key={ id } id={ id } style={ thisObj.visibleStyle(is_active) } src={ team.url } name={ team.name } onUnreadCountChange={ handleUnreadCountChange }
onNotificationClick={ handleNotificationClick } ref={ id } active={ is_active } />)
});
var views_row = (<Row>
{ views }
@@ -403,6 +409,14 @@ var MattermostView = React.createClass({
}
});
webview.addEventListener('page-title-updated', function(event) {
if (thisObj.props.active) {
ipcRenderer.send('update-title', {
title: event.title
});
}
});
webview.addEventListener('console-message', (e) => {
const message = `[${this.props.name}] ${e.message}`;
switch (e.level) {

View File

@@ -229,6 +229,11 @@ app.on('ready', function() {
}
}
});
ipcMain.on('update-title', function(event, arg) {
mainWindow.setTitle(arg.title);
});
if (shouldShowTrayIcon()) {
// set up tray icon
trayIcon = new Tray(trayImages.normal);

View File

@@ -1,5 +1,9 @@
<html>
<head>
<title>Mattermost Desktop testing html</title>
</head>
<body>
<h1>window.open() test</h1>
<p>

View File

@@ -1,7 +1,8 @@
'use strict';
const path = require('path');
const fs = require('fs');
const http = require('http');
const path = require('path');
const env = require('../../modules/environment');
@@ -19,6 +20,17 @@ describe('browser/index.html', function() {
}]
};
const serverPort = 8181;
before(function() {
this.server = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end(fs.readFileSync(path.resolve(env.sourceRootDir, 'test/modules/test.html'), 'utf-8'));
}).listen(serverPort, '127.0.0.1');
});
beforeEach(function() {
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
this.app = env.getSpectronApp();
@@ -31,6 +43,10 @@ describe('browser/index.html', function() {
}
});
after(function(done) {
this.server.close(done);
})
it('should NOT show tabs when there is one team', function() {
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
@@ -78,4 +94,81 @@ describe('browser/index.html', function() {
.waitForVisible('#mattermostView0-fail', 20000)
});
});
it('should set window title by using webview\'s one', function() {
fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1,
teams: [{
name: 'title_test',
url: `http://localhost:${serverPort}`
}]
}));
return this.app.restart().then(() => {
return this.app.client.waitUntilWindowLoaded().pause(500);
})
.then(() => {
return this.app.browserWindow.getTitle().should.eventually.equal('Mattermost Desktop testing html');
});
});
it('should update window title when the activated tab\'s title is updated', function() {
fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1,
teams: [{
name: 'title_test_0',
url: `http://localhost:${serverPort}`
}, {
name: 'title_test_1',
url: `http://localhost:${serverPort}`
}]
}));
return this.app.restart().then(() => {
return this.app.client.waitUntilWindowLoaded().pause(500);
})
.then(() => {
return this.app.client
.windowByIndex(1)
.execute(function() {
document.title = 'Title 0';
})
.windowByIndex(0)
.browserWindow.getTitle().should.eventually.equal('Title 0')
.windowByIndex(2)
.execute(function() {
document.title = 'Title 1';
})
.windowByIndex(0)
.browserWindow.getTitle().should.eventually.equal('Title 0')
});
});
it('should update window title when a tab is selected', function() {
fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1,
teams: [{
name: 'title_test_0',
url: `http://localhost:${serverPort}`
}, {
name: 'title_test_1',
url: `http://localhost:${serverPort}`
}]
}));
return this.app.restart().then(() => {
return this.app.client
.waitUntilWindowLoaded()
.pause(500)
.windowByIndex(1)
.execute(function() {
document.title = 'Title 0';
})
.windowByIndex(2)
.execute(function() {
document.title = 'Title 1';
})
.windowByIndex(0)
.browserWindow.getTitle().should.eventually.equal('Title 0')
.click('#teamTabItem1')
.browserWindow.getTitle().should.eventually.equal('Title 1');
});
});
});