Skip to content

Commit 8cd8639

Browse files
UPDATE 0.1.1: System Tray, END TEST
1 parent 8b2ca70 commit 8cd8639

10 files changed

Lines changed: 120 additions & 6 deletions

File tree

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: |
3333
$env:GOOS="windows"
3434
$env:GOARCH="amd64"
35-
go build -o freedom-core-windows-x64.exe ./cmd/server
35+
go build -ldflags "-H=windowsgui" -o freedom-core-windows-x64.exe ./cmd/server
3636
- uses: actions/upload-artifact@v4
3737
with:
3838
name: freedom-core-windows-x64.exe

cmd/server/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package main
22

33
import (
4-
5-
"github.com/Freedom-Guard/freedom-core/pkg/logger"
4+
"github.com/Freedom-Guard/freedom-core/internal/app"
65
"github.com/Freedom-Guard/freedom-core/internal/core"
76
"github.com/Freedom-Guard/freedom-core/pkg/config"
7+
"github.com/Freedom-Guard/freedom-core/pkg/logger"
88
)
99

1010
func main() {
1111
cfg := config.Load()
1212
logger.Log(logger.INFO, "Freedom-Core is starting... 🚀")
13+
go app.RunTray()
1314
core.StartCore(cfg)
1415
}

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ go 1.24.0
44

55
require golang.org/x/sys v0.36.0
66

7+
require (
8+
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
9+
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect
10+
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect
11+
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect
12+
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect
13+
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
14+
github.com/go-stack/stack v1.8.0 // indirect
15+
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
16+
)
17+
718
require (
819
github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d // indirect
20+
github.com/getlantern/systray v1.2.2
921
github.com/gopherjs/gopherjs v1.17.2 // indirect
1022
)

go.sum

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,39 @@ fyne.io/fyne/v2 v2.6.3 h1:cvtM2KHeRuH+WhtHiA63z5wJVBkQ9+Ay0UMl9PxFHyA=
22
fyne.io/fyne/v2 v2.6.3/go.mod h1:NGSurpRElVoI1G3h+ab2df3O5KLGh1CGbsMMcX0bPIs=
33
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
44
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
5+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
56
github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d h1:dHYKX8CBAs1zSGXm3q3M15CLAEwPEkwrK1ed8FCo+Xo=
67
github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d/go.mod h1:/eFcjDXaU2THSOOqLxOPETIbHETnamk8FA/hMjhg/gU=
8+
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4=
9+
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
10+
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So=
11+
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A=
12+
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 h1:guBYzEaLz0Vfc/jv0czrr2z7qyzTOGC9hiQ0VC+hKjk=
13+
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7/go.mod h1:zx/1xUUeYPy3Pcmet8OSXLbF47l+3y6hIPpyLWoR9oc=
14+
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0=
15+
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o=
16+
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc=
17+
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA=
18+
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA=
19+
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
20+
github.com/getlantern/systray v1.2.2 h1:dCEHtfmvkJG7HZ8lS/sLklTH4RKUcIsKrAD9sThoEBE=
21+
github.com/getlantern/systray v1.2.2/go.mod h1:pXFOI1wwqwYXEhLPm9ZGjS2u/vVELeIgNMY5HvhHhcE=
22+
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
23+
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
724
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
825
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
26+
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ=
27+
github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
28+
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
29+
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
30+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
31+
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
932
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627 h1:2JL2wmHXWIAxDofCK+AdkFi1KEg3dgkefCsm7isADzQ=
1033
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
34+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
35+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
36+
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
37+
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1138
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
1239
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
40+
gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E=

internal/app/icon.ico

222 KB
Binary file not shown.

internal/app/tray.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package app
2+
3+
import (
4+
"os"
5+
6+
"github.com/Freedom-Guard/freedom-core/pkg/logger"
7+
"github.com/getlantern/systray"
8+
9+
_ "embed"
10+
)
11+
12+
//go:embed icon.ico
13+
var iconData []byte
14+
15+
func RunTray() {
16+
systray.Run(onReady, onExit)
17+
}
18+
19+
func onReady() {
20+
systray.SetIcon(iconData)
21+
systray.SetTitle("Freedom Core")
22+
systray.SetTooltip("Freedom Core")
23+
24+
mExit := systray.AddMenuItem("Exit", "Quit the application")
25+
26+
go func() {
27+
for {
28+
select {
29+
case <-mExit.ClickedCh:
30+
logger.Log(logger.INFO, "Exiting application")
31+
systray.Quit()
32+
os.Exit(0)
33+
}
34+
}
35+
}()
36+
}
37+
38+
func onExit() {
39+
logger.Log(logger.INFO, "Freedom Core exited")
40+
}

