Ivan Valkou 5 gadi atpakaļ
vecāks
revīzija
8c69d2c41e

+ 79 - 0
.gitignore

@@ -0,0 +1,79 @@
+# Xcode
+#
+# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
+
+# macOS
+.DS_Store
+
+## Build generated
+build/
+DerivedData/
+R.generated.swift
+
+## Various settings
+!default.mode1v3
+!default.mode2v3
+!default.pbxuser
+!default.perspectivev3
+*.mode1v3
+*.mode2v3
+*.moved-aside
+*.pbxuser
+*.perspectivev3
+*.xccheckout
+*.xcscmblueprint
+xcuserdata/
+
+## Other
+*.moved-aside
+*.xccheckout
+*.xcscmblueprint
+
+## Obj-C/Swift specific
+*.hmap
+*.ipa
+*.dSYM.zip
+*.dSYM
+
+## Playgrounds
+timeline.xctimeline
+playground.xcworkspace
+
+# Swift Package Manager
+#
+# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
+# Packages/
+# Package.pins
+# Package.resolved
+.build/
+
+# CocoaPods
+#
+# We recommend against adding the Pods directory to your .gitignore. However
+# you should judge for yourself, the pros and cons are mentioned at:
+# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
+#
+# Pods/
+
+# Carthage
+#
+# Add this line if you want to avoid checking in source code from Carthage dependencies.
+# Carthage/Checkouts
+
+Carthage/Build
+
+# IDEA project files
+.idea/*
+
+# fastlane
+#
+# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
+# screenshots whenever they are needed.
+# For more information about the recommended setup visit:
+# https://docs.fastlane.tools/best-practices/source-control/#source-control
+
+fastlane/report.xml
+fastlane/Preview.html
+fastlane/screenshots
+fastlane/test_output
+fastlane/FastlaneRunner

+ 16 - 0
BuildTools/Package.resolved

@@ -0,0 +1,16 @@
+{
+  "object": {
+    "pins": [
+      {
+        "package": "SwiftFormat",
+        "repositoryURL": "https://github.com/nicklockwood/SwiftFormat",
+        "state": {
+          "branch": null,
+          "revision": "d1c8a16cc21a3dfc577fe5e881509501ed22d0ce",
+          "version": "0.47.11"
+        }
+      }
+    ]
+  },
+  "version": 1
+}

+ 11 - 0
BuildTools/Package.swift

@@ -0,0 +1,11 @@
+// swift-tools-version:5.1
+import PackageDescription
+
+let package = Package(
+    name: "BuildTools",
+    platforms: [.macOS(.v10_11)],
+    dependencies: [
+        .package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.41.2")
+    ],
+    targets: [.target(name: "BuildTools", path: "")]
+)

+ 0 - 0
BuildTools/main.swift


+ 22 - 8
FreeAPS.xcodeproj/project.pbxproj

@@ -34,10 +34,8 @@
 		3811DE4E25C9D4B800A708ED /* AuthotizedRootRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE4925C9D4B800A708ED /* AuthotizedRootRootView.swift */; };
 		3811DE4F25C9D4B800A708ED /* AuthotizedRootDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE4A25C9D4B800A708ED /* AuthotizedRootDataFlow.swift */; };
 		3811DE5025C9D4B800A708ED /* AuthotizedRootProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE4B25C9D4B800A708ED /* AuthotizedRootProvider.swift */; };
-		3811DE5A25C9D4D500A708ED /* CheckBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE5225C9D4D500A708ED /* CheckBox.swift */; };
 		3811DE5C25C9D4D500A708ED /* Formatters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE5425C9D4D500A708ED /* Formatters.swift */; };
 		3811DE5D25C9D4D500A708ED /* Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE5525C9D4D500A708ED /* Publisher.swift */; };
