Skip to content

Commit 12c5494

Browse files
committed
fix: windows deeplink write location, warnings
1 parent dd0b782 commit 12c5494

File tree

9 files changed

+54
-77
lines changed

9 files changed

+54
-77
lines changed

src/Packages/Passport/Runtime/Scripts/Private/Core/BrowserCommunicationsManager.cs

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IBrowserCommunicationsManager
2121
#endif
2222
void SetCallTimeout(int ms);
2323
void LaunchAuthURL(string url, string redirectUri);
24-
UniTask<string> Call(string fxName, string data = null, bool ignoreTimeout = false, Nullable<long> timeoutMs = null);
24+
UniTask<string> Call(string fxName, string? data = null, bool ignoreTimeout = false, Nullable<long> timeoutMs = null);
2525
#if (UNITY_IPHONE && !UNITY_EDITOR) || (UNITY_ANDROID && !UNITY_EDITOR)
2626
void ClearCache(bool includeDiskFiles);
2727
void ClearStorage();
@@ -39,14 +39,14 @@ public class BrowserCommunicationsManager : IBrowserCommunicationsManager
3939

4040
private readonly IDictionary<string, UniTaskCompletionSource<string>> requestTaskMap = new Dictionary<string, UniTaskCompletionSource<string>>();
4141
private readonly IWebBrowserClient webBrowserClient;
42-
public event OnBrowserReadyDelegate OnReady;
42+
public event OnBrowserReadyDelegate? OnReady;
4343

4444
/// <summary>
4545
/// PKCE in some platforms such as iOS and macOS will not trigger a deeplink and a proper callback needs to be
4646
/// setup.
4747
/// </summary>
48-
public event OnUnityPostMessageDelegate OnAuthPostMessage;
49-
public event OnUnityPostMessageErrorDelegate OnPostMessageError;
48+
public event OnUnityPostMessageDelegate? OnAuthPostMessage;
49+
public event OnUnityPostMessageErrorDelegate? OnPostMessageError;
5050

5151
/// <summary>
5252
/// Timeout time for waiting for each call to respond in milliseconds
@@ -71,31 +71,23 @@ public void SetCallTimeout(int ms)
7171
callTimeout = ms;
7272
}
7373

74-
public UniTask<string> Call(string fxName, string data = null, bool ignoreTimeout = false, Nullable<long> timeoutMs = null)
74+
public UniTask<string> Call(string fxName, string? data = null, bool ignoreTimeout = false, long? timeoutMs = null)
7575
{
7676
var t = new UniTaskCompletionSource<string>();
77-
string requestId = Guid.NewGuid().ToString();
77+
var requestId = Guid.NewGuid().ToString();
7878
// Add task completion source to the map so we can return the response
7979
requestTaskMap.Add(requestId, t);
8080
CallFunction(requestId, fxName, data);
81-
if (ignoreTimeout)
82-
return t.Task;
83-
else
84-
return t.Task.Timeout(TimeSpan.FromMilliseconds(timeoutMs ?? callTimeout));
81+
return ignoreTimeout ? t.Task : t.Task.Timeout(TimeSpan.FromMilliseconds(timeoutMs ?? callTimeout));
8582
}
8683

