Skip to content

Commit

Permalink
perf: defer loading icon theme if not needed (makes startup slightly …
Browse files Browse the repository at this point in the history
…faster)
  • Loading branch information
friday committed May 12, 2024
1 parent 394dde9 commit 812606f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ulauncher/ui/windows/ulauncher_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ulauncher.internals.result import Result
from ulauncher.ui import layer_shell
from ulauncher.utils.eventbus import EventBus
from ulauncher.utils.load_icon_surface import load_icon_surface # TODO: investigate why this takes ~35-40ms to load
from ulauncher.utils.load_icon_surface import load_icon_surface
from ulauncher.utils.settings import Settings
from ulauncher.utils.theme import Theme
from ulauncher.utils.wm import get_monitor
Expand Down
12 changes: 7 additions & 5 deletions ulauncher/utils/load_icon_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from gi.repository import Gdk, GdkPixbuf

from ulauncher.config import paths
from ulauncher.utils.get_icon_path import get_icon_path

logger = logging.getLogger()

Expand All @@ -18,13 +17,16 @@
def load_icon_surface(icon: str, size: int, scaling_factor: int = 1) -> ImageSurface:
real_size = size * scaling_factor
try:
icon_path = get_icon_path(icon, real_size) or DEFAULT_EXE_ICON
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_path, real_size, real_size)
if not icon.startswith("/"):
from ulauncher.utils.get_icon_path import get_icon_path

icon = get_icon_path(icon, real_size) or DEFAULT_EXE_ICON
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon, real_size, real_size)
assert pixbuf
return Gdk.cairo_surface_create_from_pixbuf(pixbuf, scaling_factor)
except Exception as e:
if icon_path == DEFAULT_EXE_ICON:
msg = f"Could not load fallback icon: {icon_path}"
if icon == DEFAULT_EXE_ICON:
msg = f"Could not load fallback icon: {icon}"
raise RuntimeError(msg) from e

logger.warning("Could not load specified icon %s (%s). Will use fallback icon", icon, e)
Expand Down

0 comments on commit 812606f

Please sign in to comment.