mirror of https://github.com/docker/docs.git
Merge pull request #228 from kitematic/refactor-es6
Refactor web-specific hooks to Webutils
This commit is contained in:
commit
cf50c7b1a1
|
|
@ -44,10 +44,10 @@ gulp.task('js', function () {
|
|||
gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.message));
|
||||
this.emit('end');
|
||||
}))
|
||||
.pipe(gulpif(options.dev, sourcemaps.init()))
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(react())
|
||||
.pipe(babel({blacklist: ['regenerator']}))
|
||||
.pipe(gulpif(options.dev, sourcemaps.write('.')))
|
||||
.pipe(sourcemaps.write())
|
||||
.pipe(gulp.dest(options.dev ? './build' : './dist/osx/' + options.appFilename + '/Contents/Resources/app/build'))
|
||||
.pipe(gulpif(options.dev, livereload()));
|
||||
});
|
||||
|
|
@ -102,7 +102,6 @@ gulp.task('dist', function () {
|
|||
'mv ./dist/osx/<%= filename %>/Contents/MacOS/Atom ./dist/osx/<%= filename %>/Contents/MacOS/<%= name %>',
|
||||
'mkdir -p ./dist/osx/<%= filename %>/Contents/Resources/app',
|
||||
'mkdir -p ./dist/osx/<%= filename %>/Contents/Resources/app/node_modules',
|
||||
'cp -R browser dist/osx/<%= filename %>/Contents/Resources/app',
|
||||
'cp package.json dist/osx/<%= filename %>/Contents/Resources/app/',
|
||||
'mkdir -p dist/osx/<%= filename %>/Contents/Resources/app/resources',
|
||||
'cp -v resources/* dist/osx/<%= filename %>/Contents/Resources/app/resources/ || :',
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"author": "Kitematic",
|
||||
"description": "Simple Docker Container management for Mac OS X.",
|
||||
"homepage": "https://kitematic.com/",
|
||||
"main": "browser/main.js",
|
||||
"main": "build/browser.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:kitematic/kitematic.git"
|
||||
|
|
|
|||
|
|
@ -37,12 +37,10 @@ var Containers = React.createClass({
|
|||
this.transitionTo('containerHome', {name: this.state.sorted[0].Name});
|
||||
}
|
||||
|
||||
ipc.on('notify', message => {
|
||||
if (message === 'application:update-available') {
|
||||
this.setState({
|
||||
updateAvailable: true
|
||||
});
|
||||
}
|
||||
ipc.on('application:update-available', () => {
|
||||
this.setState({
|
||||
updateAvailable: true
|
||||
});
|
||||
});
|
||||
autoUpdater.checkForUpdates();
|
||||
},
|
||||
|
|
@ -102,7 +100,7 @@ var Containers = React.createClass({
|
|||
},
|
||||
handleAutoUpdateClick: function () {
|
||||
metrics.track('Restarted to Update');
|
||||
ipc.send('command', 'application:quit-install');
|
||||
ipc.send('application:quit-install');
|
||||
},
|
||||
handleClickPreferences: function () {
|
||||
metrics.track('Opened Preferences', {
|
||||
|
|
|
|||
92
src/Main.js
92
src/Main.js
|
|
@ -1,87 +1,24 @@
|
|||
var remote = require('remote');
|
||||
require.main.paths.splice(0, 0, process.env.NODE_PATH);
|
||||
var app = remote.require('app');
|
||||
var bugsnag = require('bugsnag-js');
|
||||
var remote = require('remote');
|
||||
var ContainerStore = require('./ContainerStore');
|
||||
var fs = require('fs');
|
||||
var ipc = require('ipc');
|
||||
var Menu = remote.require('menu');
|
||||
var metrics = require('./Metrics');
|
||||
var path = require('path');
|
||||
var React = require('react');
|
||||
var router = require('./Router');
|
||||
var SetupStore = require('./SetupStore');
|
||||
var template = require('./MenuTemplate');
|
||||
var util = require('./Util');
|
||||
var bugsnag = require('bugsnag-js');
|
||||
var ipc = require('ipc');
|
||||
var machine = require('./DockerMachine');
|
||||
var metrics = require('./Metrics');
|
||||
var router = require('./Router');
|
||||
var template = require('./MenuTemplate');
|
||||
var webUtil = require('./WebUtil');
|
||||
|
||||
window.addEventListener('resize', function () {
|
||||
fs.writeFileSync(path.join(util.supportDir(), 'size'), JSON.stringify({
|
||||
width: window.outerWidth,
|
||||
height: window.outerHeight
|
||||
}));
|
||||
});
|
||||
webUtil.addWindowSizeSaving();
|
||||
webUtil.addLiveReload();
|
||||
webUtil.addBugReporting();
|
||||
webUtil.disableGlobalBackspace();
|
||||
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(template()));
|
||||
|
||||
var settingsjson;
|
||||
try {
|
||||
settingsjson = require(path.join(__dirname, '..', 'settings.json'), 'utf8');
|
||||
} catch (err) {
|
||||
settingsjson = {};
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = 'http://localhost:35729/livereload.js';
|
||||
head.appendChild(script);
|
||||
}
|
||||
|
||||
if (settingsjson.bugsnag) {
|
||||
bugsnag.apiKey = settingsjson.bugsnag;
|
||||
bugsnag.autoNotify = true;
|
||||
bugsnag.releaseStage = process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
||||
bugsnag.notifyReleaseStages = ['production'];
|
||||
bugsnag.appVersion = app.getVersion();
|
||||
bugsnag.metaData = {
|
||||
beta: !!settingsjson.beta
|
||||
};
|
||||
|
||||
bugsnag.beforeNotify = function(payload) {
|
||||
var re = new RegExp(util.home().replace(/\s+/g, '\\s+'), 'g');
|
||||
payload.stacktrace = payload.stacktrace.replace(/%20/g, ' ').replace(re, '<redacted homedir>');
|
||||
payload.context = payload.context.replace(/%20/g, ' ').replace(re, '<redacted homedir>');
|
||||
payload.file = payload.file.replace(/%20/g, ' ').replace(re, '<redacted homedir>');
|
||||
payload.url = '<redacted url>';
|
||||
};
|
||||
}
|
||||
|
||||
document.onkeydown = function (e) {
|
||||
e = e || window.event;
|
||||
var doPrevent;
|
||||
if (e.keyCode === 8) {
|
||||
var d = e.srcElement || e.target;
|
||||
if (d.tagName.toUpperCase() === 'INPUT' || d.tagName.toUpperCase() === 'TEXTAREA') {
|
||||
doPrevent = d.readOnly || d.disabled;
|
||||
} else {
|
||||
doPrevent = true;
|
||||
}
|
||||
} else {
|
||||
doPrevent = false;
|
||||
}
|
||||
if (doPrevent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
ipc.on('notify', msg => {
|
||||
if (msg === 'application:quitting' && localStorage.getItem('settings.closeVMOnQuit') === 'true') {
|
||||
machine.stop();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.track('Started App');
|
||||
metrics.track('app heartbeat');
|
||||
setInterval(function () {
|
||||
|
|
@ -89,6 +26,7 @@ setInterval(function () {
|
|||
}, 14400000);
|
||||
|
||||
router.run(Handler => React.render(<Handler/>, document.body));
|
||||
|
||||
SetupStore.setup().then(() => {
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(template()));
|
||||
ContainerStore.on(ContainerStore.SERVER_ERROR_EVENT, (err) => {
|
||||
|
|
@ -107,3 +45,9 @@ SetupStore.setup().then(() => {
|
|||
error: err
|
||||
});
|
||||
});
|
||||
|
||||
ipc.on('application:quitting', () => {
|
||||
if (localStorage.getItem('settings.closeVMOnQuit') === 'true') {
|
||||
machine.stop();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,5 +37,12 @@ module.exports = {
|
|||
packagejson: function () {
|
||||
return JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
||||
},
|
||||
settingsjson: function () {
|
||||
var settingsjson = {};
|
||||
try {
|
||||
settingsjson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'settings.json'), 'utf8'));
|
||||
} catch (err) {}
|
||||
return settingsjson;
|
||||
},
|
||||
webPorts: ['80', '8000', '8080', '3000', '5000', '2368', '9200', '8983']
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
var app = require('remote').require('app');
|
||||
var fs = require('fs');
|
||||
var util = require('./Util');
|
||||
var path = require('path');
|
||||
var bugsnag = require('bugsnag-js');
|
||||
|
||||
var WebUtil = {
|
||||
addWindowSizeSaving: function () {
|
||||
window.addEventListener('resize', function () {
|
||||
fs.writeFileSync(path.join(util.supportDir(), 'size'), JSON.stringify({
|
||||
width: window.outerWidth,
|
||||
height: window.outerHeight
|
||||
}));
|
||||
});
|
||||
},
|
||||
addLiveReload: function () {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = 'http://localhost:35729/livereload.js';
|
||||
head.appendChild(script);
|
||||
}
|
||||
},
|
||||
addBugReporting: function () {
|
||||
var settingsjson = util.settingsjson();
|
||||
if (settingsjson.bugsnag) {
|
||||
bugsnag.apiKey = settingsjson.bugsnag;
|
||||
bugsnag.autoNotify = true;
|
||||
bugsnag.releaseStage = process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
||||
bugsnag.notifyReleaseStages = ['production'];
|
||||
bugsnag.appVersion = app.getVersion();
|
||||
bugsnag.metaData = {
|
||||
beta: !!settingsjson.beta
|
||||
};
|
||||
|
||||
bugsnag.beforeNotify = function(payload) {
|
||||
var re = new RegExp(util.home().replace(/\s+/g, '\\s+'), 'g');
|
||||
payload.stacktrace = payload.stacktrace.replace(/%20/g, ' ').replace(re, '<redacted homedir>');
|
||||
payload.context = payload.context.replace(/%20/g, ' ').replace(re, '<redacted homedir>');
|
||||
payload.file = payload.file.replace(/%20/g, ' ').replace(re, '<redacted homedir>');
|
||||
payload.url = '<redacted url>';
|
||||
};
|
||||
}
|
||||
},
|
||||
disableGlobalBackspace: function () {
|
||||
document.onkeydown = function (e) {
|
||||
e = e || window.event;
|
||||
var doPrevent;
|
||||
if (e.keyCode === 8) {
|
||||
var d = e.srcElement || e.target;
|
||||
if (d.tagName.toUpperCase() === 'INPUT' || d.tagName.toUpperCase() === 'TEXTAREA') {
|
||||
doPrevent = d.readOnly || d.disabled;
|
||||
} else {
|
||||
doPrevent = true;
|
||||
}
|
||||
} else {
|
||||
doPrevent = false;
|
||||
}
|
||||
if (doPrevent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = WebUtil;
|
||||
|
|
@ -5,21 +5,20 @@ var fs = require('fs');
|
|||
var ipc = require('ipc');
|
||||
var path = require('path');
|
||||
|
||||
process.env.NODE_PATH = __dirname + '/../node_modules';
|
||||
process.env.RESOURCES_PATH = __dirname + '/../resources';
|
||||
process.env.NODE_PATH = path.join(__dirname, '/../node_modules');
|
||||
process.env.RESOURCES_PATH = path.join(__dirname, '/../resources');
|
||||
process.chdir(path.join(__dirname, '..'));
|
||||
process.env.PATH = '/usr/local/bin:' + process.env.PATH;
|
||||
|
||||
var size = {}, settingsjson = {};
|
||||
try {
|
||||
var sizeFile = JSON.parse(fs.readFileSync(path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], 'Library', 'Application\ Support', 'Kitematic', 'size')));
|
||||
size = sizeFile;
|
||||
size = JSON.parse(fs.readFileSync(path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], 'Library', 'Application\ Support', 'Kitematic', 'size')));
|
||||
} catch (err) {}
|
||||
try {
|
||||
settingsjson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'settings.json'), 'utf8'));
|
||||
} catch (err) {}
|
||||
|
||||
app.on('ready', function() {
|
||||
app.on('ready', function () {
|
||||
var mainWindow = new BrowserWindow({
|
||||
width: size.width || 1000,
|
||||
height: size.height || 700,
|
||||
|
|
@ -29,6 +28,7 @@ app.on('ready', function() {
|
|||
frame: false,
|
||||
show: true
|
||||
});
|
||||
|
||||
mainWindow.loadUrl(path.normalize('file://' + path.join(__dirname, '..', 'build/index.html')));
|
||||
|
||||
app.on('activate-with-no-open-windows', function () {
|
||||
|
|
@ -39,13 +39,11 @@ app.on('ready', function() {
|
|||
});
|
||||
|
||||
app.on('before-quit', function () {
|
||||
mainWindow.webContents.send('notify', 'application:quitting');
|
||||
mainWindow.webContents.send('application:quitting');
|
||||
});
|
||||
|
||||
ipc.on('command', function (event, arg) {
|
||||
if (arg === 'application:quit-install') {
|
||||
autoUpdater.quitAndInstall();
|
||||
}
|
||||
ipc.on('application:quit-install', function () {
|
||||
autoUpdater.quitAndInstall();
|
||||
});
|
||||
|
||||
mainWindow.webContents.on('new-window', function (e) {
|
||||
|
|
@ -83,7 +81,7 @@ app.on('ready', function() {
|
|||
autoUpdater.on('update-downloaded', function (e, releaseNotes, releaseName, releaseDate, updateURL) {
|
||||
console.log('Update downloaded.');
|
||||
console.log(releaseNotes, releaseName, releaseDate, updateURL);
|
||||
mainWindow.webContents.send('notify', 'application:update-available');
|
||||
mainWindow.webContents.send('application:update-available');
|
||||
});
|
||||
|
||||
autoUpdater.on('error', function (e, error) {
|
||||
Loading…
Reference in New Issue