From d557f15be70387289f9cc19e480e2ec6667f1e82 Mon Sep 17 00:00:00 2001 From: PlashSpeed-Aiman Date: Mon, 10 Oct 2022 04:12:50 +0800 Subject: [PATCH] Added Cross-Platform Dialogs --- .gitignore | 3 ++- dialog/xplatdialog.go | 7 +++++++ imaalum/imaalum.go | 36 +++++++++--------------------------- main.go | 11 ++++++----- 4 files changed, 24 insertions(+), 33 deletions(-) create mode 100644 dialog/xplatdialog.go diff --git a/.gitignore b/.gitignore index 6864e3e..df222d6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /PassGo.exe /PassGo.exe~ /Financial.pdf -/timetable.pdf \ No newline at end of file +/timetable.pdf +/cs.html diff --git a/dialog/xplatdialog.go b/dialog/xplatdialog.go new file mode 100644 index 0000000..4356f9a --- /dev/null +++ b/dialog/xplatdialog.go @@ -0,0 +1,7 @@ +package dialog + +import "github.com/sqweek/dialog" + +func XPlatMessageBox(title string, info string) { + dialog.Message(info).Title(title).Info() +} diff --git a/imaalum/imaalum.go b/imaalum/imaalum.go index c9e3000..da6c941 100644 --- a/imaalum/imaalum.go +++ b/imaalum/imaalum.go @@ -1,6 +1,8 @@ package imaalum import ( + "PassGo/dialog" + _ "PassGo/dialog" _ "PassGo/model/user" userstruct "PassGo/model/user" "encoding/base64" @@ -12,8 +14,6 @@ import ( "net/url" "os" "sync" - "syscall" - "unsafe" ) type ImaalumClient struct { @@ -82,13 +82,14 @@ func GetGeneralExamTimeTable(ws *sync.WaitGroup, client ImaalumClient) { if response.StatusCode == 200 { bodyBytes, err := io.ReadAll(response.Body) if err != nil { - MessageBoxPlain("ERROR", err.Error()) + dialog.XPlatMessageBox("ERROR", err.Error()) os.Exit(1) } _ = os.WriteFile("timetable.pdf", bodyBytes, 0644) - MessageBoxPlain("Done", "course_timetable Downloaded") + dialog.XPlatMessageBox("Done", "course_timetable Downloaded") ws.Done() + } client.client.Get("https://cas.iium.edu.my:8448/cas/logout?service=http://imaluum.iium.edu.my/") @@ -99,13 +100,13 @@ func GetConfimationSlip(ws *sync.WaitGroup, client ImaalumClient) { if response.StatusCode == 200 { bodyBytes, err := io.ReadAll(response.Body) if err != nil { - MessageBoxPlain("ERROR", err.Error()) + dialog.XPlatMessageBox("ERROR", err.Error()) os.Exit(1) } _ = os.WriteFile("cs.html", bodyBytes, 0644) - MessageBoxPlain("Done", "Download Complete") + dialog.XPlatMessageBox("Done", "Download Complete") } client.client.Get("https://cas.iium.edu.my:8448/cas/logout?service=http://imaluum.iium.edu.my/") @@ -116,33 +117,14 @@ func GetFinance(ws *sync.WaitGroup, client ImaalumClient) { if response.StatusCode == 200 { bodyBytes, err := io.ReadAll(response.Body) if err != nil { - MessageBoxPlain("ERROR", err.Error()) + dialog.XPlatMessageBox("ERROR", err.Error()) os.Exit(1) } _ = os.WriteFile("Finance.pdf", bodyBytes, 0644) - MessageBoxPlain("Done", "Download Complete") + dialog.XPlatMessageBox("Done", "Download Complete") } client.client.Get("https://cas.iium.edu.my:8448/cas/logout?service=http://imaluum.iium.edu.my/") ws.Done() } - -func MessageBox(hwnd uintptr, caption, title string, flags uint) int { - ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call( - uintptr(hwnd), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(caption))), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))), - uintptr(flags)) - - return int(ret) -} - -// MessageBoxPlain of Win32 API. -func MessageBoxPlain(title, caption string) int { - const ( - NULL = 0 - MB_OK = 0 - ) - return MessageBox(NULL, caption, title, MB_OK) -} diff --git a/main.go b/main.go index b2cbafc..611ac94 100644 --- a/main.go +++ b/main.go @@ -6,8 +6,8 @@ TODO: Encrypt Password */ import ( + "PassGo/dialog" imaalum "PassGo/imaalum" - _ "PassGo/model/user" userstruct "PassGo/model/user" "crypto/tls" "encoding/base64" @@ -49,6 +49,7 @@ AUTOMATE LOGIN TO IIUM-STUDENT WITH 2 EASY STEPS case 3: logout_network() case 4: + dialog.XPlatMessageBox("TEST", "TEST") var client = imaalum.Imaalum_login() ws.Add(3) go imaalum.GetFinance(ws, client) @@ -94,9 +95,9 @@ func logout_network() { client := &http.Client{Transport: transCfg} _, err := client.Get("https://captiveportalmahallahgombak.iium.edu.my/auth/logout.html") if err != nil { - MessageBoxPlain("ERROR", "UNABLE TO LOGOUT (I GUESS)") + dialog.XPlatMessageBox("ERROR", "UNABLE TO LOGOUT (I GUESS)") } - MessageBoxPlain("SUCCESS", "YOU ARE LOGGED OUT OF IIUM-STUDENT") + dialog.XPlatMessageBox("SUCCESS", "YOU ARE LOGGED OUT OF IIUM-STUDENT") } func connect_network() { @@ -122,13 +123,13 @@ func connect_network() { resp, err := client.PostForm("https://captiveportalmahallahgombak.iium.edu.my/cgi-bin/login", formVal) if err != nil { - MessageBoxPlain("ERROR", err.Error()) + dialog.XPlatMessageBox("ERROR", err.Error()) log.Fatal(err) } var res map[string]interface{} json.NewDecoder(resp.Body).Decode(&res) - MessageBoxPlain("SUCCESS", "You are now connected to IIUM-Student") + dialog.XPlatMessageBox("SUCCESS", "You are now connected to IIUM-Student") fmt.Println(res) }