Skip to content

Commit

Permalink
Merge pull request #24 from riskycase/vitefy
Browse files Browse the repository at this point in the history
Vitefy
  • Loading branch information
riskycase authored Nov 17, 2022
2 parents 22e5f8d + aaf500d commit bdc313c
Show file tree
Hide file tree
Showing 25 changed files with 4,034 additions and 512 deletions.
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Preact + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
3,826 changes: 3,540 additions & 286 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 23 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
{
"name": "auto-campnet-gui",
"version": "0.2.1",
"scripts": {
"tauri": "tauri",
"dev": "tauri dev",
"build": "tauri build",
"tauricon": "tauricon"
},
"dependencies": {
"@tauri-apps/api": "^1.1.0"
},
"devDependencies": {
"@tauri-apps/cli": "^1.1.1"
}
"name": "auto-campnet-gui",
"version": "1.0.0",
"scripts": {
"tauri": "tauri",
"dev": "vite",
"build": "tsc && vite build",
"tauricon": "tauricon"
},
"dependencies": {
"@cred/neopop-web": "^1.0.0",
"@tauri-apps/api": "^1.1.0",
"axios": "^1.1.3",
"preact": "^10.11.2",
"querystring": "^0.2.1",
"sass": "^1.55.0"
},
"devDependencies": {
"@preact/preset-vite": "^2.4.0",
"@tauri-apps/cli": "^1.1.1",
"@types/node": "^18.11.7",
"typescript": "^4.8.4",
"vite": "^3.2.0"
}
}
1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "app"
version = "0.2.1"
version = "1.0.0"
description = "Connect to BITS Goa campus network automatically"
authors = ["Hrishikesh Patil <hrishikeshpatil.754@gmail.com>"]
license = "MIT"
Expand All @@ -17,7 +17,7 @@ tauri-build = { version = "1.1.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0.144", features = ["derive"] }
tauri = { version = "1.1.1", features = ["fs-create-dir", "fs-read-dir", "fs-read-file", "fs-remove-file", "fs-write-file", "notification", "notification-all", "path-all", "system-tray", "window-hide", "window-show", "window-start-dragging"] }
tauri = { version = "1.1.1", features = ["fs-create-dir", "fs-read-dir", "fs-read-file", "fs-remove-file", "fs-write-file", "http-all", "notification", "notification-all", "path-all", "system-tray", "window-hide", "window-show", "window-start-dragging"] }
timer = "0.2.0"
chrono = "0.4.22"
reqwest = { version = "0.11.11", features = ["blocking"] }
Expand Down
22 changes: 12 additions & 10 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"package": {
"productName": "Auto Campnet GUI",
"version": "0.2.1"
"version": "1.0.0"
},
"build": {
"distDir": "../ui",
"devPath": "../ui",
"beforeDevCommand": "",
"beforeBuildCommand": "",
"distDir": "../dist",
"devPath": "http://localhost:5173",
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"withGlobalTauri": true
},
"tauri": {
Expand Down Expand Up @@ -98,17 +98,19 @@
"startDragging": true,
"unmaximize": false,
"unminimize": false
},
"http": {
"all": true,
"request": true,
"scope": ["https://campnet.bits-goa.ac.in:8093/*"]
}
},
"windows": [
{
"title": "Auto Campnet",
"width": 300,
"height": 500,
"resizable": false,
"fullscreen": false,
"decorations": true,
"center": true,
"minHeight": 400,
"minWidth": 360,
"visible": false
}
],
Expand Down
5 changes: 5 additions & 0 deletions src/app.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.mainContainer {
display: flex;
padding: 1rem;
align-items: center;
}
46 changes: 46 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import styles from "./app.module.scss";
import { emit, listen, Event } from "@tauri-apps/api/event";
import { Login } from "./components/login/login";
import { ElevatedCard, ToastContainer } from "@cred/neopop-web/lib/components";
import { useEffect, useState } from "preact/hooks";
import { DataBalance } from "./components/dataBalance/dataBalance";
import { Credentials } from "./types";

export function App() {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");

useEffect(() => {
listen("credentials", (creds: Event<Credentials>) => {
setUsername(creds.payload.username);
setPassword(creds.payload.password);
});
}, []);

document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") emit("minimise");
});

