|
4 | 4 | import { ErrorBoundary } from "@/app/element/errorboundary"; |
5 | 5 | import { CenteredDiv } from "@/app/element/quickelems"; |
6 | 6 | import { ModalsRenderer } from "@/app/modals/modalsrenderer"; |
| 7 | +import { NotificationPopover } from "@/app/notification/notificationpopover"; |
| 8 | +import { ContextMenuModel } from "@/app/store/contextmenu"; |
| 9 | +import { RpcApi } from "@/app/store/wshclientapi"; |
| 10 | +import { TabRpcClient } from "@/app/store/wshrpcutil"; |
7 | 11 | import { TabBar } from "@/app/tab/tabbar"; |
8 | 12 | import { TabContent } from "@/app/tab/tabcontent"; |
9 | | -import { atoms, createBlock, isDev } from "@/store/global"; |
10 | | -import { isBlank, makeIconClass } from "@/util/util"; |
| 13 | +import { atoms, createBlock, getApi, isDev } from "@/store/global"; |
| 14 | +import { fireAndForget, isBlank, makeIconClass } from "@/util/util"; |
| 15 | +import clsx from "clsx"; |
11 | 16 | import { useAtomValue } from "jotai"; |
12 | 17 | import { memo } from "react"; |
13 | | -import { NotificationPopover } from "../notification/notificationpopover"; |
14 | | - |
15 | | -import clsx from "clsx"; |
16 | 18 |
|
17 | 19 | const iconRegex = /^[a-z0-9-]+$/; |
18 | 20 |
|
@@ -56,12 +58,60 @@ const Widgets = memo(() => { |
56 | 58 | }; |
57 | 59 | const showHelp = fullConfig?.settings?.["widget:showhelp"] ?? true; |
58 | 60 | const widgets = sortByDisplayOrder(fullConfig?.widgets); |
| 61 | + |
| 62 | + const handleWidgetsBarContextMenu = (e: React.MouseEvent) => { |
| 63 | + e.preventDefault(); |
| 64 | + const menu: ContextMenuItem[] = [ |
| 65 | + { |
| 66 | + label: "Edit widgets.json", |
| 67 | + click: () => { |
| 68 | + fireAndForget(async () => { |
| 69 | + const path = `${getApi().getConfigDir()}/widgets.json`; |
| 70 | + const blockDef: BlockDef = { |
| 71 | + meta: { view: "preview", file: path }, |
| 72 | + }; |
| 73 | + await createBlock(blockDef, false, true); |
| 74 | + }); |
| 75 | + }, |
| 76 | + }, |
| 77 | + { |
| 78 | + label: "Show Help Widgets", |
| 79 | + submenu: [ |
| 80 | + { |
| 81 | + label: "On", |
| 82 | + type: "checkbox", |
| 83 | + checked: showHelp, |
| 84 | + click: () => { |
| 85 | + fireAndForget(async () => { |
| 86 | + await RpcApi.SetConfigCommand(TabRpcClient, { "widget:showhelp": true }); |
| 87 | + }); |
| 88 | + }, |
| 89 | + }, |
| 90 | + { |
| 91 | + label: "Off", |
| 92 | + type: "checkbox", |
| 93 | + checked: !showHelp, |
| 94 | + click: () => { |
| 95 | + fireAndForget(async () => { |
| 96 | + await RpcApi.SetConfigCommand(TabRpcClient, { "widget:showhelp": false }); |
| 97 | + }); |
| 98 | + }, |
| 99 | + }, |
| 100 | + ], |
| 101 | + }, |
| 102 | + ]; |
| 103 | + ContextMenuModel.showContextMenu(menu, e); |
| 104 | + }; |
| 105 | + |
59 | 106 | return ( |
60 | | - <div className="flex flex-col w-12 overflow-hidden py-1 -ml-1 select-none"> |
| 107 | + <div |
| 108 | + className="flex flex-col w-12 overflow-hidden py-1 -ml-1 select-none" |
| 109 | + onContextMenu={handleWidgetsBarContextMenu} |
| 110 | + > |
61 | 111 | {widgets?.map((data, idx) => <Widget key={`widget-${idx}`} widget={data} />)} |
| 112 | + <div className="flex-grow" /> |
62 | 113 | {showHelp ? ( |
63 | 114 | <> |
64 | | - <div className="flex-grow" /> |
65 | 115 | <Widget key="tips" widget={tipsWidget} /> |
66 | 116 | <Widget key="help" widget={helpWidget} /> |
67 | 117 | </> |
|
0 commit comments