glance-bar 0.0.0-stage → 0.1.1
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 +18 -2
- package/bin/glance.js +91 -0
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# glance-bar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run **Glance**, a tiny menu-bar app that shows your Claude Code usage and limits (unofficial), with one command:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx glance-bar
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The first run downloads the prebuilt app for your Mac (about 1.5 MB) from the matching
|
|
10
|
+
[GitHub release](https://github.com/ashishlal2003/glance/releases), checks it against the release's SHA-256
|
|
11
|
+
checksum, and starts it. It keeps running in your menu bar after the terminal closes.
|
|
12
|
+
Right-click the icon and tick **Launch at login** to have it start automatically.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx glance-bar quit # quit it
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
macOS only for now. Windows installers are on the release page.
|
|
19
|
+
Source, privacy details and limitations: https://github.com/ashishlal2003/glance
|
package/bin/glance.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher for Glance. Downloads the prebuilt app for your Mac from the matching GitHub
|
|
3
|
+
// release (verified against the release's SHA-256 digest), then opens it detached, so the
|
|
4
|
+
// terminal can close and Glance keeps running in the menu bar.
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const https = require("https");
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const crypto = require("crypto");
|
|
12
|
+
const { spawn, spawnSync } = require("child_process");
|
|
13
|
+
|
|
14
|
+
const pkg = require("../package.json");
|
|
15
|
+
const REPO = "ashishlal2003/glance";
|
|
16
|
+
const TAG = `v${pkg.version}`;
|
|
17
|
+
const HOME_DIR = path.join(os.homedir(), ".glance", TAG);
|
|
18
|
+
const APP = path.join(HOME_DIR, "Glance.app");
|
|
19
|
+
|
|
20
|
+
const log = (m) => console.log(`glance: ${m}`);
|
|
21
|
+
const die = (m) => { console.error(`glance: ${m}`); process.exit(1); };
|
|
22
|
+
|
|
23
|
+
function get(url, { json = false, toFile = null } = {}, hops = 0) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
if (hops > 5) return reject(new Error("too many redirects"));
|
|
26
|
+
https.get(url, { headers: { "User-Agent": "glance-bar-launcher", Accept: json ? "application/vnd.github+json" : "*/*" } }, (res) => {
|
|
27
|
+
if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location) {
|
|
28
|
+
res.resume();
|
|
29
|
+
return resolve(get(new URL(res.headers.location, url).toString(), { json, toFile }, hops + 1));
|
|
30
|
+
}
|
|
31
|
+
if (res.statusCode !== 200) { res.resume(); return reject(new Error(`HTTP ${res.statusCode} for ${url}`)); }
|
|
32
|
+
if (toFile) {
|
|
33
|
+
const hash = crypto.createHash("sha256");
|
|
34
|
+
const out = fs.createWriteStream(toFile);
|
|
35
|
+
res.on("data", (c) => hash.update(c));
|
|
36
|
+
res.pipe(out);
|
|
37
|
+
out.on("finish", () => resolve(hash.digest("hex")));
|
|
38
|
+
out.on("error", reject);
|
|
39
|
+
} else {
|
|
40
|
+
let body = "";
|
|
41
|
+
res.on("data", (c) => (body += c));
|
|
42
|
+
res.on("end", () => { try { resolve(json ? JSON.parse(body) : body); } catch (e) { reject(e); } });
|
|
43
|
+
}
|
|
44
|
+
}).on("error", reject);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function install() {
|
|
49
|
+
const arch = process.arch === "arm64" ? "aarch64" : "x64";
|
|
50
|
+
const name = `Glance_${arch}.app.tar.gz`;
|
|
51
|
+
log(`downloading Glance ${TAG} (${arch})...`);
|
|
52
|
+
const rel = await get(`https://api.github.com/repos/${REPO}/releases/tags/${TAG}`, { json: true });
|
|
53
|
+
const asset = (rel.assets || []).find((a) => a.name === name);
|
|
54
|
+
if (!asset) die(`release ${TAG} has no ${name}`);
|
|
55
|
+
const tmp = path.join(os.tmpdir(), `glance-${process.pid}-${name}`);
|
|
56
|
+
const sum = await get(asset.browser_download_url, { toFile: tmp });
|
|
57
|
+
const expected = (asset.digest || "").replace(/^sha256:/, "");
|
|
58
|
+
if (!expected) { fs.rmSync(tmp, { force: true }); die("release asset has no checksum to verify; refusing to install"); }
|
|
59
|
+
if (sum !== expected) { fs.rmSync(tmp, { force: true }); die("checksum mismatch; refusing to install"); }
|
|
60
|
+
fs.rmSync(HOME_DIR, { recursive: true, force: true });
|
|
61
|
+
fs.mkdirSync(HOME_DIR, { recursive: true });
|
|
62
|
+
const r = spawnSync("tar", ["-xzf", tmp, "-C", HOME_DIR]);
|
|
63
|
+
fs.rmSync(tmp, { force: true });
|
|
64
|
+
if (r.status !== 0 || !fs.existsSync(APP)) die("could not unpack the app");
|
|
65
|
+
log(`installed to ${APP}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function running() {
|
|
69
|
+
return spawnSync("pgrep", ["-f", path.join(HOME_DIR, "Glance.app")]).status === 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function main() {
|
|
73
|
+
const cmd = process.argv[2];
|
|
74
|
+
if (cmd === "--version" || cmd === "-v") return console.log(pkg.version);
|
|
75
|
+
if (cmd === "help" || cmd === "--help" || cmd === "-h") {
|
|
76
|
+
return console.log("glance-bar start Glance (downloads it the first time)\nglance-bar quit quit Glance\nglance-bar --version print the version\n\nTip: right-click the menu-bar icon and tick \"Launch at login\".");
|
|
77
|
+
}
|
|
78
|
+
if (process.platform !== "darwin") {
|
|
79
|
+
die(`this launcher supports macOS only for now. Windows installers are on the release page:\nhttps://github.com/${REPO}/releases/tag/${TAG}`);
|
|
80
|
+
}
|
|
81
|
+
if (cmd === "quit") {
|
|
82
|
+
spawnSync("pkill", ["-f", path.join(HOME_DIR, "Glance.app")]);
|
|
83
|
+
return log("quit.");
|
|
84
|
+
}
|
|
85
|
+
if (!fs.existsSync(APP)) await install();
|
|
86
|
+
if (running()) return log("already running (look for the gauge in your menu bar).");
|
|
87
|
+
spawn("open", [APP], { detached: true, stdio: "ignore" }).unref();
|
|
88
|
+
log("started. Look for the gauge in your menu bar. Right-click it for options (Launch at login, Restart, Quit).");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
main().catch((e) => die(e.message));
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glance-bar",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Tiny menu-bar app that shows your Claude Code usage and limits. Unofficial.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"glance-bar": "bin/glance.js",
|
|
7
|
+
"glance": "bin/glance.js"
|
|
8
|
+
},
|
|
9
|
+
"files": ["bin", "README.md"],
|
|
10
|
+
"engines": { "node": ">=18" },
|
|
11
|
+
"os": ["darwin", "win32", "linux"],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/ashishlal2003/glance.git",
|
|
16
|
+
"directory": "npm"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/ashishlal2003/glance",
|
|
19
|
+
"keywords": ["claude", "claude-code", "menu-bar", "usage", "tauri", "macos"]
|
|
20
|
+
}
|