capacitor dwld options

This commit is contained in:
Tamilselvan 2026-03-27 01:18:00 +05:30
parent 8c80629ca4
commit 452c030713
11 changed files with 3958 additions and 3797 deletions

10
capacitor.config.json Normal file
View File

@ -0,0 +1,10 @@
{
"appId": "com.example.app",
"appName": "PozoApp",
"webDir": "dist",
"plugins": {
"StatusBar": {
"overlay": false
}
}
}

View File

@ -12,10 +12,14 @@
}, },
"dependencies": { "dependencies": {
"@ant-design/plots": "^2.6.8", "@ant-design/plots": "^2.6.8",
"@capacitor-community/file-opener": "^8.0.0",
"@capacitor-community/speech-recognition": "^7.0.1", "@capacitor-community/speech-recognition": "^7.0.1",
"@capacitor-mlkit/barcode-scanning": "^8.0.1", "@capacitor-mlkit/barcode-scanning": "^8.0.1",
"@capacitor/android": "^8.3.0",
"@capacitor/app": "^8.0.1", "@capacitor/app": "^8.0.1",
"@capacitor/core": "^8.1.0", "@capacitor/cli": "^8.3.0",
"@capacitor/core": "^8.3.0",
"@capacitor/filesystem": "^8.1.2",
"@dnd-kit/core": "^6.3.1", "@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0", "@dnd-kit/sortable": "^10.0.0",
"@emotion/react": "^11.11.4", "@emotion/react": "^11.11.4",
@ -27,6 +31,7 @@
"@tanstack/react-query-devtools": "^5.91.1", "@tanstack/react-query-devtools": "^5.91.1",
"@tanstack/react-virtual": "^3.13.18", "@tanstack/react-virtual": "^3.13.18",
"@types/node": "^25.5.0", "@types/node": "^25.5.0",
"@vitejs/plugin-legacy": "^8.0.1",
"@zxing/library": "^0.21.3", "@zxing/library": "^0.21.3",
"antd": "^5.17.4", "antd": "^5.17.4",
"antd-img-crop": "^4.22.0", "antd-img-crop": "^4.22.0",
@ -92,7 +97,7 @@
"eslint-plugin-react-refresh": "^0.4.7", "eslint-plugin-react-refresh": "^0.4.7",
"prettier": "^3.5.3", "prettier": "^3.5.3",
"rollup-plugin-obfuscator": "^1.1.0", "rollup-plugin-obfuscator": "^1.1.0",
"sass": "^1.77.2", "sass": "^1.98.0",
"terser": "^5.31.3", "terser": "^5.31.3",
"vite": "^8.0.0", "vite": "^8.0.0",
"vite-plugin-obfuscator": "^1.0.5", "vite-plugin-obfuscator": "^1.0.5",

View File

@ -16,6 +16,7 @@ import { RadioGrpButton } from '../../Components/Forms/RadioGroup.jsx';
import { AiFillDelete } from 'react-icons/ai'; import { AiFillDelete } from 'react-icons/ai';
import upldimg from '../../Images/upldimg.png'; import upldimg from '../../Images/upldimg.png';
import { FiDelete, FiDownload } from 'react-icons/fi'; import { FiDelete, FiDownload } from 'react-icons/fi';
import { downloadFile } from '../../utils/downloadFile.js';
const allowedExcelTypes = [ const allowedExcelTypes = [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx
'application/vnd.ms-excel', // .xls 'application/vnd.ms-excel', // .xls
@ -328,10 +329,17 @@ const ConfigExcel = ({ handleSubmit, CategoryNames, SubCatData }) => {
window.navigator.msSaveOrOpenBlob(blob, filename); window.navigator.msSaveOrOpenBlob(blob, filename);
} else { } else {
// For other browsers // For other browsers
const downloadLink = document.createElement('a'); downloadFile(
downloadLink.href = window.URL.createObjectURL(blob); buffer,
downloadLink.download = filename; "CategoryDatas.xlsx",
downloadLink.click(); "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
(success) => {
if (!success) {
console.error("error occured while downloading")
}
}
);
} }
} }
}; };
@ -415,10 +423,17 @@ const ConfigExcel = ({ handleSubmit, CategoryNames, SubCatData }) => {
window.navigator.msSaveOrOpenBlob(blob, filename); window.navigator.msSaveOrOpenBlob(blob, filename);
} else { } else {
// For other browsers // For other browsers
const downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(blob); downloadFile(
downloadLink.download = filename; buffer,
downloadLink.click(); "SubcatagoryDatas.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
(success) => {
if (!success) {
console.error("Failed to download the file. Please try again.")
}
}
);
} }
} }
}; };
@ -529,10 +544,17 @@ const ConfigExcel = ({ handleSubmit, CategoryNames, SubCatData }) => {
window.navigator.msSaveOrOpenBlob(blob, filename); window.navigator.msSaveOrOpenBlob(blob, filename);
} else { } else {
// For other browsers // For other browsers
const downloadLink = document.createElement('a'); downloadFile(
downloadLink.href = window.URL.createObjectURL(blob); buffer,
downloadLink.download = filename; "BrandDatas.xlsx",
downloadLink.click(); "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
(success) => {
if (!success) {
console.error("Failed to download the file. Please try again.")
}
}
);
} }
} }
}; };
@ -673,7 +695,7 @@ const ConfigExcel = ({ handleSubmit, CategoryNames, SubCatData }) => {
...record, ...record,
...values, ...values,
}); });
} catch (errInfo) {} } catch (errInfo) { }
}; };
let childNode = children; let childNode = children;

