-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
110 lines (103 loc) · 3.76 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html>
<head>
<title>Clipboard Sync</title>
<link rel="stylesheet" href="css/css.css">
</head>
<body>
<div class="form-box">
<form id="websocket-form" class="form">
<h2 id="status" class="status-title">Connection Status: Not Connected</h2>
<div class="inputContainer">
<input type="text" id="ws-url" class="input" placeholder="WebSocket URL" required value="ws://127.0.0.1:8765">
<label for="ws-url" class="label">WebSocket URL:</label>
</div>
<div class="inputContainer">
<input type="text" id="group" class="input" placeholder="Group Name" required value="main">
<label for="group" class="label">Group Name:</label>
</div>
<div class="inputContainer">
<input type="text" id="deviceId" class="input" placeholder="Device Name" required disabled>
<label for="group" class="label">Device Name:</label>
</div>
<button type="button" onclick="disConnect()" id="disconnect-button" class="disconnectBtn">Disconnect</button>
<button class="connectBtn" value="Connect" onclick="onConnect()" id="connect-button">Connect</button>
</form>
</div>
<!--<script src="build/clipboard-sync.js"></script>-->
<script>
let app=null
const wsUrl = document.getElementById('ws-url')
const groupName = document.getElementById('group')
const device = document.getElementById('deviceId')
const connectButton = document.getElementById('connect-button')
const disconnectButton = document.getElementById('disconnect-button')
const statusText = document.getElementById('status')
// const formBox = document.getElementById('websocket-form')
const wsUrlValue = localStorage.getItem('wsUrl')
const groupNameValue = localStorage.getItem('groupName')
// const deviceIdValue = localStorage.getItem('deviceId')
let loadLocal = false
if (wsUrlValue && groupNameValue){
loadLocal = true
wsUrl.value = wsUrlValue
groupName.value = groupNameValue
// device.value = deviceIdValue
onConnect()
}
if (!device.value){
setTimeout(() => {
device.value = window.osName
}, 1000)
}
function statusUpdate(status) {
if (status.status){
wsUrl.disabled = true
groupName.disabled = true
// device.disabled = true
connectButton.style.display = 'none'
disconnectButton.style.display = 'block'
}else {
wsUrl.disabled = false
groupName.disabled = false
// device.disabled = false
connectButton.style.display = 'block'
disconnectButton.style.display = 'none'
}
if (status.message){
statusText.innerText = status.message
}
}
window.ipc_statusChange = statusUpdate
statusUpdate({status:false})
function onConnect() {
if (!groupName.value || !wsUrl.value){
alert('Please enter a group name and a WebSocket URL')
return;
}
localStorage.setItem('wsUrl', wsUrl.value)
localStorage.setItem('groupName', groupName.value)
// localStorage.setItem('deviceId', device.value)
// app = window.initApp({
// wsUrl: wsUrl.value,
// groupName: groupName.value,
// deviceId: device.value,
// statusCallback: (status) => {
// statusUpdate(status)
// }
// })
window.ipc_connectServer({
wsUrl: wsUrl.value,
groupName: groupName.value
})
}
function disConnect() {
// if (app){
// app.disconnect()
// app = null
// }
window.ipc_disconnectServer()
}
</script>
</body>
</html>