-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobal.go
211 lines (181 loc) · 5.09 KB
/
global.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package main
import (
"errors"
"fmt"
"log"
"math/rand"
"net/url"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"
"github.com/blevesearch/bleve"
"github.com/dustin/go-humanize"
"github.com/gen2brain/dlgs"
jsoniter "github.com/json-iterator/go"
"github.com/ledisdb/ledisdb/ledis"
"github.com/zserge/lorca"
)
type configGlobalStruct struct {
sourceFolder string
timeStart time.Time
execDir string
dataDir string
appInstalled bool
requestIndexing bool //необходимость запустить переиндексацию поиска
atStartCheckNewNotes bool
consoleControl bool
atStartShowConsole bool
postEditor string
cmdPort string
cmdPortable bool
appStartingMode string
appStartingModeForce bool
cmdServerMode bool
atStartOpenBrowser bool
accessLog bool
}
var configGlobal (configGlobalStruct)
var ConfigDB, NoteBookDB, NoteDB, TagsDB, FavoritesDB *ledis.DB //nolint:golint
type SearchService struct {
index bleve.Index
batch *bleve.Batch
}
var ss SearchService
var searchStatus struct {
Status string `json:"status"`
NotesTotal int `json:"notesTotal"`
NotesCurrent int `json:"notesCurrent"`
}
var optimizationStatus struct {
Status string `json:"status"`
NotesTotal int `json:"notesTotal"`
NotesCurrent int `json:"notesCurrent"`
}
type SearchContent struct {
UUID string `json:"uuid"`
Title string `json:"title"`
Cells []ContentCellsType `json:"cells"`
}
type SearchResult struct {
Title string `json:"title"`
UUID string `json:"uuid"`
NoteBookUUID string `json:"NoteBookUUID"`
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type NoteBookType struct {
UUID string
Name string
Notes map[string]int64
NotesCount int
}
type NoteBookTypeAPI struct {
UUID string `json:"uuid"`
Name string `json:"name"`
NotesCount int `json:"notesCount"`
}
type NoteType struct {
CreatedAt int32 `json:"created_at"`
UpdatedAt int32 `json:"updated_at"`
Tags []string `json:"tags"`
Title string `json:"title"`
UUID string `json:"uuid"`
URL string `json:"url_src"`
NoteBookUUID string
SearchIndex bool
}
type NoteTypeWithContentAPI struct {
CreatedAt int32 `json:"created_at"`
UpdatedAt int32 `json:"updated_at"`
Tags []string `json:"tags"`
Title string `json:"title"`
UUID string `json:"uuid"`
URL string `json:"url_src"`
NoteBookUUID string
SearchIndex bool
Content string `json:"content"`
ContentType string `json:"type"`
Favorites bool `json:"favorites"`
}
type NoteTypeAPI struct {
UpdatedAt int32 `json:"updated_at"`
Title string `json:"title"`
UUID string `json:"uuid"`
NoteBookUUID string `json:"NoteBookUUID"`
}
var NoteBook = make(map[string]NoteBookType)
var TagsCloud = make(map[string][]string)
type TagsListStruct struct {
Count int `json:"count"`
Name string `json:"name"`
URL string `json:"url"`
}
type ContentCellsType struct {
Type string `json:"type"`
Data string `json:"data"`
}
type FilesForIndexType struct {
Patch string
UUID string
}
var FilesForIndex = []FilesForIndexType{}
var systrayProcess *exec.Cmd
func RandStringBytes(n int) string {
const letterBytes = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func MemStat() {
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
//fmt.Printf("\nAlloc = %v\nTotalAlloc = %v\nSys = %v\nNumGC = %v\n\n", humanize.Bytes(mem.Alloc), humanize.Bytes(mem.TotalAlloc), humanize.Bytes(mem.Sys), mem.NumGC)
fmt.Printf("\nSystem memory usage: %v\n", humanize.Bytes(mem.Sys))
}
//https://www.codesd.com/item/golang-how-to-get-the-total-size-of-the-directory.html
func DirSize2(path string) (int64, error) {
var size int64
adjSize := func(_ string, info os.FileInfo, err error) error {
if !info.IsDir() {
size += info.Size()
}
return err
}
err := filepath.Walk(path, adjSize)
return size, err
}
// https://codereview.stackexchange.com/questions/60074/in-array-in-go
func inArray(val string, array []string) (exists bool) {
exists = false
for _, v := range array {
if val == v {
exists = true
return
}
}
return
}
func startStadaloneGUI() error {
// Create UI with basic HTML passed via data URI
ui, err := lorca.New("data:text/html,"+url.PathEscape(`<html><head><title>QVNote</title></head><body>Loading...</body></html>`), "", 1380, 768)
if err != nil {
message := "Can not start app in standalone mode (please install Google Chrome)"
showNotificationDialog(message)
log.Printf(message+": %v", err)
return errors.New("123")
}
defer ui.Close()
ui.Load("http://localhost:" + configGlobal.cmdPort + "")
// Wait until UI window is closed
<-ui.Done()
return nil
}
func showNotificationDialog(messageText string) {
if configGlobal.cmdServerMode {
return
}
dlgs.Warning("QVNote error!", messageText)
}