mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Only allow Tauri imports in the desktop app (#5995)
# Description of Changes Adds an eslint rule to disallow importing any Tauri APIs outside the desktop folder to help hint to developers that they should be following the frontend architecture. While doing this, I also discovered that you can provide a custom message in the `no-restricted-imports` rule, which is nicer than the comments that I'd previously added to the eslint config file to explain why they weren't allowed: ```text /Users/jamesbrunton/Dev/spdf1/frontend/src/core/components/shared/config/configSections/GeneralSection.tsx 19:1 error 'src/core/contexts/PreferencesContext' import is restricted from being used by a pattern. Use @app/* imports instead of absolute src/ imports no-restricted-imports 20:1 error '../../../../../core/contexts/AppConfigContext' import is restricted from being used by a pattern. Use @app/* imports instead of relative imports no-restricted-imports 21:1 error '@tauri-apps/core' import is restricted from being used by a pattern. Tauri APIs are desktop-only. Review frontend/DeveloperGuide.md for structure advice no-restricted-imports ```
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { getVersion } from "@tauri-apps/api/app";
|
||||
import type { FrontendVersionInfo } from "@core/hooks/useFrontendVersionInfo";
|
||||
|
||||
export function useFrontendVersionInfo(backendVersion: string | undefined): FrontendVersionInfo {
|
||||
const [appVersion, setAppVersion] = useState<string | null>(null);
|
||||
const [mismatchVersion, setMismatchVersion] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const fetchVersion = async () => {
|
||||
try {
|
||||
const version = await getVersion();
|
||||
if (!cancelled) {
|
||||
setAppVersion(version);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[useFrontendVersionInfo] Failed to fetch frontend version:", error);
|
||||
}
|
||||
};
|
||||
fetchVersion();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!appVersion || !backendVersion) {
|
||||
setMismatchVersion(false);
|
||||
return;
|
||||
}
|
||||
if (appVersion !== backendVersion) {
|
||||
console.warn("[useFrontendVersionInfo] Mismatch between frontend version and AppConfig version:", {
|
||||
backendVersion,
|
||||
frontendVersion: appVersion,
|
||||
});
|
||||
setMismatchVersion(true);
|
||||
} else {
|
||||
setMismatchVersion(false);
|
||||
}
|
||||
}, [appVersion, backendVersion]);
|
||||
|
||||
return { appVersion, mismatchVersion };
|
||||
}
|
||||
Reference in New Issue
Block a user