From a03c9be13bedd7fdb3de7c3a1dbd464636080df9 Mon Sep 17 00:00:00 2001 From: Mike Renoir <> Date: Wed, 6 Dec 2023 22:33:19 +0400 Subject: [PATCH 1/4] submobules update for macos --- submodules/MetalEngine/Package.swift | 6 ++++-- submodules/MetalEngine/Sources/MetalEngine.swift | 4 ++++ submodules/Utils/ShelfPack/Package.swift | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/submodules/MetalEngine/Package.swift b/submodules/MetalEngine/Package.swift index 94aa4301f4..2010efdeee 100644 --- a/submodules/MetalEngine/Package.swift +++ b/submodules/MetalEngine/Package.swift @@ -13,6 +13,7 @@ let package = Package( ], dependencies: [ .package(name: "ShelfPack", path: "../Utils/ShelfPack"), + .package(name: "TGUIKit", path: "../../../../packages/TGUIKit"), // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), ], @@ -21,7 +22,8 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "MetalEngine", - dependencies: [.product(name: "ShelfPack", package: "ShelfPack", condition: nil)], - path: "Sources/MetalEngine"), + dependencies: [.product(name: "ShelfPack", package: "ShelfPack", condition: nil), + .product(name: "TGUIKit", package: "TGUIKit", condition: nil)], + path: "Sources/"), ] ) diff --git a/submodules/MetalEngine/Sources/MetalEngine.swift b/submodules/MetalEngine/Sources/MetalEngine.swift index 3470972cc8..5efb97943e 100644 --- a/submodules/MetalEngine/Sources/MetalEngine.swift +++ b/submodules/MetalEngine/Sources/MetalEngine.swift @@ -4,8 +4,12 @@ import Metal #if os(iOS) import Display import UIKit +#else +import AppKit +import TGUIKit #endif + import IOSurface import ShelfPack diff --git a/submodules/Utils/ShelfPack/Package.swift b/submodules/Utils/ShelfPack/Package.swift index 871e14c64b..4c95aa8cd4 100644 --- a/submodules/Utils/ShelfPack/Package.swift +++ b/submodules/Utils/ShelfPack/Package.swift @@ -23,5 +23,6 @@ let package = Package( dependencies: [], path: ".", publicHeadersPath: "PublicHeaders"), - ] + ], + cxxLanguageStandard: .cxx20 ) From a723e852f798ad3617c48c9543483edf47b9dd04 Mon Sep 17 00:00:00 2001 From: Mike Renoir <> Date: Thu, 7 Dec 2023 12:22:24 +0400 Subject: [PATCH 2/4] metal engine macos changes --- .../FFMpegMediaVideoFrameDecoder.swift | 1 + .../Sources/SoftwareVideoSource.swift | 1 + .../UniversalSoftwareVideoSource.swift | 1 + submodules/MetalEngine/Package.swift | 1 + .../MetalEngine/Sources/MetalEngine.swift | 46 +++++++++++++------ .../TelegramCore/Sources/WebpagePreview.swift | 6 ++- submodules/Utils/LokiRng/Package.swift | 1 + submodules/Utils/ShelfPack/Package.swift | 1 + 8 files changed, 44 insertions(+), 14 deletions(-) diff --git a/submodules/MediaPlayer/Sources/FFMpegMediaVideoFrameDecoder.swift b/submodules/MediaPlayer/Sources/FFMpegMediaVideoFrameDecoder.swift index d79143102f..72bd74e0d3 100644 --- a/submodules/MediaPlayer/Sources/FFMpegMediaVideoFrameDecoder.swift +++ b/submodules/MediaPlayer/Sources/FFMpegMediaVideoFrameDecoder.swift @@ -2,6 +2,7 @@ import UIKit #else import AppKit +import TGUIKit #endif import CoreMedia import Accelerate diff --git a/submodules/MediaPlayer/Sources/SoftwareVideoSource.swift b/submodules/MediaPlayer/Sources/SoftwareVideoSource.swift index 577cb8f2fe..669e689746 100644 --- a/submodules/MediaPlayer/Sources/SoftwareVideoSource.swift +++ b/submodules/MediaPlayer/Sources/SoftwareVideoSource.swift @@ -3,6 +3,7 @@ import Foundation import UIKit #else import AppKit +import TGUIKit #endif import CoreMedia import SwiftSignalKit diff --git a/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift b/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift index 8b581bc6b6..72eea9f485 100644 --- a/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift +++ b/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift @@ -3,6 +3,7 @@ import Foundation import UIKit #else import AppKit +import TGUIKit #endif import SwiftSignalKit import Postbox diff --git a/submodules/MetalEngine/Package.swift b/submodules/MetalEngine/Package.swift index 2010efdeee..ec3838851c 100644 --- a/submodules/MetalEngine/Package.swift +++ b/submodules/MetalEngine/Package.swift @@ -5,6 +5,7 @@ import PackageDescription let package = Package( name: "MetalEngine", + platforms: [.macOS(.v10_13)], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( diff --git a/submodules/MetalEngine/Sources/MetalEngine.swift b/submodules/MetalEngine/Sources/MetalEngine.swift index 5efb97943e..87672cf6b5 100644 --- a/submodules/MetalEngine/Sources/MetalEngine.swift +++ b/submodules/MetalEngine/Sources/MetalEngine.swift @@ -666,13 +666,6 @@ public final class MetalEngine { fileprivate var computeStates: [ObjectIdentifier: ComputeState] = [:] init?(device: MTLDevice) { - let mainBundle = Bundle(for: Impl.self) - guard let path = mainBundle.path(forResource: "MetalEngineMetalSourcesBundle", ofType: "bundle") else { - return nil - } - guard let bundle = Bundle(path: path) else { - return nil - } self.device = device @@ -681,15 +674,42 @@ public final class MetalEngine { } self.commandQueue = commandQueue - guard let library = try? device.makeDefaultLibrary(bundle: bundle) else { - return nil - } - self.library = library + let library: MTLLibrary? - guard let vertexFunction = library.makeFunction(name: "clearVertex") else { + #if os(iOS) + let mainBundle = Bundle(for: Impl.self) + guard let path = mainBundle.path(forResource: "MetalEngineMetalSourcesBundle", ofType: "bundle") else { return nil } - guard let fragmentFunction = library.makeFunction(name: "clearFragment") else { + guard let bundle = Bundle(path: path) else { + return nil + } + library = try? device.makeDefaultLibrary(bundle: bundle) + #else + let mainBundle = Bundle(for: Impl.self) + guard let path = mainBundle.path(forResource: "MetalEngineMetalSourcesBundle", ofType: "bundle") else { + return nil + } + guard let bundle = Bundle(path: path) else { + return nil + } + guard let path = bundle.path(forResource: "MetalEngineShaders", ofType: "metallib") else { + return nil + } + library = try? device.makeLibrary(URL: .init(fileURLWithPath: path)) + #endif + + + + guard let lib = library else { + return nil + } + self.library = lib + + guard let vertexFunction = lib.makeFunction(name: "clearVertex") else { + return nil + } + guard let fragmentFunction = lib.makeFunction(name: "clearFragment") else { return nil } diff --git a/submodules/TelegramCore/Sources/WebpagePreview.swift b/submodules/TelegramCore/Sources/WebpagePreview.swift index 229e69deca..21f7e46032 100644 --- a/submodules/TelegramCore/Sources/WebpagePreview.swift +++ b/submodules/TelegramCore/Sources/WebpagePreview.swift @@ -18,6 +18,10 @@ public enum WebpagePreviewResult: Equatable { case progress case result(Result?) } +#if os(macOS) +private typealias UIImage = NSImage +#endif + public func webpagePreview(account: Account, urls: [String], webpageId: MediaId? = nil, forPeerId: PeerId? = nil) -> Signal { return webpagePreviewWithProgress(account: account, urls: urls, webpageId: webpageId, forPeerId: forPeerId) @@ -48,7 +52,7 @@ public func webpagePreviewWithProgress(account: Account, urls: [String], webpage } return .single(.result(WebpagePreviewResult.Result(webpage: webpage, sourceUrl: sourceUrl))) } else { - if #available(iOS 13.0, *) { + if #available(iOS 13.0, macOS 10.15, *) { if let forPeerId, forPeerId.namespace == Namespaces.Peer.SecretChat, let sourceUrl = urls.first, let url = URL(string: sourceUrl) { let localHosts: [String] = [ "twitter.com", diff --git a/submodules/Utils/LokiRng/Package.swift b/submodules/Utils/LokiRng/Package.swift index f2c2bcf28a..db37e9f384 100644 --- a/submodules/Utils/LokiRng/Package.swift +++ b/submodules/Utils/LokiRng/Package.swift @@ -5,6 +5,7 @@ import PackageDescription let package = Package( name: "LokiRng", + platforms: [.macOS(.v10_13)], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( diff --git a/submodules/Utils/ShelfPack/Package.swift b/submodules/Utils/ShelfPack/Package.swift index 4c95aa8cd4..9bd42def11 100644 --- a/submodules/Utils/ShelfPack/Package.swift +++ b/submodules/Utils/ShelfPack/Package.swift @@ -5,6 +5,7 @@ import PackageDescription let package = Package( name: "ShelfPack", + platforms: [.macOS(.v10_13)], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( From c75425b8a29a6b27408d046ad57f60b561b264bf Mon Sep 17 00:00:00 2001 From: Mike Renoir <> Date: Thu, 7 Dec 2023 21:11:15 +0400 Subject: [PATCH 3/4] reachibility to 14.0 --- submodules/Reachability/Sources/Reachability.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/submodules/Reachability/Sources/Reachability.swift b/submodules/Reachability/Sources/Reachability.swift index 422cbe0cd7..71e291824e 100644 --- a/submodules/Reachability/Sources/Reachability.swift +++ b/submodules/Reachability/Sources/Reachability.swift @@ -84,7 +84,7 @@ private final class WrappedLegacyReachability: NSObject { } } -@available(iOSApplicationExtension 12.0, iOS 12.0, OSX 13.0, *) +@available(iOSApplicationExtension 12.0, iOS 12.0, macOS 14.0, *) private final class PathMonitor { private let queue: Queue private let monitor: NWPathMonitor @@ -133,7 +133,7 @@ private final class PathMonitor { } } -@available(iOSApplicationExtension 12.0, iOS 12.0, OSX 13.0, *) +@available(iOSApplicationExtension 12.0, iOS 12.0, macOS 14.0, *) private final class SharedPathMonitor { static let queue = Queue() static let impl = QueueLocalObject(queue: queue, generate: { @@ -149,7 +149,7 @@ public enum Reachability { } public static var networkType: Signal { - if #available(iOSApplicationExtension 12.0, iOS 12.0, OSX 13.0, *) { + if #available(iOSApplicationExtension 12.0, iOS 12.0, macOS 14.0, *) { return Signal { subscriber in let disposable = MetaDisposable() From 677f1584c7026393cfb9bf66f3a89aad7b1628b1 Mon Sep 17 00:00:00 2001 From: Mike Renoir <> Date: Fri, 8 Dec 2023 13:21:34 +0400 Subject: [PATCH 4/4] macos 10.14 to 14.0 --- submodules/TelegramCore/Sources/Network/Network.swift | 2 +- .../Network/NetworkFrameworkTcpConnectionInterface.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/TelegramCore/Sources/Network/Network.swift b/submodules/TelegramCore/Sources/Network/Network.swift index 258494f0f3..2914559d88 100644 --- a/submodules/TelegramCore/Sources/Network/Network.swift +++ b/submodules/TelegramCore/Sources/Network/Network.swift @@ -514,7 +514,7 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa } if useNetworkFramework { - if #available(iOS 12.0, macOS 10.14, *) { + if #available(iOS 12.0, macOS 14.0, *) { context.makeTcpConnectionInterface = { delegate, delegateQueue in return NetworkFrameworkTcpConnectionInterface(delegate: delegate, delegateQueue: delegateQueue) } diff --git a/submodules/TelegramCore/Sources/Network/NetworkFrameworkTcpConnectionInterface.swift b/submodules/TelegramCore/Sources/Network/NetworkFrameworkTcpConnectionInterface.swift index 956163880d..d17d399bb9 100644 --- a/submodules/TelegramCore/Sources/Network/NetworkFrameworkTcpConnectionInterface.swift +++ b/submodules/TelegramCore/Sources/Network/NetworkFrameworkTcpConnectionInterface.swift @@ -4,7 +4,7 @@ import Network import MtProtoKit import SwiftSignalKit -@available(iOS 12.0, macOS 10.14, *) +@available(iOS 12.0, macOS 14.0, *) final class NetworkFrameworkTcpConnectionInterface: NSObject, MTTcpConnectionInterface { private struct ReadRequest { let length: Int