forked from rule110-io/surge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
188 lines (151 loc) · 3.79 KB
/
main.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
package main
import (
"os"
"log"
"github.com/leaanthony/mewn"
"github.com/rule110-io/surge-ui/surge"
"github.com/rule110-io/surge-ui/surge/platform"
"github.com/wailsapp/wails"
)
var wailsRuntime *wails.Runtime
var arguments []string
func getLocalFiles(Query string, OrderBy string, IsDesc bool, Skip int, Take int) surge.LocalFilePageResult {
return surge.SearchLocalFile(Query, OrderBy, IsDesc, Skip, Take)
}
func getRemoteFiles(Query string, OrderBy string, IsDesc bool, Skip int, Take int) surge.SearchQueryResult {
return surge.SearchRemoteFile(Query, OrderBy, IsDesc, Skip, Take)
}
func getPublicKey() string {
return surge.GetMyAddress()
}
func getFileChunkMap(Hash string, Size int) string {
if Size == 0 {
Size = 400
}
return surge.GetFileChunkMapStringByHash(Hash, Size)
}
func downloadFile(Hash string) bool {
return surge.DownloadFile(Hash)
}
func setDownloadPause(Hash string, State bool) {
surge.SetFilePause(Hash, State)
}
func openFile(Hash string) {
surge.OpenFileByHash(Hash)
}
func openLink(Link string) {
surge.OpenOSPath(Link)
}
func openLog() {
surge.OpenLogFile()
}
func openFolder(Hash string) {
surge.OpenFolderByHash(Hash)
}
//RemoteClientOnlineModel holds info of remote clients
type RemoteClientOnlineModel struct {
NumKnown int
NumOnline int
}
func seedFile() bool {
path := platform.OpenFileDialog()
if path == "" {
return false
}
return surge.SeedFile(path)
}
func removeFile(Hash string, FromDisk bool) bool {
return surge.RemoveFile(Hash, FromDisk)
}
func writeSetting(Key string, Value string) bool {
err := surge.DbWriteSetting(Key, Value)
return err != nil
}
func readSetting(Key string) string {
val, _ := surge.DbReadSetting(Key)
return val
}
func startDownloadMagnetLinks(Magnetlinks string) bool {
//need to parse Magnetlinks array and download all of them
go surge.ParsePayloadString(Magnetlinks)
return true
}
// Stats .
type Stats struct {
log *wails.CustomLogger
}
// WailsInit .
func (s *Stats) WailsInit(runtime *wails.Runtime) error {
s.log = runtime.Log.New("Stats")
go surge.WailsBind(runtime)
return nil
}
//WailsRuntime .
type WailsRuntime struct {
runtime *wails.Runtime
}
//WailsShutdown .
func (s *WailsRuntime) WailsShutdown() {
surge.Stop()
}
func main() {
defer surge.RecoverAndLog()
keepRunning := platform.ProcessStartupArgs(os.Args, &surge.FrontendReady)
if !keepRunning {
return
}
//surge.HashFile("C:\\Users\\mitch\\Downloads\\surge_remote\\surge-0.2.0-beta.windows.zip")
stats := &Stats{}
argsWithProg := os.Args
argsWithoutProg := os.Args[1:]
log.Println(argsWithProg)
log.Println(argsWithoutProg)
//invoked with a download
if len(argsWithoutProg) > 0 {
arguments = os.Args[1:]
}
//Initialize folder structures on os filesystem
newlyCreated, err := platform.InitializeFolders()
if err != nil {
log.Panic("Error on startup", err.Error())
}
surge.InitializeDb()
surge.InitializeLog()
defer surge.CloseDb()
if newlyCreated {
// seems like this is the first time starting the app
//set tour to active
surge.DbWriteSetting("Tour", "true")
//set default mode to light
surge.DbWriteSetting("DarkMode", "false")
}
surge.Start(arguments)
js := mewn.String("./frontend/dist/app.js")
css := mewn.String("./frontend/dist/app.css")
app := wails.CreateApp(&wails.AppConfig{
Width: 1144,
Height: 790,
Resizable: true,
Title: "Surge",
JS: js,
CSS: css,
Colour: "#131313",
})
app.Bind(stats)
app.Bind(getLocalFiles)
app.Bind(getRemoteFiles)
app.Bind(downloadFile)
app.Bind(setDownloadPause)
app.Bind(openFile)
app.Bind(openLink)
app.Bind(openLog)
app.Bind(openFolder)
app.Bind(getFileChunkMap)
app.Bind(seedFile)
app.Bind(removeFile)
app.Bind(writeSetting)
app.Bind(readSetting)
app.Bind(startDownloadMagnetLinks)
app.Bind(getPublicKey)
app.Run()
}