Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: tmbs on app documents location

Ilian Sapundshievfaccb811239d
diff --git a/capacitor/ios/App/App.xcodeproj/project.pbxproj b/capacitor/ios/App/App.xcodeproj/project.pbxproj
index 4509dbd62..aec310285 100644
--- a/capacitor/ios/App/App.xcodeproj/project.pbxproj
+++ b/capacitor/ios/App/App.xcodeproj/project.pbxproj
@@ -319,7 +319,7 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 10254;
+ CURRENT_PROJECT_VERSION = 10255;
DEVELOPMENT_TEAM = DLK22E2679;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
@@ -345,7 +345,7 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 10254;
+ CURRENT_PROJECT_VERSION = 10255;
DEVELOPMENT_TEAM = DLK22E2679;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index 0a88c3c2f..21e714022 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -1207,12 +1207,24 @@ export const IOActionsContextProvider = ({
};
}
fsEntries.push(fsEntry);
+ // Insert the imported file into the current directory listing.
+ // Unlike the Electron path (uploadFiles → setReflectActions),
+ // this Capacitor/web FileReader path previously only triggered
+ // thumbnail generation for *existing* entries, so freshly
+ // imported files were written to disk but never appeared until a
+ // manual reload — making import look broken (notably on the iOS
+ // App Documents location at "/").
+ setReflectActions({
+ action: 'add',
+ entry: fsEntry,
+ open: false,
+ source: 'upload',
+ });
showNotification(
'File ' + fileTargetPath + ' successfully imported.',
'default',
true,
);
- // dispatch(AppActions.reflectCreateEntry(fileTargetPath, true));
}
} catch (error) {
console.log(
diff --git a/src/renderer/services/io-capacitor.ts b/src/renderer/services/io-capacitor.ts
index 9ad1eefa8..dc003db7c 100644
--- a/src/renderer/services/io-capacitor.ts
+++ b/src/renderer/services/io-capacitor.ts
@@ -64,6 +64,36 @@ let loadedSettingsTags;
// --- Platform helpers ---
+/**
+ * Build a WebView-loadable URL (https://localhost/_capacitor_file_/… on Android,
+ * capacitor://… on iOS) for a location-relative path. Asks the Filesystem plugin
+ * for the exact native uri (so the iOS App Documents location, whose path is "/",
+ * resolves to the real Documents directory rather than the non-existent device
+ * root) and converts it for the WebView. Async because getUri is async; used by
+ * thumbnail URL resolution.
+ */
+function getNativeFileUrlAsync(path) {
+ if (!path) return Promise.resolve('');
+ if (!Capacitor || !Capacitor.convertFileSrc) return Promise.resolve(path);
+
+ const { path: rel, directory } = resolveCapacitorPath(path);
+
+ // iCloud / raw absolute paths already resolved to an encoded file:// path.
+ if (!directory) {
+ const abs = rel.startsWith('file://') ? rel.substring(7) : rel;
+ return Promise.resolve(Capacitor.convertFileSrc('file://' + abs));
+ }
+
+ return Filesystem.getUri({ directory, path: !rel || rel === '.' ? '' : rel })
+ .then(({ uri }) => Capacitor.convertFileSrc(uri))
+ .catch(() => {
+ // getUri failed — best-effort: treat the path as absolute (works on
+ // Android via the /sdcard symlink).
+ const filePath = path.startsWith('/') ? path : '/' + path;
+ return Capacitor.convertFileSrc('file://' + filePath);
+ });
+}
+
/**
* Determine the Capacitor Directory enum value and relative path from an absolute path.
* On Android with MANAGE_EXTERNAL_STORAGE, we work with absolute paths via ExternalStorage.
@@ -412,10 +442,15 @@ function listMetaDirectoryPromise(path) {
.then((result) => {
if (result && result.files) {
result.files.forEach((file) => {
- const entryPath = metaDirPath + file.name;
const ee = {};
ee.name = file.name;
- ee.path = entryPath;
+ // Return the bare filename in `path` to match the Electron/Node
+ // listMetaDirectoryPromise contract. Renderer consumers compare with
+ // `relativeThumb/MetaPath.endsWith(metaFile.path)` — a full path like
+ // "/.ts/<name>" is longer than the relative path and never matches,
+ // which silently broke file thumbnails (folder thumbs have separate
+ // logic). Callers that need to read the file rebuild the full path.
+ ee.path = file.name;
ee.isFile = file.type === 'file';
entries.push(ee);
});
@@ -469,6 +504,15 @@ function listDirectoryPromise(param, mode = ['extractThumbPath']) {
eentry.lmdt = file.mtime ? new Date(file.mtime).getTime() : 0;
}
+ // Attach a WebView-loadable URL from the real native uri returned by
+ // readdir. Location-relative paths (e.g. the iOS App Documents
+ // location stores path "/") can't be turned into a file:// URL by
+ // string manipulation alone — the plugin already resolved the
+ // absolute sandbox path, so use it directly.
+ if (file.uri && Capacitor.convertFileSrc) {
+ eentry.url = Capacitor.convertFileSrc(file.uri);
+ }
+
if (mode.includes('extractThumbPath')) {
if (!eentry.isFile) {
// Read tsm.json from subfolders
@@ -487,8 +531,17 @@ function listDirectoryPromise(param, mode = ['extractThumbPath']) {
const metaFileAvailable = metaContent.find(
(obj) => obj.name === file.name + AppConfig.metaFileExt,
);
- if (metaFileAvailable && metaFileAvailable.path) {
- metaPromises.push(getEntryMeta(eentry, metaFileAvailable.path));
+ if (metaFileAvailable) {
+ // metaContent carries bare filenames in `path`, so rebuild the
+ // full meta path (<dir>/.ts/<name>) for getEntryMeta to read.
+ const metaDir =
+ cleanTrailingDirSeparator(path) +
+ AppConfig.dirSeparator +
+ AppConfig.metaFolder +
+ AppConfig.dirSeparator;
+ metaPromises.push(
+ getEntryMeta(eentry, metaDir + metaFileAvailable.name),
+ );
}
}
}
@@ -556,6 +609,12 @@ function getPropertiesPromise(param) {
lmdt: stat.mtime ? new Date(stat.mtime).getTime() : 0,
isFile: stat.type === 'file',
name: extractFileName(path, '/'),
+ // Real native uri (e.g. file:///var/mobile/.../Documents/IMG.jpeg) turned
+ // into a WebView-loadable URL — used by the viewer for opened files.
+ ...(stat.uri &&
+ Capacitor.convertFileSrc && {
+ url: Capacitor.convertFileSrc(stat.uri),
+ }),
};
})
.catch((err) => {
@@ -1318,4 +1377,5 @@ export {
focusWindow,
shareFiles,
downloadFile,
+ getNativeFileUrlAsync,
};
diff --git a/src/renderer/utils/CommonLocation.ts b/src/renderer/utils/CommonLocation.ts
index 036cb0f4d..9136cc900 100644
--- a/src/renderer/utils/CommonLocation.ts
+++ b/src/renderer/utils/CommonLocation.ts
@@ -317,6 +317,19 @@ export class CommonLocation implements TS.Location {
return this.getURLforPathInt(thumbPath, expirationInSeconds);
}
+ // Capacitor: resolve the thumbnail's real native uri (Filesystem.getUri)
+ // rather than string-building a file:// URL. The iOS App Documents location
+ // stores path "/", so a naive file:///.ts/<name>.jpg points at the device
+ // root and the thumb never loads.
+ if (AppConfig.isCapacitor) {
+ const ioAPI = require('-/services/io-capacitor');
+ if (ioAPI.getNativeFileUrlAsync) {
+ return ioAPI
+ .getNativeFileUrlAsync(thumbPath)
+ .then((u: string) => (u ? u + (dt ? '?' + dt : '') : undefined));
+ }
+ }
+
const normalizedUrl = this.normalizeUrl(thumbPath) + (dt ? '?' + dt : '');
return Promise.resolve(normalizedUrl);
};