From 542892cb7bafb78cc83835372f297bf20c4cf415 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Tue, 14 Jan 2025 20:31:25 -0500 Subject: [PATCH] Fix polyfill --- src/tauri_polyfill.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/tauri_polyfill.js b/src/tauri_polyfill.js index d02d9e5..c145a4e 100644 --- a/src/tauri_polyfill.js +++ b/src/tauri_polyfill.js @@ -52,7 +52,22 @@ if (!window.__TAURI__) { invoke: () => {} }, fs: { - writeFile: () => {}, + writeFile: () => { + // Create a Blob from the contents + const blob = new Blob([contents]); + const link = document.createElement('a'); + const url = URL.createObjectURL(blob); + + link.href = url; + link.download = path; // Use the file name from the path + + document.body.appendChild(link); + link.click(); + + // Clean up by removing the link and revoking the object URL + document.body.removeChild(link); + URL.revokeObjectURL(url); + }, readFile: () => {}, writeTextFile: async (path, contents) => { // Create a Blob from the contents @@ -176,9 +191,9 @@ if (!window.__TAURI__) { confirm: () => {}, }, path: { - documentDir: () => {}, + documentDir: () => "/Documents", join: (...segments) => { - return segments.filter(segment => segment.length > 0) // Remove empty strings + return segments.filter(segment => (segment && segment.length > 0)) // Remove empty strings .join('/') }, basename: (path) => {