Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ main

.DS_St*
dist
SSL
SSL
*.config.json
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@
"args": ["--dev"],
"program": "${workspaceFolder}/servers/jwelly/mysql-to-surreal/main.go"
},
{
"name": "Run Jwelly Adapter Server",
"type": "go",
"request": "launch",
"mode": "auto",
"args": ["--dev"],
"program": "${workspaceFolder}/servers/jwelly/ecommerce-adapter/main.go"
},
{
"name": "Run Jwelly App Main Server",
"type": "go",
Expand Down
46 changes: 46 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"cSpell.words": [
"Acno",
"Akshat",
"bamt",
"damt",
"DSTAMPID",
"ecommerce",
"EXWT",
"Firestore",
"gofiber",
"Igroup",
"itemtag",
"itno",
"itrans",
"ITRNID",
"itrnview",
"jpillora",
"jwelly",
"jwtv",
"kacno",
"Karigar",
"lamt",
"LESSWT",
"MAMT",
"metalwt",
"mysqldb",
"robfig",
"rpsoftech",
"samt",
"SITEID",
"soham",
"SPRICE",
"STAMPID",
"tdate",
"TGDID",
"tgno",
"TPRE",
"TSNO",
"Tunch",
"UNITID",
"vono",
"vtgno",
"Wstg"
]
}
17 changes: 9 additions & 8 deletions apps/sohan/whatsapp/auto-download/index.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sohan_whatsapp_auto_download
package soham_whatsapp_auto_download

import (
"crypto/sha256"
Expand All @@ -15,7 +15,8 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
sohan_whatsapp_keys "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/keys"
soham_whatsapp_keys "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/keys"
utility_functions "github.com/rpsoftech/golang-servers/utility/functions"
utility_functions_gzip "github.com/rpsoftech/golang-servers/utility/functions/gzip"
)

