Skip to content

Commit

Permalink
Merge pull request #13 from ChenglongMa/dev-since-1.2.0
Browse files Browse the repository at this point in the history
Dev since 1.2.0
  • Loading branch information
ChenglongMa authored Aug 4, 2024
2 parents 1cffd37 + ee7c457 commit 628ff7d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 38 deletions.
3 changes: 2 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Remove-Folders -Paths @(".\dist", ".\build", ".\$EnvName")
Write-Output "Building..."

Write-Output "Creating Virtual Environment..."

.\venv\Scripts\python.exe -m pip install --upgrade pip
.\venv\Scripts\pip.exe install -r requirements-dev.txt
.\venv\Scripts\python.exe -m venv $EnvName

Write-Output "Activating Virtual Environment..."
Expand Down
4 changes: 2 additions & 2 deletions metadata.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Version: 1.2.0
Version: 1.2.1
CompanyName: Chenglong Ma
FileDescription: A launcher for starting LOL in different languages
FileDescription: LOL Launcher
InternalName: LOLauncher
LegalCopyright: © Chenglong Ma. All rights reserved.
OriginalFilename: LOLauncher.exe
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyinstaller-versionfile>=2.1.1
Binary file modified src/assets/icon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ctypes

ctypes.windll.shcore.SetProcessDpiAwareness(0)
ctypes.windll.user32.SetProcessDPIAware()
ctypes.windll.user32.SetProcessDPIAware()
49 changes: 20 additions & 29 deletions src/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def __init__(self, setting_files, config, gui_config):
self.locale_dict = {value: key for key, value in LOCALE_CODES.items()}
self.game_client = config.get("GameClient", "")
self.observers: [Observer] = []
self.watching = False
self.watch_thread = None

self.root = tk.Tk()
self.theme: str = self.ui_config.get("Theme", "light")
Expand Down Expand Up @@ -91,12 +89,19 @@ def set_quick_chat(self, icon, item):
self.quick_chat_enabled.set(not current_state)
self.quick_chat_enabled_setting = not current_state

def set_process_name(self):
process_name = easygui.enterbox("请输入进程名称", "设置进程名称", self.config.get("Process Name", "League of Legends.exe"))
if process_name:
self.config["Process Name"] = process_name
self.sync_config()
self.update_status(f"进程名称已设置为:{process_name}")

def create_menu_bar(self):
self.menu_bar = tk.Menu(self.root)
self.setting_menu = tk.Menu(self.menu_bar, tearoff=0)
self.setting_menu.add_command(label="自动检测游戏配置文件", command=self.detect_metadata_file)
self.setting_menu.add_command(label="手动选择游戏配置文件", command=self.choose_metadata_file)
# self.setting_menu.add_command(label="恢复默认", command=self.reset_settings)
self.setting_menu.add_command(label="设置进程名称", command=self.set_process_name)
self.setting_menu.add_separator()
self.setting_menu.add_command(label="切换颜色主题", command=lambda: self.root.after(0, self.toggle_theme))
self.minimize_on_closing = tk.BooleanVar(value=self.config.get("MinimizeOnClosing", True))
Expand All @@ -113,6 +118,7 @@ def toggle_theme(self):
self.theme = sv_ttk.get_theme()
self.quick_chat_warning_label.config(background=THEME_COLOR[self.theme]["warning_bg"], foreground=THEME_COLOR[self.theme]["warning_fg"])
self.quick_chat_warning_label.tag_config("link", foreground=THEME_COLOR[self.theme]["accent"], underline=True)
self.create_custom_button_style()

def create_locale_groupbox(self):
self.locale_groupbox = ttk.LabelFrame(self.root, text="语言设置", style='Card.TFrame')
Expand Down Expand Up @@ -205,9 +211,12 @@ def open_quick_chat_file(self):
create_quick_chat_file(CONFIG_FILENAME)
subprocess.run(['notepad.exe', QUICK_CHAT_FILENAME], check=False)

def create_launch_button(self):
def create_custom_button_style(self):
style = ttk.Style()
style.configure('CustomAccent.TButton', font=('Microsoft YaHei', 16, 'bold'))

def create_launch_button(self):
self.create_custom_button_style()
self.image = tk.PhotoImage(file=get_asset("button_icon.png"))
self.launch_button = ttk.Button(self.root, text="英雄联盟,启动!", image=self.image, compound=tk.LEFT,
command=self.start, style="CustomAccent.TButton")
Expand Down Expand Up @@ -281,47 +290,29 @@ def start(self):
messagebox.showerror("错误", "配置文件更新失败,无法启动游戏。")
return

self.start_observers()
self.start_game(*settings)
self.on_window_minimizing(True)

