-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (54 loc) · 1.91 KB
/
main.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
import os
import sys
import shutil
import getpass
import logging
from PyQt5.QtCore import Qt
from core.main_window import MainWindow
from PyQt5.QtWidgets import QApplication
from logging.handlers import RotatingFileHandler
name = "Youtube-Music-Desktop-Player"
author = "deeffest"
website = "deeffest.pythonanywhere.com"
version = "1.12.1"
current_dir = os.path.dirname(os.path.abspath(__file__))
def setup_logging():
log_dir = os.path.join(os.path.expanduser("~"), name, "logs")
if not os.path.exists(log_dir):
os.makedirs(log_dir)
log_file = os.path.join(log_dir, "app.log")
rotating_handler = RotatingFileHandler(
log_file, maxBytes=1 * 1024 * 1024, backupCount=0
)
rotating_handler.setLevel(logging.INFO)
rotating_handler.setFormatter(logging.Formatter(
'[%(asctime)s] %(message)s', datefmt='%Y.%m.%d %H:%M:%S'
))
logging.basicConfig(
level=logging.INFO,
handlers=[
rotating_handler,
logging.StreamHandler()
]
)
if __name__ == '__main__':
setup_logging()
sys_argv = sys.argv
app = QApplication(sys_argv)
app.setApplicationName(name)
app.setOrganizationName(author)
app.setOrganizationDomain(website)
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)
with open(f"{current_dir}/core/css/styles.css", 'r') as file:
app.setStyleSheet(file.read())
username = getpass.getuser()
sw_dir = f"C:/Users/{username}/AppData/Local/{author}/{name}/QtWebEngine/Default/Service Worker"
try:
shutil.rmtree(sw_dir)
except Exception as e:
logging.error("Failed to remove Service Worker directory: " + str(e))
custom_url = None
if len(sys_argv) > 1:
custom_url = sys_argv[1]
main_window = MainWindow(custom_url, app_info=[name, version, current_dir])
sys.exit(app.exec_())