From 27da03ec58348100c7103a63179b6aafb8114e77 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 9 Apr 2025 14:18:43 -0700 Subject: [PATCH] Add app progress on file uploads. --- src/main/decoder/decoder.ts | 19 +++++++++++++++++++ src/main/util/setAppProgressBar.ts | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/util/setAppProgressBar.ts diff --git a/src/main/decoder/decoder.ts b/src/main/decoder/decoder.ts index 4e4c290..98ea24d 100644 --- a/src/main/decoder/decoder.ts +++ b/src/main/decoder/decoder.ts @@ -42,6 +42,7 @@ import DecodeTtl from "./decode-ttl"; import { DecodedTtl } from "./decode-ttl.interface"; import DecodeVeh from "./decode-veh"; import { DecodedVeh } from "./decode-veh.interface"; +import setAppProgressbar from "../util/setAppProgressBar"; async function ImportJob(filepath: string): Promise { const parsedFilePath = path.parse(filepath); @@ -56,19 +57,33 @@ async function ImportJob(filepath: string): Promise { //The below all end up returning parts of the job object. //Some of them return additional info - e.g. owner or vehicle record data at both the job and corresponding table level. + setAppProgressbar(0.1); const env: DecodedEnv = await DecodeEnv(extensionlessFilePath); + setAppProgressbar(0.15); const ad1: DecodedAd1 = await DecodeAD1(extensionlessFilePath); + setAppProgressbar(0.2); const ad2: DecodedAD2 = await DecodeAD2(extensionlessFilePath); + setAppProgressbar(0.25); const veh: DecodedVeh = await DecodeVeh(extensionlessFilePath); + setAppProgressbar(0.3); const lin: DecodedLin = await DecodeLin(extensionlessFilePath); + setAppProgressbar(0.35); const pfh: DecodedPfh = await DecodePfh(extensionlessFilePath); + setAppProgressbar(0.4); const pfl: DecodedPfl = await DecodePfl(extensionlessFilePath); + setAppProgressbar(0.45); const pft: DecodedPft = await DecodePft(extensionlessFilePath); + setAppProgressbar(0.5); const pfm: DecodedPfm = await DecodePfm(extensionlessFilePath); + setAppProgressbar(0.55); const pfo: DecodedPfo = await DecodePfo(extensionlessFilePath); // TODO: This will be the `cieca_pfo` object + setAppProgressbar(0.6); const stl: DecodedStl = await DecodeStl(extensionlessFilePath); // TODO: This will be the `cieca_stl` object + setAppProgressbar(0.65); const ttl: DecodedTtl = await DecodeTtl(extensionlessFilePath); + setAppProgressbar(0.7); const pfp: DecodedPfp = await DecodePfp(extensionlessFilePath); + setAppProgressbar(0.75); const jobObjectUncleaned: RawJobDataObject = { ...env, @@ -89,6 +104,7 @@ async function ImportJob(filepath: string): Promise { // Replace owner information with claimant information if necessary const jobObject = ReplaceOwnerInfoWithClaimant(jobObjectUncleaned); + setAppProgressbar(0.8); if (import.meta.env.DEV) { // Save jobObject to a timestamped JSON file @@ -126,6 +142,7 @@ async function ImportJob(filepath: string): Promise { issupplement: false, jobid: null, }; + setAppProgressbar(0.85); const existingVehicleRecord: VehicleQueryResult = await client.request( QUERY_VEHICLE_BY_VIN_TYPED, @@ -141,6 +158,7 @@ async function ImportJob(filepath: string): Promise { console.log("Available Job record to upload;", newAvailableJob); + setAppProgressbar(0.95); const existingJobRecord: QueryJobByClmNoResult = await client.request( QUERY_JOB_BY_CLM_NO_TYPED, { clm_no: jobObject.clm_no }, @@ -157,6 +175,7 @@ async function ImportJob(filepath: string): Promise { jobInput: [newAvailableJob], }, ); + setAppProgressbar(-1); new Notification({ title: "Job Imported", body: `Job ${newAvailableJob.cieca_id} imported successfully`, diff --git a/src/main/util/setAppProgressBar.ts b/src/main/util/setAppProgressBar.ts new file mode 100644 index 0000000..396bbf2 --- /dev/null +++ b/src/main/util/setAppProgressBar.ts @@ -0,0 +1,9 @@ +import { getMainWindow } from "./toRenderer"; + +const setAppProgressbar = (progress: number): void => { + const mainWindow = getMainWindow(); + if (mainWindow) { + mainWindow.setProgressBar(progress); + } +}; +export default setAppProgressbar;