fix: track frontend composables

This commit is contained in:
2026-04-24 20:10:00 +08:00
parent 6a96835e95
commit 39db8c012f
3 changed files with 66 additions and 0 deletions
+4
View File
@@ -25,3 +25,7 @@ src/LiveRecorder.WebApi/live-recorder.db*
*.m4s
*.m3u8
*.zip
# Frontend source/config TypeScript files must stay trackable.
!frontend/**/*.ts
!frontend/**/*.tsx
@@ -0,0 +1,35 @@
import { computed, reactive } from "vue";
const backendStatusState = reactive({
unavailable: false,
message: "",
lastChangedAt: ""
});
function setLastChangedNow() {
backendStatusState.lastChangedAt = new Date().toLocaleTimeString();
}
export function markBackendUnavailable(message: string) {
backendStatusState.unavailable = true;
backendStatusState.message = message;
setLastChangedNow();
}
export function markBackendAvailable() {
if (!backendStatusState.unavailable && !backendStatusState.message) {
return;
}
backendStatusState.unavailable = false;
backendStatusState.message = "";
setLastChangedNow();
}
export function useBackendStatus() {
return {
backendUnavailable: computed(() => backendStatusState.unavailable),
backendMessage: computed(() => backendStatusState.message),
backendLastChangedAt: computed(() => backendStatusState.lastChangedAt)
};
}
+27
View File
@@ -0,0 +1,27 @@
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
const MOBILE_BREAKPOINT = 768;
export function useViewport() {
const width = ref(typeof window === "undefined" ? 1280 : window.innerWidth);
function syncViewport() {
width.value = window.innerWidth;
}
onMounted(() => {
syncViewport();
window.addEventListener("resize", syncViewport, { passive: true });
});
onBeforeUnmount(() => {
window.removeEventListener("resize", syncViewport);
});
const isMobile = computed(() => width.value <= MOBILE_BREAKPOINT);
return {
width,
isMobile
};
}