Skip to content

Commit 75f43ae

Browse files
feat: [SDK-4774] add OneSignal project settings support (#880)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3bc5b42 commit 75f43ae

58 files changed

Lines changed: 3061 additions & 39 deletions

File tree

Some content is hidden

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

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @OneSignal/eng-sdk-platform

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ The only thing remaining is to setup your own notification icons. You can do thi
150150
with your own. There is a complete guide for this [in the plugin's README](com.onesignal.unity.android/Editor/OneSignalConfig.androidlib/README.md). See our
151151
[Customize Notification Icons](https://documentation.onesignal.com/docs/customize-notification-icons) page for additional details.
152152
153-
### Disable Location Module
153+
### Disable Location Module (Optional)
154154
155155
By default, the OneSignal Unity SDK includes OneSignal's native location module so `OneSignal.Location` works without extra setup. If your app does not use location features, you can exclude the native location module from iOS and Android builds. There are two ways to opt out:
156156
157-
- **Editor toggle** (interactive): select **OneSignal > Disable Location Module** in the Unity Editor before resolving Android dependencies or building iOS. This is persisted per project in `ProjectSettings/OneSignalSettings.json`.
157+
- **Editor toggle** (interactive): enable **Project Settings > OneSignal > Disable Location Module** in the Unity Editor before resolving Android dependencies or building iOS. This is persisted per project in `ProjectSettings/OneSignalSettings.json`.
158158
- **Environment variable** (CLI/CI): set `ONESIGNAL_DISABLE_LOCATION=true` (or `1`) in the environment before launching Unity, for example:
159159
160160
```sh

com.onesignal.unity.android/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.onesignal.unity.android",
33
"displayName": "OneSignal Unity SDK - Android",
44
"version": "5.2.11",
5-
"unity": "2018.4",
5+
"unity": "2021.3",
66
"description": "OneSignal is the market leader in customer engagement, powering mobile push, web push, email, and in-app messages.",
77
"dependencies": {
88
"com.onesignal.unity.core": "5.2.11"

com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,6 @@ public static void Save()
8080
File.WriteAllText(_settingsPath, JsonUtility.ToJson(_settings, true));
8181
}
8282

83-
[MenuItem("OneSignal/Disable Location Module")]
84-
private static void ToggleDisableLocation()
85-
{
86-
DisableLocation = !DisableLocation;
87-
}
88-
89-
[MenuItem("OneSignal/Disable Location Module", true)]
90-
private static bool ToggleDisableLocationValidate()
91-
{
92-
Menu.SetChecked("OneSignal/Disable Location Module", DisableLocation);
93-
return true;
94-
}
95-
9683
private static readonly string _settingsPath = Path.Combine(
9784
"ProjectSettings",
9885
"OneSignalSettings.json"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Modified MIT License
3+
*
4+
* Copyright 2023 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
using System;
29+
using System.Collections.Generic;
30+
using UnityEditor;
31+
using UnityEngine;
32+
33+
namespace OneSignalSDK
34+
{
35+
/// <summary>
36+
/// Adds a "OneSignal" page under Project Settings for persistent SDK configuration.
37+
/// </summary>
38+
public static class OneSignalSettingsProvider
39+
{
40+
private const string _path = "Project/OneSignal";
41+
private const float _contentPadding = 10f;
42+
43+
[SettingsProvider]
44+
public static SettingsProvider Create()
45+
{
46+
var keywords = new HashSet<string>(
47+
new[] { "OneSignal", "Push", "Notifications", "Location", "Disable Location" }
48+
);
49+
50+
return new SettingsProvider(_path, SettingsScope.Project)
51+
{
52+
label = "OneSignal",
53+
keywords = keywords,
54+
guiHandler = _ => DrawGUI(),
55+
};
56+
}
57+
58+
private static void DrawGUI()
59+
{
60+
var environmentOverride = Environment.GetEnvironmentVariable(
61+
OneSignalSDKSettings.DisableLocationEnvVar
62+
);
63+
var hasEnvironmentOverride = !string.IsNullOrEmpty(environmentOverride);
64+
65+
EditorGUILayout.BeginHorizontal();
66+
GUILayout.Space(_contentPadding);
67+
EditorGUILayout.BeginVertical();
68+
69+
EditorGUILayout.Space();
70+
71+
EditorGUILayout.LabelField("Location", EditorStyles.boldLabel);
72+
73+
using (new EditorGUI.DisabledScope(hasEnvironmentOverride))
74+
{
75+
var newValue = EditorGUILayout.ToggleLeft(
76+
new GUIContent(
77+
"Disable Location Module",
78+
"Excludes the OneSignal location dependency from the generated native "
79+
+ "build. Enable this if your app does not use location features."
80+
),
81+
OneSignalSDKSettings.DisableLocation
82+
);
83+
84+
if (newValue != OneSignalSDKSettings.DisableLocation)
85+
OneSignalSDKSettings.DisableLocation = newValue;
86+
}
87+
88+
EditorGUILayout.Space();
89+
90+
if (hasEnvironmentOverride)
91+
{
92+
EditorGUILayout.HelpBox(
93+
$"The {OneSignalSDKSettings.DisableLocationEnvVar} environment variable is set "
94+
+ $"to \"{environmentOverride}\" and overrides this setting for the current "
95+
+ "session. The effective value is "
96+
+ $"{(OneSignalSDKSettings.EffectiveDisableLocation ? "disabled" : "enabled")}.",
97+
MessageType.Info
98+
);
99+
}
100+
else
101+
{
102+
EditorGUILayout.HelpBox(
103+
$"Set the {OneSignalSDKSettings.DisableLocationEnvVar} environment variable "
104+
+ "(\"true\" or \"1\") to override this setting for CLI and CI builds "
105+
+ "without modifying project settings.",
106+
MessageType.None
107+
);
108+
}
109+
110+
EditorGUILayout.EndVertical();
111+
GUILayout.Space(_contentPadding);
112+
EditorGUILayout.EndHorizontal();
113+
}
114+
}
115+
}

com.onesignal.unity.core/Editor/OneSignalSettingsProvider.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.onesignal.unity.core/Editor/Platform/UserManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public string ExternalId
4343
get => null;
4444
}
4545

46-
public event EventHandler<UserStateChangedEventArgs> Changed;
46+
public event EventHandler<UserStateChangedEventArgs> Changed
47+
{
48+
add { }
49+
remove { }
50+
}
4751

4852
private PushSubscription _subscription = new PushSubscription();
4953

com.onesignal.unity.core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.onesignal.unity.core",
33
"displayName": "OneSignal Unity SDK - Core",
44
"version": "5.2.11",
5-
"unity": "2018.4",
5+
"unity": "2021.3",
66
"description": "OneSignal is the market leader in customer engagement, powering mobile push, web push, email, and in-app messages.",
77
"dependencies": {
88
},

com.onesignal.unity.ios/Editor/BuildPostProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private void AddNotificationServiceExtension()
209209
extensionGuid = _project.AddAppExtension(
210210
_project.GetMainTargetGuid(),
211211
ServiceExtensionTargetName,
212-
PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS)
212+
PlayerSettings.GetApplicationIdentifier(NamedBuildTarget.iOS)
213213
+ "."
214214
+ ServiceExtensionTargetName,
215215
ServiceExtensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode

com.onesignal.unity.ios/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.onesignal.unity.ios",
33
"displayName": "OneSignal Unity SDK - iOS",
44
"version": "5.2.11",
5-
"unity": "2018.4",
5+
"unity": "2021.3",
66
"description": "OneSignal is the market leader in customer engagement, powering mobile push, web push, email, and in-app messages.",
77
"dependencies": {
88
"com.onesignal.unity.core": "5.2.11"

0 commit comments

Comments
 (0)