Skip to content

Commit

Permalink
Merge pull request #28 from antoor/v1.1-dev
Browse files Browse the repository at this point in the history
Update to v1.1.1
  • Loading branch information
antoor committed Mar 29, 2016
2 parents 4d6d559 + f31ec40 commit 1e1c7e6
Show file tree
Hide file tree
Showing 15 changed files with 920 additions and 80 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
## 2016/03

### /23
### /26
1. 文件管理双击:size < 100kb ? 编辑 : 下载
2. 调整 Custom 方式数据库部分代码 // 2-4:感谢[@Medicean](https://github.com/Medicean)
3. 添加 Shells 目录, 用于存放 shell 样本代码
4. 添加 `custom.jsp` 服务端样本代码

### /24
1. 文件管理双击文件进行编辑 //size < 100kb

### /23 (v1.1.0)
1. 优化数据处理截断算法

### /22
Expand Down Expand Up @@ -34,10 +43,8 @@
# 待做事项
* 数据高级搜索功能
* 数据库配置编辑功能
* 数据发包代理功能
* 在线检测/下载/安装更新
* 虚拟终端复制粘贴tab补全
* 文件管理双击文件进行编辑 //size < 1024kb
* 插件模块 //实时编写插件执行、UI以及各种操作API设计
* 扩展模块 //用于扩展一些高级的功能,懒人必备
* 代码重构
Expand Down
6 changes: 5 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

// 导入模块
const Cache = require('./modules/cache');
const Update = require('./modules/update');
const Menubar = require('./modules/menubar');
const Request = require('./modules/request');
const Database = require('./modules/database');
const Cache = require('./modules/cache');

// electron.crashReporter.start();

Expand Down Expand Up @@ -59,4 +60,7 @@ app
// 初始化缓存模块
new Cache(electron);

// 监听更新请求
new Update(electron);

});
99 changes: 53 additions & 46 deletions modules/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

'use strict';

// 读取package.json信息
const info = JSON.parse(
require('fs').readFileSync(require('path').join(__dirname, '../package.json'))
);

class Menubar {

constructor(electron, app, mainWindow) {
Expand All @@ -14,6 +19,7 @@ class Menubar {
Menu.setApplicationMenu(Menu.buildFromTemplate([]));
// 监听重载菜单事件
ipcMain.on('menubar', this.reload.bind(this));
ipcMain.on('quit', app.quit.bind(app));

this.electron = electron;
this.app = app;
Expand Down Expand Up @@ -95,8 +101,11 @@ class Menubar {
click: event.sender.send.bind(event.sender, 'menubar', 'tabbar-close')
}
]
}, {
// 调试
}
];
// 调试菜单
if (info['debug']) {
template.push({
label: LANG['debug']['title'],
submenu: [
{
Expand All @@ -109,51 +118,49 @@ class Menubar {
click: this.mainWindow.webContents.toggleDevTools.bind(this.mainWindow.webContents)
}
]
}
];
// OSX主菜单
// if (process.platform === 'darwin') {
template.unshift({
label: LANG['main']['title'],
submenu: [
{
label: LANG['main']['about'],
accelerator: 'Shift+CmdOrCtrl+I',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-about')
}, {
label: LANG['main']['language'],
accelerator: 'Shift+CmdOrCtrl+L',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-language')
}, {
label: LANG['main']['aproxy'],
accelerator: 'Shift+CmdOrCtrl+A',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-aproxy')
}, {
label: LANG['main']['update'],
accelerator: 'Shift+CmdOrCtrl+U',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-update')
}, {
type: 'separator'
}, {
label: LANG['main']['settings'],
accelerator: 'Shift+CmdOrCtrl+S',
click: event.sender.send.bind(event.sender, 'menubar', 'settings')
}, {
type: 'separator'
}, {
label: LANG['main']['plugin'],
accelerator: 'Shift+CmdOrCtrl+P',
click: event.sender.send.bind(event.sender, 'menubar', 'plugin')
}, {
type: 'separator'
}, {
label: LANG['main']['quit'],
accelerator: 'Command+Q',
click: this.app.quit.bind(this.app)
},
]
});
// };
};
// 主菜单
template.unshift({
label: LANG['main']['title'],
submenu: [
{
label: LANG['main']['about'],
accelerator: 'Shift+CmdOrCtrl+I',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-about')
}, {
label: LANG['main']['language'],
accelerator: 'Shift+CmdOrCtrl+L',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-language')
}, {
label: LANG['main']['aproxy'],
accelerator: 'Shift+CmdOrCtrl+A',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-aproxy')
}, {
label: LANG['main']['update'],
accelerator: 'Shift+CmdOrCtrl+U',
click: event.sender.send.bind(event.sender, 'menubar', 'settings-update')
}, {
type: 'separator'
}, {
label: LANG['main']['settings'],
accelerator: 'Shift+CmdOrCtrl+S',
click: event.sender.send.bind(event.sender, 'menubar', 'settings')
}, {
type: 'separator'
}, {
label: LANG['main']['plugin'],
accelerator: 'Shift+CmdOrCtrl+P',
click: event.sender.send.bind(event.sender, 'menubar', 'plugin')
}, {
type: 'separator'
}, {
label: LANG['main']['quit'],
accelerator: 'Command+Q',
click: this.app.quit.bind(this.app)
},
]
});
// 更新菜单栏
this.Menu.setApplicationMenu(this.Menu.buildFromTemplate(template));
}
Expand Down
118 changes: 118 additions & 0 deletions modules/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// 程序更新模块
//
/* 更新流程:
-------
1. 获取远程github上的package.json信息
2. 和本地版本进行判断,不一致则提示更新
3. 下载用户选择的更新源文件到临时目录`.antSword-{now}`
4. 替换程序中的`resources/app.asar`文件
5. 提示用户手动重启,关闭应用
*/

