mirror of
https://github.com/ayflying/p2p.git
synced 2026-03-05 01:39:23 +00:00
增加更新重启逻辑
This commit is contained in:
11
internal/logic/os/linux.go
Normal file
11
internal/logic/os/linux.go
Normal file
@@ -0,0 +1,11 @@
|
||||
//go:build !windows
|
||||
|
||||
package os
|
||||
|
||||
func (s *sOS) start() {
|
||||
|
||||
}
|
||||
|
||||
func (s *sOS) update(version, server string) {
|
||||
|
||||
}
|
||||
45
internal/logic/os/os.go
Normal file
45
internal/logic/os/os.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"github.com/ayflying/p2p/internal/service"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
)
|
||||
|
||||
type systrayType struct {
|
||||
Icon string `json:"icon" dc:"图标"`
|
||||
Title string `json:"title" dc:"标题"`
|
||||
Tooltip string `json:"tooltip" dc:"提示"`
|
||||
}
|
||||
|
||||
type sOS struct {
|
||||
systray *systrayType
|
||||
}
|
||||
|
||||
func New() *sOS {
|
||||
return &sOS{
|
||||
systray: &systrayType{},
|
||||
}
|
||||
}
|
||||
func init() {
|
||||
service.RegisterOS(New())
|
||||
}
|
||||
|
||||
func (s *sOS) Load(title string, tooltip string, ico string) {
|
||||
if title == "" {
|
||||
title = gcmd.GetArg(0).String()
|
||||
}
|
||||
if tooltip == "" {
|
||||
tooltip = gcmd.GetArg(0).String()
|
||||
}
|
||||
|
||||
s.systray = &systrayType{
|
||||
Icon: ico,
|
||||
Title: title,
|
||||
Tooltip: tooltip,
|
||||
}
|
||||
s.start()
|
||||
}
|
||||
|
||||
func (s *sOS) Update(version, server string) {
|
||||
s.update(version, server)
|
||||
}
|
||||
64
internal/logic/os/windows.go
Normal file
64
internal/logic/os/windows.go
Normal file
@@ -0,0 +1,64 @@
|
||||
//go:build windows
|
||||
|
||||
package os
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
|
||||
"github.com/getlantern/systray"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
)
|
||||
|
||||
func (s *sOS) start() {
|
||||
|
||||
// 系统托盘初始化(设置图标、右键菜单)
|
||||
go systray.Run(s.onSystrayReady, s.onSystrayExit)
|
||||
}
|
||||
|
||||
// 系统托盘初始化(设置图标、右键菜单)
|
||||
func (s *sOS) onSystrayReady() {
|
||||
|
||||
iconByte := gfile.GetBytes(s.systray.Icon)
|
||||
systray.SetIcon(iconByte)
|
||||
systray.SetTitle(s.systray.Title)
|
||||
systray.SetTooltip(s.systray.Tooltip)
|
||||
|
||||
mQuit := systray.AddMenuItem("退出", "退出应用")
|
||||
systray.AddMenuItemCheckbox("隐藏窗口", "隐藏窗口", false)
|
||||
// Sets the icon of a menu item. Only available on Mac and Windows.
|
||||
//mQuit.SetIcon(iconByte)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-mQuit.ClickedCh:
|
||||
systray.Quit()
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
func (s *sOS) onSystrayExit() {
|
||||
// clean up here
|
||||
g.Log().Debugf(gctx.New(), "系统托盘退出")
|
||||
defer os.Exit(0)
|
||||
|
||||
}
|
||||
|
||||
func (s *sOS) update(version, server string) {
|
||||
updaterPath := gcmd.GetArg(0).String()
|
||||
// 启动更新器,传递主程序路径和当前版本作为参数
|
||||
cmd := exec.Command(updaterPath, version, server)
|
||||
// 将更新器与主程序的控制台分离
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: false} // Windows特定设置
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user