Skip to content

Commit

Permalink
Release v1.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayideyia committed Sep 17, 2024
1 parent dfe5f94 commit f68adeb
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 98 deletions.
12 changes: 3 additions & 9 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

sysruntime "runtime"

"github.com/klauspost/cpuid/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/runtime"
"gopkg.in/yaml.v3"
)

Expand All @@ -26,8 +24,8 @@ var isStartup = true
var Env = &EnvResult{
BasePath: "",
AppName: "",
OS: sysruntime.GOOS,
ARCH: sysruntime.GOARCH,
OS: runtime.GOOS,
ARCH: runtime.GOARCH,
X64Level: cpuid.CPU.X64Level(),
FromTaskSch: false,
}
Expand Down Expand Up @@ -126,7 +124,3 @@ func (a *App) GetInterfaces() FlagResult {

return FlagResult{true, strings.Join(interfaceNames, "|")}
}

func (a *App) ShowMainWindow() {
runtime.WindowShow(a.Ctx)
}
40 changes: 18 additions & 22 deletions bridge/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bridge

import (
"bufio"
"fmt"
"errors"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -140,34 +140,30 @@ func (a *App) KillProcess(pid int) FlagResult {
return FlagResult{false, err.Error()}
}

waitForProcessWithTimeOut(process, 10)
err = waitForProcessExitWithTimeout(process, 15)
if err != nil {
return FlagResult{false, err.Error()}
}

return FlagResult{true, "Success"}
}

