@lvce-editor/status-bar-worker 3.13.0 → 3.15.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.
@@ -1340,7 +1340,7 @@ const handleClickExtensionStatusBarItem = async name => {
1340
1340
  };
1341
1341
 
1342
1342
  const handleClickNotification = async () => {
1343
- // TODO toggle notifications
1343
+ await invoke('Viewlet.openWidget', 'NotificationCenter');
1344
1344
  };
1345
1345
 
1346
1346
  const handleClickProblems = async () => {
@@ -1390,20 +1390,31 @@ const handleContextMenu = async (state, button, x, y) => {
1390
1390
  return state;
1391
1391
  };
1392
1392
 
1393
- const getNotificationsStatusBarItem = enabled => {
1393
+ const getAriaLabel = count => {
1394
+ if (count === 0) {
1395
+ return 'No Notifications';
1396
+ }
1397
+ if (count === 1) {
1398
+ return '1 Notification';
1399
+ }
1400
+ return `${count} Notifications`;
1401
+ };
1402
+ const getNotificationsStatusBarItem = (enabled, count = 0) => {
1394
1403
  if (!enabled) {
1395
1404
  return [];
1396
1405
  }
1397
1406
  return [{
1398
- ariaLabel: 'Notifications',
1407
+ ariaLabel: getAriaLabel(count),
1399
1408
  command: '',
1400
- // TODO should show notifications center
1401
1409
  elements: [{
1410
+ type: 'icon',
1411
+ value: 'NotificationBellIcon'
1412
+ }, ...(count > 0 ? [{
1402
1413
  type: 'text',
1403
- value: 'Notifications'
1404
- }],
1414
+ value: String(count)
1415
+ }] : [])],
1405
1416
  name: Notifications,
1406
- tooltip: 'Notifications'
1417
+ tooltip: getAriaLabel(count)
1407
1418
  }];
1408
1419
  };
1409
1420
 
@@ -1454,10 +1465,11 @@ const getProblemsStatusBarItem = (errorCount, warningCount, enabled) => {
1454
1465
  };
1455
1466
 
1456
1467
  const getBuiltinStatusBarItems = async (errorCount, warningCount, {
1468
+ notificationCount = 0,
1457
1469
  notificationsEnabled = true,
1458
1470
  problemsEnabled = true
1459
1471
  } = {}) => {
1460
- return [...getNotificationsStatusBarItem(notificationsEnabled), ...getProblemsStatusBarItem(errorCount, warningCount, problemsEnabled)];
1472
+ return [...getNotificationsStatusBarItem(notificationsEnabled, notificationCount), ...getProblemsStatusBarItem(errorCount, warningCount, problemsEnabled)];
1461
1473
  };
1462
1474
 
