refactor(scanner): more basic work to get the scanner just running
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 2m33s
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 2m33s
This commit is contained in:
1
lstMobile/src/lib/delay.ts
Normal file
1
lstMobile/src/lib/delay.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
7
lstMobile/src/lib/devMode.ts
Normal file
7
lstMobile/src/lib/devMode.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { delay } from "./delay";
|
||||
|
||||
export const devDelay = async (ms: number) => {
|
||||
if (__DEV__) {
|
||||
await delay(ms);
|
||||
}
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
|
||||
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()
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user