-		3811DE5E25C9D4D500A708ED /* FlowStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE5625C9D4D500A708ED /* FlowStack.swift */; };
 		3811DE5F25C9D4D500A708ED /* ProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE5725C9D4D500A708ED /* ProgressBar.swift */; };
 		3811DE6125C9D4D500A708ED /* ViewModifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE5925C9D4D500A708ED /* ViewModifiers.swift */; };
 		3811DE6A25C9D62600A708ED /* OnboardingBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DE6425C9D62600A708ED /* OnboardingBuilder.swift */; };
@@ -116,10 +114,8 @@
 		3811DE4925C9D4B800A708ED /* AuthotizedRootRootView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthotizedRootRootView.swift; sourceTree = "<group>"; };
 		3811DE4A25C9D4B800A708ED /* AuthotizedRootDataFlow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthotizedRootDataFlow.swift; sourceTree = "<group>"; };
 		3811DE4B25C9D4B800A708ED /* AuthotizedRootProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthotizedRootProvider.swift; sourceTree = "<group>"; };
-		3811DE5225C9D4D500A708ED /* CheckBox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckBox.swift; sourceTree = "<group>"; };
 		3811DE5425C9D4D500A708ED /* Formatters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Formatters.swift; sourceTree = "<group>"; };
 		3811DE5525C9D4D500A708ED /* Publisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Publisher.swift; sourceTree = "<group>"; };
-		3811DE5625C9D4D500A708ED /* FlowStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlowStack.swift; sourceTree = "<group>"; };
 		3811DE5725C9D4D500A708ED /* ProgressBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressBar.swift; sourceTree = "<group>"; };
 		3811DE5925C9D4D500A708ED /* ViewModifiers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModifiers.swift; sourceTree = "<group>"; };
 		3811DE6425C9D62600A708ED /* OnboardingBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingBuilder.swift; sourceTree = "<group>"; };
@@ -550,8 +546,6 @@
 			isa = PBXGroup;
 			children = (
 				3811DEE325CA063400A708ED /* PropertyWrappers */,
-				3811DE5225C9D4D500A708ED /* CheckBox.swift */,
-				3811DE5625C9D4D500A708ED /* FlowStack.swift */,
 				3811DE5425C9D4D500A708ED /* Formatters.swift */,
 				3811DE5725C9D4D500A708ED /* ProgressBar.swift */,
 				3811DE5525C9D4D500A708ED /* Publisher.swift */,
@@ -568,6 +562,7 @@
 			isa = PBXNativeTarget;
 			buildConfigurationList = 388E596725AD948E0019842D /* Build configuration list for PBXNativeTarget "FreeAPS" */;
 			buildPhases = (
+				3811DEF525CA169200A708ED /* Swiftformat */,
 				388E595425AD948C0019842D /* Sources */,
 				388E595525AD948C0019842D /* Frameworks */,
 				388E595625AD948C0019842D /* Resources */,
@@ -635,6 +630,27 @@
 		};
 /* End PBXResourcesBuildPhase section */
 
+/* Begin PBXShellScriptBuildPhase section */
+		3811DEF525CA169200A708ED /* Swiftformat */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputFileListPaths = (
+			);
+			inputPaths = (
+			);
+			name = Swiftformat;
+			outputFileListPaths = (
+			);
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "source \"${SRCROOT}\"/scripts/swiftformat.sh\n\n";
+		};
+/* End PBXShellScriptBuildPhase section */
+
 /* Begin PBXSourcesBuildPhase section */
 		388E595425AD948C0019842D /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
@@ -684,7 +700,6 @@
 				3811DE5D25C9D4D500A708ED /* Publisher.swift in Sources */,
 				3811DEAE25C9D88300A708ED /* Cache.swift in Sources */,
 				3811DEAD25C9D88300A708ED /* UserDefaults+Cache.swift in Sources */,
-				3811DE5A25C9D4D500A708ED /* CheckBox.swift in Sources */,
 				3811DE2225C9D48300A708ED /* MainProvider.swift in Sources */,
 				3811DE0C25C9D32F00A708ED /* BaseProvider.swift in Sources */,
 				3811DE5C25C9D4D500A708ED /* Formatters.swift in Sources */,
