feat(lstmobile): intial scanner setup kinda working
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 2m7s
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 2m7s
This commit is contained in:
36
lstMobile/src/lib/storage.ts
Normal file
36
lstMobile/src/lib/storage.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
|
||||
export type AppConfig = {
|
||||
serverUrl: string;
|
||||
scannerId: string;
|
||||
};
|
||||
|
||||
const CONFIG_KEY = "scanner_app_config";
|
||||
|
||||
export async function saveConfig(config: AppConfig) {
|
||||
|
||||
await AsyncStorage.setItem(CONFIG_KEY, JSON.stringify(config));
|
||||
}
|
||||
|
||||
export async function getConfig(): Promise<AppConfig | null> {
|
||||
const raw = await AsyncStorage.getItem(CONFIG_KEY);
|
||||
|
||||
if (!raw) return null;
|
||||
|
||||
try {
|
||||
return JSON.parse(raw) as AppConfig;
|
||||
} catch (error) {
|
||||
console.log("Error", error)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function hasValidConfig(config: AppConfig | null) {
|
||||
if (!config) return false;
|
||||
|
||||
return Boolean(
|
||||
config.serverUrl?.trim() &&
|
||||
config.scannerId?.trim()
|
||||
);
|
||||
}
|
||||
43
lstMobile/src/lib/versionValidation.ts
Normal file
43
lstMobile/src/lib/versionValidation.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
export type ServerVersionInfo = {
|
||||
packageName: string;
|
||||
versionName: string;
|
||||
versionCode: number;
|
||||
minSupportedVersionCode: number;
|
||||
fileName: string;
|
||||
};
|
||||
|
||||
export type StartupStatus =
|
||||
| { state: "checking" }
|
||||
| { state: "needs-config" }
|
||||
| { state: "offline" }
|
||||
| { state: "blocked"; reason: string; server: ServerVersionInfo }
|
||||
| { state: "warning"; message: string; server: ServerVersionInfo }
|
||||
| { state: "ready"; server: ServerVersionInfo | null };
|
||||
|
||||
export function evaluateVersion(
|
||||
appBuildCode: number,
|
||||
server: ServerVersionInfo
|
||||
): StartupStatus {
|
||||
if (appBuildCode < server.minSupportedVersionCode) {
|
||||
return {
|
||||
state: "blocked",
|
||||
reason: "This scanner app is too old and must be updated before use.",
|
||||
server,
|
||||
};
|
||||
}
|
||||
|
||||
if (appBuildCode !== server.versionCode) {
|
||||
return {
|
||||
state: "warning",
|
||||
message: `A newer version is available. Installed build: ${appBuildCode}, latest build: ${server.versionCode}.`,
|
||||
server,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
state: "ready",
|
||||
server,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user