internal/hiddify/run.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"sync"
1919

2020
"github.com/Freedom-Guard/freedom-core/pkg/logger"
21+
helpers "github.com/Freedom-Guard/freedom-core/pkg/utils"
2122
)
2223

2324
var releaseVersion = "3.2.0"
@@ -191,6 +192,14 @@ func PrepareCore() (string, error) {
191192
}
192193

193194
func RunHiddifyStream(ctx context.Context, args []string, callback func(string)) bool {
195+
allowed := helpers.AllowDialog("آیا اجازه می‌دهید هسته هیدیفای اجرا شود؟ / Do you allow Hiddify Core to run?")
196+
if allowed {
197+
logger.Log(logger.INFO, "کاربر اجازه داد هسته اجرا شود / User allowed the Core to run")
198+
} else {
199+
logger.Log(logger.ERROR, "کاربر اجازه نداد هسته اجرا شود / User denied the Core")
200+
return false
201+
}
202+
194203
path, err := PrepareCore()
195204
if err != nil {
196205
callback("Hiddify core not installed: " + err.Error())

internal/singbox/run.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"sync"
1919

2020
"github.com/Freedom-Guard/freedom-core/pkg/logger"
21+
helpers "github.com/Freedom-Guard/freedom-core/pkg/utils"
2122
)
2223

2324
var releaseVersion = "1.12.8"
@@ -161,6 +162,14 @@ func PrepareCore() (string, error) {
161162
}
162163

163164
func RunSingBoxStream(ctx context.Context, args []string, callback func(string)) bool {
165+
allowed := helpers.AllowDialog("آیا اجازه می‌دهید هسته singbox اجرا شود؟ / Do you allow singbox Core to run?")
166+
if allowed {
167+
logger.Log(logger.INFO, "کاربر اجازه داد هسته اجرا شود / User allowed the Core to run")
168+
} else {
169+
logger.Log(logger.ERROR, "کاربر اجازه نداد هسته اجرا شود / User denied the Core")
170+
return false
171+
}
172+
164173
path, err := PrepareCore()
165174
if err != nil {
166175
callback("Sing-box core not installed: " + err.Error())

internal/xray/run.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"sync"
1919

2020
"github.com/Freedom-Guard/freedom-core/pkg/logger"
21+
helpers "github.com/Freedom-Guard/freedom-core/pkg/utils"
2122
)
2223

2324
var releaseVersion = "25.9.11"
@@ -197,6 +198,14 @@ func PrepareCore() (string, error) {
197198
}
198199

199200
func RunXrayStream(ctx context.Context, args []string, callback func(string)) bool {
201+
allowed := helpers.AllowDialog("آیا اجازه می‌دهید هسته Xray اجرا شود؟ / Do you allow Xray Core to run?")
202+
if allowed {
203+
logger.Log(logger.INFO, "کاربر اجازه داد هسته اجرا شود / User allowed the Core to run")
204+
} else {
205+
logger.Log(logger.ERROR, "کاربر اجازه نداد هسته اجرا شود / User denied the Core")
206+
return false
207+
}
208+
200209
path, err := PrepareCore()
201210
if err != nil {
202211
callback("Xray core not installed: " + err.Error())

pkg/utils/helpers.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package helpers
22

3-
import (
4-
"github.com/gen2brain/dlgs"
5-
)
3+
import "github.com/gen2brain/dlgs"
64

75
func AllowDialog(text string) bool {
86
ok, _ := dlgs.Question("پیام", text, true)
97
return ok
108
}
9+
10+
func InfoDialog(title, text string) {
11+
dlgs.Info(title, text)
12+
}
13+
14+
func ErrorDialog(title, text string) {
15+
dlgs.Error(title, text)
16+
}

0 commit comments

Comments
 (0)