@@ -692,7 +707,6 @@
 				3811DEC525C9D99900A708ED /* StorageContainer.swift in Sources */,
 				3811DE7F25C9D6D300A708ED /* LoginBuilder.swift in Sources */,
 				3811DE3525C9D49500A708ED /* HomeRootView.swift in Sources */,
-				3811DE5E25C9D4D500A708ED /* FlowStack.swift in Sources */,
 				3811DEC325C9D99900A708ED /* UIContainer.swift in Sources */,
 				3811DE6125C9D4D500A708ED /* ViewModifiers.swift in Sources */,
 				3811DEAC25C9D88300A708ED /* NetworkManager.swift in Sources */,

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
FreeAPS/Resources/javascript/autosens-bundle.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
FreeAPS/Resources/javascript/basal-set-temp-bundle.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
FreeAPS/Resources/javascript/determine-basal-bundle.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
FreeAPS/Resources/javascript/iob-bundle.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
FreeAPS/Resources/javascript/meal-bundle.js


+ 1 - 9
FreeAPS/Sources/Application/FreeAPSApp.swift

@@ -1,15 +1,7 @@
-//
-//  FreeAPSApp.swift
-//  FreeAPS
-//
-//  Created by Ivan Valkou on 12.01.2021.
-//
-
 import SwiftUI
 import Swinject
 
