-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.py
101 lines (83 loc) · 3.52 KB
/
Utils.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import ctypes
import tkinter as tk
from tkinter import messagebox, simpledialog
import platform
import os
import sys
import shutil
# DEV MODE
DEV_MODE = True
# Check if discord is installed
def IsDiscordAppInstalled() -> bool:
"""Check if the Discord application is installed based on the OS."""
if sys.platform.startswith("win"):
# Windows: Check the LocalAppData directory for Discord
discord_paths = [
os.path.join(os.getenv("LOCALAPPDATA", ""), "Discord"),
os.path.join(os.getenv("LOCALAPPDATA", ""), "DiscordCanary"),
os.path.join(os.getenv("LOCALAPPDATA", ""), "DiscordPTB"),
]
return any(os.path.exists(path) for path in discord_paths)
elif sys.platform.startswith("linux"):
# Linux: Check common locations or use `shutil.which`
return any(os.path.exists(path) for path in [
"/usr/bin/discord",
"/snap/bin/discord",
os.path.expanduser("~/.local/bin/discord"),
]) or shutil.which("discord") is not None
elif sys.platform.startswith("darwin"):
# macOS: Check the Applications folder
discord_paths = [
"/Applications/Discord.app",
"/Applications/Discord Canary.app",
"/Applications/Discord PTB.app"
]
return any(os.path.exists(path) for path in discord_paths)
return False # Unknown platform
class PopupManager:
def __init__(self):
self.os_name = platform.system()
if self.os_name != "Windows":
self.root = tk.Tk()
self.root.withdraw() # Hide the root window
if DEV_MODE:
print(f"[DEBUG] PopupManager initialized on {self.os_name}")
def _windows_messagebox(self, title: str, text: str, icon: str) -> None:
"""Show a Windows native message box using ctypes."""
icons = {
"info": 0x40, # MB_ICONINFORMATION
"warning": 0x30, # MB_ICONWARNING
"error": 0x10 # MB_ICONERROR
}
result = ctypes.windll.user32.MessageBoxW(0, text, title, icons.get(icon, 0))
if DEV_MODE:
print(f"[DEBUG] Windows MessageBox ({icon}) -> Title: '{title}', Text: '{text}', Result: {result}")
def Warning(self, Title: str, Text: str) -> None:
"""Show a warning message box."""
if DEV_MODE:
print(f"[DEBUG] Warning: {Title} - {Text}")
if self.os_name == "Windows":
self._windows_messagebox(Title, Text, "warning")
else:
messagebox.showwarning(Title, Text)
def Info(self, Title: str, Text: str) -> None:
"""Show an info message box."""
if DEV_MODE:
print(f"[DEBUG] Info: {Title} - {Text}")
if self.os_name == "Windows":
self._windows_messagebox(Title, Text, "info")
else:
messagebox.showinfo(Title, Text)
def Error(self, Title: str, Text: str) -> None:
"""Show an error message box."""
if DEV_MODE:
print(f"[DEBUG] Error: {Title} - {Text}")
if self.os_name == "Windows":
self._windows_messagebox(Title, Text, "error")
else:
messagebox.showerror(Title, Text)
def TextInput(self, Title: str, Prompt: str) -> str | None:
"""Prompt the user for text input."""
if DEV_MODE:
print(f"[DEBUG] TextInput Prompt: {Title} - {Prompt}")
return simpledialog.askstring(Title, Prompt)