@@ -72,7 +72,12 @@ struct AccountSecurityState: Equatable {
7272 var availableTimeoutActions : [ SessionTimeoutAction ] = SessionTimeoutAction . allCases
7373
7474 /// The timeout options to show when the policy for maximum timeout value is in effect.
75- var availableTimeoutOptions : [ SessionTimeoutValue ] = SessionTimeoutValue . allCases
75+ var availableTimeoutOptions : [ SessionTimeoutValue ] {
76+ computeAvailableTimeoutOptions (
77+ type: policyTimeoutType,
78+ value: policyTimeoutValue,
79+ )
80+ }
7681
7782 /// The state of the badges in the settings tab.
7883 var badgeState : SettingsBadgeState ?
@@ -97,36 +102,9 @@ struct AccountSecurityState: Equatable {
97102
98103 /// Whether the unlock with pin code toggle is on.
99104 var isUnlockWithPINCodeOn : Bool = false
100-
105+
101106 /// The policy's maximum vault timeout value.
102- /// When set, all timeout values greater than this are no longer shown.
103- var policyTimeoutValue : Int = 0 {
104- didSet {
105- availableTimeoutOptions = SessionTimeoutValue . allCases. filter { option in
106- switch policyTimeoutType {
107- case . never:
108- return true
109- case . onAppRestart:
110- return option != . never
111- case . immediately:
112- return option == . immediately
113- case . custom:
114- if option. isCustomPlaceholder { return true }
115- guard let time = option. minutesValue else { return false }
116- return time <= policyTimeoutValue
117- case nil ,
118- . predefined:
119- if policyTimeoutValue > 0 {
120- if option. isCustomPlaceholder { return true }
121- guard let time = option. minutesValue else { return false }
122- return time <= policyTimeoutValue
123- } else {
124- return true
125- }
126- }
127- }
128- }
129- }
107+ var policyTimeoutValue : Int = 0
130108
131109 /// The policy's timeout action, if set.
132110 var policyTimeoutAction : SessionTimeoutAction ?
@@ -278,4 +256,38 @@ struct AccountSecurityState: Equatable {
278256 )
279257 }
280258 }
259+
260+ /// Returns the available timeout options based on policy type and value.
261+ ///
262+ /// - Parameters:
263+ /// - type: The policy's timeout type, if set.
264+ /// - value: The policy's maximum vault timeout value.
265+ /// - Returns: Filtered array of available session timeout values.
266+ private func computeAvailableTimeoutOptions(
267+ type: SessionTimeoutType ? ,
268+ value: Int
269+ ) -> [ SessionTimeoutValue ] {
270+ SessionTimeoutValue . allCases. filter { option in
271+ switch type {
272+ case . never:
273+ return true
274+ case . onAppRestart:
275+ return option != . never
276+ case . immediately:
277+ return option == . immediately
278+ case . custom:
279+ if option. isCustomPlaceholder { return true }
280+ guard let time = option. minutesValue else { return false }
281+ return time <= value
282+ case nil , . predefined:
283+ if value > 0 {
284+ if option. isCustomPlaceholder { return true }
285+ guard let time = option. minutesValue else { return false }
286+ return time <= value
287+ } else {
288+ return true
289+ }
290+ }
291+ }
292+ }
281293}
0 commit comments