Skip to content

Commit

Permalink
fix tray merge
Browse files Browse the repository at this point in the history
  • Loading branch information
parvit committed Sep 10, 2024
1 parent 6812f2a commit 8572592
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
9 changes: 4 additions & 5 deletions qpep-tray/common/client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package common
import (
"errors"
"github.com/parvit/qpep/qpep-tray/notify"
"github.com/parvit/qpep/shared"
"github.com/parvit/qpep/shared/logger"
"github.com/parvit/qpep/shared/configuration"
"github.com/parvit/qpep/workers/gateway"
stderr "github.com/parvit/qpep/shared/errors"
"github.com/parvit/qpep/shared/logger"
"github.com/parvit/qpep/workers/gateway"
)

var clientActive bool = false
Expand All @@ -18,7 +17,7 @@ func startClient() error {
return stderr.ErrFailed
}

outAddress := configuration2.QPepConfig.Client.LocalListeningAddress
outAddress := configuration.QPepConfig.Client.LocalListeningAddress
addressList, _ := gateway.GetLanListeningAddresses()
for idx, addr := range addressCheckBoxList {
if addr.Checked() {
Expand Down Expand Up @@ -62,7 +61,7 @@ func stopClient() error {

clientActive = false
gateway.SetSystemProxy(false)
InfoMsg("Client stopped")
notify.InfoMsg("Client stopped")
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions qpep-tray/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import (

"github.com/parvit/qpep/api"
"github.com/parvit/qpep/qpep-tray/icons"
"github.com/parvit/qpep/qpep-tray/toast"
"github.com/parvit/qpep/qpep-tray/notify"
"github.com/project-faster/systray"

. "github.com/sqweek/dialog"
)

const (
Expand Down
26 changes: 17 additions & 9 deletions qpep-tray/common/impl_linux.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package common

import (
"github.com/parvit/qpep/shared/configuration"
"github.com/parvit/qpep/qpep-tray/icons"
"github.com/parvit/qpep/qpep-tray/notify"
"github.com/parvit/qpep/shared/configuration"
"os/exec"
"path/filepath"
"syscall"

"github.com/parvit/qpep/qpep-tray/notify"
)

const (
EXENAME = "qpep"

CMD_SERVICE = `%s -service %s %s %s`
)

func getServiceCommand(start, client bool) *exec.Cmd {
Expand All @@ -32,13 +28,25 @@ func getServiceCommand(start, client bool) *exec.Cmd {
verboseFlag = ""
}

attr := &syscall.SysProcAttr{}

cmd := exec.Command(exeFile, serviceFlag, clientFlag, verboseFlag)
cmd := exec.Command(exeFile, "-service", serviceFlag, clientFlag, verboseFlag)
if cmd == nil {
notify.ErrorMsg("Could not create client command")
return nil
}
cmd.Dir, _ = filepath.Abs(ExeDir)
return cmd
}

// fakeAPICallCheckProxy executes a "fake" api call to the local server to check for the connection running through
// the global proxy, this is checked by the client that adds the "X-QPEP-PROXY" header with value "true", a missing or
// "false" value means the proxy is not running correctly
func fakeAPICallCheckProxy() bool {
return true
}

func getWaitingIcons() [][]byte {
return [][]byte{
icons.MainIconWaiting,
icons.MainIconData,
}
}
30 changes: 28 additions & 2 deletions qpep-tray/common/impl_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package common

import (
"fmt"
"github.com/parvit/qpep/shared/configuration"
"github.com/parvit/qpep/shared/logger"
"github.com/parvit/qpep/qpep-tray/icons"
"github.com/parvit/qpep/qpep-tray/notify"
"github.com/parvit/qpep/shared/configuration"
"github.com/parvit/qpep/shared/logger"
"os/exec"
"path/filepath"
"strings"
Expand Down Expand Up @@ -54,3 +54,29 @@ func getServiceCommand(start, client bool) *exec.Cmd {
cmd.SysProcAttr = attr
return cmd
}

// fakeAPICallCheckProxy executes a "fake" api call to the local server to check for the connection running through
// the global proxy, this is checked by the client that adds the "X-QPEP-PROXY" header with value "true", a missing or
// "false" value means the proxy is not running correctly
func fakeAPICallCheckProxy() bool {
data, err, _ := shared.RunCommand("powershell.exe", "-ExecutionPolicy", "ByPass", "-Command",
"Invoke-WebRequest -Uri \"http://192.168.1.40:444/qpep-client-proxy-check\" -UseBasicParsing -TimeoutSec 1",
)
logger.Info("proxy check data: %s", data)
logger.Info("proxy check error: %v", err)
if err != nil {
return false
}
if strings.Contains(string(data), "X-QPEP-PROXY, true") {
logger.Info("proxy is working")
return true
}
return false
}

func getWaitingIcons() [][]byte {
return [][]byte{
icons.MainIconWaiting,
icons.MainIconData,
}
}
6 changes: 3 additions & 3 deletions qpep-tray/common/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package common

import (
"errors"
"github.com/parvit/qpep/qpep-tray/notify"
"github.com/parvit/qpep/shared/configuration"
"github.com/parvit/qpep/shared/logger"
stderr "github.com/parvit/qpep/shared/errors"
"github.com/parvit/qpep/shared/logger"
"github.com/parvit/qpep/workers/gateway"
"github.com/parvit/qpep/qpep-tray/notify"
)

var serverActive bool = false
Expand All @@ -16,7 +16,7 @@ func startServer() error {
return stderr.ErrFailed
}

outAddress := configuration2.QPepConfig.Server.LocalListeningAddress
outAddress := configuration.QPepConfig.Server.LocalListeningAddress
addressList, _ := gateway.GetLanListeningAddresses()
for idx, addr := range addressCheckBoxList {
if addr.Checked() {
Expand Down
2 changes: 0 additions & 2 deletions qpep-tray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"github.com/parvit/qpep/qpep-tray/notify"
"github.com/parvit/qpep/shared/configuration"
"github.com/parvit/qpep/workers/gateway"
"io"
"log"
"os"
"os/signal"
"syscall"
Expand Down

0 comments on commit 8572592

Please sign in to comment.