From 306566854c0bd64306be907920919614d3e3dffa Mon Sep 17 00:00:00 2001 From: Ningyuan Li Date: Wed, 20 Sep 2023 23:09:26 +0900 Subject: [PATCH 1/2] added some missing environment variables --- src/main.c | 8 ++++++++ third_party/commons | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 15815efdc..8b071cb0b 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,14 @@ static int settings_load(app_settings_t *settings); int main(int argc, char *argv[]) { +#if TARGET_WEBOS + if (getenv("EGL_PLATFORM") == NULL) { + setenv("EGL_PLATFORM", "wayland", 0); + } + if (getenv("XDG_RUNTIME_DIR") == NULL) { + setenv("XDG_RUNTIME_DIR", "/tmp/xdg", 0); + } +#endif app_t app; int ret = app_init(&app, settings_load, argc, argv); if (ret != 0) { diff --git a/third_party/commons b/third_party/commons index e3a5edfa2..241c78c0b 160000 --- a/third_party/commons +++ b/third_party/commons @@ -1 +1 @@ -Subproject commit e3a5edfa254fe1718817ef1c0b67319a795b2f90 +Subproject commit 241c78c0bf74962da0f7aa5256821843773ee564 From 2f25c07854be5633aef1df9448a4fc181999bab2 Mon Sep 17 00:00:00 2001 From: Ningyuan Li Date: Thu, 21 Sep 2023 13:49:30 +0900 Subject: [PATCH 2/2] update sdl use /tmp if cache dir is not writable --- CMakeLists.txt | 2 +- src/app/platform/webos/path_webos.c | 6 +++++- src/app/ui/launcher/coverloader.c | 22 +++++++++++++++------- src/app/util/path.c | 8 +++++--- src/app/util/path.h | 2 +- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0d33c3db..cdd3cad96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ set(BUILD_SHARED_CORE_LIBS OFF) if (TARGET_WEBOS) set(CMAKE_INSTALL_LIBDIR lib/backports) - set(SDL2_BACKPORT_REVISION "2876d3b86c2e3c5700003dfbf3a978be17cea078") + set(SDL2_BACKPORT_REVISION "24f705048c85a67100659816bc5c418fc3a284bc") include(ExternalSDL2BackportForWebOS) unset(CMAKE_INSTALL_LIBDIR) else () diff --git a/src/app/platform/webos/path_webos.c b/src/app/platform/webos/path_webos.c index fdc370e16..30d2cc62e 100644 --- a/src/app/platform/webos/path_webos.c +++ b/src/app/platform/webos/path_webos.c @@ -17,6 +17,10 @@ char *path_pref() { char *path_cache() { const char *basedir = SDL_getenv("HOME"); char *cachedir = path_join(basedir, "cache"); - path_dir_ensure(cachedir); + if (path_dir_ensure(cachedir) == -1) { + free(cachedir); + cachedir = strdup("/tmp/moonlight-tv-cache"); + path_dir_ensure(cachedir); + } return cachedir; } \ No newline at end of file diff --git a/src/app/ui/launcher/coverloader.c b/src/app/ui/launcher/coverloader.c index 4800967b2..8bdfd88ca 100644 --- a/src/app/ui/launcher/coverloader.c +++ b/src/app/ui/launcher/coverloader.c @@ -63,7 +63,7 @@ typedef struct img_loader_req_t { #define DEBUG 0 #endif -static char *coverloader_cache_dir(); +static const char *coverloader_cache_dir(coverloader_t *loader); static GS_CLIENT coverloader_gs_client(coverloader_t *loader); @@ -136,6 +136,7 @@ struct coverloader_t { img_loader_t *base_loader; lv_lru_t *mem_cache; lazy_t client; + lazy_t cache_dir; coverloader_req_t *reqlist; refcounter_t refcounter; }; @@ -151,6 +152,7 @@ coverloader_t *coverloader_new(app_t *app) { loader->mem_cache = lv_lru_create(1024 * 1024 * 32, 720 * 1024, (lv_lru_free_t *) memcache_item_free, NULL); loader->base_loader = img_loader_create(&coverloader_impl, app->backend.executor); lazy_init(&loader->client, (lazy_supplier) app_gs_client_new, app); + lazy_init(&loader->cache_dir, (lazy_supplier) path_cache, NULL); loader->reqlist = NULL; return loader; } @@ -163,6 +165,10 @@ void coverloader_unref(coverloader_t *loader) { if (client != NULL) { gs_destroy(client); } + char *cache_dir = lazy_deinit(&loader->cache_dir); + if (cache_dir != NULL) { + free(cache_dir); + } img_loader_destroy(loader->base_loader); lv_lru_del(loader->mem_cache); refcounter_destroy(&loader->refcounter); @@ -193,8 +199,8 @@ void coverloader_display(coverloader_t *loader, const uuidstr_t *uuid, int id, l req->task = task; } -static char *coverloader_cache_dir() { - return path_cache(); +static const char *coverloader_cache_dir(coverloader_t *loader) { + return lazy_obtain(&loader->cache_dir); } static GS_CLIENT coverloader_gs_client(coverloader_t *loader) { @@ -202,11 +208,10 @@ static GS_CLIENT coverloader_gs_client(coverloader_t *loader) { } static void coverloader_cache_item_path(char path[4096], const coverloader_req_t *req) { - char *cachedir = coverloader_cache_dir(); + const char *cachedir = coverloader_cache_dir(req->loader); char basename[128]; SDL_snprintf(basename, 128, "%s_%d", (char *) &req->server_id, req->id); path_join_to(path, 4096, cachedir, basename); - free(cachedir); } static bool coverloader_memcache_get(coverloader_req_t *req) { @@ -289,13 +294,16 @@ static bool coverloader_filecache_get(coverloader_req_t *req) { char path[4096]; coverloader_cache_item_path(path, req); SDL_Surface *decoded = IMG_Load(path); - if (!decoded) { return false; } + if (!decoded) { + commons_log_warn("CoverLoader", "Failed to load cover from %s: %s", path, IMG_GetError()); + return false; + } if (cover_is_placeholder(decoded)) { SDL_FreeSurface(decoded); return false; } if (decoded->format->palette != NULL) { - SDL_Surface* true_color = SDL_ConvertSurfaceFormat(decoded, SDL_PIXELFORMAT_RGB24, 0); + SDL_Surface *true_color = SDL_ConvertSurfaceFormat(decoded, SDL_PIXELFORMAT_RGB24, 0); SDL_FreeSurface(decoded); if (true_color == NULL) { return false; diff --git a/src/app/util/path.c b/src/app/util/path.c index 5830aab3b..18f5bc75f 100644 --- a/src/app/util/path.c +++ b/src/app/util/path.c @@ -27,10 +27,12 @@ void path_join_to(char *dest, size_t maxlen, const char *parent, const char *bas snprintf(dest, maxlen, "%.*s%c%s", parentlen, parent, PATH_SEPARATOR, basename); } -void path_dir_ensure(const char *dir) { - if (access(dir, F_OK) == -1) { +int path_dir_ensure(const char *dir) { + if (access(dir, F_OK | W_OK) == -1) { if (errno == ENOENT) { - MKDIR(dir, 0755); + return MKDIR(dir, 0755); } + return -1; } + return 0; } \ No newline at end of file diff --git a/src/app/util/path.h b/src/app/util/path.h index 30ebd0f29..4e4303cc2 100644 --- a/src/app/util/path.h +++ b/src/app/util/path.h @@ -18,4 +18,4 @@ char *path_pref(); char *path_cache(); -void path_dir_ensure(const char *dir); \ No newline at end of file +int path_dir_ensure(const char *dir); \ No newline at end of file