Skip to content

Commit 1b3b6fb

Browse files
committed
poshalko
1 parent cdbd907 commit 1b3b6fb

File tree

7 files changed

+68
-45
lines changed

7 files changed

+68
-45
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = [
99
"flet[desktop]>=0.28.3",
1010
"minestat>=2.6.3",
1111
"psutil>=7.0.0",
12-
"nuitka>=2.7.3",
12+
"nava>=0.7",
1313
]
1414

1515
[tool.flet]

src/assets/iddqd.png

940 Bytes
Loading

src/assets/iddqd.wav

18.5 KB
Binary file not shown.

src/assets/mono.wav

10 KB
Binary file not shown.

src/config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
import platform
55
import psutil
66

7-
import nuitka
87
from pathlib import Path
98
import _version
109

11-
_COMPILED = getattr(nuitka, "__compiled__", False)
12-
# _COMPILED = getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS")
10+
# _COMPILED = getattr(nuitka, "__compiled__", False)
11+
_COMPILED = getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS")
1312

1413
if _COMPILED:
1514
# If the script is compiled, use the directory of the executable
1615
LAUNCHER_VERSION = _version.version
1716
LAUNCHER_DIRECTORY = os.path.dirname(sys.executable)
18-
# MEIPASS_FOLDER_NAME = os.path.basename(sys._MEIPASS)
17+
MEIPASS_FOLDER_NAME = os.path.basename(sys._MEIPASS)
18+
BASE_PATH = sys._MEIPASS
1919
else:
2020
LAUNCHER_VERSION = "[DEV]"
2121
LAUNCHER_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
22-
# MEIPASS_FOLDER_NAME = None
22+
MEIPASS_FOLDER_NAME = None
23+
BASE_PATH = os.path.dirname(__file__)
2324

2425
LAUNCHER_NAME = "Кубічний Лаунчер"
2526
WINDOW_SIZE = (900, 564)

src/routes/index.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import httpx
77
import flet as ft
8+
from nava import play
89
import minecraft_launcher_lib as mcl
910

