From 9aed43d1eb7b99ccd133c2af08421fb0ccf3f68e Mon Sep 17 00:00:00 2001
From: Bruno Muniz Azevedo Filho <bruno@elixxir.io>
Date: Tue, 23 Aug 2022 00:41:42 -0300
Subject: [PATCH] Add pre-actions for run and archive on release scheme

---
 .../xcshareddata/xcschemes/Release.xcscheme   | 38 ++++++++++++++++++-
 App/client-ios/Resources/Info.plist           |  2 +
 Sources/App/AppDelegate.swift                 | 14 +++++++
 .../SettingsAdvancedViewModel.swift           |  2 +-
 4 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/App/client-ios.xcodeproj/xcshareddata/xcschemes/Release.xcscheme b/App/client-ios.xcodeproj/xcshareddata/xcschemes/Release.xcscheme
index 04659753..800c200d 100644
--- a/App/client-ios.xcodeproj/xcshareddata/xcschemes/Release.xcscheme
+++ b/App/client-ios.xcodeproj/xcshareddata/xcschemes/Release.xcscheme
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
    LastUpgradeVersion = "1200"
-   version = "1.3">
+   version = "1.7">
    <BuildAction
       parallelizeBuildables = "YES"
       buildImplicitDependencies = "YES">
@@ -52,6 +52,24 @@
       migratedStopOnEveryIssue = "YES"
       debugServiceExtension = "internal"
       allowLocationSimulation = "YES">
+      <PreActions>
+         <ExecutionAction
+            ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
+            <ActionContent
+               title = "Run Script"
+               scriptText = "#!/bin/sh&#10;/usr/libexec/PlistBuddy -c &quot;Set :isReportingOptional YES&quot; &quot;${SRCROOT}/client-ios/Resources/Info.plist&quot;&#10;">
+               <EnvironmentBuildable>
+                  <BuildableReference
+                     BuildableIdentifier = "primary"
+                     BlueprintIdentifier = "02FDD06121EDA39A000F1286"
+                     BuildableName = "client-ios.app"
+                     BlueprintName = "client-ios"
+                     ReferencedContainer = "container:client-ios.xcodeproj">
+                  </BuildableReference>
+               </EnvironmentBuildable>
+            </ActionContent>
+         </ExecutionAction>
+      </PreActions>
       <BuildableProductRunnable
          runnableDebuggingMode = "0">
          <BuildableReference
@@ -91,5 +109,23 @@
    <ArchiveAction
       buildConfiguration = "Release"
       revealArchiveInOrganizer = "YES">
+      <PreActions>
+         <ExecutionAction
+            ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
+            <ActionContent
+               title = "Run Script"
+               scriptText = "#!/bin/sh&#10;/usr/libexec/PlistBuddy -c &quot;Set :isReportingOptional NO&quot; &quot;${SRCROOT}/client-ios/Resources/Info.plist&quot;&#10;">
+               <EnvironmentBuildable>
+                  <BuildableReference
+                     BuildableIdentifier = "primary"
+                     BlueprintIdentifier = "02FDD06121EDA39A000F1286"
+                     BuildableName = "client-ios.app"
+                     BlueprintName = "client-ios"
+                     ReferencedContainer = "container:client-ios.xcodeproj">
+                  </BuildableReference>
+               </EnvironmentBuildable>
+            </ActionContent>
+         </ExecutionAction>
+      </PreActions>
    </ArchiveAction>
 </Scheme>
diff --git a/App/client-ios/Resources/Info.plist b/App/client-ios/Resources/Info.plist
index dd578c50..d8cb845b 100644
--- a/App/client-ios/Resources/Info.plist
+++ b/App/client-ios/Resources/Info.plist
@@ -104,5 +104,7 @@
 	</array>
 	<key>UIViewControllerBasedStatusBarAppearance</key>
 	<true/>
+	<key>isReportingOptional</key>
+	<false/>
 </dict>
 </plist>
diff --git a/Sources/App/AppDelegate.swift b/Sources/App/AppDelegate.swift
index 4143a5f2..e9c2b744 100644
--- a/Sources/App/AppDelegate.swift
+++ b/Sources/App/AppDelegate.swift
@@ -23,6 +23,7 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
     @KeyObject(.hideAppList, defaultValue: false) var hideAppList: Bool
     @KeyObject(.recordingLogs, defaultValue: true) var recordingLogs: Bool
     @KeyObject(.crashReporting, defaultValue: true) var isCrashReportingEnabled: Bool
+    @KeyObject(.isReportingOptional, defaultValue: false) var isReportingOptional: Bool
 
     var calledStopNetwork = false
     var forceFailedPendingMessages = false
@@ -48,6 +49,8 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
         crashReporter.configure()
         crashReporter.setEnabled(isCrashReportingEnabled)
 
+        isReportingOptional = isReportingFeatureOptionalOnInfoPlist()
+
         UNUserNotificationCenter.current().delegate = self
 
         let window = Window()
@@ -175,6 +178,17 @@ func getUsernameFromInvitationDeepLink(_ url: URL) -> String? {
     return nil
 }
 
+func isReportingFeatureOptionalOnInfoPlist() -> Bool {
+    struct Root : Decodable {
+        let isReportingOptional : Bool
+    }
+
+    let url = Bundle.main.url(forResource: "Info", withExtension: "plist")!
+    let data = try! Data(contentsOf: url)
+    let result = try! PropertyListDecoder().decode(Root.self, from: data)
+    return result.isReportingOptional
+}
+
 // MARK: Notifications
 
 extension AppDelegate: UNUserNotificationCenterDelegate {
diff --git a/Sources/SettingsFeature/ViewModels/SettingsAdvancedViewModel.swift b/Sources/SettingsFeature/ViewModels/SettingsAdvancedViewModel.swift
index 60e7f5e7..c88dba70 100644
--- a/Sources/SettingsFeature/ViewModels/SettingsAdvancedViewModel.swift
+++ b/Sources/SettingsFeature/ViewModels/SettingsAdvancedViewModel.swift
@@ -18,7 +18,7 @@ final class SettingsAdvancedViewModel {
     @KeyObject(.crashReporting, defaultValue: true) var isCrashReporting: Bool
 
     @KeyObject(.isReportingEnabled, defaultValue: true) var isReportingEnabled: Bool
-    @KeyObject(.isReportingOptional, defaultValue: true) var isReportingOptional: Bool
+    @KeyObject(.isReportingOptional, defaultValue: false) var isReportingOptional: Bool
 
     private let isShowingUsernamesKey = "isShowingUsernames"
 
-- 
GitLab