terminal-buddy-widget 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ian Nnamani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,10 @@
1
- # Temporary Holding Version
1
+ # Terminal Buddy widget
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A small always-on-top glass window that shows what `tb` is running on this laptop.
4
+
5
+ ```bash
6
+ npx terminal-buddy-widget
7
+ # or, with the CLI installed: tb widget
8
+ ```
9
+
10
+ Part of [Terminal Buddy](https://github.com/ianth3creator/terminal-buddy).
package/bin/widget.cjs ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ // `npx terminal-buddy-widget` (or `tb widget`): start the Electron widget and return the terminal.
3
+ const { spawn } = require("node:child_process");
4
+ const path = require("node:path");
5
+ const electron = require("electron"); // path to the Electron binary
6
+ const child = spawn(electron, [path.join(__dirname, "..")], { detached: true, stdio: "ignore", windowsHide: false });
7
+ child.unref();
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "terminal-buddy-widget",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Floating desktop widget for Terminal Buddy: the current terminal run, always on top.",
5
+ "license": "MIT",
6
+ "author": "Ian Nnamani",
7
+ "homepage": "https://github.com/ianth3creator/terminal-buddy#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ianth3creator/terminal-buddy.git"
11
+ },
12
+ "main": "src/main.cjs",
13
+ "bin": {
14
+ "terminal-buddy-widget": "bin/widget.cjs"
15
+ },
16
+ "files": [
17
+ "src",
18
+ "bin",
19
+ "web",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "dependencies": {
27
+ "electron": "^39.2.0"
28
+ }
29
+ }
package/src/main.cjs ADDED
@@ -0,0 +1,137 @@
1
+ // Terminal Buddy desktop widget: a small always-on-top glass window showing the current tb run.
2
+ const { app, BrowserWindow, ipcMain, net, protocol, screen } = require("electron");
3
+ const fs = require("node:fs");
4
+ const os = require("node:os");
5
+ const path = require("node:path");
6
+ const { pathToFileURL } = require("node:url");
7
+
8
+ const HOME = process.env.TB_HOME || path.join(os.homedir(), ".terminal-buddy");
9
+ const SESSION_FILE = path.join(HOME, "session.json");
10
+ const PLACE_FILE = path.join(HOME, "widget.json");
11
+ const SIZE = { width: 380, height: 150 };
12
+
13
+ // The widget page: bundled next to this app, or the web build in the repo.
14
+ const WEB = [path.join(__dirname, "../web"), path.join(__dirname, "../../web/dist")].find((d) =>
15
+ fs.existsSync(path.join(d, "widget.html")),
16
+ );
17
+
18
+ protocol.registerSchemesAsPrivileged([{ scheme: "tb", privileges: { standard: true, secure: true, supportFetchAPI: true } }]);
19
+
20
+ if (!app.requestSingleInstanceLock()) app.quit();
21
+
22
+ /** The running tb session, if its process is still alive. */
23
+ function readSession() {
24
+ try {
25
+ const s = JSON.parse(fs.readFileSync(SESSION_FILE, "utf8"));
26
+ process.kill(s.pid, 0); // throws if that tb is gone (e.g. its window was closed hard)
27
+ return { port: s.port, token: s.token };
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ function savedPlace() {
34
+ try {
35
+ const p = JSON.parse(fs.readFileSync(PLACE_FILE, "utf8"));
36
+ // Only reuse it if it's still on a connected screen.
37
+ const onScreen = screen.getAllDisplays().some((d) => {
38
+ const a = d.workArea;
39
+ return p.x >= a.x && p.y >= a.y && p.x + 40 <= a.x + a.width && p.y + 40 <= a.y + a.height;
40
+ });
41
+ return onScreen ? p : null;
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ /** Windows 11 22H2+ can draw real acrylic glass behind a window. */
48
+ function supportsAcrylic() {
49
+ if (process.platform !== "win32") return false;
50
+ const build = Number(os.release().split(".")[2] || 0);
51
+ return build >= 22621;
52
+ }
53
+
54
+ let win = null;
55
+
56
+ function createWindow() {
57
+ const acrylic = supportsAcrylic();
58
+ const area = screen.getPrimaryDisplay().workArea;
59
+ const place = savedPlace() ?? { x: area.x + area.width - SIZE.width - 24, y: area.y + area.height - SIZE.height - 24 };
60
+
61
+ win = new BrowserWindow({
62
+ ...SIZE,
63
+ ...place,
64
+ frame: false,
65
+ resizable: false,
66
+ maximizable: false,
67
+ fullscreenable: false,
68
+ alwaysOnTop: true,
69
+ title: "Terminal Buddy",
70
+ show: false,
71
+ ...(acrylic ? { backgroundMaterial: "acrylic", backgroundColor: "#00000000" } : { transparent: true, backgroundColor: "#00000000" }),
72
+ webPreferences: {
73
+ preload: path.join(__dirname, "preload.cjs"),
74
+ contextIsolation: true,
75
+ sandbox: true,
76
+ nodeIntegration: false,
77
+ },
78
+ });
79
+ win.setAlwaysOnTop(true, "floating");
80
+
81
+ // Locked down: no navigation away, no new windows.
82
+ win.webContents.on("will-navigate", (e) => e.preventDefault());
83
+ win.webContents.setWindowOpenHandler(() => ({ action: "deny" }));
84
+
85
+ const url = process.env.TB_WIDGET_URL || "tb://app/widget.html";
86
+ win.loadURL(`${url}?mode=${acrylic ? "acrylic" : "css"}`);
87
+ win.once("ready-to-show", () => win.showInactive());
88
+
89
+ let saveTimer = null;
90
+ win.on("moved", () => {
91
+ clearTimeout(saveTimer);
92
+ saveTimer = setTimeout(() => {
93
+ try {
94
+ fs.mkdirSync(HOME, { recursive: true });
95
+ const [x, y] = win.getPosition();
96
+ fs.writeFileSync(PLACE_FILE, JSON.stringify({ x, y }));
97
+ } catch {
98
+ /* not important */
99
+ }
100
+ }, 400);
101
+ });
102
+ win.on("closed", () => (win = null));
103
+ }
104
+
105
+ app.whenReady().then(() => {
106
+ protocol.handle("tb", (req) => {
107
+ if (!WEB) return new Response("Widget files are missing.", { status: 500 });
108
+ const { pathname } = new URL(req.url);
109
+ const file = path.normalize(path.join(WEB, decodeURIComponent(pathname)));
110
+ if (!file.startsWith(path.normalize(WEB + path.sep))) return new Response("Forbidden", { status: 403 });
111
+ return net.fetch(pathToFileURL(file).toString());
112
+ });
113
+
114
+ createWindow();
115
+
116
+ // Tell the page whenever the tb session appears, changes or ends.
117
+ let last = "unset";
118
+ const push = () => {
119
+ const s = readSession();
120
+ const key = JSON.stringify(s);
121
+ if (key !== last && win) {
122
+ last = key;
123
+ win.webContents.send("session", s);
124
+ }
125
+ };
126
+ ipcMain.on("ready", () => {
127
+ last = "unset";
128
+ push();
129
+ });
130
+ setInterval(push, 1500);
131
+ ipcMain.on("close", () => app.quit());
132
+ });
133
+
134
+ app.on("second-instance", () => {
135
+ if (win) win.showInactive();
136
+ });
137
+ app.on("window-all-closed", () => app.quit());
@@ -0,0 +1,10 @@
1
+ // The only bridge between the widget page and Electron: session updates in, "close" out.
2
+ const { contextBridge, ipcRenderer } = require("electron");
3
+
4
+ contextBridge.exposeInMainWorld("tbWidget", {
5
+ onSession: (cb) => {
6
+ ipcRenderer.on("session", (_event, session) => cb(session));
7
+ ipcRenderer.send("ready");
8
+ },
9
+ close: () => ipcRenderer.send("close"),
10
+ });