@sonde/agent 0.2.6 → 0.2.7

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.
@@ -0,0 +1,112 @@
1
+ import { Box, Text, useInput } from 'ink';
2
+ import Spinner from 'ink-spinner';
3
+ import { useState } from 'react';
4
+ import { type ServiceResult, installService } from '../../cli/service.js';
5
+
6
+ interface StepServiceProps {
7
+ onNext: () => void;
8
+ }
9
+
10
+ type Phase = 'prompt' | 'installing' | 'done';
11
+
12
+ export function StepService({ onNext }: StepServiceProps): JSX.Element {
13
+ const [phase, setPhase] = useState<Phase>('prompt');
14
+ const [result, setResult] = useState<ServiceResult | null>(null);
15
+ const isLinux = process.platform === 'linux';
16
+
17
+ useInput((input, key) => {
18
+ if (!isLinux) {
19
+ if (key.return) onNext();
20
+ return;
21
+ }
22
+
23
+ if (phase === 'prompt') {
24
+ if (input === 'y' || input === 'Y' || key.return) {
25
+ setPhase('installing');
26
+ // Run async to let the spinner render
27
+ setTimeout(() => {
28
+ const res = installService();
29
+ setResult(res);
30
+ setPhase('done');
31
+ }, 0);
32
+ } else if (input === 'n' || input === 'N') {
33
+ setResult(null);
34
+ setPhase('done');
35
+ }
36
+ }
37
+
38
+ if (phase === 'done' && (key.return || input)) {
39
+ onNext();
40
+ }
41
+ });
42
+
43
+ if (!isLinux) {
44
+ return (
45
+ <Box flexDirection="column">
46
+ <Text bold>Systemd Service</Text>
47
+ <Box marginTop={1}>
48
+ <Text color="gray">Skipped — systemd services are only available on Linux.</Text>
49
+ </Box>
50
+ <Box marginTop={1}>
51
+ <Text color="gray">Press Enter to continue.</Text>
52
+ </Box>
53
+ </Box>
54
+ );
55
+ }
56
+
57
+ if (phase === 'installing') {
58
+ return (
59
+ <Box>
60
+ <Text color="cyan">
61
+ <Spinner type="dots" />
62
+ </Text>
63
+ <Text> Installing systemd service...</Text>
64
+ </Box>
65
+ );
66
+ }
67
+
68
+ if (phase === 'done') {
69
+ if (result === null) {
70
+ return (
71
+ <Box flexDirection="column">
72
+ <Text bold>Systemd Service</Text>
73
+ <Box marginTop={1}>
74
+ <Text color="gray">
75
+ Skipped. You can set this up later with:{' '}
76
+ <Text color="cyan">sonde service install</Text>
77
+ </Text>
78
+ </Box>
79
+ <Box marginTop={1}>
80
+ <Text color="gray">Press any key to continue.</Text>
81
+ </Box>
82
+ </Box>
83
+ );
84
+ }
85
+
86
+ return (
87
+ <Box flexDirection="column">
88
+ <Text bold>Systemd Service</Text>
89
+ <Box marginTop={1}>
90
+ <Text color={result.success ? 'green' : 'red'}>
91
+ {result.success ? ' OK' : ' !!'} {result.message}
92
+ </Text>
93
+ </Box>
94
+ <Box marginTop={1}>
95
+ <Text color="gray">Press any key to continue.</Text>
96
+ </Box>
97
+ </Box>
98
+ );
99
+ }
100
+
101
+ return (
102
+ <Box flexDirection="column">
103
+ <Text bold>Systemd Service</Text>
104
+ <Box marginTop={1}>
105
+ <Text>Set up sonde-agent as a systemd service? (starts on boot)</Text>
106
+ </Box>
107
+ <Box marginTop={1}>
108
+ <Text color="gray">y: install service | n: skip</Text>
109
+ </Box>
110
+ </Box>
111
+ );
112
+ }