Skip to content

Commit

Permalink
added: native dialogue for windows OS
Browse files Browse the repository at this point in the history
  • Loading branch information
Zain-ul-din committed Sep 19, 2023
1 parent 123ec93 commit e4e02bc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
71 changes: 39 additions & 32 deletions builds/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http"
"os"
"os/exec"

"github.com/sqweek/dialog"
)

func downloadFile(filepath string, url string) (err error) {
Expand Down Expand Up @@ -53,29 +55,6 @@ func install_nodejs() {
}
}

func runCommandWithProgress(command string, args ...string) error {
// Create a new command
cmd := exec.Command(command, args...)

// Redirect standard output and standard error to our program's streams
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

// Start the command
err := cmd.Start()
if err != nil {
return err
}

// Wait for the command to complete
err = cmd.Wait()
if err != nil {
return err
}

return nil
}

func load_url(url string) {
_, err := exec.Command("powershell", "-command", "start", url).Output()
if err != nil {
Expand All @@ -98,14 +77,18 @@ func run_bot() {
open_ai_url := "https://platform.openai.com/account/api-keys"
stability_ai_url := "https://platform.stability.ai/docs/getting-started/authentication"

fmt.Println("\nGet OpenAi API Key from " + open_ai_url)
load_url(open_ai_url)
if dialog.Message("Open Browser to Get OPEN AI API KEY ").YesNo() {
fmt.Println("\nGet OpenAi API Key from " + open_ai_url)
load_url(open_ai_url)
}

print("Enter OpenAI API Key OR enter NONE to skip _ ")
fmt.Scan(&open_ai_api_key)

fmt.Println("\nGet StabilityAI API Key from " + stability_ai_url)
exec.Command("start", open_ai_url)
if dialog.Message("Open Browser to Get StabilityAI API KEY ").YesNo() {
fmt.Println("\nGet StabilityAI API Key from " + stability_ai_url)
load_url(stability_ai_url)
}

print("Enter StabilityAI API Key OR enter NONE to skip _ ")
fmt.Scan(&stability_ai_api_key)
Expand All @@ -119,8 +102,7 @@ func run_bot() {
}

dot_env.WriteString("OPENAI_API_KEY=" + open_ai_api_key + "\nDREAMSTUDIO_API_KEY=" + stability_ai_api_key)

defer dot_env.Close()
dot_env.Close()

// Setup Guide
pwd, _ := os.Getwd()
Expand All @@ -129,6 +111,11 @@ func run_bot() {
println("\r OR ")
println("\r - copy & paste following code in command prompt\n pushd D: && cd " + pwd + " && npx yarn dev\n\n")

// clean up directories

os.Remove("../node-setup.msi")
os.Remove("../whatsapp-ai-bot.zip")

// run bot

run_cmd := exec.Command("powershell", "-command", "start", "./setup.exe")
Expand Down Expand Up @@ -180,7 +167,27 @@ func main() {
}

run_bot()

defer os.Remove("./node-setup.msi")
defer os.Remove("./whatsapp-ai-bot.zip")
}

// func runCommandWithProgress(command string, args ...string) error {
// // Create a new command
// cmd := exec.Command(command, args...)

// // Redirect standard output and standard error to our program's streams
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr

// // Start the command
// err := cmd.Start()
// if err != nil {
// return err
// }

// // Wait for the command to complete
// err = cmd.Wait()
// if err != nil {
// return err
// }

// return nil
// }
8 changes: 8 additions & 0 deletions builds/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module build

go 1.20

require (
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf // indirect
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf // direct
)
4 changes: 4 additions & 0 deletions builds/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf h1:pCxn3BCfu8n8VUhYl4zS1BftoZoYY0J4qVF3dqAQ4aU=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
Binary file modified builds/whatsapp-ai-bot_windows.exe
Binary file not shown.

0 comments on commit e4e02bc

Please sign in to comment.