add: notifier
This commit is contained in:
@@ -12,4 +12,6 @@ TODO
|
|||||||
- [x] 保存历史
|
- [x] 保存历史
|
||||||
- [x] 自动接收
|
- [x] 自动接收
|
||||||
- [ ] 传输加密
|
- [ ] 传输加密
|
||||||
- [ ] 单例模式
|
- [x] 单例模式
|
||||||
|
- [ ] icon
|
||||||
|
- [x] 通知
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/wailsapp/wails/v3/pkg/services/notifications"
|
||||||
)
|
)
|
||||||
|
|
||||||
// handleAsk 处理接收文件请求
|
// handleAsk 处理接收文件请求
|
||||||
@@ -48,6 +49,12 @@ func (s *Service) handleAsk(c *gin.Context) {
|
|||||||
Accepted: true,
|
Accepted: true,
|
||||||
SavePath: s.config.GetSavePath(),
|
SavePath: s.config.GetSavePath(),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_ = s.notifier.SendNotification(notifications.NotificationOptions{
|
||||||
|
ID: uuid.New().String(),
|
||||||
|
Title: "File Transfer Request",
|
||||||
|
Body: fmt.Sprintf("%s wants to transfer %s", task.Sender, task.FileName),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 等待用户决策或发送端放弃
|
// 等待用户决策或发送端放弃
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/wailsapp/wails/v3/pkg/application"
|
"github.com/wailsapp/wails/v3/pkg/application"
|
||||||
|
"github.com/wailsapp/wails/v3/pkg/services/notifications"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
|
notifier *notifications.NotificationService
|
||||||
app *application.App
|
app *application.App
|
||||||
port int
|
port int
|
||||||
|
|
||||||
@@ -28,11 +30,12 @@ type Service struct {
|
|||||||
cancelMap sync.Map
|
cancelMap sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(config *config.Config, app *application.App, port int, discoveryService *discovery.Service) *Service {
|
func NewService(config *config.Config, app *application.App, notifier *notifications.NotificationService, port int, discoveryService *discovery.Service) *Service {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
||||||
return &Service{
|
return &Service{
|
||||||
app: app,
|
app: app,
|
||||||
|
notifier: notifier,
|
||||||
port: port,
|
port: port,
|
||||||
discoveryService: discoveryService,
|
discoveryService: discoveryService,
|
||||||
config: config,
|
config: config,
|
||||||
|
|||||||
18
main.go
18
main.go
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/wailsapp/wails/v3/pkg/application"
|
"github.com/wailsapp/wails/v3/pkg/application"
|
||||||
"github.com/wailsapp/wails/v3/pkg/events"
|
"github.com/wailsapp/wails/v3/pkg/events"
|
||||||
|
"github.com/wailsapp/wails/v3/pkg/services/notifications"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed all:frontend/dist
|
//go:embed all:frontend/dist
|
||||||
@@ -28,6 +29,9 @@ func main() {
|
|||||||
Assets: application.AssetOptions{
|
Assets: application.AssetOptions{
|
||||||
Handler: application.AssetFileServerFS(assets),
|
Handler: application.AssetFileServerFS(assets),
|
||||||
},
|
},
|
||||||
|
SingleInstance: &application.SingleInstanceOptions{
|
||||||
|
UniqueID: "com.nite07.mesh-drop",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// 创建保存路径
|
// 创建保存路径
|
||||||
@@ -36,7 +40,16 @@ func main() {
|
|||||||
slog.Error("Failed to create save path", "path", conf.SavePath, "error", err)
|
slog.Error("Failed to create save path", "path", conf.SavePath, "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件传输端口
|
// 通知
|
||||||
|
notifier := notifications.New()
|
||||||
|
authorized, err := notifier.RequestNotificationAuthorization()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to request notification authorization", "error", err)
|
||||||
|
}
|
||||||
|
if !authorized {
|
||||||
|
slog.Error("Notification authorization not granted")
|
||||||
|
}
|
||||||
|
|
||||||
port := 9989
|
port := 9989
|
||||||
|
|
||||||
// 初始化发现服务
|
// 初始化发现服务
|
||||||
@@ -44,7 +57,7 @@ func main() {
|
|||||||
discoveryService.Start()
|
discoveryService.Start()
|
||||||
|
|
||||||
// 初始化传输服务
|
// 初始化传输服务
|
||||||
transferService := transfer.NewService(conf, app, port, discoveryService)
|
transferService := transfer.NewService(conf, app, notifier, port, discoveryService)
|
||||||
transferService.Start()
|
transferService.Start()
|
||||||
// 加载传输历史
|
// 加载传输历史
|
||||||
if conf.GetSaveHistory() {
|
if conf.GetSaveHistory() {
|
||||||
@@ -56,6 +69,7 @@ func main() {
|
|||||||
app.RegisterService(application.NewService(discoveryService))
|
app.RegisterService(application.NewService(discoveryService))
|
||||||
app.RegisterService(application.NewService(transferService))
|
app.RegisterService(application.NewService(transferService))
|
||||||
app.RegisterService(application.NewService(conf))
|
app.RegisterService(application.NewService(conf))
|
||||||
|
app.RegisterService(application.NewService(notifier))
|
||||||
|
|
||||||
window := app.Window.NewWithOptions(application.WebviewWindowOptions{
|
window := app.Window.NewWithOptions(application.WebviewWindowOptions{
|
||||||
Title: "mesh drop",
|
Title: "mesh drop",
|
||||||
|
|||||||
Reference in New Issue
Block a user