π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove dead code and platform conditionals from the cast app
Manav Rathi46366416b3d3
diff --git a/mobile/native/apple/apps/cast/Cast/ContentView.swift b/mobile/native/apple/apps/cast/Cast/ContentView.swiftindex 9de44e2909..c55fcc1e41 100644--- a/mobile/native/apple/apps/cast/Cast/ContentView.swift+++ b/mobile/native/apple/apps/cast/Cast/ContentView.swift@@ -43,37 +43,6 @@ struct ContentView: View {}}-struct CinematicBackground: View {- var body: some View {- ZStack {- // Clean, sophisticated gradient like Spotify- LinearGradient(- colors: [- Color(red: 0.08, green: 0.08, blue: 0.08),- Color(red: 0.04, green: 0.04, blue: 0.04),- Color(red: 0.02, green: 0.02, blue: 0.02)- ],- startPoint: .top,- endPoint: .bottom- )-- // Subtle brand accent - strategic placement- RadialGradient(- colors: [- Color(red: 29/255, green: 185/255, blue: 84/255).opacity(0.08),- Color.clear- ],- center: UnitPoint(x: 0.3, y: 0.2),- startRadius: 200,- endRadius: 800- )--- }- .ignoresSafeArea()- }-}-#Preview {ContentView()}diff --git a/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift b/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swiftindex c2b7c7fc15..8874225b5b 100644--- a/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift+++ b/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift@@ -40,8 +40,6 @@ class CastSession: ObservableObject {class RealCastPairingService {private let baseURL = "https://api.ente.com"private var pollingTimer: Timer?- private var lastLoggedMessages: [String: Date] = [:]- private let logThrottleInterval: TimeInterval = 5.0 // 5 secondsprivate var isPolling: Bool = falseprivate var isFetchingPayload: Bool = falseprivate var hasDeliveredPayload: Bool = falsediff --git a/mobile/native/apple/apps/cast/Cast/Utils/FontUtils.swift b/mobile/native/apple/apps/cast/Cast/Utils/FontUtils.swiftindex eb09092a8e..552d0ef652 100644--- a/mobile/native/apple/apps/cast/Cast/Utils/FontUtils.swift+++ b/mobile/native/apple/apps/cast/Cast/Utils/FontUtils.swift@@ -1,22 +1,16 @@import SwiftUI-#if canImport(UIKit)import UIKit-#endifstruct FontUtils {// MARK: - Safe Font Creationprivate static func safeFont(name: String, size: CGFloat, fallback: Font) -> Font {- #if canImport(UIKit)if UIFont(name: name, size: size) != nil {return .custom(name, size: size)} else {return fallback}- #else- return .custom(name, size: size)- #endif}// MARK: - Font Presetsdiff --git a/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift b/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swiftindex 4185d78e1c..b948e7c8b7 100644--- a/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift+++ b/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift@@ -1,61 +1,53 @@import Foundationimport UIKit-#if canImport(UIKit)-import UIKit-#endif-@MainActorclass ScreenSaverManager: ObservableObject {private static let shared = ScreenSaverManager()private var isDisabled = falseprivate var refreshTimer: Timer?-+static func preventScreenSaver() {shared.startPrevention()}-+static func allowScreenSaver() {shared.stopPrevention()}-+private func startPrevention() {- guard !isDisabled else {+ guard !isDisabled else {print("π« Screen saver prevention already enabled")- return+ return}-- #if os(tvOS)+UIApplication.shared.isIdleTimerDisabled = trueisDisabled = trueprint("π« Screen saver prevention enabled")-+// Fallback for problematic tvOS versions where isIdleTimerDisabled doesn't work reliably// This timer periodically refreshes the setting to ensure it stays disabledrefreshTimer = Timer.scheduledTimer(withTimeInterval: 30.0, repeats: true) { _ inUIApplication.shared.isIdleTimerDisabled = falseUIApplication.shared.isIdleTimerDisabled = true}- #endif}-+private func stopPrevention() {- guard isDisabled else {+ guard isDisabled else {print("β Screen saver prevention already disabled")- return+ return}-- #if os(tvOS)+refreshTimer?.invalidate()refreshTimer = nilUIApplication.shared.isIdleTimerDisabled = falseisDisabled = falseprint("β Screen saver prevention disabled")- #endif}-+// Cleanup method for app terminationstatic func cleanup() {shared.stopPrevention()}-}\ No newline at end of file+}diff --git a/mobile/native/apple/apps/cast/Cast/ViewModels/CastViewModel.swift b/mobile/native/apple/apps/cast/Cast/ViewModels/CastViewModel.swiftindex 3e2f586fe9..9b77abb410 100644--- a/mobile/native/apple/apps/cast/Cast/ViewModels/CastViewModel.swift+++ b/mobile/native/apple/apps/cast/Cast/ViewModels/CastViewModel.swift@@ -1,9 +1,6 @@import SwiftUIimport Combine--#if canImport(UIKit)import UIKit-#endif@MainActorclass CastViewModel: ObservableObject {@@ -20,8 +17,6 @@ class CastViewModel: ObservableObject {// MARK: - Private Propertiesprivate var cancellables = Set<AnyCancellable>()private let pairingService: RealCastPairingService- private var lastLoggedMessages: [String: Date] = [:]- private let logThrottleInterval: TimeInterval = 3.0 // 3 secondsprivate let castSession: CastSession// MARK: - Public Propertiesdiff --git a/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift b/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swiftindex d298643f4b..1fbb2ecc2f 100644--- a/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift+++ b/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift@@ -2,10 +2,7 @@ import SwiftUIimport AVKitimport Foundationimport ZIPFoundation--#if canImport(UIKit)import UIKit-#endif@MainActorclass RealSlideshowService: ObservableObject {@@ -69,7 +66,6 @@ class RealSlideshowService: ObservableObject {// Configuration Flagsprivate let verboseFileLogging = false // Reduces per-file spam unless trueprivate let verboseDecryptionLogging = false // Detailed size/key logs- private let enablePreviewFallback = true // Fetch preview image if full decrypt fails// 401 Error Handlingprivate var isHandlingAuthExpiry: Bool = false@@ -883,19 +879,6 @@ class RealSlideshowService: ObservableObject {slideTimer?.invalidate()}- func pauseVideo() {- videoPlayer?.pause()- isVideoPlaying = false- }-- func seekVideo(by seconds: Double) {- guard let player = videoPlayer else { return }- let current = player.currentTime().seconds- let target = max(0, current + seconds)- let time = CMTime(seconds: target, preferredTimescale: 600)- player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero)- }-@MainActorprivate func videoDidFinish() {isVideoPlaying = false@@ -1000,29 +983,7 @@ class RealSlideshowService: ObservableObject {}// MARK: - Network & Download-- private func downloadImage(castPayload: CastPayload, fileID: Int) async throws -> Data {- // Use preview endpoint for thumbnails suitable for TV display- let url = URL(string: "https://cast-albums.ente.com/preview/?fileID=\(fileID)")!-- var request = URLRequest(url: url)- request.setValue(castPayload.castToken, forHTTPHeaderField: "X-Cast-Access-Token")- request.setValue(castPayload.collectionKey, forHTTPHeaderField: "X-Collection-Key")-- let (data, response) = try await URLSession.shared.data(for: request)-- guard let httpResponse = response as? HTTPURLResponse else {- throw CastError.networkError("Invalid response")- }-- guard httpResponse.statusCode == 200 else {- throw CastError.serverError(httpResponse.statusCode, String(data: data, encoding: .utf8))- }-- if verboseFileLogging { print("π₯ Downloaded \(data.count) bytes for file \(fileID)") }- return data- }-+private func downloadEncryptedFile(castPayload: CastPayload, fileID: Int) async throws -> Data {// Use the file download endpoint with cast-specific headerslet url = URL(string: "\(castDownloadURL)/?fileID=\(fileID)")!@@ -1266,21 +1227,10 @@ class RealSlideshowService: ObservableObject {private func getCacheStats() async -> (count: Int, totalSize: Int) {return await fileCache.getStats()}-- func clearAllCache() async {- print("π§Ή Manually clearing all cache")- await fileCache.clear()- }-- func getCacheInfo() async -> String {- let stats = await getCacheStats()- return "Cache: \(stats.count) files, \(String(format: "%.1f", Double(stats.totalSize) / 1024 / 1024)) MB"- }}// MARK: - Live Photo Utilities-#if os(tvOS)func extractZipUsingFoundation(zipURL: URL, to destinationURL: URL) throws {do {try FileManager.default.unzipItem(at: zipURL, to: destinationURL)@@ -1289,7 +1239,6 @@ func extractZipUsingFoundation(zipURL: URL, to destinationURL: URL) throws {throw CastError.decryptionError("ZipFoundation extraction failed: \(error)")}}-#endiffunc extractLivePhotoComponents(from zipData: Data) throws -> LivePhotoComponents {let tempDirectory = FileManager.default.temporaryDirectory@@ -1310,21 +1259,8 @@ func extractLivePhotoComponents(from zipData: Data) throws -> LivePhotoComponentvar videoPath: URL?do {- // Use NSTask instead of Process for tvOS compatibility- #if os(macOS)- let task = Process()- task.executableURL = URL(fileURLWithPath: "/usr/bin/unzip")- task.arguments = ["-q", zipURL.path, "-d", extractDirectory.path]- try task.run()- task.waitUntilExit()-- if task.terminationStatus != 0 {- throw CastError.decryptionError("unzip command failed with status \(task.terminationStatus)")- }- #elseif os(tvOS)// For tvOS, we'll implement a simple zip reader using Foundationtry extractZipUsingFoundation(zipURL: zipURL, to: extractDirectory)- #endif// Enumerate all extracted files (including nested) because zips may contain a folder structure.let resourceKeys: [URLResourceKey] = [.isDirectoryKey]diff --git a/mobile/native/apple/apps/cast/Cast/Views/PairingView.swift b/mobile/native/apple/apps/cast/Cast/Views/PairingView.swiftindex 8d8d320791..6df845ac79 100644--- a/mobile/native/apple/apps/cast/Cast/Views/PairingView.swift+++ b/mobile/native/apple/apps/cast/Cast/Views/PairingView.swift@@ -1,8 +1,5 @@import SwiftUI--#if canImport(UIKit)import UIKit-#endifstruct PairingView: View {let deviceCode: Stringdiff --git a/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift b/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swiftindex 76ef0329f5..ce46634370 100644--- a/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift+++ b/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift@@ -1,8 +1,5 @@import SwiftUI--#if canImport(UIKit)import UIKit-#endifstruct SlideshowView: View {let imageData: Data?@@ -34,10 +31,8 @@ struct SlideshowView: View {@State private var preDecodedImage: UIImage? = nil@State private var previousDecodedImage: UIImage? = nil- #if os(tvOS)@FocusState private var isFocused: Bool- #endif-+init(imageData: Data? = nil, videoData: Data? = nil, isVideo: Bool = false, slideshowService: RealSlideshowService) {self.imageData = imageDataself.videoData = videoData@@ -174,7 +169,6 @@ struct SlideshowView: View {}.onTapGesture { Task { await handlePlayPauseAction() } }.onLongPressGesture { handleLongPressGesture() }- #if os(tvOS).focusable().focused($isFocused).onMoveCommand { direction in Task { await handleDirectionalInput(direction) } }@@ -186,14 +180,11 @@ struct SlideshowView: View {}}.onExitCommand { toggleControls() }- #endif.onAppear {startControlsTimer()- #if os(tvOS)isFocused = true// Backup screen saver prevention at view levelScreenSaverManager.preventScreenSaver()- #endif// CRITICAL FIX: Process initial image data if present and not already processed// This handles the case where SlideshowView is created with imageData already populated@@ -214,10 +205,8 @@ struct SlideshowView: View {}}.onDisappear {- #if os(tvOS)// Ensure screen saver prevention is disabled when view disappearsScreenSaverManager.allowScreenSaver()- #endif}}diff --git a/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift b/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swiftindex 79982d8c35..4484ce99d8 100644--- a/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift+++ b/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift@@ -1,10 +1,7 @@import SwiftUIimport AVFoundationimport AVKit--#if canImport(UIKit)import UIKit-#endifstruct VideoPlayerView: View {let videoData: Data@@ -165,14 +162,12 @@ struct VideoPlayerView: View {player.automaticallyWaitsToMinimizeStalling = true// Set audio session for proper audio handling- #if os(tvOS)do {try AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback)try AVAudioSession.sharedInstance().setActive(true)} catch {print("Failed to set audio session: \(error)")}- #endif// Add observerssetupPlayerObservers()@@ -311,13 +306,11 @@ struct VideoPlayerView: View {NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)// Deactivate audio session- #if os(tvOS)do {try AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)} catch {print("Failed to deactivate audio session: \(error)")}- #endifplayer = nilplayerItem = nil