English | 简体中文
A TypeScript plugin for Electron main-process renderer management. It watches tracked windows / webviews / offscreen renderers, starts a countdown after they go idle, and then throttles, hibernates, or destroys them. Activity restores reversible actions.
Install the root package to get the full public API.
- Node.js 20+
- ESM (
"type": "module") - Electron 20+ is an optional peer. Outside Electron the runtime still works; renderer actions fall back to an in-memory port unless you supply your own.
pnpm add smart-renderers
# or: npm install smart-renderersThis package re-exports the private workspace packages @smart-renderers/core (idle + countdown) and @smart-renderers/manager (actions). They are bundled into the published tarball and are not installed separately.
To try the latest dev tag instead of the latest official release:
pnpm add smart-renderers@devVersion badges above read npm dist-tags (latest and dev) and update automatically.
Call this from the Electron main process:
import { BrowserWindow } from "electron";
import { attachContents, createSmartRenderers } from "smart-renderers";
const renderers = createSmartRenderers({
countdownMs: 15 * 60 * 1000,
idleAfterMs: 0,
policy: {
onExpired: "hibernate",
revertOnActivity: true,
untrackOnDestroy: true,
},
});
const window = new BrowserWindow({ show: true });
const detach = attachContents(renderers, window.webContents, window);
window.on("focus", () => {
renderers.reportActivity(String(window.webContents.id));
});
window.on("closed", () => {
detach();
});
// Later
renderers.dispose();attachContents tracks webContents.id as the target id, binds a default Electron handle, and returns a function that untracks it.
- How it works
- API — options, methods, events, snapshots, lower-level exports
- Electron actions
- Packages
examples/electron is a live Electron app that attaches smart-renderers to real BrowserWindows. It shortens the timers, injects a controllable idle source, and shows countdown events plus throttle / hibernate / destroy on screen.
pnpm example:electronSee examples/electron/README.md.
MIT