936 Commits

Author SHA1 Message Date
Michael Lynch
260d524ab8 Use ruff to enforce Python docstring conventions (#1633)
We've been enforcing Python docstring conventions purely through code
review, but ruff can enforce some of the conventions automatically.

I've adjusted some of our docstrings to match ruff's expectations.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1633"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-25 12:21:54 -04:00
Michael Lynch
c4b2a8beec Replace pylint-quotes with ruff (#1635)
ruff can replicate the same functionality as pylint-quotes but with
faster performance and fewer extra tools, so this replaces pylint-quotes
with ruff.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1635"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-25 07:52:50 -04:00
Michael Lynch
85bebeb2a2 Replace isort with ruff (#1632)
Replace isort with ruff. ruff is *way* faster and does the same checks.
It gives us about a 35x performance improvement over isort:

### isort

```bash
$ time isort \
  --recursive \
  --force-single-line-imports \
  --top log \
  --diff \
  --check-only \
  --skip-glob=third_party/* \
  --skip-glob=venv/*

Skipped 2073 files

real    0m1.975s
user    0m1.743s
sys     0m0.229s
```

### ruff

```bash
$ time ruff check \
  app/ \
  scripts/render-template \
  scripts/update-service

real    0m0.063s
user    0m0.014s
sys     0m0.073s
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1632"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-22 12:05:21 -04:00
Michael Lynch
f422a80395 Replace pyflakes with ruff (#1631)
[ruff](https://docs.astral.sh/ruff/) applies the same checks as
pyflakes, but it has additional customizations and supports a wider
range of rules, so let's replace pyflakes with the equivalent ruff
checks.

Replacing pyflakes isn't so interesting because pyflakes is already
pretty fast, but we'll get a nice speedup from replacing isort (see
#1632) and consolidating dev tools.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1631"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-22 12:01:06 -04:00
Michael Lynch
3307d5d35f Bring back --allow-releaseinfo-change-suite (#1630)
In #776, we added the `--allow-releaseinfo-change-suite` to avoid
erroring out if the Raspbian apt repo changed suite names.

In #1604, we deleted the `apt update` command entirely, as it seemed
unnecessary after deleting Ansible.

In #1623, we brought back the `apt update` command, but we left off the
flag we were previously using.

In recent installs, I'm seeing this warning:

```bash
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Repository 'http://raspbian.raspberrypi.org/raspbian bullseye InRelease' changed its 'Suite' value from 'stable' to 'oldstable'
Reading package lists... Done
```

For the sake of preserving longstanging behavior, I think we should
bring back the `--allow-releaseinfo-change-suite` flag.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1630"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-22 09:50:14 -04:00
Jason Wallace
2d411f3b70 Consume paste API endpoint (#1626)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1026

This PR consumes the new `/api/paste` endpoint and removes the,
now-unused, text-to-keystroke frontend logic.

Demo video:


https://github.com/tiny-pilot/tinypilot/assets/6730025/2b3cb2c9-964b-4e90-88c9-7ab13775f02b

### Notes
1. Pasting unsupported characters (i.e., `“`, `”`, `–` (en-dash), `—`
(em-dash), etc.) now displays this error dialog:
    
<img width="870" alt="Screen Shot 2023-09-15 at 11 20 21"
src="https://github.com/tiny-pilot/tinypilot/assets/6730025/1ebad5a7-fbb6-40f4-a9fe-317a06d458a8">

Previously, these unsupported characters were silently ignored during a
paste.
As [discussed
here](https://github.com/tiny-pilot/tinypilot/pull/1545#issuecomment-1711939987),
we plan to further refine this behavior in the future.

### Peer testing
This PR is stacked onto the following PRs:
* https://github.com/tiny-pilot/tinypilot/pull/1625
* https://github.com/tiny-pilot/tinypilot/pull/1624

You can test them all on device via the following command:
```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- https://output.circle-artifacts.com/output/job/d842ed53-55a6-490d-9cfd-842155c7d6e5/artifacts/0/bundler/dist/tinypilot-community-20230919T1127Z-1.9.1-39+3e308b3.tgz && \
  sudo reboot
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1626"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-19 14:35:53 +02:00
Jason Wallace
da6f5f0897 Add paste API endpoint (#1625)
Related https://github.com/tiny-pilot/tinypilot/issues/1026

This PR adds an API endpoint that accepts text, parses each text
character to a HID keystroke, and asynchronously sends all keystrokes to
the target machine.

### Notes
1. By writing the keystrokes in a background thread, separate from main
thread that runs the HTTP server and SocketIO server, we avoid blocking
HTTP requests and WebSocket messages ([that unexpectedly disconnected
the client during a large
paste](https://github.com/tiny-pilot/tinypilot/issues/1026)).
* The background thread that writes the pasted text, is run in a "fire
and forget" manner which means we no longer report on the success or
failure of the HID file IO. However, a single write error will abort
further keystrokes from being written.

### Peer testing
You can test this PR on device via the following stacked PR:
* https://github.com/tiny-pilot/tinypilot/pull/1626

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1625"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-19 13:14:28 +02:00
Jason Wallace
3a7fe4ac65 Port text to HID keystroke logic (#1624)
Related https://github.com/tiny-pilot/tinypilot/issues/1026

This PR ports TinyPilot's "paste" functionality from the fontend to the
backend, by parsing the pasted text into HID keystrokes on the server.

This PR copies the functionality of the following JS files to Python
files, without modifying any existing code:
*
[`app/static/js/keycodes.js`](3de1916aa5/app/static/js/keycodes.js)
->
[`app/text_to_hid.py`](3de1916aa5/app/text_to_hid.py)
*
[`app/static/js/keycodes.test.js`](3de1916aa5/app/static/js/keycodes.test.js)
->
[`app/text_to_hid_test.py`](3de1916aa5/app/text_to_hid_test.py)

### Notes
1. I've changed the way that we determine if a text character (e.g.,
`A`) requires a key modifier (e.g., left shift) when being typed on a
keyboard. Instead of [all keyboard languages matching against a single
regex](3de1916aa5/app/static/js/keycodes.js (L102-L106)),
we now map a [text character on a specific language keyboard directly to
a HID
keystroke](3de1916aa5/app/text_to_hid.py (L132-L133)).
This should allow us to avoid ambiguity between keyboard languages and
support more text characters.

### Peer testing
You can test this PR on device via the following stacked PR:
* https://github.com/tiny-pilot/tinypilot/pull/1626

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1624"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-19 12:56:00 +02:00
Jason Wallace
410d472258 Add HID Keystroke class (#1629)
Related https://github.com/tiny-pilot/tinypilot/issues/1026

This PR introduces the HID `Keystroke` class that represents a
combination of HID keycode and HID modifier. This PR replaces the use of
individual `keycode` and `modifier`/`control_keys` variables with a
single `keystroke` variable.

This is a non-functional change that simplifies the way we represent HID
Keystrokes in anticipation for parsing text to HID keystrokes via
https://github.com/tiny-pilot/tinypilot/pull/1624

### Notes:
1. In https://github.com/tiny-pilot/tinypilot/pull/1625, we parse `text`
+ `language` directly to HID keystrokes in a
[`request_parser`](df246c8305/app/request_parsers/paste.py (L6-L44)).
Ideally, I'd like to do the same when [parsing JS keystroke WebSocket
messages](60fe150efe/app/request_parsers/keystroke.py (L40-L58))
which are [polluting `socket_api.py` with JS-to-HID conversion
logic](60fe150efe/app/socket_api.py (L23-L33)).
This kind of change would cause some churn, so I did not implement that
here.
2. I removed a piece of dead-code. From what I understand, this `if`
statement can never be truthy.

c972446e53/app/socket_api.py (L35-L38)

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1629"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-19 12:27:46 +02:00
Jason Wallace
c972446e53 Log message when update is complete (#1627)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1466

When updating TinyPilot via the web UI, if you're watching the detailed
update logs it's easy to miss when the update has actually completed.

This PR adds the following messages to the update-dialog's update logs:
> Restarting to complete update...
> Update is now complete.

Demo video:


https://github.com/tiny-pilot/tinypilot/assets/6730025/378c0a23-f02e-4bae-a2d7-1113a12891c1

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1627"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-18 11:21:15 +02:00
Michael Lynch
e52b808095 Enforce consistent string quoting rules (#1628)
Add the pylint-quotes pylint plugin to the build to ensure we use
consistent string quoting conventions throughout our Python code.

We had a few stray instances of inconsistent strings, so I fixed them in
this change as well.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1628"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-15 07:04:33 -04:00
Jason Wallace
dd8f36e350 Override Janus systemd config (#1622)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1578

This PR overrides the default Janus systemd config in order set
additional systemd settings. Specifically:
```diff
 [Unit]
 Description=Janus WebRTC gateway
 After=network.target
 Documentation=https://janus.conf.meetecho.com/docs/index.html
+# Give up if we restart on failure 20 times within 5 minutes (300 seconds).
+StartLimitIntervalSec=300
+StartLimitBurst=20

 [Service]
 Type=forking
 ExecStart=/usr/bin/janus --disable-colors --daemon --log-stdout
 Restart=on-failure
+RestartSec=1
 LimitNOFILE=65536

 [Install]
 WantedBy=multi-user.target
```

Janus with STUN requires the network to be online, otherwise `janus`
fails to start. Theses additional settings are needed to allow Janus
with STUN settings a better chance of starting up successfully, by
giving it more chances to restart on failure. Seeing as STUN is an
optional setting, we didn't want Janus to always require an online
network because it might unnecessarily delay TinyPilot's H.264 video
stream.

### Testing

To enable STUN, append the following block to `/etc/janus/janus.jcfg`:

```
nat: {
  stun_server = "stun.gmx.de"
  stun_port = 3478
}
```

Now if you restart your device, the `janus` service should start
successfully on boot. On my device `janus` restarted 8 times in 12
seconds before successfully running.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1622"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-14 13:09:48 +02:00
Jason Wallace
e592a568ae Update apt package lists before install (#1623)
Resolves https://github.com/tiny-pilot/tinypilot-pro/issues/1074

This PR runs `apt-get update` before installing our Debian packages to
ensure that the APT package index is up-to-date.

I have tested this fix in TinyPilot Pro:
* https://github.com/tiny-pilot/tinypilot-pro/pull/1075

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1623"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-13 14:07:20 +02:00
Jason Wallace
9fa16162fc Maintain h.264 video stream when target machine is switched off (#1619)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1487

This PR refactors our remote-screen WebRTC API to allow media tracks to
be added/removed without automatically enabling/disabling the WebRTC
streaming mode. This gives more responsibility to the (function) caller,
but also gives more control in deciding when to change streaming modes.

Demo video:


https://github.com/tiny-pilot/tinypilot/assets/6730025/d891fbcb-1cea-41fe-b775-948b5a9879e6

Notes
1. We've renamed `enableWebrtcStreamTrack` -> `addWebrtcStreamTrack`
* This method no longer enables WebRTC mode (i.e., shows the video
element)
1. We've renamed `disableWebrtcStreamTrack` -> `removeWebrtcStreamTrack`
* This method no longer disables WebRTC mode (i.e., hides the video
element)
1. WebRTC mode can now both be enabled and have zero media tracks
    * This was the cause of the original bug
1. The remote-screen will still failover to MJPEG when the connection to
Janus fails, but will not try to reconnect until a full page refresh

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1619"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-12 12:56:18 +02:00
Jason Wallace
fb4b253066 Refactor HID write timeout logic (#1621)
Related https://github.com/tiny-pilot/tinypilot/issues/1026

This PR moves the multiprocessing timeout logic to a separate `execute`
module, along with other related classes. This change simplifies the
`hid.write` module by stripping out multiprocessing details not directly
related to writing to the HID interface.

### Notes
1. We've moved the following classes to the new `execute` module:
    * `ProcessWithResult`
    * `ProcessResult`
1. We've moved the HID write timeout logic to a generic
`execute.with_timeout` function
2. We've moved `hid.write_test.py` to `execute_test.py`
3. I'm not really sure why we need this function or if it is still
required, but I kept it around anyway:

106e6448bd/app/process.py (L84-L87)

### Peer testing
You can test this build by running the following command on a device:
```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/5789b04e-8216-42fe-ad1e-227948464d03/artifacts/0/bundler/dist/tinypilot-community-20230907T1543Z-1.9.1-12+e1ba857.tgz
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1621"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-08 13:19:12 +02:00
Jason Wallace
de10f0fc50 Consolidate CircleCI config (#1613)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1612

In anticiaption of getting rid of Ansible via
https://github.com/tiny-pilot/tinypilot/issues/1596, this PR simplifies
our CircleCI config by removing the need for dynamic path-filtering.

This PR was created in the following way:
1. Deletes the previous `.circleci/config.yml` file
2. Renames `.circleci/continue_config.yml` to `.circleci/config.yml`
3. Removes the `ansible_role_changed` CircleCI pipeline parameter

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1613"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-04 16:20:08 +02:00
Michael Lynch
9f547d2b85 Delete Ansible from installation process (#1604)
Resolves #1598
Resolves #1596

This reimplements the `load-tc358743-edid` service without Ansible,
which completes our process of eliminating Ansible from TinyPilot's
install process.

The last real piece was moving the installation of the
`load-tc358743-edid` from Ansible to Debian. The rest is just deleting
remaining Ansible files and stray references to Ansible.

Note that in deleting the Ansible environment setup, we delete `apt-get
update --allow-releaseinfo-change-suite` which we added in
https://github.com/tiny-pilot/tinypilot/issues/764. I don't think we
need this command anymore, but we can bring it back in the future if we
find that we need it.

## Manual tests

I ran the following manual tests:

* Verified keyboard and mouse still worked
* Verified that I could still adjust video settings
* Verified that audio still worked in H.264 (on Voyager systems)

For the following scenarios:

- [x] Install on a bare Raspbian system
- [x] Install on a bare Raspbian system with TC358743 enabled
- [x] Install a Pro Voyager image
- [x] Install a Pro Hobbyist image
- [x] Install a bundle on a Pro 2.6.0 Voyager image to simulate an
update

## Peer testing

To test this bundle run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/a5f0e73a-fc7b-4025-b6ce-c8f05c4be707/artifacts/0/bundler/dist/tinypilot-community-20230901T1513Z-1.9.0-109+51dc0af.tgz && \
  sudo reboot
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1604"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>

---------

Co-authored-by: David Brown <dave@sterki.co>
1.9.1
2023-09-01 17:28:48 -04:00
Michael Lynch
a7cc8d036b Fix tc358743 identifier in the /boot/config.txt population (#1617)
This fixes a small bug in the tinypilot.postinst that was preventing it
from matching the right line in `/boot/config.txt` to add the
`dtoverlay=tc358743-audio` line.

## Peer testing

To test this bundle run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/0bcd7da3-9a88-4126-ada8-6a7804e02dfe/artifacts/0/bundler/dist/tinypilot-community-20230901T1500Z-1.9.0-75+03827f4.tgz && \
  sudo reboot
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1617"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-01 13:34:32 -04:00
cghague
5bf016477c Update collect-debug-logs script to include userland architecture (#1611)
Related https://github.com/tiny-pilot/tinypilot-pro/issues/1030.

Raspberry Pi OS now updates the kernel on 32-bit installations to the
64-bit kernel while simultaneously keeping the userland as 32-bit, which
means that it isn't possible to accurately determine if the user is
running a 64-bit system based on the output of `uname --all`.

This change adds additional information to the `collect-debug-logs`
script, allowing us to detect when a user is running TinyPilot on an
unsupported architecture. It also slightly reformats the relevant
section for readability.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1611"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-01 18:03:11 +01:00
Michael Lynch
550619e944 Populate TC358743 EDID file without Ansible (#1616)
Related #1598

In continuing our elimination of Ansible, this reimplements the logic to
populate the TC358743 EDID file (at
`/home/ustreamer/edids/tc358743-edid.hex`) without Ansible.

We preserve the existing behavior that if the user has overridden the
desired EDID by specifying a different value for `ustreamer_edid`, then
we use that value when we populate
`/home/ustreamer/edids/tc358743-edid.hex` on the next install.

The output of our `decode_edid` step changes because we're using a
different version of the Docker image which seems to pull down a
different version of the `decode-edid` which uses slightly different
output formatting, but the values are all the same.

I was originally bundling this with #1604, but that PR is pretty large
since it eliminates Ansible entirely, so I'm pulling out a small piece
here.

## Peer testing

To test this bundle run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/4a10bf35-34f1-4924-8af3-52f3dea7217a/artifacts/0/bundler/dist/tinypilot-community-20230901T1402Z-1.9.0-77+4903bc6.tgz
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1616"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-01 10:54:39 -04:00
Michael Lynch
ed0d1fa375 Prevent tinypilot.postinst from appending to Janus config (#1615)
There was a bug in the tinypilot.postinst where we were appending to an
existing janus.plugin.ustreamer.jcfg file instead of the intended
behavior of recreating the file fresh on each install.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1615"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-01 09:36:24 -04:00
Michael Lynch
92298b427c Replace cryptography project test in e2e tests (#1614)
Our e2e tests make sure that links work for a project that has a license
hosted outside the device (at a web URL). Our current test uses
cryptography as this project, but we're removing cryptography as a
dependency in #1596 and #1604, so we need to pick another project to
exercise in our e2e tests.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1614"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-01 08:44:32 -04:00
db39
6269be14b5 Reimplement /boot/config.txt logic in postinst script (#1602)
Resolves #1594

These changes remove some `ansible` tasks relating to the
`/boot/config.txt` logic and re-implements them using
`tinypilot.postinst` instead.

To test on a live device:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/743a657b-dbde-48b6-912e-01ee511631f0/artifacts/0/bundler/dist/tinypilot-community-20230901T1138Z-1.9.0-72+c746cda.tgz
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1602"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-09-01 13:29:12 +01:00
Michael Lynch
50e7e58347 Install yq without Ansible (#1608)
Resolves #1595

As part of our continuing effort to eliminate Ansible from our install
process, this installs yq from within the bundle installer rather than
during Ansible.

This is a slight implementation change in that we no longer download the
yq binary at install time and instead pre-download it and include it in
the TinyPilot bundle. This is preferable, as it does more work in the
packaging stage and less work on user devices, though it does increase
the size of our bundles by a few megabytes.

While we're here, we're also upgrading to the latest version of yq, so
we're upgrading from `v4.30.6` to `v4.35.1`.

### Manual tests

For expediency, I tested builds that combined:

* #1605
* #1606 
* #1608

For the manual tests, I verified:

* Video works under MJPEG and H.264
* Changing video settings works

In these environments:

- [x] Pro Voyager build
- [x] Community bundle on top of bare Raspbian system
- [x] Community bundle on top of bare Raspbian system with TC358743
enabled

### Peer tests

To test this bundle (which combines the stack of three PRs mentioned
above), run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/e70104a2-0f1f-43b7-abe9-098d6eac2799/artifacts/0/bundler/dist/tinypilot-community-20230831T0151Z-1.9.0-87+de1916a.tgz
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1608"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-31 15:53:34 -04:00
Michael Lynch
b38744dc72 Install uStreamer without Ansible (#1606)
Resolves #1600

As part of our continuing effort to eliminate Ansible from our install
process, this installs uStreamer from within the bundle installer rather
than during Ansible.

This is a slight implementation change in that we no longer download the
uStreamer package at install time and instead pre-download it and
include it in the TinyPilot bundle. This is preferable, as it does more
work in the packaging stage and less work on user devices, though it
does increase the size of our bundles by a few megabytes.

### Manual tests

For expediency, I tested builds that combined:

* #1605
* #1606 
* #1608

For the manual tests, I verified:

* Video works under MJPEG and H.264
* Changing video settings works

In these environments:

- [x] Pro Voyager build
- [x] Community bundle on top of bare Raspbian system
- [x] Community bundle on top of bare Raspbian system with TC358743
enabled

### Peer tests

To test this bundle (which combines the stack of three PRs mentioned
above), run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/e70104a2-0f1f-43b7-abe9-098d6eac2799/artifacts/0/bundler/dist/tinypilot-community-20230831T0151Z-1.9.0-87+de1916a.tgz
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1606"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-31 15:30:38 -04:00
Michael Lynch
d954422481 Install Janus without using Ansible (#1605)
Resolves #1599

As part of our ongoing work to get rid of Ansible in our install
process, this change implements the Janus Debian package install in the
bundle install script rather than in Ansible.

This is also a functional change in that we're no longer adding the
whole debian-backports repo as an apt-get source. Instead, we're
including the specific Janus `.deb` file we want in TinyPilot's install
bundle.

### Manual tests

For expediency, I tested builds that combined:

* #1605
* #1606 
* #1608

For the manual tests, I verified:

* Video works under MJPEG and H.264
* Changing video settings works

In these environments:

- [x] Pro Voyager build
- [x] Community bundle on top of bare Raspbian system
- [x] Community bundle on top of bare Raspbian system with TC358743
enabled

### Peer tests

To test this bundle (which combines the stack of three PRs mentioned
above), run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/e70104a2-0f1f-43b7-abe9-098d6eac2799/artifacts/0/bundler/dist/tinypilot-community-20230831T0151Z-1.9.0-87+de1916a.tgz
```
2023-08-31 11:33:52 -04:00
Jason Wallace
325d56f8cf Convert paste-overlay to paste-dialog (#1603)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1137

This PR completely removes the old "Paste" frontend code and replaces it
with a custom `<paste-dialog>` element.



https://github.com/tiny-pilot/tinypilot/assets/6730025/880e650f-b938-4fd6-8417-55c806cd6301



Notes:
1. Once the paste-dialog is open, you can just press the "Enter" key to
actually paste it to the target machine. This is in accordance to our
style guide:

273b200d9c/app/templates/styleguide.html (L260-L262)
However, this behavior might be unexpected especially if you're manually
typing text into the textarea and want to add a newline character. With
this in mind, I made sure that you can still add a newline character
using `Shift+Enter`.


<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1603"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-31 16:32:44 +02:00
Michael Lynch
c9417e37ae Fix blank popup window bug on Firefox (#1610)
Resolves #1609

There's a bug that affects (at least) Firefox on Win10 where if the user
tries View > Dedicated Window, the window comes up blank and the JS
console has errors about "can't access dead object".

The issue seems like a bug in Firefox. What seems to be happening is
that the popup is trying to share resources with the main window, but
the browser's garbage seems to not be aware of the additional reference.
So the popup starts loading, we redirect the original window, which
causes the browser to tear down its resources, and then the popup
continues loading, but the shared resources it was trying to access have
been garbage collected in redirecting the original window.

Adding `noopener` seems to fix the issue, as it prevents the two windows
from sharing resources:

>`noopener`
>
>If this feature is set, the new window will not have access to the
originating window via Window.opener and returns null.
>
>When `noopener` is used, non-empty target names, other than _top,
_self, and _parent, are treated like _blank in terms of deciding whether
to open a new browsing context.

https://developer.mozilla.org/en-US/docs/Web/API/Window/open#parameters
2023-08-31 09:30:37 -04:00
Michael Lynch
7014293384 Install uStreamer Launcher with Debian packaging (#1592)
Resolves #1549
Related https://github.com/tiny-pilot/tinypilot-pro/issues/972

### Overview

ustreamer-launcher is our thin wrapper around the uStreamer binary. It
reads settings from YAML files and then generates the appropriate
command-line string to execute uStreamer with command-line flags that
match the settings in the YAML files.

Previously, we installed ustreamer-launcher with Ansible. This change
performs the install through Debian packaging, as part of our ongoing
efforts to eliminate Ansible from our install.

### Design changes

The Ansible-based installer had a lot of complexity around how it
populated the base uStreamer config file at
`/opt/ustreamer-launcher/configs.d/000-defaults.yml`.

The Ansible-based installer wrote all of the non-null uStreamer settings
to `000-defaults.yml`, but this is an artifact of when
ustreamer-launcher was meant to be a general-purpose uStreamer tool
rather than something TinyPilot specific. ustreamer-launcher was
creating a `000-defaults.yml` file that was open-ended because the
client using the Ansible role could theoretically specify any Ansible
vars.

This change simplifies ustreamer-launcher to the TinyPilot use case. We
are either specifying the unique defaults for the TC358743 scenario
(e.g., Voyager) or the HDMI to USB dongle scenario (Hobbyist).

Now, instead of the installer dynamically writing arbitrary settings to
`000-defaults.yml`, that file is a symlink that can point to one of two
files.

We have two static YAML files that are always installed on the
filesystem: [one for
TC358743](f1c773c685/debian-pkg/opt/ustreamer-launcher/config-library/tc358743.yml)
and [one for HDMI to
USB](f1c773c685/debian-pkg/opt/ustreamer-launcher/config-library/hdmi-to-usb.yml).
At install time, `tinypilot.postinst` ensures that `000-defaults.yml` is
a symlink that points to either the TC358743 settings or the HDMI to USB
settings depending on whether TC358743 is enabled.

### Functional changes

This is mostly a non-functional refactoring, but for the sake of
simplicity, we're now ignoring these YAML settings:

* `ustreamer_video_path`
* `ustreamer_brightness`
* `ustreamer_tcp_nodelay`

Previously, it was possible for users to override these settings in
`/home/tinypilot/settings.yml` and ustreamer-launcher would launch
uStreamer with corresponding command-line flags. We never documented
these settings in a customer-facing place, and I don't know of any users
exercising them, so we can remove them.

We are also changing the permissions on the files in
`/opt/ustreamer-launcher`. Previously, the ownership was a mixture of
`root` and `ustreamer`. There isn't actually a need for `ustreamer` to
be an owner, so we're simplifying to `root` owning everything.
`tinypilot` still owns its override file, so the app can dynamically
make changes to settings.

### Manual tests

- Installed bundle on a clean Raspberry Pi OS Bullseye Lite system
- First install was without applying the TC358743 settings to
`/boot/config.txt`
- I verified the settings were correct, but I didn't test end-to-end
with the HDMI to USB dongle
- After that, I reinstalled after applying the settings to
`/boot/config.txt`, and the video stream worked correctly
- Installed a full Voyager microSD image on Pro

To test this bundle, run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/8d968bdd-9797-4437-ae4c-2754c8913f40/artifacts/0/bundler/dist/tinypilot-community-20230825T1401Z-1.9.0-80+5ff91e0.tgz
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1592"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-29 13:44:24 -04:00
db39
c381d6f7ef Build Debian package using CircleCI ARM executor (#1588)
Resolves #1584 

We've been using Docker+QEMU to emulate 32-bit ARM on AMD64, but this PR
switches to ARM-native CircleCI instances, which skips the emulation.

This achieves a speedup on building Debian packages from about 4m down
to about 70s.

Because Debian package building is fast again, we're changing our CI
workflow to build a Debian package on every commit rather than just on
`master` or just when we manually trigger it.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1588"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>

---------

Co-authored-by: Michael Lynch <git@mtlynch.io>
2023-08-29 17:05:03 +01:00
jotaen4tinypilot
0e8c54f6c5 Initialize dedicated window with size of current remote screen (#1590)
Resolves https://github.com/tiny-pilot/tinypilot/issues/728. Stacked on
https://github.com/tiny-pilot/tinypilot/pull/1589.

For convenience and smoother UX, this PR detects the size of the remote
screen in order to intialize the popup window with the exact same
dimensions as the remote screen. That also ensures that the remote
screen fits into the popup window exactly, with no extra padding.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1590"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-28 18:44:59 +02:00
jotaen4tinypilot
fe104929c7 Add menu item for opening dedicated window (#1589)
Part of https://github.com/tiny-pilot/tinypilot/issues/728.

This PR adds an item to the “View” menu, which is labelled “Dedicated
Window”, and which opens the remote screen in “standalone” view mode in
a popup window.


https://github.com/tiny-pilot/tinypilot/assets/83721279/f6bdbdf5-5387-4f6a-8401-9b33f92fb5cb

## Notes

- As discussed in [this issue
comment](https://github.com/tiny-pilot/tinypilot/issues/728#issuecomment-1692216456),
we decided to use a rather pragmatic and slightly unconventional
approach for hiding the remote screen from the main (parent) window, by
issuing an external redirect to a separate page. A “clean” and proper
teardown mechanism, which would allow us to stay on the main page, would
probably be rather complex to build, and also brittle to maintain.
- I’ve debated whether to use an `btn-action` (blue) or a `btn-success`
(green) for the “Refresh Page” button. I eventually went with the
former, since the action is optional, and the button is only a
convenience.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1589"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-28 18:42:09 +02:00
db39
c0d8e10628 Hardcode h264 parameters (#1585)
Resolves #1570

This change removes uStreamer variables in the Ansible role and
hardcodes them. We now also unconditionally install Janus.

To test this bundle, run:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/8025923f-9ba2-4e45-aef0-952f0f12655b/artifacts/0/bundler/dist/tinypilot-community-20230824T1222Z-1.9.0-62+3908e48.tgz
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1585"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-24 15:46:32 +01:00
jotaen4tinypilot
2dd535465f Add view mode to hide away menu and status bars (#1587)
Part of https://github.com/tiny-pilot/tinypilot/issues/728, stacked onto
https://github.com/tiny-pilot/tinypilot/pull/1586.

As demonstrated and discussed [in the original proof-of-concept
branch](https://github.com/tiny-pilot/tinypilot/pull/1574), we want to
hide the status bar and menu bar in the popup window [via a query
parameter](https://github.com/tiny-pilot/tinypilot/pull/1574/files#diff-66e482e36d313dd641cd92c815c5fa30fb380bbaa601810827b30a5b84428856R351).
So by appending `?viewMode=standalone` to the TinyPilot URL, this PR
hides the status bar, the menu bar, and the on-screen keyboard.

We will use this in a later PR, when adding the menu item for opening a
“real” popup window.

<img width="783" alt="Screenshot 2023-08-23 at 18 38 09"
src="https://github.com/tiny-pilot/tinypilot/assets/83721279/c3a22b9b-b3b8-49a3-a5b1-88d2368337ec">

The query parameter can also be used independent of the popup window,
which e.g. allows for [the iframe
use-case](https://github.com/tiny-pilot/tinypilot/issues/523).

## Notes

- `prettier-ignore` is needed above `<remote-screen>`, since Prettier
cannot handle Jinja2 templates, and would enforce a pretty [bulky
formatting
otherwise](https://github.com/tiny-pilot/tinypilot/pull/1574/files#diff-a18b3b5de30df1bcf7531723d24c214d69b2acff3cd88540e1ff186409879b0aR81-R88).
- I had to pull out a `--bar-padding` CSS variable in the
`<remote-screen>` component, so that we can dynamically override the
value. I forgot that in the [earlier
PR](https://github.com/tiny-pilot/tinypilot/pull/1583).
- In `index.html`, I injected the `display: none` via a plain `<style>`
block to hide the elements from the page. Since `index.html` itself
isn’t a web component, I’m not sure we can mimic our usual pattern with
HTML attributes here
([example](aa80dbdd3e/app/templates/custom-elements/change-hostname-dialog.html (L12-L14))),
at least not without introducing more complexity and indirection. The
`<style>` block is not super beautiful, but I thought it’s simple and
straightforward at least.
- Note sure `standalone` is the greatest name for the query parameter
value. Potential alternatives: “screen-only”, “focus-mode”,
“dedicated-screen”. (It’s maybe not *that* critical, however… 🤔) In any
event, I found something like `?viewMode=standalone` more descriptive
and flexible than `standaloneMode=true`.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1587"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-24 15:47:29 +02:00
jotaen4tinypilot
7222d29fff Simplify and tidy up HTML in index.html (#1586)
Part of https://github.com/tiny-pilot/tinypilot/issues/728, follow up of
https://github.com/tiny-pilot/tinypilot/pull/1583. Non-functional
refactoring.

https://github.com/tiny-pilot/tinypilot/pull/1583 left a stray `<div>`
in the `index.html` file, which doesn’t serve any purpose anymore.

This PR removes the `<div>`, and lifts up the `<remote-screen>` and
`<on-screen-keyboard>` components. That doesn’t have any actual effect,
as all HTML elements are positioned absolutely anyway, but to me it
makes for a slightly more intuitive code structure: i.e., we instantiate
the basic elements in the order in which they appear on the screen, and
have all dialog elements underneath.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1586"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-24 15:36:00 +02:00
jotaen4tinypilot
aa80dbdd3e Make for smooth vertical resizing of remote screen (#1583)
Part of https://github.com/tiny-pilot/tinypilot/issues/728.

The vertical resizing behaviour of the remote screen is currently so
that the screen element’s height appears to “jump” at certain steps due
to [CSS
breakpoints](069cf2d982/app/templates/custom-elements/remote-screen.html (L11-L33)),
while you resize the window vertically.

This PR implements “smooth” and step-less vertical resizing, while
maintaining a constant margin between remote screen and status-bar
during that process.

The breakpoint-less resizing is important for the “dedicated window”
(popup) that we are about to implement in
https://github.com/tiny-pilot/tinypilot/issues/728, where it would
probably feel weird if the remote screen height jumped around the way it
currently does, or if we wouldn’t be able to fill up the entire vertical
space of the popup window due to the breakpoint setup.

## Demo: After


https://github.com/tiny-pilot/tinypilot/assets/83721279/66758c7c-ce78-4f0a-8323-4990be47fe49

## Demo: Before


https://github.com/tiny-pilot/tinypilot/assets/83721279/f768b3c0-8b5b-44c3-8cbd-2ee724e46a02

## Notes

- We had introduced these breakpoints in
https://github.com/tiny-pilot/tinypilot/pull/878 originally, as kind of
“heuristic”/pragmatic approach for resizing the remote screen, without
having the remote screen visually collide with the status bar. The
breakpoints itself are arbitrary, and they don’t serve any other purpose
except for facilitating the vertical screen size while resizing the
window.
- I discovered https://github.com/tiny-pilot/tinypilot/issues/1581 while
testing this PR; so this behaviour is not a regression, but it’s
currently broken on master.
- This PR leaves a “naked” `<div>` in `index.html` which we technically
don’t need anymore. I’ll clean that up in a later PR, to avoid a noisy
whitespace diff here.
- The `page-content` CSS class is orphaned, so I’ve removed it.

I’ve tested on device with Firefox and Chrome, and I tried to check all
imaginable scaling constellations of window sizes and aspect ratios,
both with MJPEG and H.264, and both in full screen and regular window
mode. The biggest risk of this PR would be that we accidentally mess
with the mouse cursor positioning/alignment. It would be cool if you
could double-check on device as well, with a real target screen, just so
that we are safe.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1583"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-23 17:36:35 +02:00
db39
a6a36fc47c Remove explicit cma specification in /boot/cmdline.txt (#1582)
Resolves #1580

This change removes ansible tasks that explicitly set 128MiB of CMA.
They're no longer needed because RaspberryPi OS Bullseye now uses 512MiB
by default.

To run this build:

```bash
curl \
  --silent \
  --show-error \
  --location \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/master/scripts/install-bundle | \
  sudo bash -s -- \
    https://output.circle-artifacts.com/output/job/d38fa2bc-26f1-448d-984e-6653963d20ad/artifacts/0/bundler/dist/tinypilot-community-20230823T1154Z-1.9.0-56+5b44790.tgz
```

You can check the CMA with this command:

```bash
dmesg | grep -i cma
```

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1582"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-23 15:15:54 +01:00
jotaen4tinypilot
edb4441569 Add STUN support in Janus config (#1579)
Part of https://github.com/tiny-pilot/tinypilot/issues/1460.

This PR templatizes the Janus main config file, and adds a privileged
script for (re-)generating the config from the template plus from the
properties in `settings.yml` (i.e., `ustreamer_janus_stun_server` and
`ustreamer_janus_stun_port`).

## Notes

- In the Debian `postinst` routine, we deliberately delegate to a
privileged script instead of just inlining the logic ([like we do for
writing the app
settings](e305440929/debian-pkg/debian/tinypilot.postinst (L73-L80)),
for example), since we want to re-use the `configure-janus` logic in the
backend in a later step.
- Later, when calling the `configure-janus` privileged script from the
backend, we also need to restart the uStreamer and Janus systemd
services manually. To me, it felt safer and more explicit to let the
caller take care of that, instead of making the service restart part of
`configure-janus`. I also wasn’t sure we should be issuing direct calls
to `systemctl` or `/usr/sbin/service` anyways during the Debian install
procedure, instead of using `deb-systemd-invoke`.
- I debated whether we should add a comment above the `nat {}` block in
the Janus config, however, I wasn’t sure whether a generic explanation
of what STUN is would add enough value.
- Since neither `ustreamer_janus_stun_server` nor
`ustreamer_janus_stun_port` do have default values, it doesn’t make
sense to list them [in
`settings.py`](e305440929/app/update/settings.py (L24-L31)).
We currently don’t have an authoritative place anymore that lists and
documents all supported properties in `settings.yml`, so the two newly
added STUN properties are implicit and undocumented now. I have opened
https://github.com/tiny-pilot/tinypilot/issues/1573 for tracking that,
since I think this is a broader issue.

A few more things on testing:

- I have tested this PR quite a bit on device with the [latest bundle
build off
`af5ec0d`](https://output.circle-artifacts.com/output/job/29dc16fa-0b35-4b41-b920-85e61fa8883f/artifacts/0/bundler/dist/tinypilot-community-20230822T1618Z-1.9.0-66+af5ec0d.tgz),
so if you like, I’d suggest that a brief spot-check QA on your end would
suffice.
- Please note that testing this PR is only about verifying that we
generate a valid Janus config [according to the
documentation](7c7093e188/conf/janus.jcfg.sample.in (L259-L288)),
not about actually verifying the STUN mechanism itself, as the setup for
that [is quite complex and
laborious](https://github.com/tiny-pilot/tinypilotkvm.com/issues/939#issuecomment-1592775400).
We already gathered enough evidence that Janus with STUN in itself does
the job, and solves the use-case scenarios we are after.
- We [have an
issue](https://github.com/tiny-pilot/tinypilot/issues/1578) where Janus
would fail to come up right after booting, if a STUN server is
specified. We’ll fix this separately.


<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1579"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-23 14:24:18 +02:00
jotaen4tinypilot
e305440929 Resolve tinypilot home dir independent from $HOME (#1572)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1571.

There are several places in the app where we rely on the `~` path
shortcut, or the `$HOME` environment variable respectively. (For example
when [processing the `settings.yml`
file](https://github.com/tiny-pilot/tinypilot/blob/master/app/update/settings.py#L21).)
However, there are scenarios where the app (or parts of it) are run
under a different user, e.g. `root`, or with `sudo`, in which case `~`
would erroneously resolve to `/root` instead of `/home/tinypilot`.

This PR makes sure that the app always uses `/home/tinypilot` for
accessing TinyPilot-specific objects, independent of what the `$HOME`
environment variable contains. TinyPilot-specific objects are:

- `settings.yml`
- `logs/**` (i.e., update result logs)
- `.flask-secret-key`
- `tinypilot.db`
- `app_settings.cfg` (no change needed, as [this is already referenced
in an absolute
manner](504e7f113d/debian-pkg/debian/tinypilot.service (L12)))

I suggest that we don’t just hard-code the `/home/tinypilot` path as is,
because that would make local development more inconvenient – you always
would need to initialize and switch to a `tinypilot` user before being
able to start developing. Therefore, I introduced a new environment
variable (`TINYPILOT_HOME_DIR`), that lets us overrride the
`/home/tinypilot` default. Unfortunately, we cannot put this variable
into
[`dev_app_settings.cfg`](504e7f113d/dev_app_settings.cfg),
since the app config can only be read during a Flask request execution
context, but not at initialization time (at least not in a “clean” way).
To me, the `env.abs_path_in_home_dir` helper function (as proposed here)
wouldn’t be too bad either, though.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1572"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-22 15:56:24 +02:00
Michael Lynch
a2a7bc4d46 Get rid of uStreamer capture device Ansible vars (#1554)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1501
Resolves #1267

This change gets rid of the `ustreamer_capture_device` Ansible var
(TC358743 vs. HDMI to USB) and the config file where we stored the
result. Instead, we'll track capture device based on whether
`dtoverlay=tc358743` appears in `/boot/config.txt`.

In theory, relying on `/boot/config.txt` will cause incorrect behavior
if a user enables the TC358743 overlay even though they're using HDMI to
USB. That's unlikely to happen in practice, so I think it's worth the
tradeoff, as this assumption eliminates a **lot** of complexity.

As a side-effect of eliminating `ustreamer_capture_device`, we can
remove a lot of cruft from the bundle install file.

### Background

We originally added the "uStreamer settings file" because we needed a
way to keep track of whether the device was using a HDMI to USB dongle
(like a DIY TinyPilot) or a TC358743-based HDMI to CSI chip (like a
Voyager).

At the time of the original implementation, the uStreamer Ansible role
was independent of TinyPilot, so it couldn't write to TinyPilot
settings. So, we created a "uStreamer settings file" at
`/home/ustreamer.config.yml` that would essentially persist the setting
for whether the system was TC358743-based so that the initiator of the
Ansible role wouldn't have to re-specify it every time.

### Implementation notes

* I'm broadening the scope a little bit by tackling #1267 at the same
time, but I feel like the major cost of both those issues is the testing
to make sure everything is correct, so I might as well fix and test both
at the same time.
* With this change, the Ansible role no longer adds the
`dtoverlay=tc358743` line to `/boot/config.txt` because it's now the
user's responsibility to do that in advance if they've got a DIY
TinyPilot with an HDMI to CSI chip. For Pro, Packer will take
responsibility for adding that line.
  * The Ansible role still adds the `dtoverlay=tc358743-audio` line.
* `bundler/bundle/install` used to be responsible for creating
`/home/tinypilot/settings.yml` if it didn't already exist, but this
change moves that responsibility to `tinypilot.postinst`.
* I'm deliberately leaving a `debug` task in the Ansible role because I
think it's helpful to have the output in logs.
* This change drops the `ustreamer_persistent` var and instead always
launches ustreamer with the `--persistent` flag. The setting used to be
unofficially configurable via settings, but we're dropping that
configurability (see
https://github.com/tiny-pilot/tinypilot-pro/issues/972).

### Documentation impact

After we merge this, we need to update our
[wiki](https://github.com/tiny-pilot/tinypilot/wiki/Installation-Options#example-tc358743-hdmi-to-csi-capture-chip)
with the new TC358743 install method, which should simplify down to:

```bash
if ! grep --silent '^dtoverlay=tc358743$' /boot/config.txt; then
  echo 'dtoverlay=tc358743' | sudo tee --append /boot/config.txt
fi
```

Corresponding changes in Pro:
https://github.com/tiny-pilot/tinypilot-pro/compare/no-capture-pro?expand=1
(difference is just Packer config)

### Manual tests

I performed the following manual tests to verify we're not breaking
functionality.

- [x] Verify TinyPilot Community install with HDMI to USB dongle
- [x] Verify TinyPilot Community install with HDMI to CSI bridge
- [x] Verify TinyPilot Pro Hobbyist image
- [x] Verify TinyPilot Pro Voyager image
- [x] Verify installing TinyPilot Pro bundle on top of TinyPilot Pro
2.6.0 Voyager image
- [x] Verify installing TinyPilot Pro bundle on top of TinyPilot Pro
2.6.0 Hobbyist image

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1554"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-21 08:56:11 -04:00
Michael Lynch
504e7f113d Delete dead ustreamer_port var (#1569)
As of 710ed072e9, we no longer honor this
variable, so we can safely delete it.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1569"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-16 21:33:04 +02:00
Jason Wallace
b9d60675e8 Populate uStreamer Janus plugin config after reading capture device (#1568)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1567

WebRTC audio streaming stopped working since
https://github.com/tiny-pilot/tinypilot/pull/1470. The problem was that
the uStreamer Janus plugin config file was being written before
populating the `ustreamer_capture_device` variable, which resulted in no
Janus audio config:

b379ac26ea/ansible-role-ustreamer/templates/janus.plugin.ustreamer.jcfg.j2 (L5-L10)

The `ustreamer_capture_device` variable is populated when reading the
`/home/ustreamer/config.yml` file:

b379ac26ea/ansible-role-ustreamer/tasks/check_saved_settings.yml (L11-L14)

Back in https://github.com/tiny-pilot/tinypilot/pull/1470, I
specifically mentioned that I was shifting where the TC358743 chip was
being provisioned, but I incorrectly assumed that only the uStreamer
launcher cared about the uStreamer config file:
> I've [moved the TC358743 provisioning closer down to the uStreamer
launcher
tasks](05f256fc6c/ansible-role-ustreamer/tasks/main.yml (L112-L136))
because the [TC358743 provisioning sets a bunch of ustreamer
variables](9cbfe64187/ansible-role-ustreamer/tasks/provision_tc358743.yml (L61-L68))
which is only put into effect by the uStreamer launcher.

This PR only writes the uStreamer Janus plugin config file after we have
determined the uStreamer capture device.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1568"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-15 17:39:07 +02:00
Michael Lynch
330978abc7 Skip installing git in build_bundle CI step (#1564)
`create-bundle` [used to depend on
git](https://github.com/tiny-pilot/tinypilot/blob/1.8.0/bundler/create-bundle),
as it downloaded external roles using git and used `git` to pull version
information about the local repo.

We've since simplified the bundle build process, so we no longer require
git, and we can delete the CI step when we install git into the
container. This saves us about 5s on every bundle build in CI.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1564"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-11 07:58:48 -04:00
Jason Wallace
ecc15fa8b9 Migrate to less-frequently-used ports (#1562)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1551

A TinyPilot device uses ports that are also popular with other
applications. This PR migrates our production ports to make them less
likely to collide with other apps:
* TinyPilot port `8000` to port `48000`
   * In dev mode, we still use port `8000`

fa560f4ca7/dev-scripts/serve-dev (L12-L14)
* uStreamer port `8001` to port `48001`
* Janus port `8002` to port `48002`


<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1562"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-11 12:45:47 +02:00
Jason Wallace
710ed072e9 Drop the use of the uStreamer port Ansible variable (#1563)
Related https://github.com/tiny-pilot/tinypilot/issues/1551

In https://github.com/tiny-pilot/tinypilot/pull/1562, we're moving
uStreamer from port `8001` to port `48001`. However, before we do that I
thought it might be a good time to hardcode the port number and
<s>enforce non-user-configurability</s> drop the use of the
`ustreamer_port` Ansible variable.

According to https://github.com/tiny-pilot/tinypilot-pro/issues/972,
`ustreamer_port` is already considered a non-user-configurable variable.
This PR enforces `ustreamer_port` as being non-user-configurable.

This PR does the following:
* Reverts https://github.com/tiny-pilot/tinypilot/pull/1493
(which introduced that `_CONSTANTS` variable in
`app/update/settings.py`)
* Hardcodes the uStreamer port to `8001` in the TinyPilot NGINX config
and the uStreamer launcher script.
* Drops the use of the `ustreamer_port` Ansible variable.
* Cleans up the `/home/tinypilot/settings.yml` file by removing any
user-defined `ustreamer_port` at install/update time.

Notes
1. TinyPilot Pro would require the following additional change:
    ```diff
    # debian-pkg/debian/tinypilot.postinst
    
     KEYBOARD_PATH = '{{ tinypilot_keyboard_interface }}'
     MOUSE_PATH = '{{ tinypilot_mouse_interface }}'
    -USTREAMER_BASEURL = 'http://127.0.0.1:{{ ustreamer_port }}'
    +USTREAMER_BASEURL = 'http://127.0.0.1:8001'
    ```
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1563"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-10 15:38:24 +02:00
Jason Wallace
c1aa1b41e2 Upgrade circleci/path-filtering to version 1.0.0 (#1560)
This was supposed to resolve this
https://github.com/tiny-pilot/tinypilot/issues/1559, but it wasn't
actually related.

Might as well upgrade `circleci/path-filtering` while we're here.





<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1560"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-10 12:49:21 +02:00
Jason Wallace
04c0772148 Fix instructions on how to manually trigger a bundle build (#1561)
Resolves https://github.com/tiny-pilot/tinypilot/issues/1548

This PR moves the comments that explains how to trigger a code-based
bundle build from `.circleci/config.yml` to
`.circleci/continue_config.yml` and updates the contributing docs to
reference the correct CircleCI config file.

So the correct ways to [manually trigger a bundle
build](1ea663b0ee/CONTRIBUTING.md (installing-a-nightly-bundle))
is either the:
1. Code-based way
> 1. In [the CircleCI configuration](/.circleci/continue_config.yml),
change the `bundle_build_branch` parameter’s `default` value from
`master` to `<< pipeline.git.branch >>`.
> 1. Push your changes as branch to GitHub. CircleCI will now
automatically build bundles for all subsequent commits of that branch.
> 1. Before eventually merging your feature branch, remember to revert
the `bundle_build_branch` parameter to the original value (i.e.,
`master`)
3. CircleCI web UI way
> 1. On CircleCI’s overview page for the respective branch, click the
“Trigger Pipeline” button.
> 1. In the dialog, enter `bundle_build_branch` as parameter name, and
the (exact) name of the branch as parameter value.
> 1. Click the “Trigger Pipeline” button in the dialog. CircleCI will
now build a bundle for the latest commit of that branch.

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1561"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-10 12:36:25 +02:00
cghague
f9ab492c34 Improve voltage warning lines in TinyPilot logs (#1544)
Resolves #1495

Parses the output of `journalctl` into a simple “yes” or “no” result. If
the result is “yes”, the latest voltage warning is also included in the
output.

## Parsing the output of `journalctl`

I initially considered piping the output of `journalctl` into `grep` for
readability, but getting the correct exit code as well as just the
latest voltage warning was quite awkward with this approach. I therefore
settled on using just the filtering and output options that are built
into `journalctl`:

- The `-q` argument is used to suppress the unwanted `journalctl` header
text.
- The `-r` argument causes `journalctl` to output from newest to oldest.
- The `-n 1` argument causes `journalctl` to stop after outputting a
single line.
- The `-g "voltage"` argument limits output to only lines that contain
the word “voltage”.

The end result of this combination of arguments is that `journalctl`
will efficiently output only the most recent voltage warning. In
addition, the exit status of the command reflects whether or not any
matching lines were found, which allows for a simple `if <command>` test
to be used.

Short arguments were used for consistency with the majority of the rest
of the `collect-debug-logs` script.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1544"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-10 00:58:31 +01:00
cghague
edcf2f82aa Improve CPU throttle lines in TinyPilot logs (#1543)
Resolves #1489

Parses the output of `vcgencmd get_throttled` into a simple “yes” or
“no” result.

## Decoding the output of `vcgencmd get_throttled`

We could decode the output of `vcgencmd get_throttled` to get more
details, but for our purposes we simply want to detect that nothing
relating to throttling has occurred since the device was booted, a
situation which is indicated by an output value of `0x0`.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1543"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-10 00:58:18 +01:00
cghague
48f63f8640 Improve temperature lines in TinyPilot logs (#1542)
Resolves #1488

Runs a simple text replacement to make the output of `vcgencmd
measure_temp` more readable.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1542"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
2023-08-10 00:58:05 +01:00