-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition.go
More file actions
87 lines (68 loc) · 1.76 KB
/
position.go
File metadata and controls
87 lines (68 loc) · 1.76 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
package devbrowser
import (
"errors"
"strconv"
"strings"
)
func (h *DevBrowser) BrowserPositionAndSizeChanged(fieldName string, oldValue, newValue string) error {
if !h.IsOpenFlag {
return nil
}
err := h.SetBrowserPositionAndSize(newValue)
if err != nil {
return err
}
return h.RestartBrowser()
}
func (b *DevBrowser) SetBrowserPositionAndSize(newConfig string) (err error) {
this := errors.New("setBrowserPositionAndSize")
position, width, height, err := getBrowserPositionAndSize(newConfig)
if err != nil {
return errors.Join(this, err)
}
b.Position = position
b.Width, err = strconv.Atoi(width)
if err != nil {
return errors.Join(this, err)
}
b.Height, err = strconv.Atoi(height)
if err != nil {
return errors.Join(this, err)
}
// Save the new configuration to db
if err := b.SaveConfig(); err != nil {
return errors.Join(this, err)
}
return
}
func getBrowserPositionAndSize(config string) (position, width, height string, err error) {
current := strings.Split(config, ":")
if len(current) != 2 {
err = errors.New("browse config must be in the format: 1930,0:800,600")
return
}
positions := strings.Split(current[0], ",")
if len(positions) != 2 {
err = errors.New("position must be with commas e.g.: 1930,0:800,600")
return
}
position = current[0]
sizes := strings.Split(current[1], ",")
if len(sizes) != 2 {
err = errors.New("width and height must be with commas e.g.: 1930,0:800,600")
return
}
widthInt, err := strconv.Atoi(sizes[0])
if err != nil {
err = errors.New("width must be an integer number")
return
}
width = strconv.Itoa(widthInt)
heightInt, err := strconv.Atoi(sizes[1])
if err != nil {
err = errors.New("height must be an integer number")
return
}
height = strconv.Itoa(heightInt)
return
}