TagSpaces is an offline, open source, document manager with tagging support
fix: exporting files on mobile devices, enabling multiple downloading as well
Ilian Sapundshiev34b7df0fba36
diff --git a/src/renderer/components/FileUploadContainer.tsx b/src/renderer/components/FileUploadContainer.tsxindex e1b9c6f52..2826cab16 100644--- a/src/renderer/components/FileUploadContainer.tsx+++ b/src/renderer/components/FileUploadContainer.tsx@@ -68,42 +68,10 @@ const FileUploadContainer = forwardRef(},onFileUpload(dirPath: string) {directoryPath.current = dirPath;- /* if (AppConfig.isCordovaAndroid) {- PlatformIO.selectFileDialog()- .then(file => {- console.log('file', file.uri);- return [file.uri];- })- .then(arrFiles => {- props- .uploadFiles(- arrFiles,- props.directoryPath,- props.onUploadProgress- )- .then(fsEntries => {- props.reflectCreateEntries(fsEntries);- return true;- })- .catch(error => {- console.log('uploadFiles', error);- });- props.toggleUploadDialog();- return true;- })- .catch(error => {- console.log('uploadFiles', error);- });- } else { */fileInput.current.click();- // }},}));- /* if (AppConfig.isCordovaAndroid) {- return null;- } */-const fileInput = useRef<HTMLInputElement>(null);function handleFileInputChange(selection: ChangeEvent<HTMLInputElement>) {diff --git a/src/renderer/components/menus/TagLibraryMenu.tsx b/src/renderer/components/menus/TagLibraryMenu.tsxindex 6567d1bec..562818245 100644--- a/src/renderer/components/menus/TagLibraryMenu.tsx+++ b/src/renderer/components/menus/TagLibraryMenu.tsx@@ -16,7 +16,6 @@**/-import AppConfig from '-/AppConfig';import {CreateFileIcon,ExportIcon,@@ -131,14 +130,12 @@ function TagLibraryMenu(props: Props) {</ListItemIcon><ListItemText primary={t('core:importTags')} /></MenuItem>- {!AppConfig.isCordovaAndroid && !AppConfig.isCapacitorAndroid && (- <MenuItem data-tid="exportTagGroup" onClick={handleExportTagGroup}>- <ListItemIcon>- <ExportIcon />- </ListItemIcon>- <ListItemText primary={t('core:exportTagGroupsButton')} />- </MenuItem>- )}+ <MenuItem data-tid="exportTagGroup" onClick={handleExportTagGroup}>+ <ListItemIcon>+ <ExportIcon />+ </ListItemIcon>+ <ListItemText primary={t('core:exportTagGroupsButton')} />+ </MenuItem><MenuItemdata-tid="taglibraryHelp"onClick={() => {diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.jsonindex 4951063e6..e81cbcb76 100644--- a/src/renderer/locales/en/core.json+++ b/src/renderer/locales/en/core.json@@ -618,6 +618,9 @@"duplicateTitle": "Search name already exist!","savedSearchesTitle": "Stored Search Queries","exportCsv": "Export current file and folder list as CSV file",+ "exportInProgress": "Exporting CSV…",+ "exportSuccessful": "CSV export saved",+ "exportError": "Export failed: {{message}}","lat": "Latitude","lng": "Longitude","coordinatesTitleHelper": "Invalid coordinate (supported 40.123 or 40° 7.38’)",diff --git a/src/renderer/perspectives/grid/components/MainContainer.tsx b/src/renderer/perspectives/grid/components/MainContainer.tsxindex 9b10f0a92..e807513ec 100644--- a/src/renderer/perspectives/grid/components/MainContainer.tsx+++ b/src/renderer/perspectives/grid/components/MainContainer.tsx@@ -44,10 +44,12 @@ import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';import { openURLExternally } from '-/services/utils-io';import { TS } from '-/tagspaces.namespace';import useFirstRender from '-/utils/useFirstRender';+import AppConfig from '-/AppConfig';import { Box } from '@mui/material';import Links from 'assets/links';import React, { useCallback, useEffect, useRef, useState } from 'react';import { GlobalHotKeys } from 'react-hotkeys';+import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';import GridCell from './GridCell';@@ -62,6 +64,7 @@ function GridPerspective(props: Props) {const { openEntry, openPrevFile, openNextFile, openedEntry, fileChanged } =useOpenedEntryContext();const { showNotification } = useNotificationContext();+ const { t } = useTranslation();const { actions } = usePerspectiveActionsContext();const { showDirectories } = usePerspectiveSettingsContext();const { currentLocation } = useCurrentLocationContext();@@ -137,10 +140,36 @@ function GridPerspective(props: Props) {const handleExportCsvMenu = () => {if (Pro) {- if (selectedEntries && selectedEntries.length > 0) {- Pro.exportAsCsv.ExportAsCsv(selectedEntries);- } else {- Pro.exportAsCsv.ExportAsCsv(sortedDirContent);+ const entries =+ selectedEntries && selectedEntries.length > 0+ ? selectedEntries+ : sortedDirContent;+ const result = Pro.exportAsCsv.ExportAsCsv(entries);+ // On native mobile the export is written via the filesystem (no browser+ // download), so confirm start/completion explicitly — otherwise the tap+ // looks like a no-op. On web/electron the browser download is feedback.+ if (+ AppConfig.isNativeMobile &&+ result &&+ typeof result.then === 'function'+ ) {+ showNotification(t('core:exportInProgress'));+ result+ .then((res: { path?: string; shared?: boolean }) => {+ // iOS routes through the share sheet (res.shared) — the share UI is+ // the confirmation, so only toast on the Android Download-folder save.+ if (!res?.shared) {+ showNotification(t('core:exportSuccessful'));+ }+ return true;+ })+ .catch((e: any) => {+ showNotification(+ t('core:exportError', { message: e?.message || e }),+ 'error',+ true,+ );+ });}}};diff --git a/src/renderer/perspectives/grid/components/MainToolbar.tsx b/src/renderer/perspectives/grid/components/MainToolbar.tsxindex f634a8b37..40469cbd4 100644--- a/src/renderer/perspectives/grid/components/MainToolbar.tsx+++ b/src/renderer/perspectives/grid/components/MainToolbar.tsx@@ -42,6 +42,7 @@ import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';+import { useIOActionsContext } from '-/hooks/useIOActionsContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';@@ -51,7 +52,6 @@ import { Pro } from '-/pro';import { getKeyBindingObject, isHideProFeatures } from '-/reducers/settings';import { Box, Divider, Toolbar } from '@mui/material';import { alpha, useTheme } from '@mui/material/styles';-import { saveAs } from 'file-saver';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';@@ -90,6 +90,7 @@ function MainToolbar(props: Props) {const { loadParentDirectoryContent, currentDirectoryPath } =useDirectoryContentContext();const { selectedEntries } = useSelectedEntriesContext();+ const { downloadFsEntry } = useIOActionsContext();const keyBindings = useSelector(getKeyBindingObject);const hideProFeatures: boolean = useSelector(isHideProFeatures);const { currentLocation } = useCurrentLocationContext();@@ -105,28 +106,21 @@ function MainToolbar(props: Props) {}function multipleDownload() {+ // downloadFsEntry handles every backend (object-store signed URLs,+ // encrypted blobs, plain URLs) and every platform: web/electron via an+ // <a download> anchor, native mobile via @capacitor/filesystem (Android →+ // public Download/ folder, iOS → Cache + share sheet). It also surfaces+ // start/completion notifications on mobile.selectedEntries?.forEach((entry) => {if (entry.isFile) {- const cleanedPath = entry.path.startsWith('/')- ? entry.path.substr(1)- : entry.path;- currentLocation- ?.generateURLforPath(cleanedPath, 900)- .then((url) => fetch(url))- .then((res) => res.blob()) // Gets the response and returns it as a blob- .then((blob) => {- saveAs(blob, entry.name);- });+ downloadFsEntry(entry);}});}const showDownloadButton =- AppConfig.isWeb &&selectedEntries?.length > 0 &&- // (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) &&- !AppConfig.isCordovaAndroid &&- !AppConfig.isCapacitorAndroid; // saveAs do not work on Android+ (AppConfig.isWeb || AppConfig.isNativeMobile);const folderSettingsAvailable = haveLocalSetting();@@ -290,9 +284,7 @@ function MainToolbar(props: Props) {</TsToolbarButton>)}{!hideProFeatures &&- Pro &&- !AppConfig.isCordovaAndroid &&- !AppConfig.isCapacitorAndroid && ( // SaveAs do not work on Android+ Pro && ( // SaveAs do not work on Android<TsToolbarButtontooltip={t('core:exportCsv')}title={t('core:startExportButton')}diff --git a/src/renderer/services/export-import-utils.ts b/src/renderer/services/export-import-utils.tsindex c327ac655..fdb193ae1 100644--- a/src/renderer/services/export-import-utils.ts+++ b/src/renderer/services/export-import-utils.ts@@ -109,7 +109,10 @@ export async function downloadEnvelope(): Promise<void> {const { blob, ext } = await serializeEnvelope(env, aesPassword);const dateTimeTag = formatDateTime4Tag(new Date(), true);- saveAsTextFile(blob, `tagspaces-export [${dateTimeTag}]${ext}`);+ // On native mobile saveAsTextFile returns a promise (native write + share);+ // await it so the caller's "successfully exported" notification only fires+ // once the file is actually persisted. On desktop/web it resolves to void.+ await saveAsTextFile(blob, `tagspaces-export [${dateTimeTag}]${ext}`);}export function readImportFile(diff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.tsindex 47b6fb58d..6e85051ea 100644--- a/src/renderer/services/utils-io.ts+++ b/src/renderer/services/utils-io.ts@@ -291,7 +291,22 @@ export function getPrevFile(}export function saveAsTextFile(blob: any, filename: string) {+ if (AppConfig.isCapacitor) {+ // file-saver triggers a download via an <a download> + blob: URL click.+ // That does nothing inside the Capacitor WebView (there is no Downloads+ // mechanism, and iOS WKWebView blocks blob downloads), so exports silently+ // failed on Android/iOS. Route through the native filesystem instead:+ // downloadFile() fetches the blob: URL and writes the bytes via+ // @capacitor/filesystem — Android into the public Download/ folder, iOS+ // into Cache followed by the share sheet ("Save to Files", AirDrop, …).+ const ioAPI = require('-/services/io-capacitor');+ const url = URL.createObjectURL(blob);+ return ioAPI+ .downloadFile(filename, url)+ .finally(() => URL.revokeObjectURL(url));+ }saveAs(blob, filename);+ return Promise.resolve({ path: filename, shared: false });}export function isFulfilled<T>(