@prozilla-os/core 1.0.7

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.
Files changed (161) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +1 -0
  3. package/package.json +43 -0
  4. package/src/components/_utils/button/Button.module.css +25 -0
  5. package/src/components/_utils/button/Button.tsx +48 -0
  6. package/src/components/_utils/directory-list/DirectoryList.module.css +70 -0
  7. package/src/components/_utils/directory-list/DirectoryList.tsx +203 -0
  8. package/src/components/_utils/directory-list/ImagePreview.module.css +19 -0
  9. package/src/components/_utils/directory-list/ImagePreview.tsx +33 -0
  10. package/src/components/_utils/dropdown-button/DropdownButton.module.css +60 -0
  11. package/src/components/_utils/dropdown-button/DropdownButton.tsx +40 -0
  12. package/src/components/_utils/header-menu/HeaderMenu.module.css +8 -0
  13. package/src/components/_utils/header-menu/HeaderMenu.tsx +15 -0
  14. package/src/components/_utils/index.ts +10 -0
  15. package/src/components/_utils/interactable/Interactable.tsx +42 -0
  16. package/src/components/_utils/progress-bar/ProgressBar.module.css +20 -0
  17. package/src/components/_utils/progress-bar/ProgressBar.tsx +22 -0
  18. package/src/components/_utils/web-view/WebView.module.css +15 -0
  19. package/src/components/_utils/web-view/WebView.tsx +47 -0
  20. package/src/components/actions/Actions.module.css +281 -0
  21. package/src/components/actions/Actions.tsx +108 -0
  22. package/src/components/actions/actions/ClickAction.tsx +30 -0
  23. package/src/components/actions/actions/Divider.tsx +5 -0
  24. package/src/components/actions/actions/DropdownAction.tsx +50 -0
  25. package/src/components/actions/actions/RadioAction.tsx +50 -0
  26. package/src/components/actions/actions/TextDisplay.tsx +12 -0
  27. package/src/components/actions/actions/ToggleAction.tsx +31 -0
  28. package/src/components/actions/index.ts +7 -0
  29. package/src/components/desktop/Desktop.module.css +49 -0
  30. package/src/components/desktop/Desktop.tsx +199 -0
  31. package/src/components/index.ts +10 -0
  32. package/src/components/modals/ModalView.module.css +14 -0
  33. package/src/components/modals/ModalView.tsx +54 -0
  34. package/src/components/modals/ModalsView.module.css +4 -0
  35. package/src/components/modals/ModalsView.tsx +32 -0
  36. package/src/components/modals/_utils/WindowedModal.module.css +92 -0
  37. package/src/components/modals/_utils/WindowedModal.tsx +71 -0
  38. package/src/components/modals/dialog-box/DialogBox.module.css +27 -0
  39. package/src/components/modals/dialog-box/DialogBox.tsx +26 -0
  40. package/src/components/modals/file-selector/FileSelector.module.css +25 -0
  41. package/src/components/modals/file-selector/FileSelector.tsx +77 -0
  42. package/src/components/modals/index.ts +7 -0
  43. package/src/components/modals/share/Option.tsx +23 -0
  44. package/src/components/modals/share/Share.module.css +153 -0
  45. package/src/components/modals/share/Share.tsx +197 -0
  46. package/src/components/prozilla-os/ProzillaOS.module.css +14 -0
  47. package/src/components/prozilla-os/ProzillaOS.tsx +76 -0
  48. package/src/components/taskbar/Taskbar.module.css +218 -0
  49. package/src/components/taskbar/Taskbar.tsx +193 -0
  50. package/src/components/taskbar/app-icon/AppIcon.module.css +62 -0
  51. package/src/components/taskbar/app-icon/AppIcon.tsx +76 -0
  52. package/src/components/taskbar/indicators/Battery.module.css +32 -0
  53. package/src/components/taskbar/indicators/Battery.tsx +114 -0
  54. package/src/components/taskbar/indicators/Calendar.module.css +24 -0
  55. package/src/components/taskbar/indicators/Calendar.tsx +67 -0
  56. package/src/components/taskbar/indicators/Network.module.css +17 -0
  57. package/src/components/taskbar/indicators/Network.tsx +38 -0
  58. package/src/components/taskbar/indicators/Volume.module.css +17 -0
  59. package/src/components/taskbar/indicators/Volume.tsx +38 -0
  60. package/src/components/taskbar/indicators/index.ts +4 -0
  61. package/src/components/taskbar/menus/AppList.module.css +33 -0
  62. package/src/components/taskbar/menus/HomeMenu.module.css +47 -0
  63. package/src/components/taskbar/menus/HomeMenu.tsx +118 -0
  64. package/src/components/taskbar/menus/SearchMenu.module.css +68 -0
  65. package/src/components/taskbar/menus/SearchMenu.tsx +100 -0
  66. package/src/components/taskbar/menus/UtilMenu.module.css +41 -0
  67. package/src/components/taskbar/menus/UtilMenu.tsx +23 -0
  68. package/src/components/windows/WindowFallbackView.tsx +38 -0
  69. package/src/components/windows/WindowView.module.css +152 -0
  70. package/src/components/windows/WindowView.tsx +233 -0
  71. package/src/components/windows/WindowsView.tsx +89 -0
  72. package/src/constants/index.ts +3 -0
  73. package/src/constants/modals.const.ts +3 -0
  74. package/src/constants/themes.const.ts +8 -0
  75. package/src/constants/utils.const.ts +19 -0
  76. package/src/constants/virtualDrive.const.ts +20 -0
  77. package/src/features/_utils/array.utils.ts +14 -0
  78. package/src/features/_utils/browser.utils.ts +111 -0
  79. package/src/features/_utils/date.utils.ts +90 -0
  80. package/src/features/_utils/event.utils.ts +39 -0
  81. package/src/features/_utils/index.ts +8 -0
  82. package/src/features/_utils/math.utils.ts +18 -0
  83. package/src/features/_utils/number.utils.ts +3 -0
  84. package/src/features/_utils/string.utils.ts +31 -0
  85. package/src/features/_utils/time.utils.ts +13 -0
  86. package/src/features/actions/actionsManager.ts +7 -0
  87. package/src/features/index.ts +12 -0
  88. package/src/features/math/vector2.ts +75 -0
  89. package/src/features/modals/modal.ts +74 -0
  90. package/src/features/modals/modalsManager.ts +72 -0
  91. package/src/features/settings/settings.ts +109 -0
  92. package/src/features/settings/settingsManager.ts +31 -0
  93. package/src/features/storage/storageManager.ts +35 -0
  94. package/src/features/system/configs/app.tsx +60 -0
  95. package/src/features/system/configs/appsConfig.ts +60 -0
  96. package/src/features/system/configs/desktopConfig.ts +46 -0
  97. package/src/features/system/configs/index.ts +9 -0
  98. package/src/features/system/configs/miscConfig.ts +19 -0
  99. package/src/features/system/configs/modalsConfig.ts +28 -0
  100. package/src/features/system/configs/taskbarConfig.ts +19 -0
  101. package/src/features/system/configs/trackingConfig.ts +24 -0
  102. package/src/features/system/configs/virtualDriveConfig.ts +39 -0
  103. package/src/features/system/configs/windowsConfig.ts +34 -0
  104. package/src/features/system/systemManager.ts +68 -0
  105. package/src/features/tracking/trackingManager.ts +40 -0
  106. package/src/features/virtual-drive/file/index.ts +2 -0
  107. package/src/features/virtual-drive/file/virtualFile.ts +197 -0
  108. package/src/features/virtual-drive/file/virtualFileLink.ts +111 -0
  109. package/src/features/virtual-drive/folder/index.ts +2 -0
  110. package/src/features/virtual-drive/folder/virtualFolder.ts +388 -0
  111. package/src/features/virtual-drive/folder/virtualFolderLink.ts +148 -0
  112. package/src/features/virtual-drive/index.ts +3 -0
  113. package/src/features/virtual-drive/root/defaultData.ts +140 -0
  114. package/src/features/virtual-drive/root/virtualRoot.ts +244 -0
  115. package/src/features/virtual-drive/virtualBase.ts +191 -0
  116. package/src/features/windows/windowsManager.ts +244 -0
  117. package/src/features/z-index/zIndexGroup.ts +40 -0
  118. package/src/features/z-index/zIndexManager.ts +46 -0
  119. package/src/hooks/_utils/history.ts +50 -0
  120. package/src/hooks/_utils/index.ts +6 -0
  121. package/src/hooks/_utils/keyboard.ts +111 -0
  122. package/src/hooks/_utils/mouse.ts +32 -0
  123. package/src/hooks/_utils/outsideClick.tsx +33 -0
  124. package/src/hooks/_utils/screen.ts +61 -0
  125. package/src/hooks/_utils/scrollWithShadows.ts +138 -0
  126. package/src/hooks/apps/appFolder.ts +30 -0
  127. package/src/hooks/index.ts +9 -0
  128. package/src/hooks/modals/alert.tsx +34 -0
  129. package/src/hooks/modals/contextMenu.tsx +47 -0
  130. package/src/hooks/modals/index.ts +4 -0
  131. package/src/hooks/modals/modalsContext.ts +10 -0
  132. package/src/hooks/modals/modalsManagerContext.ts +10 -0
  133. package/src/hooks/modals/modalsManagerProvider.tsx +16 -0
  134. package/src/hooks/modals/modalsProvider.tsx +20 -0
  135. package/src/hooks/modals/windowedModal.ts +47 -0
  136. package/src/hooks/settings/settingsManagerContext.ts +10 -0
  137. package/src/hooks/settings/settingsManagerProvider.tsx +16 -0
  138. package/src/hooks/system/systemManagerContext.ts +8 -0
  139. package/src/hooks/system/systemManagerProvider.tsx +26 -0
  140. package/src/hooks/themes/themes.tsx +22 -0
  141. package/src/hooks/tracking/trackingManagerContext.ts +10 -0
  142. package/src/hooks/tracking/trackingManagerProvider.tsx +13 -0
  143. package/src/hooks/virtual-drive/virtualRootContext.ts +10 -0
  144. package/src/hooks/virtual-drive/virtualRootProvider.tsx +13 -0
  145. package/src/hooks/windows/windowsContext.ts +10 -0
  146. package/src/hooks/windows/windowsManagerContext.ts +10 -0
  147. package/src/hooks/windows/windowsManagerProvider.tsx +24 -0
  148. package/src/hooks/windows/windowsProvider.tsx +20 -0
  149. package/src/hooks/z-index/zIndex.ts +32 -0
  150. package/src/hooks/z-index/zIndexManagerContext.ts +10 -0
  151. package/src/hooks/z-index/zIndexManagerProvider.tsx +11 -0
  152. package/src/index.ts +5 -0
  153. package/src/styles/global/fonts.css +18 -0
  154. package/src/styles/global/scrollbar.css +29 -0
  155. package/src/styles/global/themes.css +67 -0
  156. package/src/styles/global/variables.css +92 -0
  157. package/src/styles/global.css +65 -0
  158. package/src/styles/index.ts +3 -0
  159. package/src/styles/utils.module.css +22 -0
  160. package/src/types/util.d.ts +3 -0
  161. package/src/types/vite-env.d.ts +1 -0
