Skip to content

Commit e83cc37

Browse files
committed
init
1 parent fb8ebe8 commit e83cc37

File tree

8 files changed

+971
-0
lines changed

8 files changed

+971
-0
lines changed

cmd/water-maker/main.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"sync"
6+
"sync/atomic"
7+
8+
fyne "fyne.io/fyne/v2"
9+
"fyne.io/fyne/v2/app"
10+
"fyne.io/fyne/v2/container"
11+
"fyne.io/fyne/v2/data/binding"
12+
"fyne.io/fyne/v2/widget"
13+
14+
"fyne.io/fyne/v2/dialog"
15+
16+
data "github.com/sarumaj/water-maker/pkg/data"
17+
handler "github.com/sarumaj/water-maker/pkg/handler"
18+
)
19+
20+
func main() {
21+
h := handler.NewHandler()
22+
23+
myApp := app.NewWithID("com.github.sarumaj.domestic.water-maker")
24+
icon, err := data.Fs.ReadFile("images/icon.png")
25+
if err != nil {
26+
panic(err)
27+
}
28+
app.SetMetadata(
29+
fyne.AppMetadata{
30+
Name: "Watermaker",
31+
Build: 1,
32+
Version: "1.0.0",
33+
ID: myApp.Metadata().ID,
34+
Icon: fyne.NewStaticResource("icon", icon),
35+
},
36+
)
37+
38+
myWindow := myApp.NewWindow(myApp.Metadata().Name)
39+
myWindow.Resize(fyne.Size{Width: 800, Height: 600})
40+
myWindow.SetFixedSize(true)
41+
42+
resolver := func() {
43+
if err := recover(); err != nil {
44+
if val, ok := err.(error); ok {
45+
dialog.ShowError(val, myWindow)
46+
} else {
47+
dialog.ShowError(fmt.Errorf("%v", err), myWindow)
48+
}
49+
}
50+
}
51+
defer resolver()
52+
53+
progress := widget.NewProgressBar()
54+
progress.Resize(fyne.Size{Width: 390, Height: 60})
55+
progress.Move(fyne.Position{X: 390, Y: 10})
56+
57+
list := widget.NewListWithData(
58+
h.Messages,
59+
func() fyne.CanvasObject {
60+
return widget.NewLabel("template")
61+
},
62+
func(i binding.DataItem, o fyne.CanvasObject) {
63+
o.(*widget.Label).Bind(i.(binding.String))
64+
},
65+
)
66+
list.Resize(fyne.Size{Width: 780, Height: 510})
67+
list.Move(fyne.Position{X: 10, Y: 80})
68+
69+
SendMessage := func(msg string) {
70+
h.Log(msg)
71+
list.ScrollToBottom()
72+
}
73+
74+
browseBtn := widget.NewButton("browse", func() {
75+
defer resolver()
76+
dialog.ShowFolderOpen(h.Browse, myWindow)
77+
list.ScrollToBottom()
78+
})
79+
browseBtn.Resize(fyne.Size{Width: 180, Height: 60})
80+
browseBtn.Move(fyne.Position{X: 10, Y: 10})
81+
82+
startBtn := widget.NewButton("start", func() {
83+
defer resolver()
84+
if length := len(h.Files); length > 0 {
85+
wg := &sync.WaitGroup{}
86+
var cnt uint32
87+
for i, length := 0, len(h.Files); i < length; i++ {
88+
wg.Add(1)
89+
go func(i int, wg *sync.WaitGroup) {
90+
file := h.Files[i]
91+
SendMessage(fmt.Sprintf("Setting watermark on %s\n", file.Base))
92+
file.SetWatermark()
93+
SendMessage(fmt.Sprintf("Set watermark on %s\n", file.Base))
94+
progress.SetValue(float64(atomic.LoadUint32(&cnt)+1) / float64(length))
95+
atomic.AddUint32(&cnt, 1)
96+
wg.Done()
97+
}(i, wg)
98+
}
99+
wg.Wait()
100+
h.Clear()
101+
dialog.ShowInformation("Completed", "Done", myWindow)
102+
} else {
103+
dialog.ShowInformation("Nothing to do", "Select files first", myWindow)
104+
}
105+
})
106+
startBtn.Resize(fyne.Size{Width: 180, Height: 60})
107+
startBtn.Move(fyne.Position{X: 200, Y: 10})
108+
109+
myWindow.SetContent(
110+
container.NewWithoutLayout(
111+
browseBtn,
112+
startBtn,
113+
progress,
114+
list,
115+
),
116+
)
117+
118+
myWindow.ShowAndRun()
119+
}

go.mod

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module github.com/sarumaj/water-maker
2+
3+
go 1.18
4+
5+
require (
6+
fyne.io/fyne/v2 v2.2.3
7+
github.com/httpsOmkar/graphics-go v0.0.0-20191104103446-7a2f2ed96a63
8+
)
9+
10+
require (
11+
fyne.io/systray v1.10.1-0.20220621085403-9a2652634e93 // indirect
12+
github.com/davecgh/go-spew v1.1.1 // indirect
13+
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 // indirect
14+
github.com/fsnotify/fsnotify v1.5.4 // indirect
15+
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
16+
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
17+
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
18+
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
19+
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec // indirect
20+
github.com/godbus/dbus/v5 v5.1.0 // indirect
21+
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect
22+
github.com/gopherjs/gopherjs v1.17.2 // indirect
23+
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
24+
github.com/pmezard/go-difflib v1.0.0 // indirect
25+
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
26+
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect
27+
github.com/stretchr/testify v1.7.2 // indirect
28+
github.com/tevino/abool v1.2.0 // indirect
29+
github.com/yuin/goldmark v1.4.0 // indirect
30+
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd // indirect
31+
golang.org/x/mobile v0.0.0-20211207041440-4e6c2922fdee // indirect
32+
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
33+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
34+
golang.org/x/text v0.3.7 // indirect
35+
gopkg.in/yaml.v3 v3.0.1 // indirect
36+
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
37+
)

0 commit comments

Comments
 (0)