Skip to content

Commit

Permalink
1 个修复, 1 个新增,2 个优化
Browse files Browse the repository at this point in the history
修复:发布版 npm 模块的下载位置有误
新增:右键菜单-重启应用
优化:应用升级后的重启功能
优化:对话框输出信息的显示‘
  • Loading branch information
Alex committed Nov 24, 2017
1 parent fdcf519 commit 22ee985
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ GUI workflow for Front-End developers based on Electron
- 刷新:刷新页面
- 开发者工具:开启或关闭开发者工具
- 检查更新:检查是否有新版本
- 重启应用:刷新解决不了的问题就重启吧
- 在线更新:
- 打开应用后默认检查更新,右键菜单也可以点击检查更新
- 当 github 上存在更新的版本时,显示 **一键升级** 按钮
Expand Down
24 changes: 19 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
{
"name": "splice",
"version": "1.1.1",
"version": "1.1.2",
"manifest": [{
"version": "1.1.2",
"files": ["src/js/updater.js", "README.md", "src/css/style.css"],
"packages": [],
"logs": ["修复:发布版 npm 模块的下载位置有误", "新增:右键菜单-重启应用", "优化:应用升级后的重启功能", "优化:对话框输出信息的显示"]
}, {
"version": "1.1.1",
"files": ["src/js/index.js", "src/js/modules.js", "src/js/workflow.js", "src/main.js"],
"packages": ["gulp-base64"],
"logs": ["css 新增功能:图片转 base64"]
"files": [
"src/js/index.js",
"src/js/modules.js",
"src/js/workflow.js",
"src/main.js"
],
"packages": [
"gulp-base64"
],
"logs": [
"css 新增功能:图片转 base64"
]
}],
"description": "GUI workflow for Front-End developers based on Electron",
"main": "src/main.js",
Expand Down Expand Up @@ -92,4 +106,4 @@
"last 10 versions",
"not ie <= 8"
]
}
}
15 changes: 13 additions & 2 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@
position: fixed;
right: 16px;
background-color: #fff;
box-shadow: 0 2px 4px rgba(0,0,0,.12),0 0 6px rgba(0,0,0,.04);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32),0 0 6px rgba(0,0,0,.04);
border: 1px solid rgba(0, 0, 0, 0.12);
transition: opacity .3s,transform .3s,right .3s,top .4s;
overflow: hidden;
opacity: 0;
Expand Down Expand Up @@ -608,11 +609,17 @@
margin: 0 auto;
}
.notification__dialog .notification__content {
height: 230px;
min-height: 150px;
max-height: 400px;
overflow-y: scroll;
margin: 16px -20px 0;
padding: 0 20px;
}
.notification__content pre {
/*换行*/
word-break: break-word;
white-space: pre-line;
}
.notification__footer {
text-align: center;
}
Expand All @@ -623,3 +630,7 @@
opacity: 1;
transition: all 250ms ease-out;
}
#dialogBtn {
margin-left: 50%;
transform: translateX(-50%);
}
43 changes: 29 additions & 14 deletions src/js/updater.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
var updater = {
// 重启应用
relaunch: function() {
remote.app.relaunch();
remote.app.exit(0);
},
// 右键菜单
contextmenu: function () {
var self = this;
var menu = new Menu();
Expand All @@ -23,6 +29,10 @@ var updater = {
self.updateDetect(self.app);
}
}));
menu.append(new MenuItem({
label: '重启应用',
click: self.relaunch
}));

window.addEventListener('contextmenu', function (event) {
event.preventDefault();
Expand Down Expand Up @@ -232,7 +242,7 @@ var updater = {
}
}
document.getElementById('dialogBtn').addEventListener('click', function(e) {
location.reload();
self.relaunch();
});
var done = function(progress, autoload, content) {
console.log('progress is', progress);
Expand All @@ -245,17 +255,16 @@ var updater = {
// 升级成功,重载中...
// 提示信息
btnTxt('升级成功,重载中...')
location.reload();
self.relaunch();
}, 3000);
} else {
if (content) {app.dialogTitle = '模块安装提示';
app.dialogContent = content;
app.showDialogBtn = true;
app.dialogBtn = '重启应用';
app.showDialog = true;

} else {
location.reload();
self.relaunch();
}
}
}
Expand Down Expand Up @@ -472,21 +481,22 @@ var updater = {

// 安装新增模块
if (packages.length > 0) {
console.log('需要安装新模块');
console.log('需要安装新模块:' + packages.join(','));
self.install(packages, function(stdout, stderr) {
console.log('stdout, stderr', stdout, stderr);
// showMsg(`<b>执行 npm install 安装新增模块时输出如下</b>:
// ${stdout}
// ${stderr}
// <b>如有问题,请自行在应用根目录安装如下模块</b>:
// ${packages.join(', ')}`);
let content = `<b>如有问题,请自行在应用根目录安装新增的 npm 模块</b>:
${packages.join(', ')}
let content = `<b>如重启后使用有问题,请自行在应用根目录(.../resources/app/)安装新增的 npm 模块</b>:
<span style="color: red;">${packages.join(', ')}</span>
<br/>
<br/>
<b>执行 npm install 安装新增模块时输出如下</b>:
<br/>
${stdout}
${stderr}
<pre>${stdout}
${stderr}</pre>
`;
// 确认信息后点击重启应用
done(progress, false, content);
Expand All @@ -496,12 +506,13 @@ var updater = {
// ${error}
// <b>请自行在应用根目录安装如下模块</b>:
// ${packages.join(', ')}`);
let content = `<b>请自行在应用根目录安装新增的 npm 模块</b>:
${packages.join(', ')}
let content = `<b>请自行在应用根目录(.../resources/app/)安装新增的 npm 模块</b>:
<span style="color: red;">${packages.join(', ')}</span>
<br/>
<br/>
<b>执行 npm install 安装新增模块时出错</b>:
<br/>
${error}
<pre>${error}</pre>
`;
// 确认信息后点击重启应用
done(progress, false, content);
Expand Down Expand Up @@ -531,8 +542,12 @@ var updater = {
success = success || function() {};
fail = fail || function() {};

let cmd = `npm i -S ${packages.join(' ')}`;
exec(cmd, function(error, stdout, stderr) {
// __dirname 是项目运行时入口文件所在的文件夹
let folder = path.join(__dirname, '../');
let cmd = `npm i -S ${packages.join(' ')} --prefix ./`;
exec(cmd, {
cwd: folder
}, function(error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
fail(error);
Expand Down

0 comments on commit 22ee985

Please sign in to comment.