Added final unmount and unmount on press when connected

This commit is contained in:
2026-07-29 18:16:29 +01:00
parent 7e3744c8a7
commit 0d5d110a53

25
main.py
View File

@@ -1,5 +1,6 @@
from functools import partial from functools import partial
import json import json
from os import getuid
from pathlib import Path from pathlib import Path
from queue import Empty, Queue from queue import Empty, Queue
import subprocess import subprocess
@@ -59,7 +60,12 @@ def loadOrCreateConfig(path: Path) -> Config:
def onButtonPressed(state: AppState) -> None: def onButtonPressed(state: AppState) -> None:
if state.diskState == "disconnected":
state.diskState = "pairing" state.diskState = "pairing"
elif state.diskState == "pairing":
state.diskState = "disconnected"
elif state.diskState == "connected":
unmountDisk(state)
print("Changing disk state") print("Changing disk state")
@@ -153,6 +159,8 @@ def mountDisk(state: AppState) -> None:
"mount", "mount",
f"{node}1", f"{node}1",
f"/mnt/{state.config.diskSerial}", f"/mnt/{state.config.diskSerial}",
"-o",
f"uid={getuid()}",
], ],
check=True, check=True,
) )
@@ -162,6 +170,21 @@ def mountDisk(state: AppState) -> None:
state.diskState = "connected" state.diskState = "connected"
def unmountDisk(state: AppState) -> None:
try:
subprocess.run(
[
"umount",
f"/mnt/{state.config.diskSerial}",
],
check=True,
)
except subprocess.CalledProcessError:
pass
else:
state.diskState = "disconnected"
def main() -> None: def main() -> None:
try: try:
state = AppState() state = AppState()
@@ -214,6 +237,8 @@ def main() -> None:
finally: finally:
state.stopEvent.set() state.stopEvent.set()
if state.diskState == "connected":
unmountDisk(state)
return return