Skip to content

armgit / ente

Public Imported from GitHub
0

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

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.swift
index 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.swift
index 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 seconds
private var isPolling: Bool = false
private var isFetchingPayload: Bool = false
private var hasDeliveredPayload: Bool = false
diff --git a/mobile/native/apple/apps/cast/Cast/Utils/FontUtils.swift b/mobile/native/apple/apps/cast/Cast/Utils/FontUtils.swift
index 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
-#endif
struct FontUtils {
// MARK: - Safe Font Creation
private 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 Presets
diff --git a/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift b/mobile/native/apple/apps/cast/Cast/Utils/ScreenSaverManager.swift
index 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 Foundation
import UIKit
-#if canImport(UIKit)
-import UIKit
-#endif
-
@MainActor
class ScreenSaverManager: ObservableObject {
private static let shared = ScreenSaverManager()
private var isDisabled = false
private 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 = true
isDisabled = true
print("🚫 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 disabled
refreshTimer = Timer.scheduledTimer(withTimeInterval: 30.0, repeats: true) { _ in
UIApplication.shared.isIdleTimerDisabled = false
UIApplication.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 = nil
UIApplication.shared.isIdleTimerDisabled = false
isDisabled = false
print("βœ… Screen saver prevention disabled")
- #endif
}
-
+
// Cleanup method for app termination
static 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.swift
index 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 SwiftUI
import Combine
-
-#if canImport(UIKit)
import UIKit
-#endif
@MainActor
class CastViewModel: ObservableObject {
@@ -20,8 +17,6 @@ class CastViewModel: ObservableObject {
// MARK: - Private Properties
private var cancellables = Set<AnyCancellable>()
private let pairingService: RealCastPairingService
- private var lastLoggedMessages: [String: Date] = [:]
- private let logThrottleInterval: TimeInterval = 3.0 // 3 seconds
private let castSession: CastSession
// MARK: - Public Properties
diff --git a/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift b/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift
index 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 SwiftUI
import AVKit
import Foundation
import ZIPFoundation
-
-#if canImport(UIKit)
import UIKit
-#endif
@MainActor
class RealSlideshowService: ObservableObject {
@@ -69,7 +66,6 @@ class RealSlideshowService: ObservableObject {
// Configuration Flags
private let verboseFileLogging = false // Reduces per-file spam unless true
private let verboseDecryptionLogging = false // Detailed size/key logs
- private let enablePreviewFallback = true // Fetch preview image if full decrypt fails
// 401 Error Handling
private 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)
- }
-
@MainActor
private 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 headers
let 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)")
}
}
-#endif
func extractLivePhotoComponents(from zipData: Data) throws -> LivePhotoComponents {
let tempDirectory = FileManager.default.temporaryDirectory
@@ -1310,21 +1259,8 @@ func extractLivePhotoComponents(from zipData: Data) throws -> LivePhotoComponent
var 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 Foundation
try 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.swift
index 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
-#endif
struct PairingView: View {
let deviceCode: String
diff --git a/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift b/mobile/native/apple/apps/cast/Cast/Views/SlideshowView.swift
index 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
-#endif
struct 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 = imageData
self.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 level
ScreenSaverManager.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 disappears
ScreenSaverManager.allowScreenSaver()
- #endif
}
}
diff --git a/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift b/mobile/native/apple/apps/cast/Cast/Views/VideoPlayerView.swift
index 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 SwiftUI
import AVFoundation
import AVKit
-
-#if canImport(UIKit)
import UIKit
-#endif
struct 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 observers
setupPlayerObservers()
@@ -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)")
}
- #endif
player = nil
playerItem = nil