forked from wailsapp/wails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.go
89 lines (76 loc) · 2.03 KB
/
window.go
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
package runtime
import (
"bytes"
"runtime"
"github.com/abadojack/whatlanggo"
"github.com/wailsapp/wails/lib/interfaces"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/encoding/korean"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
func detectEncoding(text string) (encoding.Encoding, string) {
// korean
var enc encoding.Encoding
info := whatlanggo.Detect(text)
//fmt.Println("Language:", info.Lang.String(), " Script:", whatlanggo.Scripts[info.Script], " Confidence: ", info.Confidence)
switch info.Lang.String() {
case "Korean":
enc = korean.EUCKR
case "Mandarin":
enc = simplifiedchinese.GBK
case "Japanese":
enc = japanese.EUCJP
}
return enc, info.Lang.String()
}
// ProcessEncoding attempts to convert CKJ strings to UTF-8
func ProcessEncoding(text string) string {
if runtime.GOOS != "windows" {
return text
}
encoding, _ := detectEncoding(text)
if encoding != nil {
var bufs bytes.Buffer
wr := transform.NewWriter(&bufs, encoding.NewEncoder())
_, err := wr.Write([]byte(text))
defer wr.Close()
if err != nil {
return ""
}
return bufs.String()
}
return text
}
// Window exposes an interface for manipulating the window
type Window struct {
renderer interfaces.Renderer
}
// NewWindow creates a new Window struct
func NewWindow(renderer interfaces.Renderer) *Window {
return &Window{
renderer: renderer,
}
}
// SetColour sets the the window colour
func (r *Window) SetColour(colour string) error {
return r.renderer.SetColour(colour)
}
// Fullscreen makes the window fullscreen
func (r *Window) Fullscreen() {
r.renderer.Fullscreen()
}
// UnFullscreen attempts to restore the window to the size/position before fullscreen
func (r *Window) UnFullscreen() {
r.renderer.UnFullscreen()
}
// SetTitle sets the the window title
func (r *Window) SetTitle(title string) {
title = ProcessEncoding(title)
r.renderer.SetTitle(title)
}
// Close shuts down the window and therefore the app
func (r *Window) Close() {
r.renderer.Close()
}