-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathapp.go
More file actions
777 lines (681 loc) · 20.4 KB
/
Copy pathapp.go
File metadata and controls
777 lines (681 loc) · 20.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
package main
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"os"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/pkg/sftp"
"github.com/rymdport/portal/filechooser"
"github.com/rymdport/portal/settings"
"github.com/rymdport/portal/settings/appearance"
"github.com/wailsapp/wails/v2/pkg/runtime"
"golang.org/x/crypto/ssh"
"reManager/internal/component"
"reManager/internal/debug"
"reManager/internal/httputil"
"reManager/internal/logger"
"reManager/internal/platform"
"reManager/internal/storage"
"reManager/internal/vellum"
versionpkg "reManager/internal/version"
rmdevice "github.com/rmitchellscott/remarkable-go/device"
)
func resolveDialogDir(defaultDir string) string {
if defaultDir != "" {
if info, err := os.Stat(defaultDir); err == nil && info.IsDir() {
return defaultDir
}
}
home, _ := os.UserHomeDir()
return home
}
func openFileDialog(ctx context.Context, title, defaultDir string) (string, error) {
dir := resolveDialogDir(defaultDir)
if platform.IsRunningInFlatpak() {
files, err := filechooser.OpenFile("", title, &filechooser.OpenFileOptions{
CurrentFolder: dir,
})
debug.Println("[DEBUG] openFileDialog: files:", files, "err:", err)
if err != nil {
return "", err
}
if len(files) == 0 {
return "", nil
}
return strings.TrimPrefix(files[0], "file://"), nil
}
return runtime.OpenFileDialog(ctx, runtime.OpenDialogOptions{
Title: title,
DefaultDirectory: dir,
})
}
func openMultipleFilesDialog(ctx context.Context, title, defaultDir string) ([]string, error) {
dir := resolveDialogDir(defaultDir)
if platform.IsRunningInFlatpak() {
files, err := filechooser.OpenFile("", title, &filechooser.OpenFileOptions{
CurrentFolder: dir,
Multiple: true,
})
debug.Println("[DEBUG] openMultipleFilesDialog: files:", files, "err:", err)
if err != nil {
return nil, err
}
for i, f := range files {
files[i] = strings.TrimPrefix(f, "file://")
}
return files, nil
}
return runtime.OpenMultipleFilesDialog(ctx, runtime.OpenDialogOptions{
Title: title,
DefaultDirectory: dir,
})
}
func saveFileDialog(ctx context.Context, title, defaultFilename, defaultDir string) (string, error) {
dir := resolveDialogDir(defaultDir)
if platform.IsRunningInFlatpak() {
files, err := filechooser.SaveFile("", title, &filechooser.SaveFileOptions{
CurrentFolder: dir,
CurrentName: defaultFilename,
})
debug.Println("[DEBUG] saveFileDialog: files:", files, "err:", err)
if err != nil {
return "", err
}
if len(files) == 0 {
return "", nil
}
return strings.TrimPrefix(files[0], "file://"), nil
}
return runtime.SaveFileDialog(ctx, runtime.SaveDialogOptions{
Title: title,
DefaultFilename: defaultFilename,
DefaultDirectory: dir,
})
}
func openDirectoryDialog(ctx context.Context, title, defaultDir string) (string, error) {
dir := resolveDialogDir(defaultDir)
if platform.IsRunningInFlatpak() {
files, err := filechooser.OpenFile("", title, &filechooser.OpenFileOptions{
CurrentFolder: dir,
Directory: true,
})
debug.Println("[DEBUG] openDirectoryDialog: files:", files, "err:", err)
if err != nil {
return "", err
}
if len(files) == 0 {
return "", nil
}
return strings.TrimPrefix(files[0], "file://"), nil
}
return runtime.OpenDirectoryDialog(ctx, runtime.OpenDialogOptions{
Title: title,
DefaultDirectory: dir,
})
}
func sanitizeFilename(name string) string {
replacer := strings.NewReplacer("/", "_", "\\", "_", ":", "_", " ", "-", "<", "_", ">", "_", "\"", "_", "|", "_", "?", "_", "*", "_")
return replacer.Replace(name)
}
type App struct {
ctx context.Context
client *ssh.Client
session *ssh.Session
mu sync.Mutex
connectCancel context.CancelFunc
commandCancel context.CancelFunc
commandSession *ssh.Session
commandStdin io.WriteCloser
dialogResponse chan string
deviceStore *storage.DeviceStore
settingsStore *storage.SettingsStore
bundleStore *storage.BundleStore
deviceInfoCache *storage.DeviceInfoCacheStore
vellumClient *vellum.Client
metadata *vellum.MetadataStore
logger *logger.Logger
operationLog *logger.CommandLog
supportBundleID string
keepaliveStop chan struct{}
keepaliveTrigger chan struct{}
connectedDeviceID string
connectedDeviceType rmdevice.Type
connectedDeviceArch rmdevice.Architecture
connectedFirmware string
writeableRootBusy bool
reconnecting bool
reconnectMu sync.Mutex
fastDialMode bool
connGen atomic.Uint64
currentConn *connTarget
installCancelCh chan struct{}
cancelMu sync.Mutex
sessionMu sync.Mutex
osInstallCancelCh chan struct{}
installActive bool
installSession *installSession
backupCancelCh chan struct{}
backupMu sync.Mutex
transfers *transferManager
transferOnce sync.Once
roundTrip time.Duration
roundTripGen uint64
roundTripMu sync.Mutex
writableRootCount int
writableRootMu sync.Mutex
agentConn net.Conn
shellSession *ssh.Session
shellStdin io.WriteCloser
shellMu sync.Mutex
shellActive bool
preventSleepStop chan struct{}
penInputDevice string
}
func NewApp() *App {
return &App{}
}
func (a *App) getClient() *ssh.Client {
a.mu.Lock()
defer a.mu.Unlock()
return a.client
}
func (a *App) getSFTPClient() (*sftp.Client, error) {
client := a.getClient()
if client == nil {
return nil, fmt.Errorf("not connected")
}
sftpClient, err := sftp.NewClient(client)
if err != nil {
return nil, fmt.Errorf("failed to create SFTP client: %w", err)
}
return sftpClient, nil
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
configDir, err := storage.GetConfigDir()
if err == nil {
l, lerr := logger.New(configDir)
if lerr == nil {
a.logger = l
debug.SetFileLogger(l)
a.logger.LogEvent("APP", "reManager starting, version="+version)
go a.logger.CleanupOldCommandLogs(30 * 24 * time.Hour)
}
}
store, err := storage.NewDeviceStore()
if err != nil {
fmt.Printf("Warning: could not initialize device store: %v\n", err)
}
a.deviceStore = store
settingsStore, err := storage.NewSettingsStore()
if err != nil {
fmt.Printf("Warning: could not initialize settings store: %v\n", err)
}
a.settingsStore = settingsStore
bundleStore, err := storage.NewBundleStore()
if err != nil {
fmt.Printf("Warning: could not initialize bundle store: %v\n", err)
}
a.bundleStore = bundleStore
deviceInfoCache, err := storage.NewDeviceInfoCacheStore()
if err != nil {
fmt.Printf("Warning: could not initialize device info cache: %v\n", err)
}
a.deviceInfoCache = deviceInfoCache
a.metadata = vellum.NewMetadataStore()
go func() {
if err := a.metadata.Load(); err != nil {
debug.Printf("[DEBUG] Failed to load metadata: %v\n", err)
runtime.EventsEmit(a.ctx, "metadata:error", err.Error())
return
}
runtime.EventsEmit(a.ctx, "metadata:loaded")
}()
go func() {
settings.OnSignalSettingChanged(func(changed settings.Changed) {
if changed.Namespace == appearance.Namespace && changed.Key == "color-scheme" {
scheme, err := appearance.ValueToColorScheme(changed.Value)
if err == nil {
var themeName string
switch scheme {
case appearance.Dark:
themeName = "dark"
case appearance.Light:
themeName = "light"
default:
themeName = "unknown"
}
runtime.EventsEmit(a.ctx, "system-theme-changed", themeName)
}
}
})
}()
}
func (a *App) shutdown(ctx context.Context) {
if a.logger != nil {
a.logger.LogEvent("APP", "reManager shutting down")
}
a.Disconnect()
if a.logger != nil {
a.logger.Close()
}
}
type DialogActionRequest struct {
Id string `json:"id"`
Label string `json:"label"`
Type string `json:"type"`
Value string `json:"value"`
}
type DialogRequest struct {
Title string `json:"title"`
Message string `json:"message"`
Note string `json:"note"`
Steps []string `json:"steps"`
ConfirmText string `json:"confirmText"`
CancelText string `json:"cancelText"`
InProgressMessage string `json:"inProgressMessage"`
InfoOnly bool `json:"infoOnly"`
InstallFlow bool `json:"installFlow"`
Success bool `json:"success"`
PrimaryAction string `json:"primaryAction"`
Actions []DialogActionRequest `json:"actions"`
}
func dialogRequestFromConfig(cfg *component.DialogConfig) DialogRequest {
var actions []DialogActionRequest
for _, a := range cfg.Actions {
actions = append(actions, DialogActionRequest{
Id: a.Id,
Label: a.Label,
Type: a.Type,
Value: a.Value,
})
}
return DialogRequest{
Title: cfg.Title,
Message: cfg.Message,
Note: cfg.Note,
Steps: cfg.Steps,
ConfirmText: cfg.ConfirmText,
CancelText: cfg.CancelText,
InProgressMessage: cfg.InProgressMessage,
InfoOnly: cfg.InfoOnly,
InstallFlow: cfg.InstallFlow,
Success: cfg.Success,
PrimaryAction: cfg.PrimaryAction,
Actions: actions,
}
}
func (a *App) RespondToDialog(response string) {
if a.dialogResponse != nil {
a.dialogResponse <- response
}
}
func (a *App) CancelInstallation() {
a.cancelMu.Lock()
defer a.cancelMu.Unlock()
if a.installCancelCh != nil {
close(a.installCancelCh)
a.installCancelCh = nil
}
}
type wailsExecutor struct {
app *App
}
func (e *wailsExecutor) Execute(cmds []component.CommandResult) error {
var operationErr error
if e.app.logger != nil && len(cmds) > 0 {
name := cmds[0].Description
if name == "" {
name = "execute"
}
e.app.operationLog = e.app.logger.StartCommandLog(e.app.connectedDeviceID, name)
defer func() {
e.app.operationLog.WriteExitCode(operationErr)
e.app.operationLog.Close()
e.app.operationLog = nil
}()
}
for _, cmd := range cmds {
runtime.EventsEmit(e.app.ctx, "command:output", fmt.Sprintf("$ %s\n", cmd.Script))
done := make(chan bool, 1)
unsub := runtime.EventsOn(e.app.ctx, "command:done", func(optionalData ...interface{}) {
if len(optionalData) > 0 {
if success, ok := optionalData[0].(bool); ok {
done <- success
return
}
}
done <- false
})
e.app.RunCommandWithOutput(cmd.Script, cmd.RequiresPTY)
success := <-done
unsub()
if !success {
operationErr = fmt.Errorf("command failed: %s", cmd.Description)
return operationErr
}
}
return nil
}
func (e *wailsExecutor) ExecuteWithOutput(cmd string) (string, error) {
debug.Printf("[DEBUG] ExecuteWithOutput waiting for lock: %s\n", cmd[:min(50, len(cmd))])
e.app.mu.Lock()
debug.Printf("[DEBUG] ExecuteWithOutput got lock: %s\n", cmd[:min(50, len(cmd))])
defer func() {
e.app.mu.Unlock()
debug.Printf("[DEBUG] ExecuteWithOutput released lock: %s\n", cmd[:min(50, len(cmd))])
}()
return e.app.runCommand(cmd)
}
func (e *wailsExecutor) ExecuteStreaming(cmd string, onOutput func(line string)) error {
var cmdLog *logger.CommandLog
if e.app.logger != nil {
cmdLog = e.app.logger.StartCommandLog(e.app.connectedDeviceID, cmd)
}
defer cmdLog.Close()
e.app.mu.Lock()
if e.app.client == nil {
e.app.mu.Unlock()
return fmt.Errorf("not connected")
}
session, err := e.app.client.NewSession()
if err != nil {
e.app.mu.Unlock()
if isConnectionDeadError(err) {
go e.app.triggerConnectionCheck()
}
return err
}
e.app.mu.Unlock()
defer session.Close()
stdout, err := session.StdoutPipe()
if err != nil {
return err
}
stderr, err := session.StderrPipe()
if err != nil {
return err
}
if err := session.Start(cmd); err != nil {
return err
}
var wg sync.WaitGroup
wg.Add(2)
readLines := func(r io.Reader) {
defer wg.Done()
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := scanner.Text()
cmdLog.Write(line + "\n")
if onOutput != nil {
onOutput(line)
}
}
}
go readLines(stdout)
go readLines(stderr)
err = session.Wait()
wg.Wait()
cmdLog.WriteExitCode(err)
return err
}
func (a *App) GetAppVersion() string {
return version
}
type UpdateCheckResult struct {
UpdateAvailable bool `json:"updateAvailable"`
LatestVersion string `json:"latestVersion"`
CurrentVersion string `json:"currentVersion"`
ReleaseURL string `json:"releaseURL"`
Error string `json:"error,omitempty"`
}
func (a *App) CheckForAppUpdate() UpdateCheckResult {
result := UpdateCheckResult{
CurrentVersion: version,
}
if version == "dev" {
return result
}
if platform.IsRunningInFlatpak() {
return a.checkFlatpakUpdate(result)
}
return a.checkGitHubUpdate(result)
}
func (a *App) checkFlatpakUpdate(result UpdateCheckResult) UpdateCheckResult {
client := httputil.NewClient(10 * time.Second)
resp, err := client.Get("https://flathub.org/api/v2/appstream/io.scottlabs.reManager")
if err != nil {
debug.Printf("[DEBUG] checkFlatpakUpdate: request failed: %v\n", err)
result.Error = "network_error"
return result
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
debug.Printf("[DEBUG] checkFlatpakUpdate: HTTP %d\n", resp.StatusCode)
result.Error = "api_error"
return result
}
body, err := io.ReadAll(resp.Body)
if err != nil {
result.Error = "read_error"
return result
}
var appstream struct {
Releases []struct {
Version string `json:"version"`
Timestamp string `json:"timestamp"`
} `json:"releases"`
}
if err := json.Unmarshal(body, &appstream); err != nil {
result.Error = "parse_error"
return result
}
if len(appstream.Releases) == 0 {
result.Error = "no_releases"
return result
}
latest := appstream.Releases[0].Version
result.LatestVersion = latest
result.ReleaseURL = "https://flathub.org/apps/io.scottlabs.reManager"
result.UpdateAvailable = isNewerVersion(version, latest)
debug.Printf("[DEBUG] checkFlatpakUpdate: current=%s, latest=%s, updateAvailable=%v\n",
version, latest, result.UpdateAvailable)
return result
}
func (a *App) checkGitHubUpdate(result UpdateCheckResult) UpdateCheckResult {
client := httputil.NewClient(10 * time.Second)
resp, err := client.Get("https://api.github.com/repos/rmitchellscott/remanager/releases/latest")
if err != nil {
debug.Printf("[DEBUG] checkGitHubUpdate: request failed: %v\n", err)
result.Error = "network_error"
return result
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
debug.Printf("[DEBUG] checkGitHubUpdate: HTTP %d\n", resp.StatusCode)
result.Error = "api_error"
return result
}
var release struct {
TagName string `json:"tag_name"`
HTMLURL string `json:"html_url"`
}
body, err := io.ReadAll(resp.Body)
if err != nil {
result.Error = "read_error"
return result
}
if err := json.Unmarshal(body, &release); err != nil {
result.Error = "parse_error"
return result
}
result.LatestVersion = release.TagName
result.ReleaseURL = "https://remanager.io"
result.UpdateAvailable = isNewerVersion(version, release.TagName)
debug.Printf("[DEBUG] checkGitHubUpdate: current=%s, latest=%s, updateAvailable=%v\n",
version, release.TagName, result.UpdateAvailable)
return result
}
func isNewerVersion(current, latest string) bool {
return versionpkg.Compare(latest, current) > 0
}
type BehaviorSettings struct {
ProxyMode bool `json:"proxyMode"`
SuppressSystemFileWarnings bool `json:"suppressSystemFileWarnings"`
PreventSleep bool `json:"preventSleep"`
CheckForUpdates bool `json:"checkForUpdates"`
SuppressGuideOffer bool `json:"suppressGuideOffer"`
}
type SettingsInfo struct {
BehaviorSettings
TabVisibility map[string]bool `json:"tabVisibility"`
Theme string `json:"theme"`
TerminalTheme string `json:"terminalTheme"`
EditorTheme string `json:"editorTheme"`
SSHAgentSocketPath string `json:"sshAgentSocketPath"`
}
func (a *App) GetSettings() SettingsInfo {
if a.settingsStore == nil {
debug.Println("[DEBUG] GetSettings: settingsStore is nil")
return SettingsInfo{
BehaviorSettings: BehaviorSettings{
ProxyMode: true,
SuppressSystemFileWarnings: false,
PreventSleep: true,
CheckForUpdates: true,
},
TabVisibility: map[string]bool{"mods": true, "maintenance": true, "utilities": true},
Theme: "system",
TerminalTheme: "match",
EditorTheme: "match",
}
}
settings, err := a.settingsStore.Load()
if err != nil {
debug.Printf("[DEBUG] GetSettings: failed to load: %v\n", err)
return SettingsInfo{
BehaviorSettings: BehaviorSettings{
ProxyMode: true,
SuppressSystemFileWarnings: false,
PreventSleep: true,
CheckForUpdates: true,
},
TabVisibility: map[string]bool{"mods": true, "maintenance": true, "utilities": true},
Theme: "system",
TerminalTheme: "match",
EditorTheme: "match",
}
}
debug.Printf("[DEBUG] GetSettings: loaded PreventSleep=%v\n", settings.PreventSleep)
return SettingsInfo{
BehaviorSettings: BehaviorSettings{
ProxyMode: settings.ProxyMode,
SuppressSystemFileWarnings: settings.SuppressSystemFileWarnings,
PreventSleep: settings.PreventSleep,
CheckForUpdates: settings.CheckForUpdates,
SuppressGuideOffer: settings.SuppressGuideOffer,
},
TabVisibility: settings.TabVisibility,
Theme: settings.Theme,
TerminalTheme: settings.TerminalTheme,
EditorTheme: settings.EditorTheme,
SSHAgentSocketPath: settings.SSHAgentSocketPath,
}
}
func (a *App) SaveSettings(tabVisibility map[string]bool, proxyMode bool, suppressSystemFileWarnings bool, preventSleep bool, theme string, terminalTheme string, editorTheme string, checkForUpdates bool, sshAgentSocketPath string) error {
debug.Printf("[DEBUG] SaveSettings: preventSleep=%v, isConnected=%v\n", preventSleep, a.IsConnected())
if a.settingsStore == nil {
return fmt.Errorf("settings store not initialized")
}
existing, _ := a.settingsStore.Load()
var suppressGuideOffer bool
if existing != nil {
suppressGuideOffer = existing.SuppressGuideOffer
}
settings := &storage.Settings{
TabVisibility: storage.TabVisibility(tabVisibility),
ProxyMode: proxyMode,
SuppressSystemFileWarnings: suppressSystemFileWarnings,
PreventSleep: preventSleep,
Theme: theme,
TerminalTheme: terminalTheme,
EditorTheme: editorTheme,
CheckForUpdates: checkForUpdates,
SuppressGuideOffer: suppressGuideOffer,
SSHAgentSocketPath: sshAgentSocketPath,
}
if preventSleep && a.IsConnected() {
debug.Println("[DEBUG] SaveSettings: starting prevent sleep")
if err := a.StartPreventSleep(); err != nil {
debug.Printf("[DEBUG] SaveSettings: StartPreventSleep failed: %v\n", err)
}
} else {
debug.Println("[DEBUG] SaveSettings: stopping prevent sleep")
a.StopPreventSleep()
}
return a.settingsStore.Save(settings)
}
func (a *App) GetSystemColorScheme() string {
scheme, err := appearance.GetColorScheme()
if err != nil {
return "unknown"
}
switch scheme {
case appearance.Dark:
return "dark"
case appearance.Light:
return "light"
default:
return "unknown"
}
}
func (a *App) UninstallVellum(removeAllPackages bool) {
go func() {
if a.vellumClient == nil {
runtime.EventsEmit(a.ctx, "vellum:uninstall-error", "Not connected")
return
}
runtime.EventsEmit(a.ctx, "vellum:uninstall-start")
err := a.vellumClient.UninstallVellum(removeAllPackages, func(line string) {
runtime.EventsEmit(a.ctx, "vellum:uninstall-output", line)
})
if err != nil {
runtime.EventsEmit(a.ctx, "vellum:uninstall-error", err.Error())
return
}
a.vellumClient = nil
runtime.EventsEmit(a.ctx, "vellum:uninstall-complete")
}()
}
func (a *App) CleanupBrokenVellum() {
go func() {
client := a.getClient()
if client == nil {
runtime.EventsEmit(a.ctx, "vellum:cleanup-error", "Not connected")
return
}
runtime.EventsEmit(a.ctx, "vellum:cleanup-start")
session, err := client.NewSession()
if err != nil {
runtime.EventsEmit(a.ctx, "vellum:cleanup-error", err.Error())
return
}
err = session.Run("rm -rf " + vellum.VellumRoot)
session.Close()
if err != nil {
runtime.EventsEmit(a.ctx, "vellum:cleanup-error", err.Error())
return
}
a.vellumClient = nil
runtime.EventsEmit(a.ctx, "vellum:cleanup-complete")
runtime.EventsEmit(a.ctx, "vellum:bootstrap-prompt", nil)
}()
}