-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
105 lines (87 loc) · 2.25 KB
/
main.go
File metadata and controls
105 lines (87 loc) · 2.25 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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/dialog"
"github.com/mouuff/SmartCut/internal"
"github.com/mouuff/SmartCut/pkg/brain"
"github.com/mouuff/SmartCut/pkg/controller"
"github.com/mouuff/SmartCut/pkg/reader"
"github.com/mouuff/SmartCut/pkg/types"
"github.com/mouuff/SmartCut/pkg/utils"
"github.com/mouuff/SmartCut/pkg/view"
"golang.design/x/clipboard"
)
type SmartCutCmd struct {
flagSet *flag.FlagSet
config string
versionFlag bool
noUpdateFlag bool
}
// Init initializes the command
func (cmd *SmartCutCmd) Init(args []string) error {
cmd.flagSet = flag.NewFlagSet("smartcut", flag.ExitOnError)
cmd.flagSet.StringVar(&cmd.config, "config", "", "configuration file override")
cmd.flagSet.BoolVar(&cmd.versionFlag, "version", false, "prints the version and exit")
cmd.flagSet.BoolVar(&cmd.noUpdateFlag, "no-update", false, "disable automatic updates")
return cmd.flagSet.Parse(args)
}
// Run runs the command
func (cmd *SmartCutCmd) Run(a fyne.App, w fyne.Window) error {
config, err := utils.GetOrCreateConfiguration(cmd.config)
if err != nil {
return err
}
b, err := brain.NewOllamaBrain(config.HostUrl)
if err != nil {
return err
}
err = clipboard.Init()
if err != nil {
return err
}
// ir := reader.NewClipboardReader(ctx.Background())
ir := reader.NewShortcutReader()
ir.Start()
// MVC setup
m := types.NewSmartCutModel(config)
v := view.NewSmartCutView(w, m)
c := controller.NewSmartCutController(context.Background(), b, m, config)
// Setup View / Controller hooks
ir.OnInput = c.GenerateForInput
v.OnRequestGenerate = c.GenerateForInput
c.OnRequestFocus = v.RequestFocus
w.SetContent(v.Layout())
return nil
}
func main() {
cmd := &SmartCutCmd{}
err := cmd.Init(os.Args[1:])
if err != nil {
log.Fatal(err)
}
if cmd.versionFlag {
fmt.Println(internal.SmartCutVersion)
return
}
a := app.NewWithID("com.mouuff.smartcut")
w := a.NewWindow("SmartCut - " + internal.SmartCutVersion)
w.Resize(fyne.NewSize(800, 400))
err = cmd.Run(a, w)
if err != nil {
dialog.ShowError(err, w)
}
w.ShowAndRun()
if !cmd.noUpdateFlag {
u := internal.GetSmartCutUpdater()
err = u.SelfUpdate()
if err != nil {
log.Println(err)
}
}
}