Skip to content

Commit

Permalink
Fixed mac build (#8123)
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink authored Sep 4, 2024
2 parents 7834899 + 6b1b640 commit 4f6aaf6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
8 changes: 6 additions & 2 deletions build/tribler.spec
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ if sys.platform == 'darwin':
show_console = True

data_to_copy = [
# UI related files
(os.path.join(src_dir, "tribler", "ui", "dist"), 'ui/dist'),
(os.path.join(src_dir, "tribler", "ui", "public"), 'ui/public'),

# Tribler source files and resources
(os.path.join(src_dir, "tribler", "core"), 'tribler_source/tribler/core'),
(os.path.join(src_dir, "tribler", "ui", "public"), 'tribler_source/tribler/ui/public'),
(os.path.join(src_dir, "tribler", "ui", "dist"), 'tribler_source/tribler/ui/dist'),
(os.path.join(src_dir, "tribler", "ui"), 'tribler_source/tribler/ui'),
(os.path.join(root_dir, "build", "win", "resources"), 'tribler_source/resources'),

(os.path.dirname(aiohttp_apispec.__file__), 'aiohttp_apispec')
Expand Down
2 changes: 1 addition & 1 deletion src/run_tribler.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async def main() -> None:
if server_url and torrent_uri:
await start_download(config, server_url, torrent_uri)

image_path = Path(tribler.__file__).parent / "ui/public/tribler.png"
image_path = tribler.get_webui_root() / "public" / "tribler.png"
image = Image.open(image_path.resolve())
api_port = session.rest_manager.get_api_port()
url = f"http://{config.get('api/http_host')}:{api_port}/ui/#/downloads/all?key={config.get('api/key')}"
Expand Down
14 changes: 14 additions & 0 deletions src/tribler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pathlib
import sys


def get_webui_root() -> pathlib.Path:
"""
Get the location of the "ui" directory.
When compiled through PyInstaller, the ui directory changes.
When running from source or when using cx_Freeze, we can use the ``__file__``.
"""
if hasattr(sys, '_MEIPASS'):
return pathlib.Path(sys._MEIPASS) / 'ui' # noqa: SLF001
return pathlib.Path(__file__).parent.absolute() / "ui"
4 changes: 2 additions & 2 deletions src/tribler/core/restapi/webui_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
import mimetypes
import pathlib

from aiohttp import ClientSession, web

import tribler
from tribler.core.restapi.rest_endpoint import RESTEndpoint, RESTResponse


Expand All @@ -22,7 +22,7 @@ def __init__(self) -> None:
self._logger = logging.getLogger(self.__class__.__name__)
self.app.add_routes([web.get('/{path:.*}', self.return_files)])

self.webui_root = (pathlib.Path(__file__).absolute() / "../../../ui/").resolve()
self.webui_root = tribler.get_webui_root()
self.has_dist = (self.webui_root / 'dist').exists()
self.session = ClientSession() if not self.has_dist else None

Expand Down

0 comments on commit 4f6aaf6

Please sign in to comment.