Skip to content

Commit

Permalink
Added Cross-Platform Dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
PlashSpeed-Aiman committed Oct 9, 2022
1 parent 45df33b commit d557f15
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/PassGo.exe
/PassGo.exe~
/Financial.pdf
/timetable.pdf
/timetable.pdf
/cs.html
7 changes: 7 additions & 0 deletions dialog/xplatdialog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dialog

import "github.com/sqweek/dialog"

func XPlatMessageBox(title string, info string) {
dialog.Message(info).Title(title).Info()
}
36 changes: 9 additions & 27 deletions imaalum/imaalum.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package imaalum

import (
"PassGo/dialog"
_ "PassGo/dialog"
_ "PassGo/model/user"
userstruct "PassGo/model/user"
"encoding/base64"
Expand All @@ -12,8 +14,6 @@ import (
"net/url"
"os"
"sync"
"syscall"
"unsafe"
)

type ImaalumClient struct {
Expand Down Expand Up @@ -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/")
Expand All @@ -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/")
Expand All @@ -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)
}
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ TODO: Encrypt Password
*/

import (
"PassGo/dialog"
imaalum "PassGo/imaalum"
_ "PassGo/model/user"
userstruct "PassGo/model/user"
"crypto/tls"
"encoding/base64"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand All @@ -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)

}
Expand Down

0 comments on commit d557f15

Please sign in to comment.