Aha. Interesting. So, I need to include system_uri.dll and call install
to register the app with the system? I’m not sure what that does… but from what I can see… I have gotten the scheme back (safe-[encoded stuff]
) after allowing my app in Authenticator. But there is also something called execPath in appInfo I see.
I do not know how the scheme is used, or how it needs to look for various situations. (I am guessing it’s safe-[encoded stuff]
because the browser is supposed to use safe://
?)
The execPath I guess though, will be the URI that is called, that will launch the application.
So, it looks to me like we are passing in this scheme and the exec URI when calling install
(together with the app info).
Then the Authenticator calls this execPath when app is allowed.
Then I am a little bit wiser I think.
This is all very interesting, and great that you were right now working with it
I cannot find where the SafeMessages app in mobile libraries call install
with appInfo. I have missed this part completely.
So, this is what I have done now:
public class NativeBindings : INativeBindings
{
#region Install
public void InstallUri(AppInfo info, InstallUriCb callback)
{
InstallUriNative(info.Id, info.Vendor, info.Name, info.Exec, info.Icon, info.Schemes, callback.ToHandlePtr(), OnInstallUriCb);
}
[DllImport("system_uri.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "install")]
public static extern void InstallUriNative(
string bundle,
string vendor,
string name,
string exec,
string icon,
string schemes,
IntPtr userDataPtr,
InstallUriCb callback);
private static void OnInstallUriCb(IntPtr cbPtr, FfiResult result)
{
var cb = cbPtr.HandlePtrToType<InstallUriCb>();
cb(IntPtr.Zero, result);
}
#endregion
and it will be used by this:
public static Task<bool> InstallUriAsync(AppInfo appInfo)
{
return Task.Run(
() => {
var tcs = new TaskCompletionSource<bool>();
InstallUriCb callback = (_, result) => {
if (result.ErrorCode != 0)
{
tcs.SetException(result.ToException());
return;
}
tcs.SetResult(true);
};
NativeBindings.InstallUri(appInfo, callback);
return tcs.Task;
});
}
which in turn will be used by this:
public async Task<bool> InstallUriAsync()
{
State.AppId = "oetyng.apps.safe.eventstore";
var appInfo = new AppInfo
{
Id = AppId,
Name = "SAFE EventStore",
Vendor = "Oetyng",
Icon = "some icon",
Exec = "",
Schemes = ""
};
var installed = await Session.InstallUriAsync(appInfo);
Debug.WriteLine($"Installed: {installed}");
return installed;
}
and this I will call, just like you do, before gen_auth_uri.
(However, since the installation is always done before generating auth uri, I put the call within that method instead)
which gives this:
public async Task<string> GenerateAppRequestAsync()
{
if (!await InstallUriAsync())
throw new InvalidOperationException();
var authReq = new AuthReq
{
AppContainer = true,
AppExchangeInfo = new AppExchangeInfo { Id = AppId, Scope = "", Name = "SAFE EventStore", Vendor = "Oetyng" },
Containers = new List<ContainerPermissions> { new ContainerPermissions { ContainerName = "_publicNames", Access = { Insert = true } } }
};
var encodedReq = await Session.EncodeAuthReqAsync(authReq);
var formattedReq = UrlFormat.Convert(encodedReq, false);
Debug.WriteLine($"Encoded Req: {formattedReq}");
return formattedReq;
}
As you can see, I still have to figure out what value the Schemes
and Exec
properties shall have.
My app will already be running, so opening it again seems strange… It is exposing HTTP endpoints though, so I could execute a simple console application which just calls some HTTP endpoint in my app and then shuts down… Seems like an odd way to go about it, but currently only idea I have.
As to what causes the serialization error:
I got it from here: https://github.com/maidsafe/safe_client_libs/tree/alpha-2/safe_app a few days ago. So, that is 0.4.0.