@jini-ai/desktop-host 0.7.2 → 0.7.3-next.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/CHANGELOG.md +1 -7
- package/README.md +3 -1
- package/dist/app-version/index.d.ts +3 -0
- package/dist/app-version/index.js +3 -0
- package/dist/app-version/loader.d.ts +23 -0
- package/dist/app-version/loader.js +38 -0
- package/dist/app-version/store.d.ts +16 -0
- package/dist/app-version/store.js +23 -0
- package/dist/app-version/update-check.d.ts +30 -0
- package/dist/app-version/update-check.js +35 -0
- package/dist/electron/app-version.d.ts +46 -0
- package/dist/electron/app-version.js +38 -0
- package/dist/electron/electron-url-capture.js +40 -37
- package/dist/electron/index.d.ts +1 -0
- package/dist/electron/index.js +1 -0
- package/dist/electron/testing.js +96 -79
- package/dist/electron/updates/auto-update-controller.js +168 -154
- package/dist/electron/updates/instance-presence.js +22 -19
- package/dist/electron/usability/index.d.ts +1 -0
- package/dist/electron/usability/index.js +1 -0
- package/dist/electron/usability/workspace-menu.d.ts +125 -0
- package/dist/electron/usability/workspace-menu.js +71 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/logging.d.ts +8 -1
- package/dist/logging.js +49 -33
- package/dist/preview-scheduler.d.ts +28 -0
- package/dist/preview-scheduler.js +36 -0
- package/dist/protocol.d.ts +2 -1
- package/dist/protocol.js +1 -1
- package/dist/shell.d.ts +1 -1
- package/dist/shell.js +1 -1
- package/dist/shutdown/index.d.ts +1 -0
- package/dist/shutdown/index.js +1 -0
- package/dist/shutdown/last-window-quit.d.ts +125 -0
- package/dist/shutdown/last-window-quit.js +130 -0
- package/dist/sidecar.js +13 -9
- package/package.json +21 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeErrorForLog } from '@jini-ai/core';
|
|
1
2
|
import { decideFinalQuit, decideRestartClick, electUpdaterOwner, shouldCheckNow, FIRST_CHECK_DELAY_MS, UPDATER_TICK_MS, UPDATE_CHECK_INTERVAL_MS, PRESENCE_STALE_MS } from './update-policy.js';
|
|
2
3
|
/** Default update copy is replaceable as a whole by the host. */
|
|
3
4
|
export const defaultUpdateMessages = {
|
|
@@ -60,171 +61,184 @@ export function createElectronUpdaterAdapter({ updater }) {
|
|
|
60
61
|
function isNativeUpdater(updater) {
|
|
61
62
|
return updater.on.length !== 1;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
function logError({ ctx, build, error }) {
|
|
65
|
+
ctx.deps.log({ message: build({ message: describeErrorForLog({ err: error }) }) });
|
|
66
|
+
}
|
|
67
|
+
/** Request a restart only before staging; a second quit could interrupt Squirrel's handoff.
|
|
68
|
+
* @complexity O(n) live presence records; effects are explanation or a quit request.
|
|
67
69
|
*/
|
|
68
|
-
|
|
69
|
-
const {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
log({ message: messages.error({ message: messageOf(error) }) });
|
|
105
|
-
// A failed Squirrel handoff must release the held quit rather than leave the app hanging.
|
|
106
|
-
if (installStarted)
|
|
107
|
-
deps.quit();
|
|
108
|
-
};
|
|
70
|
+
function requestRestart(ctx) {
|
|
71
|
+
const { state, deps } = ctx;
|
|
72
|
+
if (state.stopped || state.installStarted)
|
|
73
|
+
return;
|
|
74
|
+
const count = otherInstances(ctx);
|
|
75
|
+
const action = decideRestartClick({ updateReady: state.readyVersion !== null, otherInstances: count });
|
|
76
|
+
if (action === 'others-open')
|
|
77
|
+
deps.explainOthersOpen({ count });
|
|
78
|
+
if (action !== 'restart')
|
|
79
|
+
return;
|
|
80
|
+
state.restartRequested = true;
|
|
81
|
+
deps.quit();
|
|
82
|
+
}
|
|
83
|
+
function onDownloaded(ctx, info) {
|
|
84
|
+
const { state, deps, messages } = ctx;
|
|
85
|
+
if (state.stopped)
|
|
86
|
+
return;
|
|
87
|
+
state.readyVersion = info.version;
|
|
88
|
+
deps.log({ message: messages.downloaded({ version: info.version }) });
|
|
89
|
+
if (state.promptedVersion === info.version)
|
|
90
|
+
return;
|
|
91
|
+
state.promptedVersion = info.version;
|
|
92
|
+
// Promise wrapping catches a prompt that throws synchronously as well as a rejection.
|
|
93
|
+
Promise.resolve().then(() => deps.promptUpdateReady({ version: info.version })).then(restart => { if (restart && !state.stopped)
|
|
94
|
+
requestRestart(ctx); }, error => logError({ ctx, build: messages.promptFailed, error }));
|
|
95
|
+
}
|
|
96
|
+
function onUpdaterError({ ctx, error }) {
|
|
97
|
+
if (ctx.state.stopped)
|
|
98
|
+
return;
|
|
99
|
+
logError({ ctx, build: ctx.messages.error, error });
|
|
100
|
+
// A failed Squirrel handoff must release the held quit rather than leave the app hanging.
|
|
101
|
+
if (ctx.state.installStarted)
|
|
102
|
+
ctx.deps.quit();
|
|
103
|
+
}
|
|
104
|
+
function registerUpdaterListeners(ctx) {
|
|
105
|
+
const { updater } = ctx.deps;
|
|
109
106
|
if (isNativeUpdater(updater)) {
|
|
110
|
-
updater.on('update-downloaded', onDownloaded);
|
|
111
|
-
updater.on('error',
|
|
107
|
+
updater.on('update-downloaded', (info) => onDownloaded(ctx, info));
|
|
108
|
+
updater.on('error', (error) => onUpdaterError({ ctx, error }));
|
|
112
109
|
}
|
|
113
110
|
else {
|
|
114
|
-
updater.on({ event: 'update-downloaded', listener: ({ payload }) => onDownloaded(payload) });
|
|
115
|
-
updater.on({ event: 'error', listener: ({ payload }) =>
|
|
111
|
+
updater.on({ event: 'update-downloaded', listener: ({ payload }) => onDownloaded(ctx, payload) });
|
|
112
|
+
updater.on({ event: 'error', listener: ({ payload }) => onUpdaterError({ ctx, error: payload }) });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function otherInstances({ deps }) { return deps.presence.readLive().filter(record => record.pid !== deps.pid).length; }
|
|
116
|
+
function heartbeat(ctx) {
|
|
117
|
+
const { deps } = ctx;
|
|
118
|
+
try {
|
|
119
|
+
deps.presence.write({ record: { pid: deps.pid, startedAt: ctx.startedAt, heartbeatAt: ctx.now() } });
|
|
116
120
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
presence.write({ record: { pid, startedAt, heartbeatAt: now() } });
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
log({ message: messages.presenceWriteFailed({ message: messageOf(error) }) });
|
|
124
|
-
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
logError({ ctx, build: ctx.messages.presenceWriteFailed, error });
|
|
125
123
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
checking = false;
|
|
135
|
-
log({ message: messages.checkFailed({ message: messageOf(error) }) });
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
result.then(value => value?.downloadPromise ?? null)
|
|
139
|
-
.catch(error => log({ message: messages.checkFailed({ message: messageOf(error) }) }))
|
|
140
|
-
.finally(() => { checking = false; });
|
|
124
|
+
}
|
|
125
|
+
function check(ctx) {
|
|
126
|
+
const { state } = ctx;
|
|
127
|
+
state.lastCheckAt = ctx.now();
|
|
128
|
+
state.checking = true;
|
|
129
|
+
let result;
|
|
130
|
+
try {
|
|
131
|
+
result = ctx.deps.updater.checkForUpdates();
|
|
141
132
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const time = now();
|
|
147
|
-
const isOwner = electUpdaterOwner({ instances: presence.readLive(), now: time, staleMs: timing.staleMs }) === pid;
|
|
148
|
-
if (shouldCheckNow({ isOwner, lastCheckAt, now: time, busy: checking || readyVersion !== null, intervalMs: timing.checkIntervalMs }))
|
|
149
|
-
check();
|
|
133
|
+
catch (error) {
|
|
134
|
+
state.checking = false;
|
|
135
|
+
logError({ ctx, build: ctx.messages.checkFailed, error });
|
|
136
|
+
return;
|
|
150
137
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
138
|
+
result.then(value => value?.downloadPromise ?? null)
|
|
139
|
+
.catch(error => logError({ ctx, build: ctx.messages.checkFailed, error }))
|
|
140
|
+
.finally(() => { state.checking = false; });
|
|
141
|
+
}
|
|
142
|
+
function tick(ctx) {
|
|
143
|
+
const { state, deps } = ctx;
|
|
144
|
+
if (state.stopped)
|
|
145
|
+
return;
|
|
146
|
+
heartbeat(ctx);
|
|
147
|
+
const time = ctx.now();
|
|
148
|
+
const isOwner = electUpdaterOwner({ instances: deps.presence.readLive(), now: time, staleMs: ctx.timing.staleMs }) === deps.pid;
|
|
149
|
+
if (shouldCheckNow({ isOwner, lastCheckAt: state.lastCheckAt, now: time, busy: state.checking || state.readyVersion !== null, intervalMs: ctx.timing.checkIntervalMs }))
|
|
150
|
+
check(ctx);
|
|
151
|
+
}
|
|
152
|
+
/** Hand off installation with native flags; false lets the current quit proceed on a sync failure.
|
|
153
|
+
* Logs failures and cancels their fallback; successful handoffs retain it. @complexity O(1).
|
|
154
|
+
*/
|
|
155
|
+
function startInstall(ctx, { silent, relaunch }) {
|
|
156
|
+
const { deps, handles, timers } = ctx;
|
|
157
|
+
const { updater } = deps;
|
|
158
|
+
ctx.state.installStarted = true;
|
|
159
|
+
updater.autoRunAppAfterInstall = relaunch;
|
|
160
|
+
// Arm before the handoff so a synchronous failure cannot leave the held quit hanging.
|
|
161
|
+
const fallback = timers.setTimeout({ callback: () => { if (!ctx.state.stopped)
|
|
162
|
+
deps.quit(); }, ms: ctx.timing.stageTimeoutMs });
|
|
163
|
+
fallback.unref?.();
|
|
164
|
+
handles.push(fallback);
|
|
165
|
+
try {
|
|
166
|
+
if (isNativeUpdater(updater))
|
|
167
|
+
updater.quitAndInstall(silent, relaunch);
|
|
168
|
+
else
|
|
169
|
+
updater.quitAndInstall({}, { isSilent: silent, isForceRunAfter: relaunch });
|
|
165
170
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
updater.autoRunAppAfterInstall = relaunch;
|
|
172
|
-
// Arm before the handoff so a synchronous failure cannot leave the held quit hanging.
|
|
173
|
-
const fallback = timers.setTimeout({ callback: () => { if (!stopped)
|
|
174
|
-
deps.quit(); }, ms: timing.stageTimeoutMs });
|
|
175
|
-
fallback.unref?.();
|
|
176
|
-
handles.push(fallback);
|
|
177
|
-
try {
|
|
178
|
-
if (isNativeUpdater(updater))
|
|
179
|
-
updater.quitAndInstall(silent, relaunch);
|
|
180
|
-
else
|
|
181
|
-
updater.quitAndInstall({}, { isSilent: silent, isForceRunAfter: relaunch });
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
timers.clear({ timer: fallback });
|
|
185
|
-
handles.splice(handles.indexOf(fallback), 1);
|
|
186
|
-
log({ message: messages.error({ message: messageOf(error) }) });
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
return true;
|
|
171
|
+
catch (error) {
|
|
172
|
+
timers.clear({ timer: fallback });
|
|
173
|
+
handles.splice(handles.indexOf(fallback), 1);
|
|
174
|
+
logError({ ctx, build: ctx.messages.error, error });
|
|
175
|
+
return false;
|
|
190
176
|
}
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
function startController(ctx) {
|
|
180
|
+
const { state, timers, timing, handles } = ctx;
|
|
181
|
+
if (state.started || state.stopped)
|
|
182
|
+
return;
|
|
183
|
+
// Advertise presence immediately so siblings see us, while delaying the first update check.
|
|
184
|
+
state.started = true;
|
|
185
|
+
heartbeat(ctx);
|
|
186
|
+
const first = timers.setTimeout({ callback: () => tick(ctx), ms: timing.firstCheckDelayMs });
|
|
187
|
+
const every = timers.setInterval({ callback: () => tick(ctx), ms: timing.tickMs });
|
|
188
|
+
first.unref?.();
|
|
189
|
+
every.unref?.();
|
|
190
|
+
handles.push(first, every);
|
|
191
|
+
}
|
|
192
|
+
function beforeFinalQuit(ctx) {
|
|
193
|
+
const { state, deps } = ctx;
|
|
194
|
+
if (state.stopped)
|
|
195
|
+
return false;
|
|
196
|
+
const action = decideFinalQuit({ platform: deps.platform, updateReady: state.readyVersion !== null,
|
|
197
|
+
otherInstances: state.readyVersion !== null && !state.installStarted ? otherInstances(ctx) : 0,
|
|
198
|
+
restartRequested: state.restartRequested, installStarted: state.installStarted });
|
|
199
|
+
if (deps.platform === 'win32' && !state.installStarted)
|
|
200
|
+
deps.updater.autoInstallOnAppQuit = action === 'install-on-quit';
|
|
201
|
+
if (action === 'stage-then-quit')
|
|
202
|
+
return startInstall(ctx, { silent: false, relaunch: false });
|
|
203
|
+
if (action === 'install-and-relaunch')
|
|
204
|
+
return startInstall(ctx, { silent: true, relaunch: true });
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
function willQuit(ctx) {
|
|
208
|
+
if (ctx.state.stopped)
|
|
209
|
+
return;
|
|
210
|
+
ctx.state.stopped = true;
|
|
211
|
+
for (const handle of ctx.handles)
|
|
212
|
+
ctx.timers.clear({ timer: handle });
|
|
213
|
+
ctx.deps.presence.remove({ pid: ctx.deps.pid });
|
|
214
|
+
}
|
|
215
|
+
/** Coordinates quiet downloads and last-instance installs through injected effects.
|
|
216
|
+
* No single-instance lock is acquired. Construction registers updater listeners but starts no timers.
|
|
217
|
+
* @complexity O(1) construction; O(n) live records per tick or final quit.
|
|
218
|
+
*/
|
|
219
|
+
export function createAutoUpdateController(deps, options = {}) {
|
|
220
|
+
const clock = deps.clock !== undefined ? deps.clock : { nowMs: deps.now };
|
|
221
|
+
const now = () => clock.nowMs();
|
|
222
|
+
const ctx = {
|
|
223
|
+
deps, now,
|
|
224
|
+
timers: options.timers ?? deps.timers ?? createNodeUpdateTimers(),
|
|
225
|
+
timing: { ...defaultUpdateTiming, ...deps.timing, ...options.timing },
|
|
226
|
+
messages: options.messages ?? deps.messages ?? defaultUpdateMessages,
|
|
227
|
+
startedAt: now(),
|
|
228
|
+
handles: [],
|
|
229
|
+
state: { started: false, stopped: false, lastCheckAt: null, checking: false, readyVersion: null, promptedVersion: null, restartRequested: false, installStarted: false },
|
|
230
|
+
};
|
|
231
|
+
deps.updater.autoDownload = true;
|
|
232
|
+
// Windows registers its quit handler only if this is true at download time; final-quit policy
|
|
233
|
+
// later decides whether to allow installation. macOS must withhold Squirrel until the final quit.
|
|
234
|
+
deps.updater.autoInstallOnAppQuit = deps.platform === 'win32';
|
|
235
|
+
registerUpdaterListeners(ctx);
|
|
191
236
|
return {
|
|
192
|
-
start()
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
heartbeat();
|
|
198
|
-
const first = timers.setTimeout({ callback: tick, ms: timing.firstCheckDelayMs });
|
|
199
|
-
const every = timers.setInterval({ callback: tick, ms: timing.tickMs });
|
|
200
|
-
first.unref?.();
|
|
201
|
-
every.unref?.();
|
|
202
|
-
handles.push(first, every);
|
|
203
|
-
},
|
|
204
|
-
tick,
|
|
205
|
-
requestRestart,
|
|
206
|
-
beforeFinalQuit() {
|
|
207
|
-
if (stopped)
|
|
208
|
-
return false;
|
|
209
|
-
const action = decideFinalQuit({ platform, updateReady: readyVersion !== null,
|
|
210
|
-
otherInstances: readyVersion !== null && !installStarted ? otherInstances() : 0,
|
|
211
|
-
restartRequested, installStarted });
|
|
212
|
-
if (platform === 'win32' && !installStarted)
|
|
213
|
-
updater.autoInstallOnAppQuit = action === 'install-on-quit';
|
|
214
|
-
if (action === 'stage-then-quit')
|
|
215
|
-
return startInstall({ silent: false, relaunch: false });
|
|
216
|
-
if (action === 'install-and-relaunch')
|
|
217
|
-
return startInstall({ silent: true, relaunch: true });
|
|
218
|
-
return false;
|
|
219
|
-
},
|
|
220
|
-
willQuit() {
|
|
221
|
-
if (stopped)
|
|
222
|
-
return;
|
|
223
|
-
stopped = true;
|
|
224
|
-
for (const handle of handles)
|
|
225
|
-
timers.clear({ timer: handle });
|
|
226
|
-
presence.remove({ pid });
|
|
227
|
-
},
|
|
237
|
+
start: () => startController(ctx),
|
|
238
|
+
tick: () => tick(ctx),
|
|
239
|
+
requestRestart: () => requestRestart(ctx),
|
|
240
|
+
beforeFinalQuit: () => beforeFinalQuit(ctx),
|
|
241
|
+
willQuit: () => willQuit(ctx),
|
|
228
242
|
};
|
|
229
243
|
}
|
|
230
244
|
//# sourceMappingURL=auto-update-controller.js.map
|
|
@@ -54,26 +54,29 @@ export function createFileInstancePresence({ directory, filesystem, isAlive, wri
|
|
|
54
54
|
catch {
|
|
55
55
|
return [];
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
for (const name of names) {
|
|
59
|
-
let record;
|
|
60
|
-
try {
|
|
61
|
-
record = parseRecord(filesystem.readFileSync({ path: path.join(directory, name), encoding: 'utf8' }));
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
// Leave unreadable/malformed records alone: a sibling may be writing on a filesystem
|
|
67
|
-
// without atomic rename. Remove confirmed dead PIDs so crashes do not linger.
|
|
68
|
-
if (record !== null && name === `${record.pid}.json`) {
|
|
69
|
-
if (isAlive({ pid: record.pid }))
|
|
70
|
-
live.push(record);
|
|
71
|
-
else
|
|
72
|
-
remove({ pid: record.pid });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return live;
|
|
57
|
+
return collectLiveRecords(names, { directory, filesystem, isAlive }, remove);
|
|
76
58
|
},
|
|
77
59
|
};
|
|
78
60
|
}
|
|
61
|
+
function collectLiveRecords(names, { directory, filesystem, isAlive }, remove) {
|
|
62
|
+
const live = [];
|
|
63
|
+
for (const name of names) {
|
|
64
|
+
let record;
|
|
65
|
+
try {
|
|
66
|
+
record = parseRecord(filesystem.readFileSync({ path: path.join(directory, name), encoding: 'utf8' }));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// Leave unreadable/malformed records alone: a sibling may be writing on a filesystem
|
|
72
|
+
// without atomic rename. Remove confirmed dead PIDs so crashes do not linger.
|
|
73
|
+
if (record !== null && name === `${record.pid}.json`) {
|
|
74
|
+
if (isAlive({ pid: record.pid }))
|
|
75
|
+
live.push(record);
|
|
76
|
+
else
|
|
77
|
+
remove({ pid: record.pid });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return live;
|
|
81
|
+
}
|
|
79
82
|
//# sourceMappingURL=instance-presence.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The workspace window's application menu: Electron's default menus, plus History with
|
|
3
|
+
* Back (Cmd+[) and Forward (Cmd+]) for the project tab on screen.
|
|
4
|
+
*
|
|
5
|
+
* A menu accelerator is the one key binding that still fires while focus is inside a project tab's
|
|
6
|
+
* `<webview>` guest, which a key listener in the host page never sees. Setting a menu
|
|
7
|
+
* replaces the default, so this template rebuilds it role for role and adds History. The one
|
|
8
|
+
* difference: an unpackaged run's Help menu lost Electron's own links (electronjs.org, docs,
|
|
9
|
+
* issues). A packaged app never showed those.
|
|
10
|
+
*
|
|
11
|
+
* **Main only asks.** A click sends `back` or `forward` to the focused window's renderer and knows
|
|
12
|
+
* nothing about tabs. Every project tab stays mounted, and only the visible one subscribes, so a
|
|
13
|
+
* command with no project tab showing reaches nobody.
|
|
14
|
+
*
|
|
15
|
+
* No `electron` import, so it can be tested under plain node.
|
|
16
|
+
*/
|
|
17
|
+
/** What a click asks the renderer to do. */
|
|
18
|
+
type HistoryCommand = "back" | "forward";
|
|
19
|
+
/** A menu click's focused window, as far as this module reads one. Electron types it as a
|
|
20
|
+
* `BaseWindow`, which has no `webContents`, so that is optional. */
|
|
21
|
+
interface HistoryCommandWindow {
|
|
22
|
+
isDestroyed(): boolean;
|
|
23
|
+
webContents?: {
|
|
24
|
+
send(channel: string, payload: string): void;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** One History item. `click` has the leading parameters of Electron's `MenuItem` click. */
|
|
28
|
+
interface HistoryMenuItem {
|
|
29
|
+
label: string;
|
|
30
|
+
accelerator: string;
|
|
31
|
+
click: (item: unknown, window: HistoryCommandWindow | undefined) => void;
|
|
32
|
+
}
|
|
33
|
+
/** The History menu: exactly Back, then Forward. */
|
|
34
|
+
interface HistoryMenu {
|
|
35
|
+
label: string;
|
|
36
|
+
submenu: [HistoryMenuItem, HistoryMenuItem];
|
|
37
|
+
}
|
|
38
|
+
/** The View menu: Electron's default reload/dev-tools items, this shell's own Zoom controls in
|
|
39
|
+
* place of the built-in zoom roles (the built-in roles target the top-level webContents instead of
|
|
40
|
+
* the visible guest), then Toggle Full Screen. */
|
|
41
|
+
interface ViewMenu<Zoom> {
|
|
42
|
+
label: string;
|
|
43
|
+
submenu: [
|
|
44
|
+
{
|
|
45
|
+
role: "reload";
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
role: "forceReload";
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
role: "toggleDevTools";
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: "separator";
|
|
55
|
+
},
|
|
56
|
+
...Zoom[],
|
|
57
|
+
{
|
|
58
|
+
type: "separator";
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
role: "togglefullscreen";
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
/** One top-level entry of {@link workspaceMenuTemplate}: an Electron menu role, View, History, or
|
|
66
|
+
* Find. */
|
|
67
|
+
type WorkspaceMenuEntry<Find, Zoom> = {
|
|
68
|
+
role: "appMenu" | "fileMenu" | "editMenu" | "windowMenu";
|
|
69
|
+
} | {
|
|
70
|
+
role: "help";
|
|
71
|
+
submenu: [];
|
|
72
|
+
} | ViewMenu<Zoom> | HistoryMenu | Find;
|
|
73
|
+
/**
|
|
74
|
+
* Electron's default View menu, with the supplied Zoom controls in place of
|
|
75
|
+
* the built-in zoom roles.
|
|
76
|
+
*
|
|
77
|
+
* @complexity O(1).
|
|
78
|
+
*/
|
|
79
|
+
declare function viewMenu<Zoom>({ label, zoomItems }: {
|
|
80
|
+
label: string;
|
|
81
|
+
zoomItems: Zoom[];
|
|
82
|
+
}, _optional?: {}): ViewMenu<Zoom>;
|
|
83
|
+
/**
|
|
84
|
+
* Sends one history command to a window's renderer.
|
|
85
|
+
*
|
|
86
|
+
* @param window the menu click's focused window. Electron types it as a `BaseWindow`, which has
|
|
87
|
+
* no `webContents`, so that is checked rather than assumed.
|
|
88
|
+
* @param command
|
|
89
|
+
* @returns whether anything was sent.
|
|
90
|
+
* @complexity O(1).
|
|
91
|
+
*/
|
|
92
|
+
declare function sendHistoryCommand({ window, command, channel }: {
|
|
93
|
+
window: HistoryCommandWindow | undefined;
|
|
94
|
+
command: HistoryCommand;
|
|
95
|
+
channel: string;
|
|
96
|
+
}, _optional?: {}): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* The History menu. Named for Chrome's, which has the same two shortcuts.
|
|
99
|
+
*
|
|
100
|
+
* @complexity O(1).
|
|
101
|
+
*/
|
|
102
|
+
declare function historyMenu({ channel, labels }: {
|
|
103
|
+
channel: string;
|
|
104
|
+
labels: {
|
|
105
|
+
menu: string;
|
|
106
|
+
back: string;
|
|
107
|
+
forward: string;
|
|
108
|
+
};
|
|
109
|
+
}, _optional?: {}): HistoryMenu;
|
|
110
|
+
/**
|
|
111
|
+
* Electron's default application menu with History and Find added before Window. The Help menu is
|
|
112
|
+
* empty, as a packaged app's default is.
|
|
113
|
+
*
|
|
114
|
+
* @param platform `process.platform`; only macOS gets the app menu.
|
|
115
|
+
* @complexity O(1).
|
|
116
|
+
*/
|
|
117
|
+
declare function workspaceMenuTemplate<Find, Zoom>({ platform, view, history, find }: {
|
|
118
|
+
platform: NodeJS.Platform;
|
|
119
|
+
view: ViewMenu<Zoom>;
|
|
120
|
+
history: HistoryMenu;
|
|
121
|
+
find: Find;
|
|
122
|
+
}, _optional?: {}): WorkspaceMenuEntry<Find, Zoom>[];
|
|
123
|
+
export { sendHistoryCommand, historyMenu, viewMenu, workspaceMenuTemplate };
|
|
124
|
+
export type { HistoryCommandWindow, HistoryCommand, HistoryMenu, HistoryMenuItem, ViewMenu, WorkspaceMenuEntry };
|
|
125
|
+
//# sourceMappingURL=workspace-menu.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Electron's default View menu, with the supplied Zoom controls in place of
|
|
3
|
+
* the built-in zoom roles.
|
|
4
|
+
*
|
|
5
|
+
* @complexity O(1).
|
|
6
|
+
*/
|
|
7
|
+
function viewMenu({ label, zoomItems }, _optional = {}) {
|
|
8
|
+
return {
|
|
9
|
+
label,
|
|
10
|
+
submenu: [
|
|
11
|
+
{ role: "reload" },
|
|
12
|
+
{ role: "forceReload" },
|
|
13
|
+
{ role: "toggleDevTools" },
|
|
14
|
+
{ type: "separator" },
|
|
15
|
+
...zoomItems,
|
|
16
|
+
{ type: "separator" },
|
|
17
|
+
{ role: "togglefullscreen" },
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sends one history command to a window's renderer.
|
|
23
|
+
*
|
|
24
|
+
* @param window the menu click's focused window. Electron types it as a `BaseWindow`, which has
|
|
25
|
+
* no `webContents`, so that is checked rather than assumed.
|
|
26
|
+
* @param command
|
|
27
|
+
* @returns whether anything was sent.
|
|
28
|
+
* @complexity O(1).
|
|
29
|
+
*/
|
|
30
|
+
function sendHistoryCommand({ window, command, channel }, _optional = {}) {
|
|
31
|
+
if (!window || window.isDestroyed() || !window.webContents)
|
|
32
|
+
return false;
|
|
33
|
+
window.webContents.send(channel, command);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The History menu. Named for Chrome's, which has the same two shortcuts.
|
|
38
|
+
*
|
|
39
|
+
* @complexity O(1).
|
|
40
|
+
*/
|
|
41
|
+
function historyMenu({ channel, labels }, _optional = {}) {
|
|
42
|
+
return {
|
|
43
|
+
label: labels.menu,
|
|
44
|
+
submenu: [
|
|
45
|
+
{ label: labels.back, accelerator: "CmdOrCtrl+[", click: (_item, window) => void sendHistoryCommand({ window, command: "back", channel }) },
|
|
46
|
+
{ label: labels.forward, accelerator: "CmdOrCtrl+]", click: (_item, window) => void sendHistoryCommand({ window, command: "forward", channel }) },
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Electron's default application menu with History and Find added before Window. The Help menu is
|
|
52
|
+
* empty, as a packaged app's default is.
|
|
53
|
+
*
|
|
54
|
+
* @param platform `process.platform`; only macOS gets the app menu.
|
|
55
|
+
* @complexity O(1).
|
|
56
|
+
*/
|
|
57
|
+
function workspaceMenuTemplate({ platform, view, history, find }, _optional = {}) {
|
|
58
|
+
return [
|
|
59
|
+
// `as const`: a conditional spread otherwise widens this role, and every entry after it, to `string`.
|
|
60
|
+
...(platform === "darwin" ? [{ role: "appMenu" }] : []),
|
|
61
|
+
{ role: "fileMenu" },
|
|
62
|
+
{ role: "editMenu" },
|
|
63
|
+
view,
|
|
64
|
+
history,
|
|
65
|
+
find,
|
|
66
|
+
{ role: "windowMenu" },
|
|
67
|
+
{ role: "help", submenu: [] },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
export { sendHistoryCommand, historyMenu, viewMenu, workspaceMenuTemplate };
|
|
71
|
+
//# sourceMappingURL=workspace-menu.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/logging.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LogDiagnosticsSink, type Logger } from '@jini-ai/core/primitives';
|
|
2
2
|
export type LogAppend = (args: {
|
|
3
3
|
path: string;
|
|
4
4
|
data: string;
|
|
@@ -12,12 +12,19 @@ export declare function appendLogLine({ logPath, line }: {
|
|
|
12
12
|
}): boolean;
|
|
13
13
|
/** Where echoed lines go; defaults to the process's global `console`. */
|
|
14
14
|
export type LogConsole = Pick<Console, 'error' | 'info' | 'warn'>;
|
|
15
|
+
/**
|
|
16
|
+
* File logger (JSON lines) with an optional console echo. Both carry safe metadata only (see
|
|
17
|
+
* `serializeMessage`). A host that wants the full error injects `diagnostics`: it receives every
|
|
18
|
+
* call unchanged, after the file line; a throwing sink is recorded (class only) and never throws.
|
|
19
|
+
* @complexity O(projected meta, see `describeLogMeta`) per call plus one append.
|
|
20
|
+
*/
|
|
15
21
|
export declare function createFileLogger({ logPath }: {
|
|
16
22
|
logPath: string;
|
|
17
23
|
}, options?: {
|
|
18
24
|
echoToConsole?: boolean;
|
|
19
25
|
append?: LogAppend;
|
|
20
26
|
console?: LogConsole;
|
|
27
|
+
diagnostics?: LogDiagnosticsSink;
|
|
21
28
|
}): Logger;
|
|
22
29
|
/**
|
|
23
30
|
* Matches the known-harmless undici `setTypeOfService EINVAL` shape (see
|