1011
from minestat import MineStat, SlpProtocols
@@ -16,6 +17,7 @@
1617
from updater import updater
1718
from config import (
1819
AUTHLIB_INJECTOR_URL,
20+
BASE_PATH,
1921
SERVER_IP,
2022
SKINS_CACHE_FOLDER,
2123
LAUNCHER_DIRECTORY,
@@ -32,6 +34,7 @@ def __init__(self, page: ft.Page):
3234
super().__init__(route="/")
3335
self.page = page
3436
self.controls = []
37+
self._keypressed_list = []
3538
self._max_progress = 0
3639
self._download_callback = { # lambda : self._progress_text.text = status,
3740
"setStatus": lambda status: self._set_progress_text(status),
@@ -42,23 +45,43 @@ def __init__(self, page: ft.Page):
4245
self.page.run_task(self._server_status_update)
4346
self.page.run_task(self._check_launcher_updates)
4447
self.page.run_task(self._check_modpack_update_task)
48+
self.page.on_keyboard_event = self.on_keyboard_event
49+
50+
async def on_keyboard_event(self, event: ft.KeyboardEvent):
51+
# check iddqd
52+
self._keypressed_list.append(event.key)
53+
if len(self._keypressed_list) > 5:
54+
self._keypressed_list.pop(0)
55+
if self._keypressed_list == ["I", "D", "D", "Q", "D"]:
56+
self._keypressed_list = []
57+
play(os.path.join(BASE_PATH, "assets", "iddqd.wav"), async_mode=True)
58+
event.page.views[0].pagelet.appbar.leading.content = ft.Image(
59+
src="iddqd.png",
60+
filter_quality=ft.FilterQuality.NONE,
61+
fit=ft.ImageFit.CONTAIN,
62+
width=64,
63+
height=64,
64+
)
65+
self.page.update()
4566

4667
async def _check_launcher_updates(self):
4768
while True:
4869
if await updater.check_for_update():
4970
self.page.open(self._update_banner)
5071
self.page.update()
5172
await asyncio.sleep(60)
52-
73+
5374
async def _check_modpack_update_task(self):
5475
while True:
55-
await asyncio.sleep(60)
76+
await asyncio.sleep(60)
5677
await asyncio.to_thread(self._check_modpack_update)
5778

5879
def _check_modpack_update(self):
5980
modpack._fetch_latest_index()
6081
if not modpack.is_up_to_date():
61-
self._installed_version.value = f"Встановлена версія: {modpack.installed_version}"
82+
self._installed_version.value = (
83+
f"Встановлена версія: {modpack.installed_version}"
84+
)
6285
self._latest_version.value = f"Остання версія: {modpack.remote_version}"
6386
# update changelog
6487
self._get_changelog()
@@ -107,7 +130,6 @@ def _install_update(self):
107130
logging.info("Launcher exited.")
108131

109132
def kill_app(self):
110-
111133
logging.info("Trying to exit program via asyncio")
112134
to_cancel = asyncio.all_tasks(self.page.loop)
113135
if not to_cancel:
@@ -132,6 +154,10 @@ def _get_changelog(self):
132154
# add new _changelog
133155
self.pagelet.content.content.controls.append(self._changelog)
134156

157+
def __open_monobank(self, event: ft.TapEvent):
158+
play(os.path.join(BASE_PATH, "assets", "mono.wav"), async_mode=True)
159+
self._open_link("https://send.monobank.ua/jar/48bPzh2JmA")
160+
135161
def build_ui(self):
136162
self._update_banner = ft.Banner(
137163
bgcolor=ft.Colors.SECONDARY_CONTAINER,
@@ -192,9 +218,7 @@ def build_ui(self):
192218
# donate button
193219
ft.IconButton(
194220
icon=ft.Icons.ATTACH_MONEY,
195-
on_click=lambda e: self._open_link(
196-
"https://send.monobank.ua/jar/48bPzh2JmA"
197-
),
221+
on_click=self.__open_monobank,
198222
tooltip="Підтримати проект",
199223
),
200224
# github
@@ -236,28 +260,26 @@ def build_ui(self):
236260
padding=ft.Padding(0, 0, 8, 0),
237261
),
238262
],
239-
240263
)
241264
self._play_button = ft.FloatingActionButton(
242265
icon=ft.Icons.PLAY_ARROW,
243-
244266
text="Грати",
245267
width=160,
246268
on_click=self._check_game,
247269
)
248270
self._check_game_button = ft.FloatingActionButton(
249271
icon=ft.Icons.RESTART_ALT,
250272
bgcolor=ft.Colors.SECONDARY_CONTAINER,
251-
252273
tooltip="Перевстановити гру",
253274
on_click=self._force_install_game,
254275
)
255276
self._open_game_folder_button = ft.FloatingActionButton(
256277
icon=ft.Icons.FOLDER,
257278
bgcolor=ft.Colors.SECONDARY_CONTAINER,
258-
259279
tooltip="Відкрити папку з грою",
260-
on_click=lambda e: self._open_link(f"file://{settings.minecraft_directory}"),
280+
on_click=lambda e: self._open_link(
281+
f"file://{settings.minecraft_directory}"
282+
),
261283
)
262284
self.floating_action_button = ft.Container(
263285
ft.Row(

src/updater.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import sys
3-
# import shutil
3+
import shutil
44
import httpx
55
import logging
66
import subprocess
@@ -13,7 +13,7 @@
1313
SYSTEM_OS,
1414
LAUNCHER_DIRECTORY,
1515
APPDATA_FOLDER,
16-
# MEIPASS_FOLDER_NAME,
16+
MEIPASS_FOLDER_NAME,
1717
)
1818

1919

@@ -32,7 +32,7 @@ async def check_for_update(self) -> bool:
3232
if "dev" in self.version or not _COMPILED:
3333
# Don't check for updates in dev build or if not compiled
3434
return False
35-
# self.clear_old_meipass()
35+
self.clear_old_meipass()
3636
self.update_available = (
3737
await self.get_latest_version() != self.version
3838
and self.latest_version != ""
@@ -69,19 +69,19 @@ def download_update(self):
6969
logging.info("Update downloaded successfully.")
7070
self.replace_current_version()
7171

72-
# def copy_meipass(self):
73-
# # HACK: copy _MEIPASS to the temp directory
74-
# if not os.path.exists(
75-
# os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME),
76-
# ):
77-
# os.makedirs(os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME))
78-
# # copy _MEIPASS to the temp
79-
# shutil.copytree(
80-
# sys._MEIPASS,
81-
# os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME),
82-
# dirs_exist_ok=True,
83-
# )
84-
# logging.info(f"Copied _MEIPASS to temporary directory: {MEIPASS_FOLDER_NAME}")
72+
def copy_meipass(self):
73+
# HACK: copy _MEIPASS to the temp directory
74+
if not os.path.exists(
75+
os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME),
76+
):
77+
os.makedirs(os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME))
78+
# copy _MEIPASS to the temp
79+
shutil.copytree(
80+
sys._MEIPASS,
81+
os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME),
82+
dirs_exist_ok=True,
83+
)
84+
logging.info(f"Copied _MEIPASS to temporary directory: {MEIPASS_FOLDER_NAME}")
8585

