@lvce-editor/status-bar-worker 2.2.0 → 2.4.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.
@@ -1245,23 +1245,28 @@ const diff2 = uid => {
1245
1245
  return result;
1246
1246
  };
1247
1247
 
1248
- const getMatchingItem = (itemsLeft, itemsRight, name) => {
1249
- for (const item of itemsLeft) {
1250
- if (item.name === name) {
1251
- return item;
1252
- }
1253
- }
1254
- for (const item of itemsRight) {
1248
+ const getMatchingItemInternal = (items, name) => {
1249
+ for (const item of items) {
1255
1250
  if (item.name === name) {
1256
1251
  return item;
1257
1252
  }
1258
1253
  }
1259
1254
  return undefined;
1260
1255
  };
1256
+ const getMatchingItem = (itemsLeft, itemsRight, name) => {
1257
+ return getMatchingItemInternal(itemsLeft, name) ?? getMatchingItemInternal(itemsRight, name);
1258
+ };
1261
1259
 
1262
1260
  const handleClickExtensionStatusBarItem = async name => {
1263
- // @ts-ignore
1264
- await invoke$1(`ExtensionHostStatusBar.executeCommand`, name);
1261
+ // TODO maybe relay this to extension management worker,
1262
+ // and it forwards it to the right extension host?
1263
+
1264
+ try {
1265
+ // @ts-ignore
1266
+ await invoke$1(`ExtensionHostStatusBar.executeCommand`, name);
1267
+ } catch (error) {
1268
+ console.error(new VError(error, `Failed to execute status bar command: ${name}`));
1269
+ }
1265
1270
  };
1266
1271
 
1267
1272
  const handleClickNotification = async () => {
@@ -1306,78 +1311,6 @@ const handleContextMenu = async state => {
1306
1311
  return state;
1307
1312
  };
1308
1313
 
1309
- const handleExtensionsChanged = async state => {
1310
- // TODO requery status bar items
1311
- return state;
1312
- };
1313
-
1314
- const id = 7201;
1315
- const sendMessagePortToExtensionHostWorker = async port => {
1316
- await sendMessagePortToExtensionHostWorker$1(port, id);
1317
- };
1318
-
1319
- const createExtensionHostRpc = async () => {
1320
- try {
1321
- const rpc = await create$4({
1322
- commandMap: {},
1323
- send: sendMessagePortToExtensionHostWorker
1324
- });
1325
- return rpc;
1326
- } catch (error) {
1327
- throw new VError(error, `Failed to create extension host rpc`);
1328
- }
1329
- };
1330
-
1331
- const initialize = async () => {
1332
- const rpc = await createExtensionHostRpc();
1333
- set$2(rpc);
1334
- };
1335
-
1336
- const getIndex = (items, item) => {
1337
- for (let i = 0; i < items.length; i++) {
1338
- if (items[i].name === item.name) {
1339
- return i;
1340
- }
1341
- }
1342
- return -1;
1343
- };
1344
-
1345
- const updateArray = (items, newItem) => {
1346
- const index = getIndex(items, newItem);
1347
- const before = items.slice(0, index);
1348
- const after = items.slice(index + 1);
1349
- return [...before, newItem, ...after];
1350
- };
1351
-
1352
- const itemLeftUpdate = (state, newItem) => {
1353
- return {
1354
- ...state,
1355
- statusBarItemsLeft: updateArray([...state.statusBarItemsLeft], newItem)
1356
- };
1357
- };
1358
-
1359
- const itemRightCreate = (state, newItem) => {
1360
- const {
1361
- statusBarItemsRight
1362
- } = state;
1363
- const newStatusBarItemsRight = [...statusBarItemsRight, newItem];
1364
- return {
1365
- ...state,
1366
- statusBarItemsRight: newStatusBarItemsRight
1367
- };
1368
- };
1369
-
1370
- const itemRightUpdate = (state, newItem) => {
1371
- const {
1372
- statusBarItemsRight
1373
- } = state;
1374
- const newStatusBarItemsRight = updateArray([...statusBarItemsRight], newItem);
1375
- return {
1376
- ...state,
1377
- statusBarItemsRight: newStatusBarItemsRight
1378
- };
1379
- };
1380
-
1381
1314
  const OnStatusBarItem = 'onStatusBarItem';
1382
1315
 
1383
1316
  const GetStatusBarItems = 'ExtensionHost.getStatusBarItems2';
@@ -1565,6 +1498,100 @@ const getStatusBarItems = async ({
1565
1498
  return [...uiStatusBarItems.map(toStatusBarItem), ...extraItems];
1566
1499
  };
1567
1500
 
1501
+ const handleExtensionsChanged = async state => {
1502
+ const {
1503
+ assetDir,
1504
+ errorCount,
1505
+ platform,
1506
+ warningCount
1507
+ } = state;
1508
+ // TODO requery status bar items
1509
+ const statusBarItems = await getStatusBarItems({
1510
+ assetDir,
1511
+ builtinNotificationsEnabled: false,
1512
+ builtinProblemsEnabled: false,
1513
+ errorCount,
1514
+ platform,
1515
+ showItems: true,
1516
+ warningCount
1517
+ });
1518
+ return {
1519
+ ...state,
1520
+ statusBarItemsLeft: [...statusBarItems]
1521
+ };
1522
+ };
1523
+
1524
+ const handleItemsChanged = async state => {
1525
+ return handleExtensionsChanged(state);
1526
+ };
1527
+
1528
+ const id = 7201;
1529
+ const sendMessagePortToExtensionHostWorker = async port => {
1530
+ await sendMessagePortToExtensionHostWorker$1(port, id);
1531
+ };
1532
+
1533
+ const createExtensionHostRpc = async () => {
1534
+ try {
1535
+ const rpc = await create$4({
1536
+ commandMap: {},
1537
+ send: sendMessagePortToExtensionHostWorker
1538
+ });
1539
+ return rpc;
1540
+ } catch (error) {
1541
+ throw new VError(error, `Failed to create extension host rpc`);
1542
+ }
1543
+ };
1544
+
1545
+ const initialize = async () => {
1546
+ const rpc = await createExtensionHostRpc();
1547
+ set$2(rpc);
1548
+ };
1549
+
1550
+ const getIndex = (items, item) => {
1551
+ for (let i = 0; i < items.length; i++) {
1552
+ if (items[i].name === item.name) {
1553
+ return i;
1554
+ }
1555
+ }
1556
+ return -1;
1557
+ };
1558
+
1559
+ const updateArray = (items, newItem) => {
1560
+ const index = getIndex(items, newItem);
1561
+ const before = items.slice(0, index);
1562
+ const after = items.slice(index + 1);
1563
+ return [...before, newItem, ...after];
1564
+ };
1565
+
1566
+ const itemLeftUpdate = (state, newItem) => {
1567
+ return {
1568
+ ...state,
1569
+ statusBarItemsLeft: updateArray([...state.statusBarItemsLeft], newItem)
1570
+ };
1571
+ };
1572
+
1573
+ const itemRightCreate = (state, newItem) => {
1574
+ const {
1575
+ statusBarItemsRight
1576
+ } = state;
1577
+ const newStatusBarItemsRight = [...statusBarItemsRight, newItem];
1578
+ return {
1579
+ ...state,
1580
+ statusBarItemsRight: newStatusBarItemsRight
1581
+ };
1582
+ };
1583
+
1584
+ const itemRightUpdate = (state, newItem) => {
1585
+ const {
1586
+ statusBarItemsRight
1587
+ } = state;
1588
+ const newStatusBarItemsRight = updateArray([...statusBarItemsRight], newItem);
1589
+ return {
1590
+ ...state,
1591
+ statusBarItemsRight: newStatusBarItemsRight
1592
+ };
1593
+ };
1594
+
1568
1595
  const get = async key => {
1569
1596
  return getPreference(key);
1570
1597
  };
@@ -2084,9 +2111,11 @@ const commandMap = {
2084
2111
  'StatusBar.create': create,
2085
2112
  'StatusBar.diff2': diff2,
2086
2113
  'StatusBar.getCommandIds': getCommandIds,
2114
+ 'StatusBar.handleChange': wrapCommand(handleItemsChanged),
2087
2115
  'StatusBar.handleClick': wrapCommand(handleClick),
2088
2116
  'StatusBar.handleContextMenu': wrapCommand(handleContextMenu),
2089
2117
  'StatusBar.handleExtensionsChanged': wrapCommand(handleExtensionsChanged),
2118
+ 'StatusBar.handleItemsChanged': wrapCommand(handleItemsChanged),
2090
2119
  'StatusBar.initialize': initialize,
2091
2120
  'StatusBar.itemLeftUpdate': wrapCommand(itemLeftUpdate),
2092
2121
  'StatusBar.itemRightCreate': wrapCommand(itemRightCreate),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",