From 6c8d848eee1523059e0cf1fabe03beb52410e6ec Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 12:52:58 +0800 Subject: [PATCH 1/2] App: no size left to iOS on the Storage access pages and dialogs, and checked Several sizes on these pages were only preferences or lower bounds, so iOS was free to choose them, and iOS versions choose differently: the Continue button's height (laid out away from a device, it covered the whole page), the heading and the line under it (any width from 0, the companion's iOS 12 fault), the device line in the header, the dialogs' text, the empty footer's height and the page's scroll width. Each is now set by the layout. App/LayoutCheck.swift (the check OrchardLinux/tools runs on its iOS apps) lays the Storage access pages and two dialogs out at every iPhone, iPod touch and iPad size, upright and on its side, with the device's size classes, and fails on any of that, on broken or cut-off text and on anything off the screen. scripts/check-layout.sh runs it in a simulator; pull requests run it. Assisted-by: LLM --- .github/workflows/check.yml | 15 +++ App/AppDelegate.swift | 14 +++ App/AppModel.swift | 4 + App/Components.swift | 5 +- App/Dialog.swift | 3 +- App/LayoutCheck.swift | 150 +++++++++++++++++++++++++++ App/Pages.swift | 8 +- App/RootViewController.swift | 5 + ResizeAPFS.xcodeproj/project.pbxproj | 6 +- scripts/check-layout.sh | 41 ++++++++ 10 files changed, 246 insertions(+), 5 deletions(-) create mode 100644 App/LayoutCheck.swift create mode 100755 scripts/check-layout.sh diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index be8cb95..a9a6d5a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -22,3 +22,18 @@ jobs: python3 -m unittest discover -s Tests/ReleaseTests - name: Host tests run: swift test -j 2 + # Every Storage access page and dialog at the size of every iPhone, iPod touch + # and iPad (App/LayoutCheck.swift): fails on a width or height left to iOS + # (iOS 12 drew such a page two letters wide in the companion), broken or cut + # off text and anything off the screen. + layout: + runs-on: macos-15-intel # arm64 Mac runners are short; queued jobs are dropped after 15 min + timeout-minutes: 20 + env: + DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false + - name: Layout check + run: scripts/check-layout.sh diff --git a/App/AppDelegate.swift b/App/AppDelegate.swift index 6e2475f..c69adf8 100644 --- a/App/AppDelegate.swift +++ b/App/AppDelegate.swift @@ -8,6 +8,20 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { var frame = UIScreen.main.bounds #if targetEnvironment(simulator) + if ProcessInfo.processInfo.environment["ORCHARD_LAYOUT_CHECK"] != nil { + let pages: [(String, StorageAccess.Phase)] = [("access", .start), ("access-working", .getting), ("access-failed", .failed)] + let dialogs = [("dialog-stop", DialogController(title: "Stop resizing?", message: "The current step finishes first. APFS keeps the size it has then and the partition stays 64 GB. You can continue or grow APFS back later.", action: "Stop", cancel: "Keep resizing") {}), + ("dialog-snapshot", DialogController(title: "Remove system snapshot?", message: "iOS then starts without it, as after checkra1n’s Install Cydia, and can shrink further. It can’t be brought back.", action: "Remove") {})] + LayoutCheck.finish(pages.flatMap { name, phase in + LayoutCheck.problems(name) { _ in + let model = AppModel() + model.showAccessPage(phase) + let controller = RootViewController(model: model) + controller.loadViewIfNeeded() + return controller + } + } + dialogs.flatMap { name, dialog in LayoutCheck.problems(name) { _ in dialog } }) + } // UI tests check the iPod touch's 320 × 568 pt layout, which current simulators lack. if ProcessInfo.processInfo.arguments.contains("--ipod-size") { frame = CGRect(x: 0, y: 0, width: 320, height: 568) } #endif diff --git a/App/AppModel.swift b/App/AppModel.swift index 703ebd9..58da827 100644 --- a/App/AppModel.swift +++ b/App/AppModel.swift @@ -48,6 +48,10 @@ final class AppModel { /// `.getting` and `.failed` have their own pages, before any storage is shown. private(set) var accessPhase: StorageAccess.Phase private var accessBegun = false + #if targetEnvironment(simulator) + /// The layout check (LayoutCheck.swift) shows each Storage access page. + func showAccessPage(_ phase: StorageAccess.Phase) { accessPhase = phase } + #endif init(access: StorageAccess? = nil) { self.access = access diff --git a/App/Components.swift b/App/Components.swift index c4681d8..aac4cf5 100644 --- a/App/Components.swift +++ b/App/Components.swift @@ -332,8 +332,11 @@ final class ActionButton: UIControl { row.isUserInteractionEnabled = false row.translatesAutoresizingMaskIntoConstraints = false addSubview(row) + // 50 high: a height left open is one iOS versions pick differently (LayoutCheck.swift). + let height = heightAnchor.constraint(equalToConstant: 50) + height.priority = UILayoutPriority(999) NSLayoutConstraint.activate([row.centerXAnchor.constraint(equalTo: centerXAnchor), row.centerYAnchor.constraint(equalTo: centerYAnchor), - heightAnchor.constraint(greaterThanOrEqualToConstant: 50)]) + heightAnchor.constraint(greaterThanOrEqualToConstant: 50), height]) isEnabled = enabled addTarget(self, action: #selector(tapped), for: .touchUpInside) isAccessibilityElement = true diff --git a/App/Dialog.swift b/App/Dialog.swift index 94e6ca2..650bf60 100644 --- a/App/Dialog.swift +++ b/App/Dialog.swift @@ -51,7 +51,8 @@ final class DialogController: UIViewController { box.translatesAutoresizingMaskIntoConstraints = false view.addSubview(box) let width = box.widthAnchor.constraint(equalToConstant: 300) - width.priority = .defaultHigh + // Above the text's own wishes (750): its width is never left to iOS (LayoutCheck.swift). + width.priority = UILayoutPriority(999) NSLayoutConstraint.activate([ column.topAnchor.constraint(equalTo: box.topAnchor), column.bottomAnchor.constraint(equalTo: box.bottomAnchor), column.leadingAnchor.constraint(equalTo: box.leadingAnchor), column.trailingAnchor.constraint(equalTo: box.trailingAnchor), diff --git a/App/LayoutCheck.swift b/App/LayoutCheck.swift new file mode 100644 index 0000000..5087cbc --- /dev/null +++ b/App/LayoutCheck.swift @@ -0,0 +1,150 @@ +// The layout check (scripts/check-layout.sh): every page at the size of every +// iPhone, iPod touch and iPad, upright and on its side. It fails on what went +// wrong on devices before: a width Auto Layout has to pick by itself (iOS 12 +// picked about two letters for the companion's Storage access page), text broken +// inside a word or cut off, anything outside the screen. Simulator only. The same +// check as OrchardLinux/tools' companion/App/LayoutCheck.swift. +#if targetEnvironment(simulator) +import UIKit + +enum LayoutCheck { + /// Points: iPhone SE (1st) and iPod touch (6th), iPhone 8, iPhone XR, iPad mini + /// and iPad 9.7", iPad 10.2", iPad Pro 12.9"; upright and on their side. + static let sizes: [CGSize] = { + let upright = [CGSize(width: 320, height: 568), CGSize(width: 375, height: 667), + CGSize(width: 414, height: 896), CGSize(width: 768, height: 1024), + CGSize(width: 810, height: 1080), CGSize(width: 1024, height: 1366)] + return upright + upright.map { CGSize(width: $0.height, height: $0.width) } + }() + + /// The problems of one screen: `make` builds its controller for a size (it may + /// word the screen for the device of that size), laid out first in a tiny window, + /// as a window can be before it gets its size, then at each size in turn. + static func problems(_ screen: String, sizes: [CGSize] = sizes, _ make: (CGSize) -> UIViewController) -> [String] { + var problems: [String] = [] + for size in sizes { + let controller = make(size) + let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) + // The size classes of the device of that size (an iPad is regular both ways; + // a phone is compact across, and compact high on its side). + let host = UIViewController() + host.addChild(controller) + controller.view.frame = host.view.bounds + controller.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] + host.view.addSubview(controller.view) + controller.didMove(toParent: host) + let pad = min(size.width, size.height) >= 600 + host.setOverrideTraitCollection(UITraitCollection(traitsFrom: [ + UITraitCollection(horizontalSizeClass: pad ? .regular : .compact), + UITraitCollection(verticalSizeClass: pad || size.height > size.width ? .regular : .compact), + UITraitCollection(userInterfaceIdiom: pad ? .pad : .phone)]), forChild: controller) + window.rootViewController = host + window.isHidden = false + window.layoutIfNeeded() + window.frame = CGRect(origin: .zero, size: size) + window.layoutIfNeeded() + problems += check(controller.view, in: window).map { "\(screen) at \(Int(size.width))x\(Int(size.height)): \($0)" } + // ORCHARD_LAYOUT_SHOTS=DIR: a picture of the screen, upright, at 2x, for review. + if let dir = ProcessInfo.processInfo.environment["ORCHARD_LAYOUT_SHOTS"], size.height > size.width { + let format = UIGraphicsImageRendererFormat() + format.scale = 2 + let image = UIGraphicsImageRenderer(bounds: window.bounds, format: format).image { window.layer.render(in: $0.cgContext) } + let name = screen.replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: "(", with: "").replacingOccurrences(of: ")", with: "") + try? image.pngData()?.write(to: URL(fileURLWithPath: "\(dir)/\(name)@\(Int(size.width))x\(Int(size.height)).png")) + } + window.isHidden = true + } + return problems + } + + /// Prints the problems and ends the app: status 0 without any. + static func finish(_ problems: [String]) -> Never { + problems.forEach { print("LAYOUT: \($0)") } + print(problems.isEmpty ? "LAYOUT OK" : "LAYOUT FAILED: \(problems.count) problems") + exit(problems.isEmpty ? 0 : 1) + } + + private static func describe(_ view: UIView) -> String { + if let label = view as? UILabel { return "label \"\(label.text ?? "")\"" } + return String(describing: type(of: view)) + } + + private static func labels(_ view: UIView) -> [UILabel] { + (view as? UILabel).map { [$0] } ?? view.subviews.flatMap(labels) + } + + /// Text that wraps must get its width from the layout, never from its own wish + /// to be narrow or wide: where that wish decides, iOS versions decide differently + /// (iOS 12 made the Storage access page's text about two letters wide). So each + /// such label is laid out wanting no width, then all it can get, and must not move. + private static func undecided(_ root: UIView, in window: UIWindow) -> [String] { + let wrapping = labels(root).filter { $0.numberOfLines != 1 && !($0.text ?? "").isEmpty } + let saved = wrapping.map { ($0.contentHuggingPriority(for: .horizontal), $0.contentCompressionResistancePriority(for: .horizontal)) } + func widths(hug: UILayoutPriority, resist: UILayoutPriority) -> [CGFloat] { + for label in wrapping { + label.setContentHuggingPriority(hug, for: .horizontal) + label.setContentCompressionResistancePriority(resist, for: .horizontal) + label.invalidateIntrinsicContentSize() + } + root.setNeedsLayout() + window.layoutIfNeeded() + return wrapping.map { $0.bounds.width } + } + // 990: far above the system's own 750 and 250, below the 999 a screen + // decides a width with (StatusController's column, keepNote). + let narrow = widths(hug: UILayoutPriority(990), resist: UILayoutPriority(1)) + let wide = widths(hug: UILayoutPriority(1), resist: UILayoutPriority(990)) + for (label, (hug, resist)) in zip(wrapping, saved) { + label.setContentHuggingPriority(hug, for: .horizontal) + label.setContentCompressionResistancePriority(resist, for: .horizontal) + } + root.setNeedsLayout() + window.layoutIfNeeded() + return zip(wrapping, zip(narrow, wide)).compactMap { label, w in + abs(w.0 - w.1) > 0.5 ? "\(describe(label)) has no width of its own: \(Int(w.0)) to \(Int(w.1)), as the system picks" : nil + } + } + + private static func check(_ root: UIView, in window: UIWindow) -> [String] { + var problems = undecided(root, in: window) + func visit(_ view: UIView, clip: CGRect) { + guard !view.isHidden, view.alpha > 0 else { return } + let frame = view.convert(view.bounds, to: window) + if view.hasAmbiguousLayout { problems.append("\(describe(view)) has no definite size or place") } + if frame.minX < clip.minX - 0.5 || frame.maxX > clip.maxX + 0.5 || frame.minY < clip.minY - 0.5 || frame.maxY > clip.maxY + 0.5 { + problems.append("\(describe(view)) at \(frame) is outside \(clip)") + } + if let label = view as? UILabel, let text = label.attributedText, text.length > 0 { + // Each word as the label draws it: its own attributes, on one line. + let string = text.string as NSString + var at = 0 + while at < string.length { + let space = string.rangeOfCharacter(from: .whitespacesAndNewlines, options: [], range: NSRange(location: at, length: string.length - at)) + let end = space.location == NSNotFound ? string.length : space.location + if end > at { + let word = text.attributedSubstring(from: NSRange(location: at, length: end - at)) + let width = word.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: .greatestFiniteMagnitude), + options: [.usesLineFragmentOrigin], context: nil).width + if width > label.bounds.width + 0.5 { + problems.append("\(describe(view)) is \(Int(label.bounds.width)) wide, which breaks \"\(word.string)\" (\(Int(ceil(width))) wide)") + break + } + } + at = end + 1 + } + let needed = label.sizeThatFits(CGSize(width: label.bounds.width, height: .greatestFiniteMagnitude)).height + if needed > label.bounds.height + 1 { problems.append("\(describe(view)) is cut off (\(Int(label.bounds.height)) of \(Int(needed)) high)") } + } + // A scroll view's content may go past its frame, vertically only. + var inner = clip + if let scroll = view as? UIScrollView { + if scroll.contentSize.width > scroll.bounds.width + 0.5 { problems.append("scrolls sideways (\(scroll.contentSize.width) in \(scroll.bounds.width))") } + inner = CGRect(x: frame.minX, y: -.greatestFiniteMagnitude / 2, width: frame.width, height: .greatestFiniteMagnitude) + } + view.subviews.forEach { visit($0, clip: inner) } + } + visit(root, clip: window.bounds) + return problems + } +} +#endif diff --git a/App/Pages.swift b/App/Pages.swift index 8951a5c..116677b 100644 --- a/App/Pages.swift +++ b/App/Pages.swift @@ -172,8 +172,11 @@ struct Pages { let lines = stack(.vertical, 3, device.enumerated().map { label($1, Theme.font(m.caption, $0 == 0 ? .medium : .regular), $0 == 0 ? Theme.ink : Theme.muted, lines: 1, align: .right) }, align: .trailing) return stack(.horizontal, 10, [tile, name, spacer(), lines] + trailing, align: .center) } + // The names take the rest of the row: no width of theirs is left to iOS. let titles = stack(.vertical, 4, [name, label(device.joined(separator: " · "), Theme.font(m.caption), Theme.muted, lines: 2)]) - return stack(.horizontal, 12, [tile, titles, spacer()] + trailing, align: .center) + titles.setContentHuggingPriority(UILayoutPriority(1), for: .horizontal) + trailing.forEach { $0.setContentHuggingPriority(.required, for: .horizontal) } + return stack(.horizontal, 12, [tile, titles] + trailing, align: .center) } private func title(_ text: String, _ subtitle: String?, identifier: String? = nil, centered: Bool = false) -> UIView { @@ -190,6 +193,9 @@ struct Pages { heading.textAlignment = .center let views: [UIView] = [badge, heading] + lines.map { label($0, Theme.font(m.description), Theme.muted, align: .center) } let column = stack(.vertical, 10, views, align: .center) + // The text as wide as the page, centred in it: a width left to iOS is one iOS 12 + // can make a few letters (the companion's Storage access page did). + for view in views where view is UILabel { view.widthAnchor.constraint(equalTo: column.widthAnchor).isActive = true } column.setCustomSpacing(16, after: badge) column.isLayoutMarginsRelativeArrangement = true column.layoutMargins = UIEdgeInsets(top: m.regular ? 24 : 12, left: 0, bottom: 0, right: 0) diff --git a/App/RootViewController.swift b/App/RootViewController.swift index 23109f0..9dc6ed4 100644 --- a/App/RootViewController.swift +++ b/App/RootViewController.swift @@ -91,6 +91,8 @@ final class RootViewController: UIViewController, UIScrollViewDelegate { page.topAnchor.constraint(equalTo: scroll.contentLayoutGuide.topAnchor, constant: 8), page.bottomAnchor.constraint(equalTo: scroll.contentLayoutGuide.bottomAnchor, constant: -16), page.centerXAnchor.constraint(equalTo: scroll.centerXAnchor), + // Scrolls up and down only: the content is as wide as the screen. + scroll.contentLayoutGuide.widthAnchor.constraint(equalTo: scroll.frameLayoutGuide.widthAnchor), page.widthAnchor.constraint(lessThanOrEqualToConstant: metrics.contentWidth), width, widthCap, footerBar.leadingAnchor.constraint(equalTo: view.leadingAnchor), footerBar.trailingAnchor.constraint(equalTo: view.trailingAnchor), @@ -108,6 +110,8 @@ final class RootViewController: UIViewController, UIScrollViewDelegate { } private var sideConstraints: [NSLayoutConstraint] = [] private var headerTop: NSLayoutConstraint? + /// An empty footer is no height, not one iOS picks (LayoutCheck.swift). + private lazy var footerEmpty = footer.heightAnchor.constraint(equalToConstant: 0) /// A hairline under the header once the page scrolls beneath it. func scrollViewDidScroll(_ scrollView: UIScrollView) { @@ -199,6 +203,7 @@ final class RootViewController: UIViewController, UIScrollViewDelegate { footer.arrangedSubviews.forEach { $0.removeFromSuperview() } for view in Pages(self, metrics).footer() { footer.addArrangedSubview(view) } footerBar.isHidden = footer.arrangedSubviews.isEmpty + footerEmpty.isActive = footer.arrangedSubviews.isEmpty footerKey = key } diff --git a/ResizeAPFS.xcodeproj/project.pbxproj b/ResizeAPFS.xcodeproj/project.pbxproj index c2848fe..8b3550b 100644 --- a/ResizeAPFS.xcodeproj/project.pbxproj +++ b/ResizeAPFS.xcodeproj/project.pbxproj @@ -6,7 +6,7 @@ objects = { A00000000000000000000001 = { isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = YES; LastUpgradeCheck = 1600; TargetAttributes = { A00000000000000000000010 = { CreatedOnToolsVersion = 16.0; }; A00000000000000000000011 = { CreatedOnToolsVersion = 16.0; TestTargetID = A00000000000000000000010; }; }; }; buildConfigurationList = A00000000000000000000020; compatibilityVersion = "Xcode 15.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = (en, Base); mainGroup = A00000000000000000000002; packageReferences = (); productRefGroup = A00000000000000000000004; projectDirPath = ""; projectRoot = ""; targets = (A00000000000000000000010, A00000000000000000000011, A00000000000000000000012); }; A00000000000000000000002 = { isa = PBXGroup; children = (A00000000000000000000003, A00000000000000000000005, A00000000000000000000006, A00000000000000000000004); sourceTree = ""; }; - A00000000000000000000003 = { isa = PBXGroup; path = App; sourceTree = ""; children = (A00000000000000000000101, A00000000000000000000102, A00000000000000000000103, A00000000000000000000104, A00000000000000000000105, A00000000000000000000106, A00000000000000000000108, A00000000000000000000109, A0000000000000000000010A, A0000000000000000000010F, A00000000000000000000113, A0000000000000000000010B, A0000000000000000000010C, A0000000000000000000010D, A0000000000000000000010E); }; + A00000000000000000000003 = { isa = PBXGroup; path = App; sourceTree = ""; children = (A00000000000000000000101, A00000000000000000000102, A00000000000000000000103, A00000000000000000000104, A00000000000000000000105, A00000000000000000000106, A00000000000000000000108, A00000000000000000000109, A0000000000000000000010A, A0000000000000000000010F, A00000000000000000000113, A0000000000000000000010B, A0000000000000000000010C, A0000000000000000000010D, A0000000000000000000010E, A00000000000000000000120); }; A00000000000000000000004 = { isa = PBXGroup; name = Products; children = (A00000000000000000000110, A00000000000000000000111, A00000000000000000000112); sourceTree = ""; }; A00000000000000000000005 = { isa = PBXGroup; path = UITests; sourceTree = ""; children = (A00000000000000000000107); }; A00000000000000000000101 = { isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -18,6 +18,7 @@ A00000000000000000000108 = { isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; A00000000000000000000109 = { isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; A0000000000000000000010E = { isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dialog.swift; sourceTree = ""; }; + A00000000000000000000120 = { isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutCheck.swift; sourceTree = ""; }; A0000000000000000000010F = { isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ../Access/StorageAccess.swift; sourceTree = ""; }; A00000000000000000000113 = { isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedApp.swift; sourceTree = ""; }; A0000000000000000000010A = { isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pages.swift; sourceTree = ""; }; @@ -26,6 +27,7 @@ A0000000000000000000010D = { isa = PBXFileReference; lastKnownFileType = folder; path = Fonts; sourceTree = ""; }; A00000000000000000000209 = { isa = PBXBuildFile; fileRef = A00000000000000000000109; }; A0000000000000000000020E = { isa = PBXBuildFile; fileRef = A0000000000000000000010E; }; + A00000000000000000000220 = { isa = PBXBuildFile; fileRef = A00000000000000000000120; }; A0000000000000000000020F = { isa = PBXBuildFile; fileRef = A0000000000000000000010F; }; A00000000000000000000213 = { isa = PBXBuildFile; fileRef = A00000000000000000000113; }; A0000000000000000000020A = { isa = PBXBuildFile; fileRef = A0000000000000000000010A; }; @@ -45,7 +47,7 @@ A00000000000000000000207 = { isa = PBXBuildFile; fileRef = A00000000000000000000107; }; A00000000000000000000010 = { isa = PBXNativeTarget; buildConfigurationList = A00000000000000000000021; buildPhases = (A00000000000000000000030, A00000000000000000000031, A00000000000000000000032); buildRules = (); dependencies = (A00000000000000000000053); name = ResizeAPFS; packageProductDependencies = (); productName = ResizeAPFS; productReference = A00000000000000000000110; productType = "com.apple.product-type.application"; }; A00000000000000000000011 = { isa = PBXNativeTarget; buildConfigurationList = A00000000000000000000022; buildPhases = (A00000000000000000000033, A00000000000000000000034, A00000000000000000000035); buildRules = (); dependencies = (A00000000000000000000051); name = ResizeAPFSUITests; packageProductDependencies = (); productName = ResizeAPFSUITests; productReference = A00000000000000000000111; productType = "com.apple.product-type.bundle.ui-testing"; }; - A00000000000000000000030 = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = (A00000000000000000000201, A00000000000000000000202, A00000000000000000000203, A00000000000000000000204, A00000000000000000000205, A00000000000000000000209, A0000000000000000000020A, A0000000000000000000020F, A00000000000000000000213, A0000000000000000000020B, A0000000000000000000020E); runOnlyForDeploymentPostprocessing = 0; }; + A00000000000000000000030 = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = (A00000000000000000000201, A00000000000000000000202, A00000000000000000000203, A00000000000000000000204, A00000000000000000000205, A00000000000000000000209, A0000000000000000000020A, A0000000000000000000020F, A00000000000000000000213, A0000000000000000000020B, A0000000000000000000020E, A00000000000000000000220); runOnlyForDeploymentPostprocessing = 0; }; A00000000000000000000031 = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = (A00000000000000000000206); runOnlyForDeploymentPostprocessing = 0; }; A00000000000000000000032 = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = (A00000000000000000000208, A0000000000000000000020C, A0000000000000000000020D); runOnlyForDeploymentPostprocessing = 0; }; A00000000000000000000033 = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = (A00000000000000000000207); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/scripts/check-layout.sh b/scripts/check-layout.sh new file mode 100755 index 0000000..1d10e08 --- /dev/null +++ b/scripts/check-layout.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# The app's layout check (App/LayoutCheck.swift) in an iOS simulator: every +# Storage access page and dialog at every iPhone, iPod touch and iPad size. +# Prints every problem; fails on any. ORCHARD_LAYOUT_SHOTS=DIR also saves a +# picture of each at every upright size. +set -euo pipefail +cd "$(dirname "$0")/.." +build=$PWD/.build/layout-check +app=$build/ResizeAPFS.app +rm -rf "$build" && mkdir -p "$app" +target=$(uname -m)-apple-ios15.0-simulator +sdk=$(xcrun --sdk iphonesimulator --show-sdk-path) +swiftc() { xcrun --sdk iphonesimulator swiftc -target "$target" -sdk "$sdk" -swift-version 5 "$@"; } +swiftc -parse-as-library -emit-library -static -emit-module -module-name ResizeCore \ + -emit-module-path "$build/ResizeCore.swiftmodule" Sources/ResizeCore/*.swift -o "$build/libResizeCore.a" +swiftc -I "$build" -L "$build" -lResizeCore App/*.swift Access/StorageAccess.swift -o "$app/ResizeAPFS" +cp App/Info.plist "$app/Info.plist" +plutil -replace CFBundleSupportedPlatforms -json '["iPhoneSimulator"]' "$app/Info.plist" +for key in CFBundleExecutable CFBundleIdentifier CFBundleName; do + value=$(plutil -extract "$key" raw "$app/Info.plist") + case $value in *'$('*) plutil -replace "$key" -string "$([ $key = CFBundleIdentifier ] && echo org.orchardlinux.resize-apfs || echo ResizeAPFS)" "$app/Info.plist";; esac +done +cp -R App/Fonts "$app/Fonts" +codesign --force --sign - --timestamp=none "$app" >/dev/null +id=$(plutil -extract CFBundleIdentifier raw "$app/Info.plist") + +udid() { plutil -extract devices json -o - - | { grep -o '"udid" *: *"[^"]*"' || true; } | head -1 | cut -d'"' -f4; } +device=$(xcrun simctl list devices booted -j | udid) +if [ -z "$device" ]; then + device=$(xcrun simctl list devices available -j | udid) + [ -n "$device" ] || { echo 'No iOS simulator available' >&2; exit 1; } + echo "Booting simulator $device" + xcrun simctl boot "$device" + trap 'xcrun simctl shutdown "$device"' EXIT +fi +xcrun simctl bootstatus "$device" -b >/dev/null +xcrun simctl install "$device" "$app" +[ -z "${ORCHARD_LAYOUT_SHOTS:-}" ] || { mkdir -p "$ORCHARD_LAYOUT_SHOTS"; export SIMCTL_CHILD_ORCHARD_LAYOUT_SHOTS=$ORCHARD_LAYOUT_SHOTS; } +log=$(SIMCTL_CHILD_ORCHARD_LAYOUT_CHECK=1 xcrun simctl launch --console --terminate-running-process "$device" "$id" 2>&1) +echo "$log" | grep '^LAYOUT' || { echo "$log" | tail -20; exit 1; } +echo "$log" | grep -qx 'LAYOUT OK' From 180ecb9eef7f44bb7d1dd1e9805bb2a86d62c8cd Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 13:04:57 +0800 Subject: [PATCH 2/2] Layout check: run once the app has launched, output flushed On the CI's Intel Mac the check took longer than iOS lets a launch take, so iOS ended the app before it printed anything. Assisted-by: LLM --- App/AppDelegate.swift | 5 +++-- App/LayoutCheck.swift | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/App/AppDelegate.swift b/App/AppDelegate.swift index c69adf8..d5e89e2 100644 --- a/App/AppDelegate.swift +++ b/App/AppDelegate.swift @@ -12,7 +12,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { let pages: [(String, StorageAccess.Phase)] = [("access", .start), ("access-working", .getting), ("access-failed", .failed)] let dialogs = [("dialog-stop", DialogController(title: "Stop resizing?", message: "The current step finishes first. APFS keeps the size it has then and the partition stays 64 GB. You can continue or grow APFS back later.", action: "Stop", cancel: "Keep resizing") {}), ("dialog-snapshot", DialogController(title: "Remove system snapshot?", message: "iOS then starts without it, as after checkra1n’s Install Cydia, and can shrink further. It can’t be brought back.", action: "Remove") {})] - LayoutCheck.finish(pages.flatMap { name, phase in + LayoutCheck.start { pages.flatMap { name, phase in LayoutCheck.problems(name) { _ in let model = AppModel() model.showAccessPage(phase) @@ -20,7 +20,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { controller.loadViewIfNeeded() return controller } - } + dialogs.flatMap { name, dialog in LayoutCheck.problems(name) { _ in dialog } }) + } + dialogs.flatMap { name, dialog in LayoutCheck.problems(name) { _ in dialog } }} + return true } // UI tests check the iPod touch's 320 × 568 pt layout, which current simulators lack. if ProcessInfo.processInfo.arguments.contains("--ipod-size") { frame = CGRect(x: 0, y: 0, width: 320, height: 568) } diff --git a/App/LayoutCheck.swift b/App/LayoutCheck.swift index 5087cbc..7381ef5 100644 --- a/App/LayoutCheck.swift +++ b/App/LayoutCheck.swift @@ -57,8 +57,15 @@ enum LayoutCheck { return problems } + /// Runs `check` once the app has launched (iOS ends an app whose launch takes as long + /// as the check does on a slow Mac), then prints its problems and ends the app. + static func start(_ check: @escaping () -> [String]) { + DispatchQueue.main.async { finish(check()) } + } + /// Prints the problems and ends the app: status 0 without any. static func finish(_ problems: [String]) -> Never { + setvbuf(stdout, nil, _IOLBF, 0) problems.forEach { print("LAYOUT: \($0)") } print(problems.isEmpty ? "LAYOUT OK" : "LAYOUT FAILED: \(problems.count) problems") exit(problems.isEmpty ? 0 : 1)