-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
56 lines (48 loc) · 1.29 KB
/
Copy pathmain.go
File metadata and controls
56 lines (48 loc) · 1.29 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
package main
import (
"embed"
"os"
"path/filepath"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
// 单实例:已有实例在运行则把路径写入临时文件、唤醒其窗口后退出本进程。
// 必须先写文件再唤醒窗口:旧实例的轮询线程发现文件后发出 open-path 事件并跳转。
if !ensureSingleInstance() {
if len(os.Args) > 1 {
_ = os.WriteFile(filepath.Join(os.TempDir(), openPathFile), []byte(os.Args[1]), 0o644)
}
wakeExistingWindow()
return
}
// 记录启动参数(外部程序通过 %V 传入的文件夹路径 / CLSID)
if len(os.Args) > 1 {
startupArg = os.Args[1]
}
// Create an instance of the app structure
app := NewApp()
// Create application with options
err := wails.Run(&options.App{
Title: "文件管理器",
Width: 1280,
Height: 800,
MinWidth: 900,
MinHeight: 600,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 250, G: 250, B: 250, A: 1},
OnStartup: app.startup,
OnBeforeClose: app.beforeClose,
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}