@lvce-editor/activity-bar-worker 7.0.0 → 7.2.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.
@@ -1,1711 +1,1768 @@
1
- const normalizeLine = line => {
2
- if (line.startsWith('Error: ')) {
3
- return line.slice('Error: '.length);
4
- }
5
- if (line.startsWith('VError: ')) {
6
- return line.slice('VError: '.length);
7
- }
8
- return line;
1
+ const toCommandId = key => {
2
+ const dotIndex = key.indexOf('.');
3
+ return key.slice(dotIndex + 1);
9
4
  };
10
- const getCombinedMessage = (error, message) => {
11
- const stringifiedError = normalizeLine(`${error}`);
12
- if (message) {
13
- return `${message}: ${stringifiedError}`;
14
- }
15
- return stringifiedError;
5
+ const create$a = () => {
6
+ const states = Object.create(null);
7
+ const commandMapRef = {};
8
+ return {
9
+ clear() {
10
+ for (const key of Object.keys(states)) {
11
+ delete states[key];
12
+ }
13
+ },
14
+ diff(uid, modules, numbers) {
15
+ const {
16
+ oldState,
17
+ scheduledState
18
+ } = states[uid];
19
+ const diffResult = [];
20
+ for (let i = 0; i < modules.length; i++) {
21
+ const fn = modules[i];
22
+ if (!fn(oldState, scheduledState)) {
23
+ diffResult.push(numbers[i]);
24
+ }
25
+ }
26
+ return diffResult;
27
+ },
28
+ dispose(uid) {
29
+ delete states[uid];
30
+ },
31
+ get(uid) {
32
+ return states[uid];
33
+ },
34
+ getCommandIds() {
35
+ const keys = Object.keys(commandMapRef);
36
+ const ids = keys.map(toCommandId);
37
+ return ids;
38
+ },
39
+ getKeys() {
40
+ return Object.keys(states).map(Number);
41
+ },
42
+ registerCommands(commandMap) {
43
+ Object.assign(commandMapRef, commandMap);
44
+ },
45
+ set(uid, oldState, newState, scheduledState) {
46
+ states[uid] = {
47
+ newState,
48
+ oldState,
49
+ scheduledState: scheduledState ?? newState
50
+ };
51
+ },
52
+ wrapCommand(fn) {
53
+ const wrapped = async (uid, ...args) => {
54
+ const {
55
+ newState,
56
+ oldState
57
+ } = states[uid];
58
+ const newerState = await fn(newState, ...args);
59
+ if (oldState === newerState || newState === newerState) {
60
+ return;
61
+ }
62
+ const latestOld = states[uid];
63
+ const latestNew = {
64
+ ...latestOld.newState,
65
+ ...newerState
66
+ };
67
+ states[uid] = {
68
+ newState: latestNew,
69
+ oldState: latestOld.oldState,
70
+ scheduledState: latestNew
71
+ };
72
+ };
73
+ return wrapped;
74
+ },
75
+ wrapGetter(fn) {
76
+ const wrapped = (uid, ...args) => {
77
+ const {
78
+ newState
79
+ } = states[uid];
80
+ return fn(newState, ...args);
81
+ };
82
+ return wrapped;
83
+ },
84
+ wrapLoadContent(fn) {
85
+ const wrapped = async (uid, ...args) => {
86
+ const {
87
+ newState,
88
+ oldState
89
+ } = states[uid];
90
+ const result = await fn(newState, ...args);
91
+ const {
92
+ error,
93
+ state
94
+ } = result;
95
+ if (oldState === state || newState === state) {
96
+ return {
97
+ error
98
+ };
99
+ }
100
+ const latestOld = states[uid];
101
+ const latestNew = {
102
+ ...latestOld.newState,
103
+ ...state
104
+ };
105
+ states[uid] = {
106
+ newState: latestNew,
107
+ oldState: latestOld.oldState,
108
+ scheduledState: latestNew
109
+ };
110
+ return {
111
+ error
112
+ };
113
+ };
114
+ return wrapped;
115
+ }
116
+ };
16
117
  };
17
- const NewLine$2 = '\n';
18
- const getNewLineIndex$1 = (string, startIndex = undefined) => {
19
- return string.indexOf(NewLine$2, startIndex);
118
+ const terminate = () => {
119
+ globalThis.close();
20
120
  };
21
- const mergeStacks = (parent, child) => {
22
- if (!child) {
23
- return parent;
24
- }
25
- const parentNewLineIndex = getNewLineIndex$1(parent);
26
- const childNewLineIndex = getNewLineIndex$1(child);
27
- if (childNewLineIndex === -1) {
28
- return parent;
121
+
122
+ const {
123
+ diff,
124
+ get: get$2,
125
+ getCommandIds,
126
+ registerCommands,
127
+ set: set$4,
128
+ wrapCommand,
129
+ wrapGetter
130
+ } = create$a();
131
+
132
+ // TODO parentUid might ot be needed
133
+ const create$9 = (id, uri, x, y, width, height, args, parentUid, platform = 0) => {
134
+ const state = {
135
+ accountEnabled: true,
136
+ activityBarItems: [],
137
+ currentViewletId: '',
138
+ filteredItems: [],
139
+ focus: 0,
140
+ focused: false,
141
+ focusedIndex: -1,
142
+ height,
143
+ initial: true,
144
+ itemHeight: 48,
145
+ numberOfVisibleItems: 0,
146
+ platform,
147
+ scrollBarHeight: 0,
148
+ selectedIndex: -1,
149
+ sideBarLocation: 0,
150
+ sideBarVisible: false,
151
+ uid: id,
152
+ updateProgress: 0,
153
+ updateState: '',
154
+ userLoginState: 'logged out',
155
+ width,
156
+ x,
157
+ y
158
+ };
159
+ set$4(id, state, state);
160
+ return state;
161
+ };
162
+
163
+ const hashString = value => {
164
+ let hash = 2_166_136_261;
165
+ for (const character of value) {
166
+ hash ^= character.codePointAt(0) || 0;
167
+ hash = Math.imul(hash, 16_777_619);
29
168
  }
30
- const parentFirstLine = parent.slice(0, parentNewLineIndex);
31
- const childRest = child.slice(childNewLineIndex);
32
- const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
33
- if (parentFirstLine.includes(childFirstLine)) {
34
- return parentFirstLine + childRest;
169
+ return (hash >>> 0).toString(36);
170
+ };
171
+ const isCustomIconUrl = icon => {
172
+ return icon.startsWith('http://') || icon.startsWith('https://') || icon.startsWith('file://') || icon.startsWith('/');
173
+ };
174
+ const getCustomIconClass = (id, iconUrl) => {
175
+ const hashInput = id + '\n' + iconUrl;
176
+ return `MaskIconCustomView${hashString(hashInput)}`;
177
+ };
178
+ const getIconClass = (item, builtinPrefix) => {
179
+ if (item.customIconClass) {
180
+ return item.customIconClass;
35
181
  }
36
- return child;
182
+ return `${builtinPrefix}${item.icon}`;
37
183
  };
38
- class VError extends Error {
39
- constructor(error, message) {
40
- const combinedMessage = getCombinedMessage(error, message);
41
- super(combinedMessage);
42
- this.name = 'VError';
43
- if (error instanceof Error) {
44
- this.stack = mergeStacks(this.stack, error.stack);
45
- }
46
- if (error.codeFrame) {
47
- // @ts-ignore
48
- this.codeFrame = error.codeFrame;
49
- }
50
- if (error.code) {
51
- // @ts-ignore
52
- this.code = error.code;
184
+ const escapeCssUrl = url => {
185
+ return url.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '\\a ').replaceAll('\r', '\\d ').replaceAll('\f', '\\c ');
186
+ };
187
+ const getCustomIconCss = items => {
188
+ const seen = new Set();
189
+ let css = '';
190
+ for (const item of items) {
191
+ const {
192
+ customIconClass,
193
+ customIconUrl
194
+ } = item;
195
+ if (!customIconClass || !customIconUrl || seen.has(customIconClass)) {
196
+ continue;
53
197
  }
54
- }
55
- }
56
-
57
- class AssertionError extends Error {
58
- constructor(message) {
59
- super(message);
60
- this.name = 'AssertionError';
61
- }
198
+ seen.add(customIconClass);
199
+ css += `.${customIconClass} {
200
+ mask-image: url("${escapeCssUrl(customIconUrl)}");
62
201
  }
63
- const Object$1 = 1;
64
- const Number$1 = 2;
65
- const Array$1 = 3;
66
- const String = 4;
67
- const Boolean$1 = 5;
68
- const Function = 6;
69
- const Null = 7;
70
- const Unknown = 8;
71
- const getType = value => {
72
- switch (typeof value) {
73
- case 'number':
74
- return Number$1;
75
- case 'function':
76
- return Function;
77
- case 'string':
78
- return String;
79
- case 'object':
80
- if (value === null) {
81
- return Null;
82
- }
83
- if (Array.isArray(value)) {
84
- return Array$1;
85
- }
86
- return Object$1;
87
- case 'boolean':
88
- return Boolean$1;
89
- default:
90
- return Unknown;
202
+ `;
91
203
  }
204
+ return css;
92
205
  };
93
- const number = value => {
94
- const type = getType(value);
95
- if (type !== Number$1) {
96
- throw new AssertionError('expected value to be of type number');
97
- }
206
+ const getCustomIconSignature = items => {
207
+ return items.map(item => {
208
+ if (!item.customIconClass || !item.customIconUrl) {
209
+ return '';
210
+ }
211
+ return `${item.customIconClass}\n${item.customIconUrl}`;
212
+ }).filter(Boolean).join('\n');
98
213
  };
99
214
 
100
- const isMessagePort = value => {
101
- return value && value instanceof MessagePort;
102
- };
103
- const isMessagePortMain = value => {
104
- return value && value.constructor && value.constructor.name === 'MessagePortMain';
105
- };
106
- const isOffscreenCanvas = value => {
107
- return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
215
+ const isEqual$2 = (oldState, newState) => {
216
+ return oldState.itemHeight === newState.itemHeight && getCustomIconSignature(oldState.filteredItems) === getCustomIconSignature(newState.filteredItems);
108
217
  };
109
- const isInstanceOf = (value, constructorName) => {
110
- return value?.constructor?.name === constructorName;
218
+
219
+ const isEqual$1 = (oldState, newState) => {
220
+ return oldState.focused === newState.focused && oldState.focus === newState.focus;
111
221
  };
112
- const isSocket = value => {
113
- return isInstanceOf(value, 'Socket');
222
+
223
+ const isEqual = (oldState, newState) => {
224
+ return oldState.activityBarItems === newState.activityBarItems && oldState.filteredItems === newState.filteredItems && oldState.focusedIndex === newState.focusedIndex && oldState.sideBarLocation === newState.sideBarLocation && oldState.sideBarVisible === newState.sideBarVisible && oldState.updateProgress === newState.updateProgress && oldState.updateState === newState.updateState;
114
225
  };
115
- const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
116
- const isTransferrable = value => {
117
- for (const fn of transferrables) {
118
- if (fn(value)) {
119
- return true;
120
- }
121
- }
122
- return false;
123
- };
124
- const walkValue = (value, transferrables, isTransferrable) => {
125
- if (!value) {
126
- return;
127
- }
128
- if (isTransferrable(value)) {
129
- transferrables.push(value);
130
- return;
131
- }
132
- if (Array.isArray(value)) {
133
- for (const item of value) {
134
- walkValue(item, transferrables, isTransferrable);
135
- }
136
- return;
137
- }
138
- if (typeof value === 'object') {
139
- for (const property of Object.values(value)) {
140
- walkValue(property, transferrables, isTransferrable);
141
- }
142
- return;
143
- }
144
- };
145
- const getTransferrables = value => {
146
- const transferrables = [];
147
- walkValue(value, transferrables, isTransferrable);
148
- return transferrables;
149
- };
150
- const attachEvents = that => {
151
- const handleMessage = (...args) => {
152
- const data = that.getData(...args);
153
- that.dispatchEvent(new MessageEvent('message', {
154
- data
155
- }));
156
- };
157
- that.onMessage(handleMessage);
158
- const handleClose = event => {
159
- that.dispatchEvent(new Event('close'));
160
- };
161
- that.onClose(handleClose);
162
- };
163
- class Ipc extends EventTarget {
164
- constructor(rawIpc) {
165
- super();
166
- this._rawIpc = rawIpc;
167
- attachEvents(this);
168
- }
169
- }
170
- const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
171
- const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
172
- const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
173
- const NewLine$1 = '\n';
174
- const joinLines$1 = lines => {
175
- return lines.join(NewLine$1);
176
- };
177
- const RE_AT = /^\s+at/;
178
- const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
179
- const isNormalStackLine = line => {
180
- return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
226
+
227
+ const RenderItems = 4;
228
+ const RenderFocus = 6;
229
+ const RenderFocusContext = 7;
230
+ const RenderCss = 11;
231
+ const RenderIncremental = 12;
232
+
233
+ const modules = [isEqual, isEqual$1, isEqual$1, isEqual$2];
234
+ const numbers = [RenderIncremental, RenderFocus, RenderFocusContext, RenderCss];
235
+
236
+ const diff2 = uid => {
237
+ return diff(uid, modules, numbers);
181
238
  };
182
- const getDetails = lines => {
183
- const index = lines.findIndex(isNormalStackLine);
184
- if (index === -1) {
185
- return {
186
- actualMessage: joinLines$1(lines),
187
- rest: []
188
- };
189
- }
190
- let lastIndex = index - 1;
191
- while (++lastIndex < lines.length) {
192
- if (!isNormalStackLine(lines[lastIndex])) {
193
- break;
194
- }
239
+
240
+ const List = 1;
241
+
242
+ const focus = state => {
243
+ const {
244
+ focus
245
+ } = state;
246
+ if (focus) {
247
+ return state;
195
248
  }
196
249
  return {
197
- actualMessage: lines[index - 1],
198
- rest: lines.slice(index, lastIndex)
250
+ ...state,
251
+ focus: List
199
252
  };
200
253
  };
201
- const splitLines$1 = lines => {
202
- return lines.split(NewLine$1);
203
- };
204
- const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
205
- const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
206
- const isMessageCodeBlockStartIndex = line => {
207
- return RE_MESSAGE_CODE_BLOCK_START.test(line);
208
- };
209
- const isMessageCodeBlockEndIndex = line => {
210
- return RE_MESSAGE_CODE_BLOCK_END.test(line);
211
- };
212
- const getMessageCodeBlock = stderr => {
213
- const lines = splitLines$1(stderr);
214
- const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
215
- const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
216
- const relevantLines = lines.slice(startIndex, endIndex);
217
- const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
218
- return relevantMessage;
219
- };
220
- const isModuleNotFoundMessage = line => {
221
- return line.includes('[ERR_MODULE_NOT_FOUND]');
222
- };
223
- const getModuleNotFoundError = stderr => {
224
- const lines = splitLines$1(stderr);
225
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
226
- const message = lines[messageIndex];
254
+
255
+ const focusIndex = (state, index) => {
227
256
  return {
228
- code: ERR_MODULE_NOT_FOUND,
229
- message
257
+ ...state,
258
+ focused: true,
259
+ focusedIndex: index
230
260
  };
231
261
  };
232
- const isModuleNotFoundError = stderr => {
233
- if (!stderr) {
234
- return false;
235
- }
236
- return stderr.includes('ERR_MODULE_NOT_FOUND');
237
- };
238
- const isModulesSyntaxError = stderr => {
239
- if (!stderr) {
240
- return false;
241
- }
242
- return stderr.includes('SyntaxError: Cannot use import statement outside a module');
243
- };
244
- const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
245
- const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
246
- const isUnhelpfulNativeModuleError = stderr => {
247
- return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
262
+
263
+ const focusFirst = state => {
264
+ return focusIndex(state, -1);
248
265
  };
249
- const getNativeModuleErrorMessage = stderr => {
250
- const message = getMessageCodeBlock(stderr);
251
- return {
252
- code: E_INCOMPATIBLE_NATIVE_MODULE,
253
- message: `Incompatible native node module: ${message}`
254
- };
266
+
267
+ const focusLast = state => {
268
+ return focusIndex(state, -1);
255
269
  };
256
- const getModuleSyntaxError = () => {
257
- return {
258
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
259
- message: `ES Modules are not supported in electron`
260
- };
270
+
271
+ const focusNext = state => {
272
+ return focusIndex(state, -1);
261
273
  };
262
- const getHelpfulChildProcessError = (stdout, stderr) => {
263
- if (isUnhelpfulNativeModuleError(stderr)) {
264
- return getNativeModuleErrorMessage(stderr);
265
- }
266
- if (isModulesSyntaxError(stderr)) {
267
- return getModuleSyntaxError();
268
- }
269
- if (isModuleNotFoundError(stderr)) {
270
- return getModuleNotFoundError(stderr);
271
- }
272
- const lines = splitLines$1(stderr);
274
+
275
+ const focusNone = state => {
273
276
  const {
274
- actualMessage,
275
- rest
276
- } = getDetails(lines);
277
- return {
278
- code: '',
279
- message: actualMessage,
280
- stack: rest
281
- };
282
- };
283
- class IpcError extends VError {
284
- // @ts-ignore
285
- constructor(betterMessage, stdout = '', stderr = '') {
286
- if (stdout || stderr) {
287
- // @ts-ignore
288
- const {
289
- code,
290
- message,
291
- stack
292
- } = getHelpfulChildProcessError(stdout, stderr);
293
- const cause = new Error(message);
294
- // @ts-ignore
295
- cause.code = code;
296
- cause.stack = stack;
297
- super(cause, betterMessage);
298
- } else {
299
- super(betterMessage);
300
- }
301
- // @ts-ignore
302
- this.name = 'IpcError';
303
- // @ts-ignore
304
- this.stdout = stdout;
305
- // @ts-ignore
306
- this.stderr = stderr;
307
- }
308
- }
309
- const readyMessage = 'ready';
310
- const getData$2 = event => {
311
- return event.data;
312
- };
313
- const listen$7 = () => {
314
- // @ts-ignore
315
- if (typeof WorkerGlobalScope === 'undefined') {
316
- throw new TypeError('module is not in web worker scope');
277
+ focusedIndex
278
+ } = state;
279
+ if (focusedIndex === -1) {
280
+ return state;
317
281
  }
318
- return globalThis;
319
- };
320
- const signal$8 = global => {
321
- global.postMessage(readyMessage);
282
+ return focusIndex(state, -1);
322
283
  };
323
- class IpcChildWithModuleWorker extends Ipc {
324
- getData(event) {
325
- return getData$2(event);
326
- }
327
- send(message) {
328
- // @ts-ignore
329
- this._rawIpc.postMessage(message);
330
- }
331
- sendAndTransfer(message) {
332
- const transfer = getTransferrables(message);
333
- // @ts-ignore
334
- this._rawIpc.postMessage(message, transfer);
335
- }
336
- dispose() {
337
- // ignore
338
- }
339
- onClose(callback) {
340
- // ignore
341
- }
342
- onMessage(callback) {
343
- this._rawIpc.addEventListener('message', callback);
344
- }
345
- }
346
- const wrap$f = global => {
347
- return new IpcChildWithModuleWorker(global);
284
+
285
+ const Button$2 = 'button';
286
+ const None$1 = 'none';
287
+ const Tab$1 = 'tab';
288
+ const ToolBar = 'toolbar';
289
+
290
+ const Div = 4;
291
+ const Text = 12;
292
+ const Reference = 100;
293
+
294
+ const Button$1 = 'event.button';
295
+ const ClientX = 'event.clientX';
296
+ const ClientY = 'event.clientY';
297
+
298
+ const Enter = 3;
299
+ const Space = 9;
300
+ const PageUp = 10;
301
+ const PageDown = 11;
302
+ const End = 255;
303
+ const Home = 12;
304
+ const UpArrow = 14;
305
+ const DownArrow = 16;
306
+
307
+ const ActivityBar$3 = 1;
308
+ const Settings$1 = 12;
309
+ const ActivityBarAdditionalViews = 17;
310
+
311
+ const Separator = 1;
312
+ const None = 0;
313
+ const Checked = 2;
314
+ const Unchecked = 3;
315
+
316
+ const LeftClick = 0;
317
+
318
+ const Web = 1;
319
+
320
+ const ExtensionManagementWorker = 9006;
321
+ const RendererWorker = 1;
322
+
323
+ const Left = 1;
324
+ const Right = 2;
325
+
326
+ const SetCss = 'Viewlet.setCss';
327
+ const SetDom2 = 'Viewlet.setDom2';
328
+ const SetFocusContext = 'Viewlet.setFocusContext';
329
+ const SetPatches = 'Viewlet.setPatches';
330
+
331
+ const FocusActivityBar = 5;
332
+ const FocusExplorer = 13;
333
+
334
+ const getKeyBindings = () => {
335
+ return [{
336
+ command: 'ActivityBar.focusNext',
337
+ key: DownArrow,
338
+ when: FocusActivityBar
339
+ }, {
340
+ command: 'ActivityBar.focusPrevious',
341
+ key: UpArrow,
342
+ when: FocusActivityBar
343
+ }, {
344
+ command: 'ActivityBar.focusFirst',
345
+ key: Home,
346
+ when: FocusActivityBar
347
+ }, {
348
+ command: 'ActivityBar.focusFirst',
349
+ key: PageUp,
350
+ when: FocusActivityBar
351
+ }, {
352
+ command: 'ActivityBar.focusLast',
353
+ key: PageDown,
354
+ when: FocusActivityBar
355
+ }, {
356
+ command: 'ActivityBar.focusLast',
357
+ key: End,
358
+ when: FocusActivityBar
359
+ }, {
360
+ command: 'ActivityBar.selectCurrent',
361
+ key: Space,
362
+ when: FocusActivityBar
363
+ }, {
364
+ command: 'ActivityBar.selectCurrent',
365
+ key: Enter,
366
+ when: FocusActivityBar
367
+ }];
348
368
  };
349
- const waitForFirstMessage = async port => {
369
+
370
+ const getMenuEntriesAccountLoggedIn = state => {
350
371
  const {
351
- promise,
352
- resolve
353
- } = Promise.withResolvers();
354
- port.addEventListener('message', resolve, {
355
- once: true
356
- });
357
- const event = await promise;
358
- // @ts-ignore
359
- return event.data;
372
+ userLoginState
373
+ } = state;
374
+ const signOutLabel = userLoginState === 'logging out' ? 'Signing Out...' : 'Sign Out';
375
+ return [{
376
+ command: 'ActivityBar.handleClickSignOut',
377
+ flags: None,
378
+ id: 'signOut',
379
+ label: signOutLabel
380
+ }];
360
381
  };
361
- const listen$6 = async () => {
362
- const parentIpcRaw = listen$7();
363
- signal$8(parentIpcRaw);
364
- const parentIpc = wrap$f(parentIpcRaw);
365
- const firstMessage = await waitForFirstMessage(parentIpc);
366
- if (firstMessage.method !== 'initialize') {
367
- throw new IpcError('unexpected first message');
368
- }
369
- const type = firstMessage.params[0];
370
- if (type === 'message-port') {
371
- parentIpc.send({
372
- id: firstMessage.id,
373
- jsonrpc: '2.0',
374
- result: null
375
- });
376
- parentIpc.dispose();
377
- const port = firstMessage.params[1];
378
- return port;
379
- }
380
- return globalThis;
382
+ const getMenuEntriesAccountLoggedOut = state => {
383
+ const {
384
+ userLoginState
385
+ } = state;
386
+ const signInLabel = userLoginState === 'logging in' ? 'Signing In...' : 'Sign In';
387
+ return [{
388
+ command: 'ActivityBar.handleClickSignIn',
389
+ flags: None,
390
+ id: 'signIn',
391
+ label: signInLabel
392
+ }];
381
393
  };
382
- class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
383
- getData(event) {
384
- return getData$2(event);
385
- }
386
- send(message) {
387
- this._rawIpc.postMessage(message);
388
- }
389
- sendAndTransfer(message) {
390
- const transfer = getTransferrables(message);
391
- this._rawIpc.postMessage(message, transfer);
392
- }
393
- dispose() {
394
- if (this._rawIpc.close) {
395
- this._rawIpc.close();
396
- }
397
- }
398
- onClose(callback) {
399
- // ignore
400
- }
401
- onMessage(callback) {
402
- this._rawIpc.addEventListener('message', callback);
403
- this._rawIpc.start();
394
+ const getMenuEntriesAccount = state => {
395
+ // TODO maybe query it now from layout?
396
+ const {
397
+ userLoginState
398
+ } = state;
399
+ if (userLoginState === 'logged in' || userLoginState === 'logging out') {
400
+ return getMenuEntriesAccountLoggedIn(state);
404
401
  }
405
- }
406
- const wrap$e = port => {
407
- return new IpcChildWithModuleWorkerAndMessagePort(port);
408
- };
409
- const IpcChildWithModuleWorkerAndMessagePort$1 = {
410
- __proto__: null,
411
- listen: listen$6,
412
- wrap: wrap$e
402
+ return getMenuEntriesAccountLoggedOut(state);
413
403
  };
414
- const addListener = (emitter, type, callback) => {
415
- if ('addEventListener' in emitter) {
416
- emitter.addEventListener(type, callback);
417
- } else {
418
- emitter.on(type, callback);
404
+
405
+ const Tab = 1;
406
+ const Button = 1 << 1;
407
+ const Progress = 1 << 2;
408
+ const Enabled = 1 << 3;
409
+ const Selected = 1 << 4;
410
+ const Focused = 1 << 5;
411
+ const MarginTop = 1 << 6;
412
+
413
+ const emptyObject = {};
414
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
415
+ const i18nString = (key, placeholders = emptyObject) => {
416
+ if (placeholders === emptyObject) {
417
+ return key;
419
418
  }
419
+ const replacer = (match, rest) => {
420
+ return placeholders[rest];
421
+ };
422
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
420
423
  };
421
- const removeListener = (emitter, type, callback) => {
422
- if ('removeEventListener' in emitter) {
423
- emitter.removeEventListener(type, callback);
424
- } else {
425
- emitter.off(type, callback);
426
- }
424
+
425
+ const Account$1 = 'Account';
426
+ const Explorer$1 = 'Explorer';
427
+ const Search$2 = 'Search';
428
+ const SourceControl$2 = 'Source Control';
429
+ const RunAndDebug$1 = 'Run and Debug';
430
+ const Extensions$2 = 'Extensions';
431
+ const Settings = 'Settings';
432
+ const AdditionalViews = 'Additional Views';
433
+ const ActivityBar$2 = 'Activity Bar';
434
+ const MoveSideBarLeft = 'Move Side Bar Left';
435
+ const MoveSideBarRight = 'Move Side Bar Right';
436
+ const HideActivityBar = 'Hide Activity Bar';
437
+ const CheckForUpdates = 'Check For Updates';
438
+ const ColorTheme = 'Color Theme';
439
+ const CommandPalette = 'Command Palette';
440
+ const KeyboardShortcuts = 'Keyboard Shortcuts';
441
+
442
+ const account = () => {
443
+ return i18nString(Account$1);
427
444
  };
428
- const getFirstEvent = (eventEmitter, eventMap) => {
429
- const {
430
- promise,
431
- resolve
432
- } = Promise.withResolvers();
433
- const listenerMap = Object.create(null);
434
- const cleanup = value => {
435
- for (const event of Object.keys(eventMap)) {
436
- removeListener(eventEmitter, event, listenerMap[event]);
437
- }
438
- resolve(value);
439
- };
440
- for (const [event, type] of Object.entries(eventMap)) {
441
- const listener = event => {
442
- cleanup({
443
- event,
444
- type
445
- });
446
- };
447
- addListener(eventEmitter, event, listener);
448
- listenerMap[event] = listener;
449
- }
450
- return promise;
445
+ const explorer = () => {
446
+ return i18nString(Explorer$1);
451
447
  };
452
- const Message$1 = 3;
453
- const create$5$1 = async ({
454
- isMessagePortOpen,
455
- messagePort
456
- }) => {
457
- if (!isMessagePort(messagePort)) {
458
- throw new IpcError('port must be of type MessagePort');
459
- }
460
- if (isMessagePortOpen) {
461
- return messagePort;
462
- }
463
- const eventPromise = getFirstEvent(messagePort, {
464
- message: Message$1
465
- });
466
- messagePort.start();
467
- const {
468
- event,
469
- type
470
- } = await eventPromise;
471
- if (type !== Message$1) {
472
- throw new IpcError('Failed to wait for ipc message');
473
- }
474
- if (event.data !== readyMessage) {
475
- throw new IpcError('unexpected first message');
476
- }
477
- return messagePort;
478
- };
479
- const signal$1 = messagePort => {
480
- messagePort.start();
448
+ const search = () => {
449
+ return i18nString(Search$2);
481
450
  };
482
- class IpcParentWithMessagePort extends Ipc {
483
- getData = getData$2;
484
- send(message) {
485
- this._rawIpc.postMessage(message);
486
- }
487
- sendAndTransfer(message) {
488
- const transfer = getTransferrables(message);
489
- this._rawIpc.postMessage(message, transfer);
490
- }
491
- dispose() {
492
- this._rawIpc.close();
493
- }
494
- onMessage(callback) {
495
- this._rawIpc.addEventListener('message', callback);
496
- }
497
- onClose(callback) {}
498
- }
499
- const wrap$5 = messagePort => {
500
- return new IpcParentWithMessagePort(messagePort);
451
+ const sourceControl = () => {
452
+ return i18nString(SourceControl$2);
501
453
  };
502
- const IpcParentWithMessagePort$1 = {
503
- __proto__: null,
504
- create: create$5$1,
505
- signal: signal$1,
506
- wrap: wrap$5
454
+ const runAndDebug = () => {
455
+ return i18nString(RunAndDebug$1);
507
456
  };
508
-
509
- class CommandNotFoundError extends Error {
510
- constructor(command) {
511
- super(`Command not found ${command}`);
512
- this.name = 'CommandNotFoundError';
513
- }
514
- }
515
- const commands = Object.create(null);
516
- const register = commandMap => {
517
- Object.assign(commands, commandMap);
457
+ const extensions = () => {
458
+ return i18nString(Extensions$2);
518
459
  };
519
- const getCommand = key => {
520
- return commands[key];
460
+ const settings = () => {
461
+ return i18nString(Settings);
521
462
  };
522
- const execute = (command, ...args) => {
523
- const fn = getCommand(command);
524
- if (!fn) {
525
- throw new CommandNotFoundError(command);
526
- }
527
- return fn(...args);
463
+ const additionalViews = () => {
464
+ return i18nString(AdditionalViews);
528
465
  };
529
-
530
- const Two$1 = '2.0';
531
- const callbacks = Object.create(null);
532
- const get$2 = id => {
533
- return callbacks[id];
466
+ const activityBar = () => {
467
+ return i18nString(ActivityBar$2);
534
468
  };
535
- const remove$1 = id => {
536
- delete callbacks[id];
469
+ const moveSideBarRight = () => {
470
+ return i18nString(MoveSideBarRight);
537
471
  };
538
- class JsonRpcError extends Error {
539
- constructor(message) {
540
- super(message);
541
- this.name = 'JsonRpcError';
542
- }
543
- }
544
- const NewLine = '\n';
545
- const DomException = 'DOMException';
546
- const ReferenceError$1 = 'ReferenceError';
547
- const SyntaxError$1 = 'SyntaxError';
548
- const TypeError$1 = 'TypeError';
549
- const getErrorConstructor = (message, type) => {
550
- if (type) {
551
- switch (type) {
552
- case DomException:
553
- return DOMException;
554
- case ReferenceError$1:
555
- return ReferenceError;
556
- case SyntaxError$1:
557
- return SyntaxError;
558
- case TypeError$1:
559
- return TypeError;
560
- default:
561
- return Error;
562
- }
563
- }
564
- if (message.startsWith('TypeError: ')) {
565
- return TypeError;
566
- }
567
- if (message.startsWith('SyntaxError: ')) {
568
- return SyntaxError;
569
- }
570
- if (message.startsWith('ReferenceError: ')) {
571
- return ReferenceError;
572
- }
573
- return Error;
472
+ const moveSideBarLeft = () => {
473
+ return i18nString(MoveSideBarLeft);
574
474
  };
575
- const constructError = (message, type, name) => {
576
- const ErrorConstructor = getErrorConstructor(message, type);
577
- if (ErrorConstructor === DOMException && name) {
578
- return new ErrorConstructor(message, name);
579
- }
580
- if (ErrorConstructor === Error) {
581
- const error = new Error(message);
582
- if (name && name !== 'VError') {
583
- error.name = name;
584
- }
585
- return error;
586
- }
587
- return new ErrorConstructor(message);
475
+ const hideActivityBar = () => {
476
+ return i18nString(HideActivityBar);
588
477
  };
589
- const joinLines = lines => {
590
- return lines.join(NewLine);
478
+ const checkForUpdates = () => {
479
+ return i18nString(CheckForUpdates);
591
480
  };
592
- const splitLines = lines => {
593
- return lines.split(NewLine);
481
+ const commandPalette = () => {
482
+ return i18nString(CommandPalette);
594
483
  };
595
- const getCurrentStack = () => {
596
- const stackLinesToSkip = 3;
597
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
598
- return currentStack;
484
+ const keyboardShortcuts = () => {
485
+ return i18nString(KeyboardShortcuts);
599
486
  };
600
- const getNewLineIndex = (string, startIndex = undefined) => {
601
- return string.indexOf(NewLine, startIndex);
487
+ const colorTheme = () => {
488
+ return i18nString(ColorTheme);
602
489
  };
603
- const getParentStack = error => {
604
- let parentStack = error.stack || error.data || error.message || '';
605
- if (parentStack.startsWith(' at')) {
606
- parentStack = error.message + NewLine + parentStack;
490
+
491
+ const menuEntryMoveSideBar = sideBarLocation => {
492
+ switch (sideBarLocation) {
493
+ case Left:
494
+ return {
495
+ command: 'Layout.moveSideBarRight',
496
+ flags: None,
497
+ id: 'moveSideBarRight',
498
+ label: moveSideBarRight()
499
+ };
500
+ case Right:
501
+ return {
502
+ command: 'Layout.moveSideBarLeft',
503
+ flags: None,
504
+ id: 'moveSideBarLeft',
505
+ label: moveSideBarLeft()
506
+ };
507
+ default:
508
+ throw new Error('unexpected side bar location');
607
509
  }
608
- return parentStack;
609
510
  };
610
- const MethodNotFound = -32601;
611
- const Custom = -32001;
612
- const restoreJsonRpcError = error => {
613
- const currentStack = getCurrentStack();
614
- if (error && error instanceof Error) {
615
- if (typeof error.stack === 'string') {
616
- error.stack = error.stack + NewLine + currentStack;
617
- }
618
- return error;
511
+
512
+ const menuEntrySeparator = {
513
+ command: '',
514
+ flags: Separator,
515
+ id: 'separator',
516
+ label: ''
517
+ };
518
+
519
+ const toContextMenuItem$1 = activityBarItem => {
520
+ const isEnabled = activityBarItem.flags & Enabled;
521
+ return {
522
+ args: [activityBarItem.id],
523
+ command: 'ActivityBar.toggleActivityBarItem',
524
+ flags: isEnabled ? Checked : Unchecked,
525
+ id: `toggle-${activityBarItem.id}`,
526
+ label: activityBarItem.id
527
+ };
528
+ };
529
+
530
+ const getMenuEntriesActivityBar = state => {
531
+ const {
532
+ activityBarItems,
533
+ sideBarLocation
534
+ } = state;
535
+ const topItems = activityBarItems.filter(item => !(item.flags & Button));
536
+ const bottomItems = activityBarItems.filter(item => item.flags & Button);
537
+ const entries = topItems.map(toContextMenuItem$1);
538
+ if (bottomItems.length > 0) {
539
+ entries.push(menuEntrySeparator, ...bottomItems.map(toContextMenuItem$1));
619
540
  }
620
- if (error && error.code && error.code === MethodNotFound) {
621
- const restoredError = new JsonRpcError(error.message);
622
- const parentStack = getParentStack(error);
623
- restoredError.stack = parentStack + NewLine + currentStack;
624
- return restoredError;
541
+ return [...entries, menuEntrySeparator, menuEntryMoveSideBar(sideBarLocation), {
542
+ command: 'Layout.hideActivityBar',
543
+ flags: None,
544
+ id: 'hideActivityBar',
545
+ label: hideActivityBar()
546
+ }];
547
+ };
548
+
549
+ const getNumberOfVisibleItems = state => {
550
+ const {
551
+ height,
552
+ itemHeight
553
+ } = state;
554
+ const numberOfVisibleItemsTop = Math.floor(height / itemHeight);
555
+ return numberOfVisibleItemsTop;
556
+ };
557
+ const getHiddenItems = state => {
558
+ const numberOfVisibleItems = getNumberOfVisibleItems(state);
559
+ const items = state.activityBarItems.filter(item => item.flags & Enabled);
560
+ if (numberOfVisibleItems >= items.length) {
561
+ return [];
625
562
  }
626
- if (error && error.message) {
627
- const restoredError = constructError(error.message, error.type, error.name);
628
- if (error.data) {
629
- if (error.data.stack && error.data.type && error.message) {
630
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
631
- } else if (error.data.stack) {
632
- restoredError.stack = error.data.stack;
633
- }
634
- if (error.data.codeFrame) {
635
- // @ts-ignore
636
- restoredError.codeFrame = error.data.codeFrame;
637
- }
638
- if (error.data.code) {
639
- // @ts-ignore
640
- restoredError.code = error.data.code;
641
- }
642
- if (error.data.type) {
643
- // @ts-ignore
644
- restoredError.name = error.data.type;
645
- }
646
- } else {
647
- if (error.stack) {
648
- const lowerStack = restoredError.stack || '';
649
- // @ts-ignore
650
- const indexNewLine = getNewLineIndex(lowerStack);
651
- const parentStack = getParentStack(error);
652
- // @ts-ignore
653
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
654
- }
655
- if (error.codeFrame) {
656
- // @ts-ignore
657
- restoredError.codeFrame = error.codeFrame;
658
- }
659
- }
660
- return restoredError;
661
- }
662
- if (typeof error === 'string') {
663
- return new Error(`JsonRpc Error: ${error}`);
563
+ return items.slice(numberOfVisibleItems - 2, -1);
564
+ };
565
+
566
+ const toContextMenuItem = activityBarItem => {
567
+ return {
568
+ command: '-1',
569
+ // TODO
570
+ flags: None,
571
+ id: '8000',
572
+ // TODO
573
+ label: activityBarItem.id
574
+ };
575
+ };
576
+ const getMenuEntriesAdditionalViews = state => {
577
+ const hiddenActivityBarItems = getHiddenItems(state);
578
+ return hiddenActivityBarItems.map(toContextMenuItem);
579
+ };
580
+
581
+ const keyBindingsUri = 'app://keybindings';
582
+ const getMenuEntriesSettings = state => {
583
+ const {
584
+ platform
585
+ } = state;
586
+ const items = [{
587
+ command: 'QuickPick.showEverything',
588
+ flags: None,
589
+ id: 'commandPalette',
590
+ label: commandPalette()
591
+ }, menuEntrySeparator, {
592
+ command: 'Preferences.openSettingsJson',
593
+ flags: None,
594
+ id: 'settings',
595
+ label: settings()
596
+ }, {
597
+ args: [keyBindingsUri],
598
+ command: 'Main.openUri',
599
+ flags: None,
600
+ id: 'keyboardShortcuts',
601
+ label: keyboardShortcuts()
602
+ }, {
603
+ command: 'QuickPick.showColorTheme',
604
+ flags: None,
605
+ id: 'colorTheme',
606
+ label: colorTheme()
607
+ }];
608
+ if (platform !== Web) {
609
+ items.push(menuEntrySeparator, {
610
+ command: 'AutoUpdater.checkForUpdates',
611
+ flags: None,
612
+ id: 'checkForUpdates',
613
+ label: checkForUpdates()
614
+ });
664
615
  }
665
- return new Error(`JsonRpc Error: ${error}`);
616
+ return items;
666
617
  };
667
- const unwrapJsonRpcResult = responseMessage => {
668
- if ('error' in responseMessage) {
669
- const restoredError = restoreJsonRpcError(responseMessage.error);
670
- throw restoredError;
618
+
619
+ const normalizeLine = line => {
620
+ if (line.startsWith('Error: ')) {
621
+ return line.slice('Error: '.length);
671
622
  }
672
- if ('result' in responseMessage) {
673
- return responseMessage.result;
623
+ if (line.startsWith('VError: ')) {
624
+ return line.slice('VError: '.length);
674
625
  }
675
- throw new JsonRpcError('unexpected response message');
676
- };
677
- const warn = (...args) => {
678
- console.warn(...args);
626
+ return line;
679
627
  };
680
- const resolve = (id, response) => {
681
- const fn = get$2(id);
682
- if (!fn) {
683
- console.log(response);
684
- warn(`callback ${id} may already be disposed`);
685
- return;
628
+ const getCombinedMessage = (error, message) => {
629
+ const stringifiedError = normalizeLine(`${error}`);
630
+ if (message) {
631
+ return `${message}: ${stringifiedError}`;
686
632
  }
687
- fn(response);
688
- remove$1(id);
633
+ return stringifiedError;
689
634
  };
690
- const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
691
- const getErrorType = prettyError => {
692
- if (prettyError && prettyError.type) {
693
- return prettyError.type;
635
+ const NewLine$2 = '\n';
636
+ const getNewLineIndex$1 = (string, startIndex = undefined) => {
637
+ return string.indexOf(NewLine$2, startIndex);
638
+ };
639
+ const mergeStacks = (parent, child) => {
640
+ if (!child) {
641
+ return parent;
694
642
  }
695
- if (prettyError && prettyError.constructor && prettyError.constructor.name) {
696
- return prettyError.constructor.name;
643
+ const parentNewLineIndex = getNewLineIndex$1(parent);
644
+ const childNewLineIndex = getNewLineIndex$1(child);
645
+ if (childNewLineIndex === -1) {
646
+ return parent;
697
647
  }
698
- return undefined;
699
- };
700
- const isAlreadyStack = line => {
701
- return line.trim().startsWith('at ');
648
+ const parentFirstLine = parent.slice(0, parentNewLineIndex);
649
+ const childRest = child.slice(childNewLineIndex);
650
+ const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
651
+ if (parentFirstLine.includes(childFirstLine)) {
652
+ return parentFirstLine + childRest;
653
+ }
654
+ return child;
702
655
  };
703
- const getStack = prettyError => {
704
- const stackString = prettyError.stack || '';
705
- const newLineIndex = stackString.indexOf('\n');
706
- if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
707
- return stackString.slice(newLineIndex + 1);
656
+ class VError extends Error {
657
+ constructor(error, message) {
658
+ const combinedMessage = getCombinedMessage(error, message);
659
+ super(combinedMessage);
660
+ this.name = 'VError';
661
+ if (error instanceof Error) {
662
+ this.stack = mergeStacks(this.stack, error.stack);
663
+ }
664
+ if (error.codeFrame) {
665
+ // @ts-ignore
666
+ this.codeFrame = error.codeFrame;
667
+ }
668
+ if (error.code) {
669
+ // @ts-ignore
670
+ this.code = error.code;
671
+ }
672
+ }
673
+ }
674
+
675
+ class AssertionError extends Error {
676
+ constructor(message) {
677
+ super(message);
678
+ this.name = 'AssertionError';
679
+ }
680
+ }
681
+ const Object$1 = 1;
682
+ const Number$1 = 2;
683
+ const Array$1 = 3;
684
+ const String$1 = 4;
685
+ const Boolean$1 = 5;
686
+ const Function = 6;
687
+ const Null = 7;
688
+ const Unknown = 8;
689
+ const getType = value => {
690
+ switch (typeof value) {
691
+ case 'number':
692
+ return Number$1;
693
+ case 'function':
694
+ return Function;
695
+ case 'string':
696
+ return String$1;
697
+ case 'object':
698
+ if (value === null) {
699
+ return Null;
700
+ }
701
+ if (Array.isArray(value)) {
702
+ return Array$1;
703
+ }
704
+ return Object$1;
705
+ case 'boolean':
706
+ return Boolean$1;
707
+ default:
708
+ return Unknown;
708
709
  }
709
- return stackString;
710
710
  };
711
- const getErrorProperty = (error, prettyError) => {
712
- if (error && error.code === E_COMMAND_NOT_FOUND) {
713
- return {
714
- code: MethodNotFound,
715
- data: error.stack,
716
- message: error.message
717
- };
711
+ const number = value => {
712
+ const type = getType(value);
713
+ if (type !== Number$1) {
714
+ throw new AssertionError('expected value to be of type number');
718
715
  }
719
- return {
720
- code: Custom,
721
- data: {
722
- code: prettyError.code,
723
- codeFrame: prettyError.codeFrame,
724
- name: prettyError.name,
725
- stack: getStack(prettyError),
726
- type: getErrorType(prettyError)
727
- },
728
- message: prettyError.message
729
- };
730
716
  };
731
- const create$1$1 = (id, error) => {
732
- return {
733
- error,
734
- id,
735
- jsonrpc: Two$1
736
- };
717
+
718
+ const isMessagePort = value => {
719
+ return value && value instanceof MessagePort;
737
720
  };
738
- const getErrorResponse = (id, error, preparePrettyError, logError) => {
739
- const prettyError = preparePrettyError(error);
740
- logError(error, prettyError);
741
- const errorProperty = getErrorProperty(error, prettyError);
742
- return create$1$1(id, errorProperty);
721
+ const isMessagePortMain = value => {
722
+ return value && value.constructor && value.constructor.name === 'MessagePortMain';
743
723
  };
744
- const create$a = (message, result) => {
745
- return {
746
- id: message.id,
747
- jsonrpc: Two$1,
748
- result: result ?? null
749
- };
724
+ const isOffscreenCanvas = value => {
725
+ return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
750
726
  };
751
- const getSuccessResponse = (message, result) => {
752
- const resultProperty = result ?? null;
753
- return create$a(message, resultProperty);
727
+ const isInstanceOf = (value, constructorName) => {
728
+ return value?.constructor?.name === constructorName;
754
729
  };
755
- const getErrorResponseSimple = (id, error) => {
756
- return {
757
- error: {
758
- code: Custom,
759
- data: error,
760
- // @ts-ignore
761
- message: error.message
762
- },
763
- id,
764
- jsonrpc: Two$1
765
- };
730
+ const isSocket = value => {
731
+ return isInstanceOf(value, 'Socket');
766
732
  };
767
- const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
768
- try {
769
- const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
770
- return getSuccessResponse(message, result);
771
- } catch (error) {
772
- if (ipc.canUseSimpleErrorResponse) {
773
- return getErrorResponseSimple(message.id, error);
733
+ const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
734
+ const isTransferrable = value => {
735
+ for (const fn of transferrables) {
736
+ if (fn(value)) {
737
+ return true;
774
738
  }
775
- return getErrorResponse(message.id, error, preparePrettyError, logError);
776
739
  }
777
- };
778
- const defaultPreparePrettyError = error => {
779
- return error;
780
- };
781
- const defaultLogError = () => {
782
- // ignore
783
- };
784
- const defaultRequiresSocket = () => {
785
740
  return false;
786
741
  };
787
- const defaultResolve = resolve;
788
-
789
- // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
790
- const normalizeParams = args => {
791
- if (args.length === 1) {
792
- const options = args[0];
793
- return {
794
- execute: options.execute,
795
- ipc: options.ipc,
796
- logError: options.logError || defaultLogError,
797
- message: options.message,
798
- preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
799
- requiresSocket: options.requiresSocket || defaultRequiresSocket,
800
- resolve: options.resolve || defaultResolve
801
- };
742
+ const walkValue = (value, transferrables, isTransferrable) => {
743
+ if (!value) {
744
+ return;
802
745
  }
803
- return {
804
- execute: args[2],
805
- ipc: args[0],
806
- logError: args[5],
807
- message: args[1],
808
- preparePrettyError: args[4],
809
- requiresSocket: args[6],
810
- resolve: args[3]
811
- };
812
- };
813
- const handleJsonRpcMessage = async (...args) => {
814
- const options = normalizeParams(args);
815
- const {
816
- execute,
817
- ipc,
818
- logError,
819
- message,
820
- preparePrettyError,
821
- requiresSocket,
822
- resolve
823
- } = options;
824
- if ('id' in message) {
825
- if ('method' in message) {
826
- const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
827
- try {
828
- ipc.send(response);
829
- } catch (error) {
830
- const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
831
- ipc.send(errorResponse);
832
- }
833
- return;
746
+ if (isTransferrable(value)) {
747
+ transferrables.push(value);
748
+ return;
749
+ }
750
+ if (Array.isArray(value)) {
751
+ for (const item of value) {
752
+ walkValue(item, transferrables, isTransferrable);
834
753
  }
835
- resolve(message.id, message);
836
754
  return;
837
755
  }
838
- if ('method' in message) {
839
- await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
756
+ if (typeof value === 'object') {
757
+ for (const property of Object.values(value)) {
758
+ walkValue(property, transferrables, isTransferrable);
759
+ }
840
760
  return;
841
761
  }
842
- throw new JsonRpcError('unexpected message');
843
762
  };
844
-
845
- const Two = '2.0';
846
-
847
- const create$9 = (method, params) => {
848
- return {
849
- jsonrpc: Two,
850
- method,
851
- params
852
- };
763
+ const getTransferrables = value => {
764
+ const transferrables = [];
765
+ walkValue(value, transferrables, isTransferrable);
766
+ return transferrables;
853
767
  };
854
-
855
- const create$8 = (id, method, params) => {
856
- const message = {
857
- id,
858
- jsonrpc: Two,
859
- method,
860
- params
768
+ const attachEvents = that => {
769
+ const handleMessage = (...args) => {
770
+ const data = that.getData(...args);
771
+ that.dispatchEvent(new MessageEvent('message', {
772
+ data
773
+ }));
861
774
  };
862
- return message;
863
- };
864
-
865
- let id = 0;
866
- const create$7 = () => {
867
- return ++id;
868
- };
869
-
870
- const registerPromise = map => {
871
- const id = create$7();
872
- const {
873
- promise,
874
- resolve
875
- } = Promise.withResolvers();
876
- map[id] = resolve;
877
- return {
878
- id,
879
- promise
775
+ that.onMessage(handleMessage);
776
+ const handleClose = event => {
777
+ that.dispatchEvent(new Event('close'));
880
778
  };
779
+ that.onClose(handleClose);
881
780
  };
882
-
883
- const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
884
- const {
885
- id,
886
- promise
887
- } = registerPromise(callbacks);
888
- const message = create$8(id, method, params);
889
- if (useSendAndTransfer && ipc.sendAndTransfer) {
890
- ipc.sendAndTransfer(message);
891
- } else {
892
- ipc.send(message);
781
+ class Ipc extends EventTarget {
782
+ constructor(rawIpc) {
783
+ super();
784
+ this._rawIpc = rawIpc;
785
+ attachEvents(this);
893
786
  }
894
- const responseMessage = await promise;
895
- return unwrapJsonRpcResult(responseMessage);
787
+ }
788
+ const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
789
+ const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
790
+ const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
791
+ const NewLine$1 = '\n';
792
+ const joinLines$1 = lines => {
793
+ return lines.join(NewLine$1);
896
794
  };
897
- const createRpc = ipc => {
898
- const callbacks = Object.create(null);
899
- ipc._resolve = (id, response) => {
900
- const fn = callbacks[id];
901
- if (!fn) {
902
- console.warn(`callback ${id} may already be disposed`);
903
- return;
904
- }
905
- fn(response);
906
- delete callbacks[id];
907
- };
908
- const rpc = {
909
- async dispose() {
910
- await ipc?.dispose();
911
- },
912
- invoke(method, ...params) {
913
- return invokeHelper(callbacks, ipc, method, params, false);
914
- },
915
- invokeAndTransfer(method, ...params) {
916
- return invokeHelper(callbacks, ipc, method, params, true);
917
- },
918
- // @ts-ignore
919
- ipc,
920
- /**
921
- * @deprecated
922
- */
923
- send(method, ...params) {
924
- const message = create$9(method, params);
925
- ipc.send(message);
795
+ const RE_AT = /^\s+at/;
796
+ const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
797
+ const isNormalStackLine = line => {
798
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
799
+ };
800
+ const getDetails = lines => {
801
+ const index = lines.findIndex(isNormalStackLine);
802
+ if (index === -1) {
803
+ return {
804
+ actualMessage: joinLines$1(lines),
805
+ rest: []
806
+ };
807
+ }
808
+ let lastIndex = index - 1;
809
+ while (++lastIndex < lines.length) {
810
+ if (!isNormalStackLine(lines[lastIndex])) {
811
+ break;
926
812
  }
813
+ }
814
+ return {
815
+ actualMessage: lines[index - 1],
816
+ rest: lines.slice(index, lastIndex)
927
817
  };
928
- return rpc;
929
818
  };
930
-
931
- const requiresSocket = () => {
932
- return false;
933
- };
934
- const preparePrettyError = error => {
935
- return error;
819
+ const splitLines$1 = lines => {
820
+ return lines.split(NewLine$1);
936
821
  };
937
- const logError = () => {
938
- // handled by renderer worker
822
+ const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
823
+ const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
824
+ const isMessageCodeBlockStartIndex = line => {
825
+ return RE_MESSAGE_CODE_BLOCK_START.test(line);
939
826
  };
940
- const handleMessage = event => {
941
- const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
942
- const actualExecute = event?.target?.execute || execute;
943
- return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
827
+ const isMessageCodeBlockEndIndex = line => {
828
+ return RE_MESSAGE_CODE_BLOCK_END.test(line);
944
829
  };
945
-
946
- const handleIpc = ipc => {
947
- if ('addEventListener' in ipc) {
948
- ipc.addEventListener('message', handleMessage);
949
- } else if ('on' in ipc) {
950
- // deprecated
951
- ipc.on('message', handleMessage);
952
- }
830
+ const getMessageCodeBlock = stderr => {
831
+ const lines = splitLines$1(stderr);
832
+ const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
833
+ const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
834
+ const relevantLines = lines.slice(startIndex, endIndex);
835
+ const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
836
+ return relevantMessage;
953
837
  };
954
-
955
- const listen$1 = async (module, options) => {
956
- const rawIpc = await module.listen(options);
957
- if (module.signal) {
958
- module.signal(rawIpc);
959
- }
960
- const ipc = module.wrap(rawIpc);
961
- return ipc;
838
+ const isModuleNotFoundMessage = line => {
839
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
962
840
  };
963
-
964
- const create$6 = async ({
965
- commandMap,
966
- isMessagePortOpen = true,
967
- messagePort
968
- }) => {
969
- // TODO create a commandMap per rpc instance
970
- register(commandMap);
971
- const rawIpc = await IpcParentWithMessagePort$1.create({
972
- isMessagePortOpen,
973
- messagePort
974
- });
975
- const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
976
- handleIpc(ipc);
977
- const rpc = createRpc(ipc);
978
- messagePort.start();
979
- return rpc;
980
- };
981
-
982
- const create$5 = async ({
983
- commandMap,
984
- isMessagePortOpen,
985
- send
986
- }) => {
987
- const {
988
- port1,
989
- port2
990
- } = new MessageChannel();
991
- await send(port1);
992
- return create$6({
993
- commandMap,
994
- isMessagePortOpen,
995
- messagePort: port2
996
- });
997
- };
998
-
999
- const createSharedLazyRpc = factory => {
1000
- let rpcPromise;
1001
- const getOrCreate = () => {
1002
- if (!rpcPromise) {
1003
- rpcPromise = factory();
1004
- }
1005
- return rpcPromise;
1006
- };
841
+ const getModuleNotFoundError = stderr => {
842
+ const lines = splitLines$1(stderr);
843
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
844
+ const message = lines[messageIndex];
1007
845
  return {
1008
- async dispose() {
1009
- const rpc = await getOrCreate();
1010
- await rpc.dispose();
1011
- },
1012
- async invoke(method, ...params) {
1013
- const rpc = await getOrCreate();
1014
- return rpc.invoke(method, ...params);
1015
- },
1016
- async invokeAndTransfer(method, ...params) {
1017
- const rpc = await getOrCreate();
1018
- return rpc.invokeAndTransfer(method, ...params);
1019
- },
1020
- async send(method, ...params) {
1021
- const rpc = await getOrCreate();
1022
- rpc.send(method, ...params);
1023
- }
846
+ code: ERR_MODULE_NOT_FOUND,
847
+ message
1024
848
  };
1025
849
  };
1026
-
1027
- const create$4 = async ({
1028
- commandMap,
1029
- isMessagePortOpen,
1030
- send
1031
- }) => {
1032
- return createSharedLazyRpc(() => {
1033
- return create$5({
1034
- commandMap,
1035
- isMessagePortOpen,
1036
- send
1037
- });
1038
- });
850
+ const isModuleNotFoundError = stderr => {
851
+ if (!stderr) {
852
+ return false;
853
+ }
854
+ return stderr.includes('ERR_MODULE_NOT_FOUND');
1039
855
  };
1040
-
1041
- const create$3 = async ({
1042
- commandMap
1043
- }) => {
1044
- // TODO create a commandMap per rpc instance
1045
- register(commandMap);
1046
- const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
1047
- handleIpc(ipc);
1048
- const rpc = createRpc(ipc);
1049
- return rpc;
856
+ const isModulesSyntaxError = stderr => {
857
+ if (!stderr) {
858
+ return false;
859
+ }
860
+ return stderr.includes('SyntaxError: Cannot use import statement outside a module');
1050
861
  };
1051
-
1052
- const createMockRpc = ({
1053
- commandMap
1054
- }) => {
1055
- const invocations = [];
1056
- const invoke = (method, ...params) => {
1057
- invocations.push([method, ...params]);
1058
- const command = commandMap[method];
1059
- if (!command) {
1060
- throw new Error(`command ${method} not found`);
1061
- }
1062
- return command(...params);
862
+ const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
863
+ const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
864
+ const isUnhelpfulNativeModuleError = stderr => {
865
+ return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
866
+ };
867
+ const getNativeModuleErrorMessage = stderr => {
868
+ const message = getMessageCodeBlock(stderr);
869
+ return {
870
+ code: E_INCOMPATIBLE_NATIVE_MODULE,
871
+ message: `Incompatible native node module: ${message}`
1063
872
  };
1064
- const mockRpc = {
1065
- invocations,
1066
- invoke,
1067
- invokeAndTransfer: invoke
873
+ };
874
+ const getModuleSyntaxError = () => {
875
+ return {
876
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
877
+ message: `ES Modules are not supported in electron`
1068
878
  };
1069
- return mockRpc;
1070
879
  };
1071
-
1072
- const rpcs = Object.create(null);
1073
- const set$4 = (id, rpc) => {
1074
- rpcs[id] = rpc;
880
+ const getHelpfulChildProcessError = (stdout, stderr) => {
881
+ if (isUnhelpfulNativeModuleError(stderr)) {
882
+ return getNativeModuleErrorMessage(stderr);
883
+ }
884
+ if (isModulesSyntaxError(stderr)) {
885
+ return getModuleSyntaxError();
886
+ }
887
+ if (isModuleNotFoundError(stderr)) {
888
+ return getModuleNotFoundError(stderr);
889
+ }
890
+ const lines = splitLines$1(stderr);
891
+ const {
892
+ actualMessage,
893
+ rest
894
+ } = getDetails(lines);
895
+ return {
896
+ code: '',
897
+ message: actualMessage,
898
+ stack: rest
899
+ };
1075
900
  };
1076
- const get$1 = id => {
1077
- return rpcs[id];
901
+ class IpcError extends VError {
902
+ // @ts-ignore
903
+ constructor(betterMessage, stdout = '', stderr = '') {
904
+ if (stdout || stderr) {
905
+ // @ts-ignore
906
+ const {
907
+ code,
908
+ message,
909
+ stack
910
+ } = getHelpfulChildProcessError(stdout, stderr);
911
+ const cause = new Error(message);
912
+ // @ts-ignore
913
+ cause.code = code;
914
+ cause.stack = stack;
915
+ super(cause, betterMessage);
916
+ } else {
917
+ super(betterMessage);
918
+ }
919
+ // @ts-ignore
920
+ this.name = 'IpcError';
921
+ // @ts-ignore
922
+ this.stdout = stdout;
923
+ // @ts-ignore
924
+ this.stderr = stderr;
925
+ }
926
+ }
927
+ const readyMessage = 'ready';
928
+ const getData$2 = event => {
929
+ return event.data;
1078
930
  };
1079
- const remove = id => {
1080
- delete rpcs[id];
931
+ const listen$7 = () => {
932
+ // @ts-ignore
933
+ if (typeof WorkerGlobalScope === 'undefined') {
934
+ throw new TypeError('module is not in web worker scope');
935
+ }
936
+ return globalThis;
1081
937
  };
1082
-
1083
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1084
- const create$2 = rpcId => {
1085
- return {
1086
- async dispose() {
1087
- const rpc = get$1(rpcId);
1088
- await rpc.dispose();
1089
- },
938
+ const signal$8 = global => {
939
+ global.postMessage(readyMessage);
940
+ };
941
+ class IpcChildWithModuleWorker extends Ipc {
942
+ getData(event) {
943
+ return getData$2(event);
944
+ }
945
+ send(message) {
1090
946
  // @ts-ignore
1091
- invoke(method, ...params) {
1092
- const rpc = get$1(rpcId);
1093
- // @ts-ignore
1094
- return rpc.invoke(method, ...params);
1095
- },
947
+ this._rawIpc.postMessage(message);
948
+ }
949
+ sendAndTransfer(message) {
950
+ const transfer = getTransferrables(message);
1096
951
  // @ts-ignore
1097
- invokeAndTransfer(method, ...params) {
1098
- const rpc = get$1(rpcId);
1099
- // @ts-ignore
1100
- return rpc.invokeAndTransfer(method, ...params);
1101
- },
1102
- registerMockRpc(commandMap) {
1103
- const mockRpc = createMockRpc({
1104
- commandMap
1105
- });
1106
- set$4(rpcId, mockRpc);
1107
- // @ts-ignore
1108
- mockRpc[Symbol.dispose] = () => {
1109
- remove(rpcId);
1110
- };
1111
- // @ts-ignore
1112
- return mockRpc;
1113
- },
1114
- set(rpc) {
1115
- set$4(rpcId, rpc);
1116
- }
1117
- };
952
+ this._rawIpc.postMessage(message, transfer);
953
+ }
954
+ dispose() {
955
+ // ignore
956
+ }
957
+ onClose(callback) {
958
+ // ignore
959
+ }
960
+ onMessage(callback) {
961
+ this._rawIpc.addEventListener('message', callback);
962
+ }
963
+ }
964
+ const wrap$f = global => {
965
+ return new IpcChildWithModuleWorker(global);
966
+ };
967
+ const waitForFirstMessage = async port => {
968
+ const {
969
+ promise,
970
+ resolve
971
+ } = Promise.withResolvers();
972
+ port.addEventListener('message', resolve, {
973
+ once: true
974
+ });
975
+ const event = await promise;
976
+ // @ts-ignore
977
+ return event.data;
978
+ };
979
+ const listen$6 = async () => {
980
+ const parentIpcRaw = listen$7();
981
+ signal$8(parentIpcRaw);
982
+ const parentIpc = wrap$f(parentIpcRaw);
983
+ const firstMessage = await waitForFirstMessage(parentIpc);
984
+ if (firstMessage.method !== 'initialize') {
985
+ throw new IpcError('unexpected first message');
986
+ }
987
+ const type = firstMessage.params[0];
988
+ if (type === 'message-port') {
989
+ parentIpc.send({
990
+ id: firstMessage.id,
991
+ jsonrpc: '2.0',
992
+ result: null
993
+ });
994
+ parentIpc.dispose();
995
+ const port = firstMessage.params[1];
996
+ return port;
997
+ }
998
+ return globalThis;
999
+ };
1000
+ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
1001
+ getData(event) {
1002
+ return getData$2(event);
1003
+ }
1004
+ send(message) {
1005
+ this._rawIpc.postMessage(message);
1006
+ }
1007
+ sendAndTransfer(message) {
1008
+ const transfer = getTransferrables(message);
1009
+ this._rawIpc.postMessage(message, transfer);
1010
+ }
1011
+ dispose() {
1012
+ if (this._rawIpc.close) {
1013
+ this._rawIpc.close();
1014
+ }
1015
+ }
1016
+ onClose(callback) {
1017
+ // ignore
1018
+ }
1019
+ onMessage(callback) {
1020
+ this._rawIpc.addEventListener('message', callback);
1021
+ this._rawIpc.start();
1022
+ }
1023
+ }
1024
+ const wrap$e = port => {
1025
+ return new IpcChildWithModuleWorkerAndMessagePort(port);
1026
+ };
1027
+ const IpcChildWithModuleWorkerAndMessagePort$1 = {
1028
+ __proto__: null,
1029
+ listen: listen$6,
1030
+ wrap: wrap$e
1031
+ };
1032
+ const addListener = (emitter, type, callback) => {
1033
+ if ('addEventListener' in emitter) {
1034
+ emitter.addEventListener(type, callback);
1035
+ } else {
1036
+ emitter.on(type, callback);
1037
+ }
1038
+ };
1039
+ const removeListener = (emitter, type, callback) => {
1040
+ if ('removeEventListener' in emitter) {
1041
+ emitter.removeEventListener(type, callback);
1042
+ } else {
1043
+ emitter.off(type, callback);
1044
+ }
1045
+ };
1046
+ const getFirstEvent = (eventEmitter, eventMap) => {
1047
+ const {
1048
+ promise,
1049
+ resolve
1050
+ } = Promise.withResolvers();
1051
+ const listenerMap = Object.create(null);
1052
+ const cleanup = value => {
1053
+ for (const event of Object.keys(eventMap)) {
1054
+ removeListener(eventEmitter, event, listenerMap[event]);
1055
+ }
1056
+ resolve(value);
1057
+ };
1058
+ for (const [event, type] of Object.entries(eventMap)) {
1059
+ const listener = event => {
1060
+ cleanup({
1061
+ event,
1062
+ type
1063
+ });
1064
+ };
1065
+ addListener(eventEmitter, event, listener);
1066
+ listenerMap[event] = listener;
1067
+ }
1068
+ return promise;
1069
+ };
1070
+ const Message$1 = 3;
1071
+ const create$5$1 = async ({
1072
+ isMessagePortOpen,
1073
+ messagePort
1074
+ }) => {
1075
+ if (!isMessagePort(messagePort)) {
1076
+ throw new IpcError('port must be of type MessagePort');
1077
+ }
1078
+ if (isMessagePortOpen) {
1079
+ return messagePort;
1080
+ }
1081
+ const eventPromise = getFirstEvent(messagePort, {
1082
+ message: Message$1
1083
+ });
1084
+ messagePort.start();
1085
+ const {
1086
+ event,
1087
+ type
1088
+ } = await eventPromise;
1089
+ if (type !== Message$1) {
1090
+ throw new IpcError('Failed to wait for ipc message');
1091
+ }
1092
+ if (event.data !== readyMessage) {
1093
+ throw new IpcError('unexpected first message');
1094
+ }
1095
+ return messagePort;
1096
+ };
1097
+ const signal$1 = messagePort => {
1098
+ messagePort.start();
1099
+ };
1100
+ class IpcParentWithMessagePort extends Ipc {
1101
+ getData = getData$2;
1102
+ send(message) {
1103
+ this._rawIpc.postMessage(message);
1104
+ }
1105
+ sendAndTransfer(message) {
1106
+ const transfer = getTransferrables(message);
1107
+ this._rawIpc.postMessage(message, transfer);
1108
+ }
1109
+ dispose() {
1110
+ this._rawIpc.close();
1111
+ }
1112
+ onMessage(callback) {
1113
+ this._rawIpc.addEventListener('message', callback);
1114
+ }
1115
+ onClose(callback) {}
1116
+ }
1117
+ const wrap$5 = messagePort => {
1118
+ return new IpcParentWithMessagePort(messagePort);
1119
+ };
1120
+ const IpcParentWithMessagePort$1 = {
1121
+ __proto__: null,
1122
+ create: create$5$1,
1123
+ signal: signal$1,
1124
+ wrap: wrap$5
1118
1125
  };
1119
1126
 
1120
- const {
1121
- set: set$3
1122
- } = create$2(6010);
1123
-
1124
- const Button$2 = 'button';
1125
- const None$1 = 'none';
1126
- const Tab$1 = 'tab';
1127
- const ToolBar = 'toolbar';
1128
-
1129
- const Div = 4;
1130
- const Text = 12;
1131
- const Reference = 100;
1132
-
1133
- const Button$1 = 'event.button';
1134
- const ClientX = 'event.clientX';
1135
- const ClientY = 'event.clientY';
1136
-
1137
- const Enter = 3;
1138
- const Space = 9;
1139
- const PageUp = 10;
1140
- const PageDown = 11;
1141
- const End = 255;
1142
- const Home = 12;
1143
- const UpArrow = 14;
1144
- const DownArrow = 16;
1145
-
1146
- const ActivityBar$3 = 1;
1147
- const Settings$1 = 12;
1148
- const ActivityBarAdditionalViews = 17;
1149
-
1150
- const Separator = 1;
1151
- const None = 0;
1152
- const Checked = 2;
1153
- const Unchecked = 3;
1154
-
1155
- const LeftClick = 0;
1156
-
1157
- const Web = 1;
1158
-
1159
- const ExtensionManagementWorker = 9006;
1160
- const RendererWorker = 1;
1161
-
1162
- const Left = 1;
1163
- const Right = 2;
1164
-
1165
- const SetCss = 'Viewlet.setCss';
1166
- const SetDom2 = 'Viewlet.setDom2';
1167
- const SetFocusContext = 'Viewlet.setFocusContext';
1168
- const SetPatches = 'Viewlet.setPatches';
1169
-
1170
- const FocusActivityBar = 5;
1171
- const FocusExplorer = 13;
1172
-
1173
- const {
1174
- invoke: invoke$1,
1175
- set: set$2
1176
- } = create$2(ExtensionManagementWorker);
1177
-
1178
- const {
1179
- invoke,
1180
- invokeAndTransfer,
1181
- set: set$1
1182
- } = create$2(RendererWorker);
1183
- const showContextMenu2 = async (uid, menuId, x, y, args) => {
1184
- number(uid);
1185
- number(menuId);
1186
- number(x);
1187
- number(y);
1188
- await invoke('ContextMenu.show2', uid, menuId, x, y, args);
1127
+ class CommandNotFoundError extends Error {
1128
+ constructor(command) {
1129
+ super(`Command not found ${command}`);
1130
+ this.name = 'CommandNotFoundError';
1131
+ }
1132
+ }
1133
+ const commands = Object.create(null);
1134
+ const register = commandMap => {
1135
+ Object.assign(commands, commandMap);
1189
1136
  };
1190
- const sendMessagePortToAuthWorker = async (port, rpcId) => {
1191
- const command = 'HandleMessagePort.handleMessagePort';
1192
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToAuthWorker', port, command, rpcId);
1137
+ const getCommand = key => {
1138
+ return commands[key];
1139
+ };
1140
+ const execute = (command, ...args) => {
1141
+ const fn = getCommand(command);
1142
+ if (!fn) {
1143
+ throw new CommandNotFoundError(command);
1144
+ }
1145
+ return fn(...args);
1193
1146
  };
1194
1147
 
1195
- const toCommandId = key => {
1196
- const dotIndex = key.indexOf('.');
1197
- return key.slice(dotIndex + 1);
1148
+ const Two$1 = '2.0';
1149
+ const callbacks = Object.create(null);
1150
+ const get$1 = id => {
1151
+ return callbacks[id];
1198
1152
  };
1199
- const create$1 = () => {
1200
- const states = Object.create(null);
1201
- const commandMapRef = {};
1202
- return {
1203
- clear() {
1204
- for (const key of Object.keys(states)) {
1205
- delete states[key];
1153
+ const remove$1 = id => {
1154
+ delete callbacks[id];
1155
+ };
1156
+ class JsonRpcError extends Error {
1157
+ constructor(message) {
1158
+ super(message);
1159
+ this.name = 'JsonRpcError';
1160
+ }
1161
+ }
1162
+ const NewLine = '\n';
1163
+ const DomException = 'DOMException';
1164
+ const ReferenceError$1 = 'ReferenceError';
1165
+ const SyntaxError$1 = 'SyntaxError';
1166
+ const TypeError$1 = 'TypeError';
1167
+ const getErrorConstructor = (message, type) => {
1168
+ if (type) {
1169
+ switch (type) {
1170
+ case DomException:
1171
+ return DOMException;
1172
+ case ReferenceError$1:
1173
+ return ReferenceError;
1174
+ case SyntaxError$1:
1175
+ return SyntaxError;
1176
+ case TypeError$1:
1177
+ return TypeError;
1178
+ default:
1179
+ return Error;
1180
+ }
1181
+ }
1182
+ if (message.startsWith('TypeError: ')) {
1183
+ return TypeError;
1184
+ }
1185
+ if (message.startsWith('SyntaxError: ')) {
1186
+ return SyntaxError;
1187
+ }
1188
+ if (message.startsWith('ReferenceError: ')) {
1189
+ return ReferenceError;
1190
+ }
1191
+ return Error;
1192
+ };
1193
+ const constructError = (message, type, name) => {
1194
+ const ErrorConstructor = getErrorConstructor(message, type);
1195
+ if (ErrorConstructor === DOMException && name) {
1196
+ return new ErrorConstructor(message, name);
1197
+ }
1198
+ if (ErrorConstructor === Error) {
1199
+ const error = new Error(message);
1200
+ if (name && name !== 'VError') {
1201
+ error.name = name;
1202
+ }
1203
+ return error;
1204
+ }
1205
+ return new ErrorConstructor(message);
1206
+ };
1207
+ const joinLines = lines => {
1208
+ return lines.join(NewLine);
1209
+ };
1210
+ const splitLines = lines => {
1211
+ return lines.split(NewLine);
1212
+ };
1213
+ const getCurrentStack = () => {
1214
+ const stackLinesToSkip = 3;
1215
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
1216
+ return currentStack;
1217
+ };
1218
+ const getNewLineIndex = (string, startIndex = undefined) => {
1219
+ return string.indexOf(NewLine, startIndex);
1220
+ };
1221
+ const getParentStack = error => {
1222
+ let parentStack = error.stack || error.data || error.message || '';
1223
+ if (parentStack.startsWith(' at')) {
1224
+ parentStack = error.message + NewLine + parentStack;
1225
+ }
1226
+ return parentStack;
1227
+ };
1228
+ const MethodNotFound = -32601;
1229
+ const Custom = -32001;
1230
+ const restoreJsonRpcError = error => {
1231
+ const currentStack = getCurrentStack();
1232
+ if (error && error instanceof Error) {
1233
+ if (typeof error.stack === 'string') {
1234
+ error.stack = error.stack + NewLine + currentStack;
1235
+ }
1236
+ return error;
1237
+ }
1238
+ if (error && error.code && error.code === MethodNotFound) {
1239
+ const restoredError = new JsonRpcError(error.message);
1240
+ const parentStack = getParentStack(error);
1241
+ restoredError.stack = parentStack + NewLine + currentStack;
1242
+ return restoredError;
1243
+ }
1244
+ if (error && error.message) {
1245
+ const restoredError = constructError(error.message, error.type, error.name);
1246
+ if (error.data) {
1247
+ if (error.data.stack && error.data.type && error.message) {
1248
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
1249
+ } else if (error.data.stack) {
1250
+ restoredError.stack = error.data.stack;
1206
1251
  }
1207
- },
1208
- diff(uid, modules, numbers) {
1209
- const {
1210
- newState,
1211
- oldState
1212
- } = states[uid];
1213
- const diffResult = [];
1214
- for (let i = 0; i < modules.length; i++) {
1215
- const fn = modules[i];
1216
- if (!fn(oldState, newState)) {
1217
- diffResult.push(numbers[i]);
1218
- }
1252
+ if (error.data.codeFrame) {
1253
+ // @ts-ignore
1254
+ restoredError.codeFrame = error.data.codeFrame;
1255
+ }
1256
+ if (error.data.code) {
1257
+ // @ts-ignore
1258
+ restoredError.code = error.data.code;
1259
+ }
1260
+ if (error.data.type) {
1261
+ // @ts-ignore
1262
+ restoredError.name = error.data.type;
1263
+ }
1264
+ } else {
1265
+ if (error.stack) {
1266
+ const lowerStack = restoredError.stack || '';
1267
+ // @ts-ignore
1268
+ const indexNewLine = getNewLineIndex(lowerStack);
1269
+ const parentStack = getParentStack(error);
1270
+ // @ts-ignore
1271
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
1272
+ }
1273
+ if (error.codeFrame) {
1274
+ // @ts-ignore
1275
+ restoredError.codeFrame = error.codeFrame;
1219
1276
  }
1220
- return diffResult;
1221
- },
1222
- dispose(uid) {
1223
- delete states[uid];
1224
- },
1225
- get(uid) {
1226
- return states[uid];
1227
- },
1228
- getCommandIds() {
1229
- const keys = Object.keys(commandMapRef);
1230
- const ids = keys.map(toCommandId);
1231
- return ids;
1232
- },
1233
- getKeys() {
1234
- return Object.keys(states).map(key => {
1235
- return Number.parseFloat(key);
1236
- });
1237
- },
1238
- registerCommands(commandMap) {
1239
- Object.assign(commandMapRef, commandMap);
1240
- },
1241
- set(uid, oldState, newState) {
1242
- states[uid] = {
1243
- newState,
1244
- oldState
1245
- };
1246
- },
1247
- wrapCommand(fn) {
1248
- const wrapped = async (uid, ...args) => {
1249
- const {
1250
- newState,
1251
- oldState
1252
- } = states[uid];
1253
- const newerState = await fn(newState, ...args);
1254
- if (oldState === newerState || newState === newerState) {
1255
- return;
1256
- }
1257
- const latestOld = states[uid];
1258
- const latestNew = {
1259
- ...latestOld.newState,
1260
- ...newerState
1261
- };
1262
- states[uid] = {
1263
- newState: latestNew,
1264
- oldState: latestOld.oldState
1265
- };
1266
- };
1267
- return wrapped;
1268
- },
1269
- wrapGetter(fn) {
1270
- const wrapped = (uid, ...args) => {
1271
- const {
1272
- newState
1273
- } = states[uid];
1274
- return fn(newState, ...args);
1275
- };
1276
- return wrapped;
1277
- },
1278
- wrapLoadContent(fn) {
1279
- const wrapped = async (uid, ...args) => {
1280
- const {
1281
- newState,
1282
- oldState
1283
- } = states[uid];
1284
- const result = await fn(newState, ...args);
1285
- const {
1286
- error,
1287
- state
1288
- } = result;
1289
- if (oldState === state || newState === state) {
1290
- return {
1291
- error
1292
- };
1293
- }
1294
- const latestOld = states[uid];
1295
- const latestNew = {
1296
- ...latestOld.newState,
1297
- ...state
1298
- };
1299
- states[uid] = {
1300
- newState: latestNew,
1301
- oldState: latestOld.oldState
1302
- };
1303
- return {
1304
- error
1305
- };
1306
- };
1307
- return wrapped;
1308
1277
  }
1309
- };
1278
+ return restoredError;
1279
+ }
1280
+ if (typeof error === 'string') {
1281
+ return new Error(`JsonRpc Error: ${error}`);
1282
+ }
1283
+ return new Error(`JsonRpc Error: ${error}`);
1310
1284
  };
1311
- const terminate = () => {
1312
- globalThis.close();
1285
+ const unwrapJsonRpcResult = responseMessage => {
1286
+ if ('error' in responseMessage) {
1287
+ const restoredError = restoreJsonRpcError(responseMessage.error);
1288
+ throw restoredError;
1289
+ }
1290
+ if ('result' in responseMessage) {
1291
+ return responseMessage.result;
1292
+ }
1293
+ throw new JsonRpcError('unexpected response message');
1313
1294
  };
1314
-
1315
- const {
1316
- diff,
1317
- get,
1318
- getCommandIds,
1319
- registerCommands,
1320
- set,
1321
- wrapCommand,
1322
- wrapGetter
1323
- } = create$1();
1324
-
1325
- // TODO parentUid might ot be needed
1326
- const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) => {
1327
- const state = {
1328
- accountEnabled: true,
1329
- activityBarItems: [],
1330
- currentViewletId: '',
1331
- filteredItems: [],
1332
- focus: 0,
1333
- focused: false,
1334
- focusedIndex: -1,
1335
- height,
1336
- initial: true,
1337
- itemHeight: 48,
1338
- numberOfVisibleItems: 0,
1339
- platform,
1340
- scrollBarHeight: 0,
1341
- selectedIndex: -1,
1342
- sideBarLocation: 0,
1343
- sideBarVisible: false,
1344
- uid: id,
1345
- updateProgress: 0,
1346
- updateState: '',
1347
- userLoginState: 'logged out',
1348
- width,
1349
- x,
1350
- y
1351
- };
1352
- set(id, state, state);
1353
- return state;
1295
+ const warn = (...args) => {
1296
+ console.warn(...args);
1354
1297
  };
1355
-
1356
- const isEqual$2 = (oldState, newState) => {
1357
- return oldState.itemHeight === newState.itemHeight;
1298
+ const resolve = (id, response) => {
1299
+ const fn = get$1(id);
1300
+ if (!fn) {
1301
+ console.log(response);
1302
+ warn(`callback ${id} may already be disposed`);
1303
+ return;
1304
+ }
1305
+ fn(response);
1306
+ remove$1(id);
1358
1307
  };
1359
-
1360
- const isEqual$1 = (oldState, newState) => {
1361
- return oldState.focused === newState.focused && oldState.focus === newState.focus;
1308
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
1309
+ const getErrorType = prettyError => {
1310
+ if (prettyError && prettyError.type) {
1311
+ return prettyError.type;
1312
+ }
1313
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
1314
+ return prettyError.constructor.name;
1315
+ }
1316
+ return undefined;
1362
1317
  };
1363
-
1364
- const isEqual = (oldState, newState) => {
1365
- return oldState.activityBarItems === newState.activityBarItems && oldState.filteredItems === newState.filteredItems && oldState.focusedIndex === newState.focusedIndex && oldState.sideBarLocation === newState.sideBarLocation && oldState.sideBarVisible === newState.sideBarVisible && oldState.updateProgress === newState.updateProgress && oldState.updateState === newState.updateState;
1318
+ const isAlreadyStack = line => {
1319
+ return line.trim().startsWith('at ');
1366
1320
  };
1367
-
1368
- const RenderItems = 4;
1369
- const RenderFocus = 6;
1370
- const RenderFocusContext = 7;
1371
- const RenderCss = 11;
1372
- const RenderIncremental = 12;
1373
-
1374
- const modules = [isEqual, isEqual$1, isEqual$1, isEqual$2];
1375
- const numbers = [RenderIncremental, RenderFocus, RenderFocusContext, RenderCss];
1376
-
1377
- const diff2 = uid => {
1378
- return diff(uid, modules, numbers);
1321
+ const getStack = prettyError => {
1322
+ const stackString = prettyError.stack || '';
1323
+ const newLineIndex = stackString.indexOf('\n');
1324
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
1325
+ return stackString.slice(newLineIndex + 1);
1326
+ }
1327
+ return stackString;
1379
1328
  };
1380
-
1381
- const List = 1;
1382
-
1383
- const focus = state => {
1384
- const {
1385
- focus
1386
- } = state;
1387
- if (focus) {
1388
- return state;
1329
+ const getErrorProperty = (error, prettyError) => {
1330
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
1331
+ return {
1332
+ code: MethodNotFound,
1333
+ data: error.stack,
1334
+ message: error.message
1335
+ };
1389
1336
  }
1390
1337
  return {
1391
- ...state,
1392
- focus: List
1338
+ code: Custom,
1339
+ data: {
1340
+ code: prettyError.code,
1341
+ codeFrame: prettyError.codeFrame,
1342
+ name: prettyError.name,
1343
+ stack: getStack(prettyError),
1344
+ type: getErrorType(prettyError)
1345
+ },
1346
+ message: prettyError.message
1393
1347
  };
1394
1348
  };
1395
-
1396
- const focusIndex = (state, index) => {
1349
+ const create$1$1 = (id, error) => {
1397
1350
  return {
1398
- ...state,
1399
- focused: true,
1400
- focusedIndex: index
1351
+ error,
1352
+ id,
1353
+ jsonrpc: Two$1
1401
1354
  };
1402
1355
  };
1403
-
1404
- const focusFirst = state => {
1405
- return focusIndex(state, -1);
1356
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
1357
+ const prettyError = preparePrettyError(error);
1358
+ logError(error, prettyError);
1359
+ const errorProperty = getErrorProperty(error, prettyError);
1360
+ return create$1$1(id, errorProperty);
1406
1361
  };
1407
-
1408
- const focusLast = state => {
1409
- return focusIndex(state, -1);
1362
+ const create$8 = (message, result) => {
1363
+ return {
1364
+ id: message.id,
1365
+ jsonrpc: Two$1,
1366
+ result: result ?? null
1367
+ };
1410
1368
  };
1411
-
1412
- const focusNext = state => {
1413
- return focusIndex(state, -1);
1369
+ const getSuccessResponse = (message, result) => {
1370
+ const resultProperty = result ?? null;
1371
+ return create$8(message, resultProperty);
1414
1372
  };
1415
-
1416
- const focusNone = state => {
1417
- const {
1418
- focusedIndex
1419
- } = state;
1420
- if (focusedIndex === -1) {
1421
- return state;
1373
+ const getErrorResponseSimple = (id, error) => {
1374
+ return {
1375
+ error: {
1376
+ code: Custom,
1377
+ data: error,
1378
+ // @ts-ignore
1379
+ message: error.message
1380
+ },
1381
+ id,
1382
+ jsonrpc: Two$1
1383
+ };
1384
+ };
1385
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
1386
+ try {
1387
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
1388
+ return getSuccessResponse(message, result);
1389
+ } catch (error) {
1390
+ if (ipc.canUseSimpleErrorResponse) {
1391
+ return getErrorResponseSimple(message.id, error);
1392
+ }
1393
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
1422
1394
  }
1423
- return focusIndex(state, -1);
1424
1395
  };
1425
-
1426
- const getKeyBindings = () => {
1427
- return [{
1428
- command: 'ActivityBar.focusNext',
1429
- key: DownArrow,
1430
- when: FocusActivityBar
1431
- }, {
1432
- command: 'ActivityBar.focusPrevious',
1433
- key: UpArrow,
1434
- when: FocusActivityBar
1435
- }, {
1436
- command: 'ActivityBar.focusFirst',
1437
- key: Home,
1438
- when: FocusActivityBar
1439
- }, {
1440
- command: 'ActivityBar.focusFirst',
1441
- key: PageUp,
1442
- when: FocusActivityBar
1443
- }, {
1444
- command: 'ActivityBar.focusLast',
1445
- key: PageDown,
1446
- when: FocusActivityBar
1447
- }, {
1448
- command: 'ActivityBar.focusLast',
1449
- key: End,
1450
- when: FocusActivityBar
1451
- }, {
1452
- command: 'ActivityBar.selectCurrent',
1453
- key: Space,
1454
- when: FocusActivityBar
1455
- }, {
1456
- command: 'ActivityBar.selectCurrent',
1457
- key: Enter,
1458
- when: FocusActivityBar
1459
- }];
1396
+ const defaultPreparePrettyError = error => {
1397
+ return error;
1460
1398
  };
1461
-
1462
- const getMenuEntriesAccountLoggedIn = state => {
1463
- const {
1464
- userLoginState
1465
- } = state;
1466
- const signOutLabel = userLoginState === 'logging out' ? 'Signing Out...' : 'Sign Out';
1467
- return [{
1468
- command: 'ActivityBar.handleClickSignOut',
1469
- flags: None,
1470
- id: 'signOut',
1471
- label: signOutLabel
1472
- }];
1399
+ const defaultLogError = () => {
1400
+ // ignore
1473
1401
  };
1474
- const getMenuEntriesAccountLoggedOut = state => {
1475
- const {
1476
- userLoginState
1477
- } = state;
1478
- const signInLabel = userLoginState === 'logging in' ? 'Signing In...' : 'Sign In';
1479
- return [{
1480
- command: 'ActivityBar.handleClickSignIn',
1481
- flags: None,
1482
- id: 'signIn',
1483
- label: signInLabel
1484
- }];
1402
+ const defaultRequiresSocket = () => {
1403
+ return false;
1404
+ };
1405
+ const defaultResolve = resolve;
1406
+
1407
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
1408
+ const normalizeParams = args => {
1409
+ if (args.length === 1) {
1410
+ const options = args[0];
1411
+ return {
1412
+ execute: options.execute,
1413
+ ipc: options.ipc,
1414
+ logError: options.logError || defaultLogError,
1415
+ message: options.message,
1416
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
1417
+ requiresSocket: options.requiresSocket || defaultRequiresSocket,
1418
+ resolve: options.resolve || defaultResolve
1419
+ };
1420
+ }
1421
+ return {
1422
+ execute: args[2],
1423
+ ipc: args[0],
1424
+ logError: args[5],
1425
+ message: args[1],
1426
+ preparePrettyError: args[4],
1427
+ requiresSocket: args[6],
1428
+ resolve: args[3]
1429
+ };
1485
1430
  };
1486
- const getMenuEntriesAccount = state => {
1487
- // TODO maybe query it now from layout?
1431
+ const handleJsonRpcMessage = async (...args) => {
1432
+ const options = normalizeParams(args);
1488
1433
  const {
1489
- userLoginState
1490
- } = state;
1491
- if (userLoginState === 'logged in' || userLoginState === 'logging out') {
1492
- return getMenuEntriesAccountLoggedIn(state);
1434
+ execute,
1435
+ ipc,
1436
+ logError,
1437
+ message,
1438
+ preparePrettyError,
1439
+ requiresSocket,
1440
+ resolve
1441
+ } = options;
1442
+ if ('id' in message) {
1443
+ if ('method' in message) {
1444
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1445
+ try {
1446
+ ipc.send(response);
1447
+ } catch (error) {
1448
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
1449
+ ipc.send(errorResponse);
1450
+ }
1451
+ return;
1452
+ }
1453
+ resolve(message.id, message);
1454
+ return;
1493
1455
  }
1494
- return getMenuEntriesAccountLoggedOut(state);
1456
+ if ('method' in message) {
1457
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1458
+ return;
1459
+ }
1460
+ throw new JsonRpcError('unexpected message');
1495
1461
  };
1496
1462
 
1497
- const Tab = 1;
1498
- const Button = 1 << 1;
1499
- const Progress = 1 << 2;
1500
- const Enabled = 1 << 3;
1501
- const Selected = 1 << 4;
1502
- const Focused = 1 << 5;
1503
- const MarginTop = 1 << 6;
1463
+ const Two = '2.0';
1504
1464
 
1505
- const emptyObject = {};
1506
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1507
- const i18nString = (key, placeholders = emptyObject) => {
1508
- if (placeholders === emptyObject) {
1509
- return key;
1510
- }
1511
- const replacer = (match, rest) => {
1512
- return placeholders[rest];
1465
+ const create$7 = (method, params) => {
1466
+ return {
1467
+ jsonrpc: Two,
1468
+ method,
1469
+ params
1513
1470
  };
1514
- return key.replaceAll(RE_PLACEHOLDER, replacer);
1515
1471
  };
1516
1472
 
1517
- const Account$1 = 'Account';
1518
- const Explorer$1 = 'Explorer';
1519
- const Search$2 = 'Search';
1520
- const SourceControl$2 = 'Source Control';
1521
- const RunAndDebug$1 = 'Run and Debug';
1522
- const Extensions$2 = 'Extensions';
1523
- const Settings = 'Settings';
1524
- const AdditionalViews = 'Additional Views';
1525
- const ActivityBar$2 = 'Activity Bar';
1526
- const MoveSideBarLeft = 'Move Side Bar Left';
1527
- const MoveSideBarRight = 'Move Side Bar Right';
1528
- const HideActivityBar = 'Hide Activity Bar';
1529
- const CheckForUpdates = 'Check For Updates';
1530
- const ColorTheme = 'Color Theme';
1531
- const CommandPalette = 'Command Palette';
1532
- const KeyboardShortcuts = 'Keyboard Shortcuts';
1533
-
1534
- const account = () => {
1535
- return i18nString(Account$1);
1536
- };
1537
- const explorer = () => {
1538
- return i18nString(Explorer$1);
1539
- };
1540
- const search = () => {
1541
- return i18nString(Search$2);
1542
- };
1543
- const sourceControl = () => {
1544
- return i18nString(SourceControl$2);
1545
- };
1546
- const runAndDebug = () => {
1547
- return i18nString(RunAndDebug$1);
1548
- };
1549
- const extensions = () => {
1550
- return i18nString(Extensions$2);
1551
- };
1552
- const settings = () => {
1553
- return i18nString(Settings);
1473
+ const create$6 = (id, method, params) => {
1474
+ const message = {
1475
+ id,
1476
+ jsonrpc: Two,
1477
+ method,
1478
+ params
1479
+ };
1480
+ return message;
1554
1481
  };
1555
- const additionalViews = () => {
1556
- return i18nString(AdditionalViews);
1482
+
1483
+ let id = 0;
1484
+ const create$5 = () => {
1485
+ return ++id;
1557
1486
  };
1558
- const activityBar = () => {
1559
- return i18nString(ActivityBar$2);
1487
+
1488
+ const registerPromise = map => {
1489
+ const id = create$5();
1490
+ const {
1491
+ promise,
1492
+ resolve
1493
+ } = Promise.withResolvers();
1494
+ map[id] = resolve;
1495
+ return {
1496
+ id,
1497
+ promise
1498
+ };
1560
1499
  };
1561
- const moveSideBarRight = () => {
1562
- return i18nString(MoveSideBarRight);
1500
+
1501
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
1502
+ const {
1503
+ id,
1504
+ promise
1505
+ } = registerPromise(callbacks);
1506
+ const message = create$6(id, method, params);
1507
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
1508
+ ipc.sendAndTransfer(message);
1509
+ } else {
1510
+ ipc.send(message);
1511
+ }
1512
+ const responseMessage = await promise;
1513
+ return unwrapJsonRpcResult(responseMessage);
1563
1514
  };
1564
- const moveSideBarLeft = () => {
1565
- return i18nString(MoveSideBarLeft);
1515
+ const createRpc = ipc => {
1516
+ const callbacks = Object.create(null);
1517
+ ipc._resolve = (id, response) => {
1518
+ const fn = callbacks[id];
1519
+ if (!fn) {
1520
+ console.warn(`callback ${id} may already be disposed`);
1521
+ return;
1522
+ }
1523
+ fn(response);
1524
+ delete callbacks[id];
1525
+ };
1526
+ const rpc = {
1527
+ async dispose() {
1528
+ await ipc?.dispose();
1529
+ },
1530
+ invoke(method, ...params) {
1531
+ return invokeHelper(callbacks, ipc, method, params, false);
1532
+ },
1533
+ invokeAndTransfer(method, ...params) {
1534
+ return invokeHelper(callbacks, ipc, method, params, true);
1535
+ },
1536
+ // @ts-ignore
1537
+ ipc,
1538
+ /**
1539
+ * @deprecated
1540
+ */
1541
+ send(method, ...params) {
1542
+ const message = create$7(method, params);
1543
+ ipc.send(message);
1544
+ }
1545
+ };
1546
+ return rpc;
1566
1547
  };
1567
- const hideActivityBar = () => {
1568
- return i18nString(HideActivityBar);
1548
+
1549
+ const requiresSocket = () => {
1550
+ return false;
1569
1551
  };
1570
- const checkForUpdates = () => {
1571
- return i18nString(CheckForUpdates);
1552
+ const preparePrettyError = error => {
1553
+ return error;
1572
1554
  };
1573
- const commandPalette = () => {
1574
- return i18nString(CommandPalette);
1555
+ const logError = () => {
1556
+ // handled by renderer worker
1575
1557
  };
1576
- const keyboardShortcuts = () => {
1577
- return i18nString(KeyboardShortcuts);
1558
+ const handleMessage = event => {
1559
+ const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
1560
+ const actualExecute = event?.target?.execute || execute;
1561
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
1578
1562
  };
1579
- const colorTheme = () => {
1580
- return i18nString(ColorTheme);
1563
+
1564
+ const handleIpc = ipc => {
1565
+ if ('addEventListener' in ipc) {
1566
+ ipc.addEventListener('message', handleMessage);
1567
+ } else if ('on' in ipc) {
1568
+ // deprecated
1569
+ ipc.on('message', handleMessage);
1570
+ }
1581
1571
  };
1582
1572
 
1583
- const menuEntryMoveSideBar = sideBarLocation => {
1584
- switch (sideBarLocation) {
1585
- case Left:
1586
- return {
1587
- command: 'Layout.moveSideBarRight',
1588
- flags: None,
1589
- id: 'moveSideBarRight',
1590
- label: moveSideBarRight()
1591
- };
1592
- case Right:
1593
- return {
1594
- command: 'Layout.moveSideBarLeft',
1595
- flags: None,
1596
- id: 'moveSideBarLeft',
1597
- label: moveSideBarLeft()
1598
- };
1599
- default:
1600
- throw new Error('unexpected side bar location');
1573
+ const listen$1 = async (module, options) => {
1574
+ const rawIpc = await module.listen(options);
1575
+ if (module.signal) {
1576
+ module.signal(rawIpc);
1601
1577
  }
1578
+ const ipc = module.wrap(rawIpc);
1579
+ return ipc;
1580
+ };
1581
+
1582
+ const create$4 = async ({
1583
+ commandMap,
1584
+ isMessagePortOpen = true,
1585
+ messagePort
1586
+ }) => {
1587
+ // TODO create a commandMap per rpc instance
1588
+ register(commandMap);
1589
+ const rawIpc = await IpcParentWithMessagePort$1.create({
1590
+ isMessagePortOpen,
1591
+ messagePort
1592
+ });
1593
+ const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
1594
+ handleIpc(ipc);
1595
+ const rpc = createRpc(ipc);
1596
+ messagePort.start();
1597
+ return rpc;
1602
1598
  };
1603
1599
 
1604
- const menuEntrySeparator = {
1605
- command: '',
1606
- flags: Separator,
1607
- id: 'separator',
1608
- label: ''
1600
+ const create$3 = async ({
1601
+ commandMap,
1602
+ isMessagePortOpen,
1603
+ send
1604
+ }) => {
1605
+ const {
1606
+ port1,
1607
+ port2
1608
+ } = new MessageChannel();
1609
+ await send(port1);
1610
+ return create$4({
1611
+ commandMap,
1612
+ isMessagePortOpen,
1613
+ messagePort: port2
1614
+ });
1609
1615
  };
1610
1616
 
1611
- const toContextMenuItem$1 = activityBarItem => {
1612
- const isEnabled = activityBarItem.flags & Enabled;
1617
+ const createSharedLazyRpc = factory => {
1618
+ let rpcPromise;
1619
+ const getOrCreate = () => {
1620
+ if (!rpcPromise) {
1621
+ rpcPromise = factory();
1622
+ }
1623
+ return rpcPromise;
1624
+ };
1613
1625
  return {
1614
- args: [activityBarItem.id],
1615
- command: 'ActivityBar.toggleActivityBarItem',
1616
- flags: isEnabled ? Checked : Unchecked,
1617
- id: `toggle-${activityBarItem.id}`,
1618
- label: activityBarItem.id
1626
+ async dispose() {
1627
+ const rpc = await getOrCreate();
1628
+ await rpc.dispose();
1629
+ },
1630
+ async invoke(method, ...params) {
1631
+ const rpc = await getOrCreate();
1632
+ return rpc.invoke(method, ...params);
1633
+ },
1634
+ async invokeAndTransfer(method, ...params) {
1635
+ const rpc = await getOrCreate();
1636
+ return rpc.invokeAndTransfer(method, ...params);
1637
+ },
1638
+ async send(method, ...params) {
1639
+ const rpc = await getOrCreate();
1640
+ rpc.send(method, ...params);
1641
+ }
1619
1642
  };
1620
1643
  };
1621
1644
 
1622
- const getMenuEntriesActivityBar = state => {
1623
- const {
1624
- activityBarItems,
1625
- sideBarLocation
1626
- } = state;
1627
- const topItems = activityBarItems.filter(item => !(item.flags & Button));
1628
- const bottomItems = activityBarItems.filter(item => item.flags & Button);
1629
- const entries = [...topItems.map(toContextMenuItem$1)];
1630
- if (bottomItems.length > 0) {
1631
- entries.push(menuEntrySeparator, ...bottomItems.map(toContextMenuItem$1));
1632
- }
1633
- return [...entries, menuEntrySeparator, menuEntryMoveSideBar(sideBarLocation), {
1634
- command: 'Layout.hideActivityBar',
1635
- flags: None,
1636
- id: 'hideActivityBar',
1637
- label: hideActivityBar()
1638
- }];
1645
+ const create$2 = async ({
1646
+ commandMap,
1647
+ isMessagePortOpen,
1648
+ send
1649
+ }) => {
1650
+ return createSharedLazyRpc(() => {
1651
+ return create$3({
1652
+ commandMap,
1653
+ isMessagePortOpen,
1654
+ send
1655
+ });
1656
+ });
1639
1657
  };
1640
1658
 
1641
- const getNumberOfVisibleItems = state => {
1642
- const {
1643
- height,
1644
- itemHeight
1645
- } = state;
1646
- const numberOfVisibleItemsTop = Math.floor(height / itemHeight);
1647
- return numberOfVisibleItemsTop;
1659
+ const create$1 = async ({
1660
+ commandMap
1661
+ }) => {
1662
+ // TODO create a commandMap per rpc instance
1663
+ register(commandMap);
1664
+ const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
1665
+ handleIpc(ipc);
1666
+ const rpc = createRpc(ipc);
1667
+ return rpc;
1648
1668
  };
1649
- const getHiddenItems = state => {
1650
- const numberOfVisibleItems = getNumberOfVisibleItems(state);
1651
- const items = state.activityBarItems.filter(item => item.flags & Enabled);
1652
- if (numberOfVisibleItems >= items.length) {
1653
- return [];
1654
- }
1655
- return items.slice(numberOfVisibleItems - 2, -1);
1669
+
1670
+ const createMockRpc = ({
1671
+ commandMap
1672
+ }) => {
1673
+ const invocations = [];
1674
+ const invoke = (method, ...params) => {
1675
+ invocations.push([method, ...params]);
1676
+ const command = commandMap[method];
1677
+ if (!command) {
1678
+ throw new Error(`command ${method} not found`);
1679
+ }
1680
+ return command(...params);
1681
+ };
1682
+ const mockRpc = {
1683
+ invocations,
1684
+ invoke,
1685
+ invokeAndTransfer: invoke
1686
+ };
1687
+ return mockRpc;
1656
1688
  };
1657
1689
 
1658
- const toContextMenuItem = activityBarItem => {
1690
+ const rpcs = Object.create(null);
1691
+ const set$3 = (id, rpc) => {
1692
+ rpcs[id] = rpc;
1693
+ };
1694
+ const get = id => {
1695
+ return rpcs[id];
1696
+ };
1697
+ const remove = id => {
1698
+ delete rpcs[id];
1699
+ };
1700
+
1701
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1702
+ const create = rpcId => {
1659
1703
  return {
1660
- command: '-1',
1661
- // TODO
1662
- flags: None,
1663
- id: '8000',
1664
- // TODO
1665
- label: activityBarItem.id
1704
+ async dispose() {
1705
+ const rpc = get(rpcId);
1706
+ await rpc.dispose();
1707
+ },
1708
+ // @ts-ignore
1709
+ invoke(method, ...params) {
1710
+ const rpc = get(rpcId);
1711
+ // @ts-ignore
1712
+ return rpc.invoke(method, ...params);
1713
+ },
1714
+ // @ts-ignore
1715
+ invokeAndTransfer(method, ...params) {
1716
+ const rpc = get(rpcId);
1717
+ // @ts-ignore
1718
+ return rpc.invokeAndTransfer(method, ...params);
1719
+ },
1720
+ registerMockRpc(commandMap) {
1721
+ const mockRpc = createMockRpc({
1722
+ commandMap
1723
+ });
1724
+ set$3(rpcId, mockRpc);
1725
+ // @ts-ignore
1726
+ mockRpc[Symbol.dispose] = () => {
1727
+ remove(rpcId);
1728
+ };
1729
+ // @ts-ignore
1730
+ return mockRpc;
1731
+ },
1732
+ set(rpc) {
1733
+ set$3(rpcId, rpc);
1734
+ }
1666
1735
  };
1667
1736
  };
1668
- const getMenuEntriesAdditionalViews = state => {
1669
- const hiddenActivityBarItems = getHiddenItems(state);
1670
- return hiddenActivityBarItems.map(toContextMenuItem);
1671
- };
1672
1737
 
1673
- const keyBindingsUri = 'app://keybindings';
1674
- const getMenuEntriesSettings = state => {
1675
- const {
1676
- platform
1677
- } = state;
1678
- const items = [{
1679
- command: 'QuickPick.showEverything',
1680
- flags: None,
1681
- id: 'commandPalette',
1682
- label: commandPalette()
1683
- }, menuEntrySeparator, {
1684
- command: 'Preferences.openSettingsJson',
1685
- flags: None,
1686
- id: 'settings',
1687
- label: settings()
1688
- }, {
1689
- args: [keyBindingsUri],
1690
- command: 'Main.openUri',
1691
- flags: None,
1692
- id: 'keyboardShortcuts',
1693
- label: keyboardShortcuts()
1694
- }, {
1695
- command: 'QuickPick.showColorTheme',
1696
- flags: None,
1697
- id: 'colorTheme',
1698
- label: colorTheme()
1699
- }];
1700
- if (platform !== Web) {
1701
- items.push(menuEntrySeparator, {
1702
- command: 'AutoUpdater.checkForUpdates',
1703
- flags: None,
1704
- id: 'checkForUpdates',
1705
- label: checkForUpdates()
1706
- });
1707
- }
1708
- return items;
1738
+ const {
1739
+ set: set$2
1740
+ } = create(6010);
1741
+
1742
+ const {
1743
+ invoke: invoke$1,
1744
+ set: set$1
1745
+ } = create(ExtensionManagementWorker);
1746
+
1747
+ const {
1748
+ invoke,
1749
+ invokeAndTransfer,
1750
+ set
1751
+ } = create(RendererWorker);
1752
+ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1753
+ number(uid);
1754
+ number(menuId);
1755
+ number(x);
1756
+ number(y);
1757
+ await invoke('ContextMenu.show2', uid, menuId, x, y, args);
1758
+ };
1759
+ const sendMessagePortToAuthWorker = async (port, rpcId) => {
1760
+ const command = 'HandleMessagePort.handleMessagePort';
1761
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToAuthWorker', port, command, rpcId);
1762
+ };
1763
+ const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1764
+ const command = 'Extensions.handleMessagePort';
1765
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1709
1766
  };
1710
1767
 
1711
1768
  const show2 = async (uid, menuId, x, y, args) => {
@@ -1750,7 +1807,7 @@ const updateItemsWithBadgeCount = async items => {
1750
1807
  const badgeCounts = await invoke('Layout.getBadgeCounts');
1751
1808
  const newItems = items.map(item => {
1752
1809
  const badgeCount = badgeCounts[item.id] || 0;
1753
- const badgeText = badgeCount ? `${badgeCount}` : '';
1810
+ const badgeText = badgeCount ? String(badgeCount) : '';
1754
1811
  return {
1755
1812
  ...item,
1756
1813
  badgeText
@@ -2011,11 +2068,11 @@ const handleContextMenu = async (state, button, eventX, eventY) => {
2011
2068
  const commandMap$1 = {};
2012
2069
 
2013
2070
  const handleExtensionManagementMessagePort = async port => {
2014
- const rpc = await create$6({
2071
+ const rpc = await create$4({
2015
2072
  commandMap: commandMap$1,
2016
2073
  messagePort: port
2017
2074
  });
2018
- set$2(rpc);
2075
+ set$1(rpc);
2019
2076
  };
2020
2077
 
2021
2078
  const Explorer = 'Explorer';
@@ -2025,13 +2082,24 @@ const Search = 'Search';
2025
2082
  const SourceControl = 'Source Control';
2026
2083
 
2027
2084
  const toActivityBarItem = view => {
2028
- return {
2085
+ const icon = view.icon || Extensions$1;
2086
+ const customIconUrl = isCustomIconUrl(icon) ? icon : undefined;
2087
+ const customIconClass = customIconUrl ? getCustomIconClass(view.id, customIconUrl) : undefined;
2088
+ const item = {
2029
2089
  flags: Tab | Enabled,
2030
- icon: view.icon || Extensions$1,
2090
+ icon,
2031
2091
  id: view.id,
2032
2092
  keyShortcuts: '',
2033
2093
  title: view.title || view.id
2034
2094
  };
2095
+ if (customIconClass && customIconUrl) {
2096
+ return {
2097
+ ...item,
2098
+ customIconClass,
2099
+ customIconUrl
2100
+ };
2101
+ }
2102
+ return item;
2035
2103
  };
2036
2104
  const getActivityBarItems = (state, contributedViews = []) => {
2037
2105
  const {
@@ -2341,19 +2409,20 @@ const loadContent = async state => {
2341
2409
  };
2342
2410
  };
2343
2411
 
2344
- const getCss = itemHeight => {
2412
+ const getCss = (itemHeight, items = []) => {
2345
2413
  return `:root {
2346
2414
  --ActivityBarItemHeight: var(--${itemHeight}px);
2347
2415
  }
2348
- `;
2416
+ ${getCustomIconCss(items)}`;
2349
2417
  };
2350
2418
 
2351
2419
  const renderCss = (oldState, newState) => {
2352
2420
  const {
2421
+ filteredItems,
2353
2422
  itemHeight,
2354
2423
  uid
2355
2424
  } = newState;
2356
- const css = getCss(itemHeight);
2425
+ const css = getCss(itemHeight, filteredItems);
2357
2426
  return [SetCss, uid, css];
2358
2427
  };
2359
2428
 
@@ -2447,12 +2516,12 @@ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2447
2516
  };
2448
2517
 
2449
2518
  const compareNodes = (oldNode, newNode) => {
2450
- const patches = [];
2451
2519
  // Check if node type changed - return null to signal incompatible nodes
2452
2520
  // (caller should handle this with a Replace operation)
2453
2521
  if (oldNode.type !== newNode.type) {
2454
2522
  return null;
2455
2523
  }
2524
+ const patches = [];
2456
2525
  // Handle reference nodes - special handling for uid changes
2457
2526
  if (oldNode.type === Reference) {
2458
2527
  if (oldNode.uid !== newNode.uid) {
@@ -2488,7 +2557,7 @@ const compareNodes = (oldNode, newNode) => {
2488
2557
  }
2489
2558
  // Check for removed attributes
2490
2559
  for (const key of oldKeys) {
2491
- if (!(key in newNode)) {
2560
+ if (!Object.hasOwn(newNode, key)) {
2492
2561
  patches.push({
2493
2562
  type: RemoveAttribute,
2494
2563
  key
@@ -2703,7 +2772,6 @@ const getClassName = (isFocused, marginTop, isSelected) => {
2703
2772
  const getActivityBarItemInProgressDom = item => {
2704
2773
  const {
2705
2774
  flags,
2706
- icon,
2707
2775
  title
2708
2776
  } = item;
2709
2777
  const isTab = flags & Tab;
@@ -2726,7 +2794,7 @@ const getActivityBarItemInProgressDom = item => {
2726
2794
  type: Div
2727
2795
  }, {
2728
2796
  childCount: 0,
2729
- className: mergeClassNames(Icon, `MaskIcon${icon}`),
2797
+ className: mergeClassNames(Icon, getIconClass(item, 'MaskIcon')),
2730
2798
  role: None$1,
2731
2799
  type: Div
2732
2800
  }, ...getBadgeVirtualDom()];
@@ -2736,7 +2804,6 @@ const getActivityBarItemWithBadgeDom = item => {
2736
2804
  const {
2737
2805
  badgeText,
2738
2806
  flags,
2739
- icon,
2740
2807
  title
2741
2808
  } = item;
2742
2809
  if (!badgeText) {
@@ -2763,7 +2830,7 @@ const getActivityBarItemWithBadgeDom = item => {
2763
2830
  type: Div
2764
2831
  }, {
2765
2832
  childCount: 0,
2766
- className: mergeClassNames(Icon, `MaskIcon${icon}`),
2833
+ className: mergeClassNames(Icon, getIconClass(item, 'MaskIcon')),
2767
2834
  role: None$1,
2768
2835
  type: Div
2769
2836
  }, {
@@ -2773,10 +2840,10 @@ const getActivityBarItemWithBadgeDom = item => {
2773
2840
  }, text(badgeText)];
2774
2841
  };
2775
2842
 
2776
- const getIconVirtualDom = (icon, type = Div) => {
2843
+ const getIconVirtualDom = (icon, type = Div, customIconClass = '') => {
2777
2844
  return {
2778
2845
  childCount: 0,
2779
- className: `MaskIcon MaskIcon${icon}`,
2846
+ className: customIconClass ? `MaskIcon ${customIconClass}` : `MaskIcon MaskIcon${icon}`,
2780
2847
  role: None$1,
2781
2848
  type
2782
2849
  };
@@ -2808,7 +2875,7 @@ const getActivityBarItemVirtualDom = item => {
2808
2875
  role,
2809
2876
  title,
2810
2877
  type: Div
2811
- }, getIconVirtualDom(icon)];
2878
+ }, getIconVirtualDom(icon, Div, item.customIconClass)];
2812
2879
  }
2813
2880
 
2814
2881
  // TODO support progress on selected activity bar item
@@ -2823,7 +2890,7 @@ const getActivityBarItemVirtualDom = item => {
2823
2890
  ariaLabel: '',
2824
2891
  ariaSelected,
2825
2892
  childCount: 0,
2826
- className: mergeClassNames(className, `Icon${icon}`),
2893
+ className: mergeClassNames(className, getIconClass(item, 'Icon')),
2827
2894
  role,
2828
2895
  title,
2829
2896
  type: Div
@@ -2909,8 +2976,8 @@ const render2 = (uid, diffResult) => {
2909
2976
  const {
2910
2977
  newState,
2911
2978
  oldState
2912
- } = get(uid);
2913
- set(uid, newState, newState);
2979
+ } = get$2(uid);
2980
+ set$4(uid, newState, newState);
2914
2981
  const commands = applyRender(oldState, newState, diffResult);
2915
2982
  return commands;
2916
2983
  };
@@ -2990,7 +3057,7 @@ const toggleActivityBarItem = async (state, itemId) => {
2990
3057
  };
2991
3058
 
2992
3059
  const commandMap = {
2993
- 'ActivityBar.create': create,
3060
+ 'ActivityBar.create': create$9,
2994
3061
  'ActivityBar.diff2': diff2,
2995
3062
  'ActivityBar.focus': wrapCommand(focus),
2996
3063
  'ActivityBar.focusFirst': wrapCommand(focusFirst),
@@ -3029,25 +3096,39 @@ const commandMap = {
3029
3096
  'ActivityBar.toggleActivityBarItem': wrapCommand(toggleActivityBarItem)
3030
3097
  };
3031
3098
 
3032
- const send = async port => {
3099
+ const send$1 = async port => {
3033
3100
  // @ts-ignore
3034
3101
  await sendMessagePortToAuthWorker(port);
3035
3102
  };
3036
3103
  const initializeAuthWorker = async () => {
3037
- const rpc = await create$4({
3104
+ const rpc = await create$2({
3105
+ commandMap: {},
3106
+ send: send$1
3107
+ });
3108
+ set$2(rpc);
3109
+ };
3110
+
3111
+ const send = async port => {
3112
+ await sendMessagePortToExtensionManagementWorker(port, 0);
3113
+ };
3114
+ const initializeExtensionManagementWorker = async () => {
3115
+ const rpc = await create$2({
3038
3116
  commandMap: {},
3039
3117
  send
3040
3118
  });
3041
- set$3(rpc);
3119
+ set$1(rpc);
3042
3120
  };
3043
3121
 
3044
- const listen = async () => {
3045
- registerCommands(commandMap);
3046
- const rpc = await create$3({
3122
+ const initializeRendererWorker = async () => {
3123
+ const rpc = await create$1({
3047
3124
  commandMap: commandMap
3048
3125
  });
3049
- set$1(rpc);
3050
- await initializeAuthWorker();
3126
+ set(rpc);
3127
+ };
3128
+
3129
+ const listen = async () => {
3130
+ registerCommands(commandMap);
3131
+ await Promise.all([initializeRendererWorker(), initializeAuthWorker(), initializeExtensionManagementWorker()]);
3051
3132
  };
3052
3133
 
3053
3134
  const main = async () => {