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