Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .csharpierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Exclude Packages folders (Unity packages and third-party code)
**/Packages/**
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run Checks
on:
pull_request:
branches:
- "**"

jobs:
test:
runs-on: ubuntu-22.04

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "8.0.x"

- name: Install CSharpier
run: dotnet tool install -g csharpier

- name: Check formatting
run: csharpier check .
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["csharpier.csharpier-vscode"]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[csharp]": {
"editor.defaultFormatter": "csharpier.csharpier-vscode"
}
}
86 changes: 62 additions & 24 deletions OneSignalExample/Assets/App/Editor/iOS/BuildPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@
using System.IO;
using System.Linq;

namespace App.Editor.iOS {
namespace App.Editor.iOS
{
/// <summary>
/// Adds the ExampleWidgetExtension to the iOS project frameworks to the iOS project and enables the main target
/// for Live Activities.
/// </summary>
public class BuildPostProcessor : IPostprocessBuildWithReport {

public class BuildPostProcessor : IPostprocessBuildWithReport
{
private static readonly string WdigetExtensionTargetRelativePath = "ExampleWidget";
private static readonly string WidgetExtensionTargetName = "ExampleWidgetExtension";
private static readonly string WidgetExtensionPath = Path.Combine("iOS", "ExampleWidget");
private static readonly string[] WidgetExtensionFiles = new string[] { "Assets.xcassets", "ExampleWidgetBundle.swift", "ExampleWidgetLiveActivity.swift" };
private static readonly string[] WidgetExtensionFiles = new string[]
{
"Assets.xcassets",
"ExampleWidgetBundle.swift",
"ExampleWidgetLiveActivity.swift",
};

/// <summary>
/// must be between 40 and 50 to ensure that it's not overriden by Podfile generation (40) and that it's
Expand All @@ -54,22 +60,32 @@ public class BuildPostProcessor : IPostprocessBuildWithReport {
/// </summary>
public int callbackOrder => 45;

public void OnPostprocessBuild(BuildReport report) {
public void OnPostprocessBuild(BuildReport report)
{
if (report.summary.platform != BuildTarget.iOS)
return;

Debug.Log("BuildPostProcessor.OnPostprocessBuild for target " + report.summary.platform + " at path " + report.summary.outputPath + " with CWD " + Directory.GetCurrentDirectory());
Debug.Log(
"BuildPostProcessor.OnPostprocessBuild for target "
+ report.summary.platform
+ " at path "
+ report.summary.outputPath
+ " with CWD "
+ Directory.GetCurrentDirectory()
);

EnableAppForLiveActivities(report.summary.outputPath);
CreateWidgetExtension(report.summary.outputPath);

Debug.Log("BuildPostProcessor.OnPostprocessBuild complete");
}

static void EnableAppForLiveActivities(string outputPath) {
static void EnableAppForLiveActivities(string outputPath)
{
var plistPath = Path.Combine(outputPath, "Info.plist");

if (!File.Exists(plistPath)) {
if (!File.Exists(plistPath))
{
Debug.LogError($"Could not find PList {plistPath}!");
return;
}
Expand All @@ -80,12 +96,14 @@ static void EnableAppForLiveActivities(string outputPath) {
mainPlist.WriteToFile(plistPath);
}

static void CreateWidgetExtension(string outputPath) {
static void CreateWidgetExtension(string outputPath)
{
AddWidgetExtensionToProject(outputPath);
AddWidgetExtensionToPodFile(outputPath);
}

static void AddWidgetExtensionToProject(string outputPath) {
static void AddWidgetExtensionToProject(string outputPath)
{
var project = new PBXProject();
var projectPath = PBXProject.GetPBXProjectPath(outputPath);
project.ReadFromString(File.ReadAllText(projectPath));
Expand All @@ -99,21 +117,29 @@ static void AddWidgetExtensionToProject(string outputPath) {
var widgetDestPath = Path.Combine(outputPath, WdigetExtensionTargetRelativePath);

Directory.CreateDirectory(widgetDestPath);
CopyFileOrDirectory(Path.Combine(WidgetExtensionPath, "Info.plist"), Path.Combine(widgetDestPath, "Info.plist"));
CopyFileOrDirectory(
Path.Combine(WidgetExtensionPath, "Info.plist"),
Path.Combine(widgetDestPath, "Info.plist")
);

extensionGuid = project.AddAppExtension(project.GetUnityMainTargetGuid(),
extensionGuid = project.AddAppExtension(
project.GetUnityMainTargetGuid(),
WidgetExtensionTargetName,
$"{PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS)}.{WidgetExtensionTargetName}",
$"{WdigetExtensionTargetRelativePath}/Info.plist"
);

var buildPhaseID = project.AddSourcesBuildPhase(extensionGuid);

foreach (var file in WidgetExtensionFiles) {
foreach (var file in WidgetExtensionFiles)
{
var destPathRelative = Path.Combine(WdigetExtensionTargetRelativePath, file);
var sourceFileGuid = project.AddFile(destPathRelative, destPathRelative);
project.AddFileToBuildSection(extensionGuid, buildPhaseID, sourceFileGuid);
CopyFileOrDirectory(Path.Combine(WidgetExtensionPath, file), Path.Combine(outputPath, destPathRelative));
CopyFileOrDirectory(
Path.Combine(WidgetExtensionPath, file),
Path.Combine(outputPath, destPathRelative)
);
}

project.SetBuildProperty(extensionGuid, "TARGETED_DEVICE_FAMILY", "1,2");
Expand All @@ -123,16 +149,19 @@ static void AddWidgetExtensionToProject(string outputPath) {
project.WriteToFile(projectPath);
}

static void AddWidgetExtensionToPodFile(string outputPath) {
static void AddWidgetExtensionToPodFile(string outputPath)
{
var podfilePath = Path.Combine(outputPath, "Podfile");

if (!File.Exists(podfilePath)) {
if (!File.Exists(podfilePath))
{
Debug.LogError($"Could not find Podfile {podfilePath}!");
return;
}

var podfile = File.ReadAllText(podfilePath);
podfile += $"target '{WidgetExtensionTargetName}' do\n pod 'OneSignalXCFramework', '>= 5.0.2', '< 6.0.0'\nend\n";
podfile +=
$"target '{WidgetExtensionTargetName}' do\n pod 'OneSignalXCFramework', '>= 5.0.2', '< 6.0.0'\nend\n";
File.WriteAllText(podfilePath, podfile);
}

Expand All @@ -150,20 +179,29 @@ static void CopyFileOrDirectory(string sourcePath, string destinationPath)
{
file.CopyTo(destinationPath, true);
}
else {
Directory.CreateDirectory(destinationPath);
else
{
Directory.CreateDirectory(destinationPath);

foreach (FileInfo childFile in dir.EnumerateFiles().Where(f => !f.Name.EndsWith(".meta")))
foreach (
FileInfo childFile in dir.EnumerateFiles().Where(f => !f.Name.EndsWith(".meta"))
)
{
CopyFileOrDirectory(childFile.FullName, Path.Combine(destinationPath, childFile.Name));
CopyFileOrDirectory(
childFile.FullName,
Path.Combine(destinationPath, childFile.Name)
);
}

foreach (DirectoryInfo subDir in dir.GetDirectories())
{
CopyFileOrDirectory(subDir.FullName, Path.Combine(destinationPath, subDir.Name));
CopyFileOrDirectory(
subDir.FullName,
Path.Combine(destinationPath, subDir.Name)
);
}
}
}
}
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@
* THE SOFTWARE.
*/