func waitForProcessWithTimeOut(process *os.Process, maxWaitSeconds int64) {
done := make(chan struct {
state *os.ProcessState
err error
})

// 无限等等进程结束
func waitForProcessExitWithTimeout(process *os.Process, timeoutSeconds int64) error {
done := make(chan error, 1)
go func() {
state, err := process.Wait()
done <- struct {
state *os.ProcessState
err error
}{state, err}
_, err := process.Wait()
done <- err
}()

select {
case <-time.After(time.Second * time.Duration(maxWaitSeconds)):
// 这里错误没有处理,在*nix系统-9信号不能被程序捕获。而windows如果程序被保护,可能无法结束,大多数情况也能正常结束。
_ = process.Kill()
case result := <-done:
if result.err != nil {
fmt.Println("Command finished with error:", result.err)
} else {
fmt.Println("Command finished successfully with state:", result.state)
case err := <-done:
if err != nil {
return err
}
case <-time.After(time.Duration(timeoutSeconds) * time.Second):
process.Kill()
return errors.New("timeout waiting for process to exit")
}

return nil
}
21 changes: 21 additions & 0 deletions bridge/tray_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build darwin

package bridge

import (
"embed"
"os"

"github.com/wailsapp/wails/v2/pkg/runtime"
)

func InitTray(a *App, icon []byte, fs embed.FS) {}

func (a *App) UpdateTray(tray TrayContent) {}

func (a *App) UpdateTrayMenus(menus []MenuItem) {}

func (a *App) ExitApp() {
runtime.Quit(a.Ctx)
os.Exit(0)
}
17 changes: 4 additions & 13 deletions bridge/tray_others.go → bridge/tray_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build windows || darwin
//go:build windows

package bridge

Expand Down Expand Up @@ -37,27 +37,19 @@ func InitTray(a *App, icon []byte, fs embed.FS) {
}
}

isDarwin := Env.OS == "darwin"

go func() {
sysruntime.LockOSThread()
defer sysruntime.UnlockOSThread()
systray.Run(func() {
systray.SetIcon([]byte(icon))
systray.SetTitle("GUI.for.Cores")
systray.SetTooltip("GUI.for.Cores")
systray.SetOnClick(func(menu systray.IMenu) { runtime.WindowShow(a.Ctx) })
systray.SetOnRClick(func(menu systray.IMenu) { menu.ShowMenu() })
if isDarwin {
systray.SetOnClick(func(menu systray.IMenu) { menu.ShowMenu() })
} else {
systray.SetTitle("GUI.for.Cores")
systray.SetOnClick(func(menu systray.IMenu) { a.ShowMainWindow() })
}

// Ensure the tray is still available if rolling-release fails
mShowWindow := systray.AddMenuItem("Show Main Window", "Show Main Window")
mRestart := systray.AddMenuItem("Restart", "Restart")
mExit := systray.AddMenuItem("Exit", "Exit")
mShowWindow.Click(func() { a.ShowMainWindow() })
mRestart.Click(func() { a.RestartApp() })
mExit.Click(func() { a.ExitApp() })
}, nil)
Expand Down Expand Up @@ -86,8 +78,7 @@ func createMenuItem(menu MenuItem, a *App, parent *systray.MenuItem) {
} else {
m = parent.AddSubMenuItem(menu.Text, menu.Tooltip)
}

m.Click(func() { go runtime.EventsEmit(a.Ctx, menu.Event) })
m.Click(func() { runtime.EventsEmit(a.Ctx, menu.Event) })

if menu.Checked {
m.Check()
Expand Down
2 changes: 1 addition & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VITE_APP_TITLE = GUI.for.SingBox
VITE_APP_VERSION = v1.8.4
VITE_APP_VERSION = v1.8.5
VITE_APP_PROJECT_URL = https://github.com/GUI-for-Cores/GUI.for.SingBox
VITE_APP_VERSION_API = https://api.github.com/repos/GUI-for-Cores/GUI.for.SingBox/releases/latest
VITE_APP_TG_GROUP = https://t.me/GUI_for_Cores
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/bridge/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export const RestartApp = App.RestartApp

export const ExitApp = App.ExitApp

export const ShowMainWindow = App.ShowMainWindow

export const UpdateTray = async (tray: TrayContent) => {
const { icon = '', title = '', tooltip = '' } = tray
await App.UpdateTray({ icon, title, tooltip })
Expand Down
1 change: 0 additions & 1 deletion frontend/src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ export default {
fallback: '🐟 Fallback'
},
tray: {
showMainWindow: 'Show Main Window',
restart: 'Restart',
restartTip: 'Restart App',
exit: 'Exit',
Expand Down
1 change: 0 additions & 1 deletion frontend/src/lang/locale/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ export default {
fallback: '🐟 漏网之鱼'
},
tray: {
showMainWindow: '显示主窗口',
restart: '重启',
restartTip: '重启程序',
exit: '退出',
Expand Down
25 changes: 2 additions & 23 deletions frontend/src/utils/tray.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import i18n from '@/lang'
import { Theme, type MenuItem, Color, Lang } from '@/constant'
import { useAppSettingsStore, useKernelApiStore, useEnvStore, usePluginsStore } from '@/stores'
import {
Notify,
RestartApp,
EventsOn,
EventsOff,
UpdateTray,
UpdateTrayMenus,
ShowMainWindow
} from '@/bridge'
import { Notify, RestartApp, EventsOn, EventsOff, UpdateTray, UpdateTrayMenus } from '@/bridge'
import {
debounce,
exitApp,
Expand Down Expand Up @@ -153,16 +145,6 @@ const getTrayMenus = () => {
}

const trayMenus: MenuItem[] = [
{
type: 'item',
text: 'tray.showMainWindow',
hidden: envStore.env.os !== 'darwin',
event: ShowMainWindow
},
{
type: 'separator',
hidden: envStore.env.os !== 'darwin',
},
{
type: 'item',
text: 'kernel.mode',
Expand Down Expand Up @@ -388,9 +370,6 @@ export const updateTrayMenus = debounce(async () => {
const trayMenus = getTrayMenus()
const trayIcons = getTrayIcons()

const isDarwin = useEnvStore().env.os === 'darwin'
const title = isDarwin ? '' : APP_TITLE

await UpdateTray({ icon: trayIcons, title, tooltip: APP_TITLE + ' ' + APP_VERSION })
await UpdateTray({ icon: trayIcons, title: APP_TITLE, tooltip: APP_TITLE + ' ' + APP_VERSION })
await UpdateTrayMenus(trayMenus as any)
}, 500)
2 changes: 0 additions & 2 deletions frontend/wailsjs/go/bridge/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export function Requests(arg1:string,arg2:string,arg3:{[key: string]: string},ar

export function RestartApp():Promise<bridge.FlagResult>;

export function ShowMainWindow():Promise<void>;

export function StartServer(arg1:string,arg2:string):Promise<bridge.FlagResult>;

export function StopServer(arg1:string):Promise<bridge.FlagResult>;
Expand Down
4 changes: 0 additions & 4 deletions frontend/wailsjs/go/bridge/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ export function RestartApp() {
return window['go']['bridge']['App']['RestartApp']();
}

export function ShowMainWindow() {
return window['go']['bridge']['App']['ShowMainWindow']();
}

export function StartServer(arg1, arg2) {
return window['go']['bridge']['App']['StartServer'](arg1, arg2);
}
Expand Down
14 changes: 6 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ require (
)

require (
github.com/energye/systray v1.0.2
github.com/klauspost/cpuid/v2 v2.2.8
github.com/oschwald/geoip2-golang v1.11.0
github.com/robfig/cron/v3 v3.0.1
golang.org/x/text v0.18.0
golang.org/x/text v0.16.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -27,7 +28,6 @@ require (

require (
github.com/bep/debounce v1.2.1 // indirect
github.com/energye/systray v1.0.2
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
Expand All @@ -46,7 +46,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/samber/lo v1.44.0 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/tkrajina/go-reflector v0.5.6 // indirect
Expand All @@ -55,10 +55,8 @@ require (
github.com/wailsapp/go-webview2 v1.0.10 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

replace github.com/energye/systray => github.com/mklnz/systray v1.0.3-alpha.1
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3IS
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/energye/systray v1.0.2 h1:63R4prQkANtpM2CIA4UrDCuwZFt+FiygG77JYCsNmXc=
github.com/energye/systray v1.0.2/go.mod h1:sp7Q/q/I4/w5ebvpSuJVep71s9Bg7L9ZVp69gBASehM=
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
Expand Down Expand Up @@ -48,8 +50,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mklnz/systray v1.0.3-alpha.1 h1:92NbWMoPjrJ7jMb7gGGvkM6u5vwxyyzt8Nz71/Hz5tY=
github.com/mklnz/systray v1.0.3-alpha.1/go.mod h1:sp7Q/q/I4/w5ebvpSuJVep71s9Bg7L9ZVp69gBASehM=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/oschwald/geoip2-golang v1.11.0 h1:hNENhCn1Uyzhf9PTmquXENiWS6AlxAEnBII6r8krA3w=
Expand All @@ -71,8 +71,8 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA=
github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -99,11 +99,11 @@ github.com/wailsapp/wails/v2 v2.9.1 h1:irsXnoQrCpeKzKTYZ2SUVlRRyeMR6I0vCO9Q1cvlE
github.com/wailsapp/wails/v2 v2.9.1/go.mod h1:7maJV2h+Egl11Ak8QZN/jlGLj2wg05bsQS+ywJPT0gI=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -113,12 +113,12 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down

0 comments on commit f68adeb

Please sign in to comment.