ee-core 1.2.0 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/baseApp.js +0 -24
- package/lib/eeApp.js +37 -21
- package/lib/socket/ipcServer.js +25 -8
- package/package.json +1 -1
- package/tools/codeCompress.js +3 -1
package/lib/baseApp.js
CHANGED
|
@@ -108,30 +108,6 @@ class BaseApp extends EeAppCore {
|
|
|
108
108
|
return this[HTTPCLIENT];
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
/**
|
|
112
|
-
* 调用 egg api
|
|
113
|
-
*/
|
|
114
|
-
// async curlEgg (method, uri, params, timeout = 15000) {
|
|
115
|
-
// let result = null;
|
|
116
|
-
// try {
|
|
117
|
-
// const port = this.config.egg.port;
|
|
118
|
-
// const url = "http://127.0.0.1:" + port + uri;
|
|
119
|
-
// // console.log('[ee:baseApp] [curlEgg] url:', url);
|
|
120
|
-
// const response = await this.curl(url, {
|
|
121
|
-
// method: method,
|
|
122
|
-
// contentType: 'application/json',
|
|
123
|
-
// data: params,
|
|
124
|
-
// dataType: 'json',
|
|
125
|
-
// timeout: timeout,
|
|
126
|
-
// });
|
|
127
|
-
// result = response.data;
|
|
128
|
-
// } catch (err) {
|
|
129
|
-
// this.logger.error('[ee:baseApp] [curlEgg] throw error:', err);
|
|
130
|
-
// }
|
|
131
|
-
|
|
132
|
-
// return result;
|
|
133
|
-
// }
|
|
134
|
-
|
|
135
111
|
/**
|
|
136
112
|
* core app have been loaded
|
|
137
113
|
*/
|
package/lib/eeApp.js
CHANGED
|
@@ -12,7 +12,10 @@ class EeApp extends BaseApp {
|
|
|
12
12
|
|
|
13
13
|
this.electron = {
|
|
14
14
|
mainWindow: null,
|
|
15
|
-
tray: null
|
|
15
|
+
tray: null,
|
|
16
|
+
extra: {
|
|
17
|
+
closeWindow: false,
|
|
18
|
+
}
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -53,23 +56,21 @@ class EeApp extends BaseApp {
|
|
|
53
56
|
*/
|
|
54
57
|
async createElectronApp () {
|
|
55
58
|
const self = this;
|
|
56
|
-
|
|
59
|
+
|
|
60
|
+
const gotTheLock = app.requestSingleInstanceLock();
|
|
61
|
+
if (!gotTheLock) {
|
|
62
|
+
await this.appQuit();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
57
65
|
|
|
58
66
|
app.on('second-instance', (event) => {
|
|
59
|
-
|
|
60
|
-
if (self.electron.mainWindow.isMinimized()) {
|
|
61
|
-
self.electron.mainWindow.restore();
|
|
62
|
-
}
|
|
63
|
-
self.electron.mainWindow.focus()
|
|
64
|
-
}
|
|
67
|
+
self.restoreMainWindow();
|
|
65
68
|
})
|
|
66
69
|
|
|
67
70
|
app.whenReady().then(() => {
|
|
68
71
|
self.createWindow();
|
|
69
72
|
app.on('activate', function () {
|
|
70
|
-
|
|
71
|
-
self.createWindow();
|
|
72
|
-
}
|
|
73
|
+
self.restoreMainWindow();
|
|
73
74
|
})
|
|
74
75
|
})
|
|
75
76
|
|
|
@@ -79,15 +80,18 @@ class EeApp extends BaseApp {
|
|
|
79
80
|
self.appQuit();
|
|
80
81
|
}
|
|
81
82
|
})
|
|
83
|
+
|
|
84
|
+
app.on('before-quit', () => {
|
|
85
|
+
self.electron.extra.closeWindow = true;
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
await this.electronAppReady();
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
/**
|
|
85
92
|
* 创建应用主窗口
|
|
86
93
|
*/
|
|
87
94
|
async createWindow () {
|
|
88
|
-
|
|
89
|
-
await this.electronAppReady();
|
|
90
|
-
|
|
91
95
|
const winOptions = this.config.windowsOption;
|
|
92
96
|
this.electron.mainWindow = new BrowserWindow(winOptions);
|
|
93
97
|
|
|
@@ -110,6 +114,18 @@ class EeApp extends BaseApp {
|
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
|
|
117
|
+
/**
|
|
118
|
+
* 还原窗口
|
|
119
|
+
*/
|
|
120
|
+
restoreMainWindow () {
|
|
121
|
+
if (this.electron.mainWindow) {
|
|
122
|
+
if (this.electron.mainWindow.isMinimized()) {
|
|
123
|
+
this.electron.mainWindow.restore();
|
|
124
|
+
}
|
|
125
|
+
this.electron.mainWindow.show()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
113
129
|
/**
|
|
114
130
|
* 加载已经实现的功能
|
|
115
131
|
*/
|
|
@@ -220,12 +236,12 @@ class EeApp extends BaseApp {
|
|
|
220
236
|
/**
|
|
221
237
|
* 限制一个窗口
|
|
222
238
|
*/
|
|
223
|
-
async limitOneWindow () {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
239
|
+
// async limitOneWindow () {
|
|
240
|
+
// const gotTheLock = app.requestSingleInstanceLock();
|
|
241
|
+
// if (!gotTheLock) {
|
|
242
|
+
// await this.appQuit();
|
|
243
|
+
// }
|
|
244
|
+
// }
|
|
229
245
|
|
|
230
246
|
/**
|
|
231
247
|
* electron app退出
|
|
@@ -234,7 +250,7 @@ class EeApp extends BaseApp {
|
|
|
234
250
|
await this.beforeClose();
|
|
235
251
|
|
|
236
252
|
// 窗口销毁
|
|
237
|
-
this.electron.mainWindow.
|
|
253
|
+
//this.electron.mainWindow.close();
|
|
238
254
|
|
|
239
255
|
//console.log('Exit now!');
|
|
240
256
|
// 托盘销毁
|
package/lib/socket/ipcServer.js
CHANGED
|
@@ -81,15 +81,15 @@ class IpcServer {
|
|
|
81
81
|
for (const key in fns) {
|
|
82
82
|
let channel = pathName + '.' + key;
|
|
83
83
|
debug('register channel %s', channel);
|
|
84
|
-
|
|
84
|
+
|
|
85
|
+
function findFn (app, c) {
|
|
85
86
|
try {
|
|
86
87
|
// 找函数
|
|
87
|
-
const cmd =
|
|
88
|
-
const args = params;
|
|
88
|
+
const cmd = c;
|
|
89
89
|
let fn = null;
|
|
90
90
|
if (is.string(cmd)) {
|
|
91
91
|
const actions = cmd.split('.');
|
|
92
|
-
let obj =
|
|
92
|
+
let obj = app;
|
|
93
93
|
actions.forEach(key => {
|
|
94
94
|
obj = obj[key];
|
|
95
95
|
if (!obj) throw new Error(`class or function '${key}' not exists`);
|
|
@@ -98,12 +98,29 @@ class IpcServer {
|
|
|
98
98
|
}
|
|
99
99
|
if (!fn) throw new Error('function not exists');
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
event.reply(`${channel}`, result)
|
|
101
|
+
return fn;
|
|
103
102
|
} catch (err) {
|
|
104
|
-
|
|
103
|
+
app.logger.error('[ee:socket:ipcMain] throw error:', err);
|
|
105
104
|
}
|
|
106
|
-
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// send/on 模型
|
|
109
|
+
ipcMain.on(channel, async (event, params) => {
|
|
110
|
+
const fn = findFn(self.app, channel);
|
|
111
|
+
const result = await fn.call(self.app, params, event);
|
|
112
|
+
|
|
113
|
+
event.returnValue = result;
|
|
114
|
+
event.reply(`${channel}`, result);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// invoke/handle 模型
|
|
118
|
+
ipcMain.handle(channel, async (event, params) => {
|
|
119
|
+
const fn = findFn(self.app, channel);
|
|
120
|
+
const result = await fn.call(self.app, params, event);
|
|
121
|
+
|
|
122
|
+
return result;
|
|
123
|
+
});
|
|
107
124
|
}
|
|
108
125
|
}
|
|
109
126
|
}
|
package/package.json
CHANGED
package/tools/codeCompress.js
CHANGED
|
@@ -128,7 +128,9 @@ class CodeCompress {
|
|
|
128
128
|
* 移除备份
|
|
129
129
|
*/
|
|
130
130
|
rmBackup () {
|
|
131
|
-
fs.
|
|
131
|
+
if (fs.existsSync(this.backupCodeDir)) {
|
|
132
|
+
fs.rmSync(this.backupCodeDir, {recursive: true, force: true});
|
|
133
|
+
}
|
|
132
134
|
return;
|
|
133
135
|
}
|
|
134
136
|
|