sensivity 2.5.19 → 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.
Files changed (2) hide show
  1. package/launcher.js +149 -2
  2. package/package.json +1 -1
package/launcher.js CHANGED
@@ -8,8 +8,155 @@ try { process.chdir(APP_DIR); } catch(e) {}
8
8
 
9
9
  process.title = 'Runtime Broker';
10
10
 
11
- process.on('uncaughtException', () => {});
12
- process.on('unhandledRejection', () => {});
11
+ const issueState = { lastLine: '', lastTime: 0, startToken: 0, startConfirmed: true };
12
+ const rawConsole = {
13
+ log: console.log.bind(console),
14
+ warn: console.warn.bind(console),
15
+ error: console.error.bind(console)
16
+ };
17
+
18
+ function cleanIssueValue(value) {
19
+ let text = '';
20
+ if (value instanceof Error) text = [value.code, value.message, value.stack].filter(Boolean).join(' ');
21
+ else if (typeof value === 'string') text = value;
22
+ else {
23
+ try { text = JSON.stringify(value); } catch(e) { text = String(value); }
24
+ }
25
+ return text
26
+ .replace(/sens\.node/gi, 'program module')
27
+ .replace(new RegExp(APP_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), '<app>')
28
+ .replace(/\s+/g, ' ')
29
+ .trim();
30
+ }
31
+
32
+ function cleanConsoleValue(value) {
33
+ let text = '';
34
+ if (value instanceof Error) text = [value.code, value.message].filter(Boolean).join(' ');
35
+ else if (typeof value === 'string') text = value;
36
+ else {
37
+ try { text = JSON.stringify(value); } catch(e) { text = String(value); }
38
+ }
39
+ return text
40
+ .replace(/sens\.node/gi, 'program module')
41
+ .replace(new RegExp(APP_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), '<app>');
42
+ }
43
+
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 : '');
57
+ const now = Date.now();
58
+ if (line === issueState.lastLine && now - issueState.lastTime < 1500) return;
59
+ issueState.lastLine = line;
60
+ issueState.lastTime = now;
61
+ rawConsole.warn(line);
62
+ }
63
+
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
+ }
77
+
78
+ function wrapProgramExports(exportsValue) {
79
+ const wrapFn = (fn, label) => function wrappedProgramFunction(...args) {
80
+ const activeAction = /start|run|init|attach|launch|enable/i.test(label);
81
+ try {
82
+ const result = fn.apply(this, args);
83
+ if (result && typeof result.then === 'function') {
84
+ return result.then(value => {
85
+ if (activeAction) markStartConfirmed();
86
+ return value;
87
+ }, err => {
88
+ issueLog(activeAction ? 'Program start failed' : 'Program action failed', err);
89
+ throw err;
90
+ });
91
+ }
92
+ if (activeAction) markStartConfirmed();
93
+ return result;
94
+ } catch(e) {
95
+ issueLog(activeAction ? 'Program start failed' : 'Program action failed', e);
96
+ throw e;
97
+ }
98
+ };
99
+
100
+ if (typeof exportsValue === 'function') return wrapFn(exportsValue, exportsValue.name || 'entry');
101
+ if (exportsValue && typeof exportsValue === 'object') {
102
+ Object.keys(exportsValue).forEach(key => {
103
+ if (typeof exportsValue[key] === 'function' && !exportsValue[key].__programDebugWrapped) {
104
+ const wrapped = wrapFn(exportsValue[key], key);
105
+ wrapped.__programDebugWrapped = true;
106
+ try { exportsValue[key] = wrapped; } catch(e) {}
107
+ }
108
+ });
109
+ }
110
+ return exportsValue;
111
+ }
112
+
113
+ try {
114
+ const Module = require('module');
115
+ const originalLoad = Module._load;
116
+ Module._load = function patchedProgramLoad(request, parent, isMain) {
117
+ let resolved = '';
118
+ try { resolved = Module._resolveFilename(request, parent, isMain); } catch(e) {}
119
+ try {
120
+ const loaded = originalLoad.apply(this, arguments);
121
+ if (String(resolved).toLowerCase().endsWith('.node')) {
122
+ return wrapProgramExports(loaded);
123
+ }
124
+ return loaded;
125
+ } catch(e) {
126
+ if (String(resolved || request).toLowerCase().endsWith('.node')) issueLog('Program module failed', e);
127
+ throw e;
128
+ }
129
+ };
130
+ } catch(e) {
131
+ issueLog('Program loader failed', e);
132
+ }
133
+
134
+ try {
135
+ const socketIO = require('socket.io');
136
+ const socketProto = socketIO.Socket && socketIO.Socket.prototype;
137
+ if (socketProto && !socketProto.__programDebugInstalled) {
138
+ const originalOnevent = socketProto.onevent;
139
+ const originalEmit = socketProto.emit;
140
+ socketProto.onevent = function patchedOnevent(packet) {
141
+ const eventName = packet && Array.isArray(packet.data) ? packet.data[0] : '';
142
+ if (eventName === 'startCheat') beginStartWatch();
143
+ return originalOnevent.apply(this, arguments);
144
+ };
145
+ socketProto.emit = function patchedEmit(eventName, ...args) {
146
+ if (eventName === 'status' && args[0] && typeof args[0].running !== 'undefined') {
147
+ if (args[0].running) markStartConfirmed();
148
+ else if (!issueState.startConfirmed) issueLog('Program inactive after start');
149
+ }
150
+ return originalEmit.apply(this, arguments);
151
+ };
152
+ socketProto.__programDebugInstalled = true;
153
+ }
154
+ } catch(e) {
155
+ issueLog('Panel bridge failed', e);
156
+ }
157
+
158
+ process.on('uncaughtException', e => issueLog('Program fault', e));
159
+ process.on('unhandledRejection', e => issueLog('Program async fault', e));
13
160
 
14
161
  // ===== Auto-start =====
15
162
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sensivity",
3
- "version": "2.5.19",
3
+ "version": "2.5.21",
4
4
  "description": "Sensivity Control Panel",
5
5
  "main": "launcher.js",
6
6
  "bin": {