Skip to content

Commit 860166b

Browse files
committed
'v2.2'
1 parent c06b97d commit 860166b

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ BlueStacks Root GUI is a utility designed to easily toggle root access settings
7777
5. **Build the Executable (Optional):**
7878
```bash
7979
pip install pyinstaller
80-
pyinstaller --onefile --windowed --icon=favicon.ico --name BlueStacksRootGUI main.py
80+
pyinstaller --onefile --windowed --icon="favicon.ico" --add-data "favicon.ico;." --name BlueStacksRootGUI main.py
8181
```
8282
The executable will be in the `dist/` folder.
8383

main.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@
3737
logger = logging.getLogger(__name__)
3838

3939

40+
def resource_path(relative_path):
41+
"""Get absolute path to resource, works for dev and for PyInstaller"""
42+
try:
43+
base_path = sys._MEIPASS
44+
except AttributeError:
45+
base_path = os.path.abspath(".")
46+
except Exception:
47+
base_path = os.path.abspath(".")
48+
49+
path = os.path.join(base_path, relative_path)
50+
return path
51+
52+
4053
class Worker(QObject):
4154
"""
4255
Runs a function in a separate thread and emits signals upon completion or error.
@@ -306,15 +319,17 @@ def __init__(self):
306319
def _set_icon(self):
307320
"""Sets the window icon if the icon file exists."""
308321
try:
309-
app_icon = QIcon(constants.ICON_FILENAME)
322+
icon_path = resource_path(constants.ICON_FILENAME)
323+
app_icon = QIcon(icon_path)
310324
if not app_icon.isNull():
311325
self.setWindowIcon(app_icon)
326+
logger.debug(f"Window icon set from {icon_path}")
312327
else:
313328
logger.warning(
314-
f"{constants.ICON_FILENAME} not found or is invalid. Skipping window icon."
329+
f"Icon file loaded from {icon_path} but QIcon is null. Check icon validity/path."
315330
)
316331
except Exception as e:
317-
logger.error(f"Error setting window icon: {e}")
332+
logger.error(f"Error setting window icon using resource_path: {e}")
318333

319334
def init_ui(self) -> None:
320335
"""Creates and arranges the UI widgets."""
@@ -1134,14 +1149,17 @@ def closeEvent(self, event) -> None:
11341149
logger.error(f"Error setting AppUserModelID: {e}")
11351150

11361151
app = QApplication(sys.argv)
1137-
app_icon = QIcon(constants.ICON_FILENAME)
1138-
if not app_icon.isNull():
1139-
app.setWindowIcon(app_icon)
1140-
logger.debug(f"Application icon set from {constants.ICON_FILENAME}")
1141-
else:
1142-
logger.warning(
1143-
f"Application icon file '{constants.ICON_FILENAME}' not found or invalid."
1144-
)
1152+
1153+
try:
1154+
icon_path = resource_path(constants.ICON_FILENAME)
1155+
app_icon = QIcon(icon_path)
1156+
if not app_icon.isNull():
1157+
app.setWindowIcon(app_icon)
1158+
logger.debug(f"Application icon set from {icon_path}")
1159+
else:
1160+
logger.warning(f"App icon file loaded from {icon_path} but QIcon is null.")
1161+
except Exception as e:
1162+
logger.error(f"Error setting application icon using resource_path: {e}")
11451163

11461164
window = BluestacksRootToggle()
11471165
window.show()

0 commit comments

Comments
 (0)