-
Notifications
You must be signed in to change notification settings - Fork 2
/
launch.py
114 lines (105 loc) · 4.21 KB
/
launch.py
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
from shutil import copyfile
import subprocess
import os
import filecmp
# Defines
THEME_NAME = 0
THEME_PATH = 1
# Variables
class vars:
chosen_theme = None # chosen list of theme info from theme_list, None until chosen
# Colors
class color:
black = "\u001b[30m"
red = "\u001b[31m"
green = "\u001b[32m"
yellow = "\u001b[33m"
blue = "\u001b[34m"
magenta = "\u001b[35m"
cyan = "\u001b[36m"
white = "\u001b[37m"
end = "\u001b[0m"
# Themes
theme_list = [
["Default"],
["Exit"],
["Information Superhighway", "themes/InformationSuperhighway/discord.css"],
["Joan", "themes/Joan/discord.css"],
["Syndicate", "themes/Syndicate/discord.css"],
["Nanotrasen", "themes/Nanotrasen/discord.css"],
["ToonTown", "themes/ToonTown/discord.css"],
]
#==================================================================#
# Builds the menu to choose themes from (or revert to normal.)
# Ways to improve this in the future:
# * Smarter reverting - only revert when it needs to! right now
# it will always revert when it may not need to
#==================================================================#
def select_theme():
print(f"{color.green}Select a theme to enable!{color.end}")
print(" # Number - Theme\n =========================================")
iteration = 1
for theme in theme_list:
print(f">#{str(iteration)} - {theme[THEME_NAME]}")
iteration += 1
print(" ");
chosen_index = 0
while vars.chosen_theme == None:
chosen_index = input("Theme #> ")
if(not chosen_index.isnumeric()):
print(f"{color.red}Please enter the number of the theme.{color.end}")
continue
if(not chosen_index.isnumeric() or not int(chosen_index) > 0 or not int(chosen_index) <= len(theme_list)):
print(f"{color.red}Please enter a valid selection.{color.end}")
continue
chosen_index = int(chosen_index)
vars.chosen_theme = theme_list[chosen_index-1]
#==================================================================#
# The actual beautifuldiscord call and setup
# if the hot reloader is already set up, the selected option may be the same
#==================================================================#
def hook():
#setup (check needs to happen before file is copied or it will always fail)
skip_hook = os.path.exists("discord.css")
if(skip_hook and filecmp.cmp(vars.chosen_theme[THEME_PATH], "discord.css")):
return
print(f"{color.green}Selected {vars.chosen_theme[THEME_NAME]}! {color.end}{color.yellow}Loading...{color.end}")
try:
copyfile(vars.chosen_theme[THEME_PATH], os.path.abspath("discord.css"))
except FileNotFoundError as file_error:
print(f"{color.red}File not found! {file_error}{color.end}")
return
if(skip_hook):
return
#call
print(f"{color.yellow}hooking into discord (please wait until relaunch){color.end}")
try:
subprocess.run(["beautifuldiscord", "--css", os.path.abspath("discord.css")], stdout = subprocess.DEVNULL)
except Exception as error:
print(error)
#==================================================================#
# reverts hook, removes the discord.css file from main part of repo
#==================================================================#
def unhook_and_cleanup():
already_default = not os.path.exists("discord.css")
if(already_default):
return
try:
subprocess.run(["beautifuldiscord", "--revert"], stdout = subprocess.DEVNULL)
except Exception as error:
print(f"{color.red}{error}{color.end}")
print(f"{color.yellow}As discord is still assumingly hooked to the css, we are not going to del the css file.{color.end}")
return
os.remove("discord.css")
#==================================================================#
# Main code
#==================================================================#
def main():
select_theme()
if(vars.chosen_theme[THEME_NAME] == "Exit"):
return
if(vars.chosen_theme[THEME_NAME] == "Default"):
unhook_and_cleanup()
return
hook()
main()