8686
def replace_current_version(self):
8787
# self.copy_meipass()
@@ -93,7 +93,7 @@ def replace_current_version(self):
9393
"/c",
9494
"timeout /t 1 & "
9595
+ f"move /y {os.path.join(self.temp_dir, self.executable)} {os.path.join(LAUNCHER_DIRECTORY, self.executable)} & "
96-
# + f"move /y {os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME)} {sys._MEIPASS} & "
96+
+ f"move /y {os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME)} {sys._MEIPASS} & "
9797
+ f"start {os.path.join(LAUNCHER_DIRECTORY, self.executable)}",
9898
],
9999
creationflags=subprocess.CREATE_NO_WINDOW,
@@ -111,22 +111,22 @@ def replace_current_version(self):
111111
"-c",
112112
"sleep 1 && "
113113
+ f"mv '{os.path.join(self.temp_dir, self.executable)}' '{os.path.join(LAUNCHER_DIRECTORY, self.executable)}' && "
114-
# + f"mv '{os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME)}' '{sys._MEIPASS}' && "
114+
+ f"mv '{os.path.join(self.temp_dir, MEIPASS_FOLDER_NAME)}' '{sys._MEIPASS}' && "
115115
+ f"exec '{os.path.join(LAUNCHER_DIRECTORY, self.executable)}'",
116116
],
117117
start_new_session=True,
118118
)
119119

120-
# def clear_old_meipass(self):
121-
# # HACK: remove old _MEIPASS folder
122-
# meipass_parent = os.path.dirname(sys._MEIPASS)
123-
# meipass_folder = os.path.basename(sys._MEIPASS)
124-
# for folder in os.listdir(meipass_parent):
125-
# if folder.startswith("_MEI") and folder != meipass_folder:
126-
# shutil.rmtree(os.path.join(meipass_parent, folder))
127-
# logging.info(f"Removed old _MEIPASS folder: {folder}")
120+
def clear_old_meipass(self):
121+
# HACK: remove old _MEIPASS folder
122+
meipass_parent = os.path.dirname(sys._MEIPASS)
123+
meipass_folder = os.path.basename(sys._MEIPASS)
124+
for folder in os.listdir(meipass_parent):
125+
if folder.startswith("_MEI") and folder != meipass_folder:
126+
shutil.rmtree(os.path.join(meipass_parent, folder))
127+
logging.info(f"Removed old _MEIPASS folder: {folder}")
128128

129-
# logging.info("Old MEIPASS folders cleared.")
129+
logging.info("Old MEIPASS folders cleared.")
130130

131131

132132
updater = Updater()

0 commit comments

Comments
 (0)