@lvce-editor/status-bar-worker 3.14.0 → 3.15.1

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,41 @@ 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
+ const [notificationItem] = getNotificationsStatusBarItem(true, count);
1625
+ if (!notificationItem) {
1626
+ return state;
1627
+ }
1628
+ return {
1629
+ ...state,
1630
+ statusBarItemsRight: statusBarItemsRight.map(item => item.name === Notifications ? notificationItem : item)
1631
+ };
1632
+ };
1633
+
1634
+ const handleNotificationCountChangedAll = async count => {
1635
+ for (const uid of getKeys()) {
1636
+ const {
1637
+ newState,
1638
+ oldState
1639
+ } = get$3(uid);
1640
+ const newerState = handleNotificationCountChanged(newState, count);
1641
+ if (newState === newerState || oldState === newerState) {
1642
+ continue;
1643
+ }
1644
+ set$3(uid, oldState, newerState);
1645
+ }
1646
+ };
1647
+
1595
1648
  const commandMap$1 = {
1596
- 'StatusBar.handleChange': handleExtensionManagementChange
1649
+ 'StatusBar.handleChange': handleExtensionManagementChange,
1650
+ 'StatusBar.handleNotificationCountChanged': handleNotificationCountChangedAll
1597
1651
  };
1598
1652
 
1599
1653
  const handleExtensionManagementMessagePort = async port => {
@@ -1714,8 +1768,8 @@ const loadContent = async state => {
1714
1768
  ...state,
1715
1769
  errorCount: 0,
1716
1770
  initial: false,
1717
- statusBarItemsLeft: [...statusBarItems],
1718
- statusBarItemsRight: [],
1771
+ statusBarItemsLeft: statusBarItems.filter(item => item.name !== Notifications),
1772
+ statusBarItemsRight: statusBarItems.filter(item => item.name === Notifications),
1719
1773
  warningCount: 0
1720
1774
  };
1721
1775
  };
@@ -1913,6 +1967,7 @@ const commandMap = {
1913
1967
  'StatusBar.handleExtensionManagementMessagePort': handleExtensionManagementMessagePort,
1914
1968
  'StatusBar.handleExtensionsChanged': wrapCommand(handleExtensionsChanged),
1915
1969
  'StatusBar.handleItemsChanged': wrapCommand(handleItemsChanged),
1970
+ 'StatusBar.handleNotificationCountChanged': wrapCommand(handleNotificationCountChanged),
1916
1971
  'StatusBar.handleProblemsSummaryChange': wrapCommand(handleProblemsSummaryChange),
1917
1972
  'StatusBar.initialize': initialize,
1918
1973
  'StatusBar.itemLeftUpdate': wrapCommand(itemLeftUpdate),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "3.14.0",
3
+ "version": "3.15.1",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",