sideby 0.17.0 → 0.19.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/README.md +11 -1
- package/ai-tasks.json +90 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +9 -1
- package/dist/src/cli/commands.js +507 -26
- package/dist/src/cli/json-schemas.js +196 -19
- package/dist/src/cli/main.js +79 -13
- package/dist/src/core/after-install.d.ts +54 -0
- package/dist/src/core/after-install.js +78 -0
- package/dist/src/core/ask.d.ts +87 -1
- package/dist/src/core/ask.js +122 -7
- package/dist/src/core/autostart.d.ts +38 -8
- package/dist/src/core/autostart.js +85 -39
- package/dist/src/core/brand-mark.d.ts +49 -11
- package/dist/src/core/brand-mark.js +116 -38
- package/dist/src/core/browser-profiles.js +7 -32
- package/dist/src/core/config.d.ts +19 -0
- package/dist/src/core/config.js +75 -2
- package/dist/src/core/desktop-app.d.ts +1 -1
- package/dist/src/core/desktop-app.js +2 -2
- package/dist/src/core/edit-settings.d.ts +24 -0
- package/dist/src/core/edit-settings.js +97 -0
- package/dist/src/core/handoff-brief.d.ts +4 -2
- package/dist/src/core/handoff-brief.js +6 -1
- package/dist/src/core/handoff-chain.d.ts +24 -0
- package/dist/src/core/handoff-chain.js +2 -0
- package/dist/src/core/handoff-run.d.ts +4 -3
- package/dist/src/core/handoff-run.js +14 -9
- package/dist/src/core/launch.d.ts +2 -0
- package/dist/src/core/launch.js +14 -10
- package/dist/src/core/local-build.d.ts +12 -5
- package/dist/src/core/local-build.js +49 -31
- package/dist/src/core/lock.d.ts +30 -0
- package/dist/src/core/lock.js +143 -0
- package/dist/src/core/pick-commands.d.ts +42 -0
- package/dist/src/core/pick-commands.js +44 -0
- package/dist/src/core/quota-levels.d.ts +6 -1
- package/dist/src/core/quota-levels.js +16 -5
- package/dist/src/core/shell-init.js +3 -1
- package/dist/src/core/shell-setup.d.ts +40 -0
- package/dist/src/core/shell-setup.js +54 -0
- package/dist/src/core/skill-check.d.ts +2 -0
- package/dist/src/core/skill-check.js +2 -0
- package/dist/src/core/task-spec.d.ts +95 -0
- package/dist/src/core/task-spec.js +209 -0
- package/dist/src/core/terminal.d.ts +21 -4
- package/dist/src/core/terminal.js +155 -10
- package/dist/src/core/update.d.ts +27 -16
- package/dist/src/core/update.js +69 -95
- package/dist/src/core/windows-dirs.d.ts +19 -0
- package/dist/src/core/windows-dirs.js +39 -0
- package/dist/src/desktop/icon.js +12 -15
- package/dist/src/families/claude/ai-task.d.ts +8 -0
- package/dist/src/families/claude/ai-task.js +38 -0
- package/dist/src/families/claude/handoff-hook.js +4 -4
- package/dist/src/families/claude/index.js +3 -0
- package/dist/src/families/codex/handoff-hook.js +4 -4
- package/dist/src/families/codex/index.js +9 -0
- package/dist/src/families/grok/handoff-hook.js +4 -4
- package/dist/src/families/grok/index.js +1 -0
- package/dist/src/families/pi/index.js +1 -0
- package/dist/src/handoff/hook.js +51 -30
- package/dist/src/handoff/levels.d.ts +24 -0
- package/dist/src/handoff/levels.js +70 -0
- package/dist/src/handoff/messages.d.ts +6 -3
- package/dist/src/handoff/messages.js +20 -7
- package/dist/src/handoff/reader.d.ts +6 -3
- package/dist/src/menubar/agent.d.ts +3 -0
- package/dist/src/menubar/agent.js +21 -0
- package/dist/src/menubar/script.d.ts +8 -0
- package/dist/src/menubar/script.js +457 -0
- package/dist/src/menubar/snapshot.d.ts +115 -0
- package/dist/src/menubar/snapshot.js +255 -0
- package/dist/src/menubar/strings.d.ts +87 -0
- package/dist/src/menubar/strings.js +88 -0
- package/dist/src/panel/background.js +12 -19
- package/dist/src/panel/handler.d.ts +30 -0
- package/dist/src/panel/handler.js +148 -80
- package/dist/src/panel/i18n.d.ts +72 -0
- package/dist/src/panel/i18n.js +144 -0
- package/dist/src/panel/page-logic.d.ts +105 -0
- package/dist/src/panel/page-logic.js +170 -15
- package/dist/src/panel/page-script.js +419 -111
- package/dist/src/panel/page-styles.js +45 -13
- package/dist/src/panel/page.d.ts +7 -0
- package/dist/src/panel/page.js +11 -1
- package/dist/src/runtime.d.ts +44 -2
- package/dist/src/runtime.js +107 -6
- package/dist/src/types.d.ts +14 -0
- package/package.json +4 -3
- package/schemas/alias-list.json +119 -0
- package/schemas/alias.json +27 -1
- package/schemas/ask-choices.json +168 -0
- package/schemas/ask-print.json +87 -0
- package/schemas/config.json +28 -1
- package/schemas/edit.json +119 -0
- package/schemas/error.json +4 -0
- package/schemas/families.json +4 -0
- package/schemas/list.json +4 -0
- package/schemas/local.json +1 -1
- package/schemas/menubar-snapshot.json +646 -0
- package/schemas/menubar-start.json +112 -0
- package/schemas/menubar.json +165 -0
- package/schemas/new.json +19 -0
- package/schemas/shell-init-setup.json +124 -0
- package/skills/sideby/SKILL.md +11 -4
- package/skills/sideby/references/accounts.md +10 -0
- package/skills/sideby/references/ai-tasks.md +10 -0
- package/skills/sideby/references/handoff.md +3 -1
- package/skills/sideby/references/panel.md +6 -0
- package/skills/sideby/references/setup.md +1 -1
- package/skills/sideby/references/update.md +1 -1
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
// The Menu Bar Item's process (spec §3.31, ADR-0034): JXA run by the system's `osascript`, with no compiled code. It
|
|
2
|
+
// draws what `sideby menubar snapshot --json` says and turns clicks into sideby commands; it reads no other file and
|
|
3
|
+
// decides nothing itself. Arguments: the Node binary and the sideby entry the LaunchAgent recorded.
|
|
4
|
+
import { FAVICON_SVG, MENUBAR_ICON_SVG } from '../core/brand-mark.js';
|
|
5
|
+
import { MENUBAR_STRINGS } from './strings.js';
|
|
6
|
+
/** Seconds between two snapshots, and between two looks at a running one. */
|
|
7
|
+
export const SNAPSHOT_SECONDS = 120;
|
|
8
|
+
export const TICK_SECONDS = 5;
|
|
9
|
+
/** A snapshot older than this greys the title. */
|
|
10
|
+
export const STALE_SECONDS = 15 * 60;
|
|
11
|
+
/** A snapshot still running after this is ended, so a stuck one cannot stop the refreshes. */
|
|
12
|
+
export const SNAPSHOT_TIMEOUT_SECONDS = 60;
|
|
13
|
+
export const MENUBAR_SCRIPT = String.raw `
|
|
14
|
+
ObjC.import('Cocoa');
|
|
15
|
+
ObjC.import('Carbon');
|
|
16
|
+
function run(argv) {
|
|
17
|
+
var node = argv[0], entry = argv[1];
|
|
18
|
+
var SNAPSHOT = ${SNAPSHOT_SECONDS}, TICK = ${TICK_SECONDS}, STALE = ${STALE_SECONDS}, TIMEOUT = ${SNAPSHOT_TIMEOUT_SECONDS};
|
|
19
|
+
var lang = 'en';
|
|
20
|
+
try { lang = ObjC.unwrap($.NSLocale.preferredLanguages.firstObject) || 'en'; } catch (e) {}
|
|
21
|
+
var app = $.NSApplication.sharedApplication;
|
|
22
|
+
app.setActivationPolicy($.NSApplicationActivationPolicyAccessory);
|
|
23
|
+
var item = $.NSStatusBar.systemStatusBar.statusItemWithLength($.NSVariableStatusItemLength);
|
|
24
|
+
// Keeps the place a user drags it to with Command held, such as out from under the notch.
|
|
25
|
+
item.autosaveName = 'dev.sideby.menubar';
|
|
26
|
+
// Sai, the sideby buddy, in colour (core/brand-mark.ts); a system gauge, drawn as a template, where this macOS cannot read SVG.
|
|
27
|
+
var icon = $.NSImage.alloc.initWithData($(${JSON.stringify(MENUBAR_ICON_SVG)}).dataUsingEncoding($.NSUTF8StringEncoding));
|
|
28
|
+
if (!icon || icon.isNil() || !icon.isValid) {
|
|
29
|
+
icon = $.NSImage.imageWithSystemSymbolNameAccessibilityDescription('gauge.with.needle', 'sideby');
|
|
30
|
+
if (icon && !icon.isNil()) icon.template = true;
|
|
31
|
+
}
|
|
32
|
+
if (icon && !icon.isNil()) {
|
|
33
|
+
icon.accessibilityDescription = 'sideby';
|
|
34
|
+
item.button.image = icon;
|
|
35
|
+
item.button.imagePosition = $.NSImageLeft;
|
|
36
|
+
} else item.button.title = 'sideby';
|
|
37
|
+
|
|
38
|
+
var out = ObjC.unwrap($.NSTemporaryDirectory()) + 'sideby-menubar-' + $.NSProcessInfo.processInfo.processIdentifier + '.json';
|
|
39
|
+
var snap = null, task = null, handle = null, lastStart = 0, lastOk = 0, failed = false;
|
|
40
|
+
var refs = [], actions = [], footer = null, appearance = '';
|
|
41
|
+
// The first words, before any snapshot has said which language to use.
|
|
42
|
+
var zh = /^zh/i.test(lang);
|
|
43
|
+
var CARD_ICON = ${JSON.stringify(FAVICON_SVG)};
|
|
44
|
+
var LOADING = zh ? ${JSON.stringify(MENUBAR_STRINGS.zh.loading)} : ${JSON.stringify(MENUBAR_STRINGS.en.loading)};
|
|
45
|
+
var OPEN_PANEL = zh ? ${JSON.stringify(MENUBAR_STRINGS.zh.openPanel)} : ${JSON.stringify(MENUBAR_STRINGS.en.openPanel)};
|
|
46
|
+
var now = function () { return Date.now() / 1000; };
|
|
47
|
+
|
|
48
|
+
function sideby(args) {
|
|
49
|
+
var t = $.NSTask.alloc.init;
|
|
50
|
+
t.executableURL = $.NSURL.fileURLWithPath(node);
|
|
51
|
+
t.arguments = $([entry].concat(args));
|
|
52
|
+
t.standardOutput = $.NSFileHandle.fileHandleWithNullDevice;
|
|
53
|
+
t.standardError = $.NSFileHandle.fileHandleWithNullDevice;
|
|
54
|
+
return t;
|
|
55
|
+
}
|
|
56
|
+
function act(args) {
|
|
57
|
+
var t = sideby(args);
|
|
58
|
+
if (t.launchAndReturnError(null)) actions.push(t);
|
|
59
|
+
}
|
|
60
|
+
function startSnapshot() {
|
|
61
|
+
if (task) return;
|
|
62
|
+
$.NSFileManager.defaultManager.createFileAtPathContentsAttributes(out, $(), $());
|
|
63
|
+
var t = sideby(['menubar', 'snapshot', '--json', '--lang', lang]);
|
|
64
|
+
handle = $.NSFileHandle.fileHandleForWritingAtPath(out);
|
|
65
|
+
t.standardOutput = handle;
|
|
66
|
+
lastStart = now();
|
|
67
|
+
if (t.launchAndReturnError(null)) task = t;
|
|
68
|
+
else { failed = true; closeHandle(); }
|
|
69
|
+
}
|
|
70
|
+
function closeHandle() {
|
|
71
|
+
if (handle) { handle.closeFile; handle = null; }
|
|
72
|
+
}
|
|
73
|
+
function finishSnapshot() {
|
|
74
|
+
var ok = task.terminationStatus === 0;
|
|
75
|
+
task = null;
|
|
76
|
+
closeHandle();
|
|
77
|
+
if (ok) {
|
|
78
|
+
try {
|
|
79
|
+
var text = ObjC.unwrap($.NSString.stringWithContentsOfFileEncodingError(out, $.NSUTF8StringEncoding, null));
|
|
80
|
+
var next = JSON.parse(text);
|
|
81
|
+
if (next && next.schemaVersion === 1) { snap = next; lastOk = now(); failed = false; hotkey(snap.hotkey); build(); return; }
|
|
82
|
+
} catch (e) {}
|
|
83
|
+
}
|
|
84
|
+
failed = true;
|
|
85
|
+
build();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The shortcut that toggles the menu from anywhere (config menubar.hotkey), registered with Carbon's
|
|
89
|
+
// RegisterEventHotKey: it needs no permission, unlike watching every key press. macOS hands a press to this app as a
|
|
90
|
+
// system-defined event of subtype 6 whose data1 is the key's reference. While the menu is open the key is
|
|
91
|
+
// unregistered, so the press reaches the menu, where a hidden item with the same key closes it.
|
|
92
|
+
var hotkeyWant = null, hotkeyRef = 0, hotkeyBound = false, menuOpen = false, closedAt = 0;
|
|
93
|
+
function bindHotkeyFunctions() {
|
|
94
|
+
if (hotkeyBound) return;
|
|
95
|
+
ObjC.bindFunction('GetApplicationEventTarget', ['void *', []]);
|
|
96
|
+
ObjC.bindFunction('RegisterEventHotKey', ['int', ['unsigned int', 'unsigned int', 'unsigned long long', 'void *', 'unsigned int', 'void *']]);
|
|
97
|
+
ObjC.bindFunction('UnregisterEventHotKey', ['int', ['unsigned long long']]);
|
|
98
|
+
$.NSEvent.addLocalMonitorForEventsMatchingMaskHandler($.NSEventMaskSystemDefined, function (e) {
|
|
99
|
+
// A press queued while the menu was open arrives just after it closes; it meant "close", not "open again".
|
|
100
|
+
if (e.subtype === 6 && hotkeyRef && Number(e.data1) === hotkeyRef && !menuOpen && now() - closedAt > 0.5) openMenu();
|
|
101
|
+
return e;
|
|
102
|
+
});
|
|
103
|
+
hotkeyBound = true;
|
|
104
|
+
}
|
|
105
|
+
// Drops the menu from the icon when it shows; at the pointer when the icon is hidden, such as by a full menu bar or
|
|
106
|
+
// under the notch, where clicking it would do nothing.
|
|
107
|
+
function openMenu() {
|
|
108
|
+
var w = item.button.window;
|
|
109
|
+
if (w && !w.isNil() && (w.occlusionState & $.NSWindowOcclusionStateVisible)) { item.button.performClick(null); return; }
|
|
110
|
+
app.activateIgnoringOtherApps(true);
|
|
111
|
+
item.menu.popUpMenuPositioningItemAtLocationInView(null, $.NSEvent.mouseLocation, null);
|
|
112
|
+
app.deactivate;
|
|
113
|
+
}
|
|
114
|
+
function registerHotkey() {
|
|
115
|
+
if (hotkeyRef || !hotkeyWant) return;
|
|
116
|
+
var buf = $.NSMutableData.dataWithLength(8);
|
|
117
|
+
// EventHotKeyID { OSType signature 'sdby'; UInt32 id 1 } is passed in one register, the id in the high half.
|
|
118
|
+
if ($.RegisterEventHotKey(hotkeyWant.keyCode, hotkeyWant.modifiers, 4294967296 + 0x73646279, $.GetApplicationEventTarget(), 0, buf.mutableBytes) !== 0) return;
|
|
119
|
+
// The EventHotKeyRef the call wrote, read back from the buffer as a little-endian number.
|
|
120
|
+
var hex = (ObjC.unwrap(buf.description).match(/0x([0-9a-f]{16})/i) || ['', ''])[1];
|
|
121
|
+
var ref = 0;
|
|
122
|
+
for (var i = 7; i >= 0; i--) ref = ref * 256 + parseInt(hex.substr(i * 2, 2), 16);
|
|
123
|
+
hotkeyRef = ref || 0;
|
|
124
|
+
}
|
|
125
|
+
function unregisterHotkey() {
|
|
126
|
+
if (hotkeyRef) $.UnregisterEventHotKey(hotkeyRef);
|
|
127
|
+
hotkeyRef = 0;
|
|
128
|
+
}
|
|
129
|
+
function hotkey(h) {
|
|
130
|
+
var key = function (x) { return x ? x.keyCode + ':' + x.modifiers : ''; };
|
|
131
|
+
if (key(h) === key(hotkeyWant) && (hotkeyRef || !h || menuOpen)) return;
|
|
132
|
+
try {
|
|
133
|
+
bindHotkeyFunctions();
|
|
134
|
+
unregisterHotkey();
|
|
135
|
+
hotkeyWant = h || null;
|
|
136
|
+
if (!menuOpen) registerHotkey();
|
|
137
|
+
} catch (e) {}
|
|
138
|
+
}
|
|
139
|
+
// The hidden item that closes the open menu with the same key; Carbon modifier flags to Cocoa ones.
|
|
140
|
+
function closeItem(menu) {
|
|
141
|
+
if (!hotkeyWant) return;
|
|
142
|
+
var flags = { 4096: 1 << 18, 2048: 1 << 19, 512: 1 << 17, 256: 1 << 20 }, mask = 0;
|
|
143
|
+
Object.keys(flags).forEach(function (f) { if (hotkeyWant.modifiers & Number(f)) mask += flags[f]; });
|
|
144
|
+
var mi = $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent('sideby', 'closeMenu:', hotkeyWant.label.slice(-1).toLowerCase());
|
|
145
|
+
mi.keyEquivalentModifierMask = mask;
|
|
146
|
+
mi.target = target;
|
|
147
|
+
mi.hidden = true;
|
|
148
|
+
mi.allowsKeyEquivalentWhenHidden = true;
|
|
149
|
+
menu.addItem(mi);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function color(level) {
|
|
153
|
+
if (level === 'fail') return $.NSColor.systemRedColor;
|
|
154
|
+
if (level === 'warn') return $.NSColor.systemOrangeColor;
|
|
155
|
+
if (level === 'stale') return $.NSColor.secondaryLabelColor;
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
function attrs(c, font, para) {
|
|
159
|
+
var d = $.NSMutableDictionary.dictionary;
|
|
160
|
+
if (c) d.setObjectForKey(c, $.NSForegroundColorAttributeName);
|
|
161
|
+
if (font) d.setObjectForKey(font, $.NSFontAttributeName);
|
|
162
|
+
if (para) d.setObjectForKey(para, $.NSParagraphStyleAttributeName);
|
|
163
|
+
return d;
|
|
164
|
+
}
|
|
165
|
+
function str(text, d) {
|
|
166
|
+
// The bridge lacks initWithString:attributes: (no BridgeSupport entry), so it is sent by name.
|
|
167
|
+
return $.NSAttributedString.alloc.performSelectorWithObjectWithObject('initWithString:attributes:', $(text), d);
|
|
168
|
+
}
|
|
169
|
+
function styled(text, c) { return str(text, attrs(c, null, null)); }
|
|
170
|
+
function width(text, font) { return str(text, attrs(null, font, null)).size.width; }
|
|
171
|
+
// Old numbers, or the last refresh failed: they may no longer be true, so they are drawn grey.
|
|
172
|
+
function stale() { return !snap || failed || now() - lastOk > STALE; }
|
|
173
|
+
function drawTitle() {
|
|
174
|
+
var text = snap && snap.title ? ' ' + snap.title : '';
|
|
175
|
+
item.button.attributedTitle = styled(text, stale() ? color('stale') : color(snap && snap.level));
|
|
176
|
+
if (snap) item.button.toolTip = snap.tooltip;
|
|
177
|
+
}
|
|
178
|
+
function footerText() {
|
|
179
|
+
if (!snap) return LOADING;
|
|
180
|
+
var l = snap.labels;
|
|
181
|
+
if (task && !lastOk) return l.refreshing;
|
|
182
|
+
if (failed) return l.refreshFailed;
|
|
183
|
+
var minutes = Math.floor((now() - lastOk) / 60);
|
|
184
|
+
return minutes < 1 ? l.updatedJustNow : l.updatedMinutes.replace('{n}', String(minutes));
|
|
185
|
+
}
|
|
186
|
+
function add(menu, title, action, tag, key) {
|
|
187
|
+
var mi = $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent(title, action || null, key || '');
|
|
188
|
+
if (action) { mi.target = target; mi.tag = tag || 0; } else mi.enabled = false;
|
|
189
|
+
menu.addItem(mi);
|
|
190
|
+
return mi;
|
|
191
|
+
}
|
|
192
|
+
function header(menu, title) {
|
|
193
|
+
if ($.NSMenuItem.respondsToSelector('sectionHeaderWithTitle:')) menu.addItem($.NSMenuItem.sectionHeaderWithTitle(title));
|
|
194
|
+
else add(menu, title, null);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function dark() {
|
|
198
|
+
var best = app.effectiveAppearance.bestMatchFromAppearancesWithNames($([$.NSAppearanceNameAqua, $.NSAppearanceNameDarkAqua]));
|
|
199
|
+
return ObjC.unwrap(best) === ObjC.unwrap($.NSAppearanceNameDarkAqua);
|
|
200
|
+
}
|
|
201
|
+
function hex(h) {
|
|
202
|
+
var n = parseInt(h.slice(1), 16);
|
|
203
|
+
return $.NSColor.colorWithSRGBRedGreenBlueAlpha((n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255, 1);
|
|
204
|
+
}
|
|
205
|
+
// The Panel's quota colours (page-styles.ts): bars by level on a soft track, so both look alike.
|
|
206
|
+
var BAR = { ok: '#22c55e', warn: '#f59e0b', fail: '#ef4444' };
|
|
207
|
+
function svgImage(svg, size, template) {
|
|
208
|
+
var img = $.NSImage.alloc.initWithData($(svg).dataUsingEncoding($.NSUTF8StringEncoding));
|
|
209
|
+
if (!img || img.isNil() || !img.isValid) return null;
|
|
210
|
+
img.size = $.NSMakeSize(size, size);
|
|
211
|
+
img.template = template;
|
|
212
|
+
return img;
|
|
213
|
+
}
|
|
214
|
+
function symbol(name) {
|
|
215
|
+
var img = $.NSImage.imageWithSystemSymbolNameAccessibilityDescription(name, name);
|
|
216
|
+
return img && !img.isNil() ? img : null;
|
|
217
|
+
}
|
|
218
|
+
function logoImage(logo) {
|
|
219
|
+
if (!logo) return null;
|
|
220
|
+
// In its brand colour like the Panel, else in the text colour of this appearance. Painted here, not as a template:
|
|
221
|
+
// headers cannot be clicked, and macOS greys a template image on an item that cannot be clicked.
|
|
222
|
+
var rule = logo.fillRule ? ' fill-rule="' + logo.fillRule + '"' : '';
|
|
223
|
+
var fill = /^#[0-9a-f]{3,8}$/i.test(logo.color || '') ? logo.color : dark() ? '#f5f5f7' : '#1d1d1f';
|
|
224
|
+
return svgImage('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path' + rule + ' fill="' + fill + '" d="' + logo.path + '"/></svg>', 14, false);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
var GUTTER = $.NSImage.alloc.initWithSize($.NSMakeSize(14, 14));
|
|
228
|
+
|
|
229
|
+
// A quota window as a small rounded bar: a soft track, filled as far as it is used, coloured by level.
|
|
230
|
+
var BAR_W = 44, BAR_H = 5;
|
|
231
|
+
function bar(b) {
|
|
232
|
+
var img = $.NSImage.alloc.initWithSize($.NSMakeSize(BAR_W, BAR_H));
|
|
233
|
+
img.lockFocus;
|
|
234
|
+
hex(dark() ? '#1f2c3a' : '#e4edf4').set;
|
|
235
|
+
$.NSBezierPath.bezierPathWithRoundedRectXRadiusYRadius($.NSMakeRect(0, 0, BAR_W, BAR_H), BAR_H / 2, BAR_H / 2).fill;
|
|
236
|
+
if (b.percent > 0) {
|
|
237
|
+
(stale() ? $.NSColor.tertiaryLabelColor : hex(BAR[b.level] || BAR.ok)).set;
|
|
238
|
+
var w = Math.max(BAR_H, BAR_W * Math.min(100, b.percent) / 100);
|
|
239
|
+
$.NSBezierPath.bezierPathWithRoundedRectXRadiusYRadius($.NSMakeRect(0, 0, w, BAR_H), BAR_H / 2, BAR_H / 2).fill;
|
|
240
|
+
}
|
|
241
|
+
img.unlockFocus;
|
|
242
|
+
var att = $.NSTextAttachment.alloc.init;
|
|
243
|
+
att.image = img;
|
|
244
|
+
att.bounds = $.NSMakeRect(0, 1.5, BAR_W, BAR_H);
|
|
245
|
+
return $.NSAttributedString.attributedStringWithAttachment(att);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Columns: the name, then per window its bar and percent, then the reset time. One set of tab stops lines them up
|
|
249
|
+
// across every tool; the window names sit once in each tool's header, over their column. A tool with one window
|
|
250
|
+
// draws it in the second column, under the others' long window.
|
|
251
|
+
function layout(sections) {
|
|
252
|
+
var size = $.NSFont.menuFontOfSize(0).pointSize;
|
|
253
|
+
var L = {
|
|
254
|
+
font: $.NSFont.menuFontOfSize(size),
|
|
255
|
+
mono: $.NSFont.monospacedDigitSystemFontOfSizeWeight(size, 0),
|
|
256
|
+
head: $.NSFont.systemFontOfSizeWeight(size - 2, $.NSFontWeightSemibold),
|
|
257
|
+
small: $.NSFont.systemFontOfSize(size - 2),
|
|
258
|
+
};
|
|
259
|
+
var nameW = 0, first = false;
|
|
260
|
+
sections.forEach(function (s) {
|
|
261
|
+
nameW = Math.max(nameW, width(s.title, L.head));
|
|
262
|
+
if (s.columns[0]) first = true;
|
|
263
|
+
s.rows.concat(s.more ? s.more.rows : []).forEach(function (r) { nameW = Math.max(nameW, width(r.label, L.font)); });
|
|
264
|
+
});
|
|
265
|
+
var pctW = width('100%', L.mono), x = Math.ceil(nameW) + 20, stops = [], at = [];
|
|
266
|
+
function tab(pos) { stops.push($.NSTextTab.alloc.initWithTextAlignmentLocationOptions($.NSTextAlignmentLeft, pos, $())); }
|
|
267
|
+
for (var c = 0; c < (first ? 2 : 1); c++) {
|
|
268
|
+
at.push(x);
|
|
269
|
+
tab(x); x += BAR_W + 7;
|
|
270
|
+
tab(x); x += pctW + 20;
|
|
271
|
+
}
|
|
272
|
+
tab(x);
|
|
273
|
+
L.reset = x;
|
|
274
|
+
L.first = first;
|
|
275
|
+
L.para = $.NSMutableParagraphStyle.alloc.init;
|
|
276
|
+
L.para.tabStops = $(stops);
|
|
277
|
+
// The header has a tab stop at each bar and at the reset column, for its window names.
|
|
278
|
+
L.headPara = $.NSMutableParagraphStyle.alloc.init;
|
|
279
|
+
L.headPara.tabStops = $(at.concat([x]).map(function (pos) {
|
|
280
|
+
return $.NSTextTab.alloc.initWithTextAlignmentLocationOptions($.NSTextAlignmentLeft, pos, $());
|
|
281
|
+
}));
|
|
282
|
+
L.width = x + width('24d 23h', L.font) + 70;
|
|
283
|
+
return L;
|
|
284
|
+
}
|
|
285
|
+
function rowTitle(r, L) {
|
|
286
|
+
var line = $.NSMutableAttributedString.alloc.init;
|
|
287
|
+
var plain = attrs(null, L.font, L.para), dim = attrs($.NSColor.secondaryLabelColor, L.font, L.para);
|
|
288
|
+
line.appendAttributedString(str(r.label, plain));
|
|
289
|
+
if (!r.bars) {
|
|
290
|
+
line.appendAttributedString(str('\t' + r.note, dim));
|
|
291
|
+
return line;
|
|
292
|
+
}
|
|
293
|
+
r.bars.forEach(function (b, i) {
|
|
294
|
+
if (!i && !L.first) return;
|
|
295
|
+
if (!b) { line.appendAttributedString(str('\t\t', plain)); return; }
|
|
296
|
+
line.appendAttributedString(str('\t', plain));
|
|
297
|
+
line.appendAttributedString(bar(b));
|
|
298
|
+
var c = stale() ? color('stale') : b.level === 'ok' ? null : color(b.level);
|
|
299
|
+
line.appendAttributedString(str('\t' + b.percent + '%', attrs(c, L.mono, L.para)));
|
|
300
|
+
});
|
|
301
|
+
if (r.reset) line.appendAttributedString(str('\t' + r.reset, dim));
|
|
302
|
+
return line;
|
|
303
|
+
}
|
|
304
|
+
function accountItem(menu, r, L) {
|
|
305
|
+
refs.push(r.ref);
|
|
306
|
+
var mi = add(menu, r.label, 'start:', refs.length);
|
|
307
|
+
mi.attributedTitle = rowTitle(r, L);
|
|
308
|
+
// An empty image as wide as the tools' logos, so every row's text starts where the headers' text does and the
|
|
309
|
+
// window names sit over their bars.
|
|
310
|
+
mi.image = GUTTER;
|
|
311
|
+
mi.toolTip = r.tip;
|
|
312
|
+
if (r.recommended) {
|
|
313
|
+
if (mi.respondsToSelector('setBadge:')) mi.badge = $.NSMenuItemBadge.alloc.initWithString(snap.labels.recommended);
|
|
314
|
+
else {
|
|
315
|
+
var t = $.NSMutableAttributedString.alloc.initWithAttributedString(mi.attributedTitle);
|
|
316
|
+
t.appendAttributedString(styled(' ' + snap.labels.recommended, $.NSColor.controlAccentColor));
|
|
317
|
+
mi.attributedTitle = t;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return mi;
|
|
321
|
+
}
|
|
322
|
+
// A tool's header: its mark, its name, and the window names over the bar columns.
|
|
323
|
+
function sectionHeader(menu, s, L) {
|
|
324
|
+
var mi = add(menu, s.title, null);
|
|
325
|
+
var line = $.NSMutableAttributedString.alloc.init;
|
|
326
|
+
line.appendAttributedString(str(s.title, attrs($.NSColor.labelColor, L.head, L.headPara)));
|
|
327
|
+
var cols = L.first ? s.columns : [s.columns[1]];
|
|
328
|
+
cols.forEach(function (c) { line.appendAttributedString(str('\t' + (c || ''), attrs($.NSColor.tertiaryLabelColor, L.small, L.headPara))); });
|
|
329
|
+
if (s.rows.some(function (r) { return r.reset; }))
|
|
330
|
+
line.appendAttributedString(str('\t' + snap.labels.resetsHeader, attrs($.NSColor.tertiaryLabelColor, L.small, L.headPara)));
|
|
331
|
+
mi.attributedTitle = line;
|
|
332
|
+
mi.image = logoImage(s.logo) || GUTTER;
|
|
333
|
+
}
|
|
334
|
+
// The card at the top: Sai, a bold status, and a grey line naming the account the status is about.
|
|
335
|
+
function card(menu, c, L) {
|
|
336
|
+
var W = Math.max(280, L.width), H = 50;
|
|
337
|
+
var v = $.NSView.alloc.initWithFrame($.NSMakeRect(0, 0, W, H));
|
|
338
|
+
v.autoresizingMask = $.NSViewWidthSizable;
|
|
339
|
+
var icon = svgImage(CARD_ICON, 30, false);
|
|
340
|
+
if (icon) {
|
|
341
|
+
var iv = $.NSImageView.imageViewWithImage(icon);
|
|
342
|
+
iv.frame = $.NSMakeRect(14, 10, 30, 30);
|
|
343
|
+
v.addSubview(iv);
|
|
344
|
+
}
|
|
345
|
+
var status = $.NSTextField.labelWithString(c.status);
|
|
346
|
+
status.font = $.NSFont.systemFontOfSizeWeight(13, $.NSFontWeightSemibold);
|
|
347
|
+
status.textColor = (stale() ? color('stale') : color(c.level)) || $.NSColor.labelColor;
|
|
348
|
+
status.frame = $.NSMakeRect(54, 25, W - 64, 17);
|
|
349
|
+
var detail = $.NSTextField.labelWithString(c.detail);
|
|
350
|
+
detail.font = $.NSFont.systemFontOfSize(11);
|
|
351
|
+
detail.textColor = $.NSColor.secondaryLabelColor;
|
|
352
|
+
detail.frame = $.NSMakeRect(54, 9, W - 64, 15);
|
|
353
|
+
v.addSubview(status);
|
|
354
|
+
v.addSubview(detail);
|
|
355
|
+
var mi = $.NSMenuItem.alloc.init;
|
|
356
|
+
mi.view = v;
|
|
357
|
+
menu.addItem(mi);
|
|
358
|
+
}
|
|
359
|
+
function withImage(mi, name) {
|
|
360
|
+
var img = symbol(name);
|
|
361
|
+
if (img) mi.image = img;
|
|
362
|
+
return mi;
|
|
363
|
+
}
|
|
364
|
+
function build() {
|
|
365
|
+
drawTitle();
|
|
366
|
+
var menu = $.NSMenu.alloc.init;
|
|
367
|
+
menu.autoenablesItems = false;
|
|
368
|
+
refs = [];
|
|
369
|
+
if (snap) {
|
|
370
|
+
var L = layout(snap.sections);
|
|
371
|
+
if (snap.card) {
|
|
372
|
+
card(menu, snap.card, L);
|
|
373
|
+
menu.addItem($.NSMenuItem.separatorItem);
|
|
374
|
+
}
|
|
375
|
+
if (!snap.sections.length) {
|
|
376
|
+
add(menu, snap.labels.empty, null);
|
|
377
|
+
withImage(add(menu, snap.labels.addAccount, 'openPanel:'), 'plus');
|
|
378
|
+
}
|
|
379
|
+
snap.sections.forEach(function (s, i) {
|
|
380
|
+
if (i) menu.addItem($.NSMenuItem.separatorItem);
|
|
381
|
+
sectionHeader(menu, s, L);
|
|
382
|
+
s.rows.forEach(function (r) { accountItem(menu, r, L); });
|
|
383
|
+
if (s.more) {
|
|
384
|
+
var sub = $.NSMenu.alloc.init;
|
|
385
|
+
sub.autoenablesItems = false;
|
|
386
|
+
s.more.rows.forEach(function (r) { accountItem(sub, r, L); });
|
|
387
|
+
var mi = add(menu, s.more.title, null);
|
|
388
|
+
mi.image = GUTTER;
|
|
389
|
+
mi.attributedTitle = str(s.more.title, attrs($.NSColor.secondaryLabelColor, L.font, null));
|
|
390
|
+
mi.enabled = true;
|
|
391
|
+
mi.submenu = sub;
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
menu.addItem($.NSMenuItem.separatorItem);
|
|
395
|
+
footer = withImage(add(menu, footerText(), null), 'clock');
|
|
396
|
+
withImage(add(menu, snap.labels.refresh, 'refresh:', 0, 'r'), 'arrow.clockwise');
|
|
397
|
+
withImage(add(menu, snap.labels.openPanel, 'openPanel:', 0, 'o'), 'macwindow');
|
|
398
|
+
menu.addItem($.NSMenuItem.separatorItem);
|
|
399
|
+
withImage(add(menu, snap.labels.hide, 'hide:'), 'eye.slash');
|
|
400
|
+
} else {
|
|
401
|
+
footer = withImage(add(menu, footerText(), null), 'clock');
|
|
402
|
+
withImage(add(menu, OPEN_PANEL, 'openPanel:', 0, 'o'), 'macwindow');
|
|
403
|
+
}
|
|
404
|
+
closeItem(menu);
|
|
405
|
+
menu.delegate = target;
|
|
406
|
+
item.menu = menu;
|
|
407
|
+
appearance = ObjC.unwrap(app.effectiveAppearance.name);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
ObjC.registerSubclass({
|
|
411
|
+
name: 'SidebyMenuBar',
|
|
412
|
+
protocols: ['NSMenuDelegate'],
|
|
413
|
+
methods: {
|
|
414
|
+
'menuWillOpen:': { types: ['void', ['id']], implementation: function () { menuOpen = true; try { unregisterHotkey(); } catch (e) {} } },
|
|
415
|
+
'menuDidClose:': {
|
|
416
|
+
types: ['void', ['id']],
|
|
417
|
+
implementation: function () { menuOpen = false; closedAt = now(); try { registerHotkey(); } catch (e) {} },
|
|
418
|
+
},
|
|
419
|
+
'closeMenu:': { types: ['void', ['id']], implementation: function () {} },
|
|
420
|
+
'tick:': {
|
|
421
|
+
types: ['void', ['id']],
|
|
422
|
+
implementation: function () {
|
|
423
|
+
actions = actions.filter(function (t) { return t.running; });
|
|
424
|
+
if (task && task.running && now() - lastStart > TIMEOUT) task.terminate;
|
|
425
|
+
if (task && !task.running) finishSnapshot();
|
|
426
|
+
if (!task && now() - lastStart >= SNAPSHOT) startSnapshot();
|
|
427
|
+
// The bars are pictures in the colours of the moment; redraw them when light or dark mode changes.
|
|
428
|
+
if (ObjC.unwrap(app.effectiveAppearance.name) !== appearance) build();
|
|
429
|
+
else drawTitle();
|
|
430
|
+
if (footer) footer.title = footerText();
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
'refresh:': {
|
|
434
|
+
types: ['void', ['id']],
|
|
435
|
+
implementation: function () {
|
|
436
|
+
// One running already is the refresh asked for; a stuck one is ended by the timeout above.
|
|
437
|
+
if (!task) { lastStart = 0; startSnapshot(); }
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
'openPanel:': { types: ['void', ['id']], implementation: function () { act(['ui', '--background']); } },
|
|
441
|
+
'hide:': { types: ['void', ['id']], implementation: function () { act(['menubar', 'off', '--yes']); } },
|
|
442
|
+
'start:': {
|
|
443
|
+
types: ['void', ['id']],
|
|
444
|
+
implementation: function (sender) {
|
|
445
|
+
var ref = refs[sender.tag - 1];
|
|
446
|
+
if (ref) act(['menubar', 'start', ref]);
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
var target = $.SidebyMenuBar.alloc.init;
|
|
452
|
+
build();
|
|
453
|
+
startSnapshot();
|
|
454
|
+
$.NSTimer.scheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(TICK, target, 'tick:', $(), true);
|
|
455
|
+
app.run;
|
|
456
|
+
}
|
|
457
|
+
`;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { HandoffPlan } from '../core/handoff.ts';
|
|
2
|
+
import type { Account, FamilyLogo, LoginState, QuotaResult } from '../types.ts';
|
|
3
|
+
import { type MenubarLang, type MenubarStrings } from './strings.ts';
|
|
4
|
+
export type MenubarLevel = 'ok' | 'warn' | 'fail' | 'none';
|
|
5
|
+
/** One quota window drawn as a small bar. */
|
|
6
|
+
export interface MenubarBar {
|
|
7
|
+
label: string;
|
|
8
|
+
percent: number;
|
|
9
|
+
level: MenubarLevel;
|
|
10
|
+
}
|
|
11
|
+
export interface MenubarRow {
|
|
12
|
+
ref: string;
|
|
13
|
+
label: string;
|
|
14
|
+
/** The whole row as one line of text, for readers that do not draw bars. */
|
|
15
|
+
detail: string;
|
|
16
|
+
level: MenubarLevel;
|
|
17
|
+
/** The account `sideby next` would pick in this Family. */
|
|
18
|
+
recommended: boolean;
|
|
19
|
+
/** Hover text: when each window resets, and what a click does. */
|
|
20
|
+
tip: string;
|
|
21
|
+
/**
|
|
22
|
+
* The bars, in two columns: the shorter window, then the longer one. A Family with one window (such as `7d`) fills
|
|
23
|
+
* the second, so the long windows of all Families line up. Null when the row has no Quota to draw.
|
|
24
|
+
*/
|
|
25
|
+
bars: [MenubarBar | null, MenubarBar | null] | null;
|
|
26
|
+
/** How long until the fullest window resets, such as `4d 17h`; empty when nothing is used. */
|
|
27
|
+
reset: string;
|
|
28
|
+
/** What stands in for the bars: `API key`, `signed out`, `no quota yet`; empty when bars are drawn. */
|
|
29
|
+
note: string;
|
|
30
|
+
}
|
|
31
|
+
export interface MenubarSection {
|
|
32
|
+
family: string;
|
|
33
|
+
title: string;
|
|
34
|
+
/**
|
|
35
|
+
* The Family's mark before its title, as the Panel draws it: in its brand `color` when it has one, else in the
|
|
36
|
+
* menu's text colour; null when the Family has no mark.
|
|
37
|
+
*/
|
|
38
|
+
logo: {
|
|
39
|
+
path: string;
|
|
40
|
+
fillRule?: 'nonzero' | 'evenodd';
|
|
41
|
+
color?: string;
|
|
42
|
+
} | null;
|
|
43
|
+
/** The window names above the two bar columns, such as `5h` and `7d`; null where no row has that column. */
|
|
44
|
+
columns: [string | null, string | null];
|
|
45
|
+
/** The recommended account first, then the others in Display Order. */
|
|
46
|
+
rows: MenubarRow[];
|
|
47
|
+
/** API key and signed-out accounts, behind one submenu; null when there are none or nothing else to show. */
|
|
48
|
+
more: {
|
|
49
|
+
title: string;
|
|
50
|
+
rows: MenubarRow[];
|
|
51
|
+
} | null;
|
|
52
|
+
}
|
|
53
|
+
export interface MenubarSnapshot {
|
|
54
|
+
schemaVersion: 1;
|
|
55
|
+
/**
|
|
56
|
+
* The words next to the icon, such as `Codex 62%`: only once the tightest Family's best account reaches the warning
|
|
57
|
+
* level; empty while every Family has quota left, or without Quota data, so the icon stands alone.
|
|
58
|
+
*/
|
|
59
|
+
title: string;
|
|
60
|
+
level: MenubarLevel;
|
|
61
|
+
tooltip: string;
|
|
62
|
+
/** The first line of the menu as one line of text: which account the title belongs to; empty without Quota data. */
|
|
63
|
+
headline: string;
|
|
64
|
+
/** The card at the top of the menu: a bold status and a grey line naming the account; null without Quota data. */
|
|
65
|
+
card: {
|
|
66
|
+
status: string;
|
|
67
|
+
detail: string;
|
|
68
|
+
level: MenubarLevel;
|
|
69
|
+
} | null;
|
|
70
|
+
/** The shortcut that opens the menu from anywhere (config `menubar.hotkey`); null when turned off. */
|
|
71
|
+
hotkey: MenubarHotkey | null;
|
|
72
|
+
/** When this snapshot was made (ISO). */
|
|
73
|
+
updatedAt: string;
|
|
74
|
+
lang: MenubarLang;
|
|
75
|
+
sections: MenubarSection[];
|
|
76
|
+
/** Footer words; the script fills `{n}` of `updatedMinutes` itself. */
|
|
77
|
+
labels: Pick<MenubarStrings, 'recommended' | 'empty' | 'loading' | 'addAccount' | 'resetsHeader' | 'updatedJustNow' | 'updatedMinutes' | 'refreshing' | 'refreshFailed' | 'refresh' | 'openPanel' | 'hide'>;
|
|
78
|
+
}
|
|
79
|
+
export interface MenubarFamilyInput {
|
|
80
|
+
id: string;
|
|
81
|
+
title: string;
|
|
82
|
+
logo?: FamilyLogo | null;
|
|
83
|
+
/** Its Handoff ranking (`sideby next`); null when the Family has no Quota source. */
|
|
84
|
+
plan: HandoffPlan | null;
|
|
85
|
+
/** In Display Order. */
|
|
86
|
+
accounts: {
|
|
87
|
+
ref: string;
|
|
88
|
+
name: string;
|
|
89
|
+
kind: Account['kind'];
|
|
90
|
+
login: LoginState | 'not-needed';
|
|
91
|
+
quota: QuotaResult;
|
|
92
|
+
/** The other refs of its Same Login: the same subscription, so one quota. */
|
|
93
|
+
sameLogin?: readonly string[];
|
|
94
|
+
}[];
|
|
95
|
+
}
|
|
96
|
+
/** A shortcut as the menu bar script registers it: a macOS virtual key code and Carbon modifier flags. */
|
|
97
|
+
export interface MenubarHotkey {
|
|
98
|
+
keyCode: number;
|
|
99
|
+
modifiers: number;
|
|
100
|
+
/** How macOS writes it, such as `⌥⌘S`. */
|
|
101
|
+
label: string;
|
|
102
|
+
}
|
|
103
|
+
export declare const DEFAULT_MENUBAR_HOTKEY = "opt+cmd+s";
|
|
104
|
+
/** Config `menubar.hotkey` (`opt+cmd+s`, `off`) as the script registers it; null for `off` or a bad value. */
|
|
105
|
+
export declare function menubarHotkey(value: string | undefined): MenubarHotkey | null;
|
|
106
|
+
/** `2h 5m`, `3d 4h` or `12m` until `at`; at least one minute. */
|
|
107
|
+
export declare function untilText(at: string, now: Date, s: MenubarStrings): string;
|
|
108
|
+
/**
|
|
109
|
+
* Each Family's number is the Quota Pressure of the account `sideby next` would pick, or, when every account is past
|
|
110
|
+
* the fail level, the lowest of theirs; the title shows the highest of these, so it turns red when some tool has
|
|
111
|
+
* nothing left to hand over to.
|
|
112
|
+
*/
|
|
113
|
+
export declare function menubarSnapshot(families: readonly MenubarFamilyInput[], now: Date, lang: MenubarLang, hotkey?: MenubarHotkey | null): MenubarSnapshot;
|
|
114
|
+
/** The language of the menu: config `panel.language`, else the system language the script passes, else English. */
|
|
115
|
+
export declare function menubarLang(configured: string | undefined, system: string | undefined): MenubarLang;
|