3535using System . IO ;
3636using System . Linq ;
3737
38- namespace App . Editor . iOS {
38+ namespace App . Editor . iOS
39+ {
3940 /// <summary>
4041 /// Adds the ExampleWidgetExtension to the iOS project frameworks to the iOS project and enables the main target
4142 /// for Live Activities.
4243 /// </summary>
43- public class BuildPostProcessor : IPostprocessBuildWithReport {
44-
44+ public class BuildPostProcessor : IPostprocessBuildWithReport
45+ {
4546 private static readonly string WdigetExtensionTargetRelativePath = "ExampleWidget" ;
4647 private static readonly string WidgetExtensionTargetName = "ExampleWidgetExtension" ;
4748 private static readonly string WidgetExtensionPath = Path . Combine ( "iOS" , "ExampleWidget" ) ;
48- private static readonly string [ ] WidgetExtensionFiles = new string [ ] { "Assets.xcassets" , "ExampleWidgetBundle.swift" , "ExampleWidgetLiveActivity.swift" } ;
49+ private static readonly string [ ] WidgetExtensionFiles = new string [ ]
50+ {
51+ "Assets.xcassets" ,
52+ "ExampleWidgetBundle.swift" ,
53+ "ExampleWidgetLiveActivity.swift" ,
54+ } ;
4955
5056 /// <summary>
5157 /// must be between 40 and 50 to ensure that it's not overriden by Podfile generation (40) and that it's
@@ -54,22 +60,32 @@ public class BuildPostProcessor : IPostprocessBuildWithReport {
5460 /// </summary>
5561 public int callbackOrder => 45 ;
5662
57- public void OnPostprocessBuild ( BuildReport report ) {
63+ public void OnPostprocessBuild ( BuildReport report )
64+ {
5865 if ( report . summary . platform != BuildTarget . iOS )
5966 return ;
6067
61- Debug . Log ( "BuildPostProcessor.OnPostprocessBuild for target " + report . summary . platform + " at path " + report . summary . outputPath + " with CWD " + Directory . GetCurrentDirectory ( ) ) ;
68+ Debug . Log (
69+ "BuildPostProcessor.OnPostprocessBuild for target "
70+ + report . summary . platform
71+ + " at path "
72+ + report . summary . outputPath
73+ + " with CWD "
74+ + Directory . GetCurrentDirectory ( )
75+ ) ;
6276
6377 EnableAppForLiveActivities ( report . summary . outputPath ) ;
6478 CreateWidgetExtension ( report . summary . outputPath ) ;
65-
79+
6680 Debug . Log ( "BuildPostProcessor.OnPostprocessBuild complete" ) ;
6781 }
6882
69- static void EnableAppForLiveActivities ( string outputPath ) {
83+ static void EnableAppForLiveActivities ( string outputPath )
84+ {
7085 var plistPath = Path . Combine ( outputPath , "Info.plist" ) ;
7186
72- if ( ! File . Exists ( plistPath ) ) {
87+ if ( ! File . Exists ( plistPath ) )
88+ {
7389 Debug . LogError ( $ "Could not find PList { plistPath } !") ;
7490 return ;
7591 }
@@ -80,12 +96,14 @@ static void EnableAppForLiveActivities(string outputPath) {
8096 mainPlist . WriteToFile ( plistPath ) ;
8197 }
8298
83- static void CreateWidgetExtension ( string outputPath ) {
99+ static void CreateWidgetExtension ( string outputPath )
100+ {
84101 AddWidgetExtensionToProject ( outputPath ) ;
85102 AddWidgetExtensionToPodFile ( outputPath ) ;
86103 }
87104
88- static void AddWidgetExtensionToProject ( string outputPath ) {
105+ static void AddWidgetExtensionToProject ( string outputPath )
106+ {
89107 var project = new PBXProject ( ) ;
90108 var projectPath = PBXProject . GetPBXProjectPath ( outputPath ) ;
91109 project . ReadFromString ( File . ReadAllText ( projectPath ) ) ;
@@ -99,21 +117,29 @@ static void AddWidgetExtensionToProject(string outputPath) {
99117 var widgetDestPath = Path . Combine ( outputPath , WdigetExtensionTargetRelativePath ) ;
100118
101119 Directory . CreateDirectory ( widgetDestPath ) ;
102- CopyFileOrDirectory ( Path . Combine ( WidgetExtensionPath , "Info.plist" ) , Path . Combine ( widgetDestPath , "Info.plist" ) ) ;
120+ CopyFileOrDirectory (
121+ Path . Combine ( WidgetExtensionPath , "Info.plist" ) ,
122+ Path . Combine ( widgetDestPath , "Info.plist" )
123+ ) ;
103124
104- extensionGuid = project . AddAppExtension ( project . GetUnityMainTargetGuid ( ) ,
125+ extensionGuid = project . AddAppExtension (
126+ project . GetUnityMainTargetGuid ( ) ,
105127 WidgetExtensionTargetName ,
106128 $ "{ PlayerSettings . GetApplicationIdentifier ( BuildTargetGroup . iOS ) } .{ WidgetExtensionTargetName } ",
107129 $ "{ WdigetExtensionTargetRelativePath } /Info.plist"
108130 ) ;
109131
110132 var buildPhaseID = project . AddSourcesBuildPhase ( extensionGuid ) ;
111133
112- foreach ( var file in WidgetExtensionFiles ) {
134+ foreach ( var file in WidgetExtensionFiles )
135+ {
113136 var destPathRelative = Path . Combine ( WdigetExtensionTargetRelativePath , file ) ;
114137 var sourceFileGuid = project . AddFile ( destPathRelative , destPathRelative ) ;
115138 project . AddFileToBuildSection ( extensionGuid , buildPhaseID , sourceFileGuid ) ;
116- CopyFileOrDirectory ( Path . Combine ( WidgetExtensionPath , file ) , Path . Combine ( outputPath , destPathRelative ) ) ;
139+ CopyFileOrDirectory (
140+ Path . Combine ( WidgetExtensionPath , file ) ,
141+ Path . Combine ( outputPath , destPathRelative )
142+ ) ;
117143 }
118144
119145 project . SetBuildProperty ( extensionGuid , "TARGETED_DEVICE_FAMILY" , "1,2" ) ;
@@ -123,16 +149,19 @@ static void AddWidgetExtensionToProject(string outputPath) {
123149 project . WriteToFile ( projectPath ) ;
124150 }
125151
126- static void AddWidgetExtensionToPodFile ( string outputPath ) {
152+ static void AddWidgetExtensionToPodFile ( string outputPath )
153+ {
127154 var podfilePath = Path . Combine ( outputPath , "Podfile" ) ;
128155
129- if ( ! File . Exists ( podfilePath ) ) {
156+ if ( ! File . Exists ( podfilePath ) )
157+ {
130158 Debug . LogError ( $ "Could not find Podfile { podfilePath } !") ;
131159 return ;
132160 }
133161
134162 var podfile = File . ReadAllText ( podfilePath ) ;
135- podfile += $ "target '{ WidgetExtensionTargetName } ' do\n pod 'OneSignalXCFramework', '>= 5.0.2', '< 6.0.0'\n end\n ";
163+ podfile +=
164+ $ "target '{ WidgetExtensionTargetName } ' do\n pod 'OneSignalXCFramework', '>= 5.0.2', '< 6.0.0'\n end\n ";
136165 File . WriteAllText ( podfilePath , podfile ) ;
137166 }
138167
@@ -150,20 +179,29 @@ static void CopyFileOrDirectory(string sourcePath, string destinationPath)
150179 {
151180 file . CopyTo ( destinationPath , true ) ;
152181 }
153- else {
154- Directory . CreateDirectory ( destinationPath ) ;
182+ else
183+ {
184+ Directory . CreateDirectory ( destinationPath ) ;
155185
156- foreach ( FileInfo childFile in dir . EnumerateFiles ( ) . Where ( f => ! f . Name . EndsWith ( ".meta" ) ) )
186+ foreach (
187+ FileInfo childFile in dir . EnumerateFiles ( ) . Where ( f => ! f . Name . EndsWith ( ".meta" ) )
188+ )
157189 {
158- CopyFileOrDirectory ( childFile . FullName , Path . Combine ( destinationPath , childFile . Name ) ) ;
190+ CopyFileOrDirectory (
191+ childFile . FullName ,
192+ Path . Combine ( destinationPath , childFile . Name )
193+ ) ;
159194 }
160195
161196 foreach ( DirectoryInfo subDir in dir . GetDirectories ( ) )
162197 {
163- CopyFileOrDirectory ( subDir . FullName , Path . Combine ( destinationPath , subDir . Name ) ) ;
198+ CopyFileOrDirectory (
199+ subDir . FullName ,
200+ Path . Combine ( destinationPath , subDir . Name )
201+ ) ;
164202 }
165203 }
166204 }
167205 }
168206}
169- #endif
207+ #endif
0 commit comments