Skip to content

Commit

Permalink
Update error-handling, versions, and styles
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Oct 9, 2023
1 parent f38e76e commit cf78a4e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<body>
<div class="container">
<h1>Solidarity ✊</h1>
<hr/>
<main>
<div id="console">
<ul id="messages"></ul>
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"@commoners/bluetooth": "0.0.0",
"@commoners/serial": "0.0.0",
"@commoners/local-services": "0.0.0",
"commoners": "0.0.16"
"commoners": "0.0.17"
}
}
34 changes: 20 additions & 14 deletions src/frontend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,24 @@ if (COMMONERS.services.remote && COMMONERS.services.dynamic) {
if (COMMONERS.services.node) {
const url = new URL(COMMONERS.services.node.url)

const ws = new WebSocket(`ws://${url.host}`)
try {
const ws = new WebSocket(`ws://${url.host}`)

ws.onmessage = (o) => {
const data = JSON.parse(o.data)
onData({source: 'Node', ...data})
}
ws.onmessage = (o) => {
const data = JSON.parse(o.data)
onData({source: 'Node', ...data})
}

let send = (o: any) => {
ws.send(JSON.stringify(o))
}
let send = (o: any) => {
ws.send(JSON.stringify(o))
}

ws.onopen = () => {
send({ command: 'platform' })
send({ command: 'version' })
ws.onopen = () => {
send({ command: 'platform' })
send({ command: 'version' })
}
} catch (e) {
console.error('Failed to connect to Node.js server', e)
}
}

Expand All @@ -112,9 +116,11 @@ if (COMMONERS.services.python) {
const pythonUrl = new URL(COMMONERS.services.python.url) // Equivalent to commoners://python

setTimeout(async () => {
fetch(new URL('version', pythonUrl)).then(res => res.json()).then(payload => {
onData({ source: 'Python', command: 'version', payload })
});
try {
fetch(new URL('version', pythonUrl)).then(res => res.json()).then(payload => onData({ source: 'Python', command: 'version', payload }));
} catch (e) {
console.error('Failed to connect to Python server', e)
}
})
}

Expand Down
8 changes: 6 additions & 2 deletions src/frontend/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ main {
flex-direction: row-reverse;
}

#sidebar {
main > * {
flex-grow: 1
}

Expand Down Expand Up @@ -97,8 +97,12 @@ a:hover {
color: #535bf2;
}


h1 {
text-align: center;
margin: 0;
margin-bottom: 10px;
padding-bottom: 20px;
border-bottom: 1px solid gainsboro;
}

input,
Expand Down

0 comments on commit cf78a4e

Please sign in to comment.