@silkui/core 0.1.5 → 0.1.6

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 CHANGED
@@ -157,6 +157,22 @@ registerShortcut("Mod+Shift+B", build); // Mod is Command on macOS, Control else
157
157
  whichever app has focus; another app may hold it, and Wayland has none. `removeTray()` and
158
158
  `unregisterShortcut(accelerator)` undo them.
159
159
 
160
+ `memoryUsage()` is the app's memory as the system shows it to users, to put next to an
161
+ Electron app's in Activity Monitor or Task Manager. It is synchronous and allocates almost
162
+ nothing, so it can run every second.
163
+
164
+ ```ts
165
+ import { memoryUsage } from "@silkui/core";
166
+
167
+ const { footprint, processes } = memoryUsage(); // bytes, and how many processes they cover
168
+ ```
169
+
170
+ `footprint` is `phys_footprint` on macOS (Activity Monitor's "Memory", `/usr/bin/footprint`),
171
+ `Pss` from `/proc/self/smaps_rollup` on Linux and `PrivateUsage` on Windows. `processes` is 1:
172
+ the host runs the app, its tree and its JavaScript in one process. In a web-canvas build it
173
+ is the wasm tree's memory only, without the page's JavaScript heap. It is `null` when the
174
+ host cannot say.
175
+
160
176
  ### Attributes and accessibility
161
177
 
162
178
  `setAttribute(name, value)` sets the tree's attributes: `tabIndex`, `disabled`, `label`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silkui/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "The node and event API of a Silk UI tree for JavaScript applications that run on the embedded SilkJS engine",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.d.ts CHANGED
@@ -488,3 +488,16 @@ export function removeTray(): void;
488
488
  */
489
489
  export function registerShortcut(accelerator: string, callback: () => void): Promise<boolean>;
490
490
  export function unregisterShortcut(accelerator: string): void;
491
+
492
+ /** The app's memory: `footprint` in bytes over `processes` processes. */
493
+ export interface MemoryUsage {
494
+ footprint: number;
495
+ processes: number;
496
+ }
497
+
498
+ /**
499
+ * The app's memory as the system shows it to users (macOS `phys_footprint`, Linux `Pss`,
500
+ * Windows `PrivateUsage`). In the browser, the wasm tree's linear memory only. Cheap enough
501
+ * to call every second; `null` when the host cannot say.
502
+ */
503
+ export function memoryUsage(): MemoryUsage | null;
package/src/index.js CHANGED
@@ -1897,3 +1897,14 @@ export function unregisterShortcut(accelerator) {
1897
1897
  shortcuts.delete(id);
1898
1898
  shellCall(4, [id]);
1899
1899
  }
1900
+
1901
+ /**
1902
+ * The app's memory in bytes, as the system shows it to users: `phys_footprint` on macOS
1903
+ * (Activity Monitor's "Memory"), `Pss` on Linux and `PrivateUsage` on Windows. `processes` is
1904
+ * how many processes `footprint` counts: the host is one. In the browser it is the wasm
1905
+ * tree's linear memory, without the page's JavaScript heap. `null` when there is no answer.
1906
+ */
1907
+ export function memoryUsage() {
1908
+ const footprint = native.memoryUsage?.() ?? 0;
1909
+ return footprint > 0 ? { footprint, processes: 1 } : null;
1910
+ }