View File

@ -43,6 +43,7 @@ import Buttons from '../../Components/Forms/Buttons.jsx';
import { IoClose } from 'react-icons/io5'; import { IoClose } from 'react-icons/io5';
import { Messages } from '../../Components/Notifications/Messages.jsx'; import { Messages } from '../../Components/Notifications/Messages.jsx';
import useWhyDidYouUpdate from '../../Services/findrerender.js'; import useWhyDidYouUpdate from '../../Services/findrerender.js';
import { downloadFile } from '../../utils/downloadFile.js';
const getApplicationSampleData = (appName) => { const getApplicationSampleData = (appName) => {
const sampleDataMap = { const sampleDataMap = {
@ -2479,22 +2480,38 @@ const ProductExcel = ({
}); });
// Generate and download the file // Generate and download the file
const buffer = await workbook.xlsx.writeBuffer(); // const buffer = await workbook.xlsx.writeBuffer();
const blob = new Blob([buffer], { // const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
}); // });
const filename = 'Product Data.xlsx'; // const filename = 'Product Data.xlsx';
if (typeof window !== 'undefined') { // if (typeof window !== 'undefined') {
if (window.navigator && window.navigator.msSaveOrOpenBlob) { // if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, filename); // window.navigator.msSaveOrOpenBlob(blob, filename);
// } else {
// const downloadLink = document.createElement('a');
// downloadLink.href = window.URL.createObjectURL(blob);
// downloadLink.download = filename;
// downloadLink.click();
// }
// }
const buffer = await workbook.xlsx.writeBuffer();
downloadFile(
buffer,
"Product Data.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
(success) => {
if (success) {
console.log("File downloaded and opened successfully!");
} else { } else {
const downloadLink = document.createElement('a'); console.log("Failed to download/open file.");
downloadLink.href = window.URL.createObjectURL(blob);
downloadLink.download = filename;
downloadLink.click();
} }
} }
);
}; };
// Usage examples: // Usage examples:
@ -2864,7 +2881,7 @@ const ProductExcel = ({
...record, ...record,
...values, ...values,
}); });
} catch (errInfo) {} } catch (errInfo) { }
}; };
let childNode = children; let childNode = children;
@ -3041,15 +3058,21 @@ const ProductExcel = ({
selectUnlockedCells: true, selectUnlockedCells: true,
}); });
// const buffer = await workbook.xlsx.writeBuffer();
// const blob = new Blob([buffer], {
// type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
// });
// const downloadLink = document.createElement('a');
// downloadLink.href = window.URL.createObjectURL(blob);
// downloadLink.download = 'Product_Data.xlsx';
// downloadLink.click();
const buffer = await workbook.xlsx.writeBuffer(); const buffer = await workbook.xlsx.writeBuffer();
const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});
const downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(blob);
downloadLink.download = 'Product_Data.xlsx';
downloadLink.click();
downloadFile(
buffer,
"Product_Data.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
);
setLoading(false); setLoading(false);
} else { } else {
setLoading(false); setLoading(false);
@ -3634,8 +3657,7 @@ const ProductExcel = ({
<div className="productonlineImg"> <div className="productonlineImg">
{imagedata?.map((item, index) => ( {imagedata?.map((item, index) => (
<div <div
className={`singleimg ${ className={`singleimg ${selectedImage === item ? 'selected' : ''
selectedImage === item ? 'selected' : ''
}`} }`}
key={index} key={index}
onClick={() => setSelectedImage(item)} onClick={() => setSelectedImage(item)}

View File

@ -29,6 +29,7 @@ import { DefaultModal } from '../../Components/Modal/DefaultModal.jsx';
import Buttons from '../../Components/Forms/Buttons.jsx'; import Buttons from '../../Components/Forms/Buttons.jsx';
import { getPurchaseSupplierAndWareHouseData } from '../../Features/PurchaseOrder/PurchaseOrder.js'; import { getPurchaseSupplierAndWareHouseData } from '../../Features/PurchaseOrder/PurchaseOrder.js';
import { Messages } from '../../Components/Notifications/Messages.jsx'; import { Messages } from '../../Components/Notifications/Messages.jsx';
import { downloadFile } from '../../utils/downloadFile.js';
// Constants // Constants
const ALLOWED_EXCEL_TYPES = [ const ALLOWED_EXCEL_TYPES = [
@ -522,15 +523,19 @@ const PurchaseExcel = ({ handleSubmit }) => {
// Step 7: Export file // Step 7: Export file
const buffer = await workbook.xlsx.writeBuffer(); const buffer = await workbook.xlsx.writeBuffer();
const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});
const filename = `PurchaseOrder_${supplierDisplayName}.xlsx`; const filename = `PurchaseOrder_${supplierDisplayName}.xlsx`;
const link = document.createElement('a');
link.href = URL.createObjectURL(blob); downloadFile(
link.download = filename; buffer,
link.click(); filename,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
(success) => {
if (!success) {
setMessageType('error');
setMessageData('Failed to download the file. Please try again.');
}
}
);
setSupplierProducts([]); setSupplierProducts([]);
setSelectedSupplierData(null); setSelectedSupplierData(null);

View File

@ -19,6 +19,7 @@ import {
import QRCodeLib from 'qrcode'; import QRCodeLib from 'qrcode';
import { LuDownload } from 'react-icons/lu'; import { LuDownload } from 'react-icons/lu';
import { BsFileEarmarkPdf } from 'react-icons/bs'; import { BsFileEarmarkPdf } from 'react-icons/bs';
import { downloadFile } from '../../../utils/downloadFile';
const subDirectory = import.meta.env.ENV_MAIN_BASE_URL || '/'; const subDirectory = import.meta.env.ENV_MAIN_BASE_URL || '/';
@ -312,7 +313,19 @@ const MenuQRCode = () => {
if (openPreview) { if (openPreview) {
setIsPreviewModalOpen(true); setIsPreviewModalOpen(true);
} else { } else {
pdf.save('menu-qr.pdf'); // pdf.save('menu-qr.pdf');
const pdfBuffer = pdf.output('arraybuffer'); // ✅ arraybuffer for downloadFile
downloadFile(
pdfBuffer,
"menu-qr.pdf",
"application/pdf",
(success) => {
if (!success) {
setMessageType('error');
setMessageData('Failed to download the PDF. Please try again.');
}
}
);
} }
} catch (err) { } catch (err) {
console.error('PDF generation failed', err); console.error('PDF generation failed', err);
@ -323,17 +336,21 @@ const MenuQRCode = () => {
const downloadPreviewPdf = () => { const downloadPreviewPdf = () => {
if (!pdfPreviewUrl) return; if (!pdfPreviewUrl) return;
fetch(pdfPreviewUrl) fetch(pdfPreviewUrl)
.then((r) => r.blob()) .then((r) => r.arrayBuffer()) // ✅ arrayBuffer instead of blob
.then((blob) => { .then((buffer) => {
const url = URL.createObjectURL(blob); downloadFile(
const a = document.createElement('a'); buffer,
a.href = url; "menu-qr.pdf",
a.download = 'menu-qr.pdf'; "application/pdf",
document.body.appendChild(a); (success) => {
a.click(); if (!success) {
a.remove(); setMessageType('error');
URL.revokeObjectURL(url); setMessageData('Failed to download the file. Please try again.');
}
}
);
}); });
}; };

View File

@ -37,6 +37,7 @@ import {
import { Messages } from '../../Components/Notifications/Messages.jsx'; import { Messages } from '../../Components/Notifications/Messages.jsx';
import { getPurchaseSupplierAndWareHouseData } from '../../Features/PurchaseOrder/PurchaseOrder.js'; import { getPurchaseSupplierAndWareHouseData } from '../../Features/PurchaseOrder/PurchaseOrder.js';
import { getSupplaierIdwithTypeBasedProducts } from '../../Features/SupplierProductMapping/SupplierProductMapping.js'; import { getSupplaierIdwithTypeBasedProducts } from '../../Features/SupplierProductMapping/SupplierProductMapping.js';
import { downloadFile } from '../../utils/downloadFile.js';
const allowedExcelTypes = [ const allowedExcelTypes = [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx
@ -1007,14 +1008,19 @@ const StockExcel = ({
}); });
const buffer = await workbook.xlsx.writeBuffer(); const buffer = await workbook.xlsx.writeBuffer();
const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});
const filename = `PurchaseEntry_${supplierDisplayName}_${Date.now()}.xlsx`; const filename = `PurchaseEntry_${supplierDisplayName}_${Date.now()}.xlsx`;
const link = document.createElement('a');
link.href = URL.createObjectURL(blob); downloadFile(
link.download = filename; buffer,
link.click(); filename,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
(success) => {
if (!success) {
setMessageType('error');
setMessageData('Failed to download the file. Please try again.');
}
}
);
setSupplierProducts([]); setSupplierProducts([]);
setSelectedSupplierData(null); setSelectedSupplierData(null);
@ -1332,7 +1338,7 @@ const StockExcel = ({
...record, ...record,
...values, ...values,
}); });
} catch (errInfo) {} } catch (errInfo) { }
}; };
let childNode = children; let childNode = children;

View File

@ -60,6 +60,7 @@ import {
getCommonAppPreference, getCommonAppPreference,
} from '../../Features/BrachLogin/BranchLogin.js'; } from '../../Features/BrachLogin/BranchLogin.js';
import { IoClose } from 'react-icons/io5'; import { IoClose } from 'react-icons/io5';
import { downloadFile } from '../../utils/downloadFile.js';
const StockPriceUpdate = () => { const StockPriceUpdate = () => {
const { SadminuserAccess } = useAuth(); const { SadminuserAccess } = useAuth();
@ -322,7 +323,7 @@ const StockPriceUpdate = () => {
); );
excelDataRef.current excelDataRef.current
?.validateFields([`NewSellPrice${record.localId}`]) ?.validateFields([`NewSellPrice${record.localId}`])
.catch(() => {}); .catch(() => { });
} }
}} }}
/> />
@ -1713,14 +1714,19 @@ const StockPriceUpdate = () => {
/* ---------------- DOWNLOAD ---------------- */ /* ---------------- DOWNLOAD ---------------- */
const buffer = await workbook.xlsx.writeBuffer(); const buffer = await workbook.xlsx.writeBuffer();
const blob = new Blob([buffer], { downloadFile(
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', buffer,
}); "PriceChange_Data.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
const link = document.createElement('a'); (success) => {
link.href = URL.createObjectURL(blob); if (success) {
link.download = 'PriceChange_Data.xlsx'; console.log("Template downloaded successfully!");
link.click(); } else {
setMessageType('error');
setMessageData('Failed to download the template. Please try again.');
}
}
)
setExportLoading(false); setExportLoading(false);
}; };
@ -2395,7 +2401,7 @@ const StockPriceUpdate = () => {
<div <div
className={`export-excel-div ${exportLoading ? 'is-loading' : ''}`} className={`export-excel-div ${exportLoading ? 'is-loading' : ''}`}
onClick={ onClick={
exportLoading ? () => {} : () => showPriceChangeModal() exportLoading ? () => { } : () => showPriceChangeModal()
} }
> >
<div> <div>

View File

@ -7,6 +7,7 @@ import { RiFileExcel2Fill } from 'react-icons/ri';
import { Messages } from '../../Components/Notifications/Messages.jsx'; import { Messages } from '../../Components/Notifications/Messages.jsx';
import { getSession } from '../../Services/Others.js'; import { getSession } from '../../Services/Others.js';
import './OpeningStockExcel.scss'; import './OpeningStockExcel.scss';
import { downloadFile } from '../../utils/downloadFile.js';
const TEMPLATE_HEADERS = [ const TEMPLATE_HEADERS = [
{ key: 'ProdName', header: 'Product Name' }, { key: 'ProdName', header: 'Product Name' },
@ -203,15 +204,20 @@ const OpeningStockExcel = ({ products = [], onApply, onCancel }) => {
} }
const buffer = await workbook.xlsx.writeBuffer(); const buffer = await workbook.xlsx.writeBuffer();
const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});
const link = document.createElement('a'); downloadFile(
link.href = URL.createObjectURL(blob); buffer,
link.download = 'opening_stock_template.xlsx'; "opening_stock_template.xlsx",
link.click(); "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
URL.revokeObjectURL(link.href); (success) => {
if (success) {
console.log("Template downloaded successfully!");
} else {
setMessageType('error');
setMessageData('Failed to download the template. Please try again.');
}
}
)
} catch (error) { } catch (error) {
console.error('Template download failed:', error); console.error('Template download failed:', error);
setMessageType('error'); setMessageType('error');

62
src/utils/downloadFile.js Normal file
View File

@ -0,0 +1,62 @@
import { Capacitor } from "@capacitor/core";
import { Filesystem, Directory } from "@capacitor/filesystem";
import { FileOpener } from "@capacitor-community/file-opener";
/**
* Download and open a file (Excel, PDF, etc.)
* @param {ArrayBuffer | Blob} buffer - File data
* @param {string} filename - File name with extension
* @param {string} mimeType - File MIME type (example: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
* @param {Function} onSuccess - Optional callback, called with true/false
*/
export const downloadFile = async (buffer, filename, mimeType, onSuccess) => {
try {
const isWeb = Capacitor.getPlatform() === "web";
// 🌐 Web download
if (isWeb) {
const blob = buffer instanceof Blob ? buffer : new Blob([buffer], { type: mimeType });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
URL.revokeObjectURL(link.href);
onSuccess?.(true);
return;
}
// 📱 Mobile (Android / iOS)
// Convert ArrayBuffer → Base64
let binary = "";
const bytes = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; i++) {
binary += String.fromCharCode(bytes[i]);
}
const base64Data = btoa(binary);
// Save file inside app's Documents folder
const savedFile = await Filesystem.writeFile({
path: filename,
data: base64Data,
directory: Directory.Data, // ← was Directory.Documents
recursive: true,
});
// FileOpener requires removing "file://"
await FileOpener.open({
filePath: savedFile.uri, // ← was savedFile.uri.replace("file://", "")
contentType: mimeType,
});
onSuccess?.(true);
} catch (err) {
console.error("File download/open error:", err);
onSuccess?.(false);
}
};

View File

@ -7,7 +7,7 @@ export default defineConfig(({ mode }) => {
return { return {
plugins: [react()], plugins: [react()],
base: isProd ? "/apps/retail/" : "/", base: isProd ? "/apps/retail/" : "/", //for capcitor base: isProd ? "/" : "/",
envDir: "src", envDir: "src",
envPrefix: "ENV_", envPrefix: "ENV_",