-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
71 lines (60 loc) · 1.72 KB
/
app.go
File metadata and controls
71 lines (60 loc) · 1.72 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
package main
import (
"context"
"socket-share/internal/discovery"
"socket-share/internal/registry"
fs "socket-share/internal/share"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
dm *discovery.DiscoveryModule
fr *registry.FileRegistry
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{
dm: discovery.NewDiscoveryModule(),
fr: registry.NewFileRegistry(),
}
}
// startup is called at application startup
func (app *App) startup(ctx context.Context) {
app.ctx = ctx
go fs.StartFileServer()
go app.fr.SyncRead(app.ctx)
app.dm.Start(app.ctx)
}
// OpenFilePicker will open the native file explorer with all file type.
func (app *App) OpenFilePicker() (string, error) {
return runtime.OpenFileDialog(app.ctx, runtime.OpenDialogOptions{
Title: "Select File",
Filters: []runtime.FileFilter{
{
DisplayName: "All Files (*.*)",
Pattern: "*.*",
},
},
})
}
func (app *App) CreateNewFile(path string) registry.File {
return app.fr.NewFile(path)
}
func (app *App) DownloadFile(ip, path string) {
fs.StartFileClient(ip, path)
}
// domReady is called after front-end resources have been loaded
// func (app App) domReady(ctx context.Context) {
// // Add your action here
// }
// beforeClose is called when the application is about to quit,
// either by clicking the window close button or calling runtime.Quit.
// Returning true will cause the application to continue, false will continue shutdown as normal.
// func (app *App) beforeClose(ctx context.Context) (prevent bool) {
// return false
// }
// shutdown is called at application termination
// func (app *App) shutdown(ctx context.Context) {
// // Perform your teardown here
// }