1463
1475
  const getExtensionStatusBarItems = async (assetDir, platform) => {
@@ -1526,6 +1538,13 @@ const toUiStatusBarItems = statusBarItems => {
1526
1538
  return statusBarItems.map(toUiStatusBarItem);
1527
1539
  };
1528
1540
 
1541
+ const getNotificationCount = async () => {
1542
+ try {
1543
+ return await invoke$1('Extensions.getNotificationCount');
1544
+ } catch {
1545
+ return 0;
1546
+ }
1547
+ };
1529
1548
  const getStatusBarItems = async ({
1530
1549
  assetDir,
1531
1550
  builtinNotificationsEnabled = true,
@@ -1539,8 +1558,10 @@ const getStatusBarItems = async ({
1539
1558
  return [];
1540
1559
  }
1541
1560
  const extensionStatusBarItems = await getExtensionStatusBarItems(assetDir, platform);
1561
+ const notificationCount = await getNotificationCount();
1542
1562
  const uiStatusBarItems = toUiStatusBarItems(extensionStatusBarItems);
1543
1563
  const extraItems = await getBuiltinStatusBarItems(errorCount, warningCount, {
1564
+ notificationCount,
1544
1565
  notificationsEnabled: builtinNotificationsEnabled,
1545
1566
  problemsEnabled: builtinProblemsEnabled
1546
1567
  });
@@ -1592,8 +1613,37 @@ const handleExtensionManagementChange = async () => {
1592
1613
  }
1593
1614
  };
1594
1615
 
1616
+ const handleNotificationCountChanged = (state, count) => {
1617
+ const {
1618
+ statusBarItemsRight
1619
+ } = state;
1620
+ const notificationsEnabled = statusBarItemsRight.some(item => item.name === Notifications);
1621
+ if (!notificationsEnabled) {
1622
+ return state;
1623
+ }
1624
+ return {
1625
+ ...state,
1626
+ statusBarItemsRight: getNotificationsStatusBarItem(true, count)
1627
+ };
1628
+ };
1629
+
1630
+ const handleNotificationCountChangedAll = async count => {
1631
+ for (const uid of getKeys()) {
1632
+ const {
1633
+ newState,
1634
+ oldState
1635
+ } = get$3(uid);
1636
+ const newerState = handleNotificationCountChanged(newState, count);
1637
+ if (newState === newerState || oldState === newerState) {
1638
+ continue;
1639
+ }
1640
+ set$3(uid, oldState, newerState);
1641
+ }
1642
+ };
1643
+
1595
1644
  const commandMap$1 = {
1596
- 'StatusBar.handleChange': handleExtensionManagementChange
1645
+ 'StatusBar.handleChange': handleExtensionManagementChange,
1646
+ 'StatusBar.handleNotificationCountChanged': handleNotificationCountChangedAll
1597
1647
  };
1598
1648
 
1599
1649
  const handleExtensionManagementMessagePort = async port => {
@@ -1604,6 +1654,27 @@ const handleExtensionManagementMessagePort = async port => {
1604
1654
  set$1(rpc);
1605
1655
  };
1606
1656
 
1657
+ const handleProblemsSummaryChange = (state, summary) => {
1658
+ const {
1659
+ errorCount: oldErrorCount,
1660
+ statusBarItemsLeft: oldStatusBarItemsLeft,
1661
+ warningCount: oldWarningCount
1662
+ } = state;
1663
+ const errorCount = summary.hasEditor ? summary.errorCount : 0;
1664
+ const warningCount = summary.hasEditor ? summary.warningCount : 0;
1665
+ if (oldErrorCount === errorCount && oldWarningCount === warningCount) {
1666
+ return state;
1667
+ }
1668
+ const problemsItem = getProblemsStatusBarItem(errorCount, warningCount, true)[0];
1669
+ const statusBarItemsLeft = oldStatusBarItemsLeft.map(item => item.name === Problems ? problemsItem : item);
1670
+ return {
1671
+ ...state,
1672
+ errorCount,
1673
+ statusBarItemsLeft,
1674
+ warningCount
1675
+ };
1676
+ };
1677
+
1607
1678
  const initialize = async () => {};
1608
1679
 
1609
1680
  const getIndex = (items, item) => {
@@ -1693,8 +1764,8 @@ const loadContent = async state => {
1693
1764
  ...state,
1694
1765
  errorCount: 0,
1695
1766
  initial: false,
1696
- statusBarItemsLeft: [...statusBarItems],
1697
- statusBarItemsRight: [],
1767
+ statusBarItemsLeft: statusBarItems.filter(item => item.name !== Notifications),
1768
+ statusBarItemsRight: statusBarItems.filter(item => item.name === Notifications),
1698
1769
  warningCount: 0
1699
1770
  };
1700
1771
  };
@@ -1892,6 +1963,8 @@ const commandMap = {
1892
1963
  'StatusBar.handleExtensionManagementMessagePort': handleExtensionManagementMessagePort,
1893
1964
  'StatusBar.handleExtensionsChanged': wrapCommand(handleExtensionsChanged),
1894
1965
  'StatusBar.handleItemsChanged': wrapCommand(handleItemsChanged),
1966
+ 'StatusBar.handleNotificationCountChanged': wrapCommand(handleNotificationCountChanged),
1967
+ 'StatusBar.handleProblemsSummaryChange': wrapCommand(handleProblemsSummaryChange),
1895
1968
  'StatusBar.initialize': initialize,
1896
1969
  'StatusBar.itemLeftUpdate': wrapCommand(itemLeftUpdate),
1897
1970
  'StatusBar.itemRightCreate': wrapCommand(itemRightCreate),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "3.13.0",
3
+ "version": "3.15.0",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",