- Wails v2.16.0 + React 19 + TypeScript + Vite 7 - 插件系统(build tag 控制编译,plugin.json 运行时配置) - 支付插件(授权、账号、订单、退款、账单) - 高并发基础设施(任务池、批量处理器、限流器、环形缓冲、管道) - Windows 系统托盘(Win32 API) - CodeGraph 索引 + .memory 记忆包 - 默认图标 assets/icon.png
49 lines
842 B
Go
49 lines
842 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
)
|
|
|
|
// Instance 全局应用单例,持有 ctx 和托盘引用
|
|
type Instance struct {
|
|
mu sync.RWMutex
|
|
ctx context.Context
|
|
name string
|
|
}
|
|
|
|
// App 应用上下文入口
|
|
type App struct {
|
|
instance *Instance
|
|
}
|
|
|
|
var singleton *Instance
|
|
var once sync.Once
|
|
|
|
// Init 初始化应用全局上下文(只调用一次)
|
|
func Init() *App {
|
|
once.Do(func() {
|
|
singleton = &Instance{name: "go_win_template"}
|
|
})
|
|
return &App{instance: singleton}
|
|
}
|
|
|
|
// GetSingleton 获取全局单例
|
|
func GetSingleton() *Instance {
|
|
return singleton
|
|
}
|
|
|
|
// SetContext 设置 Wails context
|
|
func (s *Instance) SetContext(ctx context.Context) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.ctx = ctx
|
|
}
|
|
|
|
// Context 获取当前 context
|
|
func (s *Instance) Context() context.Context {
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
return s.ctx
|
|
}
|