@@ -0,0 +1,193 @@
1
+ import { CSSProperties, memo, MouseEvent, MutableRefObject, ReactEventHandler, UIEventHandler, useEffect, useRef, useState } from "react";
2
+ import styles from "./Taskbar.module.css";
3
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4
+ import { faCog, faSearch } from "@fortawesome/free-solid-svg-icons";
5
+ import { ReactSVG } from "react-svg";
6
+ import { HomeMenu } from "./menus/HomeMenu";
7
+ import { OutsideClickListener } from "../../hooks/_utils/outsideClick";
8
+ import { SearchMenu } from "./menus/SearchMenu";
9
+ import { useScrollWithShadow } from "../../hooks/_utils/scrollWithShadows";
10
+ import { AppButton } from "./app-icon/AppIcon";
11
+ import { useContextMenu } from "../../hooks/modals/contextMenu";
12
+ import { Actions } from "../actions/Actions";
13
+ import { ClickAction } from "../actions/actions/ClickAction";
14
+ import { useWindowsManager } from "../../hooks/windows/windowsManagerContext";
15
+ import { useSettingsManager } from "../../hooks/settings/settingsManagerContext";
16
+ import { SettingsManager } from "../../features/settings/settingsManager";
17
+ import { useWindows } from "../../hooks/windows/windowsContext";
18
+ import { ZIndexManager } from "../../features/z-index/zIndexManager";
19
+ import { useZIndex } from "../../hooks/z-index/zIndex";
20
+ import { Battery, Calendar, Network, Volume } from "./indicators";
21
+ import { useSystemManager } from "../../hooks";
22
+ import { App } from "../../features";
23
+
24
+ export const Taskbar = memo(() => {
25
+ const { taskbarConfig, appsConfig } = useSystemManager();
26
+ const ref = useRef<HTMLDivElement>(null);
27
+ const settingsManager = useSettingsManager();
28
+ const [showHome, setShowHome] = useState(false);
29
+ const [showSearch, setShowSearch] = useState(false);
30
+ const [hideUtilMenus, setHideUtilMenus] = useState(false);
31
+ const [searchQuery, setSearchQuery] = useState("");
32
+ const { boxShadow, onUpdate } = useScrollWithShadow({ ref: ref as MutableRefObject<HTMLElement>, shadow: {
33
+ offset: 20,
34
+ blurRadius: 10,
35
+ spreadRadius: -10,
36
+ color: { a: 25 }
37
+ } });
38
+ const inputRef = useRef(null);
39
+ const windowsManager = useWindowsManager();
40
+ const windows = useWindows();
41
+ const { onContextMenu } = useContextMenu({ Actions: (props) =>
42
+ <Actions avoidTaskbar={false} {...props}>
43
+ <ClickAction label={`Open ${"Settings"}`} icon={faCog} onTrigger={() => {
44
+ windowsManager?.open("settings");
45
+ }}/>
46
+ </Actions>
47
+ });
48
+ const [apps, setApps] = useState<App[]>([]);
49
+ const zIndex = useZIndex({ groupIndex: ZIndexManager.GROUPS.TASKBAR, index: 0 });
50
+
51
+ useEffect(() => {
52
+ const settings = settingsManager?.getSettings(SettingsManager.VIRTUAL_PATHS.taskbar);
53
+ void settings?.get("pins", (pinList: string) => {
54
+ const pins = pinList.split(",");
55
+
56
+ const newApps = appsConfig.apps.sort((appA, appB) => {
57
+ const indexA = pins.indexOf(appA.id);
58
+ const indexB = pins.indexOf(appB.id);
59
+ if (indexA < 0 && indexB > 0) {
60
+ return 1;
61
+ } else if (indexA > 0 && indexB < 0) {
62
+ return -1;
63
+ } else if (indexA < 0 && indexB < 0) {
64
+ return 0;
65
+ } else {
66
+ return indexA - indexB;
67
+ }
68
+ }).map((app) => {
69
+ app.isPinned = pins.includes(app.id);
70
+ return app;
71
+ });
72
+ setApps(newApps);
73
+ });
74
+ }, [settingsManager]);
75
+
76
+ const updateShowHome = (show: boolean) => {
77
+ setShowHome(show);
78
+
79
+ if (show) {
80
+ setShowSearch(false);
81
+ setHideUtilMenus(true);
82
+ }
83
+ };
84
+
85
+ const updateShowSearch = (show: boolean) => {
86
+ setShowSearch(show);
87
+
88
+ if (show) {
89
+ if (searchQuery !== "") {
90
+ setSearchQuery("");
91
+ }
92
+
93
+ setShowHome(false);
94
+ setHideUtilMenus(true);
95
+
96
+ if (inputRef.current) {
97
+ (inputRef.current as HTMLElement).focus();
98
+ window.scrollTo(0, document.body.scrollHeight);
99
+ }
100
+ } else {
101
+ setTimeout(() => {
102
+ if (!showSearch) {
103
+ setSearchQuery("");
104
+ }
105
+ }, 200);
106
+ }
107
+ };
108
+
109
+ const showUtilMenu = () => {
110
+ setShowHome(false);
111
+ setShowSearch(false);
112
+ setHideUtilMenus(false);
113
+ };
114
+
115
+ const search = (_query: string) => {
116
+ updateShowSearch(true);
117
+ };
118
+
119
+ return <div
120
+ style={{ "--taskbar-height": `${taskbarConfig.height}px`, zIndex } as CSSProperties}
121
+ className={styles.Taskbar}
122
+ data-allow-context-menu={true}
123
+ onContextMenu={(event) => {
124
+ if ((event.target as HTMLElement).getAttribute("data-allow-context-menu"))
125
+ onContextMenu(event as unknown as MouseEvent<HTMLElement, MouseEvent>);
126
+ }}
127
+ >
128
+ <div className={styles.MenuIcons}>
129
+ <div className={styles.HomeContainer}>
130
+ <OutsideClickListener onOutsideClick={() => { updateShowHome(false); }}>
131
+ <button
132
+ title="Home"
133
+ tabIndex={0}
134
+ className={`${styles.MenuButton} ${styles.HomeButton}`}
135
+ onClick={() => { updateShowHome(!showHome); }}
136
+ >
137
+ <ReactSVG src={"/icon.svg"}/>
138
+ </button>
139
+ <HomeMenu active={showHome} setActive={updateShowHome} search={search}/>
140
+ </OutsideClickListener>
141
+ </div>
142
+ <div className={styles.SearchContainer}>
143
+ <OutsideClickListener onOutsideClick={() => { updateShowSearch(false); }}>
144
+ <button
145
+ title="Search"
146
+ tabIndex={0}
147
+ className={styles.MenuButton}
148
+ onClick={() => { updateShowSearch(!showSearch); }}
149
+ >
150
+ <FontAwesomeIcon icon={faSearch}/>
151
+ </button>
152
+ <SearchMenu
153
+ active={showSearch}
154
+ setActive={updateShowSearch}
155
+ searchQuery={searchQuery}
156
+ setSearchQuery={setSearchQuery}
157
+ inputRef={inputRef as unknown as MutableRefObject<HTMLInputElement>}
158
+ />
159
+ </OutsideClickListener>
160
+ </div>
161
+ </div>
162
+ <div className={styles.AppIconsContainer} data-allow-context-menu={true} style={{ boxShadow }}>
163
+ <div
164
+ className={styles.AppIcons}
165
+ data-allow-context-menu={true}
166
+ onScroll={onUpdate as unknown as UIEventHandler}
167
+ onResize={onUpdate as unknown as ReactEventHandler}
168
+ ref={ref}
169
+ >
170
+ {apps.map((app) => {
171
+ if (windows == null) return;
172
+
173
+ const isActive = windows.map((window) => window.app?.id).includes(app.id);
174
+ const shouldBeShown = (app.isPinned || isActive);
175
+ return (<AppButton
176
+ windowsManager={windowsManager}
177
+ app={app}
178
+ key={app.id}
179
+ active={isActive}
180
+ visible={shouldBeShown}
181
+ />);
182
+ })}
183
+ </div>
184
+ </div>
185
+ <div className={styles.UtilIcons}>
186
+ <Battery showUtilMenu={showUtilMenu} hideUtilMenus={hideUtilMenus}/>
187
+ <Network showUtilMenu={showUtilMenu} hideUtilMenus={hideUtilMenus}/>
188
+ <Volume showUtilMenu={showUtilMenu} hideUtilMenus={hideUtilMenus}/>
189
+ <Calendar showUtilMenu={showUtilMenu} hideUtilMenus={hideUtilMenus}/>
190
+ <button title="Show Desktop" id="desktop-button" onClick={() => { windowsManager?.minimizeAll(); }}/>
191
+ </div>
192
+ </div>;
193
+ });
@@ -0,0 +1,62 @@
1
+ .App-icon {
2
+ opacity: 1;
3
+ position: relative;
4
+ width: var(--taskbar-height);
5
+ height: var(--taskbar-height);
6
+ aspect-ratio: 1;
7
+ animation: appear 100ms ease-out forwards;
8
+ }
9
+
10
+ .App-icon svg {
11
+ filter: var(--svg-drop-shadow-0);
12
+ }
13
+
14
+ .App-icon.Hidden {
15
+ animation: disappear 400ms ease-in-out forwards;
16
+ pointer-events: none;
17
+ }
18
+
19
+ @keyframes appear {
20
+ 0% {
21
+ opacity: 0;
22
+ }
23
+ 100% {
24
+ opacity: 1;
25
+ }
26
+ }
27
+
28
+ @keyframes disappear {
29
+ 0% {
30
+ opacity: 1;
31
+ }
32
+ 25% {
33
+ opacity: 0;
34
+ margin-right: 0;
35
+ }
36
+ 100% {
37
+ opacity: 0;
38
+ margin-right: calc(var(--taskbar-height) * -1);
39
+ }
40
+ }
41
+
42
+ .App-icon::after {
43
+ content: "";
44
+ position: absolute;
45
+ left: 50%;
46
+ bottom: 0;
47
+ width: 90%;
48
+ height: 0.15rem;
49
+ background-color: var(--foreground-color-0);
50
+ transition: height 200ms ease-in-out, width 200ms ease-in-out;
51
+ transform: translateX(-50%);
52
+ -webkit-transform: translateX(-50%);
53
+ }
54
+
55
+ .App-icon:hover::after,
56
+ .App-icon:focus-visible::after {
57
+ width: 100%;
58
+ }
59
+
60
+ .App-icon:not(.Active)::after {
61
+ height: 0;
62
+ }
@@ -0,0 +1,76 @@
1
+ import { FC, memo, MouseEvent } from "react";
2
+ import { App } from "../../../features/system/configs/app";
3
+ import styles from "./AppIcon.module.css";
4
+ import { ReactSVG } from "react-svg";
5
+ import { useSettingsManager } from "../../../hooks/settings/settingsManagerContext";
6
+ import { useContextMenu } from "../../../hooks/modals/contextMenu";
7
+ import { Actions } from "../../actions/Actions";
8
+ import { ClickAction } from "../../actions/actions/ClickAction";
9
+ import { WindowsManager } from "../../../features/windows/windowsManager";
10
+
11
+ interface AppButtonProps {
12
+ app: App;
13
+ windowsManager?: WindowsManager;
14
+ active: boolean;
15
+ visible: boolean;
16
+ }
17
+
18
+ export const AppButton: FC<AppButtonProps> = memo(({ app, windowsManager, active, visible }: AppButtonProps) => {
19
+ const settingsManager = useSettingsManager();
20
+ const { onContextMenu } = useContextMenu({ Actions: (props) =>
21
+ <Actions avoidTaskbar={false} {...props}>
22
+ <ClickAction label={app.name} icon={app.iconUrl as string | undefined} onTrigger={() => {
23
+ windowsManager?.open(app.id);
24
+ }}/>
25
+ {/* <ClickAction label={isPinned ? "Unpin from taskbar" : "Pin to taskbar"} icon={faThumbTack} onTrigger={() => {
26
+ const newPins = [...pins];
27
+ if (isPinned) {
28
+ removeFromArray(app.id, pins);
29
+ } else {
30
+ newPins.push(app.id);
31
+ }
32
+
33
+ const settings = settingsManager.get(SettingsManager.VIRTUAL_PATHS.taskbar);
34
+ void settings.set("pins", newPins.join(","));
35
+ }}/>
36
+ {active && <ClickAction label="Close window" icon={faTimes} onTrigger={() => {
37
+ windowsManager.close(windowsManager.getAppWindowId(app.id));
38
+ }}/>} */}
39
+ </Actions>
40
+ });
41
+
42
+ const classNames = [styles["App-icon"]];
43
+ if (active)
44
+ classNames.push(styles.Active);
45
+ if (!visible)
46
+ classNames.push(styles.Hidden);
47
+
48
+ if (!windowsManager)
49
+ return;
50
+
51
+ return (
52
+ <button
53
+ key={app.id}
54
+ tabIndex={0}
55
+ className={classNames.join(" ")}
56
+ onClick={() => {
57
+ const windowId = windowsManager.getAppWindowId(app.id);
58
+
59
+ if (!active || windowId == null) {
60
+ windowsManager.open(app.id);
61
+ } else if (!windowsManager.isFocused(windowId)) {
62
+ windowsManager.focus(windowId);
63
+ } else {
64
+ windowsManager.setMinimized(windowId);
65
+ }
66
+ }}
67
+ onContextMenu={(event) => {
68
+ if (visible)
69
+ onContextMenu(event as unknown as MouseEvent<HTMLElement, MouseEvent>);
70
+ }}
71
+ title={app.name}
72
+ >
73
+ <ReactSVG src={`/assets/apps/icons/${app.id}.svg`}/>
74
+ </button>
75
+ );
76
+ });
@@ -0,0 +1,32 @@
1
+ .Button {
2
+ position: relative;
3
+ }
4
+
5
+ .Charging-indicator {
6
+ --outline-color: var(--background-color-2);
7
+ --outline-width: 2px;
8
+
9
+ position: absolute;
10
+ top: 0.55rem;
11
+ right: 0.15rem;
12
+ height: 0.7rem !important;
13
+ }
14
+
15
+ .Menu > div {
16
+ display: flex;
17
+ gap: 0.5rem;
18
+ justify-content: center;
19
+ align-items: center;
20
+ padding: 0.5rem 1rem;
21
+ }
22
+
23
+ .Menu > div > div,
24
+ .Menu > div > div > svg {
25
+ width: auto;
26
+ height: 1.25rem;
27
+ }
28
+
29
+ .Menu > div > p {
30
+ margin: 0;
31
+ font-size: 1.25rem;
32
+ }
@@ -0,0 +1,114 @@
1
+ import { faBatteryEmpty, faBatteryFull, faBatteryHalf, faBatteryQuarter, faBatteryThreeQuarters, faMinus } from "@fortawesome/free-solid-svg-icons";
2
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3
+ import { useEffect, useState } from "react";
4
+ import styles from "./Battery.module.css";
5
+ import { UtilMenu } from "../menus/UtilMenu";
6
+ import { OutsideClickListener } from "../../../hooks/_utils/outsideClick";
7
+
8
+ type Battery = {
9
+ charging: boolean | ((prevState: boolean) => boolean);
10
+ level: number;
11
+ addEventListener: (arg0: string, arg1: {
12
+ (): void;
13
+ (): void;
14
+ }) => void;
15
+ removeEventListener: (arg0: string, arg1: {
16
+ (): void;
17
+ (): void;
18
+ }) => void;
19
+ };
20
+
21
+ interface BatteryProps {
22
+ hideUtilMenus: boolean;
23
+ showUtilMenu: Function;
24
+ }
25
+
26
+ export function Battery({ hideUtilMenus, showUtilMenu }: BatteryProps) {
27
+ const [isCharging, setIsCharging] = useState(true);
28
+ const [percentage, setPercentage] = useState(100);
29
+ const [showMenu, setShowMenu] = useState(false);
30
+ // const [chargingTime, setChargingTime] = useState(0);
31
+ // const [dischargingTime, setDischargingTime] = useState(0);
32
+
33
+ useEffect(() => {
34
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
35
+ (navigator as any).getBattery?.()?.then((battery: Battery) => {
36
+ const updateIsCharging = () => {
37
+ setIsCharging(battery.charging);
38
+ };
39
+
40
+ const updatePercentage = () => {
41
+ setPercentage(battery.level * 100);
42
+ };
43
+
44
+ // const updateChargingTime = () => {
45
+ // setChargingTime(battery.chargingTime);
46
+ // };
47
+
48
+ // const updateDischargingTime = () => {
49
+ // setDischargingTime(battery.dischargingTime);
50
+ // };
51
+
52
+ updateIsCharging();
53
+ updatePercentage();
54
+ // updateChargingTime();
55
+ // updateDischargingTime();
56
+
57
+ battery.addEventListener("chargingchange", updateIsCharging);
58
+ battery.addEventListener("levelchange", updatePercentage);
59
+ // battery.addEventListener("chargingtimechange", updateChargingTime);
60
+ // battery.addEventListener("dischargingtimechange", updateDischargingTime);
61
+
62
+ return () => {
63
+ battery.removeEventListener("chargingchange", updateIsCharging);
64
+ battery.removeEventListener("levelchange", updatePercentage);
65
+ // battery.removeEventListener("chargingtimechange", updateChargingTime);
66
+ // battery.removeEventListener("dischargingtimechange", updateDischargingTime);
67
+ };
68
+ });
69
+ }, []);
70
+
71
+ useEffect(() => {
72
+ if (hideUtilMenus && showMenu) {
73
+ setShowMenu(false);
74
+ }
75
+ }, [hideUtilMenus, showMenu]);
76
+
77
+ const updateShowMenu = (show: boolean) => {
78
+ if (show)
79
+ showUtilMenu();
80
+
81
+ setShowMenu(show);
82
+ };
83
+
84
+ let icon = faBatteryFull;
85
+ if (percentage < 10) {
86
+ icon = faBatteryEmpty;
87
+ } else if (percentage < 35) {
88
+ icon = faBatteryQuarter;
89
+ } else if (percentage < 65) {
90
+ icon = faBatteryHalf;
91
+ } else if (percentage < 90) {
92
+ icon = faBatteryThreeQuarters;
93
+ }
94
+
95
+ return (<OutsideClickListener onOutsideClick={() => { updateShowMenu(false); }}>
96
+ <button className={styles.Button} title="Battery" tabIndex={0} onClick={() => { updateShowMenu(!showMenu); }}>
97
+ {!isCharging
98
+ ? <FontAwesomeIcon className={styles["Charging-indicator"]} icon={faMinus}/>
99
+ : null
100
+ }
101
+ <FontAwesomeIcon icon={icon}/>
102
+ </button>
103
+ <UtilMenu active={showMenu} setActive={setShowMenu} className={styles.Menu}>
104
+ <div>
105
+ {!isCharging
106
+ ? <FontAwesomeIcon className={styles["Charging-indicator"]} icon={faMinus}/>
107
+ : null
108
+ }
109
+ <FontAwesomeIcon icon={icon}/>
110
+ </div>
111
+ <p>{Math.round(percentage)}%</p>
112
+ </UtilMenu>
113
+ </OutsideClickListener>);
114
+ }
@@ -0,0 +1,24 @@
1
+ .Button {
2
+ white-space: nowrap;
3
+ user-select: none;
4
+ }
5
+
6
+ .Menu > div {
7
+ display: flex;
8
+ gap: 0.5rem;
9
+ flex-direction: column;
10
+ align-items: flex-start;
11
+ padding: 0.5rem 1rem;
12
+ }
13
+
14
+ .Time, .Date {
15
+ margin: 0;
16
+ }
17
+
18
+ .Time {
19
+ font-size: 1.5rem;
20
+ }
21
+
22
+ .Date {
23
+ color: var(--foreground-color-1);
24
+ }
@@ -0,0 +1,67 @@
1
+ import { useEffect, useState } from "react";
2
+ import styles from "./Calendar.module.css";
3
+ import { OutsideClickListener } from "../../../hooks/_utils/outsideClick";
4
+ import { UtilMenu } from "../menus/UtilMenu";
5
+
6
+ interface CalendarProps {
7
+ hideUtilMenus: boolean;
8
+ showUtilMenu: Function;
9
+ }
10
+
11
+ export function Calendar({ hideUtilMenus, showUtilMenu }: CalendarProps) {
12
+ const [date, setDate] = useState(new Date());
13
+ const [showMenu, setShowMenu] = useState(false);
14
+
15
+ useEffect(() => {
16
+ const interval = setInterval(() => {
17
+ setDate(new Date());
18
+ }, showMenu ? 500 : 30000);
19
+
20
+ return () => {
21
+ clearInterval(interval);
22
+ };
23
+ }, [showMenu]);
24
+
25
+ useEffect(() => {
26
+ if (hideUtilMenus && showMenu) {
27
+ setShowMenu(false);
28
+ }
29
+ }, [hideUtilMenus, showMenu]);
30
+
31
+ const updateShowMenu = (show: boolean) => {
32
+ if (show)
33
+ showUtilMenu();
34
+
35
+ setShowMenu(show);
36
+ };
37
+
38
+ return (<OutsideClickListener onOutsideClick={() => { updateShowMenu(false); }}>
39
+ <button className={styles.Button} title="Date & Time" tabIndex={0} onClick={() => { updateShowMenu(!showMenu); }}>
40
+ {date.toLocaleString("en-GB", {
41
+ hour: "numeric",
42
+ minute: "numeric",
43
+ hour12: false,
44
+ })}
45
+ <br/>
46
+ {date.toLocaleDateString("en-GB", {
47
+ day: "numeric",
48
+ month: "short",
49
+ year: "numeric",
50
+ })}
51
+ </button>
52
+ <UtilMenu active={showMenu} setActive={setShowMenu} className={styles.Menu}>
53
+ <p className={styles.Time}>{date.toLocaleString("en-GB", {
54
+ hour: "numeric",
55
+ minute: "numeric",
56
+ second: "numeric",
57
+ hour12: false,
58
+ })}</p>
59
+ <p className={styles.Date}>{date.toLocaleString("en-GB", {
60
+ weekday: "long",
61
+ day: "numeric",
62
+ month: "long",
63
+ year: "numeric",
64
+ })}</p>
65
+ </UtilMenu>
66
+ </OutsideClickListener>);
67
+ }
@@ -0,0 +1,17 @@
1
+ .Menu > div {
2
+ display: flex;
3
+ gap: 0.5rem;
4
+ justify-content: center;
5
+ align-items: center;
6
+ padding: 0.5rem 1rem;
7
+ }
8
+
9
+ .Menu > div > svg {
10
+ width: auto;
11
+ height: 1rem;
12
+ }
13
+
14
+ .Menu > div > p {
15
+ margin: 0;
16
+ font-size: 1rem;
17
+ }
@@ -0,0 +1,38 @@
1
+ import { faWifi } from "@fortawesome/free-solid-svg-icons";
2
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3
+ import { useEffect, useState } from "react";
4
+ import { OutsideClickListener } from "../../../hooks/_utils/outsideClick";
5
+ import { UtilMenu } from "../menus/UtilMenu";
6
+ import styles from "./Network.module.css";
7
+
8
+ interface NetworkProps {
9
+ hideUtilMenus: boolean;
10
+ showUtilMenu: Function;
11
+ }
12
+
13
+ export function Network({ hideUtilMenus, showUtilMenu }: NetworkProps) {
14
+ const [showMenu, setShowMenu] = useState(false);
15
+
16
+ useEffect(() => {
17
+ if (hideUtilMenus && showMenu) {
18
+ setShowMenu(false);
19
+ }
20
+ }, [hideUtilMenus, showMenu]);
21
+
22
+ const updateShowMenu = (show: boolean) => {
23
+ if (show)
24
+ showUtilMenu();
25
+
26
+ setShowMenu(show);
27
+ };
28
+
29
+ return (<OutsideClickListener onOutsideClick={() => { updateShowMenu(false); }}>
30
+ <button title="Network" tabIndex={0} onClick={() => { updateShowMenu(!showMenu); }}>
31
+ <FontAwesomeIcon icon={faWifi}/>
32
+ </button>
33
+ <UtilMenu active={showMenu} setActive={setShowMenu} className={styles.Menu}>
34
+ <FontAwesomeIcon icon={faWifi}/>
35
+ <p>Connected</p>
36
+ </UtilMenu>
37
+ </OutsideClickListener>);
38
+ }
@@ -0,0 +1,17 @@
1
+ .Menu > div {
2
+ display: flex;
3
+ gap: 0.5rem;
4
+ justify-content: center;
5
+ align-items: center;
6
+ padding: 0.5rem 1rem;
7
+ }
8
+
9
+ .Menu > div > svg {
10
+ width: auto;
11
+ height: 1rem;
12
+ }
13
+
14
+ .Menu > div > p {
15
+ margin: 0;
16
+ font-size: 1rem;
17
+ }
@@ -0,0 +1,38 @@
1
+ import { faVolumeHigh } from "@fortawesome/free-solid-svg-icons";
2
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3
+ import { useEffect, useState } from "react";
4
+ import { OutsideClickListener } from "../../../hooks/_utils/outsideClick";
5
+ import { UtilMenu } from "../menus/UtilMenu";
6
+ import styles from "./Volume.module.css";
7
+
8
+ interface VolumeProps {
9
+ hideUtilMenus: boolean;
10
+ showUtilMenu: Function;
11
+ }
12
+
13
+ export function Volume({ hideUtilMenus, showUtilMenu }: VolumeProps) {
14
+ const [showMenu, setShowMenu] = useState(false);
15
+
16
+ useEffect(() => {
17
+ if (hideUtilMenus && showMenu) {
18
+ setShowMenu(false);
19
+ }
20
+ }, [hideUtilMenus, showMenu]);
21
+
22
+ const updateShowMenu = (show: boolean) => {
23
+ if (show)
24
+ showUtilMenu();
25
+
26
+ setShowMenu(show);
27
+ };
28
+
29
+ return (<OutsideClickListener onOutsideClick={() => { updateShowMenu(false); }}>
30
+ <button title="Volume" tabIndex={0} onClick={() => { updateShowMenu(!showMenu); }}>
31
+ <FontAwesomeIcon icon={faVolumeHigh}/>
32
+ </button>
33
+ <UtilMenu active={showMenu} setActive={setShowMenu} className={styles.Menu}>
34
+ <FontAwesomeIcon icon={faVolumeHigh}/>
35
+ <p>100%</p>
36
+ </UtilMenu>
37
+ </OutsideClickListener>);
38
+ }
@@ -0,0 +1,4 @@
1
+ export { Battery } from "./Battery";
2
+ export { Calendar } from "./Calendar";
3
+ export { Network } from "./Network";
4
+ export { Volume } from "./Volume";