Skip to content

Commit 6ee86f4

Browse files
authored
Add support for PTB, Canary (#18)
2 parents 9d6d393 + cb8c007 commit 6ee86f4

File tree

2 files changed

+249
-240
lines changed

2 files changed

+249
-240
lines changed

funcs.py

+54-53
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
1-
import os
2-
import subprocess
3-
import psutil
4-
5-
6-
def start_discord(discord_parent_path: str):
7-
# running discord from c:/ for prevent locking the script's working dir
8-
script_working_dir = os.getcwd()
9-
10-
os.chdir('c:/')
11-
if 'scoop\\apps' in discord_parent_path:
12-
latest_installed_discord_version = get_latest_installed_discord_folder_name(discord_parent_path)
13-
subprocess.Popen(f'{os.path.join(discord_parent_path, latest_installed_discord_version, "Discord.exe")}', stdout=subprocess.DEVNULL)
14-
else:
15-
subprocess.Popen(f'{os.path.join(discord_parent_path, "Update.exe")} --processStart Discord.exe')
16-
os.chdir(script_working_dir)
17-
18-
19-
def get_discord_state() -> tuple[bool, bool]:
20-
is_discord_running = False
21-
is_discord_updating = True
22-
23-
# The "--service-sandbox-type=audio" argument will only be in the
24-
# updated discord instance, so it won't be in the update module
25-
26-
for process in psutil.process_iter(['name']):
27-
if process.info.get('name') == 'Discord.exe':
28-
is_discord_running = True
29-
30-
try:
31-
for arg in process.cmdline():
32-
if '--service-sandbox-type=audio' in arg:
33-
is_discord_updating = False
34-
except psutil.NoSuchProcess:
35-
pass
36-
37-
return is_discord_running, is_discord_updating
38-
39-
40-
def kill_discord():
41-
for process in psutil.process_iter(['name']):
42-
if process.info['name'] == 'Discord.exe':
43-
try:
44-
process.kill()
45-
except psutil.NoSuchProcess:
46-
pass
47-
48-
49-
def get_latest_installed_discord_folder_name(discord_parent_path: str) -> str:
50-
discord_path = [i for i in os.listdir(discord_parent_path) if i.startswith('app-')] # remove all not 'app-' items
51-
discord_path.sort()
52-
latest_installed_discord_version = discord_path[-1] # the oldest version will be the last of list
53-
return latest_installed_discord_version
1+
import os
2+
import subprocess
3+
import psutil
4+
5+
def start_discord(discord_parent_path: str):
6+
# running discord from c:/ to prevent locking the script's working dir
7+
script_working_dir = os.getcwd()
8+
9+
os.chdir('c:/')
10+
if 'scoop\\apps' in discord_parent_path:
11+
latest_installed_discord_version = get_latest_installed_discord_folder_name(discord_parent_path)
12+
subprocess.Popen(f'{os.path.join(discord_parent_path, latest_installed_discord_version, "Discord.exe")}', stdout=subprocess.DEVNULL)
13+
else:
14+
if 'DiscordPTB' in discord_parent_path:
15+
subprocess.Popen(f'{os.path.join(discord_parent_path, "Update.exe")} --processStart DiscordPTB.exe')
16+
elif 'DiscordCanary' in discord_parent_path:
17+
subprocess.Popen(f'{os.path.join(discord_parent_path, "Update.exe")} --processStart DiscordCanary.exe')
18+
else:
19+
subprocess.Popen(f'{os.path.join(discord_parent_path, "Update.exe")} --processStart Discord.exe')
20+
os.chdir(script_working_dir)
21+
22+
def get_discord_state() -> tuple[bool, bool]:
23+
is_discord_running = False
24+
is_discord_updating = True
25+
26+
# The "--service-sandbox-type=audio" argument will only be in the
27+
# updated discord instance, so it won't be in the update module
28+
29+
for process in psutil.process_iter(['name']):
30+
if process.info.get('name') in ['Discord.exe', 'DiscordPTB.exe', 'DiscordCanary.exe']:
31+
is_discord_running = True
32+
33+
try:
34+
for arg in process.cmdline():
35+
if '--service-sandbox-type=audio' in arg:
36+
is_discord_updating = False
37+
except psutil.NoSuchProcess:
38+
pass
39+
40+
return is_discord_running, is_discord_updating
41+
42+
def kill_discord():
43+
for process in psutil.process_iter(['name']):
44+
if process.info['name'] in ['Discord.exe', 'DiscordPTB.exe', 'DiscordCanary.exe']:
45+
try:
46+
process.kill()
47+
except psutil.NoSuchProcess:
48+
pass
49+
50+
def get_latest_installed_discord_folder_name(discord_parent_path: str) -> str:
51+
discord_path = [i for i in os.listdir(discord_parent_path) if i.startswith('app-')] # remove all not 'app-' items
52+
discord_path.sort()
53+
latest_installed_discord_version = discord_path[-1] # the oldest version will be the last of list
54+
return latest_installed_discord_version

0 commit comments

Comments
 (0)