refactor(platform): replace platform checks with capability-based system

- Add PlatformCapabilities interface to define available features
- Remove isWeb(), isCapacitor(), isElectron(), isPyWebView() methods
- Update platform services to implement getCapabilities()
- Refactor DataExportSection to use capability checks instead of platform checks
- Improve platform abstraction and separation of concerns
- Make platform-specific logic more maintainable and extensible

This change decouples components from specific platform implementations,
making the codebase more maintainable and easier to extend with new platforms.
This commit is contained in:
Matthew Raymer
2025-04-08 11:29:39 +00:00
parent c8eff4d39e
commit d03fa55001
9 changed files with 106 additions and 153 deletions

View File

@@ -1,4 +1,4 @@
import { ImageResult, PlatformService } from "../PlatformService";
import { ImageResult, PlatformService, PlatformCapabilities } from "../PlatformService";
import { logger } from "../../utils/logger";
/**
@@ -15,6 +15,21 @@ import { logger } from "../../utils/logger";
* - Python-JavaScript bridge functionality
*/
export class PyWebViewPlatformService implements PlatformService {
/**
* Gets the capabilities of the PyWebView platform
* @returns Platform capabilities object
*/
getCapabilities(): PlatformCapabilities {
return {
hasFileSystem: false, // Not implemented yet
hasCamera: false, // Not implemented yet
isMobile: false,
isIOS: false,
hasFileDownload: false, // Not implemented yet
needsFileHandlingInstructions: false
};
}
/**
* Reads a file using the Python backend.
* @param _path - Path to the file to read
@@ -80,38 +95,6 @@ export class PyWebViewPlatformService implements PlatformService {
throw new Error("Not implemented");
}
/**
* Checks if running on Capacitor platform.
* @returns false, as this is not Capacitor
*/
isCapacitor(): boolean {
return false;
}
/**
* Checks if running on Electron platform.
* @returns false, as this is not Electron
*/
isElectron(): boolean {
return false;
}
/**
* Checks if running on PyWebView platform.
* @returns true, as this is the PyWebView implementation
*/
isPyWebView(): boolean {
return true;
}
/**
* Checks if running on web platform.
* @returns false, as this is not web
*/
isWeb(): boolean {
return false;
}
/**
* Should handle deep link URLs through the Python backend.
* @param _url - The deep link URL to handle