Drop reading of the pre-rename xautolock-inhibit.json state file
This commit is contained in:
@@ -18,7 +18,6 @@ SCRIPT = Path(os.environ.get("XIDLE_INHIBIT") or Path(__file__).resolve().parent
|
|||||||
BUS_NAME = "org.freedesktop.ScreenSaver"
|
BUS_NAME = "org.freedesktop.ScreenSaver"
|
||||||
OBJECT_PATH = "/org/freedesktop/ScreenSaver"
|
OBJECT_PATH = "/org/freedesktop/ScreenSaver"
|
||||||
STATE_FILE = "xidle-inhibit.json"
|
STATE_FILE = "xidle-inhibit.json"
|
||||||
OLD_STATE_FILE = "xautolock-inhibit.json"
|
|
||||||
TIMEOUT = 5.0
|
TIMEOUT = 5.0
|
||||||
DELAY = ["--release-delay", "1"]
|
DELAY = ["--release-delay", "1"]
|
||||||
SETTLE = 1.5 # longer than DELAY, to check that nothing happens
|
SETTLE = 1.5 # longer than DELAY, to check that nothing happens
|
||||||
@@ -387,21 +386,6 @@ def test_old_crash_is_not_restored(sb: Sandbox) -> None:
|
|||||||
assert "over the 30s window" in sb.log()
|
assert "over the 30s window" in sb.log()
|
||||||
|
|
||||||
|
|
||||||
def test_old_state_file_is_read_once_and_deleted(sb: Sandbox) -> None:
|
|
||||||
a = sb.client()
|
|
||||||
old = sb.runtime / OLD_STATE_FILE
|
|
||||||
old.write_text(json.dumps({
|
|
||||||
"bus_id": a.conn.get_guid(), "last_cookie": 7, "stopped_at": time.time(),
|
|
||||||
"cookies": [[7, a.name, "test-app", "Playing video"]],
|
|
||||||
}))
|
|
||||||
sb.start()
|
|
||||||
assert sb.calls() == [DISABLE]
|
|
||||||
assert "(xautolock-inhibit)" in sb.log()
|
|
||||||
assert not old.exists()
|
|
||||||
assert json.loads(sb.state_file.read_text())["cookies"] == [[7, a.name, "test-app", "Playing video"]]
|
|
||||||
assert a.inhibit() == 8
|
|
||||||
|
|
||||||
|
|
||||||
def test_unreadable_state_file_is_ignored(sb: Sandbox) -> None:
|
def test_unreadable_state_file_is_ignored(sb: Sandbox) -> None:
|
||||||
sb.state_file.write_text("{not json")
|
sb.state_file.write_text("{not json")
|
||||||
sb.start()
|
sb.start()
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ OBJECT_PATHS = ("/org/freedesktop/ScreenSaver", "/ScreenSaver") # Vivaldi uses
|
|||||||
EXIT_NAME_TAKEN = 2
|
EXIT_NAME_TAKEN = 2
|
||||||
ACTIVITY_QUIET = 300 # seconds without SimulateUserActivity that end a logged burst
|
ACTIVITY_QUIET = 300 # seconds without SimulateUserActivity that end a logged burst
|
||||||
STATE_FILE = "xidle-inhibit.json" # in $XDG_RUNTIME_DIR
|
STATE_FILE = "xidle-inhibit.json" # in $XDG_RUNTIME_DIR
|
||||||
OLD_STATE_FILE = "xautolock-inhibit.json" # before the rename (0.2); read once when upgrading
|
|
||||||
STATE_HEARTBEAT = 10 # seconds between state file touches while inhibits are held
|
STATE_HEARTBEAT = 10 # seconds between state file touches while inhibits are held
|
||||||
CONFIG_FILE = "xidle-inhibit/config" # in $XDG_CONFIG_HOME
|
CONFIG_FILE = "xidle-inhibit/config" # in $XDG_CONFIG_HOME
|
||||||
BACKENDS = ("xautolock", "xss-lock")
|
BACKENDS = ("xautolock", "xss-lock")
|
||||||
@@ -228,14 +227,6 @@ class Inhibitor:
|
|||||||
self.restore()
|
self.restore()
|
||||||
self.state_ready = True
|
self.state_ready = True
|
||||||
self.save()
|
self.save()
|
||||||
if self.state_path:
|
|
||||||
old = os.path.join(os.path.dirname(self.state_path), OLD_STATE_FILE)
|
|
||||||
try:
|
|
||||||
os.remove(old)
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
except OSError as e:
|
|
||||||
log(f"Cannot remove old state file {old}: {e}")
|
|
||||||
if self.active_count():
|
if self.active_count():
|
||||||
self.block()
|
self.block()
|
||||||
elif self.xautolock:
|
elif self.xautolock:
|
||||||
@@ -248,9 +239,6 @@ class Inhibitor:
|
|||||||
return
|
return
|
||||||
assert self.conn is not None
|
assert self.conn is not None
|
||||||
path = self.state_path
|
path = self.state_path
|
||||||
old = os.path.join(os.path.dirname(path), OLD_STATE_FILE)
|
|
||||||
if not os.path.exists(path) and os.path.exists(old):
|
|
||||||
path = old
|
|
||||||
try:
|
try:
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
state = json.load(f)
|
state = json.load(f)
|
||||||
@@ -263,8 +251,6 @@ class Inhibitor:
|
|||||||
except (OSError, ValueError, KeyError, TypeError) as e:
|
except (OSError, ValueError, KeyError, TypeError) as e:
|
||||||
log(f"Ignoring unreadable state file {path}: {e}")
|
log(f"Ignoring unreadable state file {path}: {e}")
|
||||||
return
|
return
|
||||||
if path == old:
|
|
||||||
log(f"Reading inhibits from {old} (xautolock-inhibit)")
|
|
||||||
if bus_id != self.conn.get_guid():
|
if bus_id != self.conn.get_guid():
|
||||||
# Unique names like :1.42 are reused by a new bus, so they would mean other clients.
|
# Unique names like :1.42 are reused by a new bus, so they would mean other clients.
|
||||||
if saved:
|
if saved:
|
||||||
|
|||||||
Reference in New Issue
Block a user