@nbtca/prompt 1.5.14 → 1.5.15
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/dist/app/chrome.js +7 -6
- package/dist/app/fields/list-field.js +7 -7
- package/dist/app/views/docs-render.js +1 -1
- package/dist/app/views/docs.js +10 -5
- package/dist/app/views/events-render.js +21 -8
- package/dist/app/views/events.js +52 -43
- package/dist/app/views/home.js +34 -37
- package/dist/app/views/schedule-render.js +63 -21
- package/dist/app/views/schedule.js +49 -6
- package/dist/app/views/settings.js +7 -4
- package/dist/auth/cookie-jar.js +206 -0
- package/dist/auth/cookie-transport.js +53 -29
- package/dist/auth/nbt-auth.js +10 -9
- package/dist/core/components/menu.js +44 -9
- package/dist/core/logo.js +37 -18
- package/dist/core/motion.js +23 -5
- package/dist/core/text.js +2 -2
- package/dist/core/theme.js +25 -9
- package/dist/features/calendar-query.js +39 -9
- package/dist/features/calendar.js +26 -22
- package/dist/features/docs.js +1 -1
- package/dist/features/links.js +16 -2
- package/dist/features/schedule-render.js +152 -69
- package/dist/features/schedule-view.js +19 -33
- package/dist/i18n/locales/en.json +33 -12
- package/dist/i18n/locales/zh.json +31 -10
- package/package.json +2 -6
package/dist/core/logo.js
CHANGED
|
@@ -29,15 +29,7 @@ function dotmatrixFile() {
|
|
|
29
29
|
return tier?.file ?? 'ca-dotmatrix-small.txt';
|
|
30
30
|
}
|
|
31
31
|
function paint(text, color) {
|
|
32
|
-
|
|
33
|
-
return text;
|
|
34
|
-
const fn = brand;
|
|
35
|
-
return typeof fn.multiline === 'function'
|
|
36
|
-
? fn.multiline(text)
|
|
37
|
-
: text
|
|
38
|
-
.split('\n')
|
|
39
|
-
.map((line) => brand(line))
|
|
40
|
-
.join('\n');
|
|
32
|
+
return color ? brand(text) : text;
|
|
41
33
|
}
|
|
42
34
|
function loadArt() {
|
|
43
35
|
const art = useUnicodeIcons() ? readArt(dotmatrixFile()) : readArt('ascii-logo.txt');
|
|
@@ -61,6 +53,31 @@ export function buildLogoLines() {
|
|
|
61
53
|
'',
|
|
62
54
|
];
|
|
63
55
|
}
|
|
56
|
+
function skipOnKeypress() {
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
const stdin = process.stdin;
|
|
59
|
+
if (!stdin.isTTY)
|
|
60
|
+
return { signal: controller.signal, release: () => undefined };
|
|
61
|
+
const onData = (chunk) => {
|
|
62
|
+
// Raw mode swallows SIGINT, so Ctrl+C has to exit by hand.
|
|
63
|
+
if (chunk.includes(0x03)) {
|
|
64
|
+
stdin.setRawMode(false);
|
|
65
|
+
process.exit(130);
|
|
66
|
+
}
|
|
67
|
+
controller.abort();
|
|
68
|
+
};
|
|
69
|
+
stdin.setRawMode(true);
|
|
70
|
+
stdin.on('data', onData);
|
|
71
|
+
stdin.resume();
|
|
72
|
+
return {
|
|
73
|
+
signal: controller.signal,
|
|
74
|
+
release() {
|
|
75
|
+
stdin.off('data', onData);
|
|
76
|
+
stdin.setRawMode(false);
|
|
77
|
+
stdin.pause();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
64
81
|
export async function runStartup() {
|
|
65
82
|
if (!process.stdout.isTTY)
|
|
66
83
|
return;
|
|
@@ -68,14 +85,16 @@ export async function runStartup() {
|
|
|
68
85
|
if (!startupFitsTerminal(process.stdout.rows, process.stdout.columns, art))
|
|
69
86
|
return;
|
|
70
87
|
const color = !process.env['NO_COLOR'];
|
|
88
|
+
const skip = skipOnKeypress();
|
|
71
89
|
process.stdout.write('\n');
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
color ? brand(TAGLINE) : TAGLINE,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
try {
|
|
91
|
+
await materializeBraille(art, (s) => paint(s, color), {
|
|
92
|
+
paintProgress: (s) => (color ? c.brand(s) : s),
|
|
93
|
+
signal: skip.signal,
|
|
94
|
+
});
|
|
95
|
+
await typeReveal(['', color ? brand(TAGLINE) : TAGLINE, chalk.dim(`@nbtca/prompt v${APP_INFO.version}`), ''], { signal: skip.signal });
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
skip.release();
|
|
99
|
+
}
|
|
81
100
|
}
|
package/dist/core/motion.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { getCapabilities } from './capabilities.js';
|
|
2
2
|
import { ansi } from './canvas.js';
|
|
3
3
|
const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
4
|
-
export function sleep(ms) {
|
|
5
|
-
return new Promise((resolve) =>
|
|
4
|
+
export function sleep(ms, signal) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
if (signal?.aborted) {
|
|
7
|
+
resolve();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const timer = setTimeout(done, ms);
|
|
11
|
+
signal?.addEventListener('abort', done, { once: true });
|
|
12
|
+
function done() {
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
signal?.removeEventListener('abort', done);
|
|
15
|
+
resolve();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
6
18
|
}
|
|
7
19
|
export async function typeReveal(lines, opts = {}) {
|
|
8
20
|
const write = opts.write ??
|
|
@@ -15,9 +27,13 @@ export async function typeReveal(lines, opts = {}) {
|
|
|
15
27
|
return;
|
|
16
28
|
}
|
|
17
29
|
const stepMs = opts.stepMs ?? 45;
|
|
18
|
-
for (const line of lines) {
|
|
30
|
+
for (const [index, line] of lines.entries()) {
|
|
31
|
+
if (opts.signal?.aborted) {
|
|
32
|
+
write(lines.slice(index).join('\n') + '\n');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
19
35
|
write(line + '\n');
|
|
20
|
-
await sleep(stepMs);
|
|
36
|
+
await sleep(stepMs, opts.signal);
|
|
21
37
|
}
|
|
22
38
|
}
|
|
23
39
|
const BRAILLE_BASE = 0x2800;
|
|
@@ -72,6 +88,8 @@ export async function materializeBraille(art, paint, opts = {}) {
|
|
|
72
88
|
const frameMs = opts.frameMs ?? 35;
|
|
73
89
|
let shown = 0;
|
|
74
90
|
for (let f = 1; f <= frameCount; f++) {
|
|
91
|
+
if (opts.signal?.aborted)
|
|
92
|
+
f = frameCount;
|
|
75
93
|
const target = Math.round((dots.length * f) / frameCount);
|
|
76
94
|
while (shown < target) {
|
|
77
95
|
const d = dots[shown];
|
|
@@ -86,7 +104,7 @@ export async function materializeBraille(art, paint, opts = {}) {
|
|
|
86
104
|
const painter = f === frameCount ? paint : (opts.paintProgress ?? paint);
|
|
87
105
|
write(painter(renderFrame()) + '\n');
|
|
88
106
|
if (f < frameCount) {
|
|
89
|
-
await sleep(frameMs);
|
|
107
|
+
await sleep(frameMs, opts.signal);
|
|
90
108
|
write(ansi.cursorUp(lines.length) + ansi.cursorToCol0 + ansi.eraseDown);
|
|
91
109
|
}
|
|
92
110
|
}
|
package/dist/core/text.js
CHANGED
|
@@ -69,12 +69,12 @@ export function padEndV(str, width) {
|
|
|
69
69
|
const pad = width - visualWidth(str);
|
|
70
70
|
return pad > 0 ? str + ' '.repeat(pad) : str;
|
|
71
71
|
}
|
|
72
|
-
export function truncate(str, maxWidth) {
|
|
72
|
+
export function truncate(str, maxWidth, ellipsis = '...') {
|
|
73
73
|
if (visualWidth(str) <= maxWidth)
|
|
74
74
|
return str;
|
|
75
75
|
if (maxWidth <= 0)
|
|
76
76
|
return '';
|
|
77
|
-
const marker =
|
|
77
|
+
const marker = visualWidth(ellipsis) <= maxWidth ? ellipsis : '.'.repeat(maxWidth);
|
|
78
78
|
const available = maxWidth - visualWidth(marker);
|
|
79
79
|
let w = 0;
|
|
80
80
|
let value = '';
|
package/dist/core/theme.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import gradient from 'gradient-string';
|
|
3
2
|
import { pickIcon } from './icons.js';
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
{
|
|
7
|
-
{
|
|
8
|
-
]
|
|
3
|
+
const BRAND_STOPS = [
|
|
4
|
+
{ at: 0, rgb: [0x12, 0x46, 0x89] },
|
|
5
|
+
{ at: 0.55, rgb: [0x0e, 0xa5, 0xe9] },
|
|
6
|
+
{ at: 1, rgb: [0x06, 0xb6, 0xd4] },
|
|
7
|
+
];
|
|
8
|
+
function brandColorAt(position) {
|
|
9
|
+
const upper = BRAND_STOPS.findIndex((stop) => stop.at >= position);
|
|
10
|
+
const to = BRAND_STOPS[Math.max(upper, 1)] ?? BRAND_STOPS[2];
|
|
11
|
+
const from = BRAND_STOPS[Math.max(upper, 1) - 1] ?? BRAND_STOPS[0];
|
|
12
|
+
const ratio = (position - from.at) / (to.at - from.at);
|
|
13
|
+
const mix = (index) => Math.round(from.rgb[index] + (to.rgb[index] - from.rgb[index]) * ratio);
|
|
14
|
+
return [mix(0), mix(1), mix(2)];
|
|
15
|
+
}
|
|
16
|
+
export function brandGradient(text) {
|
|
17
|
+
const lines = text.split('\n').map((line) => Array.from(line));
|
|
18
|
+
const span = Math.max(1, ...lines.map((line) => line.length - 1));
|
|
19
|
+
return lines
|
|
20
|
+
.map((line) => line
|
|
21
|
+
.map((char, column) => char.trim() ? chalk.rgb(...brandColorAt(Math.min(1, column / span)))(char) : char)
|
|
22
|
+
.join(''))
|
|
23
|
+
.join('\n');
|
|
24
|
+
}
|
|
9
25
|
export function brandMark(s) {
|
|
10
26
|
if (process.env['NO_COLOR'])
|
|
11
27
|
return s;
|
|
@@ -17,7 +33,7 @@ export const c = {
|
|
|
17
33
|
success: (s) => chalk.green(s),
|
|
18
34
|
error: (s) => chalk.red(s),
|
|
19
35
|
warn: (s) => chalk.yellow(s),
|
|
20
|
-
heading: (s) => chalk.bold
|
|
36
|
+
heading: (s) => chalk.bold(s),
|
|
21
37
|
muted: (s) => chalk.dim(s),
|
|
22
38
|
subtle: (s) => chalk.gray(s),
|
|
23
39
|
label: (s) => chalk.bold.cyan(s),
|
|
@@ -50,8 +66,8 @@ export const space = {
|
|
|
50
66
|
indent: ' ',
|
|
51
67
|
};
|
|
52
68
|
export const type = {
|
|
53
|
-
heading: (s) => chalk.bold
|
|
54
|
-
label: (s) =>
|
|
69
|
+
heading: (s) => chalk.bold(s),
|
|
70
|
+
label: (s) => s,
|
|
55
71
|
body: (s) => s,
|
|
56
72
|
hint: (s) => chalk.dim(s),
|
|
57
73
|
active: (s) => chalk.bold(c.brand(s)),
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { addLocalDays } from '../core/calendar-day.js';
|
|
2
|
+
import { fmt, t } from '../i18n/index.js';
|
|
1
3
|
const UPCOMING_DAYS = 30;
|
|
4
|
+
const YEAR_DAYS = 365;
|
|
2
5
|
export function weekRange(now) {
|
|
3
6
|
const start = new Date(now);
|
|
4
7
|
start.setHours(0, 0, 0, 0);
|
|
@@ -13,18 +16,37 @@ export function dayRange(now) {
|
|
|
13
16
|
const end = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
|
14
17
|
return { start, end };
|
|
15
18
|
}
|
|
19
|
+
export function eventEnd(event) {
|
|
20
|
+
return (event.end ??
|
|
21
|
+
(event.isAllDay
|
|
22
|
+
? new Date(event.start.getFullYear(), event.start.getMonth(), event.start.getDate() + 1)
|
|
23
|
+
: event.start));
|
|
24
|
+
}
|
|
25
|
+
function hasEnded(event, now) {
|
|
26
|
+
return event.start < now && eventEnd(event) <= now;
|
|
27
|
+
}
|
|
16
28
|
export function currentEvents(calendar, now) {
|
|
17
29
|
const { start } = dayRange(now);
|
|
18
30
|
const end = new Date(now.getTime() + UPCOMING_DAYS * 86_400_000);
|
|
19
|
-
return calendar.inRange(start, end).filter((event) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
return calendar.inRange(start, end).filter((event) => !hasEnded(event, now));
|
|
32
|
+
}
|
|
33
|
+
export function pastYearRange(now) {
|
|
34
|
+
return { start: addLocalDays(now, -YEAR_DAYS), end: now };
|
|
35
|
+
}
|
|
36
|
+
export function pastEvents(calendar, now) {
|
|
37
|
+
const { start, end } = pastYearRange(now);
|
|
38
|
+
return calendar
|
|
39
|
+
.inRange(start, end)
|
|
40
|
+
.filter((event) => hasEnded(event, now))
|
|
41
|
+
.reverse();
|
|
42
|
+
}
|
|
43
|
+
export function searchEvents(calendar, query, now) {
|
|
44
|
+
const pool = calendar.inRange(pastYearRange(now).start, addLocalDays(now, YEAR_DAYS));
|
|
45
|
+
const matches = filterEvents(pool, query);
|
|
46
|
+
return {
|
|
47
|
+
upcoming: matches.filter((event) => !hasEnded(event, now)),
|
|
48
|
+
past: matches.filter((event) => hasEnded(event, now)).reverse(),
|
|
49
|
+
};
|
|
28
50
|
}
|
|
29
51
|
export function monthRange(now) {
|
|
30
52
|
const start = new Date(now.getFullYear(), now.getMonth(), 1, 0, 0, 0, 0);
|
|
@@ -49,6 +71,14 @@ export function countdownParts(target, now) {
|
|
|
49
71
|
minutes: totalMin % 60,
|
|
50
72
|
};
|
|
51
73
|
}
|
|
74
|
+
export function formatDuration(p) {
|
|
75
|
+
const d = t().calendar.duration;
|
|
76
|
+
if (p.days > 0)
|
|
77
|
+
return fmt(d.days, { days: p.days, hours: p.hours });
|
|
78
|
+
if (p.hours > 0)
|
|
79
|
+
return fmt(d.hours, { hours: p.hours, minutes: p.minutes });
|
|
80
|
+
return fmt(d.minutes, { minutes: p.minutes });
|
|
81
|
+
}
|
|
52
82
|
/** True once a countdown is close enough to call out visually (default: 15
|
|
53
83
|
* minutes or less). A `past` countdown is never urgent — there's nothing
|
|
54
84
|
* left to hurry for. */
|
|
@@ -4,8 +4,8 @@ import { c, type, space, glyph } from '../core/theme.js';
|
|
|
4
4
|
import { pickIcon } from '../core/icons.js';
|
|
5
5
|
import { padEndV, sanitizeTerminalLine, sanitizeTerminalText, truncate, visualWidth, wrapAnsiWithIndent, wrapAnsiToVisualWidth, } from '../core/text.js';
|
|
6
6
|
import { t } from '../i18n/index.js';
|
|
7
|
-
import {
|
|
8
|
-
import { countdownParts, isCountdownUrgent, buildExportFilename } from './calendar-query.js';
|
|
7
|
+
import { localDayDifference } from '../core/calendar-day.js';
|
|
8
|
+
import { countdownParts, isCountdownUrgent, buildExportFilename, formatDuration, pastYearRange, } from './calendar-query.js';
|
|
9
9
|
import { loadFeedCache, saveFeedCache } from './calendar-store.js';
|
|
10
10
|
import { writeFileSync, existsSync } from 'fs';
|
|
11
11
|
import { join } from 'path';
|
|
@@ -88,7 +88,7 @@ export async function loadCalendarOrCache(signal) {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
export function yearHeatmap(calendar, now) {
|
|
91
|
-
return calendar.heatmap({
|
|
91
|
+
return calendar.heatmap({ ...pastYearRange(now), bucket: 'day' });
|
|
92
92
|
}
|
|
93
93
|
export function serializeEvents(events) {
|
|
94
94
|
return events.map((event) => ({
|
|
@@ -166,7 +166,22 @@ function styleTitle(title, style) {
|
|
|
166
166
|
return style(title);
|
|
167
167
|
return `${type.hint(match[1])}${match[2]}${style(title.slice(match[0].length))}`;
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
const TIME_COLUMN = ' 00:00'.length;
|
|
170
|
+
export function eventWhen(e) {
|
|
171
|
+
return e.time ? `${e.date} ${e.time}` : padEndV(e.date, visualWidth(e.date) + TIME_COLUMN);
|
|
172
|
+
}
|
|
173
|
+
export function recurringMark(e) {
|
|
174
|
+
return e.recurring ? ` ${pickIcon('↻', '~')}` : '';
|
|
175
|
+
}
|
|
176
|
+
function hangingLines(marker, content, cols) {
|
|
177
|
+
const width = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : Number.POSITIVE_INFINITY;
|
|
178
|
+
const prefixes = [`${space.indent}${marker} `, `${marker} `, marker, ''];
|
|
179
|
+
const prefix = prefixes.find((candidate) => visualWidth(candidate) < width) ?? '';
|
|
180
|
+
const continuation = ' '.repeat(visualWidth(prefix));
|
|
181
|
+
const contentWidth = Math.max(1, width - visualWidth(prefix));
|
|
182
|
+
return wrapAnsiToVisualWidth(content, contentWidth).map((line, index) => `${index === 0 ? prefix : continuation}${line}`);
|
|
183
|
+
}
|
|
184
|
+
export function renderEventBriefLines(e, now, cols = Number.POSITIVE_INFINITY) {
|
|
170
185
|
const dot = pickIcon('·', '-');
|
|
171
186
|
const proximity = eventProximity(e.startDate, now);
|
|
172
187
|
const dateStyle = proximity === 'today'
|
|
@@ -176,37 +191,26 @@ export function renderEventBrief(e, now) {
|
|
|
176
191
|
: proximity === 'week'
|
|
177
192
|
? type.body
|
|
178
193
|
: type.hint;
|
|
179
|
-
const dateTime = `${e.date}${e.time ? ' ' + e.time : ''}`;
|
|
180
194
|
const marker = proximity === 'today' ? type.active(pickIcon('●', '*')) : dateStyle(pickIcon('·', '-'));
|
|
181
195
|
const titleStyled = styleTitle(e.title, proximity === 'today' ? type.active : type.body);
|
|
182
|
-
const
|
|
183
|
-
return
|
|
196
|
+
const content = `${dateStyle(eventWhen(e))} ${type.hint(dot)} ${titleStyled}${type.hint(recurringMark(e))}`;
|
|
197
|
+
return hangingLines(marker, content, cols);
|
|
198
|
+
}
|
|
199
|
+
export function renderEventBrief(e, now) {
|
|
200
|
+
return renderEventBriefLines(e, now)[0] ?? '';
|
|
184
201
|
}
|
|
185
202
|
export function renderCountdownBanner(event, now, cols = Number.POSITIVE_INFINITY) {
|
|
186
203
|
if (!event)
|
|
187
204
|
return '';
|
|
188
205
|
const trans = t();
|
|
189
206
|
const p = countdownParts(event.startDate, now);
|
|
190
|
-
const inp = trans.calendar.inPrefix;
|
|
191
207
|
const when = p.past
|
|
192
208
|
? trans.calendar.startingNow
|
|
193
|
-
:
|
|
194
|
-
? `${inp} ${p.days}d ${p.hours}h`
|
|
195
|
-
: p.hours > 0
|
|
196
|
-
? `${inp} ${p.hours}h ${p.minutes}m`
|
|
197
|
-
: `${inp} ${p.minutes}m`;
|
|
209
|
+
: `${trans.calendar.inPrefix} ${formatDuration(p)}`;
|
|
198
210
|
const whenStyled = isCountdownUrgent(p) ? c.warn(when) : type.hint(when);
|
|
199
211
|
const dot = pickIcon('·', '-');
|
|
200
|
-
const width = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : Number.POSITIVE_INFINITY;
|
|
201
|
-
const cursor = type.active(glyph.cursor());
|
|
202
|
-
const prefixes = [`${space.indent}${cursor} `, `${cursor} `, cursor, ''];
|
|
203
|
-
const prefix = prefixes.find((candidate) => visualWidth(candidate) < width) ?? '';
|
|
204
|
-
const continuation = ' '.repeat(visualWidth(prefix));
|
|
205
|
-
const contentWidth = Math.max(1, width - visualWidth(prefix));
|
|
206
212
|
const content = `${type.label(trans.calendar.next)} ${dot} ${type.body(event.title)} ${dot} ${whenStyled}`;
|
|
207
|
-
return
|
|
208
|
-
.map((line, index) => `${index === 0 ? prefix : continuation}${line}`)
|
|
209
|
-
.join('\n');
|
|
213
|
+
return hangingLines(type.active(glyph.cursor()), content, cols).join('\n');
|
|
210
214
|
}
|
|
211
215
|
export function exportEventIcs(event, dir = process.cwd()) {
|
|
212
216
|
const base = buildExportFilename(event);
|
package/dist/features/docs.js
CHANGED
|
@@ -988,7 +988,7 @@ export async function showDocsMenu() {
|
|
|
988
988
|
title: trans.docs.chooseCategory,
|
|
989
989
|
options: [
|
|
990
990
|
...sections.map((sec) => ({ value: sec.key, label: sec.label })),
|
|
991
|
-
{ value: 'search', label: chalk.dim(trans.docs.searchPrompt
|
|
991
|
+
{ value: 'search', label: chalk.dim(trans.docs.searchPrompt) },
|
|
992
992
|
{ value: 'browser', label: chalk.dim(trans.docs.openBrowser) },
|
|
993
993
|
],
|
|
994
994
|
footer: menuFooter(),
|
package/dist/features/links.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
3
|
import { sanitizeTerminalLine } from '../core/text.js';
|
|
4
4
|
import { fmt, t } from '../i18n/index.js';
|
|
5
5
|
const BROWSER_LAUNCH_SETTLE_MS = 1000;
|
|
@@ -32,9 +32,23 @@ function settleBrowserLauncher(child) {
|
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
+
function browserCommand(url) {
|
|
36
|
+
if (process.platform === 'darwin')
|
|
37
|
+
return ['open', [url]];
|
|
38
|
+
// rundll32 takes the URL as one argument, so no shell ever parses it.
|
|
39
|
+
if (process.platform === 'win32' || process.env['WSL_DISTRO_NAME']) {
|
|
40
|
+
return ['rundll32.exe', ['url.dll,FileProtocolHandler', url]];
|
|
41
|
+
}
|
|
42
|
+
return ['xdg-open', [url]];
|
|
43
|
+
}
|
|
35
44
|
export async function launchBrowserUrl(url) {
|
|
45
|
+
if (!/^https?:\/\//i.test(url))
|
|
46
|
+
return false;
|
|
36
47
|
try {
|
|
37
|
-
|
|
48
|
+
const [command, args] = browserCommand(url);
|
|
49
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
50
|
+
child.unref();
|
|
51
|
+
return await settleBrowserLauncher(child);
|
|
38
52
|
}
|
|
39
53
|
catch {
|
|
40
54
|
return false;
|