leanweb 1.3.5 → 2.0.0
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/README.md +0 -29
- package/commands/build.js +92 -121
- package/commands/clean.js +3 -3
- package/commands/destroy.js +19 -20
- package/commands/dist.js +44 -58
- package/commands/generate.js +40 -41
- package/commands/help.js +23 -23
- package/commands/init.js +71 -80
- package/commands/serve.js +43 -63
- package/commands/upgrade.js +14 -43
- package/commands/utils.js +56 -124
- package/commands/version.js +1 -0
- package/leanweb.js +50 -51
- package/lib/lw-html-parser.js +82 -82
- package/package.json +35 -43
- package/templates/component.js +43 -43
- package/templates/env/prod.js +1 -1
- package/templates/env/test.js +1 -1
- package/templates/env.js +1 -1
- package/templates/index.html +6 -6
- package/templates/lib/api-client.js +50 -50
- package/templates/lib/lw-element.js +437 -438
- package/templates/lib/lw-event-bus.js +34 -34
- package/templates/lib/lw-expr-parser.js +163 -163
- package/commands/electron.js +0 -71
- package/templates/electron.js +0 -43
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
class LWEvent {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
constructor(eventName, data) {
|
|
3
|
+
this.eventName = eventName;
|
|
4
|
+
this.data = data;
|
|
5
|
+
}
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
class LWEventListener {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
static key = 0;
|
|
10
|
+
constructor(eventName, callback) {
|
|
11
|
+
this.eventName = eventName;
|
|
12
|
+
this.callback = callback;
|
|
13
|
+
this.key = ++LWEventListener.key;
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// const listeners = {
|
|
@@ -24,31 +24,31 @@ class LWEventListener {
|
|
|
24
24
|
// };
|
|
25
25
|
|
|
26
26
|
export default class LWEventBus {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
constructor() {
|
|
28
|
+
this.listeners = {};
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
addEventListener(eventName, callback) {
|
|
32
|
+
const listener = new LWEventListener(eventName, callback);
|
|
33
|
+
this.listeners[listener.eventName] = this.listeners[listener.eventName] || {};
|
|
34
|
+
const events = this.listeners[listener.eventName];
|
|
35
|
+
events[listener.key] = listener;
|
|
36
|
+
return listener;
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
removeEventListener(listener) {
|
|
40
|
+
if (this.listeners[listener.eventName]) {
|
|
41
|
+
delete this.listeners[listener.eventName][listener.key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
dispatchEvent(eventName, data = null) {
|
|
46
|
+
if (this.listeners[eventName]) {
|
|
47
|
+
Object.values(this.listeners[eventName]).forEach(listener => {
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
listener.callback.call(void 0, new LWEvent(eventName, data));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
54
|
}
|
|
@@ -1,194 +1,194 @@
|
|
|
1
1
|
const binaryOperations = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
'==': (a, b) => a == b,
|
|
3
|
+
'!=': (a, b) => a != b,
|
|
4
|
+
'===': (a, b) => a === b,
|
|
5
|
+
'!==': (a, b) => a !== b,
|
|
6
|
+
'<': (a, b) => a < b,
|
|
7
|
+
'<=': (a, b) => a <= b,
|
|
8
|
+
'>': (a, b) => a > b,
|
|
9
|
+
'>=': (a, b) => a >= b,
|
|
10
|
+
'<<': (a, b) => a << b,
|
|
11
|
+
'>>': (a, b) => a >> b,
|
|
12
|
+
'>>>': (a, b) => a >>> b,
|
|
13
|
+
'+': (a, b) => a + b,
|
|
14
|
+
'-': (a, b) => a - b,
|
|
15
|
+
'*': (a, b) => a * b,
|
|
16
|
+
'/': (a, b) => a / b,
|
|
17
|
+
'%': (a, b) => a % b,
|
|
18
|
+
'**': (a, b) => a ** b,
|
|
19
|
+
'|': (a, b) => a | b,
|
|
20
|
+
'^': (a, b) => a ^ b,
|
|
21
|
+
'&': (a, b) => a & b,
|
|
22
|
+
'in': (a, b) => a in b,
|
|
23
|
+
'instanceof': (a, b) => a instanceof b,
|
|
24
|
+
// '|>': (a, b) => a |> b,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const assignmentOperations = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
'=': (c, a, b) => { c[a] = b; },
|
|
29
|
+
'+=': (c, a, b) => { c[a] += b; },
|
|
30
|
+
'-=': (c, a, b) => { c[a] -= b; },
|
|
31
|
+
'*=': (c, a, b) => { c[a] *= b; },
|
|
32
|
+
'/=': (c, a, b) => { c[a] /= b; },
|
|
33
|
+
'%=': (c, a, b) => { c[a] %= b; },
|
|
34
|
+
'**=': (c, a, b) => { c[a] **= b; },
|
|
35
|
+
'&&=': (c, a, b) => { c[a] &&= b; },
|
|
36
|
+
'??=': (c, a, b) => { c[a] ??= b; },
|
|
37
|
+
'||=': (c, a, b) => { c[a] ||= b; },
|
|
38
|
+
'>>=': (c, a, b) => { c[a] >>= b; },
|
|
39
|
+
'>>>=': (c, a, b) => { c[a] >>>= b; },
|
|
40
|
+
'<<=': (c, a, b) => { c[a] <<= b; },
|
|
41
|
+
'&=': (c, a, b) => { c[a] &= b; },
|
|
42
|
+
'|=': (c, a, b) => { c[a] |= b; },
|
|
43
|
+
'^=': (c, a, b) => { c[a] ^= b; },
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const logicalOperators = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
'||': (a, b) => a || b,
|
|
48
|
+
'&&': (a, b) => a && b,
|
|
49
|
+
'??': (a, b) => a ?? b,
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
const unaryOperators = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
'-': a => -a,
|
|
54
|
+
'+': a => +a,
|
|
55
|
+
'!': a => !a,
|
|
56
|
+
'~': a => ~a,
|
|
57
|
+
'typeof': a => typeof a,
|
|
58
|
+
'void': a => void a,
|
|
59
|
+
// 'delete': a => delete a,
|
|
60
|
+
'throw': a => { throw a; },
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const updateOperators = (operator, prefix) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
if (operator === '++') {
|
|
65
|
+
return (c, a) => prefix ? ++c[a] : c[a]++;
|
|
66
|
+
} else if (operator === '--') {
|
|
67
|
+
return (c, a) => prefix ? --c[a] : c[a]--;
|
|
68
|
+
}
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
const callFunction = (node, context) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
const callee = evalNode(node.callee, context);
|
|
73
|
+
if (node.callee.type === 'OptionalMemberExpression' && (callee === void 0 || callee === null)) {
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
const args = [];
|
|
77
|
+
node.arguments.map(argument => {
|
|
78
|
+
if (argument.type === 'SpreadElement') {
|
|
79
|
+
args.push(...evalNode(argument, context));
|
|
80
|
+
} else {
|
|
81
|
+
args.push(evalNode(argument, context));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return callee(...args);
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
const nodeHandlers = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
return arr;
|
|
143
|
-
},
|
|
144
|
-
'ObjectExpression': (node, context) => node.properties.reduce((acc, prop) => ({ ...acc, ...evalNode(prop, context) }), {}),
|
|
145
|
-
'ObjectProperty': (node, context) => ({ [evalNode(node.key, context)]: evalNode(node.value, context) }),
|
|
146
|
-
'SpreadElement': (node, context) => evalNode(node.argument, context),
|
|
147
|
-
|
|
148
|
-
'Identifier': (node, context) => {
|
|
149
|
-
if (Array.isArray(context)) {
|
|
150
|
-
const hitContext = context.find(contextObj => node.name in contextObj);
|
|
151
|
-
return hitContext ? hitContext[node.name] : undefined;
|
|
152
|
-
} else if (typeof context === 'object') {
|
|
153
|
-
return context[node.name];
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
'ThisExpression': (node, context) => {
|
|
157
|
-
if (Array.isArray(context)) {
|
|
158
|
-
const hitContext = context.find(contextObj => 'this' in contextObj);
|
|
159
|
-
return hitContext ? hitContext['this'] : undefined;
|
|
160
|
-
} else if (typeof context === 'object') {
|
|
161
|
-
return context['this'];
|
|
88
|
+
'NumericLiteral': (node, context) => node.value,
|
|
89
|
+
'StringLiteral': (node, context) => node.value,
|
|
90
|
+
'BooleanLiteral': (node, context) => node.value,
|
|
91
|
+
'NullLiteral': (node, context) => null,
|
|
92
|
+
|
|
93
|
+
'RegExpLiteral': (node, context) => new RegExp(node.pattern, node.flags),
|
|
94
|
+
|
|
95
|
+
'ExpressionStatement': (node, context) => evalNode(node.expression, context),
|
|
96
|
+
'BinaryExpression': (node, context) => binaryOperations[node.operator](evalNode(node.left, context), evalNode(node.right, context)),
|
|
97
|
+
'AssignmentExpression': (node, context) => {
|
|
98
|
+
const immediateCtx = immediateContext(node.left, context);
|
|
99
|
+
assignmentOperations[node.operator](immediateCtx, node.left.name, evalNode(node.right, context));
|
|
100
|
+
},
|
|
101
|
+
'LogicalExpression': (node, context) => logicalOperators[node.operator](evalNode(node.left, context), evalNode(node.right, context)),
|
|
102
|
+
'UnaryExpression': (node, context) => unaryOperators[node.operator](evalNode(node.argument, context)),
|
|
103
|
+
'UpdateExpression': (node, context) => {
|
|
104
|
+
const immediateCtx = immediateContext(node.argument, context);
|
|
105
|
+
updateOperators(node.operator, node.prefix)(immediateCtx, node.argument.name, evalNode(node.argument, context));
|
|
106
|
+
},
|
|
107
|
+
'ConditionalExpression': (node, context) => {
|
|
108
|
+
const test = evalNode(node.test, context);
|
|
109
|
+
const consequent = evalNode(node.consequent, context);
|
|
110
|
+
const alternate = evalNode(node.alternate, context);
|
|
111
|
+
return test ? consequent : alternate;
|
|
112
|
+
},
|
|
113
|
+
'MemberExpression': (node, context) => {
|
|
114
|
+
const object = evalNode(node.object, context);
|
|
115
|
+
const member = node.computed ? object[evalNode(node.property, context)] : object[node.property.name];
|
|
116
|
+
if (typeof member === 'function') {
|
|
117
|
+
return member.bind(object);
|
|
118
|
+
}
|
|
119
|
+
return member;
|
|
120
|
+
},
|
|
121
|
+
'OptionalMemberExpression': (node, context) => {
|
|
122
|
+
const object = evalNode(node.object, context);
|
|
123
|
+
if (object === void 0 || object === null) {
|
|
124
|
+
return void 0;
|
|
125
|
+
}
|
|
126
|
+
const member = node.computed ? (object[evalNode(node.property, context)]) : (object[node.property.name]);
|
|
127
|
+
if (typeof member === 'function') {
|
|
128
|
+
return member.bind(object);
|
|
129
|
+
}
|
|
130
|
+
return member;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
'ArrayExpression': (node, context) => {
|
|
134
|
+
const arr = [];
|
|
135
|
+
node.elements.map(elem => {
|
|
136
|
+
if (elem.type === 'SpreadElement') {
|
|
137
|
+
arr.push(...evalNode(elem, context));
|
|
138
|
+
} else {
|
|
139
|
+
arr.push(evalNode(elem, context));
|
|
162
140
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
141
|
+
});
|
|
142
|
+
return arr;
|
|
143
|
+
},
|
|
144
|
+
'ObjectExpression': (node, context) => node.properties.reduce((acc, prop) => ({ ...acc, ...evalNode(prop, context) }), {}),
|
|
145
|
+
'ObjectProperty': (node, context) => ({ [evalNode(node.key, context)]: evalNode(node.value, context) }),
|
|
146
|
+
'SpreadElement': (node, context) => evalNode(node.argument, context),
|
|
147
|
+
|
|
148
|
+
'Identifier': (node, context) => {
|
|
149
|
+
if (Array.isArray(context)) {
|
|
150
|
+
const hitContext = context.find(contextObj => node.name in contextObj);
|
|
151
|
+
return hitContext ? hitContext[node.name] : undefined;
|
|
152
|
+
} else if (typeof context === 'object') {
|
|
153
|
+
return context[node.name];
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
'ThisExpression': (node, context) => {
|
|
157
|
+
if (Array.isArray(context)) {
|
|
158
|
+
const hitContext = context.find(contextObj => 'this' in contextObj);
|
|
159
|
+
return hitContext ? hitContext['this'] : undefined;
|
|
160
|
+
} else if (typeof context === 'object') {
|
|
161
|
+
return context['this'];
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
'CallExpression': (node, context) => callFunction(node, context),
|
|
166
|
+
'OptionalCallExpression': (node, context) => callFunction(node, context),
|
|
167
|
+
'NewExpression': (node, context) => callFunction(node, context),
|
|
168
|
+
|
|
169
|
+
'Directive': (node, context) => evalNode(node.value, context),
|
|
170
|
+
'DirectiveLiteral': (node, context) => node.value,
|
|
171
171
|
};
|
|
172
172
|
|
|
173
173
|
const immediateContext = (node, context) => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
174
|
+
if (Array.isArray(context)) {
|
|
175
|
+
if (context.length === 0) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
return context.find(contextObj => node.name in contextObj) ?? context[0];
|
|
179
|
+
} else if (typeof context === 'object') {
|
|
180
|
+
return context;
|
|
181
|
+
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
const evalNode = (node, context) => nodeHandlers[node.type](node, context);
|
|
185
185
|
|
|
186
186
|
const evaluate = (ast, context = {}, loc = {}) => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
try {
|
|
188
|
+
return ast.map(astNode => evalNode(astNode, context));
|
|
189
|
+
} catch (e) {
|
|
190
|
+
throw { error: e.message, location: loc, ast, context };
|
|
191
|
+
}
|
|
192
192
|
};
|
|
193
193
|
|
|
194
194
|
export { evaluate };
|
package/commands/electron.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import fse from 'fs-extra';
|
|
4
|
-
import webpack from 'webpack';
|
|
5
|
-
import * as utils from './utils.js';
|
|
6
|
-
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import { fileURLToPath } from 'url';
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
|
|
12
|
-
import { createRequire } from "module";
|
|
13
|
-
const require = createRequire(import.meta.url);
|
|
14
|
-
|
|
15
|
-
(async () => {
|
|
16
|
-
let env = '';
|
|
17
|
-
const args = process.argv;
|
|
18
|
-
if (args.length >= 3) {
|
|
19
|
-
env = args[2];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!fs.existsSync(process.cwd() + `/${utils.dirs.src}/electron.js`)) {
|
|
23
|
-
fse.copySync(`${__dirname}/../templates/electron.js`, `${process.cwd()}/${utils.dirs.src}/electron.js`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const leanwebJSONPath = `${process.cwd()}/${utils.dirs.src}/leanweb.json`;
|
|
27
|
-
const project = require(leanwebJSONPath);
|
|
28
|
-
if (!project.electron) {
|
|
29
|
-
utils.exec(`npm i -D electron --loglevel=error`);
|
|
30
|
-
project.electron = true;
|
|
31
|
-
fs.writeFileSync(leanwebJSONPath, JSON.stringify(project, null, 2));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
await utils.exec(`npx leanweb clean`);
|
|
35
|
-
await utils.exec(`npx leanweb build ${env}`);
|
|
36
|
-
|
|
37
|
-
fse.copySync(`./${utils.dirs.build}/electron.js`, `./${utils.dirs.electron}/electron.js`);
|
|
38
|
-
fse.copySync(`./${utils.dirs.build}/index.html`, `./${utils.dirs.electron}/index.html`);
|
|
39
|
-
fse.copySync(`./${utils.dirs.build}/${project.name}.css`, `./${utils.dirs.electron}/${project.name}.css`);
|
|
40
|
-
fse.copySync(`./${utils.dirs.build}/favicon.svg`, `./${utils.dirs.electron}/favicon.svg`);
|
|
41
|
-
project.resources?.forEach(resource => {
|
|
42
|
-
const source = `./${utils.dirs.build}/${resource}`;
|
|
43
|
-
if (fs.existsSync(source)) {
|
|
44
|
-
fse.copySync(source, `./${utils.dirs.electron}/${resource}`, { dereference: true });
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const webpackConfig = utils.getWebPackConfig(utils.dirs.electron, project);
|
|
49
|
-
|
|
50
|
-
const compiler = webpack({
|
|
51
|
-
...webpackConfig,
|
|
52
|
-
mode: 'development',
|
|
53
|
-
devtool: 'eval-cheap-module-source-map',
|
|
54
|
-
performance: {
|
|
55
|
-
hints: false,
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
compiler.run(async (err, stats) => {
|
|
60
|
-
if (err) {
|
|
61
|
-
console.log(err);
|
|
62
|
-
}
|
|
63
|
-
if (stats.compilation.errors.length) {
|
|
64
|
-
console.log(stats.compilation.errors);
|
|
65
|
-
}
|
|
66
|
-
if (stats.compilation.warnings.length) {
|
|
67
|
-
console.log(stats.compilation.warnings);
|
|
68
|
-
}
|
|
69
|
-
await utils.exec(`npx electron ${process.cwd()}/${utils.dirs.electron}/electron.js`);
|
|
70
|
-
});
|
|
71
|
-
})();
|
package/templates/electron.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { app, BrowserWindow } from 'electron';
|
|
2
|
-
|
|
3
|
-
const createWindow = () => {
|
|
4
|
-
// Create the browser window.
|
|
5
|
-
const win = new BrowserWindow({
|
|
6
|
-
width: 640,
|
|
7
|
-
height: 480,
|
|
8
|
-
webPreferences: {
|
|
9
|
-
nodeIntegration: true
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
// and load the index.html of the app.
|
|
14
|
-
win.loadFile('index.html');
|
|
15
|
-
|
|
16
|
-
// Open the DevTools.
|
|
17
|
-
// win.webContents.openDevTools();
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// This method will be called when Electron has finished
|
|
21
|
-
// initialization and is ready to create browser windows.
|
|
22
|
-
// Some APIs can only be used after this event occurs.
|
|
23
|
-
app.whenReady().then(createWindow);
|
|
24
|
-
|
|
25
|
-
// Quit when all windows are closed.
|
|
26
|
-
app.on('window-all-closed', () => {
|
|
27
|
-
// On macOS it is common for applications and their menu bar
|
|
28
|
-
// to stay active until the user quits explicitly with Cmd + Q
|
|
29
|
-
if (process.platform !== 'darwin') {
|
|
30
|
-
app.quit();
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
app.on('activate', () => {
|
|
35
|
-
// On macOS it's common to re-create a window in the app when the
|
|
36
|
-
// dock icon is clicked and there are no other windows open.
|
|
37
|
-
if (BrowserWindow.getAllWindows().length === 0) {
|
|
38
|
-
createWindow();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// In this file you can include the rest of your app's specific main process
|
|
43
|
-
// code. You can also put them in separate files and require them here.
|