Skip to content

Commit def8368

Browse files
authored
Merge pull request #794 from OneSignal/fg/formatting-changes
Add CSharp Formatting
2 parents e7a99ec + edb99b1 commit def8368

File tree

117 files changed

+3231
-1969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+3231
-1969
lines changed

.csharpierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Exclude Packages folders (Unity packages and third-party code)
2+
**/Packages/**

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run Checks
2+
on:
3+
pull_request:
4+
branches:
5+
- "**"
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-22.04
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v5
14+
15+
- name: Setup .NET
16+
uses: actions/setup-dotnet@v5
17+
with:
18+
dotnet-version: "8.0.x"
19+
20+
- name: Install CSharpier
21+
run: dotnet tool install -g csharpier
22+
23+
- name: Check formatting
24+
run: csharpier check .

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["csharpier.csharpier-vscode"]
3+
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.formatOnSave": true,
4+
"[csharp]": {
5+
"editor.defaultFormatter": "csharpier.csharpier-vscode"
6+
}
7+
}

OneSignalExample/Assets/App/Editor/iOS/BuildPostProcessor.cs

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,23 @@
3535
using System.IO;
3636
using 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'\nend\n";
163+
podfile +=
164+
$"target '{WidgetExtensionTargetName}' do\n pod 'OneSignalXCFramework', '>= 5.0.2', '< 6.0.0'\nend\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

OneSignalExample/Assets/OneSignal/Attribution/OneSignalVSAttribution.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
using UnityEngine;
2928
using UnityEditor.VSAttribution.OneSignalSDK;
29+
using UnityEngine;
3030

3131
namespace OneSignalSDK
3232
{
33-
internal static class AttachToInit {
34-
#if ONE_SIGNAL_INSTALLED
35-
[RuntimeInitializeOnLoadMethod] public static void Init() {
36-
if (string.IsNullOrEmpty(OneSignalPlatform.AppId))
37-
OneSignalPlatform.OnInitialize += appId => VSAttribution.SendAttributionEvent("Login", "OneSignal", appId);
38-
else
39-
VSAttribution.SendAttributionEvent("Login", "OneSignal", OneSignalPlatform.AppId);
40-
}
41-
#endif
33+
internal static class AttachToInit
34+
{
35+
#if ONE_SIGNAL_INSTALLED
36+
[RuntimeInitializeOnLoadMethod]
37+
public static void Init()
38+
{
39+
if (string.IsNullOrEmpty(OneSignalPlatform.AppId))
40+
OneSignalPlatform.OnInitialize += appId =>
41+
VSAttribution.SendAttributionEvent("Login", "OneSignal", appId);
42+
else
43+
VSAttribution.SendAttributionEvent("Login", "OneSignal", OneSignalPlatform.AppId);
44+
}
45+
#endif
4246
}
43-
}
47+
}

OneSignalExample/Assets/OneSignal/Attribution/VSAttribution.cs

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,75 @@
33

44
namespace UnityEditor.VSAttribution.OneSignalSDK
55
{
6-
public static class VSAttribution
7-
{
8-
const int k_VersionId = 4;
9-
const int k_MaxEventsPerHour = 10;
10-
const int k_MaxNumberOfElements = 1000;
6+
public static class VSAttribution
7+
{
8+
const int k_VersionId = 4;
9+
const int k_MaxEventsPerHour = 10;
10+
const int k_MaxNumberOfElements = 1000;
1111

12-
const string k_VendorKey = "unity.vsp-attribution";
13-
const string k_EventName = "vspAttribution";
12+
const string k_VendorKey = "unity.vsp-attribution";
13+
const string k_EventName = "vspAttribution";
1414

15-
static bool RegisterEvent()
16-
{
17-
AnalyticsResult result = EditorAnalytics.RegisterEventWithLimit(k_EventName, k_MaxEventsPerHour,
18-
k_MaxNumberOfElements, k_VendorKey, k_VersionId);
15+
static bool RegisterEvent()
16+
{
17+
AnalyticsResult result = EditorAnalytics.RegisterEventWithLimit(
18+
k_EventName,
19+
k_MaxEventsPerHour,
20+
k_MaxNumberOfElements,
21+
k_VendorKey,
22+
k_VersionId
23+
);
1924

20-
var isResultOk = result == AnalyticsResult.Ok;
21-
return isResultOk;
22-
}
25+
var isResultOk = result == AnalyticsResult.Ok;
26+
return isResultOk;
27+
}
2328

24-
[Serializable]
25-
struct VSAttributionData
26-
{
27-
public string actionName;
28-
public string partnerName;
29-
public string customerUid;
30-
public string extra;
31-
}
29+
[Serializable]
30+
struct VSAttributionData
31+
{
32+
public string actionName;
33+
public string partnerName;
34+
public string customerUid;
35+
public string extra;
36+
}
3237

33-
/// <summary>
34-
/// Registers and attempts to send a Verified Solutions Attribution event.
35-
/// </summary>
36-
/// <param name="actionName">Name of the action, identifying a place this event was called from.</param>
37-
/// <param name="partnerName">Identifiable Verified Solutions Partner's name.</param>
38-
/// <param name="customerUid">Unique identifier of the customer using Partner's Verified Solution.</param>
39-
public static AnalyticsResult SendAttributionEvent(string actionName, string partnerName, string customerUid)
40-
{
41-
try
42-
{
43-
// Are Editor Analytics enabled ? (Preferences)
44-
if (!EditorAnalytics.enabled)
45-
return AnalyticsResult.AnalyticsDisabled;
38+
/// <summary>
39+
/// Registers and attempts to send a Verified Solutions Attribution event.
40+
/// </summary>
41+
/// <param name="actionName">Name of the action, identifying a place this event was called from.</param>
42+
/// <param name="partnerName">Identifiable Verified Solutions Partner's name.</param>
43+
/// <param name="customerUid">Unique identifier of the customer using Partner's Verified Solution.</param>
44+
public static AnalyticsResult SendAttributionEvent(
45+
string actionName,
46+
string partnerName,
47+
string customerUid
48+
)
49+
{
50+
try
51+
{
52+
// Are Editor Analytics enabled ? (Preferences)
53+
if (!EditorAnalytics.enabled)
54+
return AnalyticsResult.AnalyticsDisabled;
4655

47-
if (!RegisterEvent())
48-
return AnalyticsResult.InvalidData;
56+
if (!RegisterEvent())
57+
return AnalyticsResult.InvalidData;
4958

50-
// Create an expected data object
51-
var eventData = new VSAttributionData
52-
{
53-
actionName = actionName,
54-
partnerName = partnerName,
55-
customerUid = customerUid,
56-
extra = "{}"
57-
};
59+
// Create an expected data object
60+
var eventData = new VSAttributionData
61+
{
62+
actionName = actionName,
63+
partnerName = partnerName,
64+
customerUid = customerUid,
65+
extra = "{}",
66+
};
5867

59-
return EditorAnalytics.SendEventWithLimit(k_EventName, eventData, k_VersionId);
60-
}
61-
catch
62-
{
63-
// Fail silently
64-
return AnalyticsResult.AnalyticsDisabled;
65-
}
66-
}
67-
}
68-
}
68+
return EditorAnalytics.SendEventWithLimit(k_EventName, eventData, k_VersionId);
69+
}
70+
catch
71+
{
72+
// Fail silently
73+
return AnalyticsResult.AnalyticsDisabled;
74+
}
75+
}
76+
}
77+
}

OneSignalExample/Assets/OneSignal/Editor/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727

2828
using System.Runtime.CompilerServices;
2929

30-
[assembly: InternalsVisibleTo("OneSignal.Packager")]
30+
[assembly: InternalsVisibleTo("OneSignal.Packager")]

0 commit comments

Comments
 (0)