From fd524adca1c555aa7680b01ecc99e6107ce92be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Sat, 3 May 2025 14:44:34 +0200 Subject: [PATCH] Strings --- NearDrop/de.lproj/Localizable.strings | 2 +- NearbyShare/NearbyConnectionManager.swift | 4 +++ NearbyShare/SleepManager.swift | 39 +++++++++++++++++++++++ QuickDrop.xcodeproj/project.pbxproj | 4 +++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 NearbyShare/SleepManager.swift diff --git a/NearDrop/de.lproj/Localizable.strings b/NearDrop/de.lproj/Localizable.strings index e384b2d..eeed851 100644 --- a/NearDrop/de.lproj/Localizable.strings +++ b/NearDrop/de.lproj/Localizable.strings @@ -48,7 +48,7 @@ "SendClipboard" = "Zwischenablage senden"; "Clipboard" = "Zwischenablage"; -"DeviceCurrentlySendingFiles" = "%1$@ sendet dir %2$@"; +"DeviceCurrentlySendingFiles" = "%1$@ sendet %2$@"; "UserManual" = "Benutzerhandbuch & Einstellungen"; "Settings" = "Einstellungen"; "AutomaticallyAcceptFiles" = "Eingehende Dateien automatisch akzeptieren"; diff --git a/NearbyShare/NearbyConnectionManager.swift b/NearbyShare/NearbyConnectionManager.swift index dcf6f03..fc012e8 100644 --- a/NearbyShare/NearbyConnectionManager.swift +++ b/NearbyShare/NearbyConnectionManager.swift @@ -399,5 +399,9 @@ public class NearbyConnectionManager : NSObject, NetServiceDelegate, InboundNear } outgoingTransfers.removeValue(forKey: connection.id) } + + public func getActiveConnectionsCount() -> Int { + return activeConnections.count + } } diff --git a/NearbyShare/SleepManager.swift b/NearbyShare/SleepManager.swift new file mode 100644 index 0000000..4f27b4b --- /dev/null +++ b/NearbyShare/SleepManager.swift @@ -0,0 +1,39 @@ +// +// SleepManager.swift +// QuickDrop +// +// Created by Leon Böttger on 03.05.25. +// + +import Foundation +import IOKit +import IOKit.pwr_mgt + +class SleepManager{ + public static let shared = SleepManager() + private var assertionID: IOPMAssertionID = 0 + + public func disableSleep() { + if(assertionID != 0) { + return + } + + IOPMAssertionCreateWithName( + kIOPMAssertionTypePreventUserIdleSystemSleep as CFString, + IOPMAssertionLevel(kIOPMAssertionLevelOn), + "QuickDrop Data Transfer" as CFString, + &assertionID + ) + } + + public func enableSleep() { + if(assertionID == 0 || NearbyConnectionManager.shared.getActiveConnectionsCount() != 0){ + return + } + + IOPMAssertionRelease(assertionID) + assertionID = 0 + } + + private init() {} +} diff --git a/QuickDrop.xcodeproj/project.pbxproj b/QuickDrop.xcodeproj/project.pbxproj index 4ce5660..ed4e98d 100644 --- a/QuickDrop.xcodeproj/project.pbxproj +++ b/QuickDrop.xcodeproj/project.pbxproj @@ -34,6 +34,7 @@ 69DCF49C2AB8C58500CBE2CC /* SwiftECC in Frameworks */ = {isa = PBXBuildFile; productRef = 69DCF49B2AB8C58500CBE2CC /* SwiftECC */; }; 69DCF49D2AB8C9A500CBE2CC /* libNearbyShare.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 69DCF4812AB70D0600CBE2CC /* libNearbyShare.dylib */; }; 69DCF49E2AB8C9A500CBE2CC /* libNearbyShare.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 69DCF4812AB70D0600CBE2CC /* libNearbyShare.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; + EB2B41E42DC63ACC0070FC39 /* SleepManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2B41E32DC63AC80070FC39 /* SleepManager.swift */; }; EB2F9BFB2DA04B69004010A2 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2F9BFA2DA04B67004010A2 /* Helpers.swift */; }; EB2F9BFE2DA05F48004010A2 /* BezelNotification in Frameworks */ = {isa = PBXBuildFile; productRef = EB2F9BFD2DA05F48004010A2 /* BezelNotification */; }; EB3643602D73A2A2009CDFF8 /* AudioManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB36435F2D73A29F009CDFF8 /* AudioManager.swift */; }; @@ -196,6 +197,7 @@ E9C8C6D22CFF66650053474D /* ro */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ro; path = ro.lproj/ShareViewController.strings; sourceTree = ""; }; E9C8C6D32CFF66650053474D /* ro */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ro; path = ro.lproj/Localizable.stringsdict; sourceTree = ""; }; E9C8C6D42CFF66650053474D /* ro */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ro; path = ro.lproj/Localizable.strings; sourceTree = ""; }; + EB2B41E32DC63AC80070FC39 /* SleepManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepManager.swift; sourceTree = ""; }; EB2F9BFA2DA04B67004010A2 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = ""; }; EB36435F2D73A29F009CDFF8 /* AudioManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioManager.swift; sourceTree = ""; }; EB3643612D73A2CA009CDFF8 /* timeIsNow.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = timeIsNow.mp3; sourceTree = ""; }; @@ -338,6 +340,7 @@ 69DCF4822AB70D0600CBE2CC /* NearbyShare */ = { isa = PBXGroup; children = ( + EB2B41E32DC63AC80070FC39 /* SleepManager.swift */, 69DA9A2729E18CB500A442DA /* Protobuf */, 69DA9A1E29E0C0B300A442DA /* NearbyConnectionManager.swift */, 69DA9A2229E17F0400A442DA /* InboundNearbyConnection.swift */, @@ -566,6 +569,7 @@ EB7CD1472D6FB0E800CB0CB5 /* Logger.swift in Sources */, 69DCF4902AB70E9700CBE2CC /* InboundNearbyConnection.swift in Sources */, 69DCF48B2AB70E8C00CBE2CC /* ukey.pb.swift in Sources */, + EB2B41E42DC63ACC0070FC39 /* SleepManager.swift in Sources */, 69DCF48A2AB70E8C00CBE2CC /* wire_format.pb.swift in Sources */, 69DCF4932AB70E9700CBE2CC /* Data+Extensions.swift in Sources */, );