diff --git a/packages/jsActions/nanoflow-actions-native/CHANGELOG.md b/packages/jsActions/nanoflow-actions-native/CHANGELOG.md index c9c6071cb..a81f7555e 100644 --- a/packages/jsActions/nanoflow-actions-native/CHANGELOG.md +++ b/packages/jsActions/nanoflow-actions-native/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +- Added a "Download web file" nanoflow action that triggers file download for web applications. +- Changed a caption for the existing "Download file" action to "Download native file". - We've migrated from using @react-native-community/geolocation to react-native-permissions for handling location permissions. ## [6.1.1] Nanoflow Commons - 2025-10-7 diff --git a/packages/jsActions/nanoflow-actions-native/src/client/DownloadWebFile.ts b/packages/jsActions/nanoflow-actions-native/src/client/DownloadWebFile.ts new file mode 100644 index 000000000..c6dcef98c --- /dev/null +++ b/packages/jsActions/nanoflow-actions-native/src/client/DownloadWebFile.ts @@ -0,0 +1,37 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. + +// BEGIN EXTRA CODE +// END EXTRA CODE + +/** + * @param {MxObject} file - File object which will be downloaded. + * @param {boolean} showFileInBrowser - Set to True to let the browser open the file in a new tab. + * Set to False if the file only needs to be downloaded to the device storage. + * @returns {Promise.} + */ +export async function DownloadWebFile(file?: mendix.lib.MxObject, showFileInBrowser?: boolean): Promise { + // BEGIN USER CODE + if (!file) { + return Promise.reject(new Error("Input parameter 'file' is required")); + } + + const target = showFileInBrowser ? "window" : "internal"; + + return new Promise((resolve, reject) => { + mx.ui + .downloadFile({ + mxobject: file, + target, + error: (err: Error) => reject(err) + }) + .then(resolve) + .catch(reject); + }); + // END USER CODE +} diff --git a/packages/jsActions/nanoflow-actions-native/typings/mx.d.ts b/packages/jsActions/nanoflow-actions-native/typings/mx.d.ts index 3b4f6acf8..06628a147 100644 --- a/packages/jsActions/nanoflow-actions-native/typings/mx.d.ts +++ b/packages/jsActions/nanoflow-actions-native/typings/mx.d.ts @@ -2,6 +2,11 @@ declare namespace mx { interface ui { toggleSidebar: () => void; + downloadFile: (args: { + mxobject: mendix.lib.MxObject; + target: "window" | "internal"; + error?: (err: Error) => void; + }) => Promise; } interface data { update: (param: { guid?: string | undefined; entity?: string | undefined; callback?: () => void }) => void;