-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.py
More file actions
129 lines (111 loc) · 3.34 KB
/
Copy pathstart.py
File metadata and controls
129 lines (111 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import os
import pathlib
import shutil
import argparse
import subprocess
from modules import read_conf
def main():
parser = argparse.ArgumentParser(prog="lasso")
parser.add_argument(
"-d",
"--debug",
action="store_true",
help="Enable debug. This keeps the alacritty window open, and shows errors.",
)
parser.add_argument(
"-m",
"--mode",
help="Pass in the shorthand of a mode (eg. ':d' for dashboard mode) in which LASSO should start.",
)
parser.add_argument(
"-n",
"--network",
action="store_true",
help="Start the LASSO network selector instead of the launcher.",
)
parser.add_argument(
"-b",
"--bluetooth",
action="store_true",
help="Start the LASSO bluetooth selector instead of the launcher.",
)
args = parser.parse_args()
if (args.network ^ args.bluetooth ^ (args.mode is None)) and not (
args.network or args.bluetooth or (args.mode is None)
):
print(
'The parameters "-b/--bluetooth", "-n/--network" and "-m/--mode" are mutually exclusive!'
)
exit()
init()
exec_path = str(pathlib.Path(__file__).parent.resolve().joinpath("lasso.py"))
if args.network and not (args.bluetooth or args.mode):
exec_path = str(
pathlib.Path(__file__).parent.resolve().joinpath("modules/network.py")
)
elif args.bluetooth and not (args.network or args.mode):
exec_path = str(
pathlib.Path(__file__).parent.resolve().joinpath("modules/bluetooth.py")
)
elif args.mode and not (args.bluetooth or args.network):
exec_path = str(pathlib.Path(__file__).parent.resolve().joinpath("lasso.py"))
args.mode = ":n" if args.mode is None else args.mode
wal_command = [
"kitty",
"--title",
"lasso",
"--class",
"lasso",
"-c",
f"/home/{read_conf.username}/.config/lasso/kitty.conf",
"fish",
"-c",
f"wal -Rqn; python {exec_path} -m {args.mode}",
]
no_wal_command = [
"alacritty",
"--title",
"lasso",
"--class",
"lasso",
"-c",
f"/home/{read_conf.username}/.config/lasso/kitty.conf",
"-e",
"python",
exec_path,
"-m",
args.mode,
]
command = (
wal_command if shutil.which("wal") and read_conf.use_wal else no_wal_command
)
if args.debug:
command.insert(1, "--hold")
if shutil.which("nixGL") and read_conf.use_nixGL:
command.insert(0, "nixGL")
process = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
check_focus_lost(process)
def check_focus_lost(process):
try:
for line in process.stdout:
if "Focused(false)" not in line:
continue
process.terminate()
break
except Exception as e:
print(f"An error occurred: {e}")
finally:
process.stdout.close()
process.stderr.close()
process.wait()
def init():
if os.path.isdir(f"/home/{os.getlogin()}/.config/lasso"):
return
shutil.copytree(
os.path.join(os.path.dirname(__file__), "res"),
f"/home/{os.getlogin()}/.config/lasso",
)
if __name__ == "__main__":
main()