Skip to content

Commit

Permalink
Added Aptabase key area in appsettings.json, configure analytics and …
Browse files Browse the repository at this point in the history
…youtuberchannel parameter added main page load event.
  • Loading branch information
Andronovo-bit committed Feb 27, 2024
1 parent 9b645be commit 9a4876f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
DOTNET_NOLOGO: true # Disable the .NET logo
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Disable the .NET first time experience
DOTNET_CLI_TELEMETRY_OPTOUT: true # Disable sending .NET CLI telemetry
APTABASE_KEY: ${{ secrets.APTABASE_KEY }} # Aptabase Key

jobs:
# MAUI Windows Build
Expand All @@ -39,6 +40,7 @@ jobs:
$jsonContent = Get-Content -Path $pathToJson -Raw | ConvertFrom-Json
$jsonContent.Settings.SponsorGameAppId = "${{ vars.GAME_ID }}"
$jsonContent.Settings.YoutuberChanneName = "${{ vars.YOUTUBE_CHANNEL }}"
$jsonContent.Settings.AptabaseKey = "$env:APTABASE_KEY"
$jsonContent | ConvertTo-Json -Depth 100 | Set-Content -Path $pathToJson
$jsonContent
shell: pwsh
Expand Down
30 changes: 25 additions & 5 deletions src/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
// .UseAptabase("YOUR-CODE") // 👈 this is where you enter your App Key
.UseMauiCommunityToolkit()
.ConfigureSyncfusionCore()
.UseLocalizationResourceManager(settings =>
Expand All @@ -31,6 +30,9 @@ public static MauiApp CreateMauiApp()
})
.ConfigureFonts(ConfigureFonts);

builder.Logging.SetMinimumLevel(LogLevel.Debug);


Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{

Expand Down Expand Up @@ -61,12 +63,12 @@ public static MauiApp CreateMauiApp()
builder.Logging.AddDebug();
#endif
builder.Services.ConfigureServices();
// builder.Services.RegisterAnalyticsObservers(); // 👈 this is where we register the observers
builder.RegisterViews();
builder.RegisterConfiguration();
builder.CheckAndAddAnalyticsBeforeBuild();

var app = builder.Build();
// app.Services.ConfigureAnalyticsSubject(); // 👈 this is where we configure the subject
app.CheckAndAddAnalyticsAfterBuild();
return app;
}

Expand All @@ -86,8 +88,6 @@ public static MauiAppBuilder RegisterViews(this MauiAppBuilder builder)
}
private static void ConfigureServices(this IServiceCollection services)
{
services.Configure<GlobalOptions>(x => x.ProjectOperationPath = Path.Combine(Path.GetTempPath(), "HuaweiHMSInstaller")); //configure value
services.Configure<GlobalOptions>(x => x.VersionNumber = "0.0.1"); //configure value
services.AddHttpClient();
services.AddScoped<IAdbOperationService, AdbOperationService>();
services.AddScoped<IAppGalleryIntegration, AppGalleryIntegration>();
Expand Down Expand Up @@ -151,4 +151,24 @@ private static void RegisterConfiguration(this MauiAppBuilder appBuilder)
throw new FileNotFoundException($"Resource {resourceName} not found.");
}
}
private static void CheckAndAddAnalyticsBeforeBuild(this MauiAppBuilder appBuilder)
{
var settings = appBuilder.Configuration.GetSection("Settings").Get<AppSettings>();
if (string.IsNullOrWhiteSpace(settings?.AptabaseKey) == false)
{
appBuilder.UseAptabase(settings.AptabaseKey);
appBuilder.Services.RegisterAnalyticsObservers(); // 👈 this is where we register the observers
appBuilder.Services.RegisterAnalyticsObservers(); // 👈 this is where we register the observers

}

}
private static void CheckAndAddAnalyticsAfterBuild(this MauiApp app)
{
var settings = app.Configuration.GetSection("Settings").Get<AppSettings>();
if (string.IsNullOrWhiteSpace(settings?.AptabaseKey) == false)
{
app.Services.ConfigureAnalyticsSubject(); // 👈 this is where we configure the subject
}
}
}
1 change: 1 addition & 0 deletions src/Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class AppSettings
public string VersionNumber { get; set; }
public string SponsorGameAppId { get; set; } = "C106234721"; //C104193349
public string YoutuberChanneName { get; set; }
public string AptabaseKey { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ await _analyticsSubject.NotifyAsync("Main Page Loaded",
new Dictionary<string, object>
{
{ "SelectedGame", selectedGame.Name },
{ "SelectedGameId", selectedGame.AppId }
{ "SelectedGameId", selectedGame.AppId },
{ "YoutuberChannel", _settings.YoutuberChanneName }
}
);

Expand Down
5 changes: 3 additions & 2 deletions src/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Settings": {
"VersionNumber": "0.0.0.1",
"VersionNumber": "0.0.1",
"SponsorGameAppId": "C106234721",
"YoutuberChanneName": "Huawei"
"YoutuberChanneName": "Huawei",
"AptabaseKey": ""
}
}

0 comments on commit 9a4876f

Please sign in to comment.