3
|
1 import psutil
|
|
2 from typing import Dict, List, Optional
|
|
3
|
|
4
|
|
5 def progname(cmdline: List[str]) -> Optional[str]:
|
|
6 if len(cmdline) < 1:
|
|
7 return None
|
|
8 if cmdline[-1].endswith('/steam'):
|
|
9 return 'steam'
|
|
10 if cmdline[0].endswith('/minecraft-launcher'):
|
|
11 return 'minecraft-launcher'
|
|
12 if cmdline[0].endswith('/java') and '--versionType' in cmdline:
|
|
13 return 'minecraft'
|
|
14 if cmdline[0].endswith('/RobloxPlayer'):
|
|
15 return 'roblox'
|
|
16
|
|
17
|
|
18 def get_running_progs() -> Dict[str, int]:
|
|
19 progs = set()
|
|
20 for proc in psutil.process_iter(['pid', 'name']):
|
|
21 try:
|
|
22 prog = progname(proc.cmdline())
|
|
23 if prog:
|
|
24 progs.add(prog)
|
|
25 except (psutil.AccessDenied, psutil.NoSuchProcess):
|
|
26 pass
|
|
27 return dict(
|
|
28 (p, p in progs)
|
|
29 for p in ['steam', 'minecraft-launcher', 'minecraft', 'roblox'])
|