feat(app): implement basic function
General - 配置界面支持配置对象存储桶 - 快捷键进入截图 - 一键上传截图 & 复制截图链接 MacOS - 状态栏指示器和应用图标
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/mac"
|
||||
|
||||
"github.com/mmmy/snapgo/internal/infrastructure/tray"
|
||||
)
|
||||
|
||||
//go:embed all:frontend/dist
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
app := NewApp()
|
||||
|
||||
// Wire up the menu-bar agent. Start() returns a `start` thunk that we
|
||||
// invoke from OnStartup so the icon appears AFTER Wails has spun up the
|
||||
// Cocoa runloop, and a `stop` thunk we call on shutdown.
|
||||
startTray, stopTray := tray.Start(tray.Callbacks{
|
||||
OnCapture: func() { app.CaptureNow() },
|
||||
OnSettings: func() { app.ShowWindow() },
|
||||
OnQuit: func() { app.QuitApp() },
|
||||
})
|
||||
|
||||
err := wails.Run(&options.App{
|
||||
Title: "SnapGo",
|
||||
Width: 900,
|
||||
Height: 640,
|
||||
MinWidth: 720,
|
||||
MinHeight: 520,
|
||||
AssetServer: &assetserver.Options{
|
||||
Assets: assets,
|
||||
},
|
||||
// Keep the standard macOS title bar for the Settings window. The
|
||||
// capture UI uses a separate native NSPanel on macOS, so the main
|
||||
// Wails window no longer needs to be frameless.
|
||||
Frameless: false,
|
||||
StartHidden: true,
|
||||
HideWindowOnClose: true,
|
||||
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 0},
|
||||
OnStartup: func(ctx context.Context) {
|
||||
app.startup(ctx)
|
||||
installActivationPolicyHooks()
|
||||
hideDockIcon()
|
||||
startTray()
|
||||
},
|
||||
OnBeforeClose: func(ctx context.Context) (prevent bool) {
|
||||
hideDockIcon()
|
||||
return false
|
||||
},
|
||||
OnShutdown: func(ctx context.Context) {
|
||||
stopTray()
|
||||
app.shutdown(ctx)
|
||||
},
|
||||
Bind: []interface{}{
|
||||
app,
|
||||
},
|
||||
Mac: &mac.Options{
|
||||
// The capture overlay is native AppKit on macOS; the Wails
|
||||
// Settings window should behave like a normal macOS window.
|
||||
WebviewIsTransparent: true,
|
||||
WindowIsTranslucent: true,
|
||||
About: &mac.AboutInfo{
|
||||
Title: "SnapGo",
|
||||
Message: "Cross-platform screenshot tool with one-click upload to S3.",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
println("Error:", err.Error())
|
||||
}
|
||||
|
||||
// Defensive: ensure the tray is torn down even if Wails exited via an
|
||||
// error path that bypassed OnShutdown.
|
||||
stopTray()
|
||||
}
|
||||
Reference in New Issue
Block a user