Skip to content

Commit 23b3918

Browse files
committed
Add args --not-check-update and --hide-banner
1 parent e3d13b3 commit 23b3918

1 file changed

Lines changed: 83 additions & 71 deletions

File tree

src/main.py

Lines changed: 83 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
__version__ = "2.1"
3434

35-
os.system("")
36-
3735

3836
class ConnectionInfo:
3937
"""Class to store connection information"""
@@ -64,6 +62,8 @@ def __init__(self):
6462
self.no_blacklist = False
6563
self.auto_blacklist = False
6664
self.quiet = False
65+
self.not_check_update = False
66+
self.hide_banner = False
6767

6868

6969
class IBlacklistManager(ABC):
@@ -902,14 +902,12 @@ def __init__(
902902
async def check_for_updates(self):
903903
"""Check for updates"""
904904

905-
if self.config.quiet:
906-
return None
907-
908905
try:
909906
loop = asyncio.get_event_loop()
910907

911908
def sync_check():
912909
try:
910+
# self.logger.debug("Check for updates")
913911
req = Request(
914912
"https://gvcoder09.github.io/nodpi_site/api/v1/update_info.json",
915913
)
@@ -939,95 +937,101 @@ def sync_check():
939937
async def print_banner(self) -> None:
940938
"""Print startup banner"""
941939

942-
self.update_check_task = asyncio.create_task(self.check_for_updates())
940+
if self.config.quiet:
941+
return
942+
943+
if not self.config.not_check_update:
944+
self.update_check_task = asyncio.create_task(self.check_for_updates())
943945

944-
try:
945-
await asyncio.wait_for(self.update_event.wait(), timeout=2.0)
946-
except asyncio.TimeoutError:
947-
if self.update_check_task and not self.update_check_task.done():
948-
self.update_check_task.cancel()
949-
try:
950-
await self.update_check_task
951-
except asyncio.CancelledError:
952-
pass
946+
try:
947+
await asyncio.wait_for(self.update_event.wait(), timeout=2.0)
948+
except asyncio.TimeoutError:
949+
if self.update_check_task and not self.update_check_task.done():
950+
self.update_check_task.cancel()
951+
try:
952+
await self.update_check_task
953+
except asyncio.CancelledError:
954+
pass
953955

954956
self.logger.info("\033]0;NoDPI\007")
955957

956958
if sys.platform == "win32":
957959
os.system("mode con: lines=33")
958960

959-
if sys.stdout.isatty():
960-
console_width = os.get_terminal_size().columns
961-
else:
962-
console_width = 80
963-
964-
disclaimer = (
965-
"DISCLAIMER. The developer and/or supplier of this software "
966-
"shall not be liable for any loss or damage, including but "
967-
"not limited to direct, indirect, incidental, punitive or "
968-
"consequential damages arising out of the use of or inability "
969-
"to use this software, even if the developer or supplier has been "
970-
"advised of the possibility of such damages. The developer and/or "
971-
"supplier of this software shall not be liable for any legal "
972-
"consequences arising out of the use of this software. This includes, "
973-
"but is not limited to, violation of laws, rules or regulations, "
974-
"as well as any claims or suits arising out of the use of this software. "
975-
"The user is solely responsible for compliance with all applicable laws "
976-
"and regulations when using this software."
977-
)
978-
wrapped_text = textwrap.TextWrapper(width=70).wrap(disclaimer)
979-
980-
left_padding = (console_width - 76) // 2
961+
if not self.config.hide_banner:
962+
if sys.stdout.isatty():
963+
console_width = os.get_terminal_size().columns
964+
else:
965+
console_width = 80
966+
# self.logger.debug("console_width=", console_width)
967+
968+
disclaimer = (
969+
"DISCLAIMER. The developer and/or supplier of this software "
970+
"shall not be liable for any loss or damage, including but "
971+
"not limited to direct, indirect, incidental, punitive or "
972+
"consequential damages arising out of the use of or inability "
973+
"to use this software, even if the developer or supplier has been "
974+
"advised of the possibility of such damages. The developer and/or "
975+
"supplier of this software shall not be liable for any legal "
976+
"consequences arising out of the use of this software. This includes, "
977+
"but is not limited to, violation of laws, rules or regulations, "
978+
"as well as any claims or suits arising out of the use of this software. "
979+
"The user is solely responsible for compliance with all applicable laws "
980+
"and regulations when using this software."
981+
)
982+
wrapped_text = textwrap.TextWrapper(width=70).wrap(disclaimer)
981983

982-
self.logger.info("\n\n\n")
983-
self.logger.info(
984-
"\033[91m" + " " * left_padding + "╔" + "═" * 72 + "╗" + "\033[0m"
985-
)
984+
left_padding = (console_width - 76) // 2
986985

987-
for line in wrapped_text:
988-
padded_line = line.ljust(70)
986+
self.logger.info("\n\n\n")
989987
self.logger.info(
990-
"\033[91m" + " " * left_padding +
991-
"║ " + padded_line + " ║" + "\033[0m"
988+
"\033[91m" + " " * left_padding + "╔" + "═" * 72 + "╗" + "\033[0m"
992989
)
993990

994-
self.logger.info(
995-
"\033[91m" + " " * left_padding + "╚" + "═" * 72 + "╝" + "\033[0m"
996-
)
991+
for line in wrapped_text:
992+
padded_line = line.ljust(70)
993+
self.logger.info(
994+
"\033[91m" + " " * left_padding +
995+
"║ " + padded_line + " ║" + "\033[0m"
996+
)
997997

998-
time.sleep(1)
998+
self.logger.info(
999+
"\033[91m" + " " * left_padding + "╚" + "═" * 72 + "╝" + "\033[0m"
1000+
)
9991001

1000-
update_message = None
1001-
if self.update_check_task and self.update_check_task.done():
1002-
try:
1003-
update_message = self.update_check_task.result()
1004-
except (asyncio.CancelledError, Exception):
1005-
pass
1002+
time.sleep(1)
10061003

1007-
self.logger.info("\033[2J\033[H")
1004+
self.logger.info("\033[2J\033[H")
10081005

1009-
self.logger.info(
1010-
"""
1011-
\033[92m ██████ █████ ██████████ ███████████ █████
1006+
self.logger.info(
1007+
"""\033[92m
1008+
██████ █████ ██████████ ███████████ █████
10121009
░░██████ ░░███ ░░███░░░░███ ░░███░░░░░███░░███
10131010
░███░███ ░███ ██████ ░███ ░░███ ░███ ░███ ░███
10141011
░███░░███░███ ███░░███ ░███ ░███ ░██████████ ░███
10151012
░███ ░░██████ ░███ ░███ ░███ ░███ ░███░░░░░░ ░███
10161013
░███ ░░█████ ░███ ░███ ░███ ███ ░███ ░███
10171014
█████ ░░█████░░██████ ██████████ █████ █████
1018-
░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░\033[0m
1019-
"""
1020-
)
1021-
self.logger.info(f"\033[92mVersion: {__version__}".center(50))
1022-
self.logger.info(
1023-
"\033[97m" +
1024-
"Enjoy watching! / Наслаждайтесь просмотром!".center(50)
1025-
)
1015+
░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░
1016+
\033[0m"""
1017+
)
1018+
self.logger.info(f"\033[92mVersion: {__version__}".center(console_width))
1019+
self.logger.info(
1020+
"\033[97m" +
1021+
"Enjoy watching! / Наслаждайтесь просмотром!".center(console_width)
1022+
)
10261023

1027-
self.logger.info("\n")
1024+
self.logger.info("\n")
10281025

1029-
if update_message:
1030-
self.logger.info(update_message)
1026+
if not self.config.not_check_update:
1027+
update_message = None
1028+
if self.update_check_task and self.update_check_task.done():
1029+
try:
1030+
update_message = self.update_check_task.result()
1031+
except (asyncio.CancelledError, Exception):
1032+
pass
1033+
if update_message:
1034+
self.logger.info(update_message)
10311035

10321036
self.logger.info(
10331037
f"\033[92m[INFO]:\033[97m Proxy is running on {self.config.host}:{self.config.port} at {datetime.now().strftime('%H:%M on %Y-%m-%d')}"
@@ -1155,6 +1159,8 @@ def load_from_args(args) -> ProxyConfig:
11551159
config.no_blacklist = args.no_blacklist
11561160
config.auto_blacklist = args.autoblacklist
11571161
config.quiet = args.quiet
1162+
config.not_check_update = args.not_check_update
1163+
config.hide_banner = args.hide_banner
11581164
return config
11591165

11601166

@@ -1294,6 +1300,9 @@ def parse_args():
12941300
"""Parse command line arguments"""
12951301

12961302
parser = argparse.ArgumentParser()
1303+
parser.add_argument(
1304+
"-q", "--quiet", action="store_true", help="Remove UI output"
1305+
)
12971306
parser.add_argument("--host", default="127.0.0.1", help="Proxy host")
12981307
parser.add_argument("--port", type=int,
12991308
default=8881, help="Proxy port")
@@ -1333,7 +1342,10 @@ def parse_args():
13331342
"--log-error", required=False, help="Path to log file for errors"
13341343
)
13351344
parser.add_argument(
1336-
"-q", "--quiet", action="store_true", help="Remove UI output"
1345+
"--not-check-update", action="store_true", help="Do not check for updates"
1346+
)
1347+
parser.add_argument(
1348+
"--hide-banner", action="store_true", help="Suppress printing banner"
13371349
)
13381350

13391351
autostart_group = parser.add_mutually_exclusive_group()

0 commit comments

Comments
 (0)