fix: the bar keeps its order when an application opens
On the laptop the browser jumped behind the disc player the moment it was
opened. 0.2.4 caused that, and the cause is two lines of the stock applet:
main.qml:153 hideActivatedLaunchers: tasks.iconsOnly || ...
main.qml:155 launchInPlace: tasks.iconsOnly && sortingStrategy === 1
For an icons-only bar the first is always true — a launcher is hidden the
instant its application starts — and the second is what puts the running
window back where the launcher was. It only does that at sortingStrategy
1. 0.2.4 set it to 0 to stop teachers dragging the icons about, so the
launcher vanished and the window was appended after the others.
Reproduced in the lab with a real Chrome window before changing anything,
and the bar read off the screen: Wonder Ink, the player, then the
browser. With 1 it is Wonder Ink, the browser, the player, through
opening, a second window, another application opening beside it, and
every close.
The launcher identity was suspected and cleared: only one browser button
appears, because google-chrome.desktop already carries Chrome's own file
name and StartupWMClass for exactly this reason.
THE COST, AND IT IS REAL. Manual sorting is also the only mode in which
MouseHandler.qml accepts a reordering drop, so a teacher who knows to drag
can rearrange the bar again. There is no value that gives both and no
Kiosk key that separates them. classroom-desktop-reset already rebuilds
the bar from the package at every login, so a drag never outlives the
session. docs/testing.md states the trade rather than burying it, and the
configuration escape is written down there too as still open.
tools/lab/order-check is the test this needed and did not have. 0.2.4
passed a full set of configuration assertions while the bar did something
else, so this one opens real application windows and reads the panel
strip as pixels — there is no image library in the lab, so it captures
PPM and names each icon by colour. Six checks, all of them behaviour.
Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0fa26f398d
commit
a31fa75d55
@@ -9,6 +9,20 @@ terminal:
|
||||
classroom-wifi "Church Wi-Fi" # prompts for the password
|
||||
classroom-wifi --list
|
||||
classroom-wifi --forget "Old Network"
|
||||
classroom-wifi --adopt --dry-run # what would be migrated
|
||||
classroom-wifi --adopt # migrate it, with rollback
|
||||
|
||||
ADOPTING A WI-FI THE INSTALLER SET UP.
|
||||
|
||||
A machine whose Wi-Fi was given to the Debian installer has it in
|
||||
/etc/network/interfaces, where ifupdown owns it. The internet works and
|
||||
NetworkManager reports the device UNMANAGED, so the room's applet says
|
||||
there is no connection and cannot scan. --adopt moves that network into a
|
||||
NetworkManager system connection and takes the stanza out of ifupdown's
|
||||
hands, which is the whole fix for both symptoms.
|
||||
|
||||
The password never leaves the machine and is never printed: this runs as
|
||||
root, reads it out of a root-only file and writes it into another one.
|
||||
|
||||
WHY THIS EXISTS RATHER THAN LETTING A TEACHER ADD ONE.
|
||||
|
||||
@@ -34,10 +48,25 @@ if the room could create a connection it was allowed to read.
|
||||
import argparse
|
||||
import getpass
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(0, "/usr/local/lib/ekklesia-classroom")
|
||||
sys.path.insert(
|
||||
0,
|
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "lib"),
|
||||
)
|
||||
|
||||
import classroom_network as ifupdown # noqa: E402
|
||||
|
||||
CONNECTIONS = "/etc/NetworkManager/system-connections"
|
||||
INTERFACES = "/etc/network/interfaces"
|
||||
|
||||
# How long NetworkManager gets to bring the network back up after the
|
||||
# hand-over before this decides it has failed and puts ifupdown back.
|
||||
ADOPT_TIMEOUT = 45
|
||||
|
||||
|
||||
def say(message):
|
||||
@@ -119,6 +148,140 @@ def add(ssid, password, name=None):
|
||||
return 0
|
||||
|
||||
|
||||
def is_wireless(device):
|
||||
return os.path.isdir(f"/sys/class/net/{device}/wireless")
|
||||
|
||||
|
||||
def connectivity():
|
||||
result = nmcli("networking", "connectivity", check=False)
|
||||
|
||||
return (result.stdout or "").strip()
|
||||
|
||||
|
||||
def online():
|
||||
"""Whether the machine can actually reach anything.
|
||||
|
||||
NetworkManager's own answer first, because that is the thing the room
|
||||
was complaining about; a real fetch second, because "full" is a claim
|
||||
and this is the moment to be sure of it.
|
||||
"""
|
||||
if connectivity() in ("full", "limited"):
|
||||
return True
|
||||
|
||||
return subprocess.run(
|
||||
["curl", "-fsS", "--max-time", "8", "-o", "/dev/null",
|
||||
"https://updates.riverofglorymn.org/stable/manifest.json"],
|
||||
capture_output=True, check=False,
|
||||
).returncode == 0
|
||||
|
||||
|
||||
def adopt(dry_run=False):
|
||||
"""Move an installer-configured Wi-Fi from ifupdown to NetworkManager.
|
||||
|
||||
Ordered so that the link is given up as late as possible and put back
|
||||
the moment anything goes wrong. The connection is created first and
|
||||
sits unused; the file is changed next; only then is the interface
|
||||
handed over, and if the room is not back on the network within
|
||||
ADOPT_TIMEOUT the file is restored and ifupdown brought back.
|
||||
"""
|
||||
try:
|
||||
with open(INTERFACES, "r", encoding="utf-8") as handle:
|
||||
text = handle.read()
|
||||
except OSError as error:
|
||||
say(f"cannot read {INTERFACES}: {error}")
|
||||
return 1
|
||||
|
||||
stanzas = ifupdown.wireless(ifupdown.parse(text), is_wireless)
|
||||
|
||||
if not stanzas:
|
||||
say("no wireless interface is configured in /etc/network/interfaces")
|
||||
say("nothing to adopt; this machine's Wi-Fi is already "
|
||||
"NetworkManager's or it has none")
|
||||
return 0
|
||||
|
||||
if len(stanzas) > 1:
|
||||
say(f"{len(stanzas)} wireless stanzas found; refusing to guess")
|
||||
return 1
|
||||
|
||||
stanza = stanzas[0]
|
||||
device = stanza["name"]
|
||||
ssid, psk = ifupdown.credentials(stanza)
|
||||
|
||||
if not ssid:
|
||||
say(f"{device} is configured through a wpa_supplicant.conf rather "
|
||||
"than named in this file")
|
||||
say("that one is not ours to move; adopt it by hand")
|
||||
return 1
|
||||
|
||||
# Never printed. The room's password is not diagnostic output.
|
||||
say(f"{device}: ifupdown holds a wireless network "
|
||||
f"({'with' if psk else 'without'} a saved password)")
|
||||
|
||||
if dry_run:
|
||||
say(f"would create a NetworkManager system connection for {ssid!r}")
|
||||
say(f"would comment the {device} stanza out of {INTERFACES}")
|
||||
say("would hand the interface over, and put it back if that failed")
|
||||
return 0
|
||||
|
||||
existing = nmcli("-t", "-f", "NAME", "connection", "show", check=False)
|
||||
already = ssid in (existing.stdout or "").splitlines()
|
||||
|
||||
if already:
|
||||
say(f"NetworkManager already has a connection named {ssid!r}")
|
||||
else:
|
||||
if add(ssid, psk) != 0:
|
||||
return 1
|
||||
|
||||
backup = f"{INTERFACES}.before-ekklesia-classroom"
|
||||
|
||||
if not os.path.exists(backup):
|
||||
shutil.copy2(INTERFACES, backup)
|
||||
say(f"kept the original at {backup}")
|
||||
|
||||
with open(INTERFACES, "w", encoding="utf-8") as handle:
|
||||
handle.write(ifupdown.comment_out(text, stanza))
|
||||
|
||||
say(f"took {device} out of ifupdown's hands")
|
||||
|
||||
# NetworkManager only re-reads which interfaces ifupdown claims when
|
||||
# its configuration is reloaded. The link is still ifupdown's at this
|
||||
# point, and NetworkManager does not touch a device it considers
|
||||
# unmanaged, so this cannot drop it.
|
||||
nmcli("general", "reload", "conf", check=False)
|
||||
|
||||
subprocess.run(["ifdown", device], capture_output=True, check=False)
|
||||
nmcli("device", "set", device, "managed", "yes", check=False)
|
||||
nmcli("connection", "up", ssid, check=False)
|
||||
|
||||
deadline = time.monotonic() + ADOPT_TIMEOUT
|
||||
|
||||
while time.monotonic() < deadline:
|
||||
if online():
|
||||
say(f"{device} is NetworkManager's now, and the room is online")
|
||||
say("the panel will show the connection at the next login")
|
||||
return 0
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
# It did not come back. Put the machine exactly as it was.
|
||||
say("NetworkManager did not get the network back; rolling back")
|
||||
shutil.copy2(backup, INTERFACES)
|
||||
nmcli("general", "reload", "conf", check=False)
|
||||
nmcli("device", "set", device, "managed", "no", check=False)
|
||||
subprocess.run(["ifup", device], capture_output=True, check=False)
|
||||
|
||||
for _ in range(10):
|
||||
if online():
|
||||
say("ifupdown has the network back; nothing was lost")
|
||||
return 1
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
say("WARNING: the machine may be offline. ifupdown was restored; try "
|
||||
f"`ifup {device}` or a reboot")
|
||||
return 1
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Provision the church Wi-Fi as a system connection.")
|
||||
@@ -130,6 +293,11 @@ def main():
|
||||
help="remove a saved connection")
|
||||
parser.add_argument("--open", action="store_true",
|
||||
help="the network has no password")
|
||||
parser.add_argument("--adopt", action="store_true",
|
||||
help="move an installer-configured Wi-Fi from "
|
||||
"ifupdown into NetworkManager")
|
||||
parser.add_argument("--dry-run", action="store_true",
|
||||
help="with --adopt, say what would change")
|
||||
arguments = parser.parse_args()
|
||||
|
||||
if arguments.list:
|
||||
@@ -139,6 +307,9 @@ def main():
|
||||
say("run this as root; it creates a connection the machine owns")
|
||||
return 1
|
||||
|
||||
if arguments.adopt:
|
||||
return adopt(dry_run=arguments.dry_run)
|
||||
|
||||
if arguments.forget:
|
||||
return forget(arguments.forget)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user