Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Trim slop comments from the cast app

Manav Rathi524f5a51e925
diff --git a/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift b/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift
index 9c6a76dc0d..231f8c6403 100644
--- a/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift
+++ b/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift
@@ -159,7 +159,6 @@ class RealCastPairingService {
}
- // Decrypt the payload using our private key
let payload = try await decryptPayload(
encryptedData: encryptedData,
publicKey: device.publicKey,
diff --git a/mobile/native/apple/apps/cast/Cast/Services/FileCache.swift b/mobile/native/apple/apps/cast/Cast/Services/FileCache.swift
index 98f52a0d65..a108fb2046 100644
--- a/mobile/native/apple/apps/cast/Cast/Services/FileCache.swift
+++ b/mobile/native/apple/apps/cast/Cast/Services/FileCache.swift
@@ -15,7 +15,6 @@ actor ThreadSafeFileCache {
self.maxBytes = maxBytes
self.shrinkTargetBytes = shrinkTargetBytes
- // Create persistent cache directory
let documentsPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
self.cacheDirectory = documentsPath.appendingPathComponent("EnteFileCache")
self.metadataURL = cacheDirectory.appendingPathComponent("cache_metadata.json")
@@ -23,17 +22,14 @@ actor ThreadSafeFileCache {
// Create cache directory if it doesn't exist
try? FileManager.default.createDirectory(at: cacheDirectory, withIntermediateDirectories: true)
- // Load existing cache from disk
loadCacheFromDisk()
}
func get(_ fileID: Int) -> Data? {
- // Check memory cache first
if let data = cache[fileID] {
return data
}
- // Check disk cache
let fileURL = cacheDirectory.appendingPathComponent("\(fileID).cache")
if let data = try? Data(contentsOf: fileURL) {
// Load into memory cache for faster future access
@@ -49,25 +45,20 @@ actor ThreadSafeFileCache {
}
func set(_ fileID: Int, data: Data) {
- // Remove existing data if present
if let existingData = cache[fileID] {
totalBytes -= existingData.count
cacheOrder.removeAll { $0 == fileID }
}
- // Add new data to memory cache
cache[fileID] = data
cacheOrder.append(fileID)
totalBytes += data.count
- // Save to disk cache
let fileURL = cacheDirectory.appendingPathComponent("\(fileID).cache")
try? data.write(to: fileURL)
- // Enforce limits
enforceLimits()
- // Save metadata
saveCacheMetadata()
print("Cached file \(fileID) content (\(data.count) bytes) - Cache size: \(cache.count) files")
@@ -78,11 +69,9 @@ actor ThreadSafeFileCache {
totalBytes -= removedData.count
cacheOrder.removeAll { $0 == fileID }
- // Remove from disk cache
let fileURL = cacheDirectory.appendingPathComponent("\(fileID).cache")
try? FileManager.default.removeItem(at: fileURL)
- // Save updated metadata
saveCacheMetadata()
print("Removed cached content for file \(fileID) (\(removedData.count) bytes)")
@@ -95,11 +84,9 @@ actor ThreadSafeFileCache {
cacheOrder.removeAll()
totalBytes = 0
- // Clear disk cache
try? FileManager.default.removeItem(at: cacheDirectory)
try? FileManager.default.createDirectory(at: cacheDirectory, withIntermediateDirectories: true)
- // Clear metadata
try? FileManager.default.removeItem(at: metadataURL)
print("Cleared file content cache (\(clearedCount) files)")
@@ -122,7 +109,6 @@ actor ThreadSafeFileCache {
if let data = cache.removeValue(forKey: oldest) {
removedBytes += data.count
- // Remove from disk cache
let fileURL = cacheDirectory.appendingPathComponent("\(oldest).cache")
try? FileManager.default.removeItem(at: fileURL)
@@ -138,7 +124,6 @@ actor ThreadSafeFileCache {
}
private func loadCacheFromDisk() {
- // Load metadata
guard let metadataData = try? Data(contentsOf: metadataURL),
let metadata = try? JSONDecoder().decode(CacheMetadata.self, from: metadataData) else {
return
@@ -146,7 +131,6 @@ actor ThreadSafeFileCache {
print("Loading existing cache from disk - \(metadata.fileIDs.count) files")
- // Load cache order and calculate total bytes
var loadedBytes = 0
var validFileIDs: [Int] = []
diff --git a/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift b/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift
index b58e6102ec..730300028f 100644
--- a/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift
+++ b/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift
@@ -42,7 +42,6 @@ class ScreenSaverManager: ObservableObject {
isDisabled = false
}
- // Cleanup method for app termination
static func cleanup() {
shared.stopPrevention()
}
diff --git a/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift b/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift
index 6e258ca0ab..c5b5c27eaf 100644
--- a/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift
+++ b/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift
@@ -190,7 +190,6 @@ class RealSlideshowService: ObservableObject {
let validFileIDs = Set(await MainActor.run { allFiles.map { $0.id } })
await cleanupExpiredCache(validFileIDs: validFileIDs)
- // Initialize slideshow state
await MainActor.run {
self.totalSlides = fileCount
self.currentFileIndex = 0
@@ -243,10 +242,7 @@ class RealSlideshowService: ObservableObject {
error = nil
}
- // Clear cache to free memory only if explicitly needed
- // await clearCache() // Commented out to preserve cache across sessions
- // Print final cache statistics
let stats = await getCacheStats()
print("Final cache stats: \(stats.count) files, \(stats.totalSize) bytes")
@@ -279,7 +275,6 @@ class RealSlideshowService: ObservableObject {
livePhotoVideoData = nil
}
// Don't clear cache automatically - preserve across sessions
- // await clearCache() // Only clear if needed for debugging
}
// MARK: - File List Management
@@ -348,7 +343,6 @@ class RealSlideshowService: ObservableObject {
}
private func fetchFilesBatch(castPayload: CastPayload, sinceTime: Int64) async throws -> (files: [[String: Any]], hasMore: Bool, latestUpdateTime: Int64) {
- // Use the collection ID and sinceTime in the API call
let url = URL(string: "\(baseURL)/cast/diff?collectionID=\(castPayload.collectionID)&sinceTime=\(sinceTime)")!
@@ -441,7 +435,6 @@ class RealSlideshowService: ObservableObject {
currentFileIndex = 0 // Wrap around to beginning
}
- // Remove from caches
prefetchCache.removeValue(forKey: id)
await removeCachedFileContent(fileID: id)
@@ -567,7 +560,6 @@ class RealSlideshowService: ObservableObject {
return
}
- // Load from network
do {
let file = allFiles[currentFileIndex]
print("Loading file \(file.id): \(file.title) at index \(currentFileIndex)")
@@ -580,7 +572,6 @@ class RealSlideshowService: ObservableObject {
print("Successfully loaded file \(file.id): \(file.title) (\(decryptedData.count) bytes)")
- // Cache the data
prefetchCache[currentFileIndex] = decryptedData
await updateCurrentSlide(with: decryptedData, file: file)
@@ -723,7 +714,6 @@ class RealSlideshowService: ObservableObject {
private func skipToNextSlide() async {
guard !allFiles.isEmpty else { return }
- // Move to next slide
currentFileIndex = (currentFileIndex + 1) % allFiles.count
// If we've gone through all files and still have errors, stop the slideshow
@@ -941,7 +931,7 @@ class RealSlideshowService: ObservableObject {
isHandlingAuthExpiry = true
- // CRITICAL: Stop screen saver prevention immediately before any UI transitions
+ // Stop screen saver prevention immediately before any UI transitions
ScreenSaverManager.allowScreenSaver()
// Stop all ongoing operations
diff --git a/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift b/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift
index 493ed6bd03..d7a34e16c6 100644
--- a/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift
+++ b/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift
@@ -6,8 +6,7 @@ struct SlideshowView: View {
let videoData: Data?
let isVideo: Bool
@ObservedObject var slideshowService: RealSlideshowService
-
- // Computed property to determine if current file is a live photo
+
private var isLivePhoto: Bool {
slideshowService.currentFile?.isLivePhoto ?? false
}
@@ -47,7 +46,7 @@ struct SlideshowView: View {
return GeometryReader { geometry in
ZStack {
- // Background layer - FIXED VERSION
+ // Background layer
if let uiImage = mainUIImage {
Image(uiImage: uiImage)
.resizable()
@@ -185,7 +184,7 @@ struct SlideshowView: View {
// Backup screen saver prevention at view level
ScreenSaverManager.preventScreenSaver()
- // CRITICAL FIX: Process initial image data if present and not already processed
+ // Process initial image data if present and not already processed
// This handles the case where SlideshowView is created with imageData already populated
// (e.g., when transitioning from .connecting to .slideshow state)
// Without this, onChange won't fire and the image won't display
diff --git a/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift b/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift
index 5bb4561250..b8c07cb2d3 100644
--- a/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift
+++ b/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift
@@ -56,17 +56,13 @@ struct VideoPlayerView: View {
private func setupVideoPlayer() {
Task {
do {
- // Extract file extension from suggested filename
let suggestedExtension = suggestedFilename?.components(separatedBy: ".").last?.lowercased()
- // Create temporary file for video data with proper extension
let tempURL = try await createTemporaryVideoFile(from: videoData, suggestedExtension: suggestedExtension)
await MainActor.run {
- // Validate that the video file can be played
let asset = AVURLAsset(url: tempURL)
- // Check if the asset is playable
Task {
let isPlayable = try await asset.load(.isPlayable)
let hasVideoTracks = try await !asset.loadTracks(withMediaType: .video).isEmpty
@@ -84,7 +80,6 @@ struct VideoPlayerView: View {
setupPlayer()
} else {
- // Try fallback with different extension
self.tryVideoFallback(originalURL: tempURL)
}
}
@@ -93,7 +88,6 @@ struct VideoPlayerView: View {
} catch {
print("Failed to setup video player: \(error)")
await MainActor.run {
- // Show error state
self.showErrorState()
}
}
@@ -166,10 +160,8 @@ struct VideoPlayerView: View {
print("Failed to set audio session: \(error)")
}
- // Add observers
setupPlayerObservers()
- // Start playing
player.play()
isPlaying = true
}
@@ -188,7 +180,6 @@ struct VideoPlayerView: View {
player.play()
}
- // Add observer for player status changes
NotificationCenter.default.addObserver(
forName: .AVPlayerItemFailedToPlayToEndTime,
object: currentItem,
@@ -289,13 +280,11 @@ struct VideoPlayerView: View {
// KVO observer removal no longer needed as we use modern async/await approach
- // Remove all notification observers
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil)
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemFailedToPlayToEndTime, object: nil)
NotificationCenter.default.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
- // Deactivate audio session
do {
try AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
} catch {
@@ -309,7 +298,6 @@ struct VideoPlayerView: View {
}
#Preview {
- // Create mock video data for preview
let mockData = Data()
VideoPlayerView(videoData: mockData, suggestedFilename: "sample_video.mp4")
}