From fce69ba1cf37544a1810e7a59a596b5959424481 Mon Sep 17 00:00:00 2001 From: Kylmakalle Date: Fri, 4 Jul 2025 16:23:15 +0300 Subject: [PATCH] WIP Fix AppBadge --- Swiftgram/SGAppBadgeOffset/BUILD | 9 ++++++ .../Sources/SGAppBadgeOffset.swift | 9 ++++++ submodules/Display/BUILD | 6 +++- submodules/Display/Source/DeviceMetrics.swift | 30 ------------------- submodules/Display/Source/WindowContent.swift | 20 +------------ 5 files changed, 24 insertions(+), 50 deletions(-) create mode 100644 Swiftgram/SGAppBadgeOffset/BUILD create mode 100644 Swiftgram/SGAppBadgeOffset/Sources/SGAppBadgeOffset.swift diff --git a/Swiftgram/SGAppBadgeOffset/BUILD b/Swiftgram/SGAppBadgeOffset/BUILD new file mode 100644 index 0000000000..23409546fb --- /dev/null +++ b/Swiftgram/SGAppBadgeOffset/BUILD @@ -0,0 +1,9 @@ +filegroup( + name = "SGAppBadgeOffset", + srcs = glob([ + "Sources/**/*.swift", + ]), + visibility = [ + "//visibility:public", + ], +) \ No newline at end of file diff --git a/Swiftgram/SGAppBadgeOffset/Sources/SGAppBadgeOffset.swift b/Swiftgram/SGAppBadgeOffset/Sources/SGAppBadgeOffset.swift new file mode 100644 index 0000000000..015c21d217 --- /dev/null +++ b/Swiftgram/SGAppBadgeOffset/Sources/SGAppBadgeOffset.swift @@ -0,0 +1,9 @@ +import Foundation + +extension Window1 { + func sgAppBadgeOffset(_ defaultOffset: CGFloat) -> CGFloat { + var additionalOffset: CGFloat = 0.0 + additionalOffset += 30.0 + return defaultOffset + additionalOffset + } +} diff --git a/submodules/Display/BUILD b/submodules/Display/BUILD index 8e56c1d1ec..e43fcfe17f 100644 --- a/submodules/Display/BUILD +++ b/submodules/Display/BUILD @@ -1,9 +1,13 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") +sgsrc = [ + "//Swiftgram/SGAppBadgeOffset:SGAppBadgeOffset" +] + swift_library( name = "Display", module_name = "Display", - srcs = glob([ + srcs = sgsrc + glob([ "Source/**/*.swift", ]), copts = [ diff --git a/submodules/Display/Source/DeviceMetrics.swift b/submodules/Display/Source/DeviceMetrics.swift index e198b6b727..a9c39dc3d4 100644 --- a/submodules/Display/Source/DeviceMetrics.swift +++ b/submodules/Display/Source/DeviceMetrics.swift @@ -389,33 +389,3 @@ public enum DeviceMetrics: CaseIterable, Equatable { return self.hasTopNotch || self.hasDynamicIsland } } - -// MARK: Swifgram -public extension DeviceMetrics { - - var deviceModelCode: String { - var systemInfo = utsname() - uname(&systemInfo) - let modelCode = withUnsafePointer(to: &systemInfo.machine) { - $0.withMemoryRebound(to: CChar.self, capacity: 1) { - ptr in String.init(validatingUTF8: ptr) - } - } - return modelCode ?? "unknown" - } - - var modelHasDynamicIsland: Bool { - switch self.deviceModelCode { - case "iPhone15,2", // iPhone 14 Pro - "iPhone15,3", // iPhone 14 Pro Max - "iPhone15,4", // iPhone 15 - "iPhone15,5", // iPhone 15 Plus - "iPhone16,1", // iPhone 15 Pro - "iPhone16,2": // iPhone 15 Pro Max - return true - default: - return false - } - } - -} diff --git a/submodules/Display/Source/WindowContent.swift b/submodules/Display/Source/WindowContent.swift index ba1255c7ee..1c0f1509f3 100644 --- a/submodules/Display/Source/WindowContent.swift +++ b/submodules/Display/Source/WindowContent.swift @@ -1219,25 +1219,7 @@ public class Window1 { if let image = self.badgeView.image { self.updateBadgeVisibility() - // MARK: Swiftgram - var badgeOffset: CGFloat - if case self.deviceMetrics = DeviceMetrics.iPhone14ProZoomed { - badgeOffset = self.deviceMetrics.statusBarHeight - DeviceMetrics.iPhone14ProZoomed.statusBarHeight - if self.deviceMetrics.modelHasDynamicIsland { - badgeOffset += 3.0 - } - } else if case self.deviceMetrics = DeviceMetrics.iPhone14ProMaxZoomed { - badgeOffset = self.deviceMetrics.statusBarHeight - DeviceMetrics.iPhone14ProMaxZoomed.statusBarHeight - if self.deviceMetrics.modelHasDynamicIsland { - badgeOffset += 3.0 - } - } else { - badgeOffset = self.deviceMetrics.statusBarHeight - DeviceMetrics.iPhone13ProMax.statusBarHeight - } - if badgeOffset != 0 { - badgeOffset += 3.0 // Centering badge in status bar for Dynamic island devices - } - self.badgeView.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.windowLayout.size.width - image.size.width) / 2.0), y: 5.0 + badgeOffset), size: image.size) + self.badgeView.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.windowLayout.size.width - image.size.width) / 2.0), y: self.sgAppBadgeOffset(5.0)), size: image.size) } } }