Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ concurrency:
cancel-in-progress: true

jobs:
format:
name: Format
runs-on: xcode-27
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Select latest stable Xcode
uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
with:
xcode-version: latest-stable

- name: Check formatting
run: xcrun swift-format lint --strict --recursive --parallel .

unit-tests:
name: Unit tests
runs-on: xcode-27
Expand Down
7 changes: 7 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": 1,
"indentation": {
"spaces": 4
},
"lineLength": 150
}
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Folders are synchronized groups. Target membership comes from exception lists in
- Don't change `CURRENT_PROJECT_VERSION`. Version changes only touch `MARKETING_VERSION`.

## Code
- Format before committing: `xcrun swift-format format -i -r -p .` (config in `.swift-format`).
CI fails on any formatting difference.
- User-facing text lives in `Normal/Resources/Localizable.xcstrings` (English only).
Xcode generates it, so don't edit it by hand. After changing text, sync it and commit
the result. This adds new strings and removes unused ones; Xcode adds the comments
Expand Down
47 changes: 25 additions & 22 deletions Normal/App/NormalApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ struct NormalApp: App {
}

if UITestSupport.isActive {
context.insert(SelectedApps(
selection: UITestSupport.mainSelection,
customDomains: UITestSupport.mainCustomDomains
))
context.insert(
SelectedApps(
selection: UITestSupport.mainSelection,
customDomains: UITestSupport.mainCustomDomains
))
if !UITestSupport.noKeys {
context.insert(Key(name: "Test Key", type: .qr, rawValue: UITestSupport.stubScanValue))
}
Expand All @@ -55,26 +56,28 @@ struct NormalApp: App {
context.insert(Key(name: "Group Key", type: .qr, rawValue: "GROUP-VALUE", groupID: group.id))
}
if UITestSupport.seedLocationKey {
context.insert(Key(
name: "Test Place",
latitude: UITestSupport.locationKeyFarAway ? 40.7484 : 37.33182,
longitude: UITestSupport.locationKeyFarAway ? -73.9857 : -122.03118,
radiusMeters: 400,
radiusKind: .unblock
))
context.insert(
Key(
name: "Test Place",
latitude: UITestSupport.locationKeyFarAway ? 40.7484 : 37.33182,
longitude: UITestSupport.locationKeyFarAway ? -73.9857 : -122.03118,
radiusMeters: 400,
radiusKind: .unblock
))
}
if UITestSupport.seedSchedule {
context.insert(BlockSchedule(
name: "Test Schedule",
selection: FamilyActivitySelection(),
startHour: 9,
startMinute: 0,
durationMinutes: 60,
weekdays: [2, 3, 4, 5, 6],
shouldBlock: true,
isTimed: false,
isEnabled: true
))
context.insert(
BlockSchedule(
name: "Test Schedule",
selection: FamilyActivitySelection(),
startHour: 9,
startMinute: 0,
durationMinutes: 60,
weekdays: [2, 3, 4, 5, 6],
shouldBlock: true,
isTimed: false,
isEnabled: true
))
}
}

