359 lines
14 KiB
JavaScript
359 lines
14 KiB
JavaScript
/// <reference types="../node_modules/.vue-global-types/vue_3.5_0_0_0.d.ts" />
|
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
import { RouterLink, RouterView } from 'vue-router';
|
|
import AppHeader from '@/components/AppHeader.vue';
|
|
import AppDrawer from '@/components/AppDrawer.vue';
|
|
import { meteoApi } from '@/api/meteo';
|
|
import { settingsApi } from '@/api/settings';
|
|
import { applyUiSizesToRoot } from '@/utils/uiSizeDefaults';
|
|
const drawerOpen = ref(false);
|
|
const debugMode = ref(localStorage.getItem('debug_mode') === '1');
|
|
const debugStats = ref(null);
|
|
let debugTimer = null;
|
|
function prefetchMeteoInBackground() {
|
|
// Préchargement du chunk route + données pour accélérer l'ouverture de /meteo
|
|
void import('@/views/CalendrierView.vue');
|
|
void meteoApi.preloadForMeteoView();
|
|
}
|
|
function toBool(value) {
|
|
if (typeof value === 'boolean')
|
|
return value;
|
|
const s = String(value ?? '').toLowerCase().trim();
|
|
return s === '1' || s === 'true' || s === 'yes' || s === 'on';
|
|
}
|
|
function formatBytes(value) {
|
|
if (value == null || Number.isNaN(value))
|
|
return '—';
|
|
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
let n = value;
|
|
let i = 0;
|
|
while (n >= 1024 && i < units.length - 1) {
|
|
n /= 1024;
|
|
i += 1;
|
|
}
|
|
return `${n.toFixed(n >= 100 ? 0 : n >= 10 ? 1 : 2)}${units[i]}`;
|
|
}
|
|
const debugCpuLabel = computed(() => {
|
|
const pct = debugStats.value?.cpu?.used_pct;
|
|
return pct != null ? `${pct.toFixed(1)}%` : '—';
|
|
});
|
|
const debugMemLabel = computed(() => {
|
|
const used = debugStats.value?.memory?.used_bytes;
|
|
const pct = debugStats.value?.memory?.used_pct;
|
|
if (used == null)
|
|
return '—';
|
|
return pct != null ? `${formatBytes(used)} (${pct.toFixed(1)}%)` : formatBytes(used);
|
|
});
|
|
const debugDiskLabel = computed(() => {
|
|
const used = debugStats.value?.disk?.used_bytes;
|
|
const pct = debugStats.value?.disk?.used_pct;
|
|
if (used == null)
|
|
return '—';
|
|
return pct != null ? `${formatBytes(used)} (${pct.toFixed(1)}%)` : formatBytes(used);
|
|
});
|
|
async function fetchDebugStats() {
|
|
try {
|
|
debugStats.value = await settingsApi.getDebugSystemStats();
|
|
}
|
|
catch {
|
|
debugStats.value = null;
|
|
}
|
|
}
|
|
function stopDebugPolling() {
|
|
if (debugTimer != null) {
|
|
window.clearInterval(debugTimer);
|
|
debugTimer = null;
|
|
}
|
|
}
|
|
function startDebugPolling() {
|
|
stopDebugPolling();
|
|
void fetchDebugStats();
|
|
debugTimer = window.setInterval(() => {
|
|
void fetchDebugStats();
|
|
}, 10000);
|
|
}
|
|
function applyUiSizesFromSettings(data) {
|
|
applyUiSizesToRoot(data);
|
|
}
|
|
async function loadDebugModeFromApi() {
|
|
try {
|
|
const data = await settingsApi.get();
|
|
debugMode.value = toBool(data.debug_mode);
|
|
localStorage.setItem('debug_mode', debugMode.value ? '1' : '0');
|
|
applyUiSizesFromSettings(data);
|
|
}
|
|
catch {
|
|
// On garde la valeur locale.
|
|
}
|
|
}
|
|
function handleSettingsUpdated(event) {
|
|
const ce = event;
|
|
if (!ce.detail || ce.detail.debug_mode == null)
|
|
return;
|
|
debugMode.value = toBool(ce.detail.debug_mode);
|
|
localStorage.setItem('debug_mode', debugMode.value ? '1' : '0');
|
|
}
|
|
function handleStorage(event) {
|
|
if (event.key !== 'debug_mode')
|
|
return;
|
|
debugMode.value = event.newValue === '1';
|
|
}
|
|
onMounted(() => {
|
|
const ric = window.requestIdleCallback;
|
|
if (ric) {
|
|
ric(() => prefetchMeteoInBackground(), { timeout: 1500 });
|
|
}
|
|
else {
|
|
window.setTimeout(prefetchMeteoInBackground, 500);
|
|
}
|
|
void loadDebugModeFromApi();
|
|
window.addEventListener('settings-updated', handleSettingsUpdated);
|
|
window.addEventListener('storage', handleStorage);
|
|
});
|
|
watch(debugMode, (enabled) => {
|
|
if (enabled)
|
|
startDebugPolling();
|
|
else {
|
|
stopDebugPolling();
|
|
debugStats.value = null;
|
|
}
|
|
}, { immediate: true });
|
|
onBeforeUnmount(() => {
|
|
stopDebugPolling();
|
|
window.removeEventListener('settings-updated', handleSettingsUpdated);
|
|
window.removeEventListener('storage', handleStorage);
|
|
});
|
|
const links = [
|
|
{ to: '/', label: 'Dashboard', icon: '🏠' },
|
|
{ to: '/jardins', label: 'Jardins', icon: '🪴' },
|
|
{ to: '/plantes', label: 'Plantes', icon: '🌱' },
|
|
{ to: '/bibliotheque', label: 'Bibliothèque', icon: '📷' },
|
|
{ to: '/outils', label: 'Outils', icon: '🔧' },
|
|
{ to: '/plantations', label: 'Plantations', icon: '🥕' },
|
|
{ to: '/taches', label: 'Tâches', icon: '✅' },
|
|
{ to: '/planning', label: 'Planning', icon: '📆' },
|
|
{ to: '/meteo', label: 'Météo', icon: '🌦️' },
|
|
{ to: '/astuces', label: 'Astuces', icon: '💡' },
|
|
{ to: '/reglages', label: 'Réglages', icon: '⚙️' },
|
|
];
|
|
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
|
|
const __VLS_ctx = {};
|
|
let __VLS_components;
|
|
let __VLS_directives;
|
|
if (__VLS_ctx.debugMode) {
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
|
|
...{ class: "fixed top-2 right-2 z-[70] bg-bg-hard/95 border border-bg-soft rounded-lg px-3 py-1.5 text-[11px] text-text-muted shadow-lg" },
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({
|
|
...{ class: "text-aqua font-semibold mr-2" },
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({
|
|
...{ class: "mr-2" },
|
|
});
|
|
(__VLS_ctx.debugCpuLabel);
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({
|
|
...{ class: "mr-2" },
|
|
});
|
|
(__VLS_ctx.debugMemLabel);
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({});
|
|
(__VLS_ctx.debugDiskLabel);
|
|
}
|
|
/** @type {[typeof AppHeader, ]} */ ;
|
|
// @ts-ignore
|
|
const __VLS_0 = __VLS_asFunctionalComponent(AppHeader, new AppHeader({
|
|
...{ 'onToggleDrawer': {} },
|
|
...{ class: "lg:hidden" },
|
|
}));
|
|
const __VLS_1 = __VLS_0({
|
|
...{ 'onToggleDrawer': {} },
|
|
...{ class: "lg:hidden" },
|
|
}, ...__VLS_functionalComponentArgsRest(__VLS_0));
|
|
let __VLS_3;
|
|
let __VLS_4;
|
|
let __VLS_5;
|
|
const __VLS_6 = {
|
|
onToggleDrawer: (...[$event]) => {
|
|
__VLS_ctx.drawerOpen = !__VLS_ctx.drawerOpen;
|
|
}
|
|
};
|
|
var __VLS_2;
|
|
/** @type {[typeof AppDrawer, ]} */ ;
|
|
// @ts-ignore
|
|
const __VLS_7 = __VLS_asFunctionalComponent(AppDrawer, new AppDrawer({
|
|
...{ 'onClose': {} },
|
|
open: (__VLS_ctx.drawerOpen),
|
|
}));
|
|
const __VLS_8 = __VLS_7({
|
|
...{ 'onClose': {} },
|
|
open: (__VLS_ctx.drawerOpen),
|
|
}, ...__VLS_functionalComponentArgsRest(__VLS_7));
|
|
let __VLS_10;
|
|
let __VLS_11;
|
|
let __VLS_12;
|
|
const __VLS_13 = {
|
|
onClose: (...[$event]) => {
|
|
__VLS_ctx.drawerOpen = false;
|
|
}
|
|
};
|
|
var __VLS_9;
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
|
|
...{ class: "lg:flex" },
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.aside, __VLS_intrinsicElements.aside)({
|
|
...{ class: "hidden lg:flex lg:flex-col lg:fixed lg:inset-y-0 lg:w-60 bg-bg-hard border-r border-bg-soft z-30" },
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
|
|
...{ class: "px-5 pt-6 pb-4 border-b border-bg-soft" },
|
|
});
|
|
const __VLS_14 = {}.RouterLink;
|
|
/** @type {[typeof __VLS_components.RouterLink, typeof __VLS_components.RouterLink, ]} */ ;
|
|
// @ts-ignore
|
|
const __VLS_15 = __VLS_asFunctionalComponent(__VLS_14, new __VLS_14({
|
|
to: "/",
|
|
...{ class: "text-green font-bold text-xl tracking-wide flex items-center gap-2" },
|
|
}));
|
|
const __VLS_16 = __VLS_15({
|
|
to: "/",
|
|
...{ class: "text-green font-bold text-xl tracking-wide flex items-center gap-2" },
|
|
}, ...__VLS_functionalComponentArgsRest(__VLS_15));
|
|
__VLS_17.slots.default;
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({});
|
|
var __VLS_17;
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.nav, __VLS_intrinsicElements.nav)({
|
|
...{ class: "flex-1 py-4 px-3 flex flex-col gap-0.5 overflow-y-auto" },
|
|
});
|
|
for (const [l] of __VLS_getVForSourceType((__VLS_ctx.links))) {
|
|
const __VLS_18 = {}.RouterLink;
|
|
/** @type {[typeof __VLS_components.RouterLink, typeof __VLS_components.RouterLink, ]} */ ;
|
|
// @ts-ignore
|
|
const __VLS_19 = __VLS_asFunctionalComponent(__VLS_18, new __VLS_18({
|
|
key: (l.to),
|
|
to: (l.to),
|
|
...{ class: "flex items-center gap-3 text-text-muted hover:text-text py-2 px-3 rounded-lg text-sm transition-colors group" },
|
|
activeClass: "bg-bg-soft text-green font-medium",
|
|
}));
|
|
const __VLS_20 = __VLS_19({
|
|
key: (l.to),
|
|
to: (l.to),
|
|
...{ class: "flex items-center gap-3 text-text-muted hover:text-text py-2 px-3 rounded-lg text-sm transition-colors group" },
|
|
activeClass: "bg-bg-soft text-green font-medium",
|
|
}, ...__VLS_functionalComponentArgsRest(__VLS_19));
|
|
__VLS_21.slots.default;
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({
|
|
...{ style: (`font-size: var(--ui-menu-icon-size, 18px); line-height: 1`) },
|
|
});
|
|
(l.icon);
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({
|
|
...{ style: (`font-size: var(--ui-menu-font-size, 13px)`) },
|
|
});
|
|
(l.label);
|
|
var __VLS_21;
|
|
}
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
|
|
...{ class: "px-4 py-4 border-t border-bg-soft text-text-muted text-xs" },
|
|
});
|
|
__VLS_asFunctionalElement(__VLS_intrinsicElements.main, __VLS_intrinsicElements.main)({
|
|
...{ class: "pt-14 lg:pt-0 lg:pl-60 min-h-screen w-full bg-bg" },
|
|
...{ style: {} },
|
|
});
|
|
const __VLS_22 = {}.RouterView;
|
|
/** @type {[typeof __VLS_components.RouterView, ]} */ ;
|
|
// @ts-ignore
|
|
const __VLS_23 = __VLS_asFunctionalComponent(__VLS_22, new __VLS_22({}));
|
|
const __VLS_24 = __VLS_23({}, ...__VLS_functionalComponentArgsRest(__VLS_23));
|
|
/** @type {__VLS_StyleScopedClasses['fixed']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['top-2']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['right-2']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['z-[70]']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['bg-bg-hard/95']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border-bg-soft']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['rounded-lg']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['px-3']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['py-1.5']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-[11px]']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-text-muted']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['shadow-lg']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-aqua']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['font-semibold']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['mr-2']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['mr-2']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['mr-2']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:hidden']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:flex']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['hidden']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:flex']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:flex-col']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:fixed']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:inset-y-0']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:w-60']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['bg-bg-hard']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border-r']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border-bg-soft']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['z-30']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['px-5']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['pt-6']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['pb-4']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border-b']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border-bg-soft']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-green']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['font-bold']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-xl']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['tracking-wide']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['gap-2']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['flex-1']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['py-4']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['px-3']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['flex-col']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['gap-0.5']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['overflow-y-auto']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['gap-3']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-text-muted']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['hover:text-text']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['py-2']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['px-3']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['rounded-lg']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-sm']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['transition-colors']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['group']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['px-4']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['py-4']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border-t']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['border-bg-soft']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-text-muted']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['text-xs']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['pt-14']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:pt-0']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['lg:pl-60']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['min-h-screen']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['w-full']} */ ;
|
|
/** @type {__VLS_StyleScopedClasses['bg-bg']} */ ;
|
|
var __VLS_dollars;
|
|
const __VLS_self = (await import('vue')).defineComponent({
|
|
setup() {
|
|
return {
|
|
RouterLink: RouterLink,
|
|
RouterView: RouterView,
|
|
AppHeader: AppHeader,
|
|
AppDrawer: AppDrawer,
|
|
drawerOpen: drawerOpen,
|
|
debugMode: debugMode,
|
|
debugCpuLabel: debugCpuLabel,
|
|
debugMemLabel: debugMemLabel,
|
|
debugDiskLabel: debugDiskLabel,
|
|
links: links,
|
|
};
|
|
},
|
|
});
|
|
export default (await import('vue')).defineComponent({
|
|
setup() {
|
|
return {};
|
|
},
|
|
});
|
|
; /* PartiallyEnd: #4569/main.vue */
|