-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
170 lines (146 loc) · 3.82 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
package main
import (
"embed"
"fmt"
"log"
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"syscall"
"time"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed build/appicon.png
var appIcon []byte
//go:embed wails.json
var wailsJSON []byte
var version string
var NeedsAdminPrivileges bool
var args []string
type FileLoader struct {
http.Handler
}
func NewFileLoader() *FileLoader {
return &FileLoader{}
}
func (h *FileLoader) ServeHTTP(res http.ResponseWriter, req *http.Request) {
var err error
requestedFilename := strings.TrimPrefix(filepath.Join(appFolder, req.URL.Path), "/")
println("Requesting file:", requestedFilename)
fileData, err := os.ReadFile(requestedFilename)
if err != nil {
res.WriteHeader(http.StatusBadRequest)
res.Write([]byte(fmt.Sprintf("Could not load file %s", requestedFilename)))
}
res.Write(fileData)
}
func main() {
// Create an instance of the app structure
app := NewApp()
// Config
err := config_init()
if err != nil {
log.Println(err)
}
// Logger
var fileLogger Logger
if *config.EnableLogging {
logsFolder, err = get_logs_folder()
if err != nil {
log.Println(err)
}
logFile := path.Join(logsFolder, time.Now().Format("2006-01-02_15-04-05")+".log")
fileLogger = NewLogger(logFile)
}
// Window State
windowsStateInt := *config.WindowStartState
windowState := options.Normal
switch windowsStateInt {
case 1:
windowState = options.Minimised
case 2:
windowState = options.Maximised
case 3:
windowState = options.Fullscreen
}
// Window Effect
windowEffectInt := *config.WindowEffect
windowEffect := windows.Auto
windowTransparent := true
switch windowEffectInt {
case 1:
windowEffect = windows.None
windowTransparent = false
case 2:
windowEffect = windows.Mica
case 3:
windowEffect = windows.Acrylic
case 4:
windowEffect = windows.Tabbed
}
// Create application with options
err = wails.Run(&options.App{
Title: "Iconium",
Width: 1280,
Height: 800,
MinWidth: 1024,
MinHeight: 768,
DisableResize: false,
Frameless: !*config.UseSystemTitleBar,
StartHidden: true,
HideWindowOnClose: false,
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 255},
AssetServer: &assetserver.Options{
Assets: assets,
Handler: NewFileLoader(),
},
Menu: nil,
Logger: fileLogger,
LogLevel: logger.TRACE,
LogLevelProduction: logger.TRACE,
OnStartup: app.startup,
OnDomReady: app.domReady,
OnBeforeClose: app.beforeClose,
OnShutdown: app.shutdown,
WindowStartState: windowState,
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: "4d1e7b7b-42a3-4357-92f3-425b1087b545",
OnSecondInstanceLaunch: app.onSecondInstanceLaunch,
},
Bind: []interface{}{
app,
},
// Windows platform specific options
Windows: &windows.Options{
WebviewIsTransparent: windowTransparent,
WindowIsTranslucent: windowTransparent,
DisableWindowIcon: false,
BackdropType: windowEffect,
// DisableFramelessWindowDecorations: false,
WebviewUserDataPath: path.Join(os.Getenv("APPDATA"), "iconium"),
ZoomFactor: 1.0,
DisablePinchZoom: true,
},
})
if err != nil {
log.Fatal(err)
}
}
func sendCommand(command ...string) (string, error) {
// Use `exec.Command` to send a command to the existing cmd window
cmd := exec.Command("cmd.exe", append([]string{"/C"}, command...)...)
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
output, err := cmd.Output()
return string(output), err
}