From 3841ce669bdd60e6565adad4a8fbe15bc22e5498 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 29 Dec 2024 10:06:07 -0500 Subject: [PATCH] pass slim iamge as env var --- .github/workflows/build.yml | 4 + backend/config/__init__.py | 1 + backend/endpoints/heartbeat.py | 14 ++- backend/endpoints/responses/heartbeat.py | 17 +++- docker/Dockerfile | 5 +- frontend/src/__generated__/index.ts | 2 + .../__generated__/models/FilesystemDict.ts | 9 ++ .../__generated__/models/HeartbeatResponse.ts | 8 +- .../models/MetadataSourcesDict.ts | 1 + .../src/__generated__/models/SytemDict.ts | 11 +++ frontend/src/components/Settings/Footer.vue | 2 +- .../Dialog/CreatePlatformBinding.vue | 2 +- .../Dialog/CreatePlatformVersion.vue | 2 +- .../src/components/common/Game/AdminMenu.vue | 4 +- .../components/common/NewVersionDialog.vue | 3 +- frontend/src/layouts/Auth.vue | 2 +- frontend/src/plugins/router.ts | 7 +- .../src/views/Player/EmulatorJS/Player.vue | 85 ++++++++++--------- frontend/src/views/Player/RuffleRS/Base.vue | 11 ++- 19 files changed, 124 insertions(+), 66 deletions(-) create mode 100644 frontend/src/__generated__/models/FilesystemDict.ts create mode 100644 frontend/src/__generated__/models/SytemDict.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a9acaeab1..8154351a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,6 +85,9 @@ jobs: platforms: linux/arm64,linux/amd64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + RUN_EMULATOR_SETUP=true + SLIM_IMAGE=false - name: Build slim image id: build-slim @@ -98,3 +101,4 @@ jobs: labels: ${{ steps.meta-slim.outputs.labels }} build-args: | RUN_EMULATOR_SETUP=false + SLIM_IMAGE=true diff --git a/backend/config/__init__.py b/backend/config/__init__.py index 7a5860b2d..646d097b4 100644 --- a/backend/config/__init__.py +++ b/backend/config/__init__.py @@ -108,6 +108,7 @@ SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON: Final = os.environ.get( ) # EMULATION +SLIM_IMAGE = str_to_bool(os.environ.get("SLIM_IMAGE", "true")) DISABLE_EMULATOR_JS = str_to_bool(os.environ.get("DISABLE_EMULATOR_JS", "false")) DISABLE_RUFFLE_RS = str_to_bool(os.environ.get("DISABLE_RUFFLE_RS", "false")) diff --git a/backend/endpoints/heartbeat.py b/backend/endpoints/heartbeat.py index 845ec11df..b66fdb031 100644 --- a/backend/endpoints/heartbeat.py +++ b/backend/endpoints/heartbeat.py @@ -9,6 +9,7 @@ from config import ( RESCAN_ON_FILESYSTEM_CHANGE_DELAY, SCHEDULED_RESCAN_CRON, SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON, + SLIM_IMAGE, UPLOAD_TIMEOUT, ) from endpoints.responses.heartbeat import HeartbeatResponse @@ -32,15 +33,20 @@ def heartbeat() -> HeartbeatResponse: """ return { - "VERSION": get_version(), - "SHOW_SETUP_WIZARD": len(db_user_handler.get_admin_users()) == 0, - "ANY_SOURCE_ENABLED": IGDB_API_ENABLED or MOBY_API_ENABLED, + "SYSTEM": { + "VERSION": get_version(), + "SHOW_SETUP_WIZARD": len(db_user_handler.get_admin_users()) == 0, + "SLIM_IMAGE": SLIM_IMAGE, + }, "METADATA_SOURCES": { + "ANY_SOURCE_ENABLED": IGDB_API_ENABLED or MOBY_API_ENABLED, "IGDB_API_ENABLED": IGDB_API_ENABLED, "MOBY_API_ENABLED": MOBY_API_ENABLED, "STEAMGRIDDB_ENABLED": STEAMGRIDDB_API_ENABLED, }, - "FS_PLATFORMS": fs_platform_handler.get_platforms(), + "FILESYSTEM": { + "FS_PLATFORMS": fs_platform_handler.get_platforms(), + }, "WATCHER": { "ENABLED": ENABLE_RESCAN_ON_FILESYSTEM_CHANGE, "TITLE": "Rescan on filesystem change", diff --git a/backend/endpoints/responses/heartbeat.py b/backend/endpoints/responses/heartbeat.py index 7f7d83946..c6475a3b9 100644 --- a/backend/endpoints/responses/heartbeat.py +++ b/backend/endpoints/responses/heartbeat.py @@ -1,6 +1,12 @@ from typing import TypedDict +class SytemDict(TypedDict): + VERSION: str + SHOW_SETUP_WIZARD: bool + SLIM_IMAGE: bool + + class WatcherDict(TypedDict): ENABLED: bool TITLE: str @@ -17,11 +23,16 @@ class SchedulerDict(TypedDict): class MetadataSourcesDict(TypedDict): + ANY_SOURCE_ENABLED: bool IGDB_API_ENABLED: bool MOBY_API_ENABLED: bool STEAMGRIDDB_ENABLED: bool +class FilesystemDict(TypedDict): + FS_PLATFORMS: list[str] + + class EmulationDict(TypedDict): DISABLE_EMULATOR_JS: bool DISABLE_RUFFLE_RS: bool @@ -37,13 +48,11 @@ class OIDCDict(TypedDict): class HeartbeatResponse(TypedDict): - VERSION: str - SHOW_SETUP_WIZARD: bool + SYSTEM: SytemDict WATCHER: WatcherDict SCHEDULER: SchedulerDict - ANY_SOURCE_ENABLED: bool METADATA_SOURCES: MetadataSourcesDict - FS_PLATFORMS: list + FILESYSTEM: FilesystemDict EMULATION: EmulationDict FRONTEND: FrontendDict OIDC: OIDCDict diff --git a/docker/Dockerfile b/docker/Dockerfile index b301f79a3..b4e6ae8ad 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -170,7 +170,10 @@ COPY --from=production-stage / / COPY --from=backend-build /src/.venv /src/.venv # Fix virtualenv link to python binary RUN ln -sf "$(which python)" /src/.venv/bin/python -ENV PATH="/src/.venv/bin:${PATH}" + +ARG SLIM_IMAGE=false +ENV PATH="/src/.venv/bin:${PATH}" \ + SLIM_IMAGE="${SLIM_IMAGE}" # Declare the supported volumes VOLUME ["/romm/resources", "/romm/library", "/romm/assets", "/romm/config", "/redis-data"] diff --git a/frontend/src/__generated__/index.ts b/frontend/src/__generated__/index.ts index 93cef8064..108f6234d 100644 --- a/frontend/src/__generated__/index.ts +++ b/frontend/src/__generated__/index.ts @@ -17,6 +17,7 @@ export type { CollectionSchema } from './models/CollectionSchema'; export type { ConfigResponse } from './models/ConfigResponse'; export type { DetailedRomSchema } from './models/DetailedRomSchema'; export type { EmulationDict } from './models/EmulationDict'; +export type { FilesystemDict } from './models/FilesystemDict'; export type { FirmwareSchema } from './models/FirmwareSchema'; export type { FrontendDict } from './models/FrontendDict'; export type { HeartbeatResponse } from './models/HeartbeatResponse'; @@ -44,6 +45,7 @@ export type { SearchRomSchema } from './models/SearchRomSchema'; export type { SimpleRomSchema } from './models/SimpleRomSchema'; export type { StateSchema } from './models/StateSchema'; export type { StatsReturn } from './models/StatsReturn'; +export type { SytemDict } from './models/SytemDict'; export type { TaskDict } from './models/TaskDict'; export type { TinfoilFeedFileSchema } from './models/TinfoilFeedFileSchema'; export type { TinfoilFeedSchema } from './models/TinfoilFeedSchema'; diff --git a/frontend/src/__generated__/models/FilesystemDict.ts b/frontend/src/__generated__/models/FilesystemDict.ts new file mode 100644 index 000000000..937053614 --- /dev/null +++ b/frontend/src/__generated__/models/FilesystemDict.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type FilesystemDict = { + FS_PLATFORMS: Array; +}; + diff --git a/frontend/src/__generated__/models/HeartbeatResponse.ts b/frontend/src/__generated__/models/HeartbeatResponse.ts index 5a0379fd6..97d0704f6 100644 --- a/frontend/src/__generated__/models/HeartbeatResponse.ts +++ b/frontend/src/__generated__/models/HeartbeatResponse.ts @@ -4,20 +4,20 @@ /* eslint-disable */ import type { EmulationDict } from './EmulationDict'; +import type { FilesystemDict } from './FilesystemDict'; import type { FrontendDict } from './FrontendDict'; import type { MetadataSourcesDict } from './MetadataSourcesDict'; import type { OIDCDict } from './OIDCDict'; import type { SchedulerDict } from './SchedulerDict'; +import type { SytemDict } from './SytemDict'; import type { WatcherDict } from './WatcherDict'; export type HeartbeatResponse = { - VERSION: string; - SHOW_SETUP_WIZARD: boolean; + SYSTEM: SytemDict; WATCHER: WatcherDict; SCHEDULER: SchedulerDict; - ANY_SOURCE_ENABLED: boolean; METADATA_SOURCES: MetadataSourcesDict; - FS_PLATFORMS: Array; + FILESYSTEM: FilesystemDict; EMULATION: EmulationDict; FRONTEND: FrontendDict; OIDC: OIDCDict; diff --git a/frontend/src/__generated__/models/MetadataSourcesDict.ts b/frontend/src/__generated__/models/MetadataSourcesDict.ts index 69b957236..2888a84ed 100644 --- a/frontend/src/__generated__/models/MetadataSourcesDict.ts +++ b/frontend/src/__generated__/models/MetadataSourcesDict.ts @@ -4,6 +4,7 @@ /* eslint-disable */ export type MetadataSourcesDict = { + ANY_SOURCE_ENABLED: boolean; IGDB_API_ENABLED: boolean; MOBY_API_ENABLED: boolean; STEAMGRIDDB_ENABLED: boolean; diff --git a/frontend/src/__generated__/models/SytemDict.ts b/frontend/src/__generated__/models/SytemDict.ts new file mode 100644 index 000000000..bd3b6406a --- /dev/null +++ b/frontend/src/__generated__/models/SytemDict.ts @@ -0,0 +1,11 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type SytemDict = { + VERSION: string; + SHOW_SETUP_WIZARD: boolean; + SLIM_IMAGE: boolean; +}; + diff --git a/frontend/src/components/Settings/Footer.vue b/frontend/src/components/Settings/Footer.vue index 3c6cd54ce..5d7e339f9 100644 --- a/frontend/src/components/Settings/Footer.vue +++ b/frontend/src/components/Settings/Footer.vue @@ -14,7 +14,7 @@ const heartbeatStore = storeHeartbeat(); > RomM - {{ heartbeatStore.value.VERSION }} + {{ heartbeatStore.value.SYSTEM.VERSION }} mdi-circle-smallmdi-github diff --git a/frontend/src/plugins/router.ts b/frontend/src/plugins/router.ts index a23fd922b..e2efedd78 100644 --- a/frontend/src/plugins/router.ts +++ b/frontend/src/plugins/router.ts @@ -126,9 +126,12 @@ router.beforeEach(async (to, _from, next) => { const auth = storeAuth(); const { user } = storeToRefs(auth); - if (heartbeat.value.SHOW_SETUP_WIZARD && to.name?.toString() !== "setup") { + if ( + heartbeat.value.SYSTEM.SHOW_SETUP_WIZARD && + to.name?.toString() !== "setup" + ) { next({ name: "setup" }); - } else if (!heartbeat.value.SHOW_SETUP_WIZARD) { + } else if (!heartbeat.value.SYSTEM.SHOW_SETUP_WIZARD) { if ( (to.name?.toString() === "login" || to.name?.toString() === "setup") && user.value diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index 20b9af27b..eec6c696b 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -3,6 +3,7 @@ import type { FirmwareSchema, SaveSchema, StateSchema } from "@/__generated__"; import saveApi, { saveApi as api } from "@/services/api/save"; import screenshotApi from "@/services/api/screenshot"; import stateApi from "@/services/api/state"; +import storeHeartbeat from "@/stores/heartbeat"; import type { DetailedRom } from "@/stores/roms"; import { getSupportedEJSCores } from "@/utils"; import { onBeforeUnmount, onMounted, ref } from "vue"; @@ -14,49 +15,11 @@ const props = defineProps<{ bios: FirmwareSchema | null; core: string | null; }>(); +const heartbeat = storeHeartbeat(); const romRef = ref(props.rom); const saveRef = ref(props.save); const stateRef = ref(props.state); -onBeforeUnmount(() => { - window.location.reload(); -}); - -onMounted(() => { - if (props.save) { - localStorage.setItem( - `player:${props.rom.id}:save_id`, - props.save.id.toString(), - ); - } else { - localStorage.removeItem(`player:${props.rom.id}:save_id`); - } - - if (props.state) { - localStorage.setItem( - `player:${props.rom.id}:state_id`, - props.state.id.toString(), - ); - } else { - localStorage.removeItem(`player:${props.rom.id}:state_id`); - } - - if (props.bios) { - localStorage.setItem( - `player:${props.rom.platform_slug}:bios_id`, - props.bios.id.toString(), - ); - } else { - localStorage.removeItem(`player:${props.rom.platform_slug}:bios_id`); - } - - if (props.core) { - localStorage.setItem(`player:${props.rom.platform_slug}:core`, props.core); - } else { - localStorage.removeItem(`player:${props.rom.platform_slug}:core`); - } -}); - // Declare global variables for EmulatorJS declare global { interface Window { @@ -96,7 +59,6 @@ window.EJS_biosUrl = props.bios ? `/api/firmware/${props.bios.id}/content/${props.bios.file_name}` : ""; window.EJS_player = "#game"; -window.EJS_pathtodata = "/assets/emulatorjs/"; window.EJS_color = "#A453FF"; window.EJS_alignStartButton = "center"; window.EJS_startOnLoaded = true; @@ -107,6 +69,49 @@ window.EJS_defaultOptions = { }; if (romRef.value.name) window.EJS_gameName = romRef.value.name; +onBeforeUnmount(() => { + window.location.reload(); +}); + +onMounted(() => { + window.EJS_pathtodata = heartbeat.value.SYSTEM.SLIM_IMAGE + ? "https://cdn.emulatorjs.org/4.2.0/data" + : "/assets/emulatorjs/"; + + if (props.save) { + localStorage.setItem( + `player:${props.rom.id}:save_id`, + props.save.id.toString(), + ); + } else { + localStorage.removeItem(`player:${props.rom.id}:save_id`); + } + + if (props.state) { + localStorage.setItem( + `player:${props.rom.id}:state_id`, + props.state.id.toString(), + ); + } else { + localStorage.removeItem(`player:${props.rom.id}:state_id`); + } + + if (props.bios) { + localStorage.setItem( + `player:${props.rom.platform_slug}:bios_id`, + props.bios.id.toString(), + ); + } else { + localStorage.removeItem(`player:${props.rom.platform_slug}:bios_id`); + } + + if (props.core) { + localStorage.setItem(`player:${props.rom.platform_slug}:core`, props.core); + } else { + localStorage.removeItem(`player:${props.rom.platform_slug}:core`); + } +}); + function buildStateName(): string { const states = romRef.value.user_states?.map((s) => s.file_name) ?? []; const romName = romRef.value.file_name_no_ext.trim(); diff --git a/frontend/src/views/Player/RuffleRS/Base.vue b/frontend/src/views/Player/RuffleRS/Base.vue index 4318cc456..1cc9dc279 100644 --- a/frontend/src/views/Player/RuffleRS/Base.vue +++ b/frontend/src/views/Player/RuffleRS/Base.vue @@ -1,6 +1,7 @@