|
| 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 | +} |
0 commit comments