Fix compilation for iOS

This commit is contained in:
Leon Böttger committed 2025-07-28 11:57:50 +02:00
1 parent d2fc94df75
commit 273b7459d8
14 files changed
+367 -27

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
//
// Localized.swift
// QuickDrop
//
// Created by Leon Böttger on 10.03.25.
//
import Foundation
public extension String {
func localized() -> String {
let localizedString = NSLocalizedString(self, comment: "")
return localizedString
}
}
+12 -1
View File
@@ -6,8 +6,10 @@
//
import Foundation
import AppKit
import ImageIO
#if os(macOS)
import AppKit
#endif
public class SaveFilesManager {
@@ -88,11 +90,15 @@ public class SaveFilesManager {
progress.totalUnitCount = 10
progress.kind = .file
progress.isPausable = false
#if os(macOS)
progress.publish()
#endif
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
progress.completedUnitCount = 10
#if os(macOS)
progress.unpublish()
#endif
}
try fileManager.removeItem(at: file)
@@ -110,10 +116,12 @@ public class SaveFilesManager {
if !filesFinishedDownloadingSinceLastRun.isEmpty && !isFileTransferRestricted() {
#if os(macOS)
if UserDefaults.standard.bool(forKey: UserDefaultsKeys.openFinderAfterReceiving.rawValue) {
log("Opening \(filesFinishedDownloadingSinceLastRun.count) file(s) in Finder.")
NSWorkspace.shared.activateFileViewerSelecting(filesFinishedDownloadingSinceLastRun)
}
#endif
// Clear the list of finished files
filesFinishedDownloadingSinceLastRun.removeAll()
@@ -143,6 +151,8 @@ public class SaveFilesManager {
if let bookmarkData = UserDefaults.standard.data(forKey: UserDefaultsKeys.saveFolderBookmark.rawValue) {
var isStale = false
// Not supported on iOS
#if os(macOS)
do {
let url = try URL(resolvingBookmarkData: bookmarkData, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &isStale)
@@ -160,6 +170,7 @@ public class SaveFilesManager {
} catch {
log("Failed to resolve bookmark: \(error), using default downloads folder.")
}
#endif
}
do {
+23 -7
View File
@@ -6,12 +6,21 @@
//
import Foundation
#if os(macOS)
import IOKit
import IOKit.pwr_mgt
#elseif os(iOS)
import UIKit
#endif
class SleepManager {
public static let shared = SleepManager()
#if os(macOS)
private var assertionID: IOPMAssertionID = 0
#endif
private var timer: Timer?
private init() {
@@ -24,28 +33,35 @@ class SleepManager {
}
private func disableSleep() {
if assertionID != 0 {
return
}
#if os(macOS)
if assertionID != 0 { return }
log("[SleepManager] Enabling Wakelock")
IOPMAssertionCreateWithName(
kIOPMAssertionTypePreventUserIdleDisplaySleep as CFString,
IOPMAssertionLevel(kIOPMAssertionLevelOn),
"QuickDrop Data Transfer" as CFString,
&assertionID
)
#elseif os(iOS)
log("[SleepManager] Keeping screen awake (iOS)")
UIApplication.shared.isIdleTimerDisabled = true
#endif
}
private func enableSleep() {
if assertionID == 0 {
return
}
#if os(macOS)
if assertionID == 0 { return }
log("[SleepManager] Disabling Wakelock")
IOPMAssertionRelease(assertionID)
assertionID = 0
#elseif os(iOS)
log("[SleepManager] Allowing screen to sleep (iOS)")
UIApplication.shared.isIdleTimerDisabled = false
#endif
}
private func updateSleepState() {