From c318e81e728938d4bc49b65850565b557409ef25 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:30:07 +0530 Subject: [PATCH] fix: pass posPrintWidth through params --- main/getPrintTemplates.ts | 7 ++----- main/preload.ts | 5 +++-- main/registerIpcMainActionListeners.ts | 9 ++++++--- src/utils/printTemplates.ts | 4 +++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/main/getPrintTemplates.ts b/main/getPrintTemplates.ts index 98c3ef43..a493b1e4 100644 --- a/main/getPrintTemplates.ts +++ b/main/getPrintTemplates.ts @@ -1,9 +1,8 @@ import fs from 'fs/promises'; import path from 'path'; -import { fyo } from 'src/initFyo'; import { TemplateFile } from 'utils/types'; -export async function getTemplates() { +export async function getTemplates(posTemplateWidth: number) { const paths = await getPrintTemplatePaths(); if (!paths) { return []; @@ -15,9 +14,7 @@ export async function getTemplates() { const template = await fs.readFile(filePath, 'utf-8'); const { mtime } = await fs.stat(filePath); const width = - file?.split('-')[1]?.split('.')[0] === 'POS' - ? (fyo.singles.PrintSettings?.posPrintWidth as number) - : 0; + file?.split('-')[1]?.split('.')[0] === 'POS' ? posTemplateWidth : 0; const height = file?.split('-')[1]?.split('.')[0] === 'POS' ? 22 : 0; templates.push({ diff --git a/main/preload.ts b/main/preload.ts index 0e489284..af27018f 100644 --- a/main/preload.ts +++ b/main/preload.ts @@ -75,9 +75,10 @@ const ipc = { }; }, - async getTemplates(): Promise { + async getTemplates(posTemplateWidth: number): Promise { return (await ipcRenderer.invoke( - IPC_ACTIONS.GET_TEMPLATES + IPC_ACTIONS.GET_TEMPLATES, + posTemplateWidth )) as TemplateFile[]; }, diff --git a/main/registerIpcMainActionListeners.ts b/main/registerIpcMainActionListeners.ts index d3e60626..ac63e565 100644 --- a/main/registerIpcMainActionListeners.ts +++ b/main/registerIpcMainActionListeners.ts @@ -205,9 +205,12 @@ export default function registerIpcMainActionListeners(main: Main) { }; }); - ipcMain.handle(IPC_ACTIONS.GET_TEMPLATES, async () => { - return getTemplates(); - }); + ipcMain.handle( + IPC_ACTIONS.GET_TEMPLATES, + async (_, posPrintWidth: number) => { + return getTemplates(posPrintWidth); + } + ); /** * Database Related Actions diff --git a/src/utils/printTemplates.ts b/src/utils/printTemplates.ts index cba52f01..1f636539 100644 --- a/src/utils/printTemplates.ts +++ b/src/utils/printTemplates.ts @@ -442,7 +442,9 @@ function getAllCSSAsStyleElem() { } export async function updatePrintTemplates(fyo: Fyo) { - const templateFiles = await ipc.getTemplates(); + const templateFiles = await ipc.getTemplates( + fyo.singles.PrintSettings?.posPrintWidth as number + ); const existingTemplates = (await fyo.db.getAll(ModelNameEnum.PrintTemplate, { fields: ['name', 'modified'], filters: { isCustom: false },