-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweaks to the Web interface #108
base: master
Are you sure you want to change the base?
Changes from 3 commits
15e5120
7fca6ad
66ec727
43df48b
ed4643e
18915c9
53d4778
a7eb1f0
30e2524
74e7dbd
a7c22ac
8c99f57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,12 @@ | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Sunshine</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected].0/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous"> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"> | ||
</script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" | ||
crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,64 @@ | ||
|
||
<div id="content" class="container"> | ||
<h1 class="my-4">PIN Pairing</h1> | ||
<form action="" class="form d-flex flex-column align-items-center" id="form"> | ||
<div class="card flex-column d-flex p-4 mb-4"> | ||
<input type="number" placeholder="PIN" id="pin-input" class="form-control my-4"> | ||
<button class="btn btn-primary">Send</button> | ||
</div> | ||
<div class="alert alert-warning"> | ||
<b>Warning!</b> Make sure you have access to the client you are pairing with.<br> | ||
This software can give total control to your computer, so be careful! | ||
<main role="main"> | ||
<div class="container-parent bg-light"> | ||
<div class="container py-3"> | ||
<h1>Pair a new device</h1> | ||
<p class="mb-0">Allow a new client to connect to this computer by entering the PIN code given by Moonlight here. | ||
</p> | ||
</div> | ||
</div> | ||
<div class="container-parent"> | ||
<div class="container py-3"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-6"> | ||
<div class="alert alert-warning" role="alert"> | ||
<strong>Warning!</strong> Make sure you have access to the client you are pairing with.<br /> This software | ||
can give total control to your computer, so be careful! | ||
</div> | ||
<form action="#" id="form"> | ||
<div class="mb-3"> | ||
<label for="input" class="form-label">PIN code</label> | ||
<input type="text" class="form-control form-control-lg" id="input" name="pin" placeholder="1234" | ||
minlength="4" maxlength="4" required /> | ||
<div class="valid-feedback">Pairing successful! Please check Moonlight to continue!</div> | ||
<div class="invalid-feedback">The given PIN code doesn't match, please check that it's typed correctly. | ||
</div> | ||
</div> | ||
<button type="submit" id="submit" class="btn w-100 btn-primary">Pair new device</button> | ||
</form> | ||
</div> | ||
<div id="status"></div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
|
||
<script> | ||
document.querySelector("#form").addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
let pin = document.querySelector("#pin-input").value; | ||
document.querySelector("#status").innerHTML = ""; | ||
let b = JSON.stringify({pin: pin}); | ||
fetch("/api/pin",{method: "POST",body: b}).then((response) => response.json()).then((response)=>{ | ||
if(response.status){ | ||
document.querySelector("#status").innerHTML = `<div class="alert alert-success" role="alert">Success! Please check Moonlight to continue</div>`; | ||
} else { | ||
document.querySelector("#status").innerHTML = `<div class="alert alert-danger" role="alert">PIN does not match, please check if it's typed correctly</div>`; | ||
} | ||
}) | ||
}) | ||
/** @type HTMLFormElement */ | ||
const formElement = document.querySelector("form#form"); | ||
/** @type HTMLInputElement */ | ||
const input = formElement.querySelector("input#input"); | ||
/** @type HTMLButtonElement */ | ||
const submit = formElement.querySelector("button#submit"); | ||
|
||
formElement.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
submit.disabled = true; | ||
// TODO: Check for empty or null values | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. required on PIN should be enough IIRC |
||
const body = JSON.stringify({ pin: input.value }); | ||
fetch("/api/pin", { method: "POST", body }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove both is-valid and is-invalid before fetching? This way the feedback does not stay on screen while making multiple calls |
||
.then((response) => response.json()) | ||
.then((response) => { | ||
submit.disabled = false; | ||
if (response.status === "true") { | ||
input.classList.add("is-valid"); | ||
input.classList.remove("is-invalid"); | ||
} else { | ||
input.classList.add("is-invalid"); | ||
input.classList.remove("is-valid"); | ||
} | ||
}) | ||
.catch((err) => { | ||
submit.disabled = false; | ||
console.error(err); | ||
}); | ||
}); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this a type="number" can help on mobile keyboard, since it will show only the numbers on smartphones