Expand Down Expand Up @@ -114,7 +115,7 @@ func CheckAndDownload(progress *widget.ProgressBar, win fyne.Window) string {
if runtime.GOOS == "windows" {
serverBinary = "whatsapp-client.exe"
}
serverBinary = filepath.Join(sohan_whatsapp_keys.ConfigDir, serverBinary)
serverBinary = filepath.Join(soham_whatsapp_keys.ConfigDir, serverBinary)
if checkAndRunCalled {
return serverBinary
}
Expand Down Expand Up @@ -142,7 +143,7 @@ func CheckAndDownload(progress *widget.ProgressBar, win fyne.Window) string {

needDownload := false

if _, err := os.Stat(serverBinary); os.IsNotExist(err) {
if exist, _ := utility_functions.Exist(serverBinary); !exist {
needDownload = true
}

Expand All @@ -157,7 +158,7 @@ func CheckAndDownload(progress *widget.ProgressBar, win fyne.Window) string {
})
err := downloadFileWithProgress(cloud.URL, gzipFile, progress)
if err != nil {
if _, err := os.Stat(serverBinary); os.IsNotExist(err) {
if exist, _ := utility_functions.Exist(serverBinary); !exist {
panic(fmt.Errorf("File Downloading Failed"))
// needDownload = true
}
Expand Down Expand Up @@ -222,8 +223,8 @@ func downloadFileWithProgress(url string, filepath string, progress *widget.Prog
func replaceBinarySafe(tmpFile string, serverBinary string) error {

// stop server first
if sohan_whatsapp_keys.ServerCmd != nil && sohan_whatsapp_keys.ServerCmd.Process != nil {
sohan_whatsapp_keys.ServerCmd.Process.Kill()
if soham_whatsapp_keys.ServerCmd != nil && soham_whatsapp_keys.ServerCmd.Process != nil {
soham_whatsapp_keys.ServerCmd.Process.Kill()
time.Sleep(3 * time.Second)
}

Expand All @@ -232,7 +233,7 @@ func replaceBinarySafe(tmpFile string, serverBinary string) error {

os.Remove(backup)

if _, err := os.Stat(serverBinary); err == nil {
if exist, _ := utility_functions.Exist(serverBinary); exist {
os.Rename(serverBinary, backup)
}

Expand Down
18 changes: 9 additions & 9 deletions apps/sohan/whatsapp/config/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"github.com/google/uuid"
sohan_whatsapp_keys "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/keys"
soham_whatsapp_keys "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/keys"
whatsapp_config "github.com/rpsoftech/golang-servers/functions/whatsapp/config"
whatsapp_interfaces "github.com/rpsoftech/golang-servers/interfaces/whatsapp"
utility_functions "github.com/rpsoftech/golang-servers/utility/functions"
Expand All @@ -40,17 +40,17 @@ func init() {
log.Fatal(err)
}
// fmt.Println(dirname)
sohan_whatsapp_keys.HomeDir = dirname
sohan_whatsapp_keys.ConfigDir = filepath.Join(dirname, ".wabot_service")
sohan_whatsapp_keys.ServerConfigFilePath = filepath.Join(sohan_whatsapp_keys.ConfigDir, whatsapp_config.ServerConfigFileName)
soham_whatsapp_keys.HomeDir = dirname
soham_whatsapp_keys.ConfigDir = filepath.Join(dirname, ".wabot_service")
soham_whatsapp_keys.ServerConfigFilePath = filepath.Join(soham_whatsapp_keys.ConfigDir, whatsapp_config.ServerConfigFileName)
}

func ValidateConfig() (bool, *whatsapp_interfaces.IServerConfig) {
if _, err := utility_functions.Exist(sohan_whatsapp_keys.ServerConfigFilePath); errors.Is(err, os.ErrNotExist) {
// panic(fmt.Errorf("CONFIG_NOT_EXIST_ON_PATH %s", sohan_whatsapp_keys.ServerConfigFilePath))
if _, err := utility_functions.Exist(soham_whatsapp_keys.ServerConfigFilePath); errors.Is(err, os.ErrNotExist) {
// panic(fmt.Errorf("CONFIG_NOT_EXIST_ON_PATH %s", soham_whatsapp_keys.ServerConfigFilePath))
return false, nil
}
config, err := readConfigFileAndReturniserverConfig(sohan_whatsapp_keys.ServerConfigFilePath)
config, err := readConfigFileAndReturniserverConfig(soham_whatsapp_keys.ServerConfigFilePath)
if err != nil {
return false, nil
// panic(err)
Expand Down Expand Up @@ -141,7 +141,7 @@ func ValidUUID(uuidstring string) (bool, string) {
}

func QrCodeApiCall(token string) (bool, string) {
req, err := http.NewRequest("GET", sohan_whatsapp_keys.QRCODEURL, nil)
req, err := http.NewRequest("GET", soham_whatsapp_keys.QRCODEURL, nil)

if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -171,7 +171,7 @@ func QrCodeApiCall(token string) (bool, string) {
return true, qrcodeRespo.QrCode
}
func LoginApiCall(token string) (bool, error) {
req, err := http.NewRequest("GET", sohan_whatsapp_keys.LoginStatusURL, nil)
req, err := http.NewRequest("GET", soham_whatsapp_keys.LoginStatusURL, nil)

if err != nil {
fmt.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion apps/sohan/whatsapp/keys/index.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sohan_whatsapp_keys
package soham_whatsapp_keys

import "os/exec"

Expand Down
64 changes: 35 additions & 29 deletions apps/sohan/whatsapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
_ "fyne.io/fyne/v2/driver/software"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
sohan_whatsapp_auto_download "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/auto-download"
soham_whatsapp_auto_download "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/auto-download"
soham_whatsapp_gui_config "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/config"
sohan_whatsapp_keys "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/keys"
soham_whatsapp_keys "github.com/rpsoftech/golang-servers/apps/sohan/whatsapp/keys"
"github.com/rpsoftech/golang-servers/env"
whatsapp_interfaces "github.com/rpsoftech/golang-servers/interfaces/whatsapp"
utility_functions "github.com/rpsoftech/golang-servers/utility/functions"
Expand Down Expand Up @@ -79,7 +79,7 @@ func validateGUILOCK() bool {
}
func preventMultipleGUI() {

if _, err := os.Stat(guiLock); err == nil {
if exist, _ := utility_functions.Exist(guiLock); exist {
if validateGUILOCK() {
os.Exit(0)
}
Expand Down Expand Up @@ -128,15 +128,15 @@ func startServer(a fyne.App) {

go func() {
progressBar, progressWin := showDownloadProgress(a)
serverBinary := sohan_whatsapp_auto_download.CheckAndDownload(progressBar, progressWin)
serverBinary := soham_whatsapp_auto_download.CheckAndDownload(progressBar, progressWin)
// start server
fyne.Do(func() {
progressWin.Close()
})
for {
updateTrayStatus("🟡 Starting server...")
sohan_whatsapp_keys.ServerCmd = exec.Command(serverBinary, "--dev")
serverCmd := sohan_whatsapp_keys.ServerCmd
soham_whatsapp_keys.ServerCmd = exec.Command(serverBinary, "--dev")
serverCmd := soham_whatsapp_keys.ServerCmd
if runtime.GOOS == "windows" {
serverCmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
Expand All @@ -160,15 +160,15 @@ func startServer(a fyne.App) {
go utility_functions.StreamLogs(stdout, "SERVER")
go utility_functions.StreamLogs(stderr, "SERVER")
}
err := sohan_whatsapp_keys.ServerCmd.Start()
err := soham_whatsapp_keys.ServerCmd.Start()
if err != nil {
updateTrayStatus("🔴 Server failed")
time.Sleep(50 * time.Second)
continue
}

updateTrayStatus("🟢 Server running")
err = sohan_whatsapp_keys.ServerCmd.Wait()
err = soham_whatsapp_keys.ServerCmd.Wait()
println(err)
updateTrayStatus("🔴 Server stopped")
time.Sleep(3 * time.Second)
Expand All @@ -187,8 +187,8 @@ func startServer(a fyne.App) {

func restartServer() {

if sohan_whatsapp_keys.ServerCmd != nil && sohan_whatsapp_keys.ServerCmd.Process != nil {
sohan_whatsapp_keys.ServerCmd.Process.Kill()
if soham_whatsapp_keys.ServerCmd != nil && soham_whatsapp_keys.ServerCmd.Process != nil {
soham_whatsapp_keys.ServerCmd.Process.Kill()
}

}
Expand All @@ -202,7 +202,7 @@ func saveConfig(token, number string) {
config.Tokens = make(map[string]string)
config.JID = make(map[string]string)
config.Tokens[token] = number
config.SetConfigPath(sohan_whatsapp_keys.ServerConfigFilePath)
config.SetConfigPath(soham_whatsapp_keys.ServerConfigFilePath)
soham_whatsapp_gui_config.SaveConfig(config)
}

Expand Down Expand Up @@ -360,20 +360,20 @@ func configForm(a fyne.App) fyne.CanvasObject {
widget.NewLabel("Number"),
number,
)

log.Println("Loading logo for config file")
// embedded logo
logo := canvas.NewImageFromResource(resourceIconPng)
logo.FillMode = canvas.ImageFillContain
logo.SetMinSize(fyne.NewSize(120, 80))

logoBox := container.NewHBox(
layout.NewSpacer(),
logo,
layout.NewSpacer(),
)

// logo := canvas.NewImageFromResource(resourceIconPng)
// logo.FillMode = canvas.ImageFillContain
// logo.SetMinSize(fyne.NewSize(120, 80))

// logoBox := container.NewHBox(
// layout.NewSpacer(),
// logo,
// layout.NewSpacer(),
// )
log.Println("Returning Config Container")
return container.NewVBox(
logoBox,
// logoBox,
layout.NewSpacer(),
row1,
row2,
Expand Down Expand Up @@ -468,22 +468,26 @@ func main() {
if os.Getenv("APP_ENV") == "" {
os.Setenv("APP_ENV", "PRODUCTION")
}
if !env.IsDev {
os.Setenv("FYNE_RENDER", "software")
guiLock = filepath.Join(env.FindAndReturnCurrentDir(), guiLock)
}
env.LoadEnv(filepath.Join(env.FindAndReturnCurrentDir(), "whatsapp-client.env"))
SetEnv()
log.Printf("ENV Settled")
preventMultipleGUI()
defer os.Remove(guiLock)
a := app.New()
// a.Settings().SetTheme(theme.)

log.Println("Starting GUI")
window := a.NewWindow("WABOT Config Tool")
window.Resize(fyne.NewSize(520, 380))
window.CenterOnScreen()

mainWindow = window

log.Println("Setting ICON")
// embedded icon
window.SetIcon(resourceIconPng)
// window.SetIcon(resourceIconPng)
// window.SetIcon(icon)

//////////////////////////////////////////////////
Expand Down Expand Up @@ -515,7 +519,7 @@ func main() {
quitItem,
)
desk.SetSystemTrayMenu(trayMenu)
desk.SetSystemTrayIcon(resourceIconPng)
// desk.SetSystemTrayIcon(resourceIconPng)
}

window.SetCloseIntercept(func() {
Expand All @@ -525,8 +529,9 @@ func main() {
//////////////////////////////////////////////////
// START LOGIC
//////////////////////////////////////////////////

log.Println("Starting CLIENT")
if loadConfig() {
log.Println("Config Found adn Loaded")
window.SetContent(successScreen())
go func() {
startServer(a)
Expand All @@ -536,6 +541,7 @@ func main() {
})
}()
} else {
log.Println("Config Not Found Creating New")
window.SetContent(configForm(a))
}
window.Show()
Expand Down
4 changes: 2 additions & 2 deletions env/app-env.enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
type AppEnv string

const (
APP_ENV_DEVELOPE AppEnv = "DEVELOPE"
APP_ENV_DEVELOP AppEnv = "DEVELOP"
APP_ENV_LOCAL AppEnv = "LOCAL"
APP_ENV_CI AppEnv = "CI"
APP_ENV_PRODUCTION AppEnv = "PRODUCTION"
)

var (
appEnvMap = map[string]AppEnv{
"DEVELOPE": APP_ENV_DEVELOPE,
"DEVELOP": APP_ENV_DEVELOP,
"LOCAL": APP_ENV_LOCAL,
"CI": APP_ENV_CI,
"PRODUCTION": APP_ENV_PRODUCTION,
Expand Down
Loading
Loading