Fix import error and kill existing antidrift windows on start
This commit is contained in:
@@ -7,6 +7,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import antidrift.xwindow as xwindow
|
||||||
from antidrift.xwindow import XWindow
|
from antidrift.xwindow import XWindow
|
||||||
from antidrift.config import Config, State, Block
|
from antidrift.config import Config, State, Block
|
||||||
from gi.repository import GLib, Gio
|
from gi.repository import GLib, Gio
|
||||||
|
|||||||
16
main.py
16
main.py
@@ -5,6 +5,7 @@ import os
|
|||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import argparse
|
import argparse
|
||||||
|
import psutil
|
||||||
import rich
|
import rich
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -76,6 +77,20 @@ def check_for_xdotool():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def kill_existing_antidrift():
|
||||||
|
current_pid = os.getpid()
|
||||||
|
for proc in psutil.process_iter(['pid', 'name', 'exe']):
|
||||||
|
if proc.info['name'] == '/usr/bin/antidrift' or proc.info['exe'] == '/usr/bin/antidrift':
|
||||||
|
if proc.info['pid'] == current_pid:
|
||||||
|
continue # don't kill ourselves
|
||||||
|
try:
|
||||||
|
proc.kill()
|
||||||
|
except psutil.AccessDenied:
|
||||||
|
pass
|
||||||
|
except psutil.NoSuchProcess:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main_daemon(config):
|
def main_daemon(config):
|
||||||
if os.geteuid() == 0:
|
if os.geteuid() == 0:
|
||||||
newpid = os.fork()
|
newpid = os.fork()
|
||||||
@@ -84,6 +99,7 @@ def main_daemon(config):
|
|||||||
AntiDriftDaemon(config).run()
|
AntiDriftDaemon(config).run()
|
||||||
else:
|
else:
|
||||||
if sys.argv[0] == "antidrift":
|
if sys.argv[0] == "antidrift":
|
||||||
|
kill_existing_antidrift()
|
||||||
cmd = ["sudo", "antidrift", "--daemon"]
|
cmd = ["sudo", "antidrift", "--daemon"]
|
||||||
subprocess.Popen(cmd)
|
subprocess.Popen(cmd)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user