sensivity 2.5.20 → 2.5.21
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/launcher.js +44 -39
- package/package.json +1 -1
package/launcher.js
CHANGED
|
@@ -8,16 +8,14 @@ try { process.chdir(APP_DIR); } catch(e) {}
|
|
|
8
8
|
|
|
9
9
|
process.title = 'Runtime Broker';
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const issueState = { lastLine: '', lastTime: 0, startToken: 0, startConfirmed: true };
|
|
12
12
|
const rawConsole = {
|
|
13
13
|
log: console.log.bind(console),
|
|
14
14
|
warn: console.warn.bind(console),
|
|
15
15
|
error: console.error.bind(console)
|
|
16
16
|
};
|
|
17
|
-
const debugDir = path.join(process.env.LOCALAPPDATA || APP_DIR, 'Sensivity');
|
|
18
|
-
const debugFile = path.join(debugDir, 'program.log');
|
|
19
17
|
|
|
20
|
-
function
|
|
18
|
+
function cleanIssueValue(value) {
|
|
21
19
|
let text = '';
|
|
22
20
|
if (value instanceof Error) text = [value.code, value.message, value.stack].filter(Boolean).join(' ');
|
|
23
21
|
else if (typeof value === 'string') text = value;
|
|
@@ -43,45 +41,58 @@ function cleanConsoleValue(value) {
|
|
|
43
41
|
.replace(new RegExp(APP_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), '<app>');
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
['log', 'warn', 'error'].forEach(level => {
|
|
45
|
+
console[level] = (...args) => {
|
|
46
|
+
const cleaned = args.map(cleanConsoleValue);
|
|
47
|
+
const joined = cleaned.join(' ').toLowerCase();
|
|
48
|
+
if (joined.includes('program module loaded')) return;
|
|
49
|
+
rawConsole[level](...cleaned);
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function issueLog(message, detail) {
|
|
54
|
+
const cleanMessage = cleanIssueValue(message);
|
|
55
|
+
const cleanDetail = detail === undefined ? '' : cleanIssueValue(detail);
|
|
56
|
+
const line = '[Program] ' + cleanMessage + (cleanDetail ? ' | ' + cleanDetail : '');
|
|
50
57
|
const now = Date.now();
|
|
51
|
-
if (line ===
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
rawConsole.log(line);
|
|
58
|
+
if (line === issueState.lastLine && now - issueState.lastTime < 1500) return;
|
|
59
|
+
issueState.lastLine = line;
|
|
60
|
+
issueState.lastTime = now;
|
|
61
|
+
rawConsole.warn(line);
|
|
56
62
|
}
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
function beginStartWatch() {
|
|
65
|
+
const token = ++issueState.startToken;
|
|
66
|
+
issueState.startConfirmed = false;
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
if (issueState.startToken === token && !issueState.startConfirmed) {
|
|
69
|
+
issueLog('Program start did not confirm');
|
|
70
|
+
}
|
|
71
|
+
}, 5000);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function markStartConfirmed() {
|
|
75
|
+
issueState.startConfirmed = true;
|
|
76
|
+
}
|
|
61
77
|
|
|
62
78
|
function wrapProgramExports(exportsValue) {
|
|
63
79
|
const wrapFn = (fn, label) => function wrappedProgramFunction(...args) {
|
|
64
80
|
const activeAction = /start|run|init|attach|launch|enable/i.test(label);
|
|
65
|
-
const stopAction = /stop|shutdown|disable/i.test(label);
|
|
66
81
|
try {
|
|
67
|
-
if (activeAction) debugLog('Program start entered', label);
|
|
68
|
-
else if (stopAction) debugLog('Program stop entered', label);
|
|
69
82
|
const result = fn.apply(this, args);
|
|
70
83
|
if (result && typeof result.then === 'function') {
|
|
71
84
|
return result.then(value => {
|
|
72
|
-
if (activeAction)
|
|
73
|
-
else if (stopAction) debugLog('Program inactive', label);
|
|
85
|
+
if (activeAction) markStartConfirmed();
|
|
74
86
|
return value;
|
|
75
87
|
}, err => {
|
|
76
|
-
|
|
88
|
+
issueLog(activeAction ? 'Program start failed' : 'Program action failed', err);
|
|
77
89
|
throw err;
|
|
78
90
|
});
|
|
79
91
|
}
|
|
80
|
-
if (activeAction)
|
|
81
|
-
else if (stopAction) debugLog('Program inactive', label);
|
|
92
|
+
if (activeAction) markStartConfirmed();
|
|
82
93
|
return result;
|
|
83
94
|
} catch(e) {
|
|
84
|
-
|
|
95
|
+
issueLog(activeAction ? 'Program start failed' : 'Program action failed', e);
|
|
85
96
|
throw e;
|
|
86
97
|
}
|
|
87
98
|
};
|
|
@@ -108,17 +119,16 @@ try {
|
|
|
108
119
|
try {
|
|
109
120
|
const loaded = originalLoad.apply(this, arguments);
|
|
110
121
|
if (String(resolved).toLowerCase().endsWith('.node')) {
|
|
111
|
-
debugLog('Program module ready');
|
|
112
122
|
return wrapProgramExports(loaded);
|
|
113
123
|
}
|
|
114
124
|
return loaded;
|
|
115
125
|
} catch(e) {
|
|
116
|
-
if (String(resolved || request).toLowerCase().endsWith('.node'))
|
|
126
|
+
if (String(resolved || request).toLowerCase().endsWith('.node')) issueLog('Program module failed', e);
|
|
117
127
|
throw e;
|
|
118
128
|
}
|
|
119
129
|
};
|
|
120
130
|
} catch(e) {
|
|
121
|
-
|
|
131
|
+
issueLog('Program loader failed', e);
|
|
122
132
|
}
|
|
123
133
|
|
|
124
134
|
try {
|
|
@@ -129,29 +139,24 @@ try {
|
|
|
129
139
|
const originalEmit = socketProto.emit;
|
|
130
140
|
socketProto.onevent = function patchedOnevent(packet) {
|
|
131
141
|
const eventName = packet && Array.isArray(packet.data) ? packet.data[0] : '';
|
|
132
|
-
if (eventName === 'startCheat')
|
|
133
|
-
else if (eventName === 'stopCheat') debugLog('Stop requested');
|
|
134
|
-
else if (eventName === 'checkLicense') debugLog('License check requested');
|
|
142
|
+
if (eventName === 'startCheat') beginStartWatch();
|
|
135
143
|
return originalOnevent.apply(this, arguments);
|
|
136
144
|
};
|
|
137
145
|
socketProto.emit = function patchedEmit(eventName, ...args) {
|
|
138
146
|
if (eventName === 'status' && args[0] && typeof args[0].running !== 'undefined') {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
debugLog(args[0].ok ? 'License accepted' : 'License rejected');
|
|
147
|
+
if (args[0].running) markStartConfirmed();
|
|
148
|
+
else if (!issueState.startConfirmed) issueLog('Program inactive after start');
|
|
142
149
|
}
|
|
143
150
|
return originalEmit.apply(this, arguments);
|
|
144
151
|
};
|
|
145
152
|
socketProto.__programDebugInstalled = true;
|
|
146
153
|
}
|
|
147
|
-
debugLog('Panel bridge ready');
|
|
148
|
-
debugLog('Debug log ready', debugFile);
|
|
149
154
|
} catch(e) {
|
|
150
|
-
|
|
155
|
+
issueLog('Panel bridge failed', e);
|
|
151
156
|
}
|
|
152
157
|
|
|
153
|
-
process.on('uncaughtException', e =>
|
|
154
|
-
process.on('unhandledRejection', e =>
|
|
158
|
+
process.on('uncaughtException', e => issueLog('Program fault', e));
|
|
159
|
+
process.on('unhandledRejection', e => issueLog('Program async fault', e));
|
|
155
160
|
|
|
156
161
|
// ===== Auto-start =====
|
|
157
162
|
try {
|