fix(icon): force Win32 WM_SETICON before window creation and bust desktop shortcut icon cache

This commit is contained in:
LilDosto 2026-11-04 04:23:49 +03:00
parent 3dd1e04f29
commit 8b500db276
3 changed files with 65 additions and 21 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 197 KiB

View file

@ -23,7 +23,9 @@ PrivilegesRequiredOverridesAllowed=dialog
OutputDir=dist
OutputBaseFilename=LDownloader-v{#MyAppVersion}-Setup
SetupIconFile=assets\logo.ico
UninstallDisplayIcon={app}\{#MyAppExeName}
UninstallDisplayIcon={app}\assets\ld_v35_icon.ico
ChangesAssociations=yes
CloseApplications=force
Compression=lzma2/ultra64
SolidCompression=yes
WizardStyle=modern
@ -38,11 +40,12 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
[Files]
Source: "dist\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "assets\logo.ico"; DestDir: "{app}\assets"; Flags: ignoreversion
Source: "assets\logo.ico"; DestDir: "{app}\assets"; DestName: "ld_v35_icon.ico"; Flags: ignoreversion
Source: "LICENSE"; DestDir: "{app}"; Flags: ignoreversion
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\assets\ld_v35_icon.ico"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\assets\ld_v35_icon.ico"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

View file

@ -34,7 +34,7 @@ class LDownloaderApp(tk.Tk):
except Exception:
pass
try:
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("lildosto.ldownloader.v35.icon")
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("lildosto.ldownloader.v35.ldicon2")
except Exception:
pass
@ -44,6 +44,12 @@ class LDownloaderApp(tk.Tk):
self.minsize(880, 580)
self.configure(bg=BG)
# İkon ve Logo — Pencere ekranda oluşturulmadan (update_idletasks öncesi) yüklenmelidir
self._ico_path = None
self._hicon_big = None
self._hicon_sm = None
self._load_icons()
# Ekranı ortala
self.update_idletasks()
sw = self.winfo_screenwidth()
@ -54,8 +60,9 @@ class LDownloaderApp(tk.Tk):
y = max(0, (sh - height) // 2)
self.geometry(f"{width}x{height}+{x}+{y}")
# İkon ve Logo
self._load_icons()
# Win32 HWND oluştuktan hemen sonra görev çubuğu (WM_SETICON) ikonunu zorla
self._apply_win32_icon()
self.after(100, self._apply_win32_icon)
# Tema ve stiller
apply_theme(self, config.get("theme", "dark"))
@ -78,14 +85,19 @@ class LDownloaderApp(tk.Tk):
ico_path = os.path.join(app_dir, "assets", "logo.ico")
if not os.path.isfile(ico_path):
ico_path = os.path.join(app_dir, "logo.ico")
ico_loaded = False
if os.path.isfile(ico_path):
self._ico_path = os.path.abspath(ico_path)
try:
self.iconbitmap(default=ico_path)
self.iconbitmap(self._ico_path)
ico_loaded = True
except Exception:
try:
self.iconbitmap(ico_path)
except Exception:
pass
pass
try:
self.iconbitmap(default=self._ico_path)
ico_loaded = True
except Exception:
pass
self.logo_img = None
self.window_icon_img = None
@ -97,29 +109,58 @@ class LDownloaderApp(tk.Tk):
try:
from PIL import Image, ImageTk
pil_img = Image.open(png_path).convert("RGBA")
# Kenar boşluğu kalmışsa otomatik kırp
bbox = pil_img.getbbox()
if bbox:
pil_img = pil_img.crop(bbox)
for sz in (256, 64, 48, 32, 16):
self.window_icon_imgs.append(
ImageTk.PhotoImage(pil_img.resize((sz, sz), Image.Resampling.LANCZOS))
)
self.window_icon_img = self.window_icon_imgs[0]
self.iconphoto(True, *self.window_icon_imgs)
self.logo_img = ImageTk.PhotoImage(
pil_img.resize((28, 28), Image.Resampling.LANCZOS)
pil_img.resize((30, 30), Image.Resampling.LANCZOS)
)
if not ico_loaded or sys.platform != "win32":
for sz in (64, 48, 32, 16):
self.window_icon_imgs.append(
ImageTk.PhotoImage(pil_img.resize((sz, sz), Image.Resampling.LANCZOS))
)
self.window_icon_img = self.window_icon_imgs[0]
self.iconphoto(True, *self.window_icon_imgs)
except Exception:
try:
raw = tk.PhotoImage(file=png_path)
self.window_icon_img = raw
self.iconphoto(True, raw)
factor = max(1, raw.width() // 28)
if not ico_loaded or sys.platform != "win32":
self.iconphoto(True, raw)
factor = max(1, raw.width() // 30)
self.logo_img = raw.subsample(factor, factor)
except Exception:
pass
def _apply_win32_icon(self):
if sys.platform != "win32" or not self._ico_path or not os.path.isfile(self._ico_path):
return
try:
user32 = ctypes.windll.user32
hwnd = user32.GetParent(self.winfo_id()) or self.winfo_id()
if not hwnd:
return
LR_LOADFROMFILE = 0x00000010
IMAGE_ICON = 1
WM_SETICON = 0x0080
ICON_SMALL = 0
ICON_BIG = 1
GCLP_HICON = -14
GCLP_HICONSM = -34
if not self._hicon_big:
self._hicon_big = user32.LoadImageW(0, self._ico_path, IMAGE_ICON, 256, 256, LR_LOADFROMFILE)
if not self._hicon_sm:
self._hicon_sm = user32.LoadImageW(0, self._ico_path, IMAGE_ICON, 32, 32, LR_LOADFROMFILE)
if self._hicon_big:
user32.SendMessageW(hwnd, WM_SETICON, ICON_BIG, self._hicon_big)
user32.SetClassLongPtrW(hwnd, GCLP_HICON, self._hicon_big)
if self._hicon_sm:
user32.SendMessageW(hwnd, WM_SETICON, ICON_SMALL, self._hicon_sm)
user32.SetClassLongPtrW(hwnd, GCLP_HICONSM, self._hicon_sm)
except Exception:
pass
def _build_layout(self):
# ── Birleşik Üst Çubuk (Logo + Sekmeler + Durum) ────────────
top_bar = tk.Frame(self, bg=TAB_BG, padx=24, pady=8)