1 Star 0 Fork 0

wuxia101/railapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.go 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
wuxia101 提交于 2024-07-16 11:55 . chore: init
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() })
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuxia101/railapp.git
[email protected]:wuxia101/railapp.git
wuxia101
railapp
railapp
main

搜索帮助