57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import sys
|
|
import os
|
|
import logging
|
|
from pathlib import Path
|
|
from PyQt5.QtWidgets import QApplication
|
|
from ui.main_window import MainWindow
|
|
from utils.config_utils import init_config, load_config
|
|
|
|
class AppContext:
|
|
def __init__(self):
|
|
self.app_dir = Path(__file__).parent.resolve()
|
|
self.conf_dir = self.app_dir / "conf"
|
|
self.log_dir = self.app_dir / "logs"
|
|
self.resources = self.app_dir / "resources"
|
|
|
|
# 初始化目录
|
|
self.conf_dir.mkdir(exist_ok=True)
|
|
self.log_dir.mkdir(exist_ok=True)
|
|
|
|
# 初始化配置
|
|
init_config(self.conf_dir)
|
|
self.config = load_config()
|
|
|
|
# 配置日志
|
|
logging.basicConfig(
|
|
filename=self.log_dir / "app.log",
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(levelname)s - %(message)s'
|
|
)
|
|
|
|
def validate_config(self):
|
|
"""验证配置有效性"""
|
|
return bool(self.config.get('proxy_url'))
|
|
|
|
if __name__ == "__main__":
|
|
# 设置macOS应用属性
|
|
if sys.platform == "darwin":
|
|
from Foundation import NSBundle
|
|
bundle = NSBundle.mainBundle()
|
|
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
|
|
info["CFBundleName"] = "EZProxy"
|
|
info["CFBundleIconFile"] = "icon.icns"
|
|
|
|
app = QApplication(sys.argv)
|
|
app.setQuitOnLastWindowClosed(False)
|
|
|
|
context = AppContext()
|
|
window = MainWindow(context)
|
|
|
|
# 首次运行检查代理配置
|
|
if not context.validate_config():
|
|
from ui.setup_dialog import SetupDialog
|
|
setup = SetupDialog(context)
|
|
if setup.exec_() != QDialog.Accepted:
|
|
sys.exit(0)
|
|
|
|
sys.exit(app.exec_()) |