Skip to content
Open
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
29 changes: 18 additions & 11 deletions internal/clipboard/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Clipboard struct {
LastText string
Mu sync.RWMutex
OutputText string
Disable bool
}

func NewClipboard() *Clipboard {
Expand All @@ -27,20 +28,26 @@ func NewClipboard() *Clipboard {

func (c *Clipboard) StartMonitoring() {
for {
c.Mu.Lock()
text, err := clipboard.ReadAll()
if err != nil || strings.TrimSpace(text) == "" {
switch {
case c.Disable:
time.Sleep(1 * time.Second)
default:
c.Mu.Lock()
text, err := clipboard.ReadAll()
if err != nil || strings.TrimSpace(text) == "" {
c.Mu.Unlock()
time.Sleep(100 * time.Millisecond) // Add a small delay to prevent tight looping
continue
}

if !isLikelyScreenshot(text) && text != c.LastText && text != c.OutputText {
c.LastText = text
c.Prompt <- text
}
c.Mu.Unlock()
time.Sleep(100 * time.Millisecond) // Add a small delay to prevent tight looping
continue
}

if !isLikelyScreenshot(text) && text != c.LastText && text != c.OutputText {
c.LastText = text
c.Prompt <- text
}
c.Mu.Unlock()
time.Sleep(100 * time.Millisecond) // Add a small delay to prevent tight looping
time.Sleep(100 * time.Millisecond)
}
}

Expand Down
2 changes: 2 additions & 0 deletions panes/inputPane.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func init() {
func StartClipboardMonitoring(app *tview.Application) {
clipboard.Clear()
clipboard := clipboard.NewClipboard()
ApplySystemNavConfig(app, clipboard)

var lastPublishedText string

go clipboard.StartMonitoring()
Expand Down
13 changes: 4 additions & 9 deletions panes/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ func CreateMainFlex(group1 *tview.Flex, keybindingsPane *tview.TextView) *tview.
}

func SetupMainUILayout(app *tview.Application) {
if app == nil {
StartClipboardMonitoring(nil)
ApplySystemNavConfig(nil)

select {}
} else {
StartClipboardMonitoring(app)
if app != nil {
group2 := CreateGroup2(HistoryPane, ModelList)
group4 := CreateGroup4(InputPane, PromptPane)
group3 := CreateGroup3(group4, OutputPane)
Expand Down Expand Up @@ -70,10 +66,9 @@ func SetupMainUILayout(app *tview.Application) {
app.SetRoot(mainFlex, true)
log.Println("Running app for main UI.")

StartClipboardMonitoring(app)
ApplySystemNavConfig(app)

err := app.Run()
checkNilErr(err)
} else {
select {}
}
}
21 changes: 19 additions & 2 deletions panes/sysNavPane.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import (
"os"
"os/signal"

"github.com/Codesmith28/lazyAi/internal/clipboard"
"github.com/getlantern/systray"
"github.com/rivo/tview"
)

//go:embed lazyAi.ico
var iconBytes []byte

func ApplySystemNavConfig(app *tview.Application) {
func ApplySystemNavConfig(app *tview.Application, clipboard *clipboard.Clipboard) {
onReady := func() {
systray.SetIcon(iconBytes)
systray.SetTitle("AI model is now on your clipboard!!")
systray.SetTooltip("Started!")

mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
stopMonitoring := systray.AddMenuItem("Pause", "Pause the clipboard monitoring")

go func() {
<-mQuit.ClickedCh
Expand All @@ -29,6 +31,22 @@ func ApplySystemNavConfig(app *tview.Application) {
systray.Quit()
}()

go func() {
for {
<-stopMonitoring.ClickedCh

if clipboard.Disable {
clipboard.Disable = false
stopMonitoring.SetTitle("Pause")
stopMonitoring.SetTooltip("Pause the clipboard monitoring")
} else {
clipboard.Disable = true
stopMonitoring.SetTitle("Resume")
stopMonitoring.SetTooltip("Resume the clipboard monitoring")
}
}
}()

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
Expand All @@ -46,5 +64,4 @@ func ApplySystemNavConfig(app *tview.Application) {
}

func onExit() {
// clean up here
}