From 4c3a8525d8dabe86d305cc60bfd766ecd0b8c09a Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Mon, 28 Feb 2022 09:09:15 +0330 Subject: [PATCH 01/28] update systray to 1.2.0 --- docs/systray-builds.md | 1 + go.mod | 2 +- go.sum | 4 +-- .../getlantern/systray/CHANGELOG.md | 25 ++++++++++++------- .../github.com/getlantern/systray/README.md | 15 ++++++++--- .../getlantern/systray/systray_linux.c | 7 ++++++ .../getlantern/systray/systray_linux.go | 8 ------ .../systray/systray_linux_appindicator.go | 11 ++++++++ .../systray/systray_linux_ayatana.go | 10 ++++++++ .../getlantern/systray/systray_windows.go | 21 ++++++++++------ vendor/modules.txt | 2 +- 11 files changed, 74 insertions(+), 32 deletions(-) create mode 100644 vendor/github.com/getlantern/systray/systray_linux_appindicator.go create mode 100644 vendor/github.com/getlantern/systray/systray_linux_ayatana.go diff --git a/docs/systray-builds.md b/docs/systray-builds.md index 377e77904c..a2a38fdf7a 100644 --- a/docs/systray-builds.md +++ b/docs/systray-builds.md @@ -23,6 +23,7 @@ $ sudo dnf install gtk3-devel libappindicator-gtk3-devel ```bash $ sudo pacman -S libappindicator-gtk3 gtk3 ``` +also need install `libayatana-appindicator`. You can install it by [AUR](https://aur.archlinux.org/packages/libayatana-appindicator). Other distros might require the installation of said library in their own respective name. diff --git a/go.mod b/go.mod index 6303b6756d..845d882339 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730 // indirect github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect - github.com/getlantern/systray v1.1.0 + github.com/getlantern/systray v1.2.0 github.com/go-chi/chi v4.1.2+incompatible github.com/google/go-github v17.0.0+incompatible github.com/google/uuid v1.1.2 diff --git a/go.sum b/go.sum index 908ba8b3d9..562c28ecd9 100644 --- a/go.sum +++ b/go.sum @@ -134,8 +134,8 @@ github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730/go.mod h1:6mmzY2 github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 h1:QthAQCekS1YOeYWSvoHI6ZatlG4B+GBDLxV/2ZkBsTA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= -github.com/getlantern/systray v1.1.0 h1:U0wCEqseLi2ok1fE6b88gJklzriavPJixZysZPkZd/Y= -github.com/getlantern/systray v1.1.0/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= +github.com/getlantern/systray v1.2.0 h1:MsAdOcmOnm4V+r3HFONDszdZeoj7E3q2dEvsPdsxXtI= +github.com/getlantern/systray v1.2.0/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= diff --git a/vendor/github.com/getlantern/systray/CHANGELOG.md b/vendor/github.com/getlantern/systray/CHANGELOG.md index 2b07f8548d..58e7fc8b33 100644 --- a/vendor/github.com/getlantern/systray/CHANGELOG.md +++ b/vendor/github.com/getlantern/systray/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [v1.1.0](https://github.com/getlantern/systray/tree/v1.1.0) (2020-11-18) + +[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.5...v1.1.0) + +**Merged pull requests:** + +- Add submenu support for Linux [\#183](https://github.com/getlantern/systray/pull/183) ([fbrinker](https://github.com/fbrinker)) +- Add checkbox support for Linux [\#181](https://github.com/getlantern/systray/pull/181) ([fbrinker](https://github.com/fbrinker)) +- fix SetTitle documentation [\#179](https://github.com/getlantern/systray/pull/179) ([delthas](https://github.com/delthas)) + ## [v1.0.5](https://github.com/getlantern/systray/tree/v1.0.5) (2020-10-19) [Full Changelog](https://github.com/getlantern/systray/compare/v1.0.4...v1.0.5) @@ -33,19 +43,19 @@ ## [v1.0.2](https://github.com/getlantern/systray/tree/v1.0.2) (2020-05-19) -[Full Changelog](https://github.com/getlantern/systray/compare/1.0.1...v1.0.2) +[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.1...v1.0.2) **Merged pull requests:** - remove unused dependencies [\#145](https://github.com/getlantern/systray/pull/145) ([joesis](https://github.com/joesis)) -## [1.0.1](https://github.com/getlantern/systray/tree/1.0.1) (2020-05-18) +## [v1.0.1](https://github.com/getlantern/systray/tree/v1.0.1) (2020-05-18) -[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.1...1.0.1) +[Full Changelog](https://github.com/getlantern/systray/compare/1.0.1...v1.0.1) -## [v1.0.1](https://github.com/getlantern/systray/tree/v1.0.1) (2020-05-18) +## [1.0.1](https://github.com/getlantern/systray/tree/1.0.1) (2020-05-18) -[Full Changelog](https://github.com/getlantern/systray/compare/1.0.0...v1.0.1) +[Full Changelog](https://github.com/getlantern/systray/compare/1.0.0...1.0.1) **Merged pull requests:** @@ -61,7 +71,6 @@ **Merged pull requests:** -- Backport all features and fixes from master [\#140](https://github.com/getlantern/systray/pull/140) ([joesis](https://github.com/joesis)) - Check if the menu item is nil [\#137](https://github.com/getlantern/systray/pull/137) ([myleshorton](https://github.com/myleshorton)) ## [0.9.0](https://github.com/getlantern/systray/tree/0.9.0) (2020-03-24) @@ -74,6 +83,7 @@ **Merged pull requests:** +- Backport all features and fixes from master [\#140](https://github.com/getlantern/systray/pull/140) ([joesis](https://github.com/joesis)) - Nested menu windows [\#132](https://github.com/getlantern/systray/pull/132) ([joesis](https://github.com/joesis)) - Support for nested sub-menus on OS X [\#131](https://github.com/getlantern/systray/pull/131) ([oxtoacart](https://github.com/oxtoacart)) - Use temp directory for walk resource manager [\#129](https://github.com/getlantern/systray/pull/129) ([max-b](https://github.com/max-b)) @@ -109,9 +119,6 @@ - Fixed hide show in linux \(\#37\) [\#39](https://github.com/getlantern/systray/pull/39) ([meskio](https://github.com/meskio)) - fix: linux compilation warning [\#36](https://github.com/getlantern/systray/pull/36) ([novln](https://github.com/novln)) - Added separator functionality [\#32](https://github.com/getlantern/systray/pull/32) ([oxtoacart](https://github.com/oxtoacart)) -- Add ability to show/hide menu items [\#31](https://github.com/getlantern/systray/pull/31) ([oxtoacart](https://github.com/oxtoacart)) -- Exit handling improvements [\#29](https://github.com/getlantern/systray/pull/29) ([oxtoacart](https://github.com/oxtoacart)) -- Made onExit run reliably and process terminate on quit [\#28](https://github.com/getlantern/systray/pull/28) ([oxtoacart](https://github.com/oxtoacart)) diff --git a/vendor/github.com/getlantern/systray/README.md b/vendor/github.com/getlantern/systray/README.md index 543acfd2fd..554d03749e 100644 --- a/vendor/github.com/getlantern/systray/README.md +++ b/vendor/github.com/getlantern/systray/README.md @@ -30,6 +30,8 @@ func onExit() { See [full API](https://pkg.go.dev/github.com/getlantern/systray?tab=doc) as well as [CHANGELOG](https://github.com/getlantern/systray/tree/master/CHANGELOG.md). +Note: this package requires cgo, so make sure you set `CGO_ENABLED=1` before building. + ## Try the example app! Have go v1.12+ or higher installed? Here's an example to get started on macOS: @@ -68,13 +70,20 @@ The code under `webview_example` is to demostrate how it can co-exist with other ### Linux -* Building apps requires gcc as well as the `gtk3` and `libappindicator3` development headers to be installed. For Debian or Ubuntu, you may install these using: +* Building apps requires gcc as well as the `gtk3` and `libayatana-appindicator3` development headers to be installed. For Debian or Ubuntu, you may install these using: ```sh -sudo apt-get install gcc libgtk-3-dev libappindicator3-dev +sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev ``` -On Linux Mint, `libxapp-dev` is also required . +On Linux Mint, `libxapp-dev` is also required. + +If you need to support the older `libappindicator3` library instead, you can pass the build flag `legacy_appindicator` +when building. For example: + +``` +go build -tags=legacy_appindicator` +``` To build `webview_example`, you also need to install `libwebkit2gtk-4.0-dev` and remove `webview_example/rsrc.syso` which is required on Windows. diff --git a/vendor/github.com/getlantern/systray/systray_linux.c b/vendor/github.com/getlantern/systray/systray_linux.c index 8ec3e76a54..9e14ba01fb 100644 --- a/vendor/github.com/getlantern/systray/systray_linux.c +++ b/vendor/github.com/getlantern/systray/systray_linux.c @@ -2,7 +2,13 @@ #include #include #include + +#ifdef USE_LEGACY_APPINDICATOR #include +#else +#include +#endif + #include "systray.h" static AppIndicator *global_app_indicator; @@ -222,6 +228,7 @@ void setIcon(const char* iconBytes, int length, bool template) { } void setTitle(char* ctitle) { + app_indicator_set_title(global_app_indicator, ctitle); app_indicator_set_label(global_app_indicator, ctitle, ""); free(ctitle); } diff --git a/vendor/github.com/getlantern/systray/systray_linux.go b/vendor/github.com/getlantern/systray/systray_linux.go index 1f508c7b43..ec0b751f03 100644 --- a/vendor/github.com/getlantern/systray/systray_linux.go +++ b/vendor/github.com/getlantern/systray/systray_linux.go @@ -1,13 +1,5 @@ package systray -/* -#cgo darwin CFLAGS: -DDARWIN -x objective-c -fobjc-arc -#cgo darwin LDFLAGS: -framework Cocoa -framework WebKit - -#include "systray.h" -*/ -import "C" - // SetTemplateIcon sets the systray icon as a template icon (on macOS), falling back // to a regular icon on other platforms. // templateIconBytes and iconBytes should be the content of .ico for windows and diff --git a/vendor/github.com/getlantern/systray/systray_linux_appindicator.go b/vendor/github.com/getlantern/systray/systray_linux_appindicator.go new file mode 100644 index 0000000000..3e8e3621b3 --- /dev/null +++ b/vendor/github.com/getlantern/systray/systray_linux_appindicator.go @@ -0,0 +1,11 @@ +//go:build linux && legacy_appindicator + +package systray + +/* +#cgo linux pkg-config: appindicator3-0.1 +#cgo linux CFLAGS: -DUSE_LEGACY_APPINDICATOR + +#include "systray.h" +*/ +import "C" diff --git a/vendor/github.com/getlantern/systray/systray_linux_ayatana.go b/vendor/github.com/getlantern/systray/systray_linux_ayatana.go new file mode 100644 index 0000000000..1a2c4b164f --- /dev/null +++ b/vendor/github.com/getlantern/systray/systray_linux_ayatana.go @@ -0,0 +1,10 @@ +//go:build linux && !legacy_appindicator + +package systray + +/* +#cgo linux pkg-config: ayatana-appindicator3-0.1 + +#include "systray.h" +*/ +import "C" diff --git a/vendor/github.com/getlantern/systray/systray_windows.go b/vendor/github.com/getlantern/systray/systray_windows.go index cf9f23b09d..6bdc803dab 100644 --- a/vendor/github.com/getlantern/systray/systray_windows.go +++ b/vendor/github.com/getlantern/systray/systray_windows.go @@ -36,13 +36,12 @@ var ( pCreatePopupMenu = u32.NewProc("CreatePopupMenu") pCreateWindowEx = u32.NewProc("CreateWindowExW") pDefWindowProc = u32.NewProc("DefWindowProcW") - pDeleteMenu = u32.NewProc("DeleteMenu") + pRemoveMenu = u32.NewProc("RemoveMenu") pDestroyWindow = u32.NewProc("DestroyWindow") pDispatchMessage = u32.NewProc("DispatchMessageW") pDrawIconEx = u32.NewProc("DrawIconEx") pGetCursorPos = u32.NewProc("GetCursorPos") pGetDC = u32.NewProc("GetDC") - pGetMenuItemID = u32.NewProc("GetMenuItemID") pGetMessage = u32.NewProc("GetMessageW") pGetSystemMetrics = u32.NewProc("GetSystemMetrics") pInsertMenuItem = u32.NewProc("InsertMenuItemW") @@ -254,11 +253,8 @@ func (t *winTray) wndProc(hWnd windows.Handle, message uint32, wParam, lParam ui WM_ENDSESSION = 0x0016 WM_CLOSE = 0x0010 WM_DESTROY = 0x0002 - WM_CREATE = 0x0001 ) switch message { - case WM_CREATE: - systrayReady() case WM_COMMAND: menuItemId := int32(wParam) // https://docs.microsoft.com/en-us/windows/win32/menurc/wm-command#menus @@ -557,6 +553,14 @@ func (t *winTray) addOrUpdateMenuItem(menuItemId uint32, parentId uint32, title } if res == 0 { + // Menu item does not already exist, create it + t.muMenus.RLock() + submenu, exists := t.menus[menuItemId] + t.muMenus.RUnlock() + if exists { + mi.Mask |= MIIM_SUBMENU + mi.SubMenu = submenu + } t.addToVisibleItems(parentId, menuItemId) position := t.getVisibleItemIndex(parentId, menuItemId) res, _, err = pInsertMenuItem.Call( @@ -613,14 +617,14 @@ func (t *winTray) addSeparatorMenuItem(menuItemId, parentId uint32) error { } func (t *winTray) hideMenuItem(menuItemId, parentId uint32) error { - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms647629(v=vs.85).aspx + // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-removemenu const MF_BYCOMMAND = 0x00000000 const ERROR_SUCCESS syscall.Errno = 0 t.muMenus.RLock() menu := uintptr(t.menus[parentId]) t.muMenus.RUnlock() - res, _, err := pDeleteMenu.Call( + res, _, err := pRemoveMenu.Call( menu, uintptr(menuItemId), MF_BYCOMMAND, @@ -667,7 +671,7 @@ func (t *winTray) delFromVisibleItems(parent, val uint32) { visibleItems := t.visibleItems[parent] for i, itemval := range visibleItems { if val == itemval { - visibleItems = append(visibleItems[:i], visibleItems[i+1:]...) + t.visibleItems[parent] = append(visibleItems[:i], visibleItems[i+1:]...) break } } @@ -771,6 +775,7 @@ func registerSystray() { return } + systrayReady() } func nativeLoop() { diff --git a/vendor/modules.txt b/vendor/modules.txt index 74ff4a0750..6ebf906095 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -62,7 +62,7 @@ github.com/getlantern/hidden # github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 ## explicit github.com/getlantern/ops -# github.com/getlantern/systray v1.1.0 +# github.com/getlantern/systray v1.2.0 ## explicit; go 1.13 github.com/getlantern/systray # github.com/go-chi/chi v4.1.2+incompatible From a2ee40b756d3575253ae2a1f6b24785f2592a5cd Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Mon, 28 Feb 2022 13:41:39 +0330 Subject: [PATCH 02/28] add icons --- internal/gui/gui.go | 12 ++++++++---- internal/gui/icons/green.ico | Bin 0 -> 4286 bytes internal/gui/icons/green.png | Bin 0 -> 576 bytes internal/gui/icons/red.ico | Bin 0 -> 4286 bytes internal/gui/icons/red.png | Bin 0 -> 489 bytes internal/gui/icons/yellow.ico | Bin 0 -> 4286 bytes internal/gui/icons/yellow.png | Bin 0 -> 577 bytes 7 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 internal/gui/icons/green.ico create mode 100644 internal/gui/icons/green.png create mode 100644 internal/gui/icons/red.ico create mode 100644 internal/gui/icons/red.png create mode 100644 internal/gui/icons/yellow.ico create mode 100644 internal/gui/icons/yellow.png diff --git a/internal/gui/gui.go b/internal/gui/gui.go index b1b0fb3ac2..6f480ba4c5 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -60,7 +60,7 @@ func GetOnGUIReady(icon []byte, conf *visorconfig.V1) func() { initOpenVPNLinkBtn(conf) initAdvancedButton(conf) - //initVpnClientBtn() + initVpnClientBtn() initQuitBtn() //go updateVPNConnectionStatus(conf, doneCh) @@ -168,9 +168,13 @@ func initOpenVPNLinkBtn(vc *visorconfig.V1) { }() } -//func initVpnClientBtn() { -// mVPNClient = systray.AddMenuItem("VPN", "VPN Client Connection") -//} +func initVpnClientBtn() { + mVPNClient := systray.AddMenuItem("VPN", "VPN Client Connection") + mVPNStatus := mVPNClient.AddSubMenuItem("Status", "VPN Client Status") + greenCircle, _ := iconFS.ReadFile("icons/green.png") + mVPNStatus.SetIcon(greenCircle) + mVPNClient.SetIcon(greenCircle) +} //func handleVpnClientButton(conf *visorconfig.V1) { // //mVPNClient.AddSubMenuItem() diff --git a/internal/gui/icons/green.ico b/internal/gui/icons/green.ico new file mode 100644 index 0000000000000000000000000000000000000000..e120c71f4121478460936d3bf36d1570e76ca0fd GIT binary patch literal 4286 zcmd6ry-EW?6h?1UG=*po2^ONkLVN;S#o7n(3B*Dy#X>NMh=quySXhgtMG6tI6cG`z zNFfr$LPSCekrcvuK9hkM6G=>V#|O zJ!rc&m_yq~+dKVz^p8Boe~Gqm{zRQ>P0M=J&;JAc3y<+@&O7v|ud%o6QD5($@A*gb zZ_Yy-X#VXjuK}wb^!F;(zXbZ)M@KdP6w&&&590Sig!-ExH1*ngGB zf%-xDVfBOdz$q7Vt(5#Egs}&H#O|;AZ|4u?)D9VFS36u`tEsaX5gQvd(} literal 0 HcmV?d00001 diff --git a/internal/gui/icons/green.png b/internal/gui/icons/green.png new file mode 100644 index 0000000000000000000000000000000000000000..a532af3d63d8a696760fe00296663435a22e6cab GIT binary patch literal 576 zcmV-G0>Ax$-2Aqc5`8# zXU<%{b6RR9DY6lq#x#!M2u2aGjwQ_FBW7co$2!+-)c_yB4P3#Yn!amziN`U`S9%gi ziY(w7?kVrImqa|mgP7*++5$*&*i_9#Q)vffC(~4x13ot>Fdy)tL4mn|PnvlQ8+aFDn*YZ01_a*3G+(bi z!)N$8M0gty=`z>bSirxF)%)Bmj%5%+Pjdlu+U zo#AvGw{RKbHNn+z`edhZY)=ARA|p7fd`G5~ O0000KJ2U4$bJ>|QF^lm@rA*(JA2Lgt*%a`|(xB&^ zUWr7|1GA8YBe;cUc!4`Og&mlK{!aB=eQYH`nokfkNs)3n7;|=7O{v=j%TR)5b!*GL zQFjA+ThXU{0*;~9Uc0}qu$5}Y2g;4W%^zwzpC7TQY5C(tzSqpNYh_n`lZruu!_ zgSP8~d9;1>z0==A|G;DWFVGgwpQuyqX}2Eri~m6X+++K-=H)%=YwoRh)Ytpxd;QV+ zTky~aT7L&Bd%&6p{oShlZwP(G(NV2GWwgGvpgm0I?-SUDIcPY)8|eq7 zco1Y_L14E2ZZ=ak8!wr~3ub-LefC8x!`}!M?5B%-gU@njq|jaXqE9wuTN={()I|FO D1j7d+ literal 0 HcmV?d00001 diff --git a/internal/gui/icons/red.png b/internal/gui/icons/red.png new file mode 100644 index 0000000000000000000000000000000000000000..91c7a458ac3a8d630deef984d011ab3663e2dcf5 GIT binary patch literal 489 zcmV;7gIHg^$I|EnIiq8FpR{oNk%_**o{%IZvUcf)TFc zHm=|zR*~=>AFzuzcvbMD?z0zxPX`Z!Nf0&tC3q5?Uk03l&FW!w!P7pj!ml)iuLduc z08e`-xKJ0q7VNhO&;A%(uJh0LI)G6~EK}aXiAgRPY;5dxpcaA|HU@ zRPedy&+((-0GBP)c0S)>Q`7Rti+r^^4DD(kMrt{LuEtyQ z+La9}Rr|iZA3U3hK-;xxt-24;?E$^ZEwO!kGq>rw~{luPYxmHSk62gdqZ?XGp{O$aqociGaTGbC{*lOr3MtRMLInW;US3h2< zn}vqXU#=gNQn$ZiLt|I3AM$w<2CHo~bB`^ZztgY^8XLt8iXXIx>HK{J>yUw(^ShRQ zQ0xtYY%B=Omfy@KOJ>7Gv)+PP9NP0`Vp;x1s9--`1r;P)z?6+scK1i?xR!Oli362)F6#a9Hu7?uz$1_@Jyu!UI6PFRyjHtX)r+s%b} zo;h>*&S~f}d6A9aG-hxNM=*+j0?SyyN6e*3-00@IjV{0`Zr}}| z09rVjCUL2%!1W=*VIOWoqy6lE;P4OyU>yeoPSgO01DFjsUjw|#binZ%1*QTfY803V zdS7Vzk&&?bIfG5rOw^TDPbzR2Ygn~V_3(#kS6grp4TAoCQV{d zeTL7F4-wwNL)r~Vn#2NkhA8kfP2#srfp%Wt{Se^M){dx3USwm+rnKK3ag|k^Nt3u# z?fC0goF?&?a`cJ=f=_qCw+XZ*e&QVF`Uqc8w&ROi5A3)YwJUJ}H~rsQv4Q(I**Obz zrkmk(9Jg>8<6VNQ;q=K)()OfXaWZt6egE P00000NkvXXu0mjfb0Yqi literal 0 HcmV?d00001 From 8c11669b3e6afa1a9313e6e5d86bfcac0d6c8fd7 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Wed, 2 Mar 2022 15:05:28 +0330 Subject: [PATCH 03/28] make getHTTPClient for systray --- internal/gui/gui.go | 145 +++++++++++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 34 deletions(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 6f480ba4c5..ce23b99ff0 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -4,6 +4,7 @@ package gui import ( + "context" "embed" "fmt" "io" @@ -16,9 +17,15 @@ import ( "github.com/gen2brain/dlgs" "github.com/getlantern/systray" + "github.com/skycoin/dmsg" + "github.com/skycoin/dmsg/cipher" + "github.com/skycoin/dmsg/direct" + "github.com/skycoin/dmsg/dmsgget" + "github.com/skycoin/dmsg/dmsghttp" "github.com/skycoin/skycoin/src/util/logging" "github.com/toqueteos/webbrowser" + "github.com/skycoin/skywire/pkg/servicedisc" "github.com/skycoin/skywire/pkg/skyenv" "github.com/skycoin/skywire/pkg/visor/visorconfig" ) @@ -44,10 +51,11 @@ var ( var ( mAdvancedButton *systray.MenuItem mOpenHypervisor *systray.MenuItem - //mVPNClient *systray.MenuItem - mVPNLink *systray.MenuItem - mUninstall *systray.MenuItem - mQuit *systray.MenuItem + mVPNClient *systray.MenuItem + mVPNLink *systray.MenuItem + mVPNButton *systray.MenuItem + mUninstall *systray.MenuItem + mQuit *systray.MenuItem ) // GetOnGUIReady creates func to run on GUI startup. @@ -60,7 +68,7 @@ func GetOnGUIReady(icon []byte, conf *visorconfig.V1) func() { initOpenVPNLinkBtn(conf) initAdvancedButton(conf) - initVpnClientBtn() + initVpnClientBtn(conf) initQuitBtn() //go updateVPNConnectionStatus(conf, doneCh) @@ -168,17 +176,84 @@ func initOpenVPNLinkBtn(vc *visorconfig.V1) { }() } -func initVpnClientBtn() { +func initVpnClientBtn(conf *visorconfig.V1) { mVPNClient := systray.AddMenuItem("VPN", "VPN Client Connection") - mVPNStatus := mVPNClient.AddSubMenuItem("Status", "VPN Client Status") - greenCircle, _ := iconFS.ReadFile("icons/green.png") - mVPNStatus.SetIcon(greenCircle) - mVPNClient.SetIcon(greenCircle) + // VPN Status + mVPNStatus := mVPNClient.AddSubMenuItem("Disconnect", "VPN Client Status") + mVPNStatus.Disable() + go vpnStatusBtn(mVPNStatus) + // VPN On/Off Button + mVPNButton = mVPNClient.AddSubMenuItem("On", "VPN Client Button") + // VPN Public Servers List + mVPNServersList := mVPNClient.AddSubMenuItem("Servers", "VPN Client Servers") + mVPNServers := []*systray.MenuItem{} + for _, server := range GetAvailPublicVPNServers(conf) { + mVPNServers = append(mVPNServers, mVPNServersList.AddSubMenuItemCheckbox(server, "", false)) + } + go serversBtn(mVPNServers) +} + +func vpnStatusBtn(vpnStatus *systray.MenuItem) { + time.Sleep(5 * time.Second) + vpnStatus.SetTitle("Connecting...") + time.Sleep(5 * time.Second) + vpnStatus.SetTitle("Connected") +} + +func getHTTPClient(conf *visorconfig.V1, ctx context.Context) *http.Client { + var serviceURL dmsgget.URL + serviceURL.Fill(conf.Launcher.ServiceDisc) + logger := logging.NewMasterLogger() + if serviceURL.Scheme == "dmsg" { + var keys cipher.PubKeys + servers := conf.Dmsg.Servers + + if len(servers) == 0 { + return &http.Client{} + } + + pk, sk := conf.PK, conf.SK + keys = append(keys, pk) + entries := direct.GetAllEntries(keys, servers) + dClient := direct.NewClient(entries, logger.PackageLogger("dmsg_http_systray:direct_client")) + dmsgDC, _, err := direct.StartDmsg(ctx, logger.PackageLogger("dmsg_http_systray:dmsgDC"), + pk, sk, dClient, dmsg.DefaultConfig()) + if err != nil { + return &http.Client{} + } + dmsgHTTP := http.Client{Transport: dmsghttp.MakeHTTPTransport(ctx, dmsgDC)} + return &dmsgHTTP + } + return &http.Client{} +} + +func serversBtn(servers []*systray.MenuItem) { + btnChannel := make(chan int) + for index, server := range servers { + go func(chn chan int, server *systray.MenuItem, index int) { + + select { + case <-server.ClickedCh: + chn <- index + } + }(btnChannel, server, index) + } + + for { + selectedServer := servers[<-btnChannel] + serverTempValue := strings.Split(selectedServer.String(), ",")[2] + serverPK := serverTempValue[2 : len(serverTempValue)-5] + for _, server := range servers { + server.Uncheck() + } + selectedServer.Check() + fmt.Println(serverPK) + } } -//func handleVpnClientButton(conf *visorconfig.V1) { -// //mVPNClient.AddSubMenuItem() -//} +func handleVPNButton(conf *visorconfig.V1) { + mVPNButton.SetTitle("Off") +} func handleVPNLinkButton(conf *visorconfig.V1) { vpnAddr := getVPNAddr(conf) @@ -195,25 +270,27 @@ func handleVPNLinkButton(conf *visorconfig.V1) { } // GetAvailPublicVPNServers gets all available public VPN server from service discovery URL -// func GetAvailPublicVPNServers(conf *visorconfig.V1) []string { -// sdClient := servicedisc.NewClient(log, servicedisc.Config{ -// Type: servicedisc.ServiceTypeVPN, -// PK: conf.PK, -// SK: conf.SK, -// DiscAddr: conf.Launcher.ServiceDisc, -// }) -// //ctx, _ := context.WithTimeout(context.Background(), 7*time.Second) -// vpnServers, err := sdClient.Services(context.Background(), 0) -// if err != nil { -// log.Error("Error getting public vpn servers: ", err) -// return nil -// } -// serverAddrs := make([]string, len(vpnServers)) -// for idx, server := range vpnServers { -// serverAddrs[idx] = server.Addr.PubKey().String() -// } -// return serverAddrs -// } +func GetAvailPublicVPNServers(conf *visorconfig.V1) []string { + svrConfig := servicedisc.Config{ + Type: servicedisc.ServiceTypeVPN, + PK: conf.PK, + SK: conf.SK, + DiscAddr: conf.Launcher.ServiceDisc, + } + httpC := getHTTPClient(conf, context.Background()) + sdClient := servicedisc.NewClient(log, log, svrConfig, httpC, "") + vpnServers, err := sdClient.Services(context.Background(), 0) + if err != nil { + log.Error("Error getting public vpn servers: ", err) + return nil + } + serverAddrs := make([]string, len(vpnServers)) + for idx, server := range vpnServers { + serverAddrs[idx] = server.Addr.PubKey().String() + ";" + server.Geo.Country + } + fmt.Println(serverAddrs) + return serverAddrs +} func initUninstallBtn() { if !checkIsPackage() { @@ -230,8 +307,8 @@ func handleUserInteraction(conf *visorconfig.V1, doneCh chan<- bool) { select { case <-mOpenHypervisor.ClickedCh: handleOpenHypervisor(conf) - //case <-mVPNClient.ClickedCh: - // handleVpnClientButton(conf) + case <-mVPNButton.ClickedCh: + handleVPNButton(conf) case <-mVPNLink.ClickedCh: handleVPNLinkButton(conf) case <-mUninstall.ClickedCh: From 39d2d77b0575761dd3376f3c8a56c61b3bb674a7 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 4 Mar 2022 04:30:38 +0330 Subject: [PATCH 04/28] alpha testing --- cmd/skywire-visor/commands/systray.go | 3 +- internal/gui/gui.go | 193 +++++++++++++++++++------- 2 files changed, 148 insertions(+), 48 deletions(-) diff --git a/cmd/skywire-visor/commands/systray.go b/cmd/skywire-visor/commands/systray.go index 40d101ea43..54095cfe93 100644 --- a/cmd/skywire-visor/commands/systray.go +++ b/cmd/skywire-visor/commands/systray.go @@ -5,6 +5,7 @@ package commands import ( "context" + "time" "github.com/getlantern/systray" "github.com/skycoin/skycoin/src/util/logging" @@ -33,7 +34,7 @@ func runApp(args ...string) { }() conf := initConfig(l, args, confPath) - + time.Sleep(3 * time.Second) systray.Run(gui.GetOnGUIReady(sysTrayIcon, conf), gui.OnGUIQuit) } diff --git a/internal/gui/gui.go b/internal/gui/gui.go index ce23b99ff0..99f7d7d71a 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "io/ioutil" + "net" "net/http" "strings" "sync" @@ -17,9 +18,11 @@ import ( "github.com/gen2brain/dlgs" "github.com/getlantern/systray" + "github.com/sirupsen/logrus" "github.com/skycoin/dmsg" "github.com/skycoin/dmsg/cipher" "github.com/skycoin/dmsg/direct" + dmsgdisc "github.com/skycoin/dmsg/disc" "github.com/skycoin/dmsg/dmsgget" "github.com/skycoin/dmsg/dmsghttp" "github.com/skycoin/skycoin/src/util/logging" @@ -27,6 +30,7 @@ import ( "github.com/skycoin/skywire/pkg/servicedisc" "github.com/skycoin/skywire/pkg/skyenv" + "github.com/skycoin/skywire/pkg/visor" "github.com/skycoin/skywire/pkg/visor/visorconfig" ) @@ -40,6 +44,8 @@ var log = logging.NewMasterLogger() var ( stopVisorFnMx sync.Mutex stopVisorFn func() + closeDmsgDC func() + rpcC visor.API //vpnClientStatusMu sync.Mutex //vpnClientStatus bool ) @@ -52,6 +58,7 @@ var ( mAdvancedButton *systray.MenuItem mOpenHypervisor *systray.MenuItem mVPNClient *systray.MenuItem + mVPNStatus *systray.MenuItem mVPNLink *systray.MenuItem mVPNButton *systray.MenuItem mUninstall *systray.MenuItem @@ -61,14 +68,19 @@ var ( // GetOnGUIReady creates func to run on GUI startup. func GetOnGUIReady(icon []byte, conf *visorconfig.V1) func() { doneCh := make(chan bool, 1) + logger := logging.NewMasterLogger() + logger.SetLevel(logrus.InfoLevel) + + httpC := getHTTPClient(conf, context.Background(), logger) + rpcC = rpcClient(conf, logger) + return func() { systray.SetTemplateIcon(icon, icon) - systray.SetTooltip("Skywire") initOpenVPNLinkBtn(conf) initAdvancedButton(conf) - initVpnClientBtn(conf) + initVpnClientBtn(conf, httpC, rpcC) initQuitBtn() //go updateVPNConnectionStatus(conf, doneCh) @@ -104,7 +116,6 @@ func Stop() { if !atomic.CompareAndSwapInt32(&guiStopped, 0, 1) { return } - stopVisor() systray.Quit() } @@ -176,58 +187,45 @@ func initOpenVPNLinkBtn(vc *visorconfig.V1) { }() } -func initVpnClientBtn(conf *visorconfig.V1) { +func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient visor.API) { mVPNClient := systray.AddMenuItem("VPN", "VPN Client Connection") // VPN Status - mVPNStatus := mVPNClient.AddSubMenuItem("Disconnect", "VPN Client Status") + mVPNStatus = mVPNClient.AddSubMenuItem("Status: Disconnect", "VPN Client Status") mVPNStatus.Disable() - go vpnStatusBtn(mVPNStatus) + go vpnStatusBtn(conf, rpcClient) // VPN On/Off Button mVPNButton = mVPNClient.AddSubMenuItem("On", "VPN Client Button") + if !isSetVPNClientPKExist(conf) { + mVPNButton.Disable() + } // VPN Public Servers List mVPNServersList := mVPNClient.AddSubMenuItem("Servers", "VPN Client Servers") mVPNServers := []*systray.MenuItem{} - for _, server := range GetAvailPublicVPNServers(conf) { + for _, server := range getAvailPublicVPNServers(conf, httpClient) { mVPNServers = append(mVPNServers, mVPNServersList.AddSubMenuItemCheckbox(server, "", false)) } - go serversBtn(mVPNServers) -} - -func vpnStatusBtn(vpnStatus *systray.MenuItem) { - time.Sleep(5 * time.Second) - vpnStatus.SetTitle("Connecting...") - time.Sleep(5 * time.Second) - vpnStatus.SetTitle("Connected") + go serversBtn(conf, mVPNServers, rpcClient) } -func getHTTPClient(conf *visorconfig.V1, ctx context.Context) *http.Client { - var serviceURL dmsgget.URL - serviceURL.Fill(conf.Launcher.ServiceDisc) - logger := logging.NewMasterLogger() - if serviceURL.Scheme == "dmsg" { - var keys cipher.PubKeys - servers := conf.Dmsg.Servers - - if len(servers) == 0 { - return &http.Client{} - } - - pk, sk := conf.PK, conf.SK - keys = append(keys, pk) - entries := direct.GetAllEntries(keys, servers) - dClient := direct.NewClient(entries, logger.PackageLogger("dmsg_http_systray:direct_client")) - dmsgDC, _, err := direct.StartDmsg(ctx, logger.PackageLogger("dmsg_http_systray:dmsgDC"), - pk, sk, dClient, dmsg.DefaultConfig()) - if err != nil { - return &http.Client{} +func vpnStatusBtn(conf *visorconfig.V1, rpcClient visor.API) { + for { + stats, _ := rpcClient.GetAppConnectionsSummary(skyenv.VPNClientName) + if len(stats) == 1 { + if stats[0].IsAlive { + mVPNStatus.SetTitle("Status: Connected") + mVPNButton.SetTitle("Off") + mVPNButton.Enable() + } + } else { + mVPNStatus.SetTitle("Status: Disconnected") + mVPNButton.SetTitle("On") + mVPNButton.Enable() } - dmsgHTTP := http.Client{Transport: dmsghttp.MakeHTTPTransport(ctx, dmsgDC)} - return &dmsgHTTP + time.Sleep(3 * time.Second) } - return &http.Client{} } -func serversBtn(servers []*systray.MenuItem) { +func serversBtn(conf *visorconfig.V1, servers []*systray.MenuItem, rpcClient visor.API) { btnChannel := make(chan int) for index, server := range servers { go func(chn chan int, server *systray.MenuItem, index int) { @@ -247,12 +245,40 @@ func serversBtn(servers []*systray.MenuItem) { server.Uncheck() } selectedServer.Check() - fmt.Println(serverPK) + pk := cipher.PubKey{} + if err := pk.UnmarshalText([]byte(serverPK)); err != nil { + continue + } + + rpcClient.StopApp(skyenv.VPNClientName) + rpcClient.SetAppPK(skyenv.VPNClientName, pk) + rpcClient.StartApp(skyenv.VPNClientName) } } -func handleVPNButton(conf *visorconfig.V1) { - mVPNButton.SetTitle("Off") +func handleVPNButton(conf *visorconfig.V1, rpcClient visor.API) { + stats, _ := rpcClient.GetAppConnectionsSummary(skyenv.VPNClientName) + if len(stats) == 1 { + if stats[0].IsAlive { + mVPNStatus.SetTitle("Status: Disconnecting...") + mVPNButton.Disable() + mVPNButton.SetTitle("On") + if err := rpcClient.StopApp(skyenv.VPNClientName); err != nil { + mVPNStatus.SetTitle("Status: Connected") + mVPNButton.Enable() + mVPNButton.SetTitle("Off") + } + } + } else { + mVPNStatus.SetTitle("Status: Connecting...") + mVPNButton.Disable() + mVPNButton.SetTitle("Off") + if err := rpcClient.StartApp(skyenv.VPNClientName); err != nil { + mVPNStatus.SetTitle("Status: Disconnected") + mVPNButton.Enable() + mVPNButton.SetTitle("On") + } + } } func handleVPNLinkButton(conf *visorconfig.V1) { @@ -269,15 +295,14 @@ func handleVPNLinkButton(conf *visorconfig.V1) { } } -// GetAvailPublicVPNServers gets all available public VPN server from service discovery URL -func GetAvailPublicVPNServers(conf *visorconfig.V1) []string { +// getAvailPublicVPNServers gets all available public VPN server from service discovery URL +func getAvailPublicVPNServers(conf *visorconfig.V1, httpC *http.Client) []string { svrConfig := servicedisc.Config{ Type: servicedisc.ServiceTypeVPN, PK: conf.PK, SK: conf.SK, DiscAddr: conf.Launcher.ServiceDisc, } - httpC := getHTTPClient(conf, context.Background()) sdClient := servicedisc.NewClient(log, log, svrConfig, httpC, "") vpnServers, err := sdClient.Services(context.Background(), 0) if err != nil { @@ -288,10 +313,73 @@ func GetAvailPublicVPNServers(conf *visorconfig.V1) []string { for idx, server := range vpnServers { serverAddrs[idx] = server.Addr.PubKey().String() + ";" + server.Geo.Country } - fmt.Println(serverAddrs) return serverAddrs } +func getHTTPClient(conf *visorconfig.V1, ctx context.Context, logger *logging.MasterLogger) *http.Client { + var serviceURL dmsgget.URL + serviceURL.Fill(conf.Launcher.ServiceDisc) + if serviceURL.Scheme == "dmsg" { + var keys cipher.PubKeys + servers := conf.Dmsg.Servers + var delegatedServers []cipher.PubKey + + if len(servers) == 0 { + return &http.Client{} + } + + pk, sk := cipher.GenerateKeyPair() + keys = append(keys, pk) + entries := direct.GetAllEntries(keys, servers) + dClient := direct.NewClient(entries, logger.PackageLogger("systray:dmsghttp_direct_client")) + dmsgDC, closeDmsg, err := direct.StartDmsg(ctx, logger.PackageLogger("systray:dsmghttp_dmsgDC"), + pk, sk, dClient, dmsg.DefaultConfig()) + if err != nil { + return &http.Client{} + } + dmsgHTTP := http.Client{Transport: dmsghttp.MakeHTTPTransport(ctx, dmsgDC)} + + servers, err = dClient.AvailableServers(ctx) + if err != nil { + closeDmsg() + return &http.Client{} + } + + for _, server := range servers { + delegatedServers = append(delegatedServers, server.Static) + } + + clientEntry := &dmsgdisc.Entry{ + Client: &dmsgdisc.Client{ + DelegatedServers: delegatedServers, + }, + Static: serviceURL.Addr.PK, + } + + err = dClient.PostEntry(ctx, clientEntry) + if err != nil { + closeDmsg() + return &http.Client{} + } + closeDmsgDC = closeDmsg + return &dmsgHTTP + } + return &http.Client{} +} + +func isSetVPNClientPKExist(conf *visorconfig.V1) bool { + for _, v := range conf.Launcher.Apps { + if v.Name == skyenv.VPNClientName { + for index := range v.Args { + if v.Args[index] == "-srv" { + return true + } + } + } + } + return false +} + func initUninstallBtn() { if !checkIsPackage() { mUninstall.Hide() @@ -308,7 +396,7 @@ func handleUserInteraction(conf *visorconfig.V1, doneCh chan<- bool) { case <-mOpenHypervisor.ClickedCh: handleOpenHypervisor(conf) case <-mVPNButton.ClickedCh: - handleVPNButton(conf) + handleVPNButton(conf, rpcC) case <-mVPNLink.ClickedCh: handleVPNLinkButton(conf) case <-mUninstall.ClickedCh: @@ -350,6 +438,7 @@ func handleUninstall() { func stopVisor() { stopVisorFnMx.Lock() + closeDmsgDC() stop := stopVisorFn stopVisorFnMx.Unlock() @@ -427,3 +516,13 @@ func getVPNAddr(conf *visorconfig.V1) string { return hvAddr + "/#/vpn/" + conf.PK.Hex() + "/status" } + +func rpcClient(conf *visorconfig.V1, logger *logging.MasterLogger) visor.API { + const rpcDialTimeout = time.Second * 5 + logger.PackageLogger("systray:rpc_client") + conn, err := net.DialTimeout("tcp", conf.CLIAddr, rpcDialTimeout) + if err != nil { + logger.Fatal("RPC connection failed:", err) + } + return visor.NewRPCClient(logger, conn, visor.RPCPrefix, 0) +} From ca8b036560058c9ab30e2e30b150fbda7303bb2c Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 4 Mar 2022 18:13:47 +0330 Subject: [PATCH 05/28] go mod tidy | go mod vendor --- go.mod | 3 +-- vendor/modules.txt | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 5231ea023d..e127d95812 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730 // indirect github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect github.com/getlantern/systray v1.2.0 - github.com/go-chi/chi v4.1.2+incompatible + github.com/go-chi/chi v4.1.2+incompatible // indirect github.com/google/go-github v17.0.0+incompatible github.com/google/uuid v1.1.2 github.com/gorilla/securecookie v1.1.1 @@ -64,7 +64,6 @@ require ( github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect github.com/getlantern/errors v1.0.1 // indirect github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect - github.com/go-chi/chi v4.1.2+incompatible // indirect github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/google/go-querystring v1.0.0 // indirect diff --git a/vendor/modules.txt b/vendor/modules.txt index 0c2c393e94..20d175dd61 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -54,8 +54,6 @@ github.com/getlantern/ops # github.com/getlantern/systray v1.2.0 ## explicit; go 1.13 github.com/getlantern/systray -# github.com/ghodss/yaml v1.0.0 -## explicit # github.com/go-chi/chi v4.1.2+incompatible ## explicit github.com/go-chi/chi @@ -92,8 +90,6 @@ github.com/inconshreveable/mousetrap # github.com/james-barrow/golang-ipc v0.0.0-20210227130457-95e7cc81f5e2 ## explicit; go 1.15 github.com/james-barrow/golang-ipc -# github.com/jaypipes/ghw v0.8.0 -## explicit; go 1.12 # github.com/json-iterator/go v1.1.12 ## explicit; go 1.12 github.com/json-iterator/go From c2d62cd968bcdb390e52e2d2f515df7b9b8b695b Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 09:41:44 +0330 Subject: [PATCH 06/28] improve buttons --- cmd/skywire-visor/commands/systray.go | 2 -- internal/gui/gui.go | 25 +++++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/skywire-visor/commands/systray.go b/cmd/skywire-visor/commands/systray.go index 54095cfe93..a5e37bd6c8 100644 --- a/cmd/skywire-visor/commands/systray.go +++ b/cmd/skywire-visor/commands/systray.go @@ -5,7 +5,6 @@ package commands import ( "context" - "time" "github.com/getlantern/systray" "github.com/skycoin/skycoin/src/util/logging" @@ -34,7 +33,6 @@ func runApp(args ...string) { }() conf := initConfig(l, args, confPath) - time.Sleep(3 * time.Second) systray.Run(gui.GetOnGUIReady(sysTrayIcon, conf), gui.OnGUIQuit) } diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 99f7d7d71a..1fe2594129 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -46,8 +46,6 @@ var ( stopVisorFn func() closeDmsgDC func() rpcC visor.API - //vpnClientStatusMu sync.Mutex - //vpnClientStatus bool ) var ( @@ -72,7 +70,14 @@ func GetOnGUIReady(icon []byte, conf *visorconfig.V1) func() { logger.SetLevel(logrus.InfoLevel) httpC := getHTTPClient(conf, context.Background(), logger) - rpcC = rpcClient(conf, logger) + + rpc_logger := logger.PackageLogger("systray:rpc_client") + hvAddr := getHVAddr(conf) + for !isHypervisorRunning(hvAddr) { + rpc_logger.Info("Waiting for RPC get ready...") + time.Sleep(2 * time.Second) + } + rpcC = rpcClient(conf, rpc_logger) return func() { systray.SetTemplateIcon(icon, icon) @@ -83,8 +88,6 @@ func GetOnGUIReady(icon []byte, conf *visorconfig.V1) func() { initVpnClientBtn(conf, httpC, rpcC) initQuitBtn() - //go updateVPNConnectionStatus(conf, doneCh) - go handleUserInteraction(conf, doneCh) } } @@ -188,16 +191,13 @@ func initOpenVPNLinkBtn(vc *visorconfig.V1) { } func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient visor.API) { - mVPNClient := systray.AddMenuItem("VPN", "VPN Client Connection") + mVPNClient := systray.AddMenuItem("VPN", "VPN Client Submenu") // VPN Status mVPNStatus = mVPNClient.AddSubMenuItem("Status: Disconnect", "VPN Client Status") mVPNStatus.Disable() go vpnStatusBtn(conf, rpcClient) // VPN On/Off Button - mVPNButton = mVPNClient.AddSubMenuItem("On", "VPN Client Button") - if !isSetVPNClientPKExist(conf) { - mVPNButton.Disable() - } + mVPNButton = mVPNClient.AddSubMenuItem("On", "VPN Client Switch Button") // VPN Public Servers List mVPNServersList := mVPNClient.AddSubMenuItem("Servers", "VPN Client Servers") mVPNServers := []*systray.MenuItem{} @@ -243,8 +243,10 @@ func serversBtn(conf *visorconfig.V1, servers []*systray.MenuItem, rpcClient vis serverPK := serverTempValue[2 : len(serverTempValue)-5] for _, server := range servers { server.Uncheck() + server.Enable() } selectedServer.Check() + selectedServer.Disable() pk := cipher.PubKey{} if err := pk.UnmarshalText([]byte(serverPK)); err != nil { continue @@ -517,9 +519,8 @@ func getVPNAddr(conf *visorconfig.V1) string { return hvAddr + "/#/vpn/" + conf.PK.Hex() + "/status" } -func rpcClient(conf *visorconfig.V1, logger *logging.MasterLogger) visor.API { +func rpcClient(conf *visorconfig.V1, logger *logging.Logger) visor.API { const rpcDialTimeout = time.Second * 5 - logger.PackageLogger("systray:rpc_client") conn, err := net.DialTimeout("tcp", conf.CLIAddr, rpcDialTimeout) if err != nil { logger.Fatal("RPC connection failed:", err) From 9d64c94d338f4c09d8870b9e03469730c955911a Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 10:56:44 +0330 Subject: [PATCH 07/28] remove useless icons --- internal/gui/icons/green.ico | Bin 4286 -> 0 bytes internal/gui/icons/green.png | Bin 576 -> 0 bytes internal/gui/icons/red.ico | Bin 4286 -> 0 bytes internal/gui/icons/red.png | Bin 489 -> 0 bytes internal/gui/icons/yellow.ico | Bin 4286 -> 0 bytes internal/gui/icons/yellow.png | Bin 577 -> 0 bytes 6 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 internal/gui/icons/green.ico delete mode 100644 internal/gui/icons/green.png delete mode 100644 internal/gui/icons/red.ico delete mode 100644 internal/gui/icons/red.png delete mode 100644 internal/gui/icons/yellow.ico delete mode 100644 internal/gui/icons/yellow.png diff --git a/internal/gui/icons/green.ico b/internal/gui/icons/green.ico deleted file mode 100644 index e120c71f4121478460936d3bf36d1570e76ca0fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmd6ry-EW?6h?1UG=*po2^ONkLVN;S#o7n(3B*Dy#X>NMh=quySXhgtMG6tI6cG`z zNFfr$LPSCekrcvuK9hkM6G=>V#|O zJ!rc&m_yq~+dKVz^p8Boe~Gqm{zRQ>P0M=J&;JAc3y<+@&O7v|ud%o6QD5($@A*gb zZ_Yy-X#VXjuK}wb^!F;(zXbZ)M@KdP6w&&&590Sig!-ExH1*ngGB zf%-xDVfBOdz$q7Vt(5#Egs}&H#O|;AZ|4u?)D9VFS36u`tEsaX5gQvd(} diff --git a/internal/gui/icons/green.png b/internal/gui/icons/green.png deleted file mode 100644 index a532af3d63d8a696760fe00296663435a22e6cab..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 576 zcmV-G0>Ax$-2Aqc5`8# zXU<%{b6RR9DY6lq#x#!M2u2aGjwQ_FBW7co$2!+-)c_yB4P3#Yn!amziN`U`S9%gi ziY(w7?kVrImqa|mgP7*++5$*&*i_9#Q)vffC(~4x13ot>Fdy)tL4mn|PnvlQ8+aFDn*YZ01_a*3G+(bi z!)N$8M0gty=`z>bSirxF)%)Bmj%5%+Pjdlu+U zo#AvGw{RKbHNn+z`edhZY)=ARA|p7fd`G5~ O0000KJ2U4$bJ>|QF^lm@rA*(JA2Lgt*%a`|(xB&^ zUWr7|1GA8YBe;cUc!4`Og&mlK{!aB=eQYH`nokfkNs)3n7;|=7O{v=j%TR)5b!*GL zQFjA+ThXU{0*;~9Uc0}qu$5}Y2g;4W%^zwzpC7TQY5C(tzSqpNYh_n`lZruu!_ zgSP8~d9;1>z0==A|G;DWFVGgwpQuyqX}2Eri~m6X+++K-=H)%=YwoRh)Ytpxd;QV+ zTky~aT7L&Bd%&6p{oShlZwP(G(NV2GWwgGvpgm0I?-SUDIcPY)8|eq7 zco1Y_L14E2ZZ=ak8!wr~3ub-LefC8x!`}!M?5B%-gU@njq|jaXqE9wuTN={()I|FO D1j7d+ diff --git a/internal/gui/icons/red.png b/internal/gui/icons/red.png deleted file mode 100644 index 91c7a458ac3a8d630deef984d011ab3663e2dcf5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 489 zcmV;7gIHg^$I|EnIiq8FpR{oNk%_**o{%IZvUcf)TFc zHm=|zR*~=>AFzuzcvbMD?z0zxPX`Z!Nf0&tC3q5?Uk03l&FW!w!P7pj!ml)iuLduc z08e`-xKJ0q7VNhO&;A%(uJh0LI)G6~EK}aXiAgRPY;5dxpcaA|HU@ zRPedy&+((-0GBP)c0S)>Q`7Rti+r^^4DD(kMrt{LuEtyQ z+La9}Rr|iZA3U3hK-;xxt-24;?E$^ZEwO!kGq>rw~{luPYxmHSk62gdqZ?XGp{O$aqociGaTGbC{*lOr3MtRMLInW;US3h2< zn}vqXU#=gNQn$ZiLt|I3AM$w<2CHo~bB`^ZztgY^8XLt8iXXIx>HK{J>yUw(^ShRQ zQ0xtYY%B=Omfy@KOJ>7Gv)+PP9NP0`Vp;x1s9--`1r;P)z?6+scK1i?xR!Oli362)F6#a9Hu7?uz$1_@Jyu!UI6PFRyjHtX)r+s%b} zo;h>*&S~f}d6A9aG-hxNM=*+j0?SyyN6e*3-00@IjV{0`Zr}}| z09rVjCUL2%!1W=*VIOWoqy6lE;P4OyU>yeoPSgO01DFjsUjw|#binZ%1*QTfY803V zdS7Vzk&&?bIfG5rOw^TDPbzR2Ygn~V_3(#kS6grp4TAoCQV{d zeTL7F4-wwNL)r~Vn#2NkhA8kfP2#srfp%Wt{Se^M){dx3USwm+rnKK3ag|k^Nt3u# z?fC0goF?&?a`cJ=f=_qCw+XZ*e&QVF`Uqc8w&ROi5A3)YwJUJ}H~rsQv4Q(I**Obz zrkmk(9Jg>8<6VNQ;q=K)()OfXaWZt6egE P00000NkvXXu0mjfb0Yqi From f53e5c94238d67eaed63572b504221ff3cf31d78 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 11:44:34 +0330 Subject: [PATCH 08/28] improve logs --- internal/gui/gui.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 1fe2594129..c942066ffe 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -85,7 +85,7 @@ func GetOnGUIReady(icon []byte, conf *visorconfig.V1) func() { initOpenVPNLinkBtn(conf) initAdvancedButton(conf) - initVpnClientBtn(conf, httpC, rpcC) + initVpnClientBtn(conf, httpC, rpcC, logger) initQuitBtn() go handleUserInteraction(conf, doneCh) @@ -190,7 +190,7 @@ func initOpenVPNLinkBtn(vc *visorconfig.V1) { }() } -func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient visor.API) { +func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient visor.API, logger *logging.MasterLogger) { mVPNClient := systray.AddMenuItem("VPN", "VPN Client Submenu") // VPN Status mVPNStatus = mVPNClient.AddSubMenuItem("Status: Disconnect", "VPN Client Status") @@ -201,7 +201,7 @@ func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient v // VPN Public Servers List mVPNServersList := mVPNClient.AddSubMenuItem("Servers", "VPN Client Servers") mVPNServers := []*systray.MenuItem{} - for _, server := range getAvailPublicVPNServers(conf, httpClient) { + for _, server := range getAvailPublicVPNServers(conf, httpClient, logger.PackageLogger("systray:servers")) { mVPNServers = append(mVPNServers, mVPNServersList.AddSubMenuItemCheckbox(server, "", false)) } go serversBtn(conf, mVPNServers, rpcClient) @@ -298,7 +298,8 @@ func handleVPNLinkButton(conf *visorconfig.V1) { } // getAvailPublicVPNServers gets all available public VPN server from service discovery URL -func getAvailPublicVPNServers(conf *visorconfig.V1, httpC *http.Client) []string { +func getAvailPublicVPNServers(conf *visorconfig.V1, httpC *http.Client, logger *logging.Logger) []string { + svrConfig := servicedisc.Config{ Type: servicedisc.ServiceTypeVPN, PK: conf.PK, @@ -308,7 +309,7 @@ func getAvailPublicVPNServers(conf *visorconfig.V1, httpC *http.Client) []string sdClient := servicedisc.NewClient(log, log, svrConfig, httpC, "") vpnServers, err := sdClient.Services(context.Background(), 0) if err != nil { - log.Error("Error getting public vpn servers: ", err) + logger.Error("Error getting vpn servers: ", err) return nil } serverAddrs := make([]string, len(vpnServers)) From 71c2378befb0aa8de945b74dd9a0f6abfbd1f682 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 11:53:59 +0330 Subject: [PATCH 09/28] improve buttons 2 --- internal/gui/gui.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index c942066ffe..3b1a25825d 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -215,6 +215,10 @@ func vpnStatusBtn(conf *visorconfig.V1, rpcClient visor.API) { mVPNStatus.SetTitle("Status: Connected") mVPNButton.SetTitle("Off") mVPNButton.Enable() + } else { + mVPNStatus.SetTitle("Status: Connecting...") + mVPNButton.SetTitle("Off") + mVPNButton.Disable() } } else { mVPNStatus.SetTitle("Status: Disconnected") From 8b20609a45bca50ffa219e45586a9dbd6cd3d9f1 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 11:55:33 +0330 Subject: [PATCH 10/28] change launcher from cmd to powershell --- scripts/win_installer/skywire.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/win_installer/skywire.bat b/scripts/win_installer/skywire.bat index cf42da824b..836afeadfb 100644 --- a/scripts/win_installer/skywire.bat +++ b/scripts/win_installer/skywire.bat @@ -1,5 +1,5 @@ @Echo Off -%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit +%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("powershell.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" if exist vpn-client.exe ( if not exist "apps\" ( From 2dfa48a14ebaa462aa75170584e4c67ea67f4a51 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 12:46:22 +0330 Subject: [PATCH 11/28] go mod tidy | go mod vendor --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index d617c0c97e..44792f43cc 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730 // indirect github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect github.com/getlantern/systray v1.2.0 - github.com/go-chi/chi v4.1.2+incompatible // indirect github.com/google/go-github v17.0.0+incompatible github.com/google/uuid v1.1.2 github.com/gorilla/securecookie v1.1.1 From a070f8f8b64c0236e1c181dc17bf8df1d3c84ae7 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 17:54:31 +0330 Subject: [PATCH 12/28] update check hypervisor running endpoint --- internal/gui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 3b1a25825d..6fb0b2d10a 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -456,7 +456,7 @@ func stopVisor() { func isHypervisorRunning(addr string) bool { // we check if it's up by querying `health` endpoint - resp, err := http.Get(addr + "/api/health") + resp, err := http.Get(addr) if err != nil { // hypervisor is not running in this case return false From 44424887e3cad1d34faa878620d1e5b1dc281398 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 17:55:50 +0330 Subject: [PATCH 13/28] add extension to windows systray build --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bffb630e8b..cfb67aa093 100644 --- a/Makefile +++ b/Makefile @@ -159,11 +159,11 @@ host-apps-systray: ## Build app host-apps-systray-windows: powershell -Command new-item .\apps -itemtype directory -force - powershell 'go build ${BUILD_OPTS} -o .\apps\skychat .\cmd\apps\skychat' - powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks .\cmd\apps\skysocks' - powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks-client .\cmd\apps\skysocks-client' - powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-server .\cmd\apps\vpn-server' - powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-client .\cmd\apps\vpn-client' + powershell 'go build ${BUILD_OPTS} -o .\apps\skychat.exe .\cmd\apps\skychat.exe' + powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks.exe .\cmd\apps\skysocks.exe' + powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks-client.exe .\cmd\apps\skysocks-client.exe' + powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-server.exe .\cmd\apps\vpn-server.exe' + powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-client.exe .\cmd\apps\vpn-client.exe' # Static Apps host-apps-static: ## Build app From 7c4fdaa4c0e373d2c0721feae38a9c8ccbed4cba Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 18:11:45 +0330 Subject: [PATCH 14/28] fix windows systray build name --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index cfb67aa093..1708614b65 100644 --- a/Makefile +++ b/Makefile @@ -159,11 +159,11 @@ host-apps-systray: ## Build app host-apps-systray-windows: powershell -Command new-item .\apps -itemtype directory -force - powershell 'go build ${BUILD_OPTS} -o .\apps\skychat.exe .\cmd\apps\skychat.exe' - powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks.exe .\cmd\apps\skysocks.exe' - powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks-client.exe .\cmd\apps\skysocks-client.exe' - powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-server.exe .\cmd\apps\vpn-server.exe' - powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-client.exe .\cmd\apps\vpn-client.exe' + powershell 'go build ${BUILD_OPTS} -o .\apps\skychat.exe .\cmd\apps\skychat' + powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks.exe .\cmd\apps\skysocks' + powershell 'go build ${BUILD_OPTS} -o .\apps\skysocks-client.exe .\cmd\apps\skysocks-client' + powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-server.exe .\cmd\apps\vpn-server' + powershell 'go build ${BUILD_OPTS} -tags systray -o .\apps\vpn-client.exe .\cmd\apps\vpn-client' # Static Apps host-apps-static: ## Build app From 59a7223c882c2d7a423fe6d25814f3555fedd1b7 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 18:12:12 +0330 Subject: [PATCH 15/28] change on/off to connect/disconnect --- internal/gui/gui.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 6fb0b2d10a..024f76b81a 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -196,8 +196,8 @@ func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient v mVPNStatus = mVPNClient.AddSubMenuItem("Status: Disconnect", "VPN Client Status") mVPNStatus.Disable() go vpnStatusBtn(conf, rpcClient) - // VPN On/Off Button - mVPNButton = mVPNClient.AddSubMenuItem("On", "VPN Client Switch Button") + // VPN Connect/Disconnect Button + mVPNButton = mVPNClient.AddSubMenuItem("Connect", "VPN Client Switch Button") // VPN Public Servers List mVPNServersList := mVPNClient.AddSubMenuItem("Servers", "VPN Client Servers") mVPNServers := []*systray.MenuItem{} @@ -213,16 +213,16 @@ func vpnStatusBtn(conf *visorconfig.V1, rpcClient visor.API) { if len(stats) == 1 { if stats[0].IsAlive { mVPNStatus.SetTitle("Status: Connected") - mVPNButton.SetTitle("Off") + mVPNButton.SetTitle("Disconnect") mVPNButton.Enable() } else { mVPNStatus.SetTitle("Status: Connecting...") - mVPNButton.SetTitle("Off") + mVPNButton.SetTitle("Disconnect") mVPNButton.Disable() } } else { mVPNStatus.SetTitle("Status: Disconnected") - mVPNButton.SetTitle("On") + mVPNButton.SetTitle("Connect") mVPNButton.Enable() } time.Sleep(3 * time.Second) @@ -268,21 +268,21 @@ func handleVPNButton(conf *visorconfig.V1, rpcClient visor.API) { if stats[0].IsAlive { mVPNStatus.SetTitle("Status: Disconnecting...") mVPNButton.Disable() - mVPNButton.SetTitle("On") + mVPNButton.SetTitle("Connect") if err := rpcClient.StopApp(skyenv.VPNClientName); err != nil { mVPNStatus.SetTitle("Status: Connected") mVPNButton.Enable() - mVPNButton.SetTitle("Off") + mVPNButton.SetTitle("Disconnect") } } } else { mVPNStatus.SetTitle("Status: Connecting...") mVPNButton.Disable() - mVPNButton.SetTitle("Off") + mVPNButton.SetTitle("Disconnect") if err := rpcClient.StartApp(skyenv.VPNClientName); err != nil { mVPNStatus.SetTitle("Status: Disconnected") mVPNButton.Enable() - mVPNButton.SetTitle("On") + mVPNButton.SetTitle("Connect") } } } From 8da66a18112e190dd989f6d810fde94614acdd58 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 8 Mar 2022 18:23:34 +0330 Subject: [PATCH 16/28] fix nil pointer error during quit button of systray --- internal/gui/gui.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 024f76b81a..b277b67ae6 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -371,6 +371,7 @@ func getHTTPClient(conf *visorconfig.V1, ctx context.Context, logger *logging.Ma closeDmsgDC = closeDmsg return &dmsgHTTP } + closeDmsgDC = func() {} return &http.Client{} } From 3c61f078e17e3587e8fe80a7d68f36ed6374e647 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Wed, 9 Mar 2022 12:12:20 +0330 Subject: [PATCH 17/28] Update systray-builds readme --- docs/systray-builds.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/systray-builds.md b/docs/systray-builds.md index a2a38fdf7a..553ec58f68 100644 --- a/docs/systray-builds.md +++ b/docs/systray-builds.md @@ -9,7 +9,7 @@ To build `skywire-visor` with systray feature enabled, you have to had these ins - Debian / Ubuntu and its derivations ```bash -$ sudo apt install libgtk-3-dev libappindicator3-dev +$ sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev libappindicator3-dev ``` - Fedora / RHEL and its derivations From 3b6b698422e4a86dfaabf4ad11da34d5281ff204 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Wed, 9 Mar 2022 12:24:11 +0330 Subject: [PATCH 18/28] update systray from 1.2.0 to 1.2.1 --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/getlantern/systray/CHANGELOG.md | 12 ++++++++++++ .../getlantern/systray/systray_linux_appindicator.go | 1 + .../getlantern/systray/systray_linux_ayatana.go | 1 + .../getlantern/systray/systray_nonwindows.go | 9 ++------- vendor/modules.txt | 2 +- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 44792f43cc..2a13cb6e2a 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730 // indirect github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect - github.com/getlantern/systray v1.2.0 + github.com/getlantern/systray v1.2.1 github.com/google/go-github v17.0.0+incompatible github.com/google/uuid v1.1.2 github.com/gorilla/securecookie v1.1.1 diff --git a/go.sum b/go.sum index 96f7882818..46c55998c4 100644 --- a/go.sum +++ b/go.sum @@ -167,8 +167,8 @@ github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730/go.mod h1:6mmzY2 github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 h1:QthAQCekS1YOeYWSvoHI6ZatlG4B+GBDLxV/2ZkBsTA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= -github.com/getlantern/systray v1.2.0 h1:MsAdOcmOnm4V+r3HFONDszdZeoj7E3q2dEvsPdsxXtI= -github.com/getlantern/systray v1.2.0/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= +github.com/getlantern/systray v1.2.1 h1:udsC2k98v2hN359VTFShuQW6GGprRprw6kD6539JikI= +github.com/getlantern/systray v1.2.1/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= diff --git a/vendor/github.com/getlantern/systray/CHANGELOG.md b/vendor/github.com/getlantern/systray/CHANGELOG.md index 58e7fc8b33..6eaf134b69 100644 --- a/vendor/github.com/getlantern/systray/CHANGELOG.md +++ b/vendor/github.com/getlantern/systray/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [v1.2.0](https://github.com/getlantern/systray/tree/v1.2.0) (2022-02-24) + +[Full Changelog](https://github.com/getlantern/systray/compare/v1.1.0...v1.2.0) + +** Merged pull requests:** + +- On Linux, set the title in addition to the label [\#200](https://github.com/getlantern/systray/pull/200) ([cocotyty](https://github.com/cocotyty)) +- Fix hiding/showing items with submenus on Windows [\#204](https://github.com/getlantern/systray/pull/204) ([simonlindholm](https://github.com/simonlindholm)) +- Fix delFromVisibleItems [\#205](https://github.com/getlantern/systray/pull/205) ([simonlindholm](https://github.com/simonlindholm)) +- Create menu before calling onReady on Windows [\#206](https://github.com/getlantern/systray/pull/206) ([simonlindholm](https://github.com/simonlindholm)) +- Support libayatana-appindicator on Linux [\#225](https://github.com/getlantern/systray/pull/225) ([Crosse](https://github.com/Crosse)) + ## [v1.1.0](https://github.com/getlantern/systray/tree/v1.1.0) (2020-11-18) [Full Changelog](https://github.com/getlantern/systray/compare/v1.0.5...v1.1.0) diff --git a/vendor/github.com/getlantern/systray/systray_linux_appindicator.go b/vendor/github.com/getlantern/systray/systray_linux_appindicator.go index 3e8e3621b3..dde0e23d72 100644 --- a/vendor/github.com/getlantern/systray/systray_linux_appindicator.go +++ b/vendor/github.com/getlantern/systray/systray_linux_appindicator.go @@ -1,3 +1,4 @@ +// +build linux,legacy_appindicator //go:build linux && legacy_appindicator package systray diff --git a/vendor/github.com/getlantern/systray/systray_linux_ayatana.go b/vendor/github.com/getlantern/systray/systray_linux_ayatana.go index 1a2c4b164f..2547f2e5fc 100644 --- a/vendor/github.com/getlantern/systray/systray_linux_ayatana.go +++ b/vendor/github.com/getlantern/systray/systray_linux_ayatana.go @@ -1,3 +1,4 @@ +// +build linux,!legacy_appindicator //go:build linux && !legacy_appindicator package systray diff --git a/vendor/github.com/getlantern/systray/systray_nonwindows.go b/vendor/github.com/getlantern/systray/systray_nonwindows.go index 5f6b90bdd3..12eacdfa8e 100644 --- a/vendor/github.com/getlantern/systray/systray_nonwindows.go +++ b/vendor/github.com/getlantern/systray/systray_nonwindows.go @@ -1,14 +1,9 @@ // +build !windows +// go:build !windows package systray -/* -#cgo linux pkg-config: gtk+-3.0 appindicator3-0.1 -#cgo darwin CFLAGS: -DDARWIN -x objective-c -fobjc-arc -#cgo darwin LDFLAGS: -framework Cocoa - -#include "systray.h" -*/ +// #include "systray.h" import "C" import ( diff --git a/vendor/modules.txt b/vendor/modules.txt index a3ced1f15e..668d2b5233 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -51,7 +51,7 @@ github.com/getlantern/hidden # github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 ## explicit github.com/getlantern/ops -# github.com/getlantern/systray v1.2.0 +# github.com/getlantern/systray v1.2.1 ## explicit; go 1.13 github.com/getlantern/systray # github.com/go-chi/chi/v5 v5.0.8-0.20220103230436-7dbe9a0bd10f From bdbec6b89ddbd019ea47bdd250972e6c5c0e35a8 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Wed, 9 Mar 2022 12:41:40 +0330 Subject: [PATCH 19/28] move rpcClient in related buttons, not main of systray --- internal/gui/gui.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index b277b67ae6..587750ce0c 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -71,21 +71,13 @@ func GetOnGUIReady(icon []byte, conf *visorconfig.V1) func() { httpC := getHTTPClient(conf, context.Background(), logger) - rpc_logger := logger.PackageLogger("systray:rpc_client") - hvAddr := getHVAddr(conf) - for !isHypervisorRunning(hvAddr) { - rpc_logger.Info("Waiting for RPC get ready...") - time.Sleep(2 * time.Second) - } - rpcC = rpcClient(conf, rpc_logger) - return func() { systray.SetTemplateIcon(icon, icon) systray.SetTooltip("Skywire") initOpenVPNLinkBtn(conf) initAdvancedButton(conf) - initVpnClientBtn(conf, httpC, rpcC, logger) + initVpnClientBtn(conf, httpC, logger) initQuitBtn() go handleUserInteraction(conf, doneCh) @@ -190,12 +182,21 @@ func initOpenVPNLinkBtn(vc *visorconfig.V1) { }() } -func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient visor.API, logger *logging.MasterLogger) { +func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, logger *logging.MasterLogger) { + + rpc_logger := logger.PackageLogger("systray:rpc_client") + hvAddr := getHVAddr(conf) + for !isHypervisorRunning(hvAddr) { + rpc_logger.Info("Waiting for RPC get ready...") + time.Sleep(2 * time.Second) + } + rpcC = rpcClient(conf, rpc_logger) + mVPNClient := systray.AddMenuItem("VPN", "VPN Client Submenu") // VPN Status mVPNStatus = mVPNClient.AddSubMenuItem("Status: Disconnect", "VPN Client Status") mVPNStatus.Disable() - go vpnStatusBtn(conf, rpcClient) + go vpnStatusBtn(conf, rpcC) // VPN Connect/Disconnect Button mVPNButton = mVPNClient.AddSubMenuItem("Connect", "VPN Client Switch Button") // VPN Public Servers List @@ -204,7 +205,7 @@ func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, rpcClient v for _, server := range getAvailPublicVPNServers(conf, httpClient, logger.PackageLogger("systray:servers")) { mVPNServers = append(mVPNServers, mVPNServersList.AddSubMenuItemCheckbox(server, "", false)) } - go serversBtn(conf, mVPNServers, rpcClient) + go serversBtn(conf, mVPNServers, rpcC) } func vpnStatusBtn(conf *visorconfig.V1, rpcClient visor.API) { From 9388238a15f3833f6fb9e9aec83abf1b1e1b9798 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Wed, 16 Mar 2022 14:18:14 +0330 Subject: [PATCH 20/28] downgrade systray version from 1.2.1 to 1.1.0 --- go.mod | 2 +- go.sum | 4 +- .../getlantern/systray/CHANGELOG.md | 37 +++++-------------- .../github.com/getlantern/systray/README.md | 15 ++------ .../getlantern/systray/systray_linux.c | 7 ---- .../getlantern/systray/systray_linux.go | 8 ++++ .../systray/systray_linux_appindicator.go | 12 ------ .../systray/systray_linux_ayatana.go | 11 ------ .../getlantern/systray/systray_nonwindows.go | 9 ++++- .../getlantern/systray/systray_windows.go | 21 ++++------- vendor/modules.txt | 2 +- 11 files changed, 39 insertions(+), 89 deletions(-) delete mode 100644 vendor/github.com/getlantern/systray/systray_linux_appindicator.go delete mode 100644 vendor/github.com/getlantern/systray/systray_linux_ayatana.go diff --git a/go.mod b/go.mod index 2a13cb6e2a..42e60d4a57 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730 // indirect github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect - github.com/getlantern/systray v1.2.1 + github.com/getlantern/systray v1.1.0 github.com/google/go-github v17.0.0+incompatible github.com/google/uuid v1.1.2 github.com/gorilla/securecookie v1.1.1 diff --git a/go.sum b/go.sum index 46c55998c4..861f50fdcc 100644 --- a/go.sum +++ b/go.sum @@ -167,8 +167,8 @@ github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730/go.mod h1:6mmzY2 github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 h1:QthAQCekS1YOeYWSvoHI6ZatlG4B+GBDLxV/2ZkBsTA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= -github.com/getlantern/systray v1.2.1 h1:udsC2k98v2hN359VTFShuQW6GGprRprw6kD6539JikI= -github.com/getlantern/systray v1.2.1/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= +github.com/getlantern/systray v1.1.0 h1:U0wCEqseLi2ok1fE6b88gJklzriavPJixZysZPkZd/Y= +github.com/getlantern/systray v1.1.0/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= diff --git a/vendor/github.com/getlantern/systray/CHANGELOG.md b/vendor/github.com/getlantern/systray/CHANGELOG.md index 6eaf134b69..2b07f8548d 100644 --- a/vendor/github.com/getlantern/systray/CHANGELOG.md +++ b/vendor/github.com/getlantern/systray/CHANGELOG.md @@ -1,27 +1,5 @@ # Changelog -## [v1.2.0](https://github.com/getlantern/systray/tree/v1.2.0) (2022-02-24) - -[Full Changelog](https://github.com/getlantern/systray/compare/v1.1.0...v1.2.0) - -** Merged pull requests:** - -- On Linux, set the title in addition to the label [\#200](https://github.com/getlantern/systray/pull/200) ([cocotyty](https://github.com/cocotyty)) -- Fix hiding/showing items with submenus on Windows [\#204](https://github.com/getlantern/systray/pull/204) ([simonlindholm](https://github.com/simonlindholm)) -- Fix delFromVisibleItems [\#205](https://github.com/getlantern/systray/pull/205) ([simonlindholm](https://github.com/simonlindholm)) -- Create menu before calling onReady on Windows [\#206](https://github.com/getlantern/systray/pull/206) ([simonlindholm](https://github.com/simonlindholm)) -- Support libayatana-appindicator on Linux [\#225](https://github.com/getlantern/systray/pull/225) ([Crosse](https://github.com/Crosse)) - -## [v1.1.0](https://github.com/getlantern/systray/tree/v1.1.0) (2020-11-18) - -[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.5...v1.1.0) - -**Merged pull requests:** - -- Add submenu support for Linux [\#183](https://github.com/getlantern/systray/pull/183) ([fbrinker](https://github.com/fbrinker)) -- Add checkbox support for Linux [\#181](https://github.com/getlantern/systray/pull/181) ([fbrinker](https://github.com/fbrinker)) -- fix SetTitle documentation [\#179](https://github.com/getlantern/systray/pull/179) ([delthas](https://github.com/delthas)) - ## [v1.0.5](https://github.com/getlantern/systray/tree/v1.0.5) (2020-10-19) [Full Changelog](https://github.com/getlantern/systray/compare/v1.0.4...v1.0.5) @@ -55,19 +33,19 @@ ## [v1.0.2](https://github.com/getlantern/systray/tree/v1.0.2) (2020-05-19) -[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.1...v1.0.2) +[Full Changelog](https://github.com/getlantern/systray/compare/1.0.1...v1.0.2) **Merged pull requests:** - remove unused dependencies [\#145](https://github.com/getlantern/systray/pull/145) ([joesis](https://github.com/joesis)) -## [v1.0.1](https://github.com/getlantern/systray/tree/v1.0.1) (2020-05-18) +## [1.0.1](https://github.com/getlantern/systray/tree/1.0.1) (2020-05-18) -[Full Changelog](https://github.com/getlantern/systray/compare/1.0.1...v1.0.1) +[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.1...1.0.1) -## [1.0.1](https://github.com/getlantern/systray/tree/1.0.1) (2020-05-18) +## [v1.0.1](https://github.com/getlantern/systray/tree/v1.0.1) (2020-05-18) -[Full Changelog](https://github.com/getlantern/systray/compare/1.0.0...1.0.1) +[Full Changelog](https://github.com/getlantern/systray/compare/1.0.0...v1.0.1) **Merged pull requests:** @@ -83,6 +61,7 @@ **Merged pull requests:** +- Backport all features and fixes from master [\#140](https://github.com/getlantern/systray/pull/140) ([joesis](https://github.com/joesis)) - Check if the menu item is nil [\#137](https://github.com/getlantern/systray/pull/137) ([myleshorton](https://github.com/myleshorton)) ## [0.9.0](https://github.com/getlantern/systray/tree/0.9.0) (2020-03-24) @@ -95,7 +74,6 @@ **Merged pull requests:** -- Backport all features and fixes from master [\#140](https://github.com/getlantern/systray/pull/140) ([joesis](https://github.com/joesis)) - Nested menu windows [\#132](https://github.com/getlantern/systray/pull/132) ([joesis](https://github.com/joesis)) - Support for nested sub-menus on OS X [\#131](https://github.com/getlantern/systray/pull/131) ([oxtoacart](https://github.com/oxtoacart)) - Use temp directory for walk resource manager [\#129](https://github.com/getlantern/systray/pull/129) ([max-b](https://github.com/max-b)) @@ -131,6 +109,9 @@ - Fixed hide show in linux \(\#37\) [\#39](https://github.com/getlantern/systray/pull/39) ([meskio](https://github.com/meskio)) - fix: linux compilation warning [\#36](https://github.com/getlantern/systray/pull/36) ([novln](https://github.com/novln)) - Added separator functionality [\#32](https://github.com/getlantern/systray/pull/32) ([oxtoacart](https://github.com/oxtoacart)) +- Add ability to show/hide menu items [\#31](https://github.com/getlantern/systray/pull/31) ([oxtoacart](https://github.com/oxtoacart)) +- Exit handling improvements [\#29](https://github.com/getlantern/systray/pull/29) ([oxtoacart](https://github.com/oxtoacart)) +- Made onExit run reliably and process terminate on quit [\#28](https://github.com/getlantern/systray/pull/28) ([oxtoacart](https://github.com/oxtoacart)) diff --git a/vendor/github.com/getlantern/systray/README.md b/vendor/github.com/getlantern/systray/README.md index 554d03749e..543acfd2fd 100644 --- a/vendor/github.com/getlantern/systray/README.md +++ b/vendor/github.com/getlantern/systray/README.md @@ -30,8 +30,6 @@ func onExit() { See [full API](https://pkg.go.dev/github.com/getlantern/systray?tab=doc) as well as [CHANGELOG](https://github.com/getlantern/systray/tree/master/CHANGELOG.md). -Note: this package requires cgo, so make sure you set `CGO_ENABLED=1` before building. - ## Try the example app! Have go v1.12+ or higher installed? Here's an example to get started on macOS: @@ -70,20 +68,13 @@ The code under `webview_example` is to demostrate how it can co-exist with other ### Linux -* Building apps requires gcc as well as the `gtk3` and `libayatana-appindicator3` development headers to be installed. For Debian or Ubuntu, you may install these using: +* Building apps requires gcc as well as the `gtk3` and `libappindicator3` development headers to be installed. For Debian or Ubuntu, you may install these using: ```sh -sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev +sudo apt-get install gcc libgtk-3-dev libappindicator3-dev ``` -On Linux Mint, `libxapp-dev` is also required. - -If you need to support the older `libappindicator3` library instead, you can pass the build flag `legacy_appindicator` -when building. For example: - -``` -go build -tags=legacy_appindicator` -``` +On Linux Mint, `libxapp-dev` is also required . To build `webview_example`, you also need to install `libwebkit2gtk-4.0-dev` and remove `webview_example/rsrc.syso` which is required on Windows. diff --git a/vendor/github.com/getlantern/systray/systray_linux.c b/vendor/github.com/getlantern/systray/systray_linux.c index 9e14ba01fb..8ec3e76a54 100644 --- a/vendor/github.com/getlantern/systray/systray_linux.c +++ b/vendor/github.com/getlantern/systray/systray_linux.c @@ -2,13 +2,7 @@ #include #include #include - -#ifdef USE_LEGACY_APPINDICATOR #include -#else -#include -#endif - #include "systray.h" static AppIndicator *global_app_indicator; @@ -228,7 +222,6 @@ void setIcon(const char* iconBytes, int length, bool template) { } void setTitle(char* ctitle) { - app_indicator_set_title(global_app_indicator, ctitle); app_indicator_set_label(global_app_indicator, ctitle, ""); free(ctitle); } diff --git a/vendor/github.com/getlantern/systray/systray_linux.go b/vendor/github.com/getlantern/systray/systray_linux.go index ec0b751f03..1f508c7b43 100644 --- a/vendor/github.com/getlantern/systray/systray_linux.go +++ b/vendor/github.com/getlantern/systray/systray_linux.go @@ -1,5 +1,13 @@ package systray +/* +#cgo darwin CFLAGS: -DDARWIN -x objective-c -fobjc-arc +#cgo darwin LDFLAGS: -framework Cocoa -framework WebKit + +#include "systray.h" +*/ +import "C" + // SetTemplateIcon sets the systray icon as a template icon (on macOS), falling back // to a regular icon on other platforms. // templateIconBytes and iconBytes should be the content of .ico for windows and diff --git a/vendor/github.com/getlantern/systray/systray_linux_appindicator.go b/vendor/github.com/getlantern/systray/systray_linux_appindicator.go deleted file mode 100644 index dde0e23d72..0000000000 --- a/vendor/github.com/getlantern/systray/systray_linux_appindicator.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build linux,legacy_appindicator -//go:build linux && legacy_appindicator - -package systray - -/* -#cgo linux pkg-config: appindicator3-0.1 -#cgo linux CFLAGS: -DUSE_LEGACY_APPINDICATOR - -#include "systray.h" -*/ -import "C" diff --git a/vendor/github.com/getlantern/systray/systray_linux_ayatana.go b/vendor/github.com/getlantern/systray/systray_linux_ayatana.go deleted file mode 100644 index 2547f2e5fc..0000000000 --- a/vendor/github.com/getlantern/systray/systray_linux_ayatana.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build linux,!legacy_appindicator -//go:build linux && !legacy_appindicator - -package systray - -/* -#cgo linux pkg-config: ayatana-appindicator3-0.1 - -#include "systray.h" -*/ -import "C" diff --git a/vendor/github.com/getlantern/systray/systray_nonwindows.go b/vendor/github.com/getlantern/systray/systray_nonwindows.go index 12eacdfa8e..5f6b90bdd3 100644 --- a/vendor/github.com/getlantern/systray/systray_nonwindows.go +++ b/vendor/github.com/getlantern/systray/systray_nonwindows.go @@ -1,9 +1,14 @@ // +build !windows -// go:build !windows package systray -// #include "systray.h" +/* +#cgo linux pkg-config: gtk+-3.0 appindicator3-0.1 +#cgo darwin CFLAGS: -DDARWIN -x objective-c -fobjc-arc +#cgo darwin LDFLAGS: -framework Cocoa + +#include "systray.h" +*/ import "C" import ( diff --git a/vendor/github.com/getlantern/systray/systray_windows.go b/vendor/github.com/getlantern/systray/systray_windows.go index 6bdc803dab..cf9f23b09d 100644 --- a/vendor/github.com/getlantern/systray/systray_windows.go +++ b/vendor/github.com/getlantern/systray/systray_windows.go @@ -36,12 +36,13 @@ var ( pCreatePopupMenu = u32.NewProc("CreatePopupMenu") pCreateWindowEx = u32.NewProc("CreateWindowExW") pDefWindowProc = u32.NewProc("DefWindowProcW") - pRemoveMenu = u32.NewProc("RemoveMenu") + pDeleteMenu = u32.NewProc("DeleteMenu") pDestroyWindow = u32.NewProc("DestroyWindow") pDispatchMessage = u32.NewProc("DispatchMessageW") pDrawIconEx = u32.NewProc("DrawIconEx") pGetCursorPos = u32.NewProc("GetCursorPos") pGetDC = u32.NewProc("GetDC") + pGetMenuItemID = u32.NewProc("GetMenuItemID") pGetMessage = u32.NewProc("GetMessageW") pGetSystemMetrics = u32.NewProc("GetSystemMetrics") pInsertMenuItem = u32.NewProc("InsertMenuItemW") @@ -253,8 +254,11 @@ func (t *winTray) wndProc(hWnd windows.Handle, message uint32, wParam, lParam ui WM_ENDSESSION = 0x0016 WM_CLOSE = 0x0010 WM_DESTROY = 0x0002 + WM_CREATE = 0x0001 ) switch message { + case WM_CREATE: + systrayReady() case WM_COMMAND: menuItemId := int32(wParam) // https://docs.microsoft.com/en-us/windows/win32/menurc/wm-command#menus @@ -553,14 +557,6 @@ func (t *winTray) addOrUpdateMenuItem(menuItemId uint32, parentId uint32, title } if res == 0 { - // Menu item does not already exist, create it - t.muMenus.RLock() - submenu, exists := t.menus[menuItemId] - t.muMenus.RUnlock() - if exists { - mi.Mask |= MIIM_SUBMENU - mi.SubMenu = submenu - } t.addToVisibleItems(parentId, menuItemId) position := t.getVisibleItemIndex(parentId, menuItemId) res, _, err = pInsertMenuItem.Call( @@ -617,14 +613,14 @@ func (t *winTray) addSeparatorMenuItem(menuItemId, parentId uint32) error { } func (t *winTray) hideMenuItem(menuItemId, parentId uint32) error { - // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-removemenu + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms647629(v=vs.85).aspx const MF_BYCOMMAND = 0x00000000 const ERROR_SUCCESS syscall.Errno = 0 t.muMenus.RLock() menu := uintptr(t.menus[parentId]) t.muMenus.RUnlock() - res, _, err := pRemoveMenu.Call( + res, _, err := pDeleteMenu.Call( menu, uintptr(menuItemId), MF_BYCOMMAND, @@ -671,7 +667,7 @@ func (t *winTray) delFromVisibleItems(parent, val uint32) { visibleItems := t.visibleItems[parent] for i, itemval := range visibleItems { if val == itemval { - t.visibleItems[parent] = append(visibleItems[:i], visibleItems[i+1:]...) + visibleItems = append(visibleItems[:i], visibleItems[i+1:]...) break } } @@ -775,7 +771,6 @@ func registerSystray() { return } - systrayReady() } func nativeLoop() { diff --git a/vendor/modules.txt b/vendor/modules.txt index 668d2b5233..9147bdc9ea 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -51,7 +51,7 @@ github.com/getlantern/hidden # github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 ## explicit github.com/getlantern/ops -# github.com/getlantern/systray v1.2.1 +# github.com/getlantern/systray v1.1.0 ## explicit; go 1.13 github.com/getlantern/systray # github.com/go-chi/chi/v5 v5.0.8-0.20220103230436-7dbe9a0bd10f From e85d7c84123f756da0e6421d38dce668f5bf5ced Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 18 Mar 2022 12:08:40 +0330 Subject: [PATCH 21/28] upgrade systray version from 1.1.0 to 1.2.1 --- Makefile | 16 ++++---- go.mod | 2 +- go.sum | 4 +- .../getlantern/systray/CHANGELOG.md | 37 ++++++++++++++----- .../github.com/getlantern/systray/README.md | 15 ++++++-- .../getlantern/systray/systray_linux.c | 7 ++++ .../getlantern/systray/systray_linux.go | 8 ---- .../systray/systray_linux_appindicator.go | 12 ++++++ .../systray/systray_linux_ayatana.go | 11 ++++++ .../getlantern/systray/systray_nonwindows.go | 9 +---- .../getlantern/systray/systray_windows.go | 21 +++++++---- vendor/modules.txt | 2 +- 12 files changed, 97 insertions(+), 47 deletions(-) create mode 100644 vendor/github.com/getlantern/systray/systray_linux_appindicator.go create mode 100644 vendor/github.com/getlantern/systray/systray_linux_ayatana.go diff --git a/Makefile b/Makefile index 1708614b65..9af8ad0c75 100644 --- a/Makefile +++ b/Makefile @@ -151,11 +151,11 @@ host-apps-windows: powershell 'Get-ChildItem .\cmd\apps | % { ${OPTS} go build ${BUILD_OPTS} -o ./apps $$_.FullName }' host-apps-systray: ## Build app - ${OPTS} go build ${BUILD_OPTS} -o ./apps/skychat ./cmd/apps/skychat - ${OPTS} go build ${BUILD_OPTS} -o ./apps/skysocks ./cmd/apps/skysocks - ${OPTS} go build ${BUILD_OPTS} -o ./apps/skysocks-client ./cmd/apps/skysocks-client - ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./apps/vpn-server ./cmd/apps/vpn-server - ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./apps/vpn-client ./cmd/apps/vpn-client + ${OPTS} go build ${BUILD_OPTS} -o ./apps/ ./cmd/apps/skychat + ${OPTS} go build ${BUILD_OPTS} -o ./apps/ ./cmd/apps/skysocks + ${OPTS} go build ${BUILD_OPTS} -o ./apps/ ./cmd/apps/skysocks-client + ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./apps/ ./cmd/apps/vpn-server + ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./apps/ ./cmd/apps/vpn-client host-apps-systray-windows: powershell -Command new-item .\apps -itemtype directory -force @@ -187,9 +187,9 @@ bin-systray-windows: ## Build `skywire-visor` and `skywire-cli` with systray sup powershell 'Get-ChildItem .\cmd | % { ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./ $$_.FullName }' bin-systray: ## Build `skywire-visor`, `skywire-cli` - ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./skywire-visor ./cmd/skywire-visor - ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./skywire-cli ./cmd/skywire-cli - ${OPTS} go build ${BUILD_OPTS} -o ./setup-node ./cmd/setup-node + ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./ ./cmd/skywire-visor + ${OPTS} go build ${BUILD_OPTS} -tags systray -o ./ ./cmd/skywire-cli + ${OPTS} go build ${BUILD_OPTS} -o ./ ./cmd/setup-node # Static Bin bin-static: ## Build `skywire-visor`, `skywire-cli` diff --git a/go.mod b/go.mod index 42e60d4a57..2a13cb6e2a 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730 // indirect github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 // indirect - github.com/getlantern/systray v1.1.0 + github.com/getlantern/systray v1.2.1 github.com/google/go-github v17.0.0+incompatible github.com/google/uuid v1.1.2 github.com/gorilla/securecookie v1.1.1 diff --git a/go.sum b/go.sum index 861f50fdcc..46c55998c4 100644 --- a/go.sum +++ b/go.sum @@ -167,8 +167,8 @@ github.com/getlantern/hidden v0.0.0-20201229170000-e66e7f878730/go.mod h1:6mmzY2 github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 h1:QthAQCekS1YOeYWSvoHI6ZatlG4B+GBDLxV/2ZkBsTA= github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= -github.com/getlantern/systray v1.1.0 h1:U0wCEqseLi2ok1fE6b88gJklzriavPJixZysZPkZd/Y= -github.com/getlantern/systray v1.1.0/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= +github.com/getlantern/systray v1.2.1 h1:udsC2k98v2hN359VTFShuQW6GGprRprw6kD6539JikI= +github.com/getlantern/systray v1.2.1/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= diff --git a/vendor/github.com/getlantern/systray/CHANGELOG.md b/vendor/github.com/getlantern/systray/CHANGELOG.md index 2b07f8548d..6eaf134b69 100644 --- a/vendor/github.com/getlantern/systray/CHANGELOG.md +++ b/vendor/github.com/getlantern/systray/CHANGELOG.md @@ -1,5 +1,27 @@ # Changelog +## [v1.2.0](https://github.com/getlantern/systray/tree/v1.2.0) (2022-02-24) + +[Full Changelog](https://github.com/getlantern/systray/compare/v1.1.0...v1.2.0) + +** Merged pull requests:** + +- On Linux, set the title in addition to the label [\#200](https://github.com/getlantern/systray/pull/200) ([cocotyty](https://github.com/cocotyty)) +- Fix hiding/showing items with submenus on Windows [\#204](https://github.com/getlantern/systray/pull/204) ([simonlindholm](https://github.com/simonlindholm)) +- Fix delFromVisibleItems [\#205](https://github.com/getlantern/systray/pull/205) ([simonlindholm](https://github.com/simonlindholm)) +- Create menu before calling onReady on Windows [\#206](https://github.com/getlantern/systray/pull/206) ([simonlindholm](https://github.com/simonlindholm)) +- Support libayatana-appindicator on Linux [\#225](https://github.com/getlantern/systray/pull/225) ([Crosse](https://github.com/Crosse)) + +## [v1.1.0](https://github.com/getlantern/systray/tree/v1.1.0) (2020-11-18) + +[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.5...v1.1.0) + +**Merged pull requests:** + +- Add submenu support for Linux [\#183](https://github.com/getlantern/systray/pull/183) ([fbrinker](https://github.com/fbrinker)) +- Add checkbox support for Linux [\#181](https://github.com/getlantern/systray/pull/181) ([fbrinker](https://github.com/fbrinker)) +- fix SetTitle documentation [\#179](https://github.com/getlantern/systray/pull/179) ([delthas](https://github.com/delthas)) + ## [v1.0.5](https://github.com/getlantern/systray/tree/v1.0.5) (2020-10-19) [Full Changelog](https://github.com/getlantern/systray/compare/v1.0.4...v1.0.5) @@ -33,19 +55,19 @@ ## [v1.0.2](https://github.com/getlantern/systray/tree/v1.0.2) (2020-05-19) -[Full Changelog](https://github.com/getlantern/systray/compare/1.0.1...v1.0.2) +[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.1...v1.0.2) **Merged pull requests:** - remove unused dependencies [\#145](https://github.com/getlantern/systray/pull/145) ([joesis](https://github.com/joesis)) -## [1.0.1](https://github.com/getlantern/systray/tree/1.0.1) (2020-05-18) +## [v1.0.1](https://github.com/getlantern/systray/tree/v1.0.1) (2020-05-18) -[Full Changelog](https://github.com/getlantern/systray/compare/v1.0.1...1.0.1) +[Full Changelog](https://github.com/getlantern/systray/compare/1.0.1...v1.0.1) -## [v1.0.1](https://github.com/getlantern/systray/tree/v1.0.1) (2020-05-18) +## [1.0.1](https://github.com/getlantern/systray/tree/1.0.1) (2020-05-18) -[Full Changelog](https://github.com/getlantern/systray/compare/1.0.0...v1.0.1) +[Full Changelog](https://github.com/getlantern/systray/compare/1.0.0...1.0.1) **Merged pull requests:** @@ -61,7 +83,6 @@ **Merged pull requests:** -- Backport all features and fixes from master [\#140](https://github.com/getlantern/systray/pull/140) ([joesis](https://github.com/joesis)) - Check if the menu item is nil [\#137](https://github.com/getlantern/systray/pull/137) ([myleshorton](https://github.com/myleshorton)) ## [0.9.0](https://github.com/getlantern/systray/tree/0.9.0) (2020-03-24) @@ -74,6 +95,7 @@ **Merged pull requests:** +- Backport all features and fixes from master [\#140](https://github.com/getlantern/systray/pull/140) ([joesis](https://github.com/joesis)) - Nested menu windows [\#132](https://github.com/getlantern/systray/pull/132) ([joesis](https://github.com/joesis)) - Support for nested sub-menus on OS X [\#131](https://github.com/getlantern/systray/pull/131) ([oxtoacart](https://github.com/oxtoacart)) - Use temp directory for walk resource manager [\#129](https://github.com/getlantern/systray/pull/129) ([max-b](https://github.com/max-b)) @@ -109,9 +131,6 @@ - Fixed hide show in linux \(\#37\) [\#39](https://github.com/getlantern/systray/pull/39) ([meskio](https://github.com/meskio)) - fix: linux compilation warning [\#36](https://github.com/getlantern/systray/pull/36) ([novln](https://github.com/novln)) - Added separator functionality [\#32](https://github.com/getlantern/systray/pull/32) ([oxtoacart](https://github.com/oxtoacart)) -- Add ability to show/hide menu items [\#31](https://github.com/getlantern/systray/pull/31) ([oxtoacart](https://github.com/oxtoacart)) -- Exit handling improvements [\#29](https://github.com/getlantern/systray/pull/29) ([oxtoacart](https://github.com/oxtoacart)) -- Made onExit run reliably and process terminate on quit [\#28](https://github.com/getlantern/systray/pull/28) ([oxtoacart](https://github.com/oxtoacart)) diff --git a/vendor/github.com/getlantern/systray/README.md b/vendor/github.com/getlantern/systray/README.md index 543acfd2fd..554d03749e 100644 --- a/vendor/github.com/getlantern/systray/README.md +++ b/vendor/github.com/getlantern/systray/README.md @@ -30,6 +30,8 @@ func onExit() { See [full API](https://pkg.go.dev/github.com/getlantern/systray?tab=doc) as well as [CHANGELOG](https://github.com/getlantern/systray/tree/master/CHANGELOG.md). +Note: this package requires cgo, so make sure you set `CGO_ENABLED=1` before building. + ## Try the example app! Have go v1.12+ or higher installed? Here's an example to get started on macOS: @@ -68,13 +70,20 @@ The code under `webview_example` is to demostrate how it can co-exist with other ### Linux -* Building apps requires gcc as well as the `gtk3` and `libappindicator3` development headers to be installed. For Debian or Ubuntu, you may install these using: +* Building apps requires gcc as well as the `gtk3` and `libayatana-appindicator3` development headers to be installed. For Debian or Ubuntu, you may install these using: ```sh -sudo apt-get install gcc libgtk-3-dev libappindicator3-dev +sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev ``` -On Linux Mint, `libxapp-dev` is also required . +On Linux Mint, `libxapp-dev` is also required. + +If you need to support the older `libappindicator3` library instead, you can pass the build flag `legacy_appindicator` +when building. For example: + +``` +go build -tags=legacy_appindicator` +``` To build `webview_example`, you also need to install `libwebkit2gtk-4.0-dev` and remove `webview_example/rsrc.syso` which is required on Windows. diff --git a/vendor/github.com/getlantern/systray/systray_linux.c b/vendor/github.com/getlantern/systray/systray_linux.c index 8ec3e76a54..9e14ba01fb 100644 --- a/vendor/github.com/getlantern/systray/systray_linux.c +++ b/vendor/github.com/getlantern/systray/systray_linux.c @@ -2,7 +2,13 @@ #include #include #include + +#ifdef USE_LEGACY_APPINDICATOR #include +#else +#include +#endif + #include "systray.h" static AppIndicator *global_app_indicator; @@ -222,6 +228,7 @@ void setIcon(const char* iconBytes, int length, bool template) { } void setTitle(char* ctitle) { + app_indicator_set_title(global_app_indicator, ctitle); app_indicator_set_label(global_app_indicator, ctitle, ""); free(ctitle); } diff --git a/vendor/github.com/getlantern/systray/systray_linux.go b/vendor/github.com/getlantern/systray/systray_linux.go index 1f508c7b43..ec0b751f03 100644 --- a/vendor/github.com/getlantern/systray/systray_linux.go +++ b/vendor/github.com/getlantern/systray/systray_linux.go @@ -1,13 +1,5 @@ package systray -/* -#cgo darwin CFLAGS: -DDARWIN -x objective-c -fobjc-arc -#cgo darwin LDFLAGS: -framework Cocoa -framework WebKit - -#include "systray.h" -*/ -import "C" - // SetTemplateIcon sets the systray icon as a template icon (on macOS), falling back // to a regular icon on other platforms. // templateIconBytes and iconBytes should be the content of .ico for windows and diff --git a/vendor/github.com/getlantern/systray/systray_linux_appindicator.go b/vendor/github.com/getlantern/systray/systray_linux_appindicator.go new file mode 100644 index 0000000000..dde0e23d72 --- /dev/null +++ b/vendor/github.com/getlantern/systray/systray_linux_appindicator.go @@ -0,0 +1,12 @@ +// +build linux,legacy_appindicator +//go:build linux && legacy_appindicator + +package systray + +/* +#cgo linux pkg-config: appindicator3-0.1 +#cgo linux CFLAGS: -DUSE_LEGACY_APPINDICATOR + +#include "systray.h" +*/ +import "C" diff --git a/vendor/github.com/getlantern/systray/systray_linux_ayatana.go b/vendor/github.com/getlantern/systray/systray_linux_ayatana.go new file mode 100644 index 0000000000..2547f2e5fc --- /dev/null +++ b/vendor/github.com/getlantern/systray/systray_linux_ayatana.go @@ -0,0 +1,11 @@ +// +build linux,!legacy_appindicator +//go:build linux && !legacy_appindicator + +package systray + +/* +#cgo linux pkg-config: ayatana-appindicator3-0.1 + +#include "systray.h" +*/ +import "C" diff --git a/vendor/github.com/getlantern/systray/systray_nonwindows.go b/vendor/github.com/getlantern/systray/systray_nonwindows.go index 5f6b90bdd3..12eacdfa8e 100644 --- a/vendor/github.com/getlantern/systray/systray_nonwindows.go +++ b/vendor/github.com/getlantern/systray/systray_nonwindows.go @@ -1,14 +1,9 @@ // +build !windows +// go:build !windows package systray -/* -#cgo linux pkg-config: gtk+-3.0 appindicator3-0.1 -#cgo darwin CFLAGS: -DDARWIN -x objective-c -fobjc-arc -#cgo darwin LDFLAGS: -framework Cocoa - -#include "systray.h" -*/ +// #include "systray.h" import "C" import ( diff --git a/vendor/github.com/getlantern/systray/systray_windows.go b/vendor/github.com/getlantern/systray/systray_windows.go index cf9f23b09d..6bdc803dab 100644 --- a/vendor/github.com/getlantern/systray/systray_windows.go +++ b/vendor/github.com/getlantern/systray/systray_windows.go @@ -36,13 +36,12 @@ var ( pCreatePopupMenu = u32.NewProc("CreatePopupMenu") pCreateWindowEx = u32.NewProc("CreateWindowExW") pDefWindowProc = u32.NewProc("DefWindowProcW") - pDeleteMenu = u32.NewProc("DeleteMenu") + pRemoveMenu = u32.NewProc("RemoveMenu") pDestroyWindow = u32.NewProc("DestroyWindow") pDispatchMessage = u32.NewProc("DispatchMessageW") pDrawIconEx = u32.NewProc("DrawIconEx") pGetCursorPos = u32.NewProc("GetCursorPos") pGetDC = u32.NewProc("GetDC") - pGetMenuItemID = u32.NewProc("GetMenuItemID") pGetMessage = u32.NewProc("GetMessageW") pGetSystemMetrics = u32.NewProc("GetSystemMetrics") pInsertMenuItem = u32.NewProc("InsertMenuItemW") @@ -254,11 +253,8 @@ func (t *winTray) wndProc(hWnd windows.Handle, message uint32, wParam, lParam ui WM_ENDSESSION = 0x0016 WM_CLOSE = 0x0010 WM_DESTROY = 0x0002 - WM_CREATE = 0x0001 ) switch message { - case WM_CREATE: - systrayReady() case WM_COMMAND: menuItemId := int32(wParam) // https://docs.microsoft.com/en-us/windows/win32/menurc/wm-command#menus @@ -557,6 +553,14 @@ func (t *winTray) addOrUpdateMenuItem(menuItemId uint32, parentId uint32, title } if res == 0 { + // Menu item does not already exist, create it + t.muMenus.RLock() + submenu, exists := t.menus[menuItemId] + t.muMenus.RUnlock() + if exists { + mi.Mask |= MIIM_SUBMENU + mi.SubMenu = submenu + } t.addToVisibleItems(parentId, menuItemId) position := t.getVisibleItemIndex(parentId, menuItemId) res, _, err = pInsertMenuItem.Call( @@ -613,14 +617,14 @@ func (t *winTray) addSeparatorMenuItem(menuItemId, parentId uint32) error { } func (t *winTray) hideMenuItem(menuItemId, parentId uint32) error { - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms647629(v=vs.85).aspx + // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-removemenu const MF_BYCOMMAND = 0x00000000 const ERROR_SUCCESS syscall.Errno = 0 t.muMenus.RLock() menu := uintptr(t.menus[parentId]) t.muMenus.RUnlock() - res, _, err := pDeleteMenu.Call( + res, _, err := pRemoveMenu.Call( menu, uintptr(menuItemId), MF_BYCOMMAND, @@ -667,7 +671,7 @@ func (t *winTray) delFromVisibleItems(parent, val uint32) { visibleItems := t.visibleItems[parent] for i, itemval := range visibleItems { if val == itemval { - visibleItems = append(visibleItems[:i], visibleItems[i+1:]...) + t.visibleItems[parent] = append(visibleItems[:i], visibleItems[i+1:]...) break } } @@ -771,6 +775,7 @@ func registerSystray() { return } + systrayReady() } func nativeLoop() { diff --git a/vendor/modules.txt b/vendor/modules.txt index 9147bdc9ea..668d2b5233 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -51,7 +51,7 @@ github.com/getlantern/hidden # github.com/getlantern/ops v0.0.0-20200403153110-8476b16edcd6 ## explicit github.com/getlantern/ops -# github.com/getlantern/systray v1.1.0 +# github.com/getlantern/systray v1.2.1 ## explicit; go 1.13 github.com/getlantern/systray # github.com/go-chi/chi/v5 v5.0.8-0.20220103230436-7dbe9a0bd10f From a322d2e5103c332f82a16eabf65e16d7d894feb9 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Wed, 23 Mar 2022 16:56:16 +0430 Subject: [PATCH 22/28] remove transports cache, and check transports before make route --- CHANGELOG.md | 1 + pkg/visor/init.go | 44 ++++++++++---------------------------------- pkg/visor/visor.go | 4 ---- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b17e3e38fc..50ec05b381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - config updated to `v1.1.1` - remove dsmghttp migration to skywire-visor starting +- remove transports cache from visor initialization and check them before make route ### Added - added `add-rhv` and `disable-rhv` flags to `skywire-visor` for adding remote hypervisor PK and disable remote hypervisor PK(s) on config file diff --git a/pkg/visor/init.go b/pkg/visor/init.go index 12aac7403b..78e2f06694 100644 --- a/pkg/visor/init.go +++ b/pkg/visor/init.go @@ -232,21 +232,11 @@ func initAddressResolver(ctx context.Context, v *Visor, log *logging.Logger) err return err } - // initialize cache for available transports - m, err := arClient.Transports(ctx) - if err != nil { - log.Warn("failed to fetch transports from AR") - return err - } - v.initLock.Lock() v.arClient = arClient - v.transportsCache = m v.initLock.Unlock() doneCh := make(chan struct{}, 1) - t := time.NewTicker(1 * time.Hour) - go fetchARTransports(ctx, v, log, doneCh, t) v.pushCloseStack("address_resolver", func() error { doneCh <- struct{}{} return nil @@ -255,25 +245,6 @@ func initAddressResolver(ctx context.Context, v *Visor, log *logging.Logger) err return nil } -func fetchARTransports(ctx context.Context, v *Visor, log *logging.Logger, doneCh <-chan struct{}, tick *time.Ticker) { - for { - select { - case <-tick.C: - log.Debug("Fetching PKs from AR") - m, err := v.arClient.Transports(ctx) - if err != nil { - log.WithError(err).Warn("failed to fetch AR transport") - } - v.transportCacheMu.Lock() - v.transportsCache = m - v.transportCacheMu.Unlock() - case <-doneCh: - tick.Stop() - return - } - } -} - func initDiscovery(ctx context.Context, v *Visor, log *logging.Logger) error { // Prepare app discovery factory. factory := appdisc.Factory{ @@ -512,21 +483,26 @@ func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []ro retrier := netutil.NewRetrier(log, time.Second, time.Second*20, 3, 1.3) return []router.RouteSetupHook{ func(rPK cipher.PubKey, tm *transport.Manager) error { + allTransports, err := v.arClient.Transports(ctx) + if err != nil { + log.WithError(err).Warn("failed to fetch AR transport") + } + dmsgFallback := func() error { return retrier.Do(ctx, func() error { _, err := tm.SaveTransport(ctx, rPK, network.DMSG, transport.LabelAutomatic) return err }) } - // check visor's AR transport cache - if v.transportsCache == nil && !v.conf.Transport.PublicAutoconnect { + // check visor's AR transport + if allTransports == nil && !v.conf.Transport.PublicAutoconnect { // skips if there's no AR transports - log.Warn("empty AR transports cache") + log.Warn("empty AR transports") return dmsgFallback() } - transports, ok := v.transportsCache[rPK] + transports, ok := allTransports[rPK] if !ok { - log.WithField("pk", rPK.String()).Warn("pk not found in the transports cache") + log.WithField("pk", rPK.String()).Warn("pk not found in the transports") // check if automatic transport is available, if it does, // continue with route creation if v.conf.Transport.PublicAutoconnect { diff --git a/pkg/visor/visor.go b/pkg/visor/visor.go index 59e6177c26..db11a5de5b 100644 --- a/pkg/visor/visor.go +++ b/pkg/visor/visor.go @@ -13,7 +13,6 @@ import ( dmsgdisc "github.com/skycoin/dmsg/disc" "github.com/skycoin/skycoin/src/util/logging" - "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire/internal/utclient" "github.com/skycoin/skywire/pkg/app/appdisc" "github.com/skycoin/skywire/pkg/app/appevent" @@ -84,8 +83,6 @@ type Visor struct { runtimeErrors chan error isServicesHealthy *internalHealthInfo - transportCacheMu *sync.Mutex - transportsCache map[cipher.PubKey][]string } // todo: consider moving module closing to the module system @@ -118,7 +115,6 @@ func NewVisor(conf *visorconfig.V1, restartCtx *restart.Context) (*Visor, bool) isServicesHealthy: newInternalHealthInfo(), wgTrackers: new(sync.WaitGroup), wgStunClient: new(sync.WaitGroup), - transportCacheMu: new(sync.Mutex), } v.wgStunClient.Add(1) v.isServicesHealthy.init() From a6cdddc0c9792ebcc75adf700f12cfba2462498a Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Thu, 7 Apr 2022 17:53:18 +0430 Subject: [PATCH 23/28] fix some issues --- internal/gui/gui_unix.go | 6 ++++++ pkg/app/launcher/launcher.go | 1 - scripts/mac_installer/desktop-deinstaller/deinstaller.go | 2 -- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/gui/gui_unix.go b/internal/gui/gui_unix.go index 1e00cc9991..8254db720b 100644 --- a/internal/gui/gui_unix.go +++ b/internal/gui/gui_unix.go @@ -5,6 +5,12 @@ package gui import "github.com/skycoin/skywire/pkg/util/osutil" +// TODO (darkrengarius): change path +const ( + iconName = "icons/icon.png" + deinstallerPath = "/opt/skywire/deinstaller" +) + func platformExecUninstall() error { return osutil.Run("/bin/bash", "-c", deinstallerPath) } diff --git a/pkg/app/launcher/launcher.go b/pkg/app/launcher/launcher.go index 2ac8950dad..cc65c8fe2d 100644 --- a/pkg/app/launcher/launcher.go +++ b/pkg/app/launcher/launcher.go @@ -239,7 +239,6 @@ func (l *Launcher) startApp(cmd string, args, envs []string) error { if err != nil { return err } - // Start proc and persist pid. pid, err := l.procM.Start(procConf) if err != nil { diff --git a/scripts/mac_installer/desktop-deinstaller/deinstaller.go b/scripts/mac_installer/desktop-deinstaller/deinstaller.go index 52dc36e79e..ccce67efac 100644 --- a/scripts/mac_installer/desktop-deinstaller/deinstaller.go +++ b/scripts/mac_installer/desktop-deinstaller/deinstaller.go @@ -11,7 +11,6 @@ import ( "github.com/skycoin/skycoin/src/util/logging" - "github.com/skycoin/skywire-utilities/pkg/skyenv" "github.com/skycoin/skywire/pkg/util/osutil" ) @@ -51,7 +50,6 @@ pkgutil --forget ` + osxServiceIdentifier + ` pkgutil --forget com.skycoin.skywire.updater pkgutil --forget com.skycoin.skywire.remover -rm -rf ` + filepath.Join(skyenv.PackageSkywirePath(), "local") + ` rm -rf ` + filepath.Join(os.Getenv("HOME"), "Library", "Logs", "skywire") + ` unlink /usr/local/bin/skywire-cli rm -rf /Applications/Skywire.app From fe25eefd66cbd50360a358a0e401c2fe7e9437f3 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Thu, 7 Apr 2022 18:06:38 +0430 Subject: [PATCH 24/28] fix dmsg imports --- internal/gui/gui.go | 12 ++++++------ vendor/modules.txt | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index e2ac83228a..4b6bba31b5 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -19,17 +19,17 @@ import ( "github.com/gen2brain/dlgs" "github.com/getlantern/systray" "github.com/sirupsen/logrus" - "github.com/skycoin/dmsg" - "github.com/skycoin/dmsg/direct" - dmsgdisc "github.com/skycoin/dmsg/disc" - "github.com/skycoin/dmsg/dmsgget" - "github.com/skycoin/dmsg/dmsghttp" + "github.com/skycoin/dmsg/pkg/direct" + dmsgdisc "github.com/skycoin/dmsg/pkg/disc" + "github.com/skycoin/dmsg/pkg/dmsg" + "github.com/skycoin/dmsg/pkg/dmsgget" + "github.com/skycoin/dmsg/pkg/dmsghttp" "github.com/skycoin/skycoin/src/util/logging" "github.com/toqueteos/webbrowser" "github.com/skycoin/skywire-utilities/pkg/cipher" - "github.com/skycoin/skywire-utilities/pkg/skyenv" "github.com/skycoin/skywire/pkg/servicedisc" + "github.com/skycoin/skywire/pkg/skyenv" "github.com/skycoin/skywire/pkg/visor" "github.com/skycoin/skywire/pkg/visor/visorconfig" ) diff --git a/vendor/modules.txt b/vendor/modules.txt index 17d3f2b4d0..4f5baa871a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -74,8 +74,6 @@ github.com/go-ole/go-ole/oleutil # github.com/go-stack/stack v1.8.0 ## explicit github.com/go-stack/stack -# github.com/google/go-cmp v0.5.7 -## explicit; go 1.11 # github.com/google/go-github v17.0.0+incompatible ## explicit github.com/google/go-github/github From 9d70fc02e9aa7f97b30a41467143b073df94056a Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Thu, 7 Apr 2022 18:38:02 +0430 Subject: [PATCH 25/28] fix some issues 2 --- cmd/skywire-visor/commands/systray.go | 4 ++-- internal/gui/gui_unix.go | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/cmd/skywire-visor/commands/systray.go b/cmd/skywire-visor/commands/systray.go index a5e37bd6c8..4373d35548 100644 --- a/cmd/skywire-visor/commands/systray.go +++ b/cmd/skywire-visor/commands/systray.go @@ -28,11 +28,11 @@ func runApp(args ...string) { } go func() { - runVisor(args) + runVisor() systray.Quit() }() - conf := initConfig(l, args, confPath) + conf := initConfig(l) systray.Run(gui.GetOnGUIReady(sysTrayIcon, conf), gui.OnGUIQuit) } diff --git a/internal/gui/gui_unix.go b/internal/gui/gui_unix.go index 8254db720b..1e00cc9991 100644 --- a/internal/gui/gui_unix.go +++ b/internal/gui/gui_unix.go @@ -5,12 +5,6 @@ package gui import "github.com/skycoin/skywire/pkg/util/osutil" -// TODO (darkrengarius): change path -const ( - iconName = "icons/icon.png" - deinstallerPath = "/opt/skywire/deinstaller" -) - func platformExecUninstall() error { return osutil.Run("/bin/bash", "-c", deinstallerPath) } From 77c18250ee02d2a53505faaf8d7385c8788b5b40 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Sun, 10 Apr 2022 14:14:33 +0430 Subject: [PATCH 26/28] clean useless part of skywire-visor --- cmd/skywire-visor/commands/nosystray.go | 4 ---- cmd/skywire-visor/commands/root.go | 2 -- cmd/skywire-visor/commands/systray.go | 8 -------- 3 files changed, 14 deletions(-) diff --git a/cmd/skywire-visor/commands/nosystray.go b/cmd/skywire-visor/commands/nosystray.go index f2c0e3be1e..86a050fa76 100644 --- a/cmd/skywire-visor/commands/nosystray.go +++ b/cmd/skywire-visor/commands/nosystray.go @@ -9,10 +9,6 @@ import ( "github.com/skycoin/skycoin/src/util/logging" ) -func extraFlags() { - -} - func runApp() { runVisor() } diff --git a/cmd/skywire-visor/commands/root.go b/cmd/skywire-visor/commands/root.go index d93a59b06e..18c2ec5064 100644 --- a/cmd/skywire-visor/commands/root.go +++ b/cmd/skywire-visor/commands/root.go @@ -97,8 +97,6 @@ func init() { for _, j := range hiddenflags { rootCmd.Flags().MarkHidden(j) //nolint } - - extraFlags() } var rootCmd = &cobra.Command{ diff --git a/cmd/skywire-visor/commands/systray.go b/cmd/skywire-visor/commands/systray.go index 53992c4400..cee11b4298 100644 --- a/cmd/skywire-visor/commands/systray.go +++ b/cmd/skywire-visor/commands/systray.go @@ -12,14 +12,6 @@ import ( "github.com/skycoin/skywire/internal/gui" ) -var ( - runSysTrayApp bool -) - -func extraFlags() { - rootCmd.Flags().BoolVar(&runSysTrayApp, "systray", false, "Run system tray app") -} - func runApp(args ...string) { l := logging.NewMasterLogger() sysTrayIcon, err := gui.ReadSysTrayIcon() From 15d79304856fd436c369353a2540cd12aa75d7ba Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Mon, 11 Apr 2022 19:56:19 +0430 Subject: [PATCH 27/28] typo fixing --- internal/gui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 4b6bba31b5..9fa5e3145d 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -187,7 +187,7 @@ func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, logger *log rpc_logger := logger.PackageLogger("systray:rpc_client") hvAddr := getHVAddr(conf) for !isHypervisorRunning(hvAddr) { - rpc_logger.Info("Waiting for RPC get ready...") + rpc_logger.Info("Waiting for RPC get to ready...") time.Sleep(2 * time.Second) } rpcC = rpcClient(conf, rpc_logger) From 82c773bd3287a30df5160d3644aaf88573d7fac3 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Mon, 11 Apr 2022 19:59:37 +0430 Subject: [PATCH 28/28] typo fixing --- internal/gui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 9fa5e3145d..99b2f2d4df 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -187,7 +187,7 @@ func initVpnClientBtn(conf *visorconfig.V1, httpClient *http.Client, logger *log rpc_logger := logger.PackageLogger("systray:rpc_client") hvAddr := getHVAddr(conf) for !isHypervisorRunning(hvAddr) { - rpc_logger.Info("Waiting for RPC get to ready...") + rpc_logger.Info("Waiting for RPC to get ready...") time.Sleep(2 * time.Second) } rpcC = rpcClient(conf, rpc_logger)