using UnityEngine;
using UnityEditor.VSAttribution.OneSignalSDK;
using UnityEngine;

namespace OneSignalSDK
{
internal static class AttachToInit {
#if ONE_SIGNAL_INSTALLED
[RuntimeInitializeOnLoadMethod] public static void Init() {
if (string.IsNullOrEmpty(OneSignalPlatform.AppId))
OneSignalPlatform.OnInitialize += appId => VSAttribution.SendAttributionEvent("Login", "OneSignal", appId);
else
VSAttribution.SendAttributionEvent("Login", "OneSignal", OneSignalPlatform.AppId);
}
#endif
internal static class AttachToInit
{
#if ONE_SIGNAL_INSTALLED
[RuntimeInitializeOnLoadMethod]
public static void Init()
{
if (string.IsNullOrEmpty(OneSignalPlatform.AppId))
OneSignalPlatform.OnInitialize += appId =>
VSAttribution.SendAttributionEvent("Login", "OneSignal", appId);
else
VSAttribution.SendAttributionEvent("Login", "OneSignal", OneSignalPlatform.AppId);
}
#endif
}
}
}
119 changes: 64 additions & 55 deletions OneSignalExample/Assets/OneSignal/Attribution/VSAttribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,75 @@

namespace UnityEditor.VSAttribution.OneSignalSDK
{
public static class VSAttribution
{
const int k_VersionId = 4;
const int k_MaxEventsPerHour = 10;
const int k_MaxNumberOfElements = 1000;
public static class VSAttribution
{
const int k_VersionId = 4;
const int k_MaxEventsPerHour = 10;
const int k_MaxNumberOfElements = 1000;

const string k_VendorKey = "unity.vsp-attribution";
const string k_EventName = "vspAttribution";
const string k_VendorKey = "unity.vsp-attribution";
const string k_EventName = "vspAttribution";

static bool RegisterEvent()
{
AnalyticsResult result = EditorAnalytics.RegisterEventWithLimit(k_EventName, k_MaxEventsPerHour,
k_MaxNumberOfElements, k_VendorKey, k_VersionId);
static bool RegisterEvent()
{
AnalyticsResult result = EditorAnalytics.RegisterEventWithLimit(
k_EventName,
k_MaxEventsPerHour,
k_MaxNumberOfElements,
k_VendorKey,
k_VersionId
);

var isResultOk = result == AnalyticsResult.Ok;
return isResultOk;
}
var isResultOk = result == AnalyticsResult.Ok;
return isResultOk;
}

[Serializable]
struct VSAttributionData
{
public string actionName;
public string partnerName;
public string customerUid;
public string extra;
}
[Serializable]
struct VSAttributionData
{
public string actionName;
public string partnerName;
public string customerUid;
public string extra;
}

/// <summary>
/// Registers and attempts to send a Verified Solutions Attribution event.
/// </summary>
/// <param name="actionName">Name of the action, identifying a place this event was called from.</param>
/// <param name="partnerName">Identifiable Verified Solutions Partner's name.</param>
/// <param name="customerUid">Unique identifier of the customer using Partner's Verified Solution.</param>
public static AnalyticsResult SendAttributionEvent(string actionName, string partnerName, string customerUid)
{
try
{
// Are Editor Analytics enabled ? (Preferences)
if (!EditorAnalytics.enabled)
return AnalyticsResult.AnalyticsDisabled;
/// <summary>
/// Registers and attempts to send a Verified Solutions Attribution event.
/// </summary>
/// <param name="actionName">Name of the action, identifying a place this event was called from.</param>
/// <param name="partnerName">Identifiable Verified Solutions Partner's name.</param>
/// <param name="customerUid">Unique identifier of the customer using Partner's Verified Solution.</param>
public static AnalyticsResult SendAttributionEvent(
string actionName,
string partnerName,
string customerUid
)
{
try
{
// Are Editor Analytics enabled ? (Preferences)
if (!EditorAnalytics.enabled)
return AnalyticsResult.AnalyticsDisabled;

if (!RegisterEvent())
return AnalyticsResult.InvalidData;
if (!RegisterEvent())
return AnalyticsResult.InvalidData;

// Create an expected data object
var eventData = new VSAttributionData
{
actionName = actionName,
partnerName = partnerName,
customerUid = customerUid,
extra = "{}"
};
// Create an expected data object
var eventData = new VSAttributionData
{
actionName = actionName,
partnerName = partnerName,
customerUid = customerUid,
extra = "{}",
};

return EditorAnalytics.SendEventWithLimit(k_EventName, eventData, k_VersionId);
}
catch
{
// Fail silently
return AnalyticsResult.AnalyticsDisabled;
}
}
}
}
return EditorAnalytics.SendEventWithLimit(k_EventName, eventData, k_VersionId);
}
catch
{
// Fail silently
return AnalyticsResult.AnalyticsDisabled;
}
}
}
}
2 changes: 1 addition & 1 deletion OneSignalExample/Assets/OneSignal/Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("OneSignal.Packager")]
[assembly: InternalsVisibleTo("OneSignal.Packager")]
Loading
Loading