'use strict';

const os = require('os'),
fs = require('fs'),
path = require('path'),
unzip = require('extract-zip'),
crypto = require('crypto'),
nugget = require('nugget'),
logger = require('log4js').getLogger('Update'),
superagent = require('superagent');

class Update {

constructor(electron) {
const ipcMain = electron.ipcMain;
this.info = {};
ipcMain
.on('update-check', (event, arg) => {
this.check(arg['local_ver'], (hasUpdate, retVal) => {
logger.debug('check-result', hasUpdate, retVal);
event.sender.send('update-check', {
hasUpdate: hasUpdate,
retVal: retVal
});
});
})
.on('update-download', (event, source) => {
logger.debug('update-download', source);
const info = this.info['update'];
const downloadUrl = info['sources'][source];
this.download(downloadUrl, info['md5'], (done, retVal) => {
event.sender.send('update-download', {
done: done,
retVal: retVal
});
});
});
}

// 检查是否有更新
// 参数{localVer: 本地版本号, callback: 回调函数(是否有更新, 是?更新信息:错误信息)}
check(localVer, callback) {
logger.debug('check', localVer);
superagent
.get('https://raw.githubusercontent.com/antoor/antSword/master/package.json')
.timeout(9527)
.end((err, res) => {
if (err) { return callback(false, err.toString()) };
try {
const info = JSON.parse(res.text);
this.info = info;
callback(info['version'] !== localVer, info);
} catch (e) {
return callback(false, e.toString());
}
});
}

// 下载更新
// 参数{downloadUrl: 下载地址, md5: 校验MD5, callback: 回调(成功?(true, null):(false, err))}
download(downloadUrl, md5, callback) {
// 创建临时文件
const tmpDir = os.tmpDir();
const fileName = '.antSword-' + (+new Date);
const tmpFileName = path.join(tmpDir, fileName);
// 当前目录环境
const curDir = path.join(__dirname, '../../');
// 开始下载文件
nugget(
downloadUrl,
{
target: fileName,
dir: tmpDir,
resume: true,
verbose: true,
strictSSL: downloadUrl.startsWith('https')
},
(err) => {
if (err) { return callback(false, err.toString()) };
// 校验MD5
const _md5 = crypto.createHash('md5').update(fs.readFileSync(tmpFileName)).digest('hex');
if (_md5 !== md5) { return callback(false, { type: 'md5', err: _md5 }) };
// ZIP解压
unzip(tmpFileName, {
dir: tmpDir
}, (e) => {
if (e) { return (callback(false, { type: 'unzip', err: e })) };
// 删除旧asar
// fs.unlinkSync(path.join(curDir, 'app.asar'));
// 移动新asar
fs.rename(
path.join(tmpDir, 'antSword.update'),
path.join(curDir, 'app.asar'),
(_e) => {
_e ? callback(false, _e.toString()) : callback(true);
}
);
});
}
);
}


}

module.exports = Update;
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "antsword",
"version": "1.1.0",
"version": "1.1.1",
"description": "中国蚁剑是一款跨平台的开源网站管理工具",
"main": "app.js",
"dependencies": {
"babel-core": "^6.7.2",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"electron-prebuilt": "^0.36.10",
"electron-prebuilt": "^0.37.2",
"extract-zip": "^1.5.0",
"iconv-lite": "^0.4.13",
"lib-qqwry": "^0.0.5",
"log4js": "^0.6.29",
"nedb": "^1.5.1",
"nugget": "^2.0.0",
"superagent": "^1.6.1",
"superagent-proxy": "^1.0.0",
"webpack": "^1.12.14"
Expand All @@ -27,6 +29,12 @@
"type": "git",
"url": "https://github.com/antoor/antSword"
},
"debug": true,
"update": {
"md5": "",
"logs": "",
"sources": {}
},
"bugs": {
"url": "https://github.com/antoor/antSword/issues"
},
Expand Down
2 changes: 2 additions & 0 deletions shells/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Shell-Scripts
> 此目录用于存放一些示例的服务端脚本文件,仅供参考。
Loading

0 comments on commit 1e1c7e6

Please sign in to comment.