Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
andro404-MC committed May 13, 2024
1 parent 4c119a7 commit 536da6b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Quigo ![pass](https://github.com/andro404-MC/quigo-gui/actions/workflows/test.yml/badge.svg)
# Quigo ![pass](https://github.com/andro404-MC/quigo-gui/actions/workflows/test.yml/badge.svg) ![GitHub License](https://img.shields.io/github/license/andro404-MC/quigo) ![GitHub Release](https://img.shields.io/github/v/release/andro404-MC/quigo)

A simple Google Gemini prompt saver made using Go and [fyne](https://github.com/fyne-io/fyne/).

Expand Down
67 changes: 1 addition & 66 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,22 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"os"
"path/filepath"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"github.com/BurntSushi/toml"
"golang.design/x/clipboard"
)

type configSTR struct {
Apikey string
}

var (
config configSTR
prompts = map[string]string{
"Ask": "give the shortest respond MAX 50 words",
"Correct": "Correct the grammar of the following sentence without any extra text just pure correction",
}
)
var APIKEY string

const (
url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key="
configPath = "/.config/quigo/quigo.conf"
)

var APIKEY string

func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Quigo")
Expand Down Expand Up @@ -123,51 +106,3 @@ func handle(value string, prompt string) (respond string, err error, moreError e

return generatedText, nil, nil
}

func load(c *configSTR) {
homeDir, err := os.UserHomeDir()
if err != nil {
log.Println("Error getting user home directory:", err)
os.Exit(3)
}

fullPath := homeDir + configPath
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
c.Apikey = "GEMINI-PRO"
return
}

_, err = toml.DecodeFile(fullPath, &c)
if err != nil {
log.Println("Error:", err)
return
}

return
}

func save(c *configSTR) {
fileString := fmt.Sprintf("apikey = \"%s\"", c.Apikey)

homeDir, err := os.UserHomeDir()
if err != nil {
log.Println("Error getting user home directory:", err)
os.Exit(3)
}

fullPath := homeDir + configPath

dirPath := filepath.Dir(fullPath)
err = os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
fmt.Println("Error creating directory:", err)
return
}

err = os.WriteFile(fullPath, []byte(fileString), 0o644)
if err != nil {
fmt.Println("Error:", err)
return
}
return
}
47 changes: 43 additions & 4 deletions settingTab.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,60 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"golang.org/x/exp/maps"
)

func settingTab() *fyne.Container {
data := [][]string{
maps.Keys(prompts),

Check failure on line 12 in settingTab.go

View workflow job for this annotation

GitHub Actions / build

undefined: prompts
maps.Values(prompts),

Check failure on line 13 in settingTab.go

View workflow job for this annotation

GitHub Actions / build

undefined: prompts
}

apiLabel := widget.NewLabel("APIKEY")
apiInput := widget.NewPasswordEntry()
apiInput.Text = config.Apikey

Check failure on line 18 in settingTab.go

View workflow job for this annotation

GitHub Actions / build

undefined: config
apiInput.OnChanged = func(s string) { config.Apikey = s }

Check failure on line 19 in settingTab.go

View workflow job for this annotation

GitHub Actions / build

undefined: config
apiAplly := widget.NewButton("Save", func() { save(&config); load(&config) })

promptNameLabel := widget.NewLabel("Pormpt name")
promptNameInput := widget.NewEntry()
promptLabel := widget.NewLabel("Prompt")
promptInput := widget.NewEntry()
promptAdd := widget.NewButton("Add", nil)

promptTable := widget.NewTableWithHeaders(
func() (int, int) {
return len(data[0]), len(data)
},
func() fyne.CanvasObject {
return widget.NewLabel("wide content")
},
func(i widget.TableCellID, o fyne.CanvasObject) {
o.(*widget.Label).SetText(data[i.Col][i.Row])
},
)
promptTable.StickyColumnCount = 2
promptTable.ShowHeaderColumn = false

settingsAplly := widget.NewButton("Save", func() { save(&config); load(&config) })

setting := container.NewBorder(
container.NewBorder(nil, nil, apiLabel, nil, apiInput),
apiAplly,
nil,
container.NewVBox(
container.NewBorder(
nil,
nil,
apiLabel,
nil,
apiInput,
),
widget.NewSeparator(),
container.NewBorder(nil, nil, promptNameLabel, nil, promptNameInput),
container.NewBorder(nil, nil, promptLabel, nil, promptInput),
promptAdd,
),
settingsAplly,
nil,
nil,
promptTable,
)

return setting
Expand Down

0 comments on commit 536da6b

Please sign in to comment.