代码拉取完成,页面将自动刷新
package main
import (
"context"
"github.com/energye/systray"
wailsrt "github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"os/exec"
"railapp/apputil"
"strings"
"syscall"
"time"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
systray.Run(a.systemTray, func() {
})
}
// ControllerAppList
func (a *App) ControllerAppList() []apputil.FileInfo {
return apputil.GetAppList(10 * time.Second)
}
// ControllerOpenApp
func (a *App) ControllerOpenApp(path, workSpace, workParams string) error {
return startAPP(path, workSpace, strings.Split(workParams, " ")...)
}
// StartAPP 启动应用
func startAPP(exePath, workDir string, params ...string) error {
if strings.HasSuffix(exePath, ".lnk") {
cmd := exec.Command("C:\\Windows\\System32\\cmd.exe", "/c", exePath)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
return cmd.Start()
}
cmd := exec.Command(exePath, params...) // nolint
cmd.Dir = workDir
return cmd.Start()
}
func (a *App) systemTray() {
systray.SetIcon([]byte("")) // read the icon from a file
show := systray.AddMenuItem("Show", "Show The Window")
systray.AddSeparator()
exit := systray.AddMenuItem("Exit", "Quit The Program")
show.Click(func() { wailsrt.WindowShow(a.ctx) })
exit.Click(func() { os.Exit(0) })
systray.SetOnClick(func(menu systray.IMenu) { wailsrt.WindowShow(a.ctx) })
systray.SetOnRClick(func(menu systray.IMenu) { menu.ShowMenu() })
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。