博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
appjs desktop2
阅读量:4455 次
发布时间:2019-06-07

本文共 4468 字,大约阅读时间需要 14 分钟。

var express = require('express');

var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');

var users = require('./routes/users');

var appRouter = express();

// view engine setup

appRouter.set('views', path.join(__dirname, 'views'));
appRouter.set('view engine', 'jade');

// uncomment after placing your favicon in /public

//appRouter.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
appRouter.use(logger('dev'));
appRouter.use(bodyParser.json());
appRouter.use(bodyParser.urlencoded({ extended: false }));
appRouter.use(cookieParser());
appRouter.use(express.static(path.join(__dirname, 'public')));

appRouter.use('/', routes);

appRouter.use('/users', users);

// catch 404 and forward to error handler

appRouter.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler

// will print stacktrace
if (appRouter.get('env') === 'development') {
appRouter.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler

// no stacktraces leaked to user
appRouter.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
appRouter.listen(3000,function(){
console.log("sss");
})

var app = module.exports = require('appjs');

app.serveFilesFrom(__dirname + '/content');

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();
}
}
]
}]);

menubar.on('select',function(item){

console.log("menu item "+item.label+" clicked");
});

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 window = app.createWindow('http://localhost:3000/',{

width : 640,
height : 460,
icons : __dirname + '/content/icons'
});
/*
var window = appjs.createWindow('http://localhost:23453/', {
width : 640,
height: 460,
icons : __dirname + '/content/icons'
});
var http = require('http');
server = http.createServer(function (req, res) {
res.writeHeader(200, {"Content-Type": "text/plain"});
res.end("Hello oschina\n");
})
server.listen(8000);
console.log("httpd start @8000");
var window = app.createWindow({
width : 1024,
height : 768,
icons : __dirname + '/content/icons',
showChrome : false,
alpha: true,
autoResize: false,
resizable: true,
margin: 0
/***************************** defaults ********************************
* url : 'http://appjs', // serve static file root and routers
* autoResize : false, // resizes in response to html content
* showChrome : true, // show border and title bar
* resizable : false, // control if users can resize window
* disableSecurity: true, // allow cross origin requests
* opacity : 1, // flat percent opacity for window
* alpha : false, // per-pixel alpha blended (Win & Mac)
* fullscreen : false, // client area covers whole screen
* left : -1, // centered by default
* top : -1, // centered by default

});*************************************************************************/
window.on('create', function(){
console.log("Window Created");
window.frame.show();
window.frame.center();
window.frame.setMenuBar(menubar);
});

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");
});

 

转载于:https://www.cnblogs.com/jayruan/p/5184620.html

你可能感兴趣的文章
I Hate It
查看>>
usaco 2.1 sort3...想法题...
查看>>
【转】算法的流程图表示
查看>>
jquery .filter()过滤器
查看>>
视图中增加一个自动增加的字段
查看>>
基于axis2的webservice和android简单的本地数据交互(上)
查看>>
[.Net Core] 简单使用 Mvc 内置的 Ioc
查看>>
ef 多条数据插入处理方案(据说还有更好的)
查看>>
BigDecimal 学习比较
查看>>
反演+分块套分块——bzoj2154
查看>>
任务调度~Quartz.net实现简单的任务调试
查看>>
第三次作业——for 语句及分支结构else-if
查看>>
央行紧急通知:你在用的这种支付方式将有重大变化
查看>>
数据库SQL语句学习--view
查看>>
Balsamiq Mockups
查看>>
分区表损坏后的重建
查看>>
HTML一些 标签
查看>>
Eclipse 导入外部项目无法识别为web项目并且无法在部署到tomcat下
查看>>
Java基础知识总结
查看>>
Java并发包中线程池ThreadPoolExecutor原理探究
查看>>