87-
private void CallFunction(string requestId, string fxName, string data = null)
84+
private void CallFunction(string requestId, string fxName, string? data = null)
8885
{
89-
BrowserRequest request = new BrowserRequest()
90-
{
91-
fxName = fxName,
92-
requestId = requestId,
93-
data = data
94-
};
95-
string requestJson = JsonUtility.ToJson(request).Replace("\\", "\\\\").Replace("\"", "\\\"");
86+
var request = new BrowserRequest(fxName, requestId, data);
87+
var requestJson = JsonUtility.ToJson(request).Replace("\\", "\\\\").Replace("\"", "\\\"");
9688

9789
// Call the function on the JS side
98-
string js = $"callFunction(\"{requestJson}\")";
90+
var js = $"callFunction(\"{requestJson}\")";
9991

10092
if (fxName != PassportAnalytics.TRACK)
10193
{
@@ -140,25 +132,19 @@ private void InvokeOnUnityPostMessage(string message)
140132
private void InvokeOnAuthPostMessage(string message)
141133
{
142134
PassportLogger.Info($"{TAG} Auth message received: {message}");
143-
if (OnAuthPostMessage != null)
144-
{
145-
OnAuthPostMessage.Invoke(message);
146-
}
135+
OnAuthPostMessage?.Invoke(message);
147136
}
148137

149138
private void InvokeOnPostMessageError(string id, string message)
150139
{
151140
PassportLogger.Info($"{TAG} Error message received ({id}): {message}");
152-
if (OnPostMessageError != null)
153-
{
154-
OnPostMessageError.Invoke(id, message);
155-
}
141+
OnPostMessageError?.Invoke(id, message);
156142
}
157143

158144
private void HandleResponse(string message)
159145
{
160146
PassportLogger.Debug($"{TAG} Handle response message: " + message);
161-
BrowserResponse response = message.OptDeserializeObject<BrowserResponse>();
147+
var response = message.OptDeserializeObject<BrowserResponse>();
162148

163149
// Validate the deserialised response object
164150
if (response == null || string.IsNullOrEmpty(response.responseFor) || string.IsNullOrEmpty(response.requestId))
@@ -181,10 +167,7 @@ private void HandleResponse(string message)
181167
if (response.responseFor == INIT && response.requestId == INIT_REQUEST_ID)
182168
{
183169
PassportLogger.Info($"{TAG} Browser is ready");
184-
if (OnReady != null)
185-
{
186-
OnReady.Invoke();
187-
}
170+
OnReady?.Invoke();
188171
return;
189172
}
190173

@@ -230,13 +213,13 @@ private PassportException ParseError(BrowserResponse response)
230213

231214
private void NotifyRequestResult(string requestId, string result)
232215
{
233-
BrowserResponse response = result.OptDeserializeObject<BrowserResponse>();
234-
UniTaskCompletionSource<string> completion = requestTaskMap[requestId] as UniTaskCompletionSource<string>;
216+
var response = result.OptDeserializeObject<BrowserResponse>();
217+
var completion = requestTaskMap[requestId] as UniTaskCompletionSource<string>;
235218
try
236219
{
237-
if (response.success == false || !String.IsNullOrEmpty(response.error))
220+
if (response?.success == false || !string.IsNullOrEmpty(response?.error))
238221
{
239-
PassportException exception = ParseError(response);
222+
var exception = ParseError(response);
240223
if (!completion.TrySetException(exception))
241224
throw new PassportException($"Unable to set exception for for request id {requestId}. Task has already been completed.");
242225
}

src/Packages/Passport/Runtime/Scripts/Private/Core/Model/BrowserRequest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ public class BrowserRequest
77
{
88
public string fxName;
99
public string requestId;
10-
public string data;
10+
public string? data;
11+
12+
public BrowserRequest(string fxName, string requestId, string? data)
13+
{
14+
this.fxName = fxName;
15+
this.requestId = requestId;
16+
this.data = data;
17+
}
1118
}
1219
}
1320

src/Packages/Passport/Runtime/Scripts/Private/Event/AnalyticsEvent.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ public static class EventName
1818
public const string INIT_PASSPORT = "initialisedPassport";
1919

2020
// Login
21-
public const string START_LOGIN = "startedLogin";
22-
public const string COMPLETE_LOGIN = "performedLogin";
2321
public const string START_LOGIN_PKCE = "startedLoginPkce";
2422
public const string COMPLETE_LOGIN_PKCE = "performedLoginPkce";
2523
public const string COMPLETE_RELOGIN = "performedRelogin";
2624

2725
// Connect
28-
public const string START_CONNECT_IMX = "startedConnectImx";
29-
public const string COMPLETE_CONNECT_IMX = "performedConnectImx";
3026
public const string START_CONNECT_IMX_PKCE = "startedConnectImxPkce";
3127
public const string COMPLETE_CONNECT_IMX_PKCE = "performedConnectImxPkce";
3228
public const string COMPLETE_RECONNECT = "performedReconnect";
3329

3430
// Logout
35-
public const string COMPLETE_LOGOUT = "performedLogout";
3631
public const string COMPLETE_LOGOUT_PKCE = "performedLogoutPkce";
3732
}
3833

@@ -42,7 +37,7 @@ public static class Properties
4237
}
4338

4439
public async UniTask Track(IBrowserCommunicationsManager communicationsManager, string eventName,
45-
bool? success = null, Dictionary<string, object> properties = null)
40+
bool? success = null, Dictionary<string, object>? properties = null)
4641
{
4742
try
4843
{

src/Packages/Passport/Runtime/Scripts/Private/Helpers/JsonHelpers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public static string ToJson(this IDictionary<string, object> dictionary)
8080
[Serializable]
8181
private class Wrapper<T>
8282
{
83+
#pragma warning disable CS8618
8384
public T[] Items;
85+
#pragma warning restore CS8618
8486
}
8587
}
8688
}

src/Packages/Passport/Runtime/Scripts/Private/Helpers/UriHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class UriExtensions
88
/// <summary>
99
/// Gets the specified query parameter from the given URI
1010
/// </summary>
11-
public static string GetQueryParameter(this Uri uri, string key)
11+
public static string? GetQueryParameter(this Uri uri, string key)
1212
{
1313
try
1414
{

src/Packages/Passport/Runtime/Scripts/Private/Helpers/WindowsDeepLink.cs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Immutable.Passport.Helpers
1111
{
1212
public class WindowsDeepLink : MonoBehaviour
1313
{
14-
private const string RegistryDeepLinkName = "deeplink";
14+
private const string REGISTRY_DEEP_LINK_NAME = "deeplink";
1515

1616
private static WindowsDeepLink? _instance;
1717
private Action<string>? _callback;
@@ -28,8 +28,8 @@ public class WindowsDeepLink : MonoBehaviour
2828
private static extern int RegCreateKeyEx(
2929
UIntPtr hKey,
3030
string lpSubKey,
31-
int Reserved,
32-
string lpClass,
31+
int reserved,
32+
string? lpClass,
3333
uint dwOptions,
3434
uint samDesired,
3535
IntPtr lpSecurityAttributes,
@@ -39,8 +39,8 @@ private static extern int RegCreateKeyEx(
3939
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
4040
private static extern int RegSetValueEx(
4141
UIntPtr hKey,
42-
string lpValueName,
43-
int Reserved,
42+
string? lpValueName,
43+
int reserved,
4444
uint dwType,
4545
string lpData,
4646
uint cbData);
@@ -110,7 +110,7 @@ private static void CreateCommandScript(string protocolName)
110110
{
111111
"@echo off",
112112
// Store deeplink URI in registry
113-
$"REG ADD \"HKCU\\Software\\Classes\\{protocolName}\" /v \"{RegistryDeepLinkName}\" /t REG_SZ /d %1 /f >nul 2>&1",
113+
$"REG ADD \"HKCU\\Software\\Classes\\{protocolName}\" /v \"{REGISTRY_DEEP_LINK_NAME}\" /t REG_SZ /d %1 /f >nul 2>&1",
114114
"setlocal",
115115
"",
116116
$"set \"PROJECT_PATH={projectPath}\"",
@@ -171,7 +171,7 @@ private static void CreateCommandScript(string protocolName)
171171
{
172172
"@echo off",
173173
// Store deeplink URI in registry
174-
$"REG ADD \"HKCU\\Software\\Classes\\{protocolName}\" /v \"{RegistryDeepLinkName}\" /t REG_SZ /d %1 /f >nul 2>&1",
174+
$"REG ADD \"HKCU\\Software\\Classes\\{protocolName}\" /v \"{REGISTRY_DEEP_LINK_NAME}\" /t REG_SZ /d %1 /f >nul 2>&1",
175175
// Check if game is already running
176176
$"tasklist /FI \"IMAGENAME eq {gameExeName}\" 2>NUL | find /I \"{gameExeName}\" >NUL",
177177
"if %ERRORLEVEL%==0 (",
@@ -198,7 +198,7 @@ private static void RegisterProtocol(string protocolName)
198198
UIntPtr hKey;
199199
uint disposition;
200200
// Create registry key for the protocol
201-
int result = RegCreateKeyEx(
201+
var result = RegCreateKeyEx(
202202
(UIntPtr)HKEY_CURRENT_USER,
203203
$@"Software\Classes\{protocolName}",
204204
0,
@@ -216,9 +216,9 @@ private static void RegisterProtocol(string protocolName)
216216

217217
// Set the default value for the protocol key to Application.productName
218218
// This is often used by Windows as the display name for the protocol
219-
string appProductName = Application.productName;
220-
uint productNameDataSize = (uint)((appProductName.Length + 1) * Marshal.SystemDefaultCharSize);
221-
int setDefaultResult = RegSetValueEx(hKey, null, 0, REG_SZ, appProductName, productNameDataSize);
219+
var appProductName = Application.productName;
220+
var productNameDataSize = (uint)((appProductName.Length + 1) * Marshal.SystemDefaultCharSize);
221+
var setDefaultResult = RegSetValueEx(hKey, null, 0, REG_SZ, appProductName, productNameDataSize);
222222

223223
if (setDefaultResult != 0)
224224
{
@@ -268,14 +268,7 @@ private static void RegisterProtocol(string protocolName)
268268
private static string GetGameExecutablePath(string suffix)
269269
{
270270
var exeName = Application.productName + suffix;
271-
#if UNITY_EDITOR_WIN
272-
// Returns the persistent data path in editor
273271
return Path.Combine(Application.persistentDataPath, exeName).Replace("/", "\\");
274-
#else
275-
// Returns game root directory in build
276-
var exePath = Path.Combine(Application.dataPath, "../");
277-
return Path.Combine(exePath, exeName).Replace("/", "\\");
278-
#endif
279272
}
280273

281274
private void OnApplicationFocus(bool hasFocus)
@@ -289,9 +282,9 @@ private void OnApplicationFocus(bool hasFocus)
289282
private void HandleDeeplink()
290283
{
291284
// Open registry key for the protocol
292-
string registryPath = $@"Software\Classes\{_protocolName}";
285+
var registryPath = $@"Software\Classes\{_protocolName}";
293286
UIntPtr hKey;
294-
int result = RegOpenKeyEx(
287+
var result = RegOpenKeyEx(
295288
(UIntPtr)HKEY_CURRENT_USER,
296289
registryPath,
297290
0,
@@ -307,7 +300,7 @@ private void HandleDeeplink()
307300
// Get size of deeplink data
308301
uint type = 0;
309302
uint dataSize = 0;
310-
result = RegQueryValueEx(hKey, RegistryDeepLinkName, IntPtr.Zero, ref type, null!, ref dataSize);
303+
result = RegQueryValueEx(hKey, REGISTRY_DEEP_LINK_NAME, IntPtr.Zero, ref type, null!, ref dataSize);
311304

312305
if (result != 0)
313306
{
@@ -318,7 +311,7 @@ private void HandleDeeplink()
318311

319312
// Read deeplink data
320313
var data = new byte[dataSize];
321-
result = RegQueryValueEx(hKey, RegistryDeepLinkName, IntPtr.Zero, ref type, data, ref dataSize);
314+
result = RegQueryValueEx(hKey, REGISTRY_DEEP_LINK_NAME, IntPtr.Zero, ref type, data, ref dataSize);
322315

323316
var callbackInvoked = false;
324317
if (result == 0 && type == REG_SZ)

src/Packages/Passport/Runtime/Scripts/Private/Model/Request/UnsignedTransferRequest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ public class UnsignedTransferRequest
2323
/**
2424
* The token ID
2525
*/
26-
public string tokenId;
26+
public string? tokenId;
2727

2828
/**
2929
* The token address
3030
*/
31-
public string tokenAddress;
31+
public string? tokenAddress;
3232

3333
public UnsignedTransferRequest(
3434
string type,
3535
string amount,
3636
string receiver,
37-
string tokenId = null,
38-
string tokenAddress = null
37+
string? tokenId = null,
38+
string? tokenAddress = null
3939
)
4040
{
4141
this.type = type;

src/Packages/Passport/Runtime/Scripts/Private/PassportFunction.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ namespace Immutable.Passport
33
public static class PassportFunction
44
{
55
public const string INIT = "init";
6-
public const string INIT_DEVICE_FLOW = "initDeviceFlow";
76
public const string RELOGIN = "relogin";
87
public const string RECONNECT = "reconnect";
98
public const string LOGIN_PKCE = "loginPKCE";
109
public const string CONNECT_PKCE = "connectPKCE";
1110
public const string GET_PKCE_AUTH_URL = "getPKCEAuthUrl";
12-
public const string LOGIN_CONFIRM_CODE = "loginConfirmCode";
13-
public const string CONNECT_CONFIRM_CODE = "connectConfirmCode";
1411
public const string GET_ACCESS_TOKEN = "getAccessToken";
1512
public const string GET_ID_TOKEN = "getIdToken";
1613
public const string LOGOUT = "logout";

src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ private async UniTask LaunchAuthUrl()
276276
try
277277
{
278278
var request = new GetPKCEAuthUrlRequest(!_pkceLoginOnly, _directLoginMethod);
279-
string callResponse = await _communicationsManager.Call(PassportFunction.GET_PKCE_AUTH_URL, JsonUtility.ToJson(request));
280-
StringResponse response = callResponse.OptDeserializeObject<StringResponse>();
279+
var callResponse = await _communicationsManager.Call(PassportFunction.GET_PKCE_AUTH_URL, JsonUtility.ToJson(request));
280+
var response = callResponse.OptDeserializeObject<StringResponse>();
281281

282282
if (response != null && response.success == true && response.result != null)
283283
{
284-
string url = response.result.Replace(" ", "+");
284+
var url = response.result.Replace(" ", "+");
285285
#if UNITY_ANDROID && !UNITY_EDITOR
286286
loginPKCEUrl = url;
287287
SendAuthEvent(_pkceLoginOnly ? PassportAuthEvent.LoginPKCELaunchingCustomTabs : PassportAuthEvent.ConnectImxPKCELaunchingCustomTabs);
@@ -747,7 +747,7 @@ public void ClearStorage()
747747
}
748748
#endif
749749

750-
protected virtual async void Track(string eventName, bool? success = null, Dictionary<string, object> properties = null)
750+
protected virtual async void Track(string eventName, bool? success = null, Dictionary<string, object>? properties = null)
751751
{
752752
await _analytics.Track(_communicationsManager, eventName, success, properties);
753753
}

0 commit comments

Comments
 (0)