Compare commits
2 Commits
v0.0.2-alp
...
v0.0.2-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c253a90b6 | |||
| ba30281e59 |
@@ -1,5 +1,12 @@
|
||||
# All Changes to LST can be found below.
|
||||
|
||||
## [0.0.2-alpha.8](https://git.tuffraid.net/cowch/lst_v3/compare/v0.0.2-alpha.7...v0.0.2-alpha.8) (2026-05-06)
|
||||
|
||||
|
||||
### 🌟 Enhancements
|
||||
|
||||
* **mobile:** auth added in ([ba30281](https://git.tuffraid.net/cowch/lst_v3/commits/ba30281e59040513a036fb7413e372457d04a7c8))
|
||||
|
||||
## [0.0.2-alpha.7](https://git.tuffraid.net/cowch/lst_v3/compare/v0.0.2-alpha.6...v0.0.2-alpha.7) (2026-05-06)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
boolean,
|
||||
jsonb,
|
||||
pgEnum,
|
||||
pgTable,
|
||||
text,
|
||||
@@ -25,7 +26,7 @@ export const scanUser = pgTable(
|
||||
scannerId: text("scanner_id").unique().notNull(),
|
||||
pinNumber: text("pin_number").unique().notNull(),
|
||||
pinHash: text("pin_hash").notNull(),
|
||||
excludedCommand: text("excluded_commands").default(""),
|
||||
excludedCommand: jsonb("excluded_commands").default([]),
|
||||
role: mobileRoleEnum("role").notNull().default("user"),
|
||||
active: boolean("active").default(true),
|
||||
lastScan: timestamp("last_scan").defaultNow(),
|
||||
|
||||
@@ -4,6 +4,7 @@ import type z from "zod";
|
||||
|
||||
export const scanLog = pgTable("scan_log", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
user: text("user"),
|
||||
scannerId: text("scanner_id"),
|
||||
message: text("message").notNull(),
|
||||
prompt: text("prompt"),
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"foregroundImage": "./assets/adaptive-icon-white.png",
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"versionCode": 23,
|
||||
"versionCode": 24,
|
||||
"minSupportedVersionCode": 21,
|
||||
"predictiveBackGestureEnabled": false,
|
||||
"package": "net.alpla.lst.mobile"
|
||||
|
||||
BIN
lstMobile/assets/sounds/scan.wav
Normal file
BIN
lstMobile/assets/sounds/scan.wav
Normal file
Binary file not shown.
@@ -1,9 +1,32 @@
|
||||
import { Tabs } from "expo-router";
|
||||
import { Home, Settings } from "lucide-react-native";
|
||||
import { Redirect, Tabs } from "expo-router";
|
||||
import { Container, Home, Logs, Rows4, Settings } from "lucide-react-native";
|
||||
import { useAppStore } from "../../hooks/useAppStore";
|
||||
import { useMobileAuthStore } from "../../hooks/useMobileAuth";
|
||||
|
||||
// const roles = {
|
||||
// adminOnly: ["admin"],
|
||||
// management: ["admin", "manager"],
|
||||
// allStaff: ["admin", "manager", "driver", "lead", "user"],
|
||||
// };
|
||||
|
||||
export default function TabsLayout() {
|
||||
const serverPort = useAppStore((s) => s.serverPort);
|
||||
const user = useMobileAuthStore((s) => s.user);
|
||||
const isUnlocked = useMobileAuthStore((s) => s.isUnlocked);
|
||||
|
||||
const port = parseInt(serverPort || "0", 10) >= 50000;
|
||||
|
||||
if (!user || (!isUnlocked && !port)) {
|
||||
return <Redirect href="/login" />;
|
||||
}
|
||||
|
||||
const isNormalScanner = parseInt(serverPort || "0", 10) >= 50000;
|
||||
|
||||
const hasRole = (allowed: string[] = []) => {
|
||||
const role = user?.role?.toLowerCase();
|
||||
return role ? allowed.includes(role) : false;
|
||||
};
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
screenOptions={{
|
||||
@@ -27,11 +50,24 @@ export default function TabsLayout() {
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="config"
|
||||
name="laneCheck"
|
||||
options={{
|
||||
title: "settings",
|
||||
title: "Lane Check",
|
||||
|
||||
href: isNormalScanner ? null : "/(tabs)/laneCheck",
|
||||
tabBarIcon: ({ color, size }) => <Rows4 size={size} color={color} />,
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="dockScan"
|
||||
options={{
|
||||
title: "Dock scan",
|
||||
href:
|
||||
isNormalScanner || !hasRole(["admin", "manager"])
|
||||
? null
|
||||
: "/(tabs)/dockScan",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Settings size={size} color={color} />
|
||||
<Container size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
@@ -40,7 +76,10 @@ export default function TabsLayout() {
|
||||
options={{
|
||||
title: "Logs",
|
||||
href:
|
||||
parseInt(serverPort || "0", 10) >= 50000 ? null : "/(tabs)/logs",
|
||||
isNormalScanner || !hasRole(["admin", "manager"])
|
||||
? null
|
||||
: "/(tabs)/logs",
|
||||
tabBarIcon: ({ color, size }) => <Logs size={size} color={color} />,
|
||||
}}
|
||||
/>
|
||||
{/* <Tabs.Screen
|
||||
@@ -51,6 +90,15 @@ export default function TabsLayout() {
|
||||
parseInt(serverPort || "0", 10) >= 50000 ? null : "/(tabs)/logs",
|
||||
}}
|
||||
/> */}
|
||||
<Tabs.Screen
|
||||
name="config"
|
||||
options={{
|
||||
title: "settings",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Settings size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Link } from "expo-router";
|
||||
import { Text, View } from "react-native";
|
||||
import Setup from "../setup";
|
||||
|
||||
export default function SettingsTab() {
|
||||
return <Setup />
|
||||
}
|
||||
return <Setup />;
|
||||
}
|
||||
|
||||
26
lstMobile/src/app/(tabs)/dockScan.tsx
Normal file
26
lstMobile/src/app/(tabs)/dockScan.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from "react";
|
||||
import { Text, View } from "react-native";
|
||||
import { Button } from "../../components/ui/button";
|
||||
|
||||
export default function LaneCheck() {
|
||||
const getInfo = async () => {
|
||||
const info = "ho";
|
||||
|
||||
console.log(info);
|
||||
};
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
//justifyContent: "center",
|
||||
alignItems: "center",
|
||||
marginTop: 50,
|
||||
}}
|
||||
>
|
||||
<Text>Dock Scanning</Text>
|
||||
<Button onPress={getInfo}>
|
||||
<Text>Check info</Text>
|
||||
</Button>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
37
lstMobile/src/app/(tabs)/laneCheck.tsx
Normal file
37
lstMobile/src/app/(tabs)/laneCheck.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import React, { useCallback, useEffect } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
import { Button } from "../../components/ui/button";
|
||||
import { type ZebraScanResult, zebraScanner } from "../../lib/ZebraScanner";
|
||||
|
||||
export default function LaneCheck() {
|
||||
const handleScan = useCallback(async (scan: ZebraScanResult) => {
|
||||
console.log(scan);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
zebraScanner.ensureProfile();
|
||||
zebraScanner.startListening();
|
||||
|
||||
const sub = zebraScanner.addScanListener((scan) => {
|
||||
//console.log("SCAN:", scan);
|
||||
handleScan(scan);
|
||||
});
|
||||
|
||||
return () => {
|
||||
sub.remove();
|
||||
zebraScanner.stopListening();
|
||||
};
|
||||
}, [handleScan]);
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
//justifyContent: "center",
|
||||
alignItems: "center",
|
||||
marginTop: 50,
|
||||
}}
|
||||
>
|
||||
<Text>LaneChecks</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,26 +1,21 @@
|
||||
import { PortalHost } from "@rn-primitives/portal";
|
||||
import { Stack } from "expo-router";
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import "../../global.css";
|
||||
import { PortalHost } from "@rn-primitives/portal";
|
||||
import { View } from "react-native";
|
||||
import useDeviceLock from "../hooks/useDeviceCheck";
|
||||
|
||||
export default function RootLayout() {
|
||||
useDeviceLock();
|
||||
|
||||
return (
|
||||
<>
|
||||
<StatusBar style="dark" />
|
||||
<Stack screenOptions={{ headerShown: false }}>
|
||||
<Stack.Screen name="index" />
|
||||
<View className="items-center">
|
||||
<Stack.Screen
|
||||
name="(tabs)"
|
||||
options={{
|
||||
title: "Pending update",
|
||||
headerStyle: {
|
||||
backgroundColor: "lightblue",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
<Stack.Screen name="login" />
|
||||
<Stack.Screen name="setup" />
|
||||
<Stack.Screen name="updateScreen" />
|
||||
<Stack.Screen name="(tabs)" />
|
||||
</Stack>
|
||||
<PortalHost />
|
||||
</>
|
||||
|
||||
@@ -1,127 +1,31 @@
|
||||
import axios from "axios";
|
||||
import Constants from "expo-constants";
|
||||
import { Redirect, useRouter } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Redirect } from "expo-router";
|
||||
import { ActivityIndicator, Text, View } from "react-native";
|
||||
import { useAppStore } from "../hooks/useAppStore";
|
||||
import { useMobileAuthStore } from "../hooks/useMobileAuth";
|
||||
import { useServerStore } from "../hooks/useServerCheck";
|
||||
import { devDelay } from "../lib/devMode";
|
||||
import { useAppStartup } from "../hooks/useAppStartup";
|
||||
|
||||
const startupMessages = {
|
||||
loading: "Loading app...",
|
||||
validating: "Validating data...",
|
||||
scannerMode: "Checking scanner mode...",
|
||||
normalScanner: "Starting normal ALPLAprod scanner that has no LST rules",
|
||||
checkingUpdates: "Checking for updates...",
|
||||
opening: "Opening LST scan app...",
|
||||
error: "Something went wrong during startup.",
|
||||
};
|
||||
|
||||
export default function Index() {
|
||||
const router = useRouter();
|
||||
const [message, setMessage] = useState(<Text>Starting app...</Text>);
|
||||
const [ready, setReady] = useState(false);
|
||||
const setServerVersion = useServerStore((s) => s.setServerVersion);
|
||||
//const { isUnlocked } = useMobileAuthStore();
|
||||
const { ready, startupRoute, status } = useAppStartup();
|
||||
|
||||
const hasHydrated = useAppStore((s) => s.hasHydrated);
|
||||
const serverPort = useAppStore((s) => s.serverPort);
|
||||
const serverIp = useAppStore((s) => s.serverIp);
|
||||
const build = Constants.expoConfig?.android?.versionCode ?? 1;
|
||||
const hasValidSetup = useAppStore((s) => s.hasValidSetup);
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasHydrated) {
|
||||
setMessage(<Text>Loading app...</Text>);
|
||||
return;
|
||||
}
|
||||
|
||||
const startup = async () => {
|
||||
try {
|
||||
await devDelay(1500);
|
||||
|
||||
setMessage(<Text>Validating data...</Text>);
|
||||
await devDelay(1500);
|
||||
|
||||
if (!hasValidSetup()) {
|
||||
router.replace("/setup");
|
||||
return;
|
||||
}
|
||||
|
||||
// checking for lst.
|
||||
console.log(
|
||||
`http://${serverIp}:${parseInt(serverPort || "0", 10) >= 50000 ? "3000" : serverPort}/lst/api/mobile/version`,
|
||||
);
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`http://${serverIp}:${parseInt(serverPort || "0", 10) >= 50000 ? "3000" : serverPort}/lst/api/mobile/version`,
|
||||
{
|
||||
timeout: 5000,
|
||||
},
|
||||
);
|
||||
|
||||
console.log(res.data);
|
||||
|
||||
// if the build version dose not match the latest server version force update
|
||||
if (res.status === 200) {
|
||||
setServerVersion(res.data);
|
||||
}
|
||||
|
||||
// TODO: change the header to show orange and theres a new version
|
||||
// console.log(build < res.data.minSupportedVersionCode);
|
||||
// if (build < res.data.minSupportedVersionCode) {
|
||||
// router.replace("/updateScreen");
|
||||
// return;
|
||||
// }
|
||||
} catch (error) {
|
||||
console.log("Error: ", error);
|
||||
}
|
||||
|
||||
setMessage(<Text>Checking scanner mode...</Text>);
|
||||
await devDelay(1500);
|
||||
|
||||
if (parseInt(serverPort || "0", 10) >= 50000) {
|
||||
setMessage(
|
||||
<Text>
|
||||
Starting normal alplaprod scanner that has no LST rules
|
||||
</Text>,
|
||||
);
|
||||
await devDelay(1500);
|
||||
//router.replace("/scanner");
|
||||
setReady(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setMessage(<Text>Checking for updates</Text>);
|
||||
await devDelay(1500);
|
||||
// TODO if theres an update go to update screen message :D
|
||||
setMessage(<Text>Opening LST scan app</Text>);
|
||||
await devDelay(3250);
|
||||
|
||||
setReady(true);
|
||||
} catch (error) {
|
||||
console.log("Startup error", error);
|
||||
setMessage(<Text>Something went wrong during startup.</Text>);
|
||||
}
|
||||
};
|
||||
|
||||
startup();
|
||||
}, [
|
||||
hasHydrated,
|
||||
hasValidSetup,
|
||||
serverPort,
|
||||
serverIp,
|
||||
router,
|
||||
setServerVersion,
|
||||
]);
|
||||
|
||||
// if (ready && !isUnlocked) {
|
||||
// return <Redirect href={"/login"} />;
|
||||
// }
|
||||
if (ready) {
|
||||
return <Redirect href="/(tabs)/scanner" />;
|
||||
if (ready && startupRoute) {
|
||||
return <Redirect href={startupRoute as any} />;
|
||||
}
|
||||
|
||||
if (ready) {
|
||||
return <Redirect href="/login" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
marginTop: 12,
|
||||
}}
|
||||
>
|
||||
{message}
|
||||
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
|
||||
<Text>{startupMessages[status]}</Text>
|
||||
<ActivityIndicator size="large" />
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1,27 +1,49 @@
|
||||
import axios from "axios";
|
||||
import Constants from "expo-constants";
|
||||
|
||||
import { useRouter } from "expo-router";
|
||||
import { useState } from "react";
|
||||
import { Alert, Button, Text, View } from "react-native";
|
||||
import { Button, Text, View } from "react-native";
|
||||
import { Input } from "../components/ui/input";
|
||||
import { useAppStore } from "../hooks/useAppStore";
|
||||
import { useMobileAuthStore } from "../hooks/useMobileAuth";
|
||||
|
||||
export default function Login() {
|
||||
const { setUser } = useMobileAuthStore();
|
||||
// doing this causes rerender and sub
|
||||
//const { setUser } = useMobileAuthStore();
|
||||
const [pin, setPin] = useState("");
|
||||
const serverPort = useAppStore((s) => s.serverPort);
|
||||
const serverIp = useAppStore((s) => s.serverIp);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const onLogin = async () => {
|
||||
if (pin.length < 6) {
|
||||
console.log("pin must be min 6 ");
|
||||
}
|
||||
console.log(pin);
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`http://${serverIp}:${parseInt(serverPort || "0", 10) >= 50000 ? "3000" : serverPort}/lst/api/mobile/version`,
|
||||
const res = await axios.post(
|
||||
`http://${serverIp}:${parseInt(serverPort || "0", 10) >= 50000 ? "3000" : serverPort}/lst/api/mobile/auth/pin`,
|
||||
{ pin },
|
||||
|
||||
{
|
||||
timeout: 5000,
|
||||
},
|
||||
);
|
||||
|
||||
console.log(res.data);
|
||||
} catch (error) {}
|
||||
if (res.status === 200) {
|
||||
// this way to set the user is direct and basically a 1 shot
|
||||
useMobileAuthStore.getState().setUser(res.data.data);
|
||||
return router.replace("/(tabs)/scanner");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
const config = () => {
|
||||
console.log("config");
|
||||
return router.replace("/setup");
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -43,10 +65,21 @@ export default function Login() {
|
||||
keyboardType="number-pad"
|
||||
textContentType="oneTimeCode"
|
||||
placeholder="Pin number"
|
||||
onChangeText={setPin}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
<Button title="Login" onPress={onLogin} />
|
||||
<View>
|
||||
<Text>
|
||||
Warning: If you are logged into another scanner you will encounter
|
||||
scan errors, please do not try to log into more than 1 scanner at a
|
||||
time.
|
||||
</Text>
|
||||
</View>
|
||||
<View className="flex gap-2 flex-row">
|
||||
<Button title="Login" onPress={onLogin} />
|
||||
<Button title="Config" onPress={config} />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ export default function Setup() {
|
||||
marginTop: "auto",
|
||||
alignItems: "center",
|
||||
padding: 10,
|
||||
marginBottom: 12,
|
||||
marginBottom: 50,
|
||||
}}
|
||||
>
|
||||
<Text className="text-sm color-[#312f2f]">
|
||||
|
||||
@@ -1,15 +1,133 @@
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
import axios from "axios";
|
||||
import { format } from "date-fns-tz";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Alert, Button, Text, View } from "react-native";
|
||||
import { useAppStore } from "../hooks/useAppStore";
|
||||
import { useMobileAuthStore } from "../hooks/useMobileAuth";
|
||||
import { useScannerStore } from "../hooks/useScannerStore";
|
||||
import { scannerFeedback } from "../lib/feedbackScan";
|
||||
import { sendTcpMessage } from "../lib/tcpScan";
|
||||
import { type ZebraScanResult, zebraScanner } from "../lib/ZebraScanner";
|
||||
import { ScannedLabelBox } from "./ScannedLabels";
|
||||
import { GlobalFooter } from "./UpdateFooter";
|
||||
import { Separator } from "./ui/separator";
|
||||
|
||||
import { zebraScanner } from "../lib/ZebraScanner";
|
||||
const STX = "\x02";
|
||||
const ETX = "\x03";
|
||||
|
||||
const formatName = (name?: string) =>
|
||||
name ? name.charAt(0).toUpperCase() + name.slice(1).toLowerCase() : "";
|
||||
|
||||
export default function LSTScanner() {
|
||||
const handleScan = useCallback(async (scan: any) => {
|
||||
console.log(scan);
|
||||
}, []);
|
||||
const user = useMobileAuthStore((s) => s.user);
|
||||
const logout = useMobileAuthStore((s) => s.logout);
|
||||
|
||||
// TODO : move to off tcp stuff after od
|
||||
const lastScan = useScannerStore((s) => s.lastScan);
|
||||
const setLastScan = useScannerStore((s) => s.setLastScan);
|
||||
const [tagScans, setTagScans] = useState<any>([]);
|
||||
const scannerIdFromStore = useAppStore((s) => s.scannerId);
|
||||
const serverIp = useAppStore((s) => s.serverIp);
|
||||
const serverPort = useAppStore((s) => s.serverPort);
|
||||
const [bgColor, setBGColor] = useState<string | null>(null);
|
||||
|
||||
const handleScan = useCallback(
|
||||
async (scan: ZebraScanResult) => {
|
||||
await scannerFeedback({
|
||||
type: "scan",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
|
||||
const isAlphaStart = /^[a-zA-Z]/.test(scan.data);
|
||||
const isExcluded = (user?.excludedCommand ?? []).some((cmd) =>
|
||||
scan.data.toLowerCase().includes(cmd.toLowerCase()),
|
||||
);
|
||||
|
||||
if (isAlphaStart && isExcluded) {
|
||||
Alert.alert(
|
||||
`Command: ${scan.data} is not allowed to be used, please contact logistics if this is an error`,
|
||||
);
|
||||
}
|
||||
|
||||
let commandToSend = `${STX}${user?.scannerId}@${scan.data}${ETX}`;
|
||||
|
||||
// if we are sscc we need to scan like this .... <STX>98@]C100090087710038712256<ETX>
|
||||
if (scan.data.startsWith("000")) {
|
||||
commandToSend = `${STX}${user?.scannerId}@]C1${scan.data}${ETX}`;
|
||||
setTagScans((prev: any) => [
|
||||
{
|
||||
label: parseInt(scan.data.slice(10, -1) || "000", 10).toString(),
|
||||
date: format(new Date(Date.now()), "HH:mm"),
|
||||
},
|
||||
...prev,
|
||||
]);
|
||||
}
|
||||
|
||||
const scanned = (await sendTcpMessage(
|
||||
commandToSend,
|
||||
serverIp,
|
||||
parseInt(serverPort || "0", 10),
|
||||
)) as any;
|
||||
// send the logs to lst but allow it to time out if it dose not exist just bc.
|
||||
const logInfo = { ...scanned, user: user?.name };
|
||||
|
||||
try {
|
||||
await axios.post(
|
||||
`http://${serverIp.trim()}:3000/lst/api/mobile/logs`,
|
||||
logInfo,
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
// const response = await sendTcpMessage(tcpMessage);
|
||||
console.log(scanned.data);
|
||||
if (scanned.data.status !== "error") {
|
||||
await scannerFeedback({
|
||||
type: "good",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
setBGColor("bg-green-500");
|
||||
setTimeout(() => {
|
||||
setBGColor(null);
|
||||
}, 1 * 1000);
|
||||
}
|
||||
|
||||
if (scanned.data.status === "error") {
|
||||
await scannerFeedback({
|
||||
type: scanned.data.status === "error" ? "bad" : "good",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
setBGColor("bg-red-500");
|
||||
setTimeout(() => {
|
||||
setBGColor(null);
|
||||
}, 1 * 1000);
|
||||
}
|
||||
setLastScan(scanned.data);
|
||||
|
||||
// if we change commands we want to zero out the last scanned labels
|
||||
if (isAlphaStart) {
|
||||
setTagScans([]);
|
||||
}
|
||||
},
|
||||
[
|
||||
serverIp,
|
||||
serverPort,
|
||||
setLastScan,
|
||||
user?.scannerId,
|
||||
user?.name,
|
||||
user?.excludedCommand?.some,
|
||||
user?.excludedCommand,
|
||||
],
|
||||
);
|
||||
|
||||
const clearScans = () => {
|
||||
// add in
|
||||
setTagScans([]);
|
||||
};
|
||||
|
||||
//console.log(lastScan);
|
||||
@@ -29,23 +147,69 @@ export default function LSTScanner() {
|
||||
};
|
||||
}, [handleScan]);
|
||||
return (
|
||||
<View>
|
||||
<View style={{ alignItems: "center", margin: 10 }}>
|
||||
<Text style={{ fontSize: 20, fontWeight: "600" }}>LST Scanner</Text>
|
||||
<View className={`${bgColor ?? ""} flex-1 w-screen`}>
|
||||
<View style={{ alignItems: "center", margin: 5 }}>
|
||||
<Text style={{ fontSize: 14, fontWeight: "600" }}>
|
||||
User: {formatName(user?.name ?? "")}
|
||||
</Text>
|
||||
<Text style={{ fontSize: 18, fontWeight: "600" }}>
|
||||
LST Scanner id: {user?.scannerId}
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
marginTop: 5,
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
{!lastScan ? (
|
||||
<View style={{ marginTop: 10, alignItems: "center" }}>
|
||||
<Text className="text-xl font-bold">Ready to scan</Text>
|
||||
<Text>Waiting for first scan...</Text>
|
||||
</View>
|
||||
) : (
|
||||
<View
|
||||
style={{
|
||||
marginTop: 10,
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
{lastScan.lines
|
||||
?.filter((line) => !/^\d+@$/.test(line))
|
||||
.map((i) => {
|
||||
return (
|
||||
<View
|
||||
style={{ marginTop: 10, alignItems: "center" }}
|
||||
key={i}
|
||||
>
|
||||
<Text style={{ fontSize: 18, fontWeight: "600" }}>
|
||||
{i}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
<View
|
||||
style={{
|
||||
marginTop: 50,
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Text>Relocate</Text>
|
||||
<Text>0 / 4</Text>
|
||||
<Separator className="m-2" />
|
||||
<View className="flex-1 w-full px-4">
|
||||
<ScannedLabelBox
|
||||
labels={tagScans}
|
||||
color={bgColor}
|
||||
clearScan={clearScans}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* <View>
|
||||
<Text>List of recent scanned pallets TBA</Text>
|
||||
</View> */}
|
||||
<View className="m-2">
|
||||
{user && (
|
||||
<View className="items-center">
|
||||
<Button title="Logout" onPress={logout} />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
<View>
|
||||
<GlobalFooter />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,13 @@ export default function ProdScanner() {
|
||||
|
||||
const handleScan = useCallback(
|
||||
async (scan: ZebraScanResult) => {
|
||||
await scannerFeedback({
|
||||
type: "scan",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
|
||||
let commandToSend = `${STX}${scannerIdFromStore}@${scan.data}${ETX}`;
|
||||
|
||||
// if we are sscc we need to scan like this .... <STX>98@]C100090087710038712256<ETX>
|
||||
|
||||
133
lstMobile/src/hooks/useAppStartup.tsx
Normal file
133
lstMobile/src/hooks/useAppStartup.tsx
Normal file
@@ -0,0 +1,133 @@
|
||||
import axios from "axios";
|
||||
import Constants from "expo-constants";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { devDelay } from "../lib/devMode";
|
||||
import { useAppStore } from "./useAppStore";
|
||||
import { useServerStore } from "./useServerCheck";
|
||||
|
||||
type StartupStatus =
|
||||
| "loading"
|
||||
| "validating"
|
||||
| "scannerMode"
|
||||
| "normalScanner"
|
||||
| "checkingUpdates"
|
||||
| "opening"
|
||||
| "error";
|
||||
|
||||
export function useAppStartup() {
|
||||
const [ready, setReady] = useState(false);
|
||||
const [status, setStatus] = useState<StartupStatus>("loading");
|
||||
const [startupRoute, setStartupRoute] = useState<string | null>(null);
|
||||
|
||||
const hasRunKey = useRef<string | null>(null);
|
||||
|
||||
const hasHydrated = useAppStore((s) => s.hasHydrated);
|
||||
const serverPort = useAppStore((s) => s.serverPort);
|
||||
const serverIp = useAppStore((s) => s.serverIp);
|
||||
const setServerVersion = useServerStore((s) => s.setServerVersion);
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasHydrated) {
|
||||
setStatus("loading");
|
||||
return;
|
||||
}
|
||||
|
||||
const runKey = `${serverIp}:${serverPort}`;
|
||||
|
||||
if (hasRunKey.current === runKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
hasRunKey.current = runKey;
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
const startup = async () => {
|
||||
try {
|
||||
setReady(false);
|
||||
setStartupRoute(null);
|
||||
|
||||
await devDelay(1500);
|
||||
if (cancelled) return;
|
||||
|
||||
setStatus("validating");
|
||||
await devDelay(1500);
|
||||
if (cancelled) return;
|
||||
|
||||
const hasValidSetup = useAppStore.getState().hasValidSetup;
|
||||
|
||||
if (!hasValidSetup()) {
|
||||
setStartupRoute("/setup");
|
||||
setReady(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const port =
|
||||
parseInt(serverPort || "0", 10) >= 50000 ? "3000" : serverPort;
|
||||
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`http://${serverIp}:${port}/lst/api/mobile/version`,
|
||||
{ timeout: 5000 },
|
||||
);
|
||||
|
||||
if (res.status === 200) {
|
||||
setServerVersion(res.data);
|
||||
}
|
||||
|
||||
const build = Constants.expoConfig?.android?.versionCode ?? 1;
|
||||
|
||||
if (build < res.data.minSupportedVersionCode) {
|
||||
setStartupRoute("/updateScreen");
|
||||
setReady(true);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Version check error:", error);
|
||||
}
|
||||
|
||||
setStatus("scannerMode");
|
||||
await devDelay(1500);
|
||||
if (cancelled) return;
|
||||
|
||||
if (parseInt(serverPort || "0", 10) >= 50000) {
|
||||
setStatus("normalScanner");
|
||||
await devDelay(1500);
|
||||
|
||||
setStartupRoute("/scanner");
|
||||
setReady(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("checkingUpdates");
|
||||
console.log("checking updates");
|
||||
await devDelay(1500);
|
||||
if (cancelled) return;
|
||||
|
||||
setStatus("opening");
|
||||
console.log("opening");
|
||||
await devDelay(1500);
|
||||
if (cancelled) return;
|
||||
|
||||
setStartupRoute("/(tabs)/scanner");
|
||||
console.log("scanner");
|
||||
setReady(true);
|
||||
} catch (error) {
|
||||
console.log("Startup error:", error);
|
||||
setStatus("error");
|
||||
}
|
||||
};
|
||||
|
||||
startup();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [hasHydrated, serverIp, serverPort, setServerVersion]);
|
||||
|
||||
return {
|
||||
ready,
|
||||
startupRoute,
|
||||
status,
|
||||
};
|
||||
}
|
||||
33
lstMobile/src/hooks/useDeviceCheck.tsx
Normal file
33
lstMobile/src/hooks/useDeviceCheck.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { AppState, type AppStateStatus } from "react-native";
|
||||
import { useMobileAuthStore } from "./useMobileAuth";
|
||||
|
||||
export default function useDeviceLock() {
|
||||
const [appState, setAppState] = useState<AppStateStatus>(
|
||||
AppState.currentState,
|
||||
);
|
||||
const appStateRef = useRef<AppStateStatus>(AppState.currentState);
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = AppState.addEventListener("change", (nextAppState) => {
|
||||
const previousAppState = appStateRef.current;
|
||||
|
||||
const wasActive = previousAppState === "active";
|
||||
|
||||
// if the we see aggressive locking then we should remove inactive.
|
||||
const isNowInactive =
|
||||
nextAppState === "background" || nextAppState === "inactive";
|
||||
|
||||
if (wasActive && isNowInactive) {
|
||||
useMobileAuthStore.getState().lock();
|
||||
}
|
||||
|
||||
appStateRef.current = nextAppState;
|
||||
setAppState(nextAppState);
|
||||
});
|
||||
|
||||
return () => subscription.remove();
|
||||
}, []);
|
||||
|
||||
return appState;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ type MobileUser = {
|
||||
name: string;
|
||||
role: "user" | "lead" | "manager" | "admin";
|
||||
excludedCommand: string[];
|
||||
scannerId: string;
|
||||
};
|
||||
|
||||
type AuthState = {
|
||||
|
||||
@@ -2,12 +2,13 @@ import { createAudioPlayer } from "expo-audio";
|
||||
import * as Haptics from "expo-haptics";
|
||||
|
||||
export type ScanFeedback = {
|
||||
type: "good" | "bad";
|
||||
type: "good" | "bad" | "scan";
|
||||
sound?: boolean;
|
||||
vibrate?: boolean;
|
||||
led?: boolean;
|
||||
};
|
||||
|
||||
const scan = createAudioPlayer(require("../../assets/sounds/scan.wav"));
|
||||
const goodSound = createAudioPlayer(require("../../assets/sounds/good.wav"));
|
||||
const badSound = createAudioPlayer(require("../../assets/sounds/bad.wav"));
|
||||
|
||||
@@ -18,14 +19,15 @@ export async function scannerFeedback({
|
||||
led = true,
|
||||
}: ScanFeedback) {
|
||||
if (sound) {
|
||||
const player = type === "good" ? goodSound : badSound;
|
||||
const player =
|
||||
type === "scan" ? scan : type === "good" ? goodSound : badSound;
|
||||
player.seekTo(0);
|
||||
player.play();
|
||||
}
|
||||
|
||||
if (vibrate) {
|
||||
await Haptics.notificationAsync(
|
||||
type === "good"
|
||||
type === "good" || type === "scan"
|
||||
? Haptics.NotificationFeedbackType.Success
|
||||
: Haptics.NotificationFeedbackType.Error,
|
||||
);
|
||||
|
||||
3
migrations/0045_quick_khan.sql
Normal file
3
migrations/0045_quick_khan.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE "scan_users" ALTER COLUMN "excluded_commands" SET DATA TYPE jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "scan_users" ALTER COLUMN "excluded_commands" SET DEFAULT '';--> statement-breakpoint
|
||||
ALTER TABLE "scan_log" ADD COLUMN "user" text;
|
||||
1
migrations/0046_chemical_the_leader.sql
Normal file
1
migrations/0046_chemical_the_leader.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE "scan_users" ALTER COLUMN "excluded_commands" SET DEFAULT '[]'::jsonb;
|
||||
2149
migrations/meta/0045_snapshot.json
Normal file
2149
migrations/meta/0045_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
2149
migrations/meta/0046_snapshot.json
Normal file
2149
migrations/meta/0046_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -316,6 +316,20 @@
|
||||
"when": 1777666145468,
|
||||
"tag": "0044_steady_magneto",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 45,
|
||||
"version": "7",
|
||||
"when": 1778059667805,
|
||||
"tag": "0045_quick_khan",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 46,
|
||||
"version": "7",
|
||||
"when": 1778059910210,
|
||||
"tag": "0046_chemical_the_leader",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "lst_v3",
|
||||
"version": "0.0.2-alpha.7",
|
||||
"version": "0.0.2-alpha.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "lst_v3",
|
||||
"version": "0.0.2-alpha.7",
|
||||
"version": "0.0.2-alpha.8",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@dotenvx/dotenvx": "^1.57.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lst_v3",
|
||||
"version": "0.0.2-alpha.7",
|
||||
"version": "0.0.2-alpha.8",
|
||||
"description": "The tool that supports us in our everyday alplaprod",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user