def wait_for_observer_stopping(self):
def stop_observers(self):
print("Stopping observer...")
self.watching = False
for observer in self.observers:
if observer is not None and observer.is_alive():
observer.stop()
# observer.join()
observer.join()
print("Observer stopped")
self.observers = []

def start_watch_thread(self):
self.wait_for_observer_stopping()
self.watch_thread = threading.Thread(target=self.watch_file)
self.watch_thread.start()

def watch_file(self):
self.wait_for_observer_stopping()
def start_observers(self):
event_handler = FileWatcher(*self.setting_files, selected_locale=self.selected_locale)
unique_dirs = set(os.path.dirname(file) for file in self.setting_files)
for directory in unique_dirs:
observer = Observer()
observer.schedule(event_handler, path=directory, recursive=False)
observer.start()
self.observers.append(observer)
self.watching = True
print(f"Start Watching...")

try:
while self.watching:
time.sleep(1)
except KeyboardInterrupt:
[observer.stop() for observer in self.observers]
self.watching = False
except Exception as e:
self.update_status(f"Error: {e}")
[observer.stop() for observer in self.observers]
self.watching = False

def detect_metadata_file(self):
is_yes = tk.messagebox.askyesno("提示", "您确定要重新检测以修改已有配置?")
if is_yes:
Expand Down Expand Up @@ -351,6 +342,7 @@ def choose_metadata_file(self):
tk.messagebox.showinfo("提示", msg)

def on_locale_changed(self, event):
self.stop_observers()
current_value = self.locale_var.get()
self.selected_locale = self.locale_dict[current_value]
self.update_status(f"语言将被设置为:{current_value}")
Expand Down Expand Up @@ -378,7 +370,6 @@ def on_window_minimizing(self, force_minimize=False):
self.on_window_closing(self.tray_app)

def run(self):
self.start_watch_thread()
self.tray_thread.start()
self.root.mainloop()
self.tray_thread.join()
Expand All @@ -392,7 +383,7 @@ def sync_config(self):
"GameClient": self.game_client,
"Locale": self.selected_locale,
"MinimizeOnClosing": self.minimize_on_closing.get(),
"Process Name": "League of Legends.exe",
"Process Name": self.config.get("Process Name", "League of Legends.exe"),
"QuickChatEnabled": self.quick_chat_enabled.get(),
"QuickChatShortcut": self.shortcut_var.get(),
"QuickChatDoc": QUICK_CHAT_DOC,
Expand All @@ -409,7 +400,7 @@ def on_window_closing(self, icon: pystray.Icon = None, item=None):

close = messagebox.askyesno("退出", "退出后再启动游戏时文本和语音将恢复为默认设置\n您确定要退出吗?")
if close:
self.wait_for_observer_stopping()
self.stop_observers()
if icon:
icon.stop()
self.sync_config()
Expand Down
5 changes: 2 additions & 3 deletions src/ui/quick_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def __init__(self, app, config, gui_config):
self.user_config = config
self.ui_config = gui_config
self.shortcut = None
self.lol_exe_name = self.user_config.get('Process Name', 'League of Legends.exe')
self.lol_pid = None
self.lock = threading.Lock()

Expand All @@ -62,7 +61,7 @@ def __init__(self, app, config, gui_config):
self.attributes('-alpha', 0.95)
self.config(
background=self.default_bg,
# borderwidth=10, # DON'T use this to change border width
# borderwidth=10, # DON'T use this to change border width
highlightthickness=3,
highlightcolor=self.border_color,
highlightbackground=self.border_color_inactive,
Expand Down Expand Up @@ -163,7 +162,7 @@ def toggle_window(self):
if self.winfo_viewable():
self.withdraw()
else:
self.lol_pid = is_running(self.lol_exe_name)
self.lol_pid = is_running(self.user_config.get("Process Name", "League of Legends.exe"))
if not self.lol_pid:
decision = easygui.buttonbox("游戏对局未开始,是否显示一键喊话对话框?", "提示", ["是", "取消", "关闭一键喊话"])
if not decision or decision == "取消":
Expand Down
3 changes: 1 addition & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from github import Github
from watchdog.events import FileSystemEventHandler

VERSION = '1.2.0'
VERSION = '1.2.1'
APP_NAME = 'LOLauncher'
REPO_NAME = 'ChenglongMa/LOLauncher'
SUPPORTED_PATCH_LINEs = ['live', 'pbe']
Expand Down Expand Up @@ -129,7 +129,6 @@ def is_running(process_name):
return pid
except Exception as e:
print(f"Error checking if {process_name} is running: {e}")
pass


def is_foreground_window(pid):
Expand Down

0 comments on commit 628ff7d

Please sign in to comment.