Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packaging support for appjs #239

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion binding.gyp
Expand Up @@ -32,12 +32,19 @@
'files': [
'<(module_root_dir)/node_modules/mime/',
]
},{
'destination': '<(module_root_dir)/app/data/node_modules/',
'files': [
'<(module_root_dir)/node_modules/appjs-package/',
]
},
{
'destination': '<(module_root_dir)/app/data/',
'files': [
'<(module_root_dir)/examples/hello-world/content/',
'<(module_root_dir)/examples/hello-world/app.js'
'<(module_root_dir)/examples/hello-world/app.js',
'<(module_root_dir)/examples/hello-world/package.json'

]
}
],
Expand Down
3 changes: 2 additions & 1 deletion data/linux/app.sh
@@ -1,3 +1,4 @@
#!/bin/sh

./data/bin/node --harmony ./data/app.js
DIR="$( cd "$( dirname "$0" )" && pwd )"
$DIR/data/bin/node --harmony $DIR/data/app.js $1
244 changes: 151 additions & 93 deletions examples/hello-world/app.js
@@ -1,104 +1,162 @@
var app = module.exports = require('appjs');
/**
* log any uncaught exceptions to disk in case user is not running from console.
*/
process.on('uncaughtException',function(e) {
require('fs').writeFile("error.log", e.message+"\n"+e.stack, function(err) {
if(err) {
console.log("error writing error log:",err);
} else {
console.log("uncaughtException:",e.stack);
}
});
});

app.serveFilesFrom(__dirname + '/content');
var fs = require('fs')
,path = require('path')
,app = require('appjs')
;

var menubar = app.createMenu([{
label:'&File',
submenu:[
{
label:'E&xit',
action: function(){
window.close();
}
}
]
},{
label:'&Window',
submenu:[
{
label:'Fullscreen',
action:function(item) {
window.frame.fullscreen();
console.log(item.label+" called.");
}
},
{
label:'Minimize',
action:function(){
window.frame.minimize();
}
},
{
label:'Maximize',
action:function(){
window.frame.maximize();
}
},{
label:''//separator
},{
label:'Restore',
action:function(){
window.frame.restore();
}
}
]
}]);
if (process.argv.length>2) {
var appPackage = require('appjs-package');
appPackage.getPackageInfo(process.argv[2],function(err,pInfo) {
if (err) throw err;
if (pInfo.router) {
//serve files using the package router.
app.router.use(pInfo.router);
}
app.readPackageFile = pInfo.readPackageFile;
//appPackage.launch(pInfo, app);
pInfo.readPackageFile(pInfo.launch,function(err,buffer) {
var path = require('path');
app.readPackageFile = pInfo.readPackageFile;
if (pInfo.isDir) {
app.serveFilesFrom(pInfo.path + '/content');
}
if (err) {
console.log("error:",err);
} else {
if (typeof iconsDir == "undefined") {
var iconsDir = __dirname + '/content/icons';
}

var olddir = __dirname;
if (pInfo.isPackage) {
__dirname = path.dirname(pInfo.path);
} else {
__dirname = path.dirname(pInfo.launch);
}
eval(buffer.toString());
__dirname = olddir;
}
});

});
} else {

menubar.on('select',function(item){
console.log("menu item "+item.label+" clicked");
});
var app = module.exports = require('appjs');
var iconsDir = __dirname + '/content/icons';
app.serveFilesFrom(__dirname + '/content');

var trayMenu = app.createMenu([{
label:'Show',
action:function(){
window.frame.show();
},
},{
label:'Minimize',
action:function(){
window.frame.hide();
}
},{
label:'Exit',
action:function(){
window.close();
}
}]);

var statusIcon = app.createStatusIcon({
icon:'./data/content/icons/32.png',
tooltip:'AppJS Hello World',
menu:trayMenu
});
var menubar = app.createMenu([{
label:'&File',
submenu:[
{
label:'E&xit',
action: function(){
window.close();
}
}
]
},{
label:'&Window',
submenu:[
{
label:'Fullscreen',
action:function(item) {
window.frame.fullscreen();
console.log(item.label+" called.");
}
},
{
label:'Minimize',
action:function(){
window.frame.minimize();
}
},
{
label:'Maximize',
action:function(){
window.frame.maximize();
}
},{
label:''//separator
},{
label:'Restore',
action:function(){
window.frame.restore();
}
}
]
}]);

var window = app.createWindow({
width : 640,
height : 460,
icons : __dirname + '/content/icons'
});
menubar.on('select',function(item){
console.log("menu item "+item.label+" clicked");
});

window.on('create', function(){
console.log("Window Created");
window.frame.show();
window.frame.center();
window.frame.setMenuBar(menubar);
});
var trayMenu = app.createMenu([{
label:'Show',
action:function(){
window.frame.show();
},
},{
label:'Minimize',
action:function(){
window.frame.hide();
}
},{
label:'Exit',
action:function(){
window.close();
}
}]);

window.on('ready', function(){
console.log("Window Ready");
window.process = process;
window.module = module;
var statusIcon = app.createStatusIcon({
icon:iconsDir+'/32.png',
tooltip:'AppJS Hello World',
menu:trayMenu
});

function F12(e){ return e.keyIdentifier === 'F12' }
function Command_Option_J(e){ return e.keyCode === 74 && e.metaKey && e.altKey }
var window = app.createWindow({
width : 640,
height : 460,
icons : iconsDir
});

window.addEventListener('keydown', function(e){
if (F12(e) || Command_Option_J(e)) {
window.frame.openDevTools();
}
});
});
window.on('create', function(){
console.log("Window Created");
window.frame.show();
window.frame.center();
window.frame.setMenuBar(menubar);
});

window.on('close', function(){
console.log("Window Closed");
});
window.on('ready', function(){
console.log("Window Ready");
window.process = process;
window.module = module;

function F12(e){ return e.keyIdentifier === 'F12' }
function Command_Option_J(e){ return e.keyCode === 74 && e.metaKey && e.altKey }

window.addEventListener('keydown', function(e){
if (F12(e) || Command_Option_J(e)) {
window.frame.openDevTools();
}
});
});

window.on('close', function(){
console.log("Window Closed");
});

}
35 changes: 35 additions & 0 deletions examples/hello-world/package.json
@@ -0,0 +1,35 @@
{
"name": "appjs-runtime",
"version": 0.1,
"moduleUrl": "http://appjs.delightfulsoftware.com/node_modules/",
"appUpdateUrl": "http://appjs.delightfulsoftware.com/example-apps/helloWorld.appjs",
"appdeps": {
"mime": {
"name": "mime",
"version": "1.2.5",
"platforms": {
"win32": "win32"
}
},
"appjs-win32": {
"name": "appjs-win32",
"version": "0.0.20",
"platforms": {
"win32": "win32"
}
},
"appjs": {
"name": "appjs",
"version": "0.0.20",
"platforms": {
"win32": "win32"
}
},"appjs-package": {
"name": "appjs-package",
"version": "0.1.14",
"platforms": {
"win32": "win32"
}
}
}
}