Skip to content

Commit 399a948

Browse files
committed
send
1 parent c605ac9 commit 399a948

File tree

4 files changed

+80
-13
lines changed

4 files changed

+80
-13
lines changed

assets/img/logo.png

17.1 KB
Loading

main.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ const BrowserWindow = electron.BrowserWindow;
66
const path = require('path');
77

88

9-
109
// Keep a global reference of the window object, if you don't, the window will
1110
// be closed automatically when the JavaScript object is garbage collected.
1211
let mainWindow;
1312
let logo = path.join(__dirname, 'assets/img/WeFlow.png');
1413

14+
let willClose = false;
15+
1516
function createWindow() {
1617
// Create the browser window.
1718
mainWindow = new BrowserWindow({
@@ -26,7 +27,14 @@ function createWindow() {
2627
mainWindow.loadURL('file://' + __dirname + '/app.html');
2728

2829
// Open the DevTools.
29-
//mainWindow.webContents.openDevTools();
30+
mainWindow.webContents.openDevTools();
31+
32+
mainWindow.on('close', function (event) {
33+
if(process.platform !== 'win32' && !willClose){
34+
app.hide();
35+
event.preventDefault();
36+
}
37+
});
3038

3139
// Emitted when the window is closed.
3240
mainWindow.on('closed', function () {
@@ -39,6 +47,7 @@ function createWindow() {
3947

4048
}
4149

50+
4251
// This method will be called when Electron has finished
4352
// initialization and is ready to create browser windows.
4453
app.on('ready', createWindow);
@@ -49,13 +58,23 @@ app.on('window-all-closed', function () {
4958
// to stay active until the user quits explicitly with Cmd + Q
5059
if (process.platform !== 'darwin') {
5160
app.quit();
61+
}else{
62+
// closeEmit = true;
63+
// app.hide();
5264
}
5365
});
5466

67+
app.on('before-quit', function(){
68+
willClose = true;
69+
});
70+
71+
5572
app.on('activate', function () {
5673
// On OS X it's common to re-create a window in the app when the
5774
// dock icon is clicked and there are no other windows open.
5875
if (mainWindow === null) {
5976
createWindow();
6077
}
78+
79+
app.show();
6180
});

src/_tasks/dist.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const lazyImageCSS = require('gulp-lazyimagecss'); // 自动为图片样式添
1616
const minifyCSS = require('gulp-cssnano');
1717
const imagemin = require('gulp-imagemin');
1818
const pngquant = require('imagemin-pngquant');
19-
//const tmtsprite = require('gulp-tmtsprite'); // 雪碧图合并
2019
const ejshelper = require('tmt-ejs-helper');
2120
const postcss = require('gulp-postcss'); // CSS 预处理
2221
const postcssPxtorem = require('postcss-pxtorem'); // 转换 px 为 rem
@@ -27,6 +26,12 @@ const RevAll = require('gulp-rev-all'); // reversion
2726
const revDel = require('gulp-rev-delete-original');
2827
const Common = require(path.join(__dirname, '../common'));
2928

29+
let tmtsprite;
30+
31+
if(Common.PLATFORM !== 'win32'){
32+
tmtsprite = require('gulp-tmtsprite'); // 雪碧图合并
33+
}
34+
3035
let webp = require(path.join(__dirname, './common/webp'));
3136
let changed = require(path.join(__dirname, './common/changed'))();
3237

@@ -107,7 +112,21 @@ function dist(projectPath, log, callback) {
107112
vfs.src(paths.src.less)
108113
.pipe(less())
109114
.pipe(lazyImageCSS({imagePath: lazyDir}))
110-
.pipe(vfs.dest(paths.tmp.css))
115+
.pipe(tmtsprite({margin: 4}))
116+
.pipe(gulpif(condition, vfs.dest(paths.tmp.sprite), vfs.dest(paths.tmp.css)))
117+
.on('data', function(){})
118+
.on('end', function () {
119+
console.log('compileLess success.');
120+
log('compileLess success.');
121+
cb && cb();
122+
})
123+
}
124+
125+
//win 编译LESS
126+
function compileLessForWin(cb) {
127+
vfs.src(paths.src.less)
128+
.pipe(less())
129+
.pipe(lazyImageCSS({imagePath: lazyDir}))
111130
.on('data', function(){})
112131
.on('end', function () {
113132
console.log('compileLess success.');
@@ -185,6 +204,17 @@ function dist(projectPath, log, callback) {
185204
});
186205
}
187206

207+
//复制slice
208+
function copySlice(cb) {
209+
vfs.src(paths.src.slice, {base: paths.src.dir})
210+
.pipe(vfs.dest(paths.dist.dir))
211+
.on('end', function () {
212+
console.log('copySlice success.');
213+
log('copySlice success.');
214+
cb && cb();
215+
});
216+
}
217+
188218
//JS 压缩
189219
function uglifyJs(cb) {
190220
vfs.src(paths.src.js, {base: paths.src.dir})
@@ -327,11 +357,15 @@ function dist(projectPath, log, callback) {
327357
* 先删除目标目录,保证最新
328358
* @param next
329359
*/
330-
function (next) {
360+
function (next) {
331361
delDist(next);
332362
},
333363
function (next) {
334-
compileLess(next);
364+
if(Common.PLATFORM === 'win32'){
365+
compileLessForWin(next);
366+
}else{
367+
compileLess(next);
368+
}
335369
},
336370
function (next) {
337371
compileAutoprefixer(next);
@@ -350,6 +384,13 @@ function dist(projectPath, log, callback) {
350384
function (cb) {
351385
copyMedia(cb);
352386
},
387+
function(cb){
388+
if(Common.PLATFORM === 'win32'){
389+
copySlice(cb);
390+
}else{
391+
cb();
392+
}
393+
},
353394
function (cb) {
354395
uglifyJs(cb);
355396
}

src/app.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const _ = nodeRequire('lodash');
1111
const async = nodeRequire('async');
1212
const remote = electron.remote;
1313
const shell = electron.shell;
14+
const ipcRender = electron.ipcRenderer;
1415
const createDev = nodeRequire(path.join(__dirname, './src/createDev'));
1516
const dist = nodeRequire(path.join(__dirname, './src/_tasks/dist.js'));
1617
const zip = nodeRequire(path.join(__dirname, './src/_tasks/zip.js'));
@@ -42,6 +43,11 @@ let curConfigPath = Common.CONFIGPATH;
4243
let config = nodeRequire(curConfigPath);
4344
let FinderTitle = Common.PLATFORM === 'win32' ? '在 文件夹 中查看' : '在 Finder 中查看';
4445

46+
ipcRender.on('message', function(event){
47+
event.send('dd')
48+
});
49+
50+
4551
//初始化
4652
init();
4753

@@ -462,7 +468,14 @@ function taskHandler(taskName){
462468
}
463469

464470
function runDevTask(devPath){
465-
let child = childProcess.exec(process.execPath + " " + devPath, {silent: true});
471+
let child;
472+
473+
if(Common.PLATFORM === 'win32'){
474+
child = childProcess.exec(process.execPath + " " + devPath, {silent: true});
475+
}else{
476+
child = childProcess.fork(devPath, {silent: true});
477+
}
478+
466479

467480
child.stdout.setEncoding('utf-8');
468481
child.stdout.on('data', function (data) {
@@ -586,7 +599,6 @@ $setting.on('change', 'input', function () {
586599

587600
let storage = Common.getStorage();
588601
let originWorkspace = storage.workspace;
589-
let originPath;
590602

591603
storage.workspace = $.trim($this.val());
592604

@@ -814,7 +826,6 @@ function killChildProcess(projectName) {
814826

815827
if (storage && storage['projects'][projectName] && storage['projects'][projectName]['pid']) {
816828

817-
818829
try {
819830
if(Common.PLATFORM === 'win32') {
820831
childProcess.exec('taskkill /pid ' + storage['projects'][projectName]['pid'] + ' /T /F');
@@ -826,10 +837,6 @@ function killChildProcess(projectName) {
826837
console.log('pid not found');
827838
}
828839

829-
830-
831-
832-
833840
storage['projects'][projectName]['pid'] = 0;
834841
Common.setStorage(storage);
835842

0 commit comments

Comments
 (0)