-@main
-struct FreeAPSApp: App {
+@main struct FreeAPSApp: App {
     private let resolver = Container(defaultObjectScope: .container) { container in
         UIContainer.register(container: container)
         StorageContainer.register(container: container)

+ 0 - 9
FreeAPS/Sources/Helpers/CheckBox.swift

@@ -1,9 +0,0 @@
-import SwiftUI
-
-struct CheckBox: View {
-    @Binding var isChecked: Bool
-
-    var body: some View {
-        Image(systemName: isChecked ? "checkmark.circle.fill" : "circle")
-    }
-}

+ 0 - 82
FreeAPS/Sources/Helpers/FlowStack.swift

@@ -1,82 +0,0 @@
-import SwiftUI
-
-@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
-struct FlowStack<Content>: View where Content: View {
-    // The number of columns we want to display
-    var columns: Int
-    // The total number of items in the stack
-    var numItems: Int
-    // The alignment of our columns in the last row
-    // when they don't fill all the column slots
-    var alignment: HorizontalAlignment
-
-    let content: (Int, CGFloat) -> Content
-
-    private func width(for size: CGSize) -> CGFloat {
-        size.width / CGFloat(columns)
-    }
-
-    private func index(forRow row: Int, column: Int) -> Int {
-        (row * columns) + column
-    }
-
-    private var lastRowColumns: Int { numItems % columns }
-
-    private var rows: Int { numItems / columns }
-
-    init(
-        columns: Int,
-        numItems: Int,
-        alignment: HorizontalAlignment?,
-        @ViewBuilder content: @escaping (Int, CGFloat) -> Content
-    ) {
-        self.content = content
-        self.columns = columns
-        self.numItems = numItems
-        self.alignment = alignment ?? HorizontalAlignment.leading
-    }
-
-    var body: some View {
-        // A GeometryReader is required to size items in the scroll view
-        GeometryReader { geometry in
-
-            // Assume a vertical scrolling orientation for the grid
-            ScrollView(Axis.Set.vertical) {
-                // VStacks are our rows
-                VStack(alignment: self.alignment, spacing: 0) {
-                    ForEach(0 ..< self.rows) { row in
-
-                        // HStacks are our columns
-                        HStack(spacing: 0) {
-                            ForEach(0 ..< self.columns) { column in
-                                self.content(
-                                    // Pass the index to the content
-                                    self.index(forRow: row, column: column),
-                                    // Pass the column width to the content
-                                    self.width(for: geometry.size)
-                                )
-                                // Size the content to frame to fill the column
-                                .frame(width: self.width(for: geometry.size))
-                            }
-                        }
-                    }
-
-                    // Last row
-                    // HStacks are our columns
-                    HStack(spacing: 0) {
-                        ForEach(0 ..< self.lastRowColumns) { column in
-                            self.content(
-                                // Pass the index to the content
-                                self.index(forRow: self.rows, column: column),
-                                // Pass the column width to the content
-                                self.width(for: geometry.size)
-                            )
-                            // Size the content to frame to fill the column
-                            .frame(width: self.width(for: geometry.size))
-                        }
-                    }
-                }
-            }
-        }
-    }
-}

+ 2 - 9
FreeAPS/Sources/Helpers/JSON.swift

@@ -1,13 +1,5 @@
-//
-//  JSON.swift
-//  FreeAPS
-//
-//  Created by Ivan Valkou on 19.01.2021.
-//
-
 import Foundation
 
-
 protocol JSON: Codable {
     var string: String { get }
     init?(from: String)
@@ -20,7 +12,8 @@ extension JSON {
 
     init?(from: String) {
         guard let data = from.data(using: .utf8),
-            let object = try? JSONDecoder().decode(Self.self, from: data) else {
+              let object = try? JSONDecoder().decode(Self.self, from: data)
+        else {
             return nil
         }
         self = object

+ 1 - 1
FreeAPS/Sources/Helpers/ViewModifiers.swift

@@ -66,7 +66,7 @@ struct AdaptsToSoftwareKeyboard: ViewModifier {
     private let keyboardHeightOnOpening = NotificationCenter.default
         .publisher(for: UIResponder.keyboardWillShowNotification)
         .map { $0.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect }
-        .map { $0.height }
+        .map(\.height)
 
     private let keyboardHeightOnHiding = NotificationCenter.default
         .publisher(for: UIResponder.keyboardWillHideNotification)

+ 0 - 7
FreeAPS/Sources/Models/Autosens.swift

@@ -1,10 +1,3 @@
-//
-//  Autosens.swift
-//  FreeAPS
-//
-//  Created by Ivan Valkou on 19.01.2021.
-//
-
 import Foundation
 
 struct Autosens: JSON {

+ 14 - 21
FreeAPS/Sources/Models/Profile.swift

@@ -1,10 +1,3 @@
-//
-//  Profile.swift
-//  FreeAPS
-//
-//  Created by Ivan Valkou on 21.01.2021.
-//
-
 import Foundation
 
 struct Profile: JSON {
@@ -148,43 +141,43 @@ extension Profile {
         case highTemptargetRaisesSensitivity = "high_temptarget_raises_sensitivity"
         case lowTemptargetLowersSensitivity = "low_temptarget_lowers_sensitivity"
         case sensitivityRaisesTarget = "sensitivity_raises_target"
-        case resistanceLowersTarget = "resistanceLowersTarget"
+        case resistanceLowersTarget
         case advTargetAdjustments = "adv_target_adjustments"
         case exerciseMode = "exercise_mode"
         case halfBasalExerciseTarget = "half_basal_exercise_target"
-        case maxCOB = "maxCOB"
+        case maxCOB
         case wideBGTargetRange = "wide_bg_target_range"
         case skipNeutralTemps = "skip_neutral_temps"
         case unsuspendIfNoTemp = "unsuspend_if_no_temp"
         case bolusSnoozeDIADivisor = "bolussnooze_dia_divisor"
         case min5mCarbimpact = "min_5m_carbimpact"
         case autotuneISFAdjustmentFraction = "autotune_isf_adjustmentFraction"
-        case remainingCarbsFraction = "remainingCarbsFraction"
-        case remainingCarbsCap = "remainingCarbsCap"
-        case enableUAM = "enableUAM"
+        case remainingCarbsFraction
+        case remainingCarbsCap
+        case enableUAM
         case a52RiskEnable = "A52_risk_enable"
         case enableSMBWithCOB = "enableSMB_with_COB"
         case enableSMBWithTemptarget = "enableSMB_with_temptarget"
         case enableSMBAlways = "enableSMB_always"
         case enableSMBAfterCarbs = "enableSMB_after_carbs"
         case allowSMBWithHighTemptarget = "allowSMB_with_high_temptarget"
-        case maxSMBBasalMinutes = "maxSMBBasalMinutes"
-        case maxUAMSMBBasalMinutes = "maxUAMSMBBasalMinutes"
+        case maxSMBBasalMinutes
+        case maxUAMSMBBasalMinutes
         case smbInterval = "SMBInterval"
         case bolusIncrement = "bolus_increment"
-        case curve = "curve"
-        case useCustomPeakTime = "useCustomPeakTime"
-        case insulinPeakTime = "insulinPeakTime"
-        case carbsReqThreshold = "carbsReqThreshold"
+        case curve
+        case useCustomPeakTime
+        case insulinPeakTime
+        case carbsReqThreshold
         case offlineHotspot = "offline_hotspot"
-        case noisyCGMTargetMultiplier = "noisyCGMTargetMultiplier"
+        case noisyCGMTargetMultiplier
         case suspendZerosIOB = "suspend_zeros_iob"
-        case enableEnliteBgproxy = "enableEnliteBgproxy"
+        case enableEnliteBgproxy
     }
 }
 
 enum InsulinCurve: String, Codable {
     case rapidActing = "rapid-acting"
     case ultraRapid = "ultra-rapid"
-    case bilinear = "bilinear"
+    case bilinear
 }

+ 2 - 1
FreeAPS/Sources/Modules/Base/BaseModuleBuilder.swift

@@ -7,7 +7,8 @@ protocol ModuleBuilder {
 }
 
 class BaseModuleBuilder<View: BaseView, ViewModel: ObservableObject, Provider: FreeAPS.Provider>: ModuleBuilder
-    where ViewModel: BaseViewModel<Provider>, View.ViewModel == ViewModel {
+    where ViewModel: BaseViewModel<Provider>, View.ViewModel == ViewModel
+{
     let resolver: Resolver
     lazy var viewModel: ViewModel = { buildViewModel() }()
 

+ 1 - 2
FreeAPS/Sources/Modules/Login/View/LoginRootView.swift

@@ -1,5 +1,5 @@
-import SwiftUI
 import AuthenticationServices
+import SwiftUI
 
 extension Login {
     struct RootView: BaseView {
@@ -14,7 +14,6 @@ extension Login {
                 }
                 onCompletion: { result in
                     switch result {
-
                     case let .success(authorisation):
                         viewModel.credentials = authorisation.credential as? ASAuthorizationAppleIDCredential
                     case .failure:

+ 2 - 10
FreeAPS/Sources/OpenAPS/JavaScriptWorker.swift

@@ -1,10 +1,3 @@
-//
-//  JavaScriptWorker.swift
-//  FreeAPS
-//
-//  Created by Ivan Valkou on 29.01.2021.
-//
-
 import Foundation
 import JavaScriptCore
 
@@ -29,8 +22,7 @@ final class JavaScriptWorker {
         return context
     }
 
-    @discardableResult
-    func evaluate(script: Script) -> JSValue! {
+    @discardableResult func evaluate(script: Script) -> JSValue! {
         evaluate(string: script.body)
     }
 
@@ -48,7 +40,7 @@ final class JavaScriptWorker {
         return json(for: "\(function)(\(joined))")
     }
 
-    func inCommonContext<Value>(execute: (JavaScriptWorker) -> Value) -> Value{
+    func inCommonContext<Value>(execute: (JavaScriptWorker) -> Value) -> Value {
         commonContext = createContext()
         defer {
             commonContext = nil

+ 11 - 18
FreeAPS/Sources/OpenAPS/OpenAPS.swift

@@ -1,10 +1,3 @@
-//
-//  OpenAPS.swift
-//  FreeAPS
-//
-//  Created by Ivan Valkou on 12.01.2021.
-//
-
 import Foundation
 import JavaScriptCore
 
@@ -24,7 +17,7 @@ final class OpenAPS {
             let glucose = self.loadJSON(name: "glucose")
             let currentTemp = self.loadJSON(name: "temp_basal")
             let reservoir = 100
-            let tsMilliseconds: Double = 1527924300000
+            let tsMilliseconds: Double = 1_527_924_300_000
 
             let autosensResult = self.autosense(
                 pumpHistory: pumphistory,
@@ -79,8 +72,8 @@ final class OpenAPS {
     private func iob(pumphistory: JSON, profile: JSON, clock: JSON, autosens: JSON, pumphistory24: JSON) -> JSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
-            worker.evaluate(script: Script(name:"iob-bundle"))
-            worker.evaluate(script: Script(name:"prepare-iob"))
+            worker.evaluate(script: Script(name: "iob-bundle"))
+            worker.evaluate(script: Script(name: "prepare-iob"))
             return worker.call(function: "generate", with: [
                 pumphistory,
                 profile,
@@ -94,8 +87,8 @@ final class OpenAPS {
     private func meal(pumphistory: JSON, profile: JSON, basalProfile: JSON, clock: JSON, carbs: JSON, glucose: JSON) -> JSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
-            worker.evaluate(script: Script(name:"meal-bundle"))
-            worker.evaluate(script: Script(name:"prepare-meal"))
+            worker.evaluate(script: Script(name: "meal-bundle"))
+            worker.evaluate(script: Script(name: "prepare-meal"))
             return worker.call(function: "generate", with: [
                 pumphistory,
                 profile,
@@ -110,7 +103,7 @@ final class OpenAPS {
     private func glucoseGetLast(glucose: JSON) -> JSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
-            worker.evaluate(script: Script(name:"glucose-get-last-bundle"))
+            worker.evaluate(script: Script(name: "glucose-get-last-bundle"))
             return worker.call(function: "freeaps", with: [glucose])
         }
     }
@@ -128,10 +121,10 @@ final class OpenAPS {
     ) -> JSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
-            worker.evaluate(script: Script(name:"basal-set-temp-bundle"))
-            worker.evaluate(script: Script(name:"prepare-determine-basal"))
+            worker.evaluate(script: Script(name: "basal-set-temp-bundle"))
+            worker.evaluate(script: Script(name: "prepare-determine-basal"))
             let funcKey = "tempBasalFunctions"
-            worker.evaluate(script: Script(name:"determine-basal-bundle"))
+            worker.evaluate(script: Script(name: "determine-basal-bundle"))
 
             return worker.call(
                 function: "freeaps",
@@ -161,8 +154,8 @@ final class OpenAPS {
     ) -> JSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
-            worker.evaluate(script: Script(name:"autosens-bundle"))
-            worker.evaluate(script: Script(name:"prepare-autosens"))
+            worker.evaluate(script: Script(name: "autosens-bundle"))
+            worker.evaluate(script: Script(name: "prepare-autosens"))
 
             return worker.call(
                 function: "generate",

+ 1 - 8
FreeAPS/Sources/OpenAPS/Script.swift

@@ -1,10 +1,3 @@
-//
-//  Script.swift
-//  FreeAPS
-//
-//  Created by Ivan Valkou on 29.01.2021.
-//
-
 import Foundation
 
 struct Script {
@@ -13,6 +6,6 @@ struct Script {
 
     init(name: String) {
         self.name = name
-        self.body = try! String(contentsOf: Bundle.main.url(forResource: "javascript/\(name)", withExtension: "js")!)
+        body = try! String(contentsOf: Bundle.main.url(forResource: "javascript/\(name)", withExtension: "js")!)
     }
 }

+ 4 - 1
FreeAPS/Sources/Router/Screen.swift

@@ -47,7 +47,10 @@ extension Screen {
                 image: Image(systemName: "gear"),
                 text: Text("Settings")
             )
-        case .onboarding, .login, .requestPermissions, .authorizedRoot:
+        case .authorizedRoot,
+             .login,
+             .onboarding,
+             .requestPermissions:
             fatalError("Tab for this screen \(self) did not specified")
         }
     }

+ 5 - 4
FreeAPS/Sources/Services/Network/HTTPResponseStatus.swift

@@ -229,7 +229,8 @@ extension HTTPResponseStatus: Equatable {
         switch (lhs, rhs) {
         case let (.custom(lcode, lreason), .custom(rcode, rreason)):
             return lcode == rcode && lreason == rreason
-        case (.custom, _), (_, .custom):
+        case (_, .custom),
+             (.custom, _):
             return false
         default:
             return lhs.code == rhs.code
@@ -237,9 +238,9 @@ extension HTTPResponseStatus: Equatable {
     }
 }
 
-extension HTTPResponseStatus {
+public extension HTTPResponseStatus {
     /// The numerical status code for a given HTTP response status.
-    public var code: UInt {
+    var code: UInt {
         switch self {
         case .continue:
             return 100
@@ -367,7 +368,7 @@ extension HTTPResponseStatus {
     }
 
     /// The string reason phrase for a given HTTP response status.
-    public var reasonPhrase: String {
+    var reasonPhrase: String {
         switch self {
         case .continue:
             return "Continue"

+ 8 - 11
FreeAPS/Sources/Services/Storage/Keychain/BaseKeychain.swift

@@ -91,7 +91,8 @@ final class BaseKeychain: Keychain {
 
             for item in array {
                 if let keyData = item[SecAttrAccount] as? Data,
-                    let key = String(data: keyData, encoding: .utf8) {
+                   let key = String(data: keyData, encoding: .utf8)
+                {
                     keys.update(with: key)
                 }
             }
@@ -128,8 +129,8 @@ final class BaseKeychain: Keychain {
 
         if status == errSecSuccess {
             if let resultsDictionary = result as? [String: AnyObject],
-                let accessibilityAttrValue = resultsDictionary[SecAttrAccessible] as? String,
-                let mappedValue = KeychainItemAccessibility.accessibilityForAttributeValue(accessibilityAttrValue as CFString)
+               let accessibilityAttrValue = resultsDictionary[SecAttrAccessible] as? String,
+               let mappedValue = KeychainItemAccessibility.accessibilityForAttributeValue(accessibilityAttrValue as CFString)
             {
                 return .success(mappedValue)
             }
@@ -186,8 +187,7 @@ final class BaseKeychain: Keychain {
 
     // MARK: Public Setters
 
-    @discardableResult
-    func setData(_ value: Data, forKey key: String) -> Result<Void, KeychainError> {
+    @discardableResult func setData(_ value: Data, forKey key: String) -> Result<Void, KeychainError> {
         var keychainQueryDictionary: [String: Any] = setupKeychainQueryDictionary(
             forKey: key,
             synchronizable: defaultSynchronizable.keychainFlag,
@@ -209,8 +209,7 @@ final class BaseKeychain: Keychain {
         }
     }
 
-    @discardableResult
-    func setValue<T: Encodable>(_ maybeValue: T?, forKey key: String) -> Result<Void, KeychainError> {
+    @discardableResult func setValue<T: Encodable>(_ maybeValue: T?, forKey key: String) -> Result<Void, KeychainError> {
         if let value = maybeValue {
             let wrapper = EncodableWrapper(v: value)
             let encoder = JSONEncoder()
@@ -245,8 +244,7 @@ final class BaseKeychain: Keychain {
         }
     }
 
-    @discardableResult
-    func removeObject(forKey key: String) -> Result<Void, KeychainError> {
+    @discardableResult func removeObject(forKey key: String) -> Result<Void, KeychainError> {
         removeObject(forKey: key, withAccessibility: defaultAccessibilityLevel)
     }
 
@@ -290,8 +288,7 @@ final class BaseKeychain: Keychain {
     /// Remove all items for a given Keychain Item Class
     ///
     ///
-    @discardableResult
-    private class func deleteKeychainSecClass(_ secClass: AnyObject) -> Result<Void, KeychainError> {
+    @discardableResult private class func deleteKeychainSecClass(_ secClass: AnyObject) -> Result<Void, KeychainError> {
         let query = [SecClass: secClass]
         let status = SecItemDelete(query as CFDictionary)
 

+ 2 - 4
FreeAPS/Sources/Services/Storage/Keychain/Keychain.swift

@@ -13,10 +13,8 @@ protocol Keychain: KeyValueStorage {
     func getData(forKey key: String) -> Result<Data?, KeychainError>
     func getValue<T: Decodable>(_ type: T.Type, forKey key: String) -> Result<T?, KeychainError>
 
-    @discardableResult
-    func setData(_ value: Data, forKey key: String) -> Result<Void, KeychainError>
-    @discardableResult
-    func setValue<T: Encodable>(_ maybeValue: T?, forKey key: String) -> Result<Void, KeychainError>
+    @discardableResult func setData(_ value: Data, forKey key: String) -> Result<Void, KeychainError>
+    @discardableResult func setValue<T: Encodable>(_ maybeValue: T?, forKey key: String) -> Result<Void, KeychainError>
 
     func removeObject(forKey key: String) -> Result<Void, KeychainError>
     func removeAllKeys() -> Result<Void, KeychainError>

+ 14 - 4
scripts/swiftformat.sh

@@ -23,6 +23,7 @@ consecutiveSpaces,\
 duplicateImports,\
 elseOnSameLine,\
 emptyBraces,\
+enumNamespaces,\
 fileHeader,\
 hoistPatternLet,\
 indent,\
@@ -30,7 +31,9 @@ isEmpty,\
 leadingDelimiters,\
 linebreakAtEndOfFile,\
 linebreaks,\
+modifierOrder,\
 numberFormatting,\
+preferKeyPath,\
 redundantBackticks,\
 redundantBreak,\
 redundantExtensionACL,\
@@ -46,9 +49,11 @@ redundantPattern,\
 redundantRawValues,\
 redundantReturn,\
 redundantSelf,\
+redundantType,\
 redundantVoidReturnType,\
 semicolons,\
 sortedImports,\
+sortedSwitchCases,\
 spaceAroundBraces,\
 spaceAroundBrackets,\
 spaceAroundComments,\
@@ -60,9 +65,8 @@ spaceInsideBrackets,\
 spaceInsideComments,\
 spaceInsideGenerics,\
 spaceInsideParens,\
-specifiers,\
-strongifiedSelf,\
 strongOutlets,\
+strongifiedSelf,\
 todos,\
 trailingCommas,\
 trailingSpace,\
@@ -70,11 +74,14 @@ typeSugar,\
 unusedArguments,\
 void,\
 wrap,\
-wrapArguments \
+wrapArguments,\
+wrapAttributes,\
+wrapEnumCases,\
+wrapMultilineStatementBraces,\
+wrapSwitchCases \
 --disable braces,\
 trailingClosures \
 --commas inline \
---empty void \
 --exponentcase uppercase \
 --header strip \
 --hexliteralcase uppercase \
@@ -86,5 +93,8 @@ trailingClosures \
 --trimwhitespace always \
 --maxwidth 130 \
 --wraparguments before-first \
+--funcattributes same-line \
+--typeattributes same-line \
+--varattributes same-line \
 --wrapcollections before-first \
 --exclude Pods,Generated,R.generated.swift,fastlane/swift