Expand Down
12 changes: 7 additions & 5 deletions Normal/App/UITestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ enum UITestSupport {

static let isActive = arguments.contains("-uiTestMode")

static let isUnitTestHost = !isActive
static let isUnitTestHost =
!isActive
&& ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil

static let skipOnboarding = arguments.contains("-uiTestSkipOnboarding")
Expand Down Expand Up @@ -54,10 +55,11 @@ enum UITestSupport {

private static func selection(apps: [UInt8]) -> FamilyActivitySelection {
var selection = FamilyActivitySelection()
selection.applicationTokens = Set(apps.compactMap { id in
let json = #"{"data":"\#(Data([id]).base64EncodedString())"}"#
return try? JSONDecoder().decode(ApplicationToken.self, from: Data(json.utf8))
})
selection.applicationTokens = Set(
apps.compactMap { id in
let json = #"{"data":"\#(Data([id]).base64EncodedString())"}"#
return try? JSONDecoder().decode(ApplicationToken.self, from: Data(json.utf8))
})
return selection
}

Expand Down
2 changes: 1 addition & 1 deletion Normal/Extensions/View+UnblockAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum UnblockAlert {

var message: Text {
switch self {
case let .failed(error):
case .failed(let error):
Text(error.localizedDescription)
case .mayEndLate:
Text("iOS only tracks 20 schedules and timers at once, so this unblock may end up to 30 minutes late.")
Expand Down
6 changes: 4 additions & 2 deletions Normal/Intents/AppBlockIntentPerformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ final class AppBlockIntentPerformer: BlockIntentPerforming {
logger.info("Block intent: all")
let settings = try intents.validatedSettings(requiringKey: true)
let mainSelection = try intents.mainSelection(settings: settings)
let wasAlreadyBlocked = intents.screenTimeService.blockStatus(of: .all(mainSelection), settings: settings) == .all
let wasAlreadyBlocked =
intents.screenTimeService.blockStatus(of: .all(mainSelection), settings: settings) == .all
&& intents.timedUnblockService.activeUnblocks.isEmpty

BlockActions.blockAll(
Expand All @@ -50,7 +51,8 @@ final class AppBlockIntentPerformer: BlockIntentPerforming {
logger.info("Block intent: group")
let settings = try intents.validatedSettings(requiringKey: true, groupID: id)
let group = try intents.group(id: id)
let wasAlreadyBlocked = intents.screenTimeService.blockStatus(of: .group(group), settings: settings) == .all
let wasAlreadyBlocked =
intents.screenTimeService.blockStatus(of: .group(group), settings: settings) == .all
&& !intents.timedUnblockService.isGroupUnblockActive(groupId: id)

BlockActions.blockGroup(
Expand Down
33 changes: 17 additions & 16 deletions Normal/Intents/AppUnblockIntentPerformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ final class AppUnblockIntentPerformer: UnblockIntentPerforming {
let settings: Settings
let target: UnblockTarget
switch try readiness(for: request) {
case let .settled(outcome):
case .settled(let outcome):
return outcome
case let .ready(readySettings, readyTarget):
case .ready(let readySettings, let readyTarget):
settings = readySettings
target = readyTarget
}

let keys = try Key.scoped(intents.keys(), toGroup: request.groupID)
guard keyType(for: request, keys: keys, settings: settings, group: target.group) == .location,
settings.unblockLength(for: request.duration, group: target.group) != nil
settings.unblockLength(for: request.duration, group: target.group) != nil
else { return .continueInApp(.checkKey) }
let radiusKind = Key.existingLocationKind(in: keys) ?? .unblock

Expand All @@ -74,27 +74,28 @@ final class AppUnblockIntentPerformer: UnblockIntentPerforming {
}

switch try readiness(for: request) {
case let .settled(outcome):
case .settled(let outcome):
return outcome
case let .ready(settings, target):
case .ready(let settings, let target):
guard let length = settings.unblockLength(for: request.duration, group: target.group),
let grant = UnblockGrant(target, proof: proof)
let grant = UnblockGrant(target, proof: proof)
else { return .continueInApp(.checkKey) }
return try start(grant, for: length, settings: settings)
}
}

func continueInApp(_ request: UnblockRequest) {
unlockInbox.post(UnblockRequest(
groupID: request.groupID,
duration: request.duration,
keyType: keyType(
for: request,
keys: Key.scoped((try? intents.keys()) ?? [], toGroup: request.groupID),
settings: intents.settings(),
group: request.groupID.flatMap { try? intents.group(id: $0) }
)
))
unlockInbox.post(
UnblockRequest(
groupID: request.groupID,
duration: request.duration,
keyType: keyType(
for: request,
keys: Key.scoped((try? intents.keys()) ?? [], toGroup: request.groupID),
settings: intents.settings(),
group: request.groupID.flatMap { try? intents.group(id: $0) }
)
))
}

private enum Readiness {
Expand Down
2 changes: 1 addition & 1 deletion Normal/Intents/IntentContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct IntentContext {

func mainSelection(settings: Settings) throws -> SelectedApps {
guard let mainSelection = try context.fetch(FetchDescriptor<SelectedApps>()).first,
mainSelection.hasItemsToBlock(customDomainsEnabled: settings.enableCustomDomains)
mainSelection.hasItemsToBlock(customDomainsEnabled: settings.enableCustomDomains)
else { throw BlockIntentError.noAppsSelected }
return mainSelection
}
Expand Down
14 changes: 7 additions & 7 deletions Normal/Intents/UnblockIntents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct UnblockAllIntent: LiveActivityIntent {
return .result(dialog: "").withoutDialog
case .timedUnblockRunning:
return .result(dialog: "A timed unblock is already running for all apps.")
case let .continueInApp(reason):
case .continueInApp(let reason):
return try await continueInApp(
request,
reason: reason,
Expand Down Expand Up @@ -139,9 +139,9 @@ struct UnblockGroupIntent: LiveActivityIntent {
switch try await performer.unblock(request) {
case .unblocked, .alreadyUnblocked:
return .result(dialog: "").withoutDialog
case let .timedUnblockRunning(name):
case .timedUnblockRunning(let name):
return .result(dialog: "A timed unblock is already running for \(name).")
case let .continueInApp(reason):
case .continueInApp(let reason):
return try await continueInApp(
request,
reason: reason,
Expand Down Expand Up @@ -193,8 +193,8 @@ struct OpenUnblockIntent: AppIntent {
}
}

private extension AppIntent {
func continueInApp(
extension AppIntent {
fileprivate func continueInApp(
_ request: UnblockRequest,
reason: HandOffReason,
performer: any UnblockIntentPerforming,
Expand Down Expand Up @@ -222,8 +222,8 @@ private extension AppIntent {
}
}

private extension IntentResultContainer<Never, Never, Never, IntentDialog> {
var withoutDialog: Self {
extension IntentResultContainer<Never, Never, Never, IntentDialog> {
fileprivate var withoutDialog: Self {
var result = self
result.dialog = nil
return result
Expand Down
7 changes: 4 additions & 3 deletions Normal/Models/AppGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ final class AppGroup: Identifiable {
var durationOverride: DefaultOverride<TimedUnblockDuration> {
get {
guard overridesDefaultDuration else { return .appDefault }
return defaultUnblockSeconds
return
defaultUnblockSeconds
.flatMap(TimedUnblockDuration.init(validating:))
.map(DefaultOverride.value) ?? .none
}
set {
overridesDefaultDuration = newValue != .appDefault
if case let .value(duration) = newValue {
if case .value(let duration) = newValue {
defaultUnblockSeconds = duration.seconds
} else {
defaultUnblockSeconds = nil
Expand All @@ -48,7 +49,7 @@ final class AppGroup: Identifiable {
}
set {
overridesDefaultKey = newValue != .appDefault
if case let .value(keyType) = newValue {
if case .value(let keyType) = newValue {
defaultKeyType = keyType
} else {
defaultKeyType = nil
Expand Down
2 changes: 1 addition & 1 deletion Normal/Models/BlockSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class BlockSchedule: Identifiable {
var weekdayLabels: [String] {
let symbols = Calendar.current.shortWeekdaySymbols
return weekdays.sorted().compactMap { day in
guard (1 ... 7).contains(day) else { return nil }
guard (1...7).contains(day) else { return nil }
return symbols[day - 1]
}
}
Expand Down
6 changes: 4 additions & 2 deletions Normal/Models/LocationRadiusKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ enum LocationRadiusKind: String, Codable, CaseIterable, Identifiable, Sendable {

var pickerFooter: String {
switch self {
case .unblock: "Your location key will only work while you're inside one of these areas. Set one up to unlock at the office, the gym, or anywhere you choose."
case .block: "Your location key will only work while you're outside the selected areas. Set one up to lock yourself out at home, school, or anywhere you choose."
case .unblock:
"Your location key will only work while you're inside one of these areas. Set one up to unlock at the office, the gym, or anywhere you choose."
case .block:
"Your location key will only work while you're outside the selected areas. Set one up to lock yourself out at home, school, or anywhere you choose."
}
}
}
2 changes: 1 addition & 1 deletion Normal/Models/OnboardingStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum OnboardingStep: String, CaseIterable, Sendable {

func next() -> OnboardingStep {
guard let index = Self.allCases.firstIndex(of: self),
index + 1 < Self.allCases.count
index + 1 < Self.allCases.count
else { return .complete }
return Self.allCases[index + 1]
}
Expand Down
4 changes: 2 additions & 2 deletions Normal/Models/Settings+GroupDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ extension Settings {
switch group?.durationOverride ?? .appDefault {
case .appDefault: defaultDuration
case .none: nil
case let .value(duration): unblockDurations.contains(duration) ? duration : nil
case .value(let duration): unblockDurations.contains(duration) ? duration : nil
}
}

func defaultKeyType(for group: AppGroup?) -> KeyType? {
switch group?.keyOverride ?? .appDefault {
case .appDefault: defaultKeyType
case .none: nil
case let .value(keyType): keyType
case .value(let keyType): keyType
}
}
}
6 changes: 3 additions & 3 deletions Normal/Models/Settings+UnblockDurations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extension Settings {
var defaultDuration: TimedUnblockDuration? {
get {
guard let seconds = defaultUnblockSeconds ?? defaultUnblockDuration?.rawValue,
let duration = TimedUnblockDuration(validating: seconds),
unblockDurations.contains(duration)
let duration = TimedUnblockDuration(validating: seconds),
unblockDurations.contains(duration)
else { return nil }
return duration
}
Expand All @@ -35,7 +35,7 @@ extension Settings {

func unblockLength(for request: UnlockDurationRequest, group: AppGroup?) -> UnblockLength? {
switch request {
case let .fixed(duration): .timed(duration)
case .fixed(let duration): .timed(duration)
case .permanent: .permanent
case .useDefault: defaultDuration(for: group).map(UnblockLength.timed)
case .ask: nil
Expand Down
6 changes: 3 additions & 3 deletions Normal/Models/UsageLimitEditPolicy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ nonisolated enum UsageLimitEdit: Equatable, Sendable {
var isLoosening: Bool {
switch self {
case .create: false
case let .adjust(from, to, dropsCoverage): to > from || dropsCoverage
case .adjust(let from, let to, let dropsCoverage): to > from || dropsCoverage
case .delete, .changeReset: true
}
}
Expand Down Expand Up @@ -48,7 +48,7 @@ nonisolated enum UsageLimitLockState: Equatable, Sendable {
case locked(until: Date)

var lockedUntil: Date? {
if case let .locked(until) = self {
if case .locked(let until) = self {
return until
}
return nil
Expand Down Expand Up @@ -88,7 +88,7 @@ nonisolated enum UsageLimitEditPolicy {
switch lockState(anchor: anchor, now: now) {
case .unlocked: return .allowed(.cooldownElapsed)
case .grace: return .allowed(.grace)
case let .locked(until): return .locked(until: until)
case .locked(let until): return .locked(until: until)
}
}

Expand Down
Loading