Browse Source

feat(capacitor): implement storage permission checks for file operations

- Add permission checks before writeFile and writeAndShareFile operations
- Reuse existing checkStoragePermissions method for Android devices
- Maintain iOS-specific handling (early return for iOS permission model)
- Improve error handling and logging for permission-related issues

This change ensures proper storage permission handling on Android devices
while maintaining the existing iOS behavior. The permission checks run
before any file write operations, providing better error handling and
user experience.
pull/137/head
Matthew Raymer 2 weeks ago
parent
commit
07ac340733
  1. 6
      src/services/platforms/CapacitorPlatformService.ts

6
src/services/platforms/CapacitorPlatformService.ts

@ -358,6 +358,9 @@ export class CapacitorPlatformService implements PlatformService {
*/ */
async writeFile(fileName: string, content: string): Promise<void> { async writeFile(fileName: string, content: string): Promise<void> {
try { try {
// Check storage permissions before proceeding
await this.checkStoragePermissions();
const logData = { const logData = {
targetFileName: fileName, targetFileName: fileName,
contentLength: content.length, contentLength: content.length,
@ -499,6 +502,9 @@ export class CapacitorPlatformService implements PlatformService {
logger.log("[CapacitorPlatformService]", JSON.stringify(logData, null, 2)); logger.log("[CapacitorPlatformService]", JSON.stringify(logData, null, 2));
try { try {
// Check storage permissions before proceeding
await this.checkStoragePermissions();
const { uri } = await Filesystem.writeFile({ const { uri } = await Filesystem.writeFile({
path: fileName, path: fileName,
data: content, data: content,

Loading…
Cancel
Save