Merge branch 'better-dev-mode'

This commit is contained in:
Yuya Ochiai
2017-03-08 20:17:51 +09:00
20 changed files with 117 additions and 201 deletions

View File

@@ -1,6 +1,6 @@
const React = require('react');
const {findDOMNode} = require('react-dom');
const {ipcRenderer, shell} = require('electron');
const {ipcRenderer, remote, shell} = require('electron');
const fs = require('fs');
const url = require('url');
const osLocale = require('os-locale');
@@ -8,6 +8,8 @@ const electronContextMenu = require('electron-context-menu');
const ErrorView = require('./ErrorView.jsx');
const preloadJS = `file://${remote.app.getAppPath()}/browser/webview/mattermost_bundle.js`;
const MattermostView = React.createClass({
propTypes: {
disablewebsecurity: React.PropTypes.bool,
@@ -98,7 +100,7 @@ const MattermostView = React.createClass({
osLocale().then((locale) => {
if (locale === 'ja_JP') {
applyCssFile(__dirname + '/css/jp_fonts.css');
applyCssFile(remote.app.getAppPath() + '/css/jp_fonts.css');
}
});
}
@@ -228,7 +230,7 @@ const MattermostView = React.createClass({
id={this.props.id}
className='mattermostView'
style={this.props.style}
preload='webview/mattermost.js'
preload={preloadJS}
src={this.props.src}
ref='webview'
nodeintegration='false'

View File

@@ -18,7 +18,8 @@ const appLauncher = new AutoLaunch({
function backToIndex(index) {
const target = typeof index === 'undefined' ? 0 : index;
remote.getCurrentWindow().loadURL(`file://${__dirname}/index.html?index=${target}`);
const indexURL = remote.getGlobal('isDev') ? 'http://localhost:8080/browser/index.html' : `file://${remote.app.getAppPath()}/browser/index.html`;
remote.getCurrentWindow().loadURL(`${indexURL}?index=${target}`);
}
const SettingsPage = React.createClass({

View File

@@ -3,13 +3,13 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="modules/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<div id="content"></div>
<script src="index.js"></script>
<script src="index_bundle.js"></script>
</body>
</html>

View File

@@ -103,3 +103,8 @@ ReactDOM.render(
/>,
document.getElementById('content')
);
// Deny drag&drop navigation in mainWindow.
// Drag&drop is allowed in webview of index.html.
document.addEventListener('dragover', (event) => event.preventDefault());
document.addEventListener('drop', (event) => event.preventDefault());

View File

@@ -4,14 +4,14 @@
<head>
<meta charset="UTF-8">
<title>Settings</title>
<link rel="stylesheet" href="modules/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/settings.css">
</head>
<body>
<div id="content"></div>
<script src="settings.js"></script>
<script src="settings_bundle.js"></script>
</body>
</html>

View File

@@ -20,3 +20,7 @@ ReactDOM.render(
<SettingsPage configFile={configFile}/>,
document.getElementById('content')
);
// Deny drag&drop navigation in mainWindow.
document.addEventListener('dragover', (event) => event.preventDefault());
document.addEventListener('drop', (event) => event.preventDefault());

View File

@@ -11,6 +11,8 @@ const {
systemPreferences,
session
} = require('electron');
const isDev = require('electron-is-dev');
const installExtension = require('electron-devtools-installer');
const AutoLaunch = require('auto-launch');
@@ -70,15 +72,6 @@ var mainWindow = null;
var argv = require('yargs').parse(process.argv.slice(1));
const electronConnect = argv.livereload ? require('electron-connect') : null;
var client;
if (argv.livereload) {
client = electronConnect.client.create();
client.on('reload', () => {
mainWindow.reload();
});
}
var hideOnStartup;
if (argv.hidden) {
hideOnStartup = true;
@@ -88,6 +81,8 @@ if (argv['data-dir']) {
app.setPath('userData', path.resolve(argv['data-dir']));
}
global.isDev = isDev && !argv.disableDevMode;
var config = {};
try {
const configFile = app.getPath('userData') + '/config.json';
@@ -315,6 +310,12 @@ app.on('ready', () => {
if (willAppQuit) {
return;
}
if (global.isDev) {
installExtension.default(installExtension.REACT_DEVELOPER_TOOLS).
then((name) => console.log(`Added Extension: ${name}`)).
catch((err) => console.log('An error occurred: ', err));
}
ipcMain.on('notified', () => {
if (process.platform === 'win32' || process.platform === 'linux') {
if (config.notifications.flashWindow === 2) {
@@ -483,16 +484,17 @@ app.on('ready', () => {
}
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/browser/index.html');
const indexURL = global.isDev ? 'http://localhost:8080/browser/index.html' : `file://${app.getAppPath()}/browser/index.html`;
mainWindow.loadURL(indexURL);
// Set application menu
ipcMain.on('update-menu', (event, configData) => {
var aMenu = appMenu.createMenu(mainWindow, configData);
var aMenu = appMenu.createMenu(mainWindow, configData, global.isDev);
Menu.setApplicationMenu(aMenu);
// set up context menu for tray icon
if (shouldShowTrayIcon()) {
const tMenu = trayMenu.createMenu(mainWindow, configData);
const tMenu = trayMenu.createMenu(mainWindow, configData, global.isDev);
trayIcon.setContextMenu(tMenu);
if (process.platform === 'darwin' || process.platform === 'linux') {
// store the information, if the tray was initialized, for checking in the settings, if the application
@@ -565,18 +567,4 @@ app.on('ready', () => {
// when you should delete the corresponding element.
mainWindow = null;
});
// Deny drag&drop navigation in mainWindow.
// Drag&drop is allowed in webview of index.html.
mainWindow.webContents.on('will-navigate', (event, url) => {
var dirname = __dirname;
if (process.platform === 'win32') {
dirname = '/' + dirname.replace(/\\/g, '/');
}
var index = url.indexOf('file://' + dirname);
if (index !== 0) {
event.preventDefault();
}
});
});

View File

@@ -3,7 +3,9 @@
const electron = require('electron');
const Menu = electron.Menu;
function createTemplate(mainWindow, config) {
function createTemplate(mainWindow, config, isDev) {
const settingsURL = isDev ? 'http://localhost:8080/browser/settings.html' : `file://${electron.app.getAppPath()}/browser/settings.html`;
const separatorItem = {
type: 'separator'
};
@@ -25,7 +27,7 @@ function createTemplate(mainWindow, config) {
label: 'Preferences...',
accelerator: 'CmdOrCtrl+,',
click() {
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
mainWindow.loadURL(settingsURL);
}
}, {
label: 'Sign in to Another Server',
@@ -44,7 +46,7 @@ function createTemplate(mainWindow, config) {
label: 'Settings...',
accelerator: 'CmdOrCtrl+,',
click() {
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
mainWindow.loadURL(settingsURL);
}
}, {
label: 'Sign in to Another Server',
@@ -217,8 +219,8 @@ function createTemplate(mainWindow, config) {
return template;
}
function createMenu(mainWindow, config) {
return Menu.buildFromTemplate(createTemplate(mainWindow, config));
function createMenu(mainWindow, config, isDev) {
return Menu.buildFromTemplate(createTemplate(mainWindow, config, isDev));
}
module.exports = {

View File

@@ -5,7 +5,8 @@ const {
Menu
} = require('electron');
function createTemplate(mainWindow, config) {
function createTemplate(mainWindow, config, isDev) {
const settingsURL = isDev ? 'http://localhost:8080/browser/settings.html' : `file://${app.getAppPath()}/browser/settings.html`;
var template = [
...config.teams.slice(0, 9).map((team, i) => {
return {
@@ -25,7 +26,7 @@ function createTemplate(mainWindow, config) {
}, {
label: process.platform === 'darwin' ? 'Preferences...' : 'Settings',
click: () => {
mainWindow.loadURL('file://' + __dirname + '/browser/settings.html');
mainWindow.loadURL(settingsURL);
showOrRestore(mainWindow);
if (process.platform === 'darwin') {
@@ -42,8 +43,8 @@ function createTemplate(mainWindow, config) {
return template;
}
function createMenu(mainWindow, config) {
return Menu.buildFromTemplate(createTemplate(mainWindow, config));
function createMenu(mainWindow, config, isDev) {
return Menu.buildFromTemplate(createTemplate(mainWindow, config, isDev));
}
function showOrRestore(window) {

View File

@@ -4,20 +4,19 @@
"desktopName": "Mattermost.desktop",
"version": "3.6.0",
"description": "Mattermost",
"main": "main.js",
"main": "main_bundle.js",
"author": {
"name": "Yuya Ochiai",
"email": "yuya0321@gmail.com"
},
"homepage": "https://about.mattermost.com",
"license": "Apache-2.0",
"devDependencies": {
"electron-connect": "^0.6.1"
},
"dependencies": {
"auto-launch": "^5.0.1",
"bootstrap": "^3.3.7",
"electron-context-menu": "^0.8.0",
"electron-devtools-installer": "^2.1.0",
"electron-is-dev": "^0.1.2",
"electron-squirrel-startup": "^1.0.0",
"os-locale": "^2.0.0",
"react": "^15.4.2",