From 032deba775a235c12dbaeb889ed6cf157698b563 Mon Sep 17 00:00:00 2001 From: Sam Freund Date: Tue, 24 Mar 2026 17:49:56 -0500 Subject: [PATCH] refactor dark mode checks (#2407) The current method for checking light vs. dark mode is to compare the name of the theme against a hardcoded string. This PR uses a dark mode boolean. This change is for verbosity and so that we're not reliant on theme name. Additionally, we change some references to colors to the global theme, instead of indexing the list of themes. --- .../components/app/photon-3d-visualizer.vue | 12 ++++----- .../app/photon-calibration-visualizer.vue | 8 +++--- .../src/components/app/photon-sidebar.vue | 2 +- .../cameras/CameraCalibrationCard.vue | 12 ++++----- .../cameras/CameraCalibrationInfoCard.vue | 6 ++--- .../components/cameras/CameraControlCard.vue | 6 ++--- .../components/cameras/CameraSettingsCard.vue | 4 +-- .../src/components/cameras/CamerasView.vue | 4 +-- .../src/components/common/pv-delete-modal.vue | 4 +-- .../dashboard/CameraAndPipelineSelectCard.vue | 8 +++--- .../components/dashboard/ConfigOptions.vue | 2 +- .../components/dashboard/StreamConfigCard.vue | 8 +++--- .../components/dashboard/tabs/OutputTab.vue | 10 ++++---- .../components/dashboard/tabs/TargetsTab.vue | 2 +- .../dashboard/tabs/ThresholdTab.vue | 8 +++--- .../src/components/settings/DeviceCard.vue | 20 +++++++-------- .../settings/GlobalSettingsCard.vue | 14 +++++------ .../src/components/settings/MetricsChart.vue | 25 ++++++++----------- .../settings/ObjectDetectionCard.vue | 24 +++++++++--------- photon-client/src/lib/ThemeManager.ts | 12 ++++----- .../src/views/CameraMatchingView.vue | 18 ++++++------- photon-client/src/views/DashboardView.vue | 8 +++--- 22 files changed, 107 insertions(+), 110 deletions(-) diff --git a/photon-client/src/components/app/photon-3d-visualizer.vue b/photon-client/src/components/app/photon-3d-visualizer.vue index 10cce9366..9f457ded7 100644 --- a/photon-client/src/components/app/photon-3d-visualizer.vue +++ b/photon-client/src/components/app/photon-3d-visualizer.vue @@ -50,8 +50,8 @@ const drawTargets = async (targets: PhotonTarget[]) => { return; } - if (theme.global.name.value === "LightTheme") scene.background = new Color(0xa9a9a9); - else scene.background = new Color(0x000000); + if (theme.global.current.value.dark) scene.background = new Color(0x000000); + else scene.background = new Color(0xa9a9a9); scene.remove(...previousTargets); previousTargets = []; @@ -158,8 +158,8 @@ onMounted(async () => { if (!canvas) return; renderer = new WebGLRenderer({ canvas: canvas }); - if (theme.global.name.value === "LightTheme") scene.background = new Color(0xa9a9a9); - else scene.background = new Color(0x000000); + if (theme.global.current.value.dark) scene.background = new Color(0x000000); + else scene.background = new Color(0xa9a9a9); onWindowResize(); window.addEventListener("resize", onWindowResize); @@ -234,7 +234,7 @@ watchEffect(() => { First Person @@ -244,7 +244,7 @@ watchEffect(() => { Third Person diff --git a/photon-client/src/components/app/photon-calibration-visualizer.vue b/photon-client/src/components/app/photon-calibration-visualizer.vue index 4dad72020..31910269c 100644 --- a/photon-client/src/components/app/photon-calibration-visualizer.vue +++ b/photon-client/src/components/app/photon-calibration-visualizer.vue @@ -208,8 +208,8 @@ onMounted(async () => { const ambientLight = new AmbientLight(0xffffff, 0.6); scene.add(ambientLight); - if (theme.global.name.value === "LightTheme") scene.background = new Color(0xa9a9a9); - else scene.background = new Color(0x000000); + if (theme.global.current.value.dark) scene.background = new Color(0x000000); + else scene.background = new Color(0xa9a9a9); // Initialize a stable aspect ratio so subsequent resize events derive // height from width, avoiding layout feedback during continuous resizing @@ -347,7 +347,7 @@ watch( First Person @@ -357,7 +357,7 @@ watch( Third Person diff --git a/photon-client/src/components/app/photon-sidebar.vue b/photon-client/src/components/app/photon-sidebar.vue index 86c4fa62d..deb43d6b0 100644 --- a/photon-client/src/components/app/photon-sidebar.vue +++ b/photon-client/src/components/app/photon-sidebar.vue @@ -73,7 +73,7 @@ const renderCompact = computed(() => compact.value || !mdAndUp.value); Theme diff --git a/photon-client/src/components/cameras/CameraCalibrationCard.vue b/photon-client/src/components/cameras/CameraCalibrationCard.vue index 423eb3ca1..97e3c138b 100644 --- a/photon-client/src/components/cameras/CameraCalibrationCard.vue +++ b/photon-client/src/components/cameras/CameraCalibrationCard.vue @@ -470,7 +470,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => { closable density="compact" class="mb-5" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'tonal'" + :variant="theme.global.current.value.dark ? 'tonal' : 'elevated'" :color="useSettingsStore().general.mrCalWorking ? 'buttonPassive' : 'error'" :icon="useSettingsStore().general.mrCalWorking ? 'mdi-check' : 'mdi-close'" :text=" @@ -481,7 +481,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => { />
@@ -494,7 +494,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => { color="buttonPassive" size="small" block - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'" + :variant="theme.global.current.value.dark ? 'outlined' : 'elevated'" :disabled="!settingsValid" @click="downloadCalibBoard" > @@ -509,7 +509,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => { density="compact" text="Too many corners. Finish calibration now!" icon="mdi-alert-circle-outline" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'tonal'" + :variant="theme.global.current.value.dark ? 'tonal' : 'elevated'" />
@@ -517,7 +517,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => { size="small" block color="buttonActive" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'" + :variant="theme.global.current.value.dark ? 'outlined' : 'elevated'" :disabled="!settingsValid || tooManyPoints" @click="isCalibrating ? useCameraSettingsStore().takeCalibrationSnapshot() : startCalibration()" > @@ -531,7 +531,7 @@ const setSelectedVideoFormat = (format: VideoFormat) => { mdi-import @@ -140,7 +140,7 @@ const viewingImg = ref(0); color="buttonPassive" :disabled="!currentCalibrationCoeffs" style="width: 100%" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'" + :variant="theme.global.current.value.dark ? 'outlined' : 'elevated'" @click="openExportCalibrationPrompt" > mdi-export @@ -318,7 +318,7 @@ const viewingImg = ref(0); color="primary" text="The selected video format has not been calibrated." icon="mdi-alert-circle-outline" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'tonal'" + :variant="theme.global.current.value.dark ? 'tonal' : 'elevated'" />
diff --git a/photon-client/src/components/cameras/CameraControlCard.vue b/photon-client/src/components/cameras/CameraControlCard.vue index 98b4fb351..7498c7af3 100644 --- a/photon-client/src/components/cameras/CameraControlCard.vue +++ b/photon-client/src/components/cameras/CameraControlCard.vue @@ -99,7 +99,7 @@ const expanded = ref([]); mdi-folder @@ -115,7 +115,7 @@ const expanded = ref([]); density="compact" text="There are currently no saved snapshots." icon="mdi-information-outline" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'tonal'" + :variant="theme.global.current.value.dark ? 'tonal' : 'elevated'" /> @@ -125,7 +125,7 @@ const expanded = ref([]); density="compact" text="Snapshot timestamps depend on when the coprocessor was last connected to the internet." icon="mdi-information-outline" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'tonal'" + :variant="theme.global.current.value.dark ? 'tonal' : 'elevated'" /> (() => size="small" color="buttonActive" :disabled="!settingsHaveChanged()" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'" + :variant="theme.global.current.value.dark ? 'outlined' : 'elevated'" @click="saveCameraSettings" > mdi-content-save @@ -191,7 +191,7 @@ const wrappedCameras = computed(() => block size="small" color="error" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'" + :variant="theme.global.current.value.dark ? 'outlined' : 'elevated'" @click="() => (showDeleteCamera = true)" > mdi-trash-can-outline diff --git a/photon-client/src/components/cameras/CamerasView.vue b/photon-client/src/components/cameras/CamerasView.vue index 6510bae02..874e7aa5a 100644 --- a/photon-client/src/components/cameras/CamerasView.vue +++ b/photon-client/src/components/cameras/CamerasView.vue @@ -103,7 +103,7 @@ const fpsTooLow = computed(() => { mdi-export @@ -65,7 +65,7 @@ const confirmationText = ref(""); ? confirmationText.toLowerCase() !== expectedConfirmationText.toLowerCase() : false " - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'outlined'" + :variant="theme.global.current.value.dark ? 'outlined' : 'elevated'" @click=" onConfirm(); confirmationText = ''; diff --git a/photon-client/src/components/dashboard/CameraAndPipelineSelectCard.vue b/photon-client/src/components/dashboard/CameraAndPipelineSelectCard.vue index 84df7cd47..71bc543e2 100644 --- a/photon-client/src/components/dashboard/CameraAndPipelineSelectCard.vue +++ b/photon-client/src/components/dashboard/CameraAndPipelineSelectCard.vue @@ -407,14 +407,14 @@ const wrappedCameras = computed(() => Cancel @@ -441,7 +441,7 @@ const wrappedCameras = computed(() => @@ -449,7 +449,7 @@ const wrappedCameras = computed(() => Confirm diff --git a/photon-client/src/components/dashboard/ConfigOptions.vue b/photon-client/src/components/dashboard/ConfigOptions.vue index 7350bd14d..1ef988784 100644 --- a/photon-client/src/components/dashboard/ConfigOptions.vue +++ b/photon-client/src/components/dashboard/ConfigOptions.vue @@ -122,7 +122,7 @@ const onBeforeTabUpdate = () => { density="compact" text="Camera is not connected. Please check your connection and try again." icon="mdi-alert-circle-outline" - :variant="theme.global.name.value === 'LightTheme' ? 'elevated' : 'tonal'" + :variant="theme.global.current.value.dark ? 'tonal' : 'elevated'" />