Merge pull request #240 from atom/friendly-default-app

Provide a friendly interface for opening an app
This commit is contained in:
Cheng Zhao 2014-05-05 17:04:14 +08:00
commit 0d39249025
5 changed files with 134 additions and 46 deletions

View file

@ -1,6 +1,4 @@
var app = require('app');
var dialog = require('dialog');
var ipc = require('ipc');
var Menu = require('menu');
var MenuItem = require('menu-item');
var BrowserWindow = require('browser-window');
@ -13,30 +11,12 @@ app.on('window-all-closed', function() {
app.quit();
});
app.on('open-url', function(event, url) {
dialog.showMessageBox({message: url, buttons: ['OK']});
});
app.on('ready', function() {
app.commandLine.appendSwitch('js-flags', '--harmony_collections');
mainWindow = new BrowserWindow({ width: 800, height: 600 });
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.on('page-title-updated', function(event, title) {
event.preventDefault();
this.setTitle('Atom Shell - ' + title);
});
mainWindow.on('closed', function() {
mainWindow = null;
});
mainWindow.on('unresponsive', function() {
console.log('unresponsive');
});
if (process.platform == 'darwin') {
var template = [
{
@ -117,16 +97,16 @@ app.on('ready', function() {
{
label: 'Reload',
accelerator: 'Command+R',
click: function() { BrowserWindow.getFocusedWindow().restart(); }
click: function() { mainWindow.restart(); }
},
{
label: 'Enter Fullscreen',
click: function() { BrowserWindow.getFocusedWindow().setFullscreen(true); }
click: function() { mainWindow.setFullscreen(true); }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); }
click: function() { mainWindow.toggleDevTools(); }
},
]
},
@ -196,9 +176,4 @@ app.on('ready', function() {
menu = Menu.buildFromTemplate(template);
mainWindow.setMenu(menu);
}
ipc.on('message', function(processId, routingId, type) {
if (type == 'menu')
menu.popup(mainWindow);
});
});

View file

@ -1,18 +1,127 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Atom Shell</title>
<style>
html {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
color: #555;
font-family: 'Open Sans',Helvetica,Arial,sans-serif;
padding: 30px;
}
h2 {
color: #2b6cc2;
font-family: "Crimson Text",Georgia,serif;
font-weight: 400;
line-height: 1.1;
letter-spacing: -0.015em;
}
a {
color: #2b6cc2;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
pre, code {
font-family: "Menlo","Lucida Console",monospace;
border: 1px solid #ddd;
background-color: #f8f8f8;
border-radius: 3px;
}
pre {
white-space: pre-wrap;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
}
#holder {
border: 4px dashed #ccc;
margin: 0 auto;
height: 300px;
color: #ccc;
font-size: 40px;
line-height: 300px;
text-align: center;
-webkit-user-select: none;
}
#holder.hover {
border: 4px dashed #999;
color: #eee;
}
</style>
</head>
<body>
This is the default mode of Atom Shell, please follow the instructions in
wiki to get started.
<script type="text/javascript" charset="utf-8">
var ipc = require('ipc');
<script>
var execPath = require('remote').process.execPath;
var command = execPath + ' path-to-your-app';
window.addEventListener('contextmenu', function (e) {
document.onclick = function(e) {
e.preventDefault();
ipc.send('menu');
}, false);
if (e.target.tagName == 'A')
require('shell').openExternal(e.target.href);
return false;
};
document.ondragover = document.ondrop = function(e) {
e.preventDefault();
return false;
};
</script>
<h2>Welcome to Atom Shell</h2>
<p>
To run your app with atom-shell, execute the following command under your
Console (or Terminal):
</p>
<script>document.write('<pre>' + command + '</pre>')</script>
<p>
The <code>path-to-your-app</code> should be the path to your own atom-shell
app, you can read the <a href='https://github.com/atom/atom-shell/blob/master/docs/tutorial/quick-start.md'>quick start</a>
guide in atom-shell's <a href='https://github.com/atom/atom-shell/blob/master/docs'>docs</a>
on how to write one.
</p>
<p>
Or you can just drag your app here to run it:
</p>
<div id="holder">
Drag your app here to run it
</div>
<script>
var holder = document.getElementById('holder');
holder.ondragover = function () {
this.className = 'hover';
return false;
};
holder.ondragleave = holder.ondragend = function () {
this.className = '';
return false;
};
holder.ondrop = function (e) {
this.className = '';
e.preventDefault();
var file = e.dataTransfer.files[0];
require('child_process').execFile(execPath, [file.path], {
detached: true, stdio: 'ignore'
}).unref();
return false;
};
</script>
</body>
</html>

View file

@ -1,4 +1,5 @@
var app = require('app');
var dialog = require('dialog');
var path = require('path');
var optimist = require('optimist');
@ -16,13 +17,15 @@ if (argv._.length > 0) {
try {
require(path.resolve(argv._[0]));
} catch(e) {
if (e.code == 'MODULE_NOT_FOUND') {
console.error(e.stack);
console.error('Specified app is invalid');
process.exit(1);
} else {
throw e;
}
app.focus();
dialog.showMessageBox({
type: 'warning',
buttons: ['OK'],
title: 'Error opening app',
message: 'The app provided is not a valid atom-shell app, please read the docs on how to write one:',
detail: 'https://github.com/atom/atom-shell/tree/master/docs'
});
process.exit(1);
}
} else if (argv.version) {
console.log('v' + process.versions['atom-shell']);

View file

@ -1,5 +1,6 @@
{
"name": "atom-shell-default-app",
"productName": "Atom Shell Default App",
"version": "0.1.0",
"main": "main.js",
"dependencies": {

View file

@ -15,11 +15,11 @@ describe 'app module', ->
describe 'app.getName()', ->
it 'returns the name field of package.json', ->
assert.equal app.getName(), 'atom-shell-default-app'
assert.equal app.getName(), 'Atom Shell Default App'
describe 'app.setName(name)', ->
it 'overrides the name', ->
assert.equal app.getName(), 'atom-shell-default-app'
assert.equal app.getName(), 'Atom Shell Default App'
app.setName 'test-name'
assert.equal app.getName(), 'test-name'
app.setName 'atom-shell-default-app'
app.setName 'Atom Shell Default App'