From 1604a6b3e3373cfef2655535f908f682c8fd1a96 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 23 Nov 2026 09:38:58 -0800 Subject: [PATCH] iOS: Duo orientation strict (folded portrait, unfolded landscape, never free), lock changes only after hinge reading holds 450 ms, orient log; build 54 Co-Authored-By: Claude Opus 5.5 --- ios/Stemify/UI/Nav.swift | 43 +++++++++++++++++++--------------------- ios/project.yml | 2 +- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/ios/Stemify/UI/Nav.swift b/ios/Stemify/UI/Nav.swift index b5bc2ed..2d30b12 100644 --- a/ios/Stemify/UI/Nav.swift +++ b/ios/Stemify/UI/Nav.swift @@ -137,45 +137,42 @@ final class Ui { lockOrientation() } - /// Split (unfolded) goes landscape at once. Portrait waits a moment and checks again, so a - /// frame without a hinge reading mid-rotation can't throw an unfolded phone back upright. - /// Back in the foreground: the phone may have been folded or unfolded meanwhile. - /// The split/unfolded flags are from before the app left, so locking on them at once can force - /// landscape on a phone folded meanwhile. Free the rotation while away and decide again once - /// the window has settled to the screen it came back on. - func resumed() { - Task { @MainActor in - try? await Task.sleep(for: .milliseconds(300)) - self.lockOrientation() - } - } + /// The Duo is never free to turn: folded is portrait only, unfolded is landscape only. + /// Hinge readings flicker while the window settles (coming back from the background, mid + /// fold), so the lock only changes once a reading has held for a moment. Other iPhones turn freely. + private var lockGen = 0 - /// Folded stays locked upright: while audio plays the app lives on in the background and iOS - /// would turn the free window with the phone, so it came back sideways. Unfolding meanwhile is - /// still caught on return (upright unfolded marks the phone unfolded and turns it). - /// Unfolded frees rotation, so a phone folded meanwhile isn't held in landscape. - func backgrounded() { - if folded { Orientation.lock(.portrait) } else { Orientation.lock(.allButUpsideDown) } - } + func resumed() { lockOrientation() } + + /// Leaves the lock as it is: freeing it let iOS turn the window while audio kept the app alive. + func backgrounded() {} private func lockOrientation() { - if split || unfolded { Orientation.lock(.landscape); return } - guard folded else { Orientation.lock(.allButUpsideDown); return } + guard duo || split || unfolded else { Orientation.lock(.allButUpsideDown); return } + let want: UIInterfaceOrientationMask = (split || unfolded) ? .landscape : .portrait + lockGen += 1 + let gen = lockGen Task { @MainActor in - try? await Task.sleep(for: .milliseconds(400)) - if self.folded { Orientation.lock(.portrait) } + try? await Task.sleep(for: .milliseconds(450)) + guard gen == self.lockGen else { return } + let now: UIInterfaceOrientationMask = (self.split || self.unfolded) ? .landscape : .portrait + guard now == want else { return } + Log.shared.info("orient", "lock \(want == .landscape ? "landscape" : "portrait") split=\(self.split) unfolded=\(self.unfolded)") + Orientation.lock(want) } } func setUnfolded(_ on: Bool) { guard on != unfolded else { return } unfolded = on + Log.shared.info("orient", "unfolded \(on)") lockOrientation() } func setSplit(_ on: Bool) { guard on != split else { return } split = on + Log.shared.info("orient", "split \(on)") lockOrientation() if on { nowPlayingOpen = false diff --git a/ios/project.yml b/ios/project.yml index 6f57171..f36d381 100644 --- a/ios/project.yml +++ b/ios/project.yml @@ -9,7 +9,7 @@ settings: # iOS needs a plain number for the bundle version; the label is what the app and releases show. MARKETING_VERSION: "0.10.1" VERSION_LABEL: "0.10.1" - CURRENT_PROJECT_VERSION: "53" + CURRENT_PROJECT_VERSION: "54" # Dev builds override these (build-ipa.sh dev) so they install next to the release app. APP_ID: org.cdnutter.stemify APP_NAME: Stemify