Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Created March 24, 2021 19:56
Show Gist options
  • Save jtmuller5/7ae34885d675fa7a374e1b3235b59f3a to your computer and use it in GitHub Desktop.
Save jtmuller5/7ae34885d675fa7a374e1b3235b59f3a to your computer and use it in GitHub Desktop.
Create an AtClient
/// Create an AtClient (AtClientImpl) to communicate with the person's
/// secondary server
Future<bool> onboard({String atsign}) async {
atClientImpl = null;
atClientService = AtClientService();
Directory downloadDirectory;
/// The directory where keys will be stored
if (Platform.isIOS) {
downloadDirectory =
await path_provider.getApplicationDocumentsDirectory();
}
/// Download path varies on non-iOS platforms
else {
downloadDirectory = await path_provider.getExternalStorageDirectory();
}
final appSupportDirectory =
await path_provider.getApplicationSupportDirectory();
String path = appSupportDirectory.path;
/// Setup AtClient preferences (cascade for cleanliness)
atClientPreference = AtClientPreference()
..isLocalStoreRequired = true
..commitLogPath = path
..syncStrategy = SyncStrategy.IMMEDIATE
..rootDomain = AtConstants.ROOT_DOMAIN
..hiveStoragePath = path
..downloadPath = downloadDirectory.path;
var result = await atClientService
.onboard(atClientPreference: atClientPreference, atsign: atsign)
.catchError((e) => print('Error in Onboarding: $e'));
print('result: ' + result.toString());
result ??= false;
/// Store the current At Sign for display
atClientImpl = atClientService.atClient;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment