From 08927265381c668cd8311712967506d5b1a6d99e Mon Sep 17 00:00:00 2001 From: Akari Ami Date: Sat, 20 Apr 2024 03:07:43 +0700 Subject: [PATCH] Bug fixes --- .env | 1 + DetailedLoLRPC.py | 16 +++++----- utilities.py | 77 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..772c16f --- /dev/null +++ b/.env @@ -0,0 +1 @@ +CLIENTID=MTExODA2MjcxMTY4Nzg3MjU5Mw== \ No newline at end of file diff --git a/DetailedLoLRPC.py b/DetailedLoLRPC.py index 92a4785..5956a27 100644 --- a/DetailedLoLRPC.py +++ b/DetailedLoLRPC.py @@ -1,5 +1,5 @@ from lcu_driver import Connector -from utilities import isOutdated, GITHUBURL, CLIENTID, fetchConfig, procPath, resetLog, addLog, resourcePath +from utilities import isOutdated, GITHUBURL, CLIENTID, fetchConfig, procPath, resetLog, addLog, resourcePath, yesNoBox from cdngen import * from disabler import disableNativePresence from pypresence import Presence @@ -7,11 +7,11 @@ from aiohttp import request from os import _exit, system, path as op from tray_icon import icon -from easygui import buttonbox from multiprocessing import Process, freeze_support from subprocess import Popen, PIPE from nest_asyncio import apply from json import loads +from asyncio import sleep as asyncSleep if __name__ == "__main__": @@ -26,8 +26,8 @@ # Check for updates outdated = isOutdated() if outdated: - choice = buttonbox(f"A newer version of DetailedLoLRPC detected ({outdated}). Do you want to visit the download site?", "DetailedLoLRPC", ("Yes", "No"), cancel_choice = "No", icon=resourcePath("icon.ico")) - if choice == "Yes": + choice = yesNoBox(f"A newer version of DetailedLoLRPC detected ({outdated}). Do you want to visit the download site?") + if choice: system(f"start \"\" {GITHUBURL}") sleep(1) _exit(0) @@ -77,7 +77,9 @@ async def connect(connection): @connector.close async def disconnect(_): - _exit(0) + await asyncSleep(1) + if not procPath("LeagueClient.exe"): + _exit(0) @connector.ws.register("/lol-gameflow/v1/session", event_types = ("CREATE", "UPDATE", "DELETE")) async def gameFlow(connection, event): @@ -216,8 +218,8 @@ async def chatUpdate(connection, event): isLeagueOpened = procPath("LeagueClient.exe") choice = "NoStart" if isLeagueOpened: - choice = buttonbox(f"DetailedLoLRPC might not work properly if opened after League of Legends. Continue?", "DetailedLoLRPC", ("Yes", "No"), cancel_choice = "No", icon=resourcePath("icon.ico")) - if choice == "No": + choice = yesNoBox("DetailedLoLRPC might not work properly if opened after League of Legends. Continue?") + if not choice: _exit(0) # Tray Icon diff --git a/utilities.py b/utilities.py index 1a2c587..a84b676 100644 --- a/utilities.py +++ b/utilities.py @@ -4,9 +4,23 @@ from requests import get from pickle import load, dump from json import load as loadj, dump as dumpj -from easygui import enterbox +import tkinter as tk +from tkinter import messagebox, ttk +from dotenv import load_dotenv +from base64 import b64decode -VERSION = "v2.8" +def resourcePath(relative_path): + try: + base_path = sys._MEIPASS + except Exception: + base_path = op.abspath(".") + + return op.join(base_path, relative_path) + + +load_dotenv(resourcePath(".env")) + +VERSION = "v2.9" GITHUBURL = "https://github.com/developers192/DetailedLoLRPC/releases/latest" ISSUESURL = "https://github.com/developers192/DetailedLoLRPC/issues/new" DEFAULTCONFIG = { @@ -17,15 +31,55 @@ } CONFIGDIR = op.join(getenv("APPDATA"), "DetailedLoLRPC", "config.dlrpc") LOGDIR = op.join(getenv("APPDATA"), "DetailedLoLRPC", "sessionlog.json") -CLIENTID = "1118062711687872593" +CLIENTID = b64decode(getenv("CLIENTID")).decode("utf-8") -def resourcePath(relative_path): - try: - base_path = sys._MEIPASS - except Exception: - base_path = op.abspath(".") +def yesNoBox(msg): + root = tk.Tk() + root.withdraw() + root.iconbitmap(resourcePath("icon.ico")) - return op.join(base_path, relative_path) + result = messagebox.askyesno("DetailedLoLRPC", msg) + return result + +def inputBox(msg): + root = tk.Tk() + root.withdraw() + + dialog = tk.Toplevel(root) + dialog.title("DetailedLoLRPC") + dialog.geometry("360x150") + dialog.resizable(False, False) + dialog.iconbitmap(resourcePath("icon.ico")) + + label = tk.Label(dialog, text= msg, wraplength=300) + label.pack(pady=10) + + entry = tk.Entry(dialog, width=50) + entry.pack(pady=5) + + button_frame = tk.Frame(dialog) + button_frame.pack(pady=10) + + def on_yes(): + global result + result = "-1" + result = entry.get() + dialog.destroy() + + yes_button = ttk.Button(button_frame, text="Confirm", style="Windows.TButton", command=on_yes) + yes_button.pack(side=tk.LEFT, padx=5) + + def on_no(): + global result + result = None + dialog.destroy() + dialog.protocol("WM_DELETE_WINDOW", on_no) + + no_button = ttk.Button(button_frame, text="Cancel", style="Windows.TButton", command=on_no) + no_button.pack(side=tk.LEFT, padx=5) + + dialog.wait_window(dialog) + return result def procPath(name): for proc in pi(): @@ -53,13 +107,14 @@ def getRiotPath(): if path: path = op.dirname(op.dirname(path)) else: - path = enterbox(r'Riot Services process was not found. Please enter the path to the "Riot Games" folder below (E.g. C:\Riot Games)', "DetailedLoLRPC") + n = "\n" + path = inputBox(rf'Riot Services process was not found. Please enter the path to the "Riot Games" folder below{n}(E.g. C:\Riot Games)') while True: if path is None: _exit(0) if checkRiotClientPath(path): break - path = enterbox(r'Invalid Path. Please enter the path to the "Riot Games" folder below (E.g. C:\Riot Games)', "DetailedLoLRPC") + path = inputBox(r'Invalid Path. Please enter the path to the "Riot Games" folder below (E.g. C:\Riot Games)') return path def fetchConfig(entry):