react-x11 2.6.1 → 2.8.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.
- package/README.md +5 -3
- package/package.json +10 -3
- package/src/activate.js +12 -0
- package/src/anchor.js +6 -0
- package/src/appearance.js +351 -28
- package/src/appearancehooks.js +5 -2
- package/src/application.js +41 -0
- package/src/cocoa/app.js +367 -3
- package/src/cocoa/bezels.js +51 -1
- package/src/cocoa/dnd.js +358 -0
- package/src/cocoa/dock.js +39 -0
- package/src/cocoa/filepanels.js +155 -0
- package/src/cocoa/fonts.js +93 -2
- package/src/cocoa/globalmenu.js +41 -33
- package/src/cocoa/notifications.js +244 -0
- package/src/cocoa/permissions.js +74 -0
- package/src/cocoa/presenter.js +274 -33
- package/src/cocoa/promotion.js +708 -0
- package/src/cocoa/statusitem.js +112 -0
- package/src/cocoa/window.js +113 -4
- package/src/components/Button.js +20 -1
- package/src/components/Checkbox.js +17 -2
- package/src/components/Menu.js +108 -38
- package/src/components/Radio.js +17 -2
- package/src/components/Select.js +159 -27
- package/src/components/Switch.js +8 -1
- package/src/components/native.js +99 -0
- package/src/components/theme.js +37 -20
- package/src/desktopsettings.js +34 -2
- package/src/dnd.js +137 -11
- package/src/errors.js +6 -3
- package/src/filedialog.js +81 -16
- package/src/index.d.ts +29 -2
- package/src/index.js +17 -0
- package/src/launcher.js +170 -0
- package/src/launcherhooks.js +81 -0
- package/src/nodes.js +604 -37
- package/src/notificationhooks.js +56 -0
- package/src/notifications.js +558 -0
- package/src/palette.js +144 -8
- package/src/permissionhooks.js +89 -0
- package/src/permissions.js +196 -0
- package/src/style.d.ts +10 -4
- package/src/style.js +1 -0
- package/src/styles.js +161 -15
- package/src/textselection.js +1 -4
- package/src/trayhooks.js +90 -0
- package/src/types/appearance.d.ts +24 -0
- package/src/types/components.d.ts +10 -0
- package/src/types/elements.d.ts +14 -0
- package/src/types/events.d.ts +14 -0
- package/src/types/filedialog.d.ts +18 -7
- package/src/types/launcher.d.ts +43 -0
- package/src/types/notifications.d.ts +113 -0
- package/src/types/permissions.d.ts +100 -0
- package/src/types/style.d.ts +30 -2
- package/src/types/system.d.ts +5 -3
- package/src/types/tray.d.ts +54 -0
- package/src/windowid.js +23 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// `useBadge()` and `useDockMenu()` — the launcher's view of the app, as
|
|
2
|
+
// things a component declares rather than manages.
|
|
3
|
+
//
|
|
4
|
+
// The badge lives in `launcher.js` and is cross-backend; the Dock menu is
|
|
5
|
+
// the cocoa backend's alone, because its freedesktop counterpart — desktop
|
|
6
|
+
// actions in the `.desktop` file — is an install step and not runtime code.
|
|
7
|
+
// Where a hook has no mechanism it is inert, with a one-time development
|
|
8
|
+
// note naming the backend: the inert-props policy of docs/macos.md, so
|
|
9
|
+
// shared app code stays branch-free.
|
|
10
|
+
|
|
11
|
+
import { useEffect, useRef } from 'react';
|
|
12
|
+
|
|
13
|
+
import { useAppOrNull } from './appcontext.js';
|
|
14
|
+
import { setBadge } from './launcher.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Show `value` on the app's icon while this component is mounted, and clear
|
|
18
|
+
* it on unmount.
|
|
19
|
+
*
|
|
20
|
+
* ```jsx
|
|
21
|
+
* useBadge(unread); // a count; 0 clears
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* A number shows on both backends; a string shows on macOS only — see
|
|
25
|
+
* docs/desktop.md. Nothing is shown where nothing can show it, silently: a
|
|
26
|
+
* badge is not a feature an app should branch on.
|
|
27
|
+
*/
|
|
28
|
+
export function useBadge(value) {
|
|
29
|
+
const app = useAppOrNull();
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
setBadge(value, { app }).catch(() => {});
|
|
32
|
+
}, [value, app]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
return () => {
|
|
35
|
+
setBadge(null, { app }).catch(() => {});
|
|
36
|
+
};
|
|
37
|
+
}, [app]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let warnedInert = false;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The menu behind a right-click on the Dock icon, from the same `items`
|
|
44
|
+
* vocabulary `MenuBar` and `ContextMenu` take — an item's `onSelect` fires
|
|
45
|
+
* when the user picks it.
|
|
46
|
+
*
|
|
47
|
+
* ```jsx
|
|
48
|
+
* useDockMenu([
|
|
49
|
+
* { label: 'New Window', onSelect: openWindow },
|
|
50
|
+
* { type: 'separator' },
|
|
51
|
+
* { label: 'Recent', items: recent.map(toItem) },
|
|
52
|
+
* ]);
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* Installed for as long as the component is mounted, replaced when `items`
|
|
56
|
+
* changes, and taken down on unmount. Inert off the cocoa backend, with a
|
|
57
|
+
* development note the first time.
|
|
58
|
+
*/
|
|
59
|
+
export function useDockMenu(items) {
|
|
60
|
+
const app = useAppOrNull();
|
|
61
|
+
// read at activation time, so a pick three minutes from now runs the
|
|
62
|
+
// handler from the current render rather than the mounting one
|
|
63
|
+
const live = useRef(items);
|
|
64
|
+
live.current = items;
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (typeof app?.setDockMenu !== 'function') {
|
|
68
|
+
if (process.env.NODE_ENV !== 'production' && !warnedInert && app) {
|
|
69
|
+
warnedInert = true;
|
|
70
|
+
console.warn(
|
|
71
|
+
'react-x11: useDockMenu() is inert on this backend — only the ' +
|
|
72
|
+
'cocoa backend has a Dock. On a Linux desktop the counterpart ' +
|
|
73
|
+
'is desktop actions in the .desktop file (docs/desktop.md).',
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
app.setDockMenu(items ?? null);
|
|
79
|
+
return () => app.setDockMenu(null);
|
|
80
|
+
}, [items, app]);
|
|
81
|
+
}
|