return (
<div>
<ToastContainer />
<ElevatedCard
backgroundColor="#0D0D0D"
edgeColors={{
bottom: "#161616",
right: "#121212",
}}
>
<div class={styles.mainContainer}>
<Login
username={username}
password={password}
setUsername={setUsername}
setPassword={setPassword}
/>
<DataBalance username={username} password={password} />
</div>
</ElevatedCard>
</div>
);
}
Binary file added src/assets/bitslogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/components/dataBalance/dataBalance.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.dataContainer {
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: 'Times New Roman', Times, serif;
@media screen and (max-width: 640px) {
display: none;
}
}
124 changes: 124 additions & 0 deletions src/components/dataBalance/dataBalance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { ScoreMeter } from "@cred/neopop-web/lib/components";
import { fetch, getClient, Body, ResponseType } from "@tauri-apps/api/http";
import { useEffect, useState } from "preact/hooks";

import styles from "./dataBalance.module.scss";

export function DataBalance(props: { username: string; password: string }) {
const [datas, setDatas] = useState<Array<number>>([1, 0, 0, 1, 0]);
const [units, setUnits] = useState<Array<string>>(["", "", "", "", ""]);
const [balanceTimeout, setBalanceTimeOut] = useState<NodeJS.Timeout>();

useEffect(() => {
clearTimeout(balanceTimeout);
getBalance();
}, [props]);
console.log(datas);

function getBalance() {
let cookie = "";
let csrf = "";
getClient({ maxRedirections: 1 }).then((client) =>
client
.post(
"https://campnet.bits-goa.ac.in:8093/userportal/Controller",
Body.form({
mode: "451",
json: JSON.stringify({
username: props.username,
password: props.password,
languageid: 1,
browser: "Chrome_106",
}),
})
)
.then(
(res) => (cookie = res.headers["set-cookie"].split(";")[0])
)
.then(() =>
fetch(
"https://campnet.bits-goa.ac.in:8093/userportal/webpages/myaccount/index.jsp",
{
method: "GET",
headers: {
Cookie: cookie,
},
responseType: ResponseType.Text,
}
)
)
.then((res) => {
//@ts-ignore
csrf = String(res.data).match(/k3n = '(.+)'/)[1];
})
.then(() =>
client.get(
"https://campnet.bits-goa.ac.in:8093/userportal/webpages/myaccount/AccountStatus.jsp",
{
headers: {
Cookie: cookie,
"X-CSRF-Token": csrf,
Referer:
"https://campnet.bits-goa.ac.in:8093/userportal/webpages/myaccount/login.jsp",
},
query: {
popup: `${0}`,
t: `${Date.now()}`,
},
responseType: ResponseType.Text,
}
)
)
.then((res: any) => {
const nodes = new DOMParser().parseFromString(
res.data,
"text/html"
);
const trimmedNodes = [
...nodes
.querySelector("#content3")
?.querySelectorAll("td.tabletext")!!
].slice(-5);
setDatas(
trimmedNodes.map((iter: any) =>
Number(
(
iter.childNodes[0].nodeValue as string
).trim()
)
)
);
setUnits(
trimmedNodes.map((iter: any) =>
iter.children[0].id.replace(/Language./, "")
)
);
})
.then(() => setBalanceTimeOut(setTimeout(getBalance, 15000)))
.catch((err) => console.error(err))
);
}

return (
<div class={styles.dataContainer}>
<ScoreMeter
key={datas[4]}
reading={Math.round(datas[4])}
oldReading={0}
lowerLimit={0}
upperLimit={datas[0]}
scoreDesc={units[4]}
type={
datas[4] < datas[0] / 5
? "poor"
: datas[4] < datas[0] / 3
? "average"
: "excellent"
}
/>
<span>Data Limit: {`${datas[0]} ${units[0]}`}</span>
<span>Data Used: {`${datas[3]} ${units[3]}`}</span>
<span>Data Left: {`${datas[4]} ${units[4]}`}</span>
</div>
);
}
17 changes: 17 additions & 0 deletions src/components/login/login.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.loginContainer {
display: flex;
flex-direction: column;
align-items: center;
max-width: 20rem;
padding: 1rem;
}

.loginContainer > * {
margin: 0.5rem 0;
}

.bitsLogo {
margin: 1rem 0;
height: 6.5rem;
width: 100%;
}
Loading

0 comments on commit bdc313c

Please sign in to comment.