Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ func (a *App) initializeMenu() {

// View menu
ViewMenu := AppMenu.AddSubmenu("View")
ViewMenu.AddText("Sync Scroll Position", keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey), func(cd *menu.CallbackData) {})
ViewMenu.AddText("Sync Scroll Position", keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey), func(cd *menu.CallbackData) {
runtime.EventsEmit(a.ctx, string(entities.ActionToggleSyncScrollPosition))
})

// Scan menu
ScanMenu := AppMenu.AddSubmenu("Scan")
Expand Down
8 changes: 4 additions & 4 deletions backend/entities/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
ActionReplaceComponentWithComments Action = "replaceComponentWithComments"

// View
ActionSyncScrollPosition Action = "toggleSyncScrollPosition"
ActionToggleSyncScrollPosition Action = "toggleSyncScrollPosition"
ActionShowKeyboardShortcutsModal Action = "showKeyboardShortcutsModal"

// Scan
Expand Down Expand Up @@ -105,7 +105,7 @@ var AllShortcutActions = []struct {
{ActionReplaceFileWithComments, "ReplaceFileWithComments"},
{ActionReplaceComponentWithoutComments, "ReplaceComponentWithoutComments"},
{ActionReplaceComponentWithComments, "ReplaceComponentWithComments"},
{ActionSyncScrollPosition, "ToggleSyncScrollPosition"},
{ActionToggleSyncScrollPosition, "ToggleSyncScrollPosition"},
{ActionShowKeyboardShortcutsModal, "ShowKeyboardShortcutsModal"},
{ActionScanWithOptions, "ScanWithOptions"},
}
Expand Down Expand Up @@ -296,8 +296,8 @@ var DefaultShortcuts = []Shortcut{
Description: "Sync the scroll position of the editors",
Accelerator: keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey),
Keys: "shift+mod+e",
Group: GroupActions,
Action: ActionReplaceComponentWithComments,
Group: GroupView,
Action: ActionToggleSyncScrollPosition,
},

// Scan
Expand Down
122 changes: 122 additions & 0 deletions backend/entities/mocks/mock_FileWatcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions backend/entities/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ var (
)

type Result struct {
Path string `json:"path"`
MatchType string `json:"match_type"`
Purl *[]string `json:"purl,omitempty"`
ComponentName string `json:"component"`
Matches []Match `json:"matches,omitempty"`
Path string `json:"path"`
MatchType string `json:"match_type"`
Purl *[]string `json:"purl,omitempty"`
ComponentName string `json:"component"`
Matches []Component `json:"matches,omitempty"`
}

func NewResult() *Result {
Expand Down Expand Up @@ -96,14 +96,6 @@ type ResultLicense struct {
URL string `json:"url,omitempty"`
}

type Match struct {
ID string `json:"id"`
Purl []string `json:"purl,omitempty"`
ComponentName string `json:"component"`
Matched string `json:"matched,omitempty"`
Licenses []ResultLicense `json:"licenses,omitempty"`
}

type MatchType string

const (
Expand Down
61 changes: 61 additions & 0 deletions backend/entities/watcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package entities

import (
"github.com/fsnotify/fsnotify"
"github.com/rs/zerolog/log"
)

type FileWatcher interface {
Start() error
Close() error
}

type fsNotifyWatcher struct {
watcher *fsnotify.Watcher
path string
onFileChange func()
}

func NewFsNotifyWatcher(path string, onFileChange func()) (FileWatcher, error) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
return &fsNotifyWatcher{
watcher: watcher,
path: path,
onFileChange: onFileChange,
}, nil
}

func (w *fsNotifyWatcher) Start() error {
if err := w.watcher.Add(w.path); err != nil {
log.Error().Err(err).Msgf("Error watching file: %s", w.path)
return w.Close()
}

go func() {
for {
select {
case event, ok := <-w.watcher.Events:
if !ok {
return
}
if event.Op&fsnotify.Write == fsnotify.Write {
w.onFileChange()
}
case err, ok := <-w.watcher.Errors:
if !ok {
return
}
log.Error().Err(err).Msg("Watcher error")
}
}
}()

return nil
}

func (w *fsNotifyWatcher) Close() error {
return w.watcher.Close()
}
Loading
Loading