Skip to content

Commit

Permalink
Filter out something of lastline on the comm ladder, added support …
Browse files Browse the repository at this point in the history
…for OKB 1.8, and some secret other feature
  • Loading branch information
AviiNL committed Apr 1, 2024
1 parent 29b5c17 commit 93b9be6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Options:
-V, --version Print version
```

### Hidden feature (ssh, don't tell anyone)
If you append `#width=2048` or some other number to the url `http://127.0.0.1:7878/#width=...` you can override the rendering width of the page.

[find-local-ip]: https://support.microsoft.com/en-us/windows/find-your-ip-address-in-windows-f21a9bbc-c582-55cd-35e0-73431160a1b9
[config-manager]: assets/config-manager.png
[preview]: assets/preview.png
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,24 @@ async fn index() -> Html<String> {
println!("{:?}", e);
return Html(String::from("501"));
}
let mut commladder = Comm::from_briefing(&buf);

commladder.iter_mut().for_each(|c| {
if let Some(callsign) = c.callsign.as_mut() {
if let Some(c) = callsign
.split(|c: char| !c.is_alphanumeric() && !c.is_whitespace() && c != '-')
.next()
{
*callsign = c.to_string();
}
};
});

Html(
Index {
package_elements: PackageElement::from_briefing(&buf),
steerpoints: Steerpoint::from_briefing(&buf),
commladder: Comm::from_briefing(&buf),
commladder,
}
.call()
.unwrap(),
Expand Down
46 changes: 35 additions & 11 deletions templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,44 @@
</tbody>
</table>
<script defer>
let data = {
"message": "OpenKneeboard/SimHub/DashboardLoaded",
"data": {
"width": 1024,
"height": document.body.clientHeight,
// http://127.0.0.1:7878/#width=2048
{
let h = window.location.hash;
let settings = {};
if (h.length > 0) {
h = h.substring(1);
const parts = h.split('&');
for (const part of parts) {
console.log(part);
const kvp = part.split('=');
if (kvp.length == 2) {
let value = kvp[1];
try {
settings[kvp[0]] = JSON.parse(kvp[1]);
} catch (e) {
settings[kvp[0]] = kvp[1];
}
}
}
}
};
console.log(data);
// Backwards compatibility pre 1.8
window?.chrome?.webview?.postMessage(data);
let page_width = settings.width || 1024;
let data = {
"message": "OpenKneeboard/SimHub/DashboardLoaded",
"data": {
"width": page_width,
"height": document.body.clientHeight,
}
};
// 1.8 and up will support this method to set size
window?.OpenKneeboard?.SetPreferredPixelSize(1024, document.body.clientHeight);
// Backwards compatibility pre 1.8
window?.chrome?.webview?.postMessage(data);
// 1.8 and up will support this method to set size
window?.OpenKneeboard?.SetPreferredPixelSize(page_width, document.body.clientHeight);

This comment has been minimized.

Copy link
@fredemmott

fredemmott Apr 2, 2024

The ?. only checks that window.OpenKneeboard exists, not that window.OpenKneeboard.SetPreferredPixelSize() exists, so this should raise an error on OpenKneeboard v1.7

Would recommend this instead:

if (window.OpenKneeboard?.SetPreferredPixelSize) {
  window.OpenKneeboard.SetPreferredPixelSize(width, height);
} else if (window.OpenKneeboard) {
  // send webview simhub message for v1.7 here
}

This comment has been minimized.

Copy link
@AviiNL

AviiNL Apr 2, 2024

Author Owner

Good point, thanks!

}
</script>
</body>
Expand Down

0 comments on commit 93b9be6

Please sign in to comment.