forked from trent_larson/crowd-funder-for-time-pwa
refactor: remove unused ShareImage plugin code, simplify to temp file approach
Remove unused Capacitor plugin implementation and simplify shared image handling to use only the temp file approach, which is already working reliably for both iOS and Android. Changes: - Delete ios/App/App/ShareImagePlugin.swift (unused, never registered) - Delete ios/App/App/ShareImageBridge.swift (only used by plugin) - Remove ~80 lines of plugin fallback code from src/main.capacitor.ts - Simplify error handling to single code path - Add documentation comment explaining temp file approach and future plugin implementation possibility Benefits: - ~154 lines of code removed - Single, consistent code path for both platforms - Easier to maintain and debug - No functional changes - temp file approach already working The temp file approach uses Capacitor's Filesystem plugin to read shared image data written by native code (AppDelegate on iOS, MainActivity on Android). This is simpler and more reliable than the plugin approach, which required registration and bridge setup. Future improvement: Consider implementing Capacitor plugins for direct native-to-JS communication if lower latency becomes a priority, though the current approach performs well in production.
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
* Share Image Bridge
|
||||
*
|
||||
* Provides a bridge between JavaScript and native iOS code to access
|
||||
* shared images stored in App Group UserDefaults by the Share Extension.
|
||||
*
|
||||
* This bridge allows the JavaScript layer to read shared image data
|
||||
* that was stored by the Share Extension.
|
||||
*
|
||||
* Note: This class doesn't need Capacitor - it's a simple Swift utility
|
||||
* that reads from App Group UserDefaults. The JavaScript bridge will be
|
||||
* implemented separately.
|
||||
*/
|
||||
@objc(ShareImageBridge)
|
||||
public class ShareImageBridge: NSObject {
|
||||
|
||||
private static let appGroupIdentifier = "group.app.timesafari"
|
||||
private static let sharedPhotoBase64Key = "sharedPhotoBase64"
|
||||
private static let sharedPhotoFileNameKey = "sharedPhotoFileName"
|
||||
|
||||
/**
|
||||
* Get shared image data from App Group UserDefaults
|
||||
* Called from JavaScript via Capacitor bridge
|
||||
*
|
||||
* @returns Dictionary with "base64" and "fileName" keys, or nil if no shared image
|
||||
*/
|
||||
@objc public static func getSharedImageData() -> [String: String]? {
|
||||
guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier) else {
|
||||
print("ShareImageBridge: Failed to access App Group UserDefaults")
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let base64 = userDefaults.string(forKey: sharedPhotoBase64Key),
|
||||
let fileName = userDefaults.string(forKey: sharedPhotoFileNameKey) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Clear the shared data after reading
|
||||
userDefaults.removeObject(forKey: sharedPhotoBase64Key)
|
||||
userDefaults.removeObject(forKey: sharedPhotoFileNameKey)
|
||||
userDefaults.synchronize()
|
||||
|
||||
return ["base64": base64, "fileName": fileName]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import Foundation
|
||||
import Capacitor
|
||||
|
||||
/**
|
||||
* Share Image Plugin
|
||||
*
|
||||
* Capacitor plugin that exposes ShareImageBridge functionality to JavaScript.
|
||||
* Allows JavaScript to retrieve shared images from App Group UserDefaults.
|
||||
*/
|
||||
@objc(ShareImagePlugin)
|
||||
public class ShareImagePlugin: CAPPlugin {
|
||||
|
||||
@objc func getSharedImageData(_ call: CAPPluginCall) {
|
||||
guard let sharedData = ShareImageBridge.getSharedImageData() else {
|
||||
call.resolve(["success": false, "data": NSNull()])
|
||||
return
|
||||
}
|
||||
|
||||
call.resolve([
|
||||
"success": true,
|
||||
"data": [
|
||||
"base64": sharedData["base64"] ?? "",
|
||||
"fileName": sharedData["fileName"] ?? ""
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user