Merge pull request #240 from atom/friendly-default-app
Provide a friendly interface for opening an app
This commit is contained in:
commit
0d39249025
5 changed files with 134 additions and 46 deletions
|
@ -1,6 +1,4 @@
|
||||||
var app = require('app');
|
var app = require('app');
|
||||||
var dialog = require('dialog');
|
|
||||||
var ipc = require('ipc');
|
|
||||||
var Menu = require('menu');
|
var Menu = require('menu');
|
||||||
var MenuItem = require('menu-item');
|
var MenuItem = require('menu-item');
|
||||||
var BrowserWindow = require('browser-window');
|
var BrowserWindow = require('browser-window');
|
||||||
|
@ -13,30 +11,12 @@ app.on('window-all-closed', function() {
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('open-url', function(event, url) {
|
|
||||||
dialog.showMessageBox({message: url, buttons: ['OK']});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
app.commandLine.appendSwitch('js-flags', '--harmony_collections');
|
app.commandLine.appendSwitch('js-flags', '--harmony_collections');
|
||||||
|
|
||||||
mainWindow = new BrowserWindow({ width: 800, height: 600 });
|
mainWindow = new BrowserWindow({ width: 800, height: 600 });
|
||||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
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') {
|
if (process.platform == 'darwin') {
|
||||||
var template = [
|
var template = [
|
||||||
{
|
{
|
||||||
|
@ -117,16 +97,16 @@ app.on('ready', function() {
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
accelerator: 'Command+R',
|
accelerator: 'Command+R',
|
||||||
click: function() { BrowserWindow.getFocusedWindow().restart(); }
|
click: function() { mainWindow.restart(); }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Enter Fullscreen',
|
label: 'Enter Fullscreen',
|
||||||
click: function() { BrowserWindow.getFocusedWindow().setFullscreen(true); }
|
click: function() { mainWindow.setFullscreen(true); }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle DevTools',
|
label: 'Toggle DevTools',
|
||||||
accelerator: 'Alt+Command+I',
|
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);
|
menu = Menu.buildFromTemplate(template);
|
||||||
mainWindow.setMenu(menu);
|
mainWindow.setMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
ipc.on('message', function(processId, routingId, type) {
|
|
||||||
if (type == 'menu')
|
|
||||||
menu.popup(mainWindow);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,18 +1,127 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
|
||||||
<title>Atom Shell</title>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
This is the default mode of Atom Shell, please follow the instructions in
|
<script>
|
||||||
wiki to get started.
|
var execPath = require('remote').process.execPath;
|
||||||
<script type="text/javascript" charset="utf-8">
|
var command = execPath + ' path-to-your-app';
|
||||||
var ipc = require('ipc');
|
|
||||||
|
|
||||||
window.addEventListener('contextmenu', function (e) {
|
document.onclick = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
ipc.send('menu');
|
if (e.target.tagName == 'A')
|
||||||
}, false);
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var app = require('app');
|
var app = require('app');
|
||||||
|
var dialog = require('dialog');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var optimist = require('optimist');
|
var optimist = require('optimist');
|
||||||
|
|
||||||
|
@ -16,13 +17,15 @@ if (argv._.length > 0) {
|
||||||
try {
|
try {
|
||||||
require(path.resolve(argv._[0]));
|
require(path.resolve(argv._[0]));
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (e.code == 'MODULE_NOT_FOUND') {
|
app.focus();
|
||||||
console.error(e.stack);
|
dialog.showMessageBox({
|
||||||
console.error('Specified app is invalid');
|
type: 'warning',
|
||||||
process.exit(1);
|
buttons: ['OK'],
|
||||||
} else {
|
title: 'Error opening app',
|
||||||
throw e;
|
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) {
|
} else if (argv.version) {
|
||||||
console.log('v' + process.versions['atom-shell']);
|
console.log('v' + process.versions['atom-shell']);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "atom-shell-default-app",
|
"name": "atom-shell-default-app",
|
||||||
|
"productName": "Atom Shell Default App",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -15,11 +15,11 @@ describe 'app module', ->
|
||||||
|
|
||||||
describe 'app.getName()', ->
|
describe 'app.getName()', ->
|
||||||
it 'returns the name field of package.json', ->
|
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)', ->
|
describe 'app.setName(name)', ->
|
||||||
it 'overrides the 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'
|
app.setName 'test-name'
|
||||||
assert.equal app.getName(), 'test-name'
|
assert.equal app.getName(), 'test-name'
|
||||||
app.setName 'atom-shell-default-app'
|
app.setName 'Atom Shell Default App'
|
||||||
|